Base.similar (and Zygote.Buffer) returning undefined instead of array of arrays

I am trying to initialize an array of arrays using similar and Zygote.buffer.
If I initialize an array the functions work as expected, i.e.

a = [0., 0.]

similar(a)
2-element Array{Float64,1}:
 7.229478454414514e221
 2.00297683e-315

when I enter an array of arrays as input, I would expect it to output an array of arrays, instead the function returns an array of undefined:

a = [[0.,0.],[0.,0.]]

similar(a)
2-element Array{Array{Float64,1},1}:
 #undef
 #undef

The Zygote.Buffer function acts in the same fashion.
What am I missing here?

Thanks!

similar gives you uninitialized mutable array of the same type and size.

In this case, it is an array of array. Notice, your first example is also “uninitialized” (the fact that two numbers are all over the places).

2 Likes