matrex icon indicating copy to clipboard operation
matrex copied to clipboard

Support of different data types and multiple dimensions

Open versilov opened this issue 6 years ago • 8 comments

@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!

versilov avatar Jun 11 '18 10:06 versilov

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.

michalmuskala avatar Jun 11 '18 11:06 michalmuskala

Oh, I forgot to mention, that branch is a bit messy, cuz I used it for experiments on the concept. Sorry for that!

  1. fill_data will be replaced by NIF, I think.
  2. Did not understand, how we can precompute ones and zeros, can you explain, please?
  3. OK, will update.
  4. 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.

versilov avatar Jun 11 '18 12:06 versilov

About the ones and zeros - you're right. I somehow overlooked the fact that we don't know the sizes 🤦‍♂️

michalmuskala avatar Jun 11 '18 12:06 michalmuskala

@michalmuskala, can we find someone experienced to make a code review for my C code for multi-typed arrays functionality?

versilov avatar Jun 12 '18 16:06 versilov

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 avatar Jun 21 '19 21:06 doctorcorral

@doctorcorral that's a nice idea. Does ATen have external libraries as dependencies?

versilov avatar Jul 01 '19 13:07 versilov

Curious, what's the status of this issue? I'd be interested in double's and/or multi-dimensional data.

elcritch avatar Jan 06 '20 21:01 elcritch

@elcritch, this branch is fully functional, except displaying multi-dimensional matrices in console is not working properly.

versilov avatar Feb 12 '20 17:02 versilov