Perl6-Math-Matrix icon indicating copy to clipboard operation
Perl6-Math-Matrix copied to clipboard

OO vs native shaped array?

Open MattOates opened this issue 9 years ago • 15 comments

Looking at the implementation everything is row based and OO? Wouldnt it be better to wrap a native shaped array of num64? That way the memory will be the most efficient and you will gain all the benefits of vectorised SSE optimisations that might be made in the JIT around this area.

MattOates avatar Jan 03 '16 21:01 MattOates

http://design.perl6.org/S09.html#Compact_arrays and http://design.perl6.org/S09.html#Fixed-size_arrays for some reference.

MattOates avatar Jan 03 '16 21:01 MattOates

I have planned to use native shaped array, however, i still encounter some issues with non implemented parts of native arrays, you can see the code there: https://github.com/pierre-vigier/Perl6-Math-Matrix/tree/shaped-array Not finished yet, but if you have any inputs, one of the problem i have is in add methods, where: $.cells >>+<< $b.cells triggers an error: Type check failed in binding @dims; expected Positional but got Any Not sure why yet, also, to keep the syntax: $matrix[row][column], i encounter that:

my int @a[2,2] = (1,2),(3,4);
say @a[1][1];

that gives me:

Partially dimensioned views of arrays not yet implemented. Sorry.
  in block <unit> at <unknown file> line 1

However the idea is to use native array, as for now, perfomance are pretty poor with the current implementation

pierre-vigier avatar Jan 03 '16 22:01 pierre-vigier

i will look into that next

lichtkind avatar Mar 09 '18 13:03 lichtkind

while i support the notion it will demand some massivly different internals and I think i will outsource this in a module like Math::Matrix::Native

lichtkind avatar Mar 13 '18 13:03 lichtkind

I guess the first think would be to assess if the "glitches" i was seeing then are now solved on new version of perl6. As stated above, my first idea was to do everything with Native array, however, i encountered some blocking issues at the time

pierre-vigier avatar Mar 13 '18 14:03 pierre-vigier

yes i looked into it but could not understood it fully what exactly was the glitch?

lichtkind avatar Mar 14 '18 19:03 lichtkind

When trying to access element on shaped array with syntax @a[1][1], program was crashing, as of today, it is still not implemented. However, @a[1;1] .

But more to the point, let's say i have a shaped array for the matrix of 3x3, and i want to get the middle row, @matrix[1] will crash with the same error, @matrix[1;*] as well

pierre-vigier avatar Mar 15 '18 00:03 pierre-vigier

are these results of recent tests?

lichtkind avatar Mar 15 '18 09:03 lichtkind

A few hours ago, however, not the latest version of perl6, but still not too old:

This is Rakudo version 2018.01-100-g156876dbf built on MoarVM version 2018.01-77-g9a029b408 implementing Perl 6.c.

pierre-vigier avatar Mar 15 '18 09:03 pierre-vigier

thanks, so i put it on backburner , my main issue for now is raise quality (docs tests consistency of what we have and add some easy things (split join, tensorproduct) and eigenvalues)

lichtkind avatar Mar 15 '18 11:03 lichtkind

its still a hounting idea maybe write a parallel variant to experiment with

lichtkind avatar Aug 26 '18 09:08 lichtkind

On moar 2018.08 , we still have the same "issue":

> my int @a[2,2] = (1,2),(3,4);
[[1 2] [3 4]]
> say @a[1][1];
Partially dimensioned views of shaped arrays not yet implemented. Sorry.
  in block <unit> at <unknown file> line 1

pierre-vigier avatar Sep 10 '18 01:09 pierre-vigier

thanks

lichtkind avatar Sep 11 '18 10:09 lichtkind

@lichtkind @pierre-vigier please open tickets on https://github.com/rakudo/rakudo/issues. I'm very interested in seeing this implemented with native arrays. If it is slower, we can have nice benchmarks (native vs non-native) and maybe that will result in actionable tickets.

Also check https://github.com/perl-gsoc-2019/ideas, maybe some of the work can be done as a project? I also wonder if there's anything that needs to be added to core (generally it's not the best idea to pile things up in core, but looking at the success of numpy, maybe that's not the worst idea?).

AlexDaniel avatar Jan 24 '19 00:01 AlexDaniel

i will check this. However, the current design gave up on the idea of NSA and there has to be some planning done, before we can reach for the fruits of it again. So yes I will react but have to make up my mind on some technical details before.

lichtkind avatar Jan 24 '19 12:01 lichtkind