Jerome Quelin wrote:

On Vendredi 29 Novembre 2002 17:18, Leopold Toetsch wrote:

Then what should I use for a 2D array?

The example (test) is an 2D array.


So, a so-called MultiArray is in fact one array, but the first n elems are the elems of the 1st line, the next n elems are the 2nd line, etc.?

Yes, the base is the plain Array class, which uses list.c. Only index calculation is done in multiarray.


Speaking of limitations, what can hold a multiarray? Only integers, only strings, only pmc, a mix of everything?

Everything a list can hold (i.e. all above, but no mix), though it would need a new class, which takes an list_type initializer. And datatypes smaller then INTVAL aren't done yet.


s. docs/pdds/pdd02_vtable2.pod and the usage of these params in
list.c /*
 * list_new_init uses these initializers:
 * 0 ... size (set initial size of list)
 * 1 ... array dimensions (multiarray)
 * 2 ... type (overriding type parameter)
 * 3 ... item_size for enum_type_sized
 * 4 ... items_per_chunk

If I understand correctly, this means that:
* P1[0] is the size of the "flat" one-dim array. So, for a 2d array supporting 25 rows and 80 columns, I should set P1[0] to 80*25, right?

Not exactly: you set P1[n] to the initializer key '0' and P1[n+1] to the initializer data = size for key #0, and that is indeed 80x25.


* P1[1] is the multidimension,

Same here: you set P[x] to 1 and P[x+1] to the dimension key. Please look again at the first test, which is an 2D array of 10x5.


* P1[2], I can't understand what does this one stand for

key #2 is one of the datatypes defined in datatypes.h.


* P1[3] is the packed key,

it happens to be P1[3] here. The dimension key is the data entry for the initializer key #1 - brrr.

You could do it like this (modulo the undefs inbetween):
new P1, .PerlArray
set P1[0], 2 # data type
findtype I0, "double" # untested
set P1[1], I0 # set data type # untested
set P1[2], 0 # size key
set P1[3], 2000 # size 80x25
set P1[6], 1 # multi dim key
set P1[7], P2 #

But we have no access functions in multiarray for an array of doubles. So again, you fill the initializer PMC with key/value pairs. Supported keys are listed above. Where in the initializer array these things are, is not important.

... telling that first dim goes from 0 to n, and 2nd dim from 0 to m. So, if I want a 2D array of 80x25, ie (0..79, 0..24), then I should issue the following:
new P2, .Key
set P2, 79 # 79 or 80?

80


* P1[4]: I can't understand this one, neither. And in fact it isn't used in t/pmc/multiarray.t

Only key #1 is used in multiarray (the multidimension key), but not the initializer is used there - it's here really user_data[1]. Please look at list.c:list_new_init().


Will there ever be such a PMC anyway?

A multiarray based on perlarray can grow (in the last dimension).
Growing in all dimensions isn't.

We will have more of these, when perl native types are done, and when we know, how to subclass pmcs. I really don't want to create a class for each type/growing policy/whatever combination.


Thanks for the explanations,
Jerome

HTH
leo



Reply via email to