Re: dimensions in a multidimensional array

2021-02-05 Thread Matthew Stuckwisch
I think he meant doing something like this (with fuller handling for out of 
bounds, exceptions throwing, slices, etc):

role Shaped[*@dimensions] {
has @!multipliers = 
@dimensions.reverse.produce(&[*])[0..*-2].reverse.Slip, 1;

method AT-POS(*@indices where all @dimensions Z> @indices ) { 
self.List::AT-POS( [+] @indices Z* @!multipliers ) 
}
}

In this way, you could read in serial data with a bit less work by shaping it 
after the fact, e.g. 
   
my @foo = $fh.slurp.split($delimiter);
@foo does Shaped[ … ];



> On Feb 5, 2021, at 12:31 PM, Timo Paulssen  wrote:
> 
> Shaped Arrays and Native Shaped Arrays already use one contiguous blob to 
> store all their data; in Shaped Arrays that's an array of pointers to the 
> stored objects, in a Native Shaped Array it'll be like a big array of 32bit 
> integers or whatever you have.
> 
> Regards
>   - Timo
> 
> On 05/02/2021 16:48, yary wrote:
>> This got me interested in 
>> https://docs.raku.org/language/list#index-entry-Shaped_arrays
>> 
>> and I find myself wanting to implement a role "Shaped" and applying it to 
>> List, for an immutable shaped list, whose implementation packs its elements 
>> for o(1) lookup... on my ever-lengthening to-do list
>> 
>> -y
>> 
>> 
>> On Fri, Feb 5, 2021 at 10:06 AM Elizabeth Mattijsen  wrote:
>> > On 5 Feb 2021, at 15:49, Theo van den Heuvel  wrote:
>> > I cannot seem to find an idiomatic way to get the dimensions of a 
>> > multidimensional array,
>> > other than by looking at the size of the first row and column, with 
>> > @m[0;*].elems and @m[*;0].elems.
>> > Am I missing something in the docs?
>> 
>> If it's a shaped multidimensional array, you can call the .shape method
>> 
>> my @a[3;3;3];
>> dd @a.shape;   # (3,3,3)
>> 
>> If it is not, then your workaround appears the way to do it.



Re: dimensions in a multidimensional array

2021-02-05 Thread Wesley Peng
When will we have p6’s Numpy?


On Sat, Feb 6, 2021, at 2:04 AM, Brad Gilbert wrote:
> There is a reason that you can't just ask for the dimensions of an 
> unspecified multidimensional array.
> It may be multiple dimensions.
> 
> [[1,2,3],
> [4,5,6,7,8,9,10]].shape
> 
> If it gave a result it would be something like:
> 
> (2,3|7)
> 
> On Fri, Feb 5, 2021 at 8:50 AM Theo van den Heuvel  
> wrote:
>> Hi gurus,
>> 
>> I cannot seem to find an idiomatic way to get the dimensions of a 
>> multidimensional array,
>> other than by looking at the size of the first row and column, with 
>> @m[0;*].elems and @m[*;0].elems.
>> Am I missing something in the docs?
>> 
>> Thanks,
>> 
>> -- 
>> Theo van den Heuvel
>> 

This Weekend: FOSDEM_2021 (i.e. starting tonite...)

2021-02-05 Thread William Michels via perl6-users
FOSDEM_2021 is going on this weekend [Online 6 & 7 February 2021],
running on CET (Central Europe Time, UTC/GMT +1 hour). That's 6 hours
ahead of the US East Coast and 9 hours ahead of the US West Coast. The
first talk in the "Perl_&_Raku" track is at 10am Saturday on Brussels
time, making it 4am in New York, 3am in Chicago, 2am in Denver, and
1am in San Francisco. Here are the links for the "Perl_&_Raku" track:

https://fosdem.org/2021/schedule/track/perl_and_raku_programming/
https://live.fosdem.org/watch/dperl
https://chat.fosdem.org/#/room/#perl:fosdem.org

Saturday's Perl_&_Raku schedule runs from 10am-6pm Brussels time, so
many of the later talks should be easy to watch in the US (early on
Saturday morning, depending on your location and motivation). Sunday's
schedule runs from 2pm-3:45pm Brussels time, again, watchable in the
US depending on your location (and motivation).

[Here's a widget to help with Time Zones:]
https://time.gov/widget/widget.html

See you in the FOSDEM Chat!


Re: dimensions in a multidimensional array

2021-02-05 Thread Brad Gilbert
There is a reason that you can't just ask for the dimensions of an
unspecified multidimensional array.
It may be multiple dimensions.

[[1,2,3],
[4,5,6,7,8,9,10]].shape

If it gave a result it would be something like:

(2,3|7)

On Fri, Feb 5, 2021 at 8:50 AM Theo van den Heuvel 
wrote:

> Hi gurus,
>
> I cannot seem to find an idiomatic way to get the dimensions of a
> multidimensional array,
> other than by looking at the size of the first row and column, with
> @m[0;*].elems and @m[*;0].elems.
> Am I missing something in the docs?
>
> Thanks,
>
> --
> Theo van den Heuvel
>
>


Re: dimensions in a multidimensional array

2021-02-05 Thread Timo Paulssen
Shaped Arrays and Native Shaped Arrays already use one contiguous blob 
to store all their data; in Shaped Arrays that's an array of pointers to 
the stored objects, in a Native Shaped Array it'll be like a big array 
of 32bit integers or whatever you have.


Regards
  - Timo

On 05/02/2021 16:48, yary wrote:
This got me interested in 
https://docs.raku.org/language/list#index-entry-Shaped_arrays 



and I find myself wanting to implement a role "Shaped" and applying it 
to List, for an immutable shaped list, whose implementation packs its 
elements for o(1) lookup... on my ever-lengthening to-do list


-y


On Fri, Feb 5, 2021 at 10:06 AM Elizabeth Mattijsen > wrote:


> On 5 Feb 2021, at 15:49, Theo van den Heuvel
mailto:vdheu...@heuvelhlt.nl>> wrote:
> I cannot seem to find an idiomatic way to get the dimensions of
a multidimensional array,
> other than by looking at the size of the first row and column,
with @m[0;*].elems and @m[*;0].elems.
> Am I missing something in the docs?

If it's a shaped multidimensional array, you can call the .shape
method

    my @a[3;3;3];
    dd @a.shape;   # (3,3,3)

If it is not, then your workaround appears the way to do it.



Re: dimensions in a multidimensional array

2021-02-05 Thread yary
This got me interested in
https://docs.raku.org/language/list#index-entry-Shaped_arrays

and I find myself wanting to implement a role "Shaped" and applying it to
List, for an immutable shaped list, whose implementation packs its elements
for o(1) lookup... on my ever-lengthening to-do list

-y


On Fri, Feb 5, 2021 at 10:06 AM Elizabeth Mattijsen  wrote:

> > On 5 Feb 2021, at 15:49, Theo van den Heuvel 
> wrote:
> > I cannot seem to find an idiomatic way to get the dimensions of a
> multidimensional array,
> > other than by looking at the size of the first row and column, with
> @m[0;*].elems and @m[*;0].elems.
> > Am I missing something in the docs?
>
> If it's a shaped multidimensional array, you can call the .shape method
>
> my @a[3;3;3];
> dd @a.shape;   # (3,3,3)
>
> If it is not, then your workaround appears the way to do it.


dimensions in a multidimensional array

2021-02-05 Thread Theo van den Heuvel

Hi gurus,

I cannot seem to find an idiomatic way to get the dimensions of a 
multidimensional array,
other than by looking at the size of the first row and column, with 
@m[0;*].elems and @m[*;0].elems.

Am I missing something in the docs?

Thanks,

--
Theo van den Heuvel