Randy, 

The sparse element may be explicitly merged into a sparse array:

           X =: $. 3 + i. 2 2
           0 (<1;1)} X
        0 0 | 3
        0 1 | 4
        1 0 | 5
        1 1 | 0
           
Which, you'll infer, means it can also can be calculated into X:

           6 | X
        0 0 | 3
        0 1 | 4
        1 0 | 5
        1 1 | 0

Further: remember that not all axes need be sparse.  If some axes are dense, 
the sparse element can occur naturally in those axes.  For example:

           ] X =: 4 5 {. (2;0) $. $. 3 3 $ 1
        0 | 1 1 1 0 0
        1 | 1 1 1 0 0
        2 | 1 1 1 0 0

Or, probably more to the point:

           ] X =: +/\ +\ $. 1 1 1 1
        0 | 1 2 3 4
        1 | 0 1 2 3
        2 | 0 0 1 2
        3 | 0 0 0 1

           2 $. X
        1
           
Which is to say that any operation which increases the rank of X can introduce 
0s in X. 

What all this tells you is that J will not stop you from putting 0s into your 
array, only that it'll take them out when you specifically ask it to do so.  
One way to ask it to do so is to use  $.  to turn a dense array into sparse.  
Another is to use  8&$.  whenever you suspect you've introduced 0s:

           8 $. 6 | X
        0 0 | 3
        0 1 | 4
        1 0 | 5

Please keep in mind that there is no reason to use sparse arrays if you can 
manifest the dense array in memory.  Sparse arrays are less used, and therefore 
get less attention, and therefore have more bugs in the implementation.  If you 
use them, keep that usage as simple and obvious as possible.  And, of course, 
report bugs.

-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to