pdlcore.c (PDL-2.083) | : | pdlcore.c (PDL-2.084) | ||
---|---|---|---|---|
skipping to change at line 655 | skipping to change at line 655 | |||
dest_data[i] = undefval; \ | dest_data[i] = undefval; \ | |||
} \ | } \ | |||
/* pad out, in the innermost dimension */ \ | /* pad out, in the innermost dimension */ \ | |||
if( !oob ) { \ | if( !oob ) { \ | |||
undef_count += dest_dims[0]-dest_off-i; \ | undef_count += dest_dims[0]-dest_off-i; \ | |||
for(; i< dest_dims[0]-dest_off; i++) dest_data[i] = undefval; \ | for(; i< dest_dims[0]-dest_off; i++) dest_data[i] = undefval; \ | |||
} | } | |||
#define PDL_KLUDGE_COPY_X(X, datatype_out, ctype_out, ppsym_out, ...) \ | #define PDL_KLUDGE_COPY_X(X, datatype_out, ctype_out, ppsym_out, ...) \ | |||
PDL_Indx pdl_kludge_copy_ ## ppsym_out(PDL_Indx dest_off, /* Offset into the des t data array */ \ | PDL_Indx pdl_kludge_copy_ ## ppsym_out(PDL_Indx dest_off, /* Offset into the des t data array */ \ | |||
ctype_out* dest_data, /* Data pointer in the dest da | ctype_out* dest_data, /* Data pointer in the dest data array */ \ | |||
ta array */ \ | PDL_Indx* dest_dims,/* Pointer to the dimlist for the dest pdl */ \ | |||
PDL_Indx* dest_dims,/* Pointer to the dimlist for the | PDL_Indx ndims, /* Number of dimensions in the dest pdl */ \ | |||
dest pdl */ \ | int level, /* Recursion level */ \ | |||
PDL_Indx ndims, /* Number of dimensions in the des | PDL_Indx stride, /* Stride through memory for the current dim */ \ | |||
t pdl */ \ | pdl* source_pdl, /* pointer to the source pdl */ \ | |||
int level, /* Recursion level */ \ | int plevel, /* level within the source pdl */ \ | |||
PDL_Indx stride, /* Stride through memory for the c | void* source_data, /* Data pointer in the source pdl */ \ | |||
urrent dim */ \ | ctype_out undefval, /* undefval for the dest pdl */ \ | |||
pdl* source_pdl, /* pointer to the source pdl */ \ | pdl* dest_pdl /* pointer to the dest pdl */ \ | |||
int plevel, /* level within the source pdl */ | ) { \ | |||
\ | ||||
void* source_data, /* Data pointer in the source pdl | ||||
*/ \ | ||||
ctype_out undefval, /* undefval for the dest pdl */ | ||||
\ | ||||
pdl* dest_pdl /* pointer to the dest pdl */ \ | ||||
) { \ | ||||
PDL_Indx i; \ | PDL_Indx i; \ | |||
PDL_Indx undef_count = 0; \ | PDL_Indx undef_count = 0; \ | |||
/* Can't copy into a level deeper than the number of dims in the output PDL */ \ | /* Can't copy into a level deeper than the number of dims in the output PDL */ \ | |||
if(level > ndims ) { \ | if(level > ndims ) { \ | |||
fprintf(stderr,"pdl_kludge_copy: level=%d; ndims=%"IND_FLAG"\n",level,ndims) ; \ | fprintf(stderr,"pdl_kludge_copy: level=%d; ndims=%"IND_FLAG"\n",level,ndims) ; \ | |||
croak("Internal error - please submit a bug report at https://github.com/PDL Porters/pdl/issues:\n pdl_kludge_copy: Assertion failed; ndims-1-level (%"IND_F LAG") < 0!.",ndims-1-level); \ | croak("Internal error - please submit a bug report at https://github.com/PDL Porters/pdl/issues:\n pdl_kludge_copy: Assertion failed; ndims-1-level (%"IND_F LAG") < 0!.",ndims-1-level); \ | |||
} \ | } \ | |||
if(level >= ndims - 1) { \ | if(level >= ndims - 1) { \ | |||
/* We are in as far as we can go in the destination PDL, so direct copying i s in order. */ \ | /* We are in as far as we can go in the destination PDL, so direct copying i s in order. */ \ | |||
int pdldim = source_pdl->ndims - 1 - plevel; /* which dim are we working in the source PDL? */ \ | int pdldim = source_pdl->ndims - 1 - plevel; /* which dim are we working in the source PDL? */ \ | |||
skipping to change at line 704 | skipping to change at line 704 | |||
char found_bad = 0; \ | char found_bad = 0; \ | |||
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL_, source_pdl->datatype, X, croak("Not a known data type code=%d", source_pdl->datatype)) \ | PDL_GENERICSWITCH(PDL_TYPELIST2_ALL_, source_pdl->datatype, X, croak("Not a known data type code=%d", source_pdl->datatype)) \ | |||
return undef_count; \ | return undef_count; \ | |||
} \ | } \ | |||
/* If we are here, we are not at the bottom level yet. So walk \ | /* If we are here, we are not at the bottom level yet. So walk \ | |||
* across this dim and handle copying one dim deeper via recursion. \ | * across this dim and handle copying one dim deeper via recursion. \ | |||
* The loop is placed in a convenience block so we can define the \ | * The loop is placed in a convenience block so we can define the \ | |||
* dimensional boundscheck flag -- that avoids having to evaluate the complex \ | * dimensional boundscheck flag -- that avoids having to evaluate the complex \ | |||
* ternary expression for every loop iteration. \ | * ternary expression for every loop iteration. \ | |||
*/ \ | */ \ | |||
{ \ | PDL_Indx limit = \ | |||
PDL_Indx limit = ( \ | (plevel >= 0 && \ | |||
(plevel >= 0 && \ | (source_pdl->ndims - 1 - plevel >= 0) \ | |||
(source_pdl->ndims - 1 - plevel >= 0) \ | ) \ | |||
) \ | ? (source_pdl->dims[ source_pdl->ndims-1-plevel ]) \ | |||
? (source_pdl->dims[ source_pdl->ndims-1-plevel ]) \ | : 1; \ | |||
: 1 \ | for(i=0; i < limit ; i++) \ | |||
); \ | undef_count += pdl_kludge_copy_ ## ppsym_out(0, dest_data + stride * i, \ | |||
for(i=0; i < limit ; i++) { \ | dest_dims, \ | |||
undef_count += pdl_kludge_copy_ ## ppsym_out(0, dest_data + stride * i | ndims, \ | |||
, \ | level+1, \ | |||
dest_dims, \ | stride / ((dest_dims[ndims-2-level]) ? (dest_dims[ndims-2-level]) : 1), \ | |||
ndims, \ | source_pdl, \ | |||
level+1, \ | plevel+1, \ | |||
stride / ((dest_dims[ndims-2-leve | ((PDL_Byte *) source_data) + source_pdl->dimincs[source_pdl->ndims-1-pleve | |||
l]) ? (dest_dims[ndims-2-level]) : 1), \ | l] * i * pdl_howbig(source_pdl->datatype), \ | |||
source_pdl, \ | undefval, \ | |||
plevel+1, \ | dest_pdl \ | |||
((PDL_Byte *) source_data) + sour | ); \ | |||
ce_pdl->dimincs[source_pdl->ndims-1-plevel] * i * pdl_howbig(source_pdl->datatyp | if(i >= dest_dims[ndims - 1 - level]) return undef_count; \ | |||
e), \ | ||||
undefval, \ | ||||
dest_pdl \ | ||||
); \ | ||||
} /* end of kludge_copy recursion loop */ \ | ||||
} /* end of recursion convenience block */ \ | ||||
/* pad the rest of this dim to zero if there are not enough elements in the so urce PDL... */ \ | /* pad the rest of this dim to zero if there are not enough elements in the so urce PDL... */ \ | |||
if(i < dest_dims[ndims - 1 - level]) { \ | int cursor, target; \ | |||
int cursor, target; \ | cursor = i * stride; \ | |||
cursor = i * stride; \ | target = dest_dims[ndims-1-level]*stride; \ | |||
target = dest_dims[ndims-1-level]*stride; \ | undef_count += target - cursor; \ | |||
undef_count += target - cursor; \ | for (; cursor < target; cursor++) dest_data[cursor] = undefval; \ | |||
for(; \ | ||||
cursor < target; \ | ||||
cursor++) { \ | ||||
dest_data[cursor] = undefval; \ | ||||
} \ | ||||
} /* end of padding IF statement */ \ | ||||
return undef_count; \ | return undef_count; \ | |||
} | } | |||
PDL_TYPELIST2_ALL(PDL_KLUDGE_COPY_X, INNERLOOP_X) | PDL_TYPELIST2_ALL(PDL_KLUDGE_COPY_X, INNERLOOP_X) | |||
#undef PDL_KLUDGE_COPY_X | #undef PDL_KLUDGE_COPY_X | |||
/* | /* | |||
* pdl_setav_<type> loads a new PDL with values from a Perl AV, another PDL, or | * pdl_setav_<type> loads a new PDL with values from a Perl AV, another PDL, or | |||
* a mix of both. Heterogeneous sizes are handled by padding the new PDL's | * a mix of both. Heterogeneous sizes are handled by padding the new PDL's | |||
* values out to size with the undefval. It is only called by pdl_setav in Core .XS, | * values out to size with the undefval. It is only called by pdl_setav in Core .XS, | |||
* via the trampoline pdl_from_array just above. pdl_from_array dispatches execu tion | * via the trampoline pdl_from_array just above. pdl_from_array dispatches execu tion | |||
End of changes. 3 change blocks. | ||||
55 lines changed or deleted | 36 lines changed or added |