## #2190 Problems with fast arrays

closed
nobody
5
2011-04-23
2011-04-22
No

1. make_array(hashed) does not work
We dot not get a hashed array. But we write values in a structure
returned by make_array.

(%i1) a:make_array(hashed,1);
(%o1) {Array: #(NIL NIL \$HASHED NIL NIL G968)}
(%i2) a[0]:0\$ a[1]:1\$ a[2]:2\$ a[3]:3\$ a[4]:4\$ a[5]:5\$

(%i8) a;
(%o8) {Array: #(0 1 2 3 4 5)}
(%i9) a[6]:6;

Maxima encountered a Lisp error:

Index 6 out of bounds for (SIMPLE-VECTOR 6), should be nonnegative and
<6.

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.

This is the correct behavior. The hash-table works as expected.

(%i1) a:make_array(hashed);
(%o1) #<HASH-TABLE :TEST EQUAL :COUNT 1 {C6FA0F9}>

(%i2) a[100]:100;
(%o2) 100

(%i3) a[x]:sin(x);
(%o3) sin(x)

(%i4) a[x*y]:x^2+y;
(%o4) y+x^2

(%i5) arrayinfo(a);
(%o5) [hash_table,1,100,x,x*y]

(%i6) listarray(a);
(%o6) [100,sin(x),y+x^2]

2. make_array(functional, .... ) does not work
First the check of the dimensions is not correct for the case of
arrays of type functional, but there are more problems.

Arrays of type functional allow memoizing functions, e.g.
make_array(functional, 'factorial, hashed) will store
the factorials in an array. This is an example with already
corrected code. The second call f[100000] gets the stored
value:

(%i1) f:make_array(functional, 'factorial, hashed);
(%o1) #S(MGENARRAY
:AREF NIL
:ASET NIL
:TYPE \$FUNCTIONAL
:NULL NIL
:GENERATOR MFACTORIAL
:CONTENT #<HASH-TABLE :TEST EQUAL :COUNT 1 {CBBDB51}>)
(%i2) showtime:true\$
(%i3) bfloat(f[100000]);
Evaluation took 7.5960 seconds (8.3920 elapsed) using 4.743 MB.
(%o3) 2.824229407960348b456573
(%i4) bfloat(f[100000]);
Evaluation took 0.0040 seconds (0.0030 elapsed) using 925.750 KB.
(%o4) 2.824229407960348b456573

3. listarray does not work for multidimensional arrays

(%i1) a: make_array(fixnum, 2, 2);
(%o1) {Array: #2A((0 0) (0 0))}
(%i2) arrayinfo(a);
(%o2) [declared, 2, [1, 1]]
(%i3) listarray(a);

Maxima encountered a Lisp error:

#2A((0 0) (0 0)) can't be converted to type LIST.

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.

4. array(a, ...) does not work with use_fast_arrays

Only untyped arrays are possible if the option variable
user_fast_arrays has the value true:

(%i1) array(a, 2, 2);
(%o1) #2A((NIL NIL NIL) (NIL NIL NIL) (NIL NIL NIL))
(%i2) array(a, any, 2, 2);
make_array: dimensions must be integers; found [any + 1, 3, 3]
-- an error. To debug this try: debugmode(true);

(%i3) array(a, fixnum, 2, 2);
make_array: dimensions must be integers; found [fixnum + 1, 3, 3]
-- an error. To debug this try: debugmode(true);

(%i4) array(a, hashed);
make_array: dimensions must be integers; found [hashed + 1]
-- an error. To debug this try: debugmode(true);

With the corrected code we get the expected behavior:

(%i1) array(a, 2, 2);
(%o1) #2A((NIL NIL NIL) (NIL NIL NIL) (NIL NIL NIL))
(%i2) array(a, any, 2, 2);
(%o2) #2A((NIL NIL NIL) (NIL NIL NIL) (NIL NIL NIL))
(%i3) array(a, fixnum, 2, 2);
(%o3) #2A((0 0 0) (0 0 0) (0 0 0))
(%i4) array(a, flonum, 2, 2);
(%o4) #2A((0.0 0.0 0.0) (0.0 0.0 0.0) (0.0 0.0 0.0))
(%i5) array(a, hashed);
(%o5) #<HASH-TABLE :TEST EQUAL :COUNT 1 {C6DA0F9}>

Dieter Kaiser

## Discussion

• Dieter Kaiser - 2011-04-23

The problems of this bug report have been fixed in the following commits:

Closing this bug report as fixed.
Dieter Kaiser

• Dieter Kaiser - 2011-04-23
• status: open --> closed