Different outputs with random numbers
Hi, I am running code to find the covariance of a matrix from scratch. When the code is run I sometimes get large or small random unexpected numbers or even infinity. It seems to change every time the code is run even when there is no random element in the code, and should produce the same output. Many thanks for any advice.
Code snippet:
8 Replies
Could you provide a minimal reproducible example that people can run (include all the code, etc.)?
This is a reduced code sample that reproduces the problem:
This code prints matrix of 3s and then matrix of 9s. No unexpected behaviour on M3 Macbook.
You are using
You are using
simdwidthof
to get a SIMD width specific to your system (mine would be 4) so that may be one reason it doesn't reproduce. Adding bounds checks to your load
and store
methods would confirm whether you are staying in the allocated pointers.I can reproduce on my machine (Intel Mac with Docker). Trying to reduce the example further now.
Reduced:
For the prospective bug report, the smaller reproducer also shows no bad behaviour on M3 Macbook.
Reported here
GitHub
[BUG]: Code showing non deterministic behaviour · Issue #1755 · mo...
Bug description As title. Doesn't seem to reproduce on M3 Mac. Steps to reproduce from algorithm import vectorize struct Vec: var length: Int var data: DTypePointer[DType.float32] fn init(i...
Seems like a simple problem caused by early destruction, wonder how I missed that. Fix: add
_ = a
before return b
.
I think you can fix your CovarienceMatrix
similarly.Updated: The intended fix has solved the problem, thanks for all of the help