I’m writing a utility that collects a user’s n-dimensional matrices over time and stores them in an n+1 dimensional array. Something like this:
storage[:, :, k] = input
But of course I can’t literally type those colons, because the input could be anything (as long as it’s consistent from call to call). So I’ve written this to store the input matrix:
num_input_dims = length(size(input)) storage[repeat([:], num_input_dims), k] = input
For what it’s worth, in my case
storage is actually part of an HDF5 file with a space preallocated for all of the data the user will pass in. The syntax for
[:, :, :, k] is what the HDF5 package uses for input, and I don’t think strides will work for it.
My syntax above just feels a little silly, and I’m wondering if there’s a better way.