Is not a Float64. Since this number is most likely not exactly representable by binary floating point (disclaimer, I didn’t check that) it’s closest approximation, I.e. the parsing result will be different for the two types even though the printing are the same. If you use a float32 literal (add a f0 at the end) the condition should be true assuming what you said is indeed the output of your program.
P.s. when you paste code you should make it either runnable or at least show the result you are confused about. The code you paste right now is no more than some random code that may or may not support what your question.
I did what both @yuyichao and @simonbyrne suggested and it still didn’t work properly. Here is a more complete, runnable version of the code:
using Flux, Flux.Data.MNIST, Statistics
using Flux: onehotbatch, onecold, crossentropy, throttle
using Base.Iterators: repeated, partition
using Printf, BSON
train_labels = MNIST.labels() # 60,000
train_imgs = MNIST.images() # 60,000
function make_minibatch(X, Y, idxs)
X_batch = Array{Float32}(undef, size(X[1])..., 1, length(idxs))
# Creates X-batch and the associated Y_Batch of labels
for i in 1:length(idxs) # This line loops from 1 to 128 (or whatever the lebgth of the iterator partition)
X_batch[:, :, :, i] = Float32.(X[idxs[i]]) # uses idxs iterator to place X[1 to 128] in Xbatch[28, 28, 1, (1 to 128)]
end
Y_batch = onehotbatch(Y[idxs], 0:9) # provides an efficient way of accessing labels
return (X_batch, Y_batch)
end
batch_size = 128
mb_idxs = partition(1:length(train_imgs), batch_size) # divides 60,000 into partitions or batches of 128
train_set = [make_minibatch(train_imgs, train_labels, i) for i in mb_idxs]
a = train_set[1,1]
value = (a[1])[231]
searchvalue = 0.011764707f0
println("typeof(value) = ", typeof(value))
println("typeof(searchvalue) = ", typeof(searchvalue))
println("for ", 231, " in a[1] = ", value)
if value == searchvalue
println("FOUND IT!!!")
else
println("Failed to locate it")
end
Here is the output:
typeof(value) = Float32
typeof(searchvalue) = Float32
for 231 in a[1] = 0.11764707
Failed to locate it
@yuyichao
Yes, but I understood the 0.11764707f0 Float32 literal would be the same as 0.11764707 Float32 value, because the straight up 0.11764707 != 0.11764707…hence the problem…