NArray indexing order: row major vs column major

A

ara howard

rubyists-

am i the only one who finds the current NArray indexing order
confusing:

irb(main):001:0> na = NArray.to_na a=[[0,1,2],[3,4,5]]
=> NArray.int(3,2):
[ [ 0, 1, 2 ],
[ 3, 4, 5 ] ]
irb(main):002:0> i, j = 0, 1
=> [0, 1]

# ruby uses row major (last varies fastest) indexing
irb(main):003:0> a[j]
=> 1

# narray uses column major (first vaires fastest) indexing
irb(main):004:0> na[i, j]
=> 3

# but the storage itself appears to be row major?!
irb(main):007:0> na.to_s.unpack('i6')
=> [0, 1, 2, 3, 4, 5]


this could be really confusing if one starts thinking of narrays as
column major (due to the index ordering) and processes using for k, j,
i... instead of for i, j, k... logic, or writes an narray to disk
expecting to read it back as records of columns instead of records of
rows

it seems that the storage should at least be consistent with the
indexing, and that both should, ideally, be consistent with ruby.

perhaps i am missing something obvious here, or there is a way to
modify the runtime indexing of narray's, but i have not found anything
yet.

-a
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,812
Messages
2,569,694
Members
45,478
Latest member
dontilydondon

Latest Threads

Top