On Sat, Dec 24, 2016 at 5:12 PM, Mikhail V <mikhailwas@xxxxxxxxx> wrote:Probably there is more criterias here that I am not aware of
and objective arguments to prefer "FORTRAN" order, apart
from having more traditional [x,y] notation?The argument I think comes from building/slicing matrices out of (column) vectors. You see this a lot in numerical work. If the row is of pointers, you can build sparse systems that reference underlying vector without doing any copying (you can do this with row data instead, but then you need row vectors, and that would be morally wrong). This is important since building sparse systems can be very slow if you're not careful.
I still avoid FORTRAN order because it's not mathy. E.g., the matrix element "a_{0,2}" should be accessed as "a[0][2]". For an objective argument, I'll note that graphics hardware--in particular VGA/VBE hardware, which influenced latter standards, e.g. HDMI--is row-major, top-to-bottom raster order. This has been hugely influential, and is more-or-less expected today by graphics programmers. It explains everything from most windowing systems today having GUI controls at the top and left, to why GL takes padded scanlines as texture input.One way or another, at this point, changing the order in PyGame is probably a bad idea (backwards compatibility and suchlike). At the very least, it would needs to be deferred to a major update with breaking API changes.So you kind of agree, that surfarray/pixelcopy should better deal with C order?
I am curious, if it is worth proposing adding methods which do so.
I agree, one should not touch the existing API.
Now I have tested the performance one more time, namely
comparing 3 variants to copy data from array to surface:
1. buf = Dest.get_buffer()
buf.write(Src.tostring(), 0)
2. pygame.pixelcopy.array_to_surface(Dest, Src)
3. pygame.pixelcopy.array_to_surface(Dest, Src.T)
And it turned out that I was wrong about transpose being expensive.
Actually transpose itself does not add significant overhead. First time
I was testing it, I did something wrong.
For method 2. if I define order="FORTRAN" for original array,
there is no difference in comparison to 3. But if I leave default (C)
order then the performance degrades with bigger arrays(ca. 20% slower by 800x600 8bit array).So it is indeed important thing.
Most interesting that 1. method with buffer write seems to be always faster
than others, by ca. 5%. Not a big win, but still interesting...And if I try it with FORTRAN order, it becomes 2 times slower!
So I would still look forward to having methods dealing with C order,
just to avoid writing extra transposing and full compliance
with default numpy notation.Any comments or opinions about it?It would be good to know first, which of those things
people use more often and make some use case examples.
Mikhail