Single-Precision Dot Products in Matlab
I was running some Matlab functions for stochastic gradient descent SVD, and I was surprised to find that while my code worked perfectly in the Windows environment, it was giving incorrect results when I ran it on the Linux machines. After some debugging, I found out that the dot product calculation on single-precision vectors is the source of the problem:
One way to get around this is to just convert the single-precision vectors into double-precision. It's probably better to just use the "dot" function instead:
This was a pretty subtle bug!
>> a = [1 2 3];
>> b = [3 4 5];
>> a * b'
ans =
26
>> single(a) * single(b)'
ans =
1.0737e+09
One way to get around this is to just convert the single-precision vectors into double-precision. It's probably better to just use the "dot" function instead:
>> dot(single(a),single(b))
ans =
26
This was a pretty subtle bug!