my comments on coloruse.py:

* record() appears to be dead code
* unpackpt and friends need an alternate set of nohrio dtypes that
have a proper shape,
then ptshape would not be required here. I've added these as
'alt-pt%d' to my local NOHRIO -- but it's looking like they may end up
as something slightly different.
* unpackpt: using array.len is alright in coloruse.py, but not
generally (as the input array may be > 1d):

def unpackpt(array, ptshape):
    """Unpacks pixels from a .pt? memmap, returning a
[frames][rows][columns] array"""
    t = np.empty( array.shape + (, 2), np.uint8).transpose()
    t[0] = array >> 4
    t[1] = array % 16
    result = t.transpose().reshape(ptshape[2], ptshape[0],
ptshape[1]).transpose(0, 2, 1)
    return result

*  It looks to me that you should be able to take out the first two
transposes, as they cancel out AFAICS.

* consider this alternative:
counts = np.zeros ((4, 256), int)
tilepixelcounts = counts[0]
backdroppixelcounts = counts[1]
spritepixelcounts = counts[2]
coluse = counts[3]

(this should make it possible to do
coluse[:] = counts[:3].sum(-2)
which is not only fast but elegant)

you could add another row for uicolors and slice to 4 rather than 3.

* Searching the RPG file should speed up a lot if you cache the defpal lumps..
   in fact the way you currently use them discards most of the
benefits of memmaps.
   Just have a 'cache' attribute on your RPGDir object, and __init__
should prefill it with the required memmaps (or self.lump()s -- same
difference). Accessing a memmap is fast, setting it up not so fast.
Because a memmap is not a copy of the disk file, but more like
'adaptively-virtual' memory, there is no reason not to memmap huge
files (currently 2gb is the limit IMO.. don't think you'll ever hit
that with OHR files :)

* you would then be able to look up large quantities of defpals even
quicker using take() and indexed array slicing, if you so desired:

  pals[pals == -1] = defpal0.take(pics[pals == -1])

* looking at your usage, I see I need to provide 'bare' versions of
some dtypes (eg defpal) so that access is not onerous -- eg
defpal0[pictureindex] should provide the value directly.

*
# therefore, a slightly more robust hack
for col in uicols.view(INT)[:uicols.dtype.field['textboxframe'][-1] / 2]:
    coluse[col] += 1

* from the commentary around the above area, it looks like you've been
doing some debugging the slow way.. I really suggest using IPython for
that kind of messing around (run 'easy_install ipython' to install.)

I can see how it's kind of a hack that got out of hand -- for
instance, that huge 'try' block :) It's still pretty cool though,
RPGDir gives me some good ideas, you've clearly got pretty good
fundamental understanding of numpy, and I'm always in favor of more
OHR utilities :)

David
_______________________________________________
Ohrrpgce mailing list
ohrrpgce@lists.motherhamster.org
http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org

Reply via email to