From: <rl...@st...> - 2000-12-06 12:52:03
|
A suggestion for an easy way to fix this problem: use float instead of long. Presumably floats are always 4 bytes. Rick Paul Dubois writes: >This was a patch that I put in before making this release. If you get 17.1.1 >it won't be in there. > > [...] > >cc: Error: Src/arrayobject.c, line 79: The switch statement containing this >case label already has a case label for "8". (dupcase) > case sizeof(double): >------------^ >error: command 'cc' failed with exit status 1 >tc05:/usr/tmp/chase/Numeric-17.1.2[408] > > >int do_sliced_copy(char *dest, int *dest_strides, int *dest_dimensions, > int dest_nd, char *src, int *src_strides, > int *src_dimensions, int src_nd, int elsize, > int copies) { > int i, j; > > if (src_nd == 0 && dest_nd == 0) { > switch(elsize) { > case sizeof(char): > memset(dest, *src, copies); > break; > case sizeof(short): > for(j=copies; j; --j, dest += sizeof(short)) > *(short*)dest = *(short*)src; > break; > case sizeof(long): > for(j=copies; j; --j, dest += sizeof(int)) > *(int*)dest = *(int*)src; > break; > case sizeof(double): > for(j=copies; j; --j, dest += sizeof(double)) > *(double*)dest = *(double*)src; > break; > default: > for(j=copies; j; --j, dest += elsize) > memcpy(dest, src, elsize); > } > return 0; > } |
From: <rl...@st...> - 2000-12-06 19:27:54
|
>From ta...@rh... Wed Dec 6 13:23 EST 2000 > >I think a more portable solution is to just make it all an if statement. >I'm not comfortable with presuming that floats are always 4 bytes. I agree -- I also had the thought of changing to an if statement after I sent my mail. Much better than the switch since it can't break. >I've thrown in the int and float cases to make sure we cover every >machine that may be out there. I suspect that if float is 8 bytes then int will be too. Just char, short, float, and double should suffice. If the 4-byte version is missing it will just fall back on the default (slower but otherwise OK), and if the C compiler doesn't support shorter data items then probably the user won't be using them anyway... Rick White |
From: Travis O. <Oli...@ma...> - 2000-12-06 19:57:48
|
> I agree -- I also had the thought of changing to an if statement after > I sent my mail. Much better than the switch since it can't break. I took the liberty to change this in the CVS tree. (I haven't been very active lately and wanted to help in some way.) I haven't released a new version with the change, though. -Travis |
From: Lee T. <ta...@rh...> - 2000-12-06 18:22:32
|
I think a more portable solution is to just make it all an if statement. I'm not comfortable with presuming that floats are always 4 bytes. if (src_nd == 0 && dest_nd == 0) { if (elsize == sizeof(char)) { memset(dest, *src, copies); } else if (elsize == sizeof(short)) { for(j=copies; j; --j, dest += sizeof(short)) *(short*)dest = *(short*)src; } else if (elsize == sizeof(int)) { for(j=copies; j; --j, dest += sizeof(int)) *(int*)dest = *(int*)src; } else if (elsize == sizeof(long)) { for(j=copies; j; --j, dest += sizeof(long)) *(long*)dest = *(long*)src; } else if (elsize == sizeof(float)) { for(j=copies; j; --j, dest += sizeof(float)) *(float*)dest = *(float*)src; } else if (elsize == sizeof(double)) { for(j=copies; j; --j, dest += sizeof(double)) *(double*)dest = *(double*)src; } else { for(j=copies; j; --j, dest += elsize) memcpy(dest, src, elsize); } I've thrown in the int and float cases to make sure we cover every machine that may be out there. Lee Taylor On Wed, 6 Dec 2000 rl...@st... wrote: > A suggestion for an easy way to fix this problem: use float instead of > long. Presumably floats are always 4 bytes. > Rick > > Paul Dubois writes: > > >This was a patch that I put in before making this release. If you get 17.1.1 > >it won't be in there. > > > > [...] > > > >cc: Error: Src/arrayobject.c, line 79: The switch statement containing this > >case label already has a case label for "8". (dupcase) > > case sizeof(double): > >------------^ > >error: command 'cc' failed with exit status 1 > >tc05:/usr/tmp/chase/Numeric-17.1.2[408] > > > > > >int do_sliced_copy(char *dest, int *dest_strides, int *dest_dimensions, > > int dest_nd, char *src, int *src_strides, > > int *src_dimensions, int src_nd, int elsize, > > int copies) { > > int i, j; > > > > if (src_nd == 0 && dest_nd == 0) { > > switch(elsize) { > > case sizeof(char): > > memset(dest, *src, copies); > > break; > > case sizeof(short): > > for(j=copies; j; --j, dest += sizeof(short)) > > *(short*)dest = *(short*)src; > > break; > > case sizeof(long): > > for(j=copies; j; --j, dest += sizeof(int)) > > *(int*)dest = *(int*)src; > > break; > > case sizeof(double): > > for(j=copies; j; --j, dest += sizeof(double)) > > *(double*)dest = *(double*)src; > > break; > > default: > > for(j=copies; j; --j, dest += elsize) > > memcpy(dest, src, elsize); > > } > > return 0; > > } > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > http://lists.sourceforge.net/mailman/listinfo/numpy-discussion > |