On Sunday 29 January 2012, Dima Pasechnik wrote:
> On Sunday, 29 January 2012 20:05:26 UTC+8, Willem Jan Palenstijn wrote:
> > On Sat, Jan 28, 2012 at 04:36:17PM +0100, Julien Puydt wrote:
> > > Le 29/01/2012 12:13, Willem Jan Palenstijn a �crit :
> > > >So this is the same issue with char being unsigned on your platform.
> > > >Specifically, it seems the corresponding __reduce__ function converts
> > > >a
> > 
> > char
> > 
> > > >array into a list of python ints, which has range 0-255 for you,
> > 
> > instead of the
> > 
> > > >-128-127 on x86. And the unpickle function has the opposite issue.
> > > >
> > > >I wonder how many of these are around, and if there is any general fix
> > 
> > for
> > 
> > > >them.
> > > 
> > > Well, if there is a nice inheritance graph, there's hope fixing the
> > > base class will maket the rest just go smooth.
> > > 
> > > Now, to fix the base class... If the goal is to take a "char" on one
> > > platform and turn it into a "char" on another, then it's a lost
> > > battle.
> > 
> > Which base class do you mean exactly?
> > 
> > > What are those "char" really encoding? If they are really "foo",
> > > then turning a "foo" on one platform into a "foo" on another might
> > > not be impossible!
> > 
> > In this particular case, it seems Matrix_mod2_dense's __reduce__
> > serializes its
> > data by compressing it as a black/white PNG image. So it's really just a
> > raw
> > byte stream.
> 
> and then it does (line 1750):
> 
> cdef char *buf = <char*>gdImagePngPtr(im, &size)
> data = [buf[i] for i in range(size)]
> 
> and this data goes into the pickle. No wonder it gets different on
> different platforms!

The new version of M4Ri has PNG support built in directly, but I'm not sure it 
makes things better or worse. It uses libPNG directly though.

 for(rci_t i=0; i<m; i++) {
    png_read_row(png_ptr, row, NULL);
    for(j=0; j<A->width-1; j++) {
      tmp = ((word)row[8*j+7])<<56 | ((word)row[8*j+6])<<48 \
        |   ((word)row[8*j+5])<<40 | ((word)row[8*j+4])<<32 \
        |   ((word)row[8*j+3])<<24 | ((word)row[8*j+2])<<16 \
        |   ((word)row[8*j+1])<< 8 | ((word)row[8*j+0])<< 0;
      A->rows[i][j] = ~tmp;
    }
    tmp = 0;
    switch((n/8 + ((n%8) ? 1 : 0))%8) {
    case 7: tmp |= ((word)row[8*j+7])<<56;
    case 6: tmp |= ((word)row[8*j+6])<<48; 
    case 5: tmp |= ((word)row[8*j+5])<<40;
    case 4: tmp |= ((word)row[8*j+4])<<32;
    case 3: tmp |= ((word)row[8*j+3])<<24;
    case 2: tmp |= ((word)row[8*j+2])<<16;
    case 1: tmp |= ((word)row[8*j+1])<< 8;
    case 0: tmp |= ((word)row[8*j+0])<< 0;
    };
    A->rows[i][j] |= (~tmp & bitmask_end);
  }

It's not in Sage yet, but I could cut a release if it helps.

Cheers,
Martin

--
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF
_www: http://martinralbrecht.wordpress.com/
_jab: martinralbre...@jabber.ccc.de

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to