NArray indexing order: row major vs column major

Discussion in 'Ruby' started by ara howard, Oct 28, 2003.

  1. ara howard

    ara howard Guest

    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
     
    ara howard, Oct 28, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C
    Replies:
    0
    Views:
    525
  2. Emin
    Replies:
    4
    Views:
    434
    Paul McGuire
    Jan 12, 2007
  3. Jef Driesen
    Replies:
    2
    Views:
    1,768
    Jef Driesen
    Jan 12, 2006
  4. Skybuck Flying
    Replies:
    30
    Views:
    1,144
    Bill Reid
    Sep 19, 2011
  5. C
    Replies:
    3
    Views:
    246
    Manohar Kamath [MVP]
    Oct 17, 2003
Loading...

Share This Page