Opened 5 months ago

Last modified 8 weeks ago

#8712 patch bug

Data.Ix missing info on row/column major indexing

Reported by: mirpa Owned by:
Priority: normal Milestone:
Component: libraries/base Version: 7.6.3
Keywords: row, column, major, Ix Cc: hvr, ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Documentation bug Difficulty: Easy (less than 1 hour)
Test Case: Blocked By:
Blocking: Related Tickets:


I've tried to use Data.Ix with Data.Vector for image manipulations and I confused column with row-major indexing.

I expected than Data.Ix.index ((0,0),(3,3)) (1,0) == 1 while it is actually equal to 4.

Documentation for Data.Ix should explicitly state that it is row-major indexing and function Data.Ix.index might be accompanied by example like: index ((0,0),(3,3)) (1,0) == 4 which should be obvious.

Attachments (1)

0001-Mention-that-Data.Ix-uses-row-major-indexing.patch (909 bytes) - added by bernalex 8 weeks ago.
Simple patch that clears up the ambiguity

Download all attachments as: .zip

Change History (6)

comment:1 Changed 5 months ago by carter

Hey Mirpa,

i warmly recommend not using Ix and Array types from base when indexing into multidimensional arrays,
juicy pixels has some decent bare bones facilities that should be easier to use

likewise, I have some work in progress apis for multi dimensional arrays i hope to release soon.

alternatively, REPA, YARR and/or ACCELERATE are all nice libs that can really shine on image related work loads.

comment:2 Changed 5 months ago by rwbarton

Um, there's absolutely nothing wrong with using Ix and Array with multidimensional arrays (though the poster is not using Array anyways).

Anyways, the Haskell 2010 (or 98) Report does specify that the Ix instance for (a,b) uses row-major order (though the wording is awkward: an instance for a built-in type is normally not called "derived"), so I agree that information should appear in the haddocks for Data.Ix somewhere. Incidentally there is a broken link at the end of which ought to point to the relevant part of the Report, but as I mentioned "Deriving Instances of Ix" is not an intuitive section to look at for the instance (a,b).

comment:3 Changed 5 months ago by mirpa

Thank you for recommendations on libraries. I've heard about Repa.

For info: I use FreeType binding to render monochromatic glyphs which gives me ByteString with rows-width-pitch. I convert ByteString into Data.Vector for some number crunching (filtering) and save it as grey scale image with JuicyPixels. Data.Ix is used to address Vector as 2D array.

It took me a while before I figured out why there is tearing and/or rotation in my image. I think that appropriate note in documentation could give a vital clue.

Changed 8 weeks ago by bernalex

Simple patch that clears up the ambiguity

comment:4 Changed 8 weeks ago by bernalex

  • Cc hvr ekmett added
  • Status changed from new to patch

comment:5 Changed 8 weeks ago by ekmett

Sounds good to me. It is better to be explicit about these things and hurts nothing to add these few words on the topic.

Note: See TracTickets for help on using tickets.