matrex
matrex copied to clipboard
Support of different data types and multiple dimensions
@michalmuskala can you have a look at new structure of the Matrex.Array
object in this branch: https://github.com/versilov/matrex/blob/array/lib/matrex/array.ex
I've added types, arbitrary dimensions and strides. These are now stored in Elixir structure, and data
field contents only pure data, without dimensions. Exactly like you suggested in the post on ElixirForum.
I plan to merge this new structure into the Matrex structure.
Thanks in advance!
Some remarks:
-
fiil_data
can be replaced by:binary.copy
- one idea could be to precompute things like ones and zeros at compile-time and have them as literals. This could be interesting from the performance point of view
-
:"foo_#{to_string(bar)}"
is the same as:"foo_#{bar}"
- I'm not really sure, I understand the "strides" thing. But it seems that most of the time you actually use it to traverse it as a collection - a list might be a better use there instead of a tuple
But yeah, in general this looks good to me. I like that you were able to satisfy some functions directly in elixir without going to the C side with that extra information.
Oh, I forgot to mention, that branch is a bit messy, cuz I used it for experiments on the concept. Sorry for that!
-
fill_data
will be replaced by NIF, I think. - Did not understand, how we can precompute ones and zeros, can you explain, please?
- OK, will update.
- The
strides
I borrowed from the NumPy. When I benchmarked against NumPy, I noticed, that they do matrix transposing in very short constant time. Little investigation revealed, that they just swap strides component for that. That impressed me very much and I decided to incorporate it into Matrix right away. Though, for now they are used only for enumerating and are not taken into consideration, when doing element-wise operations, I think it would be nice to have them in place for later extensions.
I also thought to use lists instead of tuples for strides and shape.
About the ones and zeros - you're right. I somehow overlooked the fact that we don't know the sizes 🤦♂️
@michalmuskala, can we find someone experienced to make a code review for my C code for multi-typed arrays functionality?
Sorry if not the right place to rise this but, I think it would be nice for Matrex.Array
to incorporate ATen for handling tensor functionality right away. Popular frameworks like PyTorch are useful because of its easy handling of tensors and tensor autodifferentiation, which is implemented on top of Autograd, which is implemented on top of ATen.
@doctorcorral that's a nice idea. Does ATen have external libraries as dependencies?
Curious, what's the status of this issue? I'd be interested in double's and/or multi-dimensional data.
@elcritch, this branch is fully functional, except displaying multi-dimensional matrices in console is not working properly.