pdlapi.c (PDL-2.074) | : | pdlapi.c (PDL-2.075) | ||
---|---|---|---|---|
/* pdlapi.c - functions for manipulating pdl structs */ | /* pdlapi.c - functions for manipulating pdl structs */ | |||
#include "pdl.h" /* Data structure declarations */ | #include "pdl.h" /* Data structure declarations */ | |||
#include "pdlcore.h" /* Core declarations */ | #include "pdlcore.h" /* Core declarations */ | |||
#define VTABLE_OR_DEFAULT(trans, func, default_func) \ | #define VTABLE_OR_DEFAULT(what, trans, func, default_func) \ | |||
PDL_RETERROR(PDL_err, ((trans)->vtable->func \ | what(PDL_err, ((trans)->vtable->func \ | |||
? (trans)->vtable->func \ | ? (trans)->vtable->func \ | |||
: pdl_ ## default_func)(trans)) | : pdl_ ## default_func)(trans)) | |||
#define REDODIMS(trans) do { \ | #define REDODIMS(what, trans) do { \ | |||
if (trans->dims_redone) { \ | if (trans->dims_redone) { \ | |||
FREETRANS(trans, 0); \ | FREETRANS(trans, 0); \ | |||
if (PDL_err.error) return PDL_err; \ | if (PDL_err.error) return PDL_err; \ | |||
trans->dims_redone = 0; \ | trans->dims_redone = 0; \ | |||
} \ | } \ | |||
VTABLE_OR_DEFAULT(trans, redodims, redodims_default); \ | if ((trans)->vtable->redodims) \ | |||
what(PDL_err, pdl_dim_checks( \ | ||||
(trans)->vtable, (trans)->pdls, \ | ||||
NULL, NULL, \ | ||||
(trans)->ind_sizes, 1)); \ | ||||
what(PDL_err, ((trans)->vtable->redodims \ | ||||
? (trans)->vtable->redodims \ | ||||
: pdl_redodims_default)(trans)); \ | ||||
} while (0) | } while (0) | |||
#define READDATA(trans) VTABLE_OR_DEFAULT(trans, readdata, readdata_affine) | #define READDATA(trans) VTABLE_OR_DEFAULT(PDL_ACCUMERROR, trans, readdata, readd | |||
#define WRITEDATA(trans) VTABLE_OR_DEFAULT(trans, writebackdata, writebackdata_a | ata_affine) | |||
ffine) | #define WRITEDATA(trans) VTABLE_OR_DEFAULT(PDL_ACCUMERROR, trans, writebackdata, | |||
writebackdata_affine) | ||||
#define FREETRANS(trans, destroy) \ | #define FREETRANS(trans, destroy) \ | |||
if(trans->vtable->freetrans) { \ | if(trans->vtable->freetrans) { \ | |||
PDLDEBUG_f(printf("call freetrans\n")); \ | PDLDEBUG_f(printf("call freetrans\n")); \ | |||
PDL_err = trans->vtable->freetrans(trans, destroy); \ | PDL_err = trans->vtable->freetrans(trans, destroy); \ | |||
/* ignore error for now as need to still free rest */ \ | /* ignore error for now as need to still free rest */ \ | |||
if (destroy) PDL_TR_CLRMAGIC(trans); \ | if (destroy) PDL_CLRMAGIC(trans); \ | |||
} | } | |||
#define CHANGED(...) \ | ||||
PDL_ACCUMERROR(PDL_err, pdl_changed(__VA_ARGS__)) | ||||
extern Core PDL; | extern Core PDL; | |||
/* Make sure transformation is done */ | /* Make sure transformation is done */ | |||
pdl_error pdl__ensure_trans(pdl_trans *trans,int what,int *wd) | pdl_error pdl__ensure_trans(pdl_trans *trans,int what,int *wd) | |||
{ | { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
PDLDEBUG_f(printf("pdl__ensure_trans\n")); | PDLDEBUG_f(printf("pdl__ensure_trans %p what=%d\n", trans, what)); | |||
PDL_TR_CHKMAGIC(trans); | PDL_TR_CHKMAGIC(trans); | |||
PDL_Indx j, flag=what, par_pvaf=0; | PDL_Indx j, flag=what, par_pvaf=0; | |||
pdl_transvtable *vtable = trans->vtable; | pdl_transvtable *vtable = trans->vtable; | |||
/* Make parents physical */ | /* Make parents physical */ | |||
for(j=0; j<vtable->nparents; j++) { | for(j=0; j<vtable->nparents; j++) { | |||
if(VAFFINE_FLAG_OK(vtable->per_pdl_flags,j)) | if(VAFFINE_FLAG_OK(vtable->per_pdl_flags,j)) | |||
par_pvaf++; | par_pvaf++; | |||
PDL_RETERROR(PDL_err, pdl_make_physvaffine(trans->pdls[j])); | PDL_RETERROR(PDL_err, pdl_make_physvaffine(trans->pdls[j])); | |||
} | } | |||
for(; j<vtable->npdls; j++) { | for(; j<vtable->npdls; j++) { | |||
if(VAFFINE_FLAG_OK(vtable->per_pdl_flags,j)) | if(VAFFINE_FLAG_OK(vtable->per_pdl_flags,j)) | |||
par_pvaf++; | par_pvaf++; | |||
PDL_RETERROR(PDL_err, pdl_make_physvaffine(trans->pdls[j])); | PDL_RETERROR(PDL_err, pdl_make_physvaffine(trans->pdls[j])); | |||
flag |= trans->pdls[j]->state & PDL_ANYCHANGED; | flag |= trans->pdls[j]->state & PDL_ANYCHANGED; | |||
} | } | |||
if (flag & PDL_PARENTDIMSCHANGED) REDODIMS(trans); | if (flag & PDL_PARENTDIMSCHANGED) REDODIMS(PDL_ACCUMERROR, trans); | |||
for(j=0; j<vtable->npdls; j++) | for(j=0; j<vtable->npdls; j++) | |||
if(trans->pdls[j]->trans_parent == trans) | if(trans->pdls[j]->trans_parent == trans) | |||
PDL_ENSURE_ALLOCATED(trans->pdls[j]); | PDL_ENSURE_ALLOCATED(trans->pdls[j]); | |||
if(flag & (PDL_PARENTDATACHANGED | PDL_PARENTDIMSCHANGED)) { | if(flag & (PDL_PARENTDATACHANGED | PDL_PARENTDIMSCHANGED)) { | |||
if(par_pvaf && (trans->flags & PDL_ITRANS_ISAFFINE)) { | if(par_pvaf && (trans->flags & PDL_ITRANS_ISAFFINE)) { | |||
/* Attention: this assumes affine = p2child */ | /* Attention: this assumes affine = p2child */ | |||
/* need to signal that redodims has already been called */ | /* need to signal that redodims has already been called */ | |||
trans->pdls[1]->state &= ~PDL_PARENTDIMSCHANGED; | trans->pdls[1]->state &= ~PDL_PARENTDIMSCHANGED; | |||
PDL_RETERROR(PDL_err, pdl_make_physvaffine(trans->pdls[1] )); | PDL_RETERROR(PDL_err, pdl_make_physvaffine(trans->pdls[1] )); | |||
PDL_RETERROR(PDL_err, pdl_readdata_vaffine(trans->pdls[1] )); | PDL_ACCUMERROR(PDL_err, pdl_readdata_vaffine(trans->pdls[ 1])); | |||
} else | } else | |||
{ | ||||
READDATA(trans); | READDATA(trans); | |||
} | ||||
} | } | |||
for(j=vtable->nparents; j<vtable->npdls; j++) { | for(j=vtable->nparents; j<vtable->npdls; j++) { | |||
pdl *child = trans->pdls[j]; | pdl *child = trans->pdls[j]; | |||
child->state &= ~PDL_ANYCHANGED; | child->state &= ~PDL_ANYCHANGED; | |||
if (!wd) continue; | if (!wd) continue; | |||
char isvaffine = (PDL_VAFFOK(child) && | char isvaffine = (PDL_VAFFOK(child) && | |||
VAFFINE_FLAG_OK(vtable->per_pdl_flags,j)); | VAFFINE_FLAG_OK(vtable->per_pdl_flags,j)); | |||
if (!isvaffine || (wd[j] & PDL_PARENTDIMSCHANGED)) | if (!isvaffine || (wd[j] & PDL_PARENTDIMSCHANGED)) | |||
PDL_RETERROR(PDL_err, pdl_changed(child,wd[j],0)); | CHANGED(child,wd[j],0); | |||
if (isvaffine) | if (isvaffine) | |||
PDL_RETERROR(PDL_err, pdl_changed(child->vafftrans->from,PDL_ PARENTDATACHANGED,0)); | CHANGED(child->vafftrans->from,PDL_PARENTDATACHANGED,0); | |||
} | } | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
pdl *pdl_null() { | pdl *pdl_null() { | |||
PDL_Anyval zero = { PDL_D, {.D=0.0} }; | PDL_Anyval zero = { PDL_D, {.D=0.0} }; | |||
PDLDEBUG_f(printf("pdl_null\n")); | PDLDEBUG_f(printf("pdl_null\n")); | |||
pdl *it = pdl_pdlnew(); | pdl *it = pdl_pdlnew(); | |||
if (!it) return it; | if (!it) return it; | |||
pdl_error PDL_err = pdl_makescratchhash(it, zero); | pdl_error PDL_err = pdl_makescratchhash(it, zero); | |||
if (PDL_err.error) { pdl_destroy(it); return NULL; } | if (PDL_err.error) { pdl_destroy(it); return NULL; } | |||
return it; | return it; | |||
} | } | |||
pdl *pdl_scalar(PDL_Anyval anyval) { | pdl *pdl_scalar(PDL_Anyval anyval) { | |||
PDLDEBUG_f(printf("pdl_scalar type=%d val=", anyval.type); pdl_dump_anyva l(anyval); printf("\n");); | PDLDEBUG_f(printf("pdl_scalar type=%d val=", anyval.type); pdl_dump_anyva l(anyval); printf("\n");); | |||
pdl *it = pdl_pdlnew(); | pdl *it = pdl_pdlnew(); | |||
if (!it) return it; | if (!it) return it; | |||
pdl_error PDL_err = pdl_makescratchhash(it, anyval); | pdl_error PDL_err = pdl_makescratchhash(it, anyval); | |||
if (PDL_err.error) { pdl_destroy(it); return NULL; } | if (PDL_err.error) { pdl_destroy(it); return NULL; } | |||
it->threadids[0] = it->ndims = 0; /* 0 dims in a scalar */ | it->broadcastids[0] = it->ndims = 0; /* 0 dims in a scalar */ | |||
it->state &= ~(PDL_ALLOCATED|PDL_NOMYDIMS); /* size changed, has dims */ | it->state &= ~(PDL_ALLOCATED|PDL_NOMYDIMS); /* size changed, has dims */ | |||
it->nvals = 1; /* 1 val in a scalar */ | it->nvals = 1; /* 1 val in a scalar */ | |||
return it; | return it; | |||
} | } | |||
pdl *pdl_get_convertedpdl(pdl *old,int type) { | pdl *pdl_get_convertedpdl(pdl *old,int type) { | |||
PDLDEBUG_f(printf("pdl_get_convertedpdl\n")); | PDLDEBUG_f(printf("pdl_get_convertedpdl\n")); | |||
if(old->datatype == type) return old; | if(old->datatype == type) return old; | |||
pdl *it = pdl_null(); | pdl *it = pdl_null(); | |||
if (!it) return it; | if (!it) return it; | |||
pdl_error PDL_err = pdl_converttypei_new(old,it,type); | pdl_error PDL_err = pdl_converttypei_new(old,it,type); | |||
if (PDL_err.error) { pdl_destroy(it); return NULL; } | if (PDL_err.error) { pdl_destroy(it); return NULL; } | |||
return it; | return it; | |||
} | } | |||
pdl_error pdl_allocdata(pdl *it) { | pdl_error pdl_allocdata(pdl *it) { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
PDLDEBUG_f(printf("pdl_allocdata %p, %"IND_FLAG", %d\n",(void*)it, it->nvals, | PDLDEBUG_f(printf("pdl_allocdata %p, %"IND_FLAG", %d\n",(void*)it, it->nvals, | |||
it->datatype)); | it->datatype)); | |||
if(it->nvals < 0) | ||||
return pdl_make_error(PDL_EUSERERROR, "Tried to allocdata with %"IND_FLAG" v | ||||
alues", it->nvals); | ||||
PDL_Indx nbytes = it->nvals * pdl_howbig(it->datatype); | PDL_Indx nbytes = it->nvals * pdl_howbig(it->datatype); | |||
PDL_Indx ncurr = it->nbytes; | PDL_Indx ncurr = it->nbytes; | |||
if (ncurr == nbytes) | if (ncurr == nbytes) | |||
return PDL_err; /* Nothing to be done */ | return PDL_err; /* Nothing to be done */ | |||
if(it->state & PDL_DONTTOUCHDATA) | if(it->state & PDL_DONTTOUCHDATA) | |||
return pdl_make_error_simple(PDL_EUSERERROR, "Trying to touch data of an unt ouchable (mmapped?) pdl"); | return pdl_make_error_simple(PDL_EUSERERROR, "Trying to touch data of an unt ouchable (mmapped?) pdl"); | |||
if(it->datasv == NULL) | if(it->datasv == NULL) | |||
it->datasv = newSVpv("",0); | it->datasv = newSVpv("",0); | |||
SV* foo = it->datasv; | SV* foo = it->datasv; | |||
(void)SvGROW ( foo, nbytes ); | (void)SvGROW ( foo, nbytes ); | |||
skipping to change at line 152 | skipping to change at line 165 | |||
it->vafftrans = NULL; | it->vafftrans = NULL; | |||
it->sv = NULL; | it->sv = NULL; | |||
it->datasv = 0; | it->datasv = 0; | |||
it->data = 0; | it->data = 0; | |||
it->has_badvalue = 0; | it->has_badvalue = 0; | |||
it->state = PDL_NOMYDIMS; | it->state = PDL_NOMYDIMS; | |||
it->dims = it->def_dims; | it->dims = it->def_dims; | |||
it->nbytes = it->nvals = it->dims[0] = 0; | it->nbytes = it->nvals = it->dims[0] = 0; | |||
it->dimincs = it->def_dimincs; | it->dimincs = it->def_dimincs; | |||
it->dimincs[0] = 1; | it->dimincs[0] = 1; | |||
it->nthreadids = 1; | it->nbroadcastids = 1; | |||
it->threadids = it->def_threadids; | it->broadcastids = it->def_broadcastids; | |||
it->threadids[0] = it->ndims = 1; | it->broadcastids[0] = it->ndims = 1; | |||
PDL_Indx i; | PDL_Indx i; | |||
for(i=0; i<PDL_NCHILDREN; i++) {it->trans_children.trans[i]=NULL;} | for(i=0; i<PDL_NCHILDREN; i++) {it->trans_children.trans[i]=NULL;} | |||
it->trans_children.next = NULL; | it->trans_children.next = NULL; | |||
it->magic = 0; | it->magic = 0; | |||
it->hdrsv = 0; | it->hdrsv = 0; | |||
PDLDEBUG_f(printf("pdl_pdlnew %p (size=%zu)\n",(void*)it,sizeof(pdl))); | PDLDEBUG_f(printf("pdl_pdlnew %p (size=%zu)\n",(void*)it,sizeof(pdl))); | |||
return it; | return it; | |||
} | } | |||
void pdl_vafftrans_free(pdl *it) | void pdl_vafftrans_free(pdl *it) | |||
skipping to change at line 221 | skipping to change at line 234 | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
PDLDEBUG_f(printf("pdl__free %p\n",(void*)it)); | PDLDEBUG_f(printf("pdl__free %p\n",(void*)it)); | |||
PDL_CHKMAGIC(it); | PDL_CHKMAGIC(it); | |||
/* now check if magic is still there */ | /* now check if magic is still there */ | |||
if (pdl__ismagic(it)) { | if (pdl__ismagic(it)) { | |||
PDLDEBUG_f(printf("%p is still magic\n",(void*)it);pdl__print_magic(it)); | PDLDEBUG_f(printf("%p is still magic\n",(void*)it);pdl__print_magic(it)); | |||
} | } | |||
it->magicno = 0x42424245; | it->magicno = 0x42424245; | |||
if(it->dims != it->def_dims) free((void*)it->dims); | if(it->dims != it->def_dims) free((void*)it->dims); | |||
if(it->dimincs != it->def_dimincs) free((void*)it->dimincs); | if(it->dimincs != it->def_dimincs) free((void*)it->dimincs); | |||
if(it->threadids != it->def_threadids) free((void*)it->threadids); | if(it->broadcastids != it->def_broadcastids) free((void*)it->broadcastids) ; | |||
if(it->vafftrans) { | if(it->vafftrans) { | |||
pdl_vafftrans_free(it); | pdl_vafftrans_free(it); | |||
} | } | |||
pdl_trans_children *p1 = it->trans_children.next; | pdl_trans_children *p1 = it->trans_children.next; | |||
while(p1) { | while(p1) { | |||
pdl_trans_children *p2 = p1->next; | pdl_trans_children *p2 = p1->next; | |||
free(p1); | free(p1); | |||
p1 = p2; | p1 = p2; | |||
} | } | |||
/* Call special freeing magic, if exists */ | /* Call special freeing magic, if exists */ | |||
if(PDL_ISMAGIC(it)) { | if(PDL_ISMAGIC(it)) { | |||
pdl__call_magic(it, PDL_MAGIC_DELETEDATA); | pdl__call_magic(it, PDL_MAGIC_DELETEDATA); | |||
pdl__magic_free(it); | pdl__magic_free(it); | |||
} | } | |||
if(it->datasv) { | if(it->datasv) { | |||
PDLDEBUG_f(printf("SvREFCNT_dec datasv=%p\n",it->datasv);) | ||||
SvREFCNT_dec(it->datasv); | SvREFCNT_dec(it->datasv); | |||
it->data=0; | it->data=0; | |||
} else if(it->data) { | } else if(it->data) { | |||
pdl_pdl_warn("Warning: special data without datasv is not freed curre ntly!!"); | pdl_pdl_warn("Warning: special data without datasv is not freed curre ntly!!"); | |||
} | } | |||
if(it->hdrsv) { | if(it->hdrsv) { | |||
PDLDEBUG_f(printf("SvREFCNT_dec hdrsv=%p\n",it->hdrsv);) | ||||
SvREFCNT_dec(it->hdrsv); | SvREFCNT_dec(it->hdrsv); | |||
it->hdrsv = 0; | it->hdrsv = 0; | |||
} | } | |||
free(it); | free(it); | |||
PDLDEBUG_f(printf("pdl__free end %p\n",(void*)it)); | PDLDEBUG_f(printf("pdl__free end %p\n",(void*)it)); | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
void pdl__removechildtrans(pdl *it,pdl_trans *trans) | void pdl__removechildtrans(pdl *it,pdl_trans *trans) | |||
{ | { | |||
PDLDEBUG_f(printf("pdl__removechildtrans(%s=%p): %p\n", | PDLDEBUG_f(printf("pdl__removechildtrans(%s=%p): %p\n", | |||
trans->vtable->name, (void*)trans, (void*)(it))); | trans->vtable->name, trans, it)); | |||
PDL_Indx i; int flag = 0; | PDL_Indx i; int flag = 0; | |||
for(i=0; i<trans->vtable->nparents; i++) | for(i=0; i<trans->vtable->nparents; i++) | |||
if(trans->pdls[i] == it) | if(trans->pdls[i] == it) | |||
trans->pdls[i] = NULL; | trans->pdls[i] = NULL; | |||
PDL_DECL_CHILDLOOP(it); | PDL_DECL_CHILDLOOP(it); | |||
PDL_START_CHILDLOOP(it) | PDL_START_CHILDLOOP(it) | |||
if (PDL_CHILDLOOP_THISCHILD(it) != trans) continue; | if (PDL_CHILDLOOP_THISCHILD(it) != trans) continue; | |||
PDL_CHILDLOOP_THISCHILD(it) = NULL; | PDL_CHILDLOOP_THISCHILD(it) = NULL; | |||
flag = 1; | flag = 1; | |||
/* Can't return; might be many times (e.g. $x+$x) */ | /* Can't return; might be many times (e.g. $x+$x) */ | |||
PDL_END_CHILDLOOP(it) | PDL_END_CHILDLOOP(it) | |||
/* this might be due to a croak when performing the trans; so | /* this might be due to a croak when performing the trans; so | |||
warn only for now, otherwise we leave trans undestructed ! */ | warn only for now, otherwise we leave trans undestructed ! */ | |||
if(!flag) | if(!flag) | |||
pdl_pdl_warn("Child not found for pdl %d, %d\n",it, trans); | pdl_pdl_warn("Child not found for pdl %p, trans %p\n",it, trans); | |||
} | } | |||
void pdl__removeparenttrans(pdl *it, pdl_trans *trans, PDL_Indx nth) | void pdl__removeparenttrans(pdl *it, pdl_trans *trans, PDL_Indx nth) | |||
{ | { | |||
PDLDEBUG_f(printf("pdl__removeparenttrans(%s=%p): %p %"IND_FLAG"\n", | PDLDEBUG_f(printf("pdl__removeparenttrans(%s=%p): %p %"IND_FLAG"\n", | |||
trans->vtable->name, (void*)trans, (void*)(it), nth)); | trans->vtable->name, (void*)trans, (void*)(it), nth)); | |||
trans->pdls[nth] = 0; | trans->pdls[nth] = 0; | |||
it->trans_parent = 0; | it->trans_parent = 0; | |||
} | } | |||
pdl_error pdl_trans_finaldestroy(pdl_trans *trans) | ||||
{ | ||||
pdl_error PDL_err = {0, NULL, 0}; | ||||
PDLDEBUG_f(printf("pdl_trans_finaldestroy %p\n", trans)); | ||||
FREETRANS(trans, 1); | ||||
if(trans->vtable->flags & PDL_TRANS_DO_BROADCAST) | ||||
pdl_freebroadcaststruct(&trans->broadcast); | ||||
trans->vtable = 0; /* Make sure no-one uses this */ | ||||
PDLDEBUG_f(printf("call free\n")); | ||||
if (trans->params) free(trans->params); | ||||
free(trans->ind_sizes); | ||||
free(trans->inc_sizes); | ||||
free(trans); | ||||
return PDL_err; | ||||
} | ||||
pdl_error pdl_destroytransform(pdl_trans *trans,int ensure,int *wd) | pdl_error pdl_destroytransform(pdl_trans *trans,int ensure,int *wd) | |||
{ | { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
PDL_TR_CHKMAGIC(trans); | PDL_TR_CHKMAGIC(trans); | |||
PDL_Indx j; | PDL_Indx j; | |||
int ismutual = (trans->flags & PDL_ITRANS_DO_DATAFLOW_ANY); | int ismutual = (trans->flags & PDL_ITRANS_DO_DATAFLOW_ANY); | |||
if (!trans->vtable) | if (!trans->vtable) | |||
return pdl_make_error(PDL_EFATAL, "ZERO VTABLE DESTTRAN 0x%p %d\n ",trans,ensure); | return pdl_make_error(PDL_EFATAL, "ZERO VTABLE DESTTRAN 0x%p %d\n ",trans,ensure); | |||
if (!ismutual) for(j=0; j<trans->vtable->nparents; j++) | if (!ismutual) for(j=0; j<trans->vtable->nparents; j++) | |||
if (trans->pdls[j]->state & PDL_DATAFLOW_ANY) { ismutual=1; break; } | if (trans->pdls[j]->state & PDL_DATAFLOW_ANY) { ismutual=1; break; } | |||
PDLDEBUG_f(printf("pdl_destroytransform %s=%p (ensure=%d ismutual=%d)\n", | PDLDEBUG_f(printf("pdl_destroytransform %s=%p (ensure=%d ismutual=%d)\n", | |||
trans->vtable ? trans->vtable->name : "NULL", | trans->vtable ? trans->vtable->name : "NULL", | |||
(void*)trans,ensure,ismutual)); | (void*)trans,ensure,ismutual)); | |||
if(ensure) | if(ensure) | |||
PDL_RETERROR(PDL_err, pdl__ensure_trans(trans,ismutual ? 0 : PDL_ PARENTDIMSCHANGED,wd)); | PDL_ACCUMERROR(PDL_err, pdl__ensure_trans(trans,ismutual ? 0 : PD L_PARENTDIMSCHANGED,wd)); | |||
pdl *destbuffer[trans->vtable->npdls]; | pdl *destbuffer[trans->vtable->npdls]; | |||
int ndest = 0; | int ndest = 0; | |||
if (ismutual) { | if (ismutual) { | |||
for(j=0; j<trans->vtable->nparents; j++) { | for(j=0; j<trans->vtable->nparents; j++) { | |||
pdl *parent = trans->pdls[j]; | pdl *parent = trans->pdls[j]; | |||
if(!parent) continue; | if(!parent) continue; | |||
PDL_CHKMAGIC(parent); | PDL_CHKMAGIC(parent); | |||
pdl__removechildtrans(parent,trans); | pdl__removechildtrans(parent,trans); | |||
if(!(parent->state & PDL_DESTROYING) && !parent->sv) | if(!(parent->state & PDL_DESTROYING) && !parent->sv) | |||
destbuffer[ndest++] = parent; | destbuffer[ndest++] = parent; | |||
} | } | |||
for(; j<trans->vtable->npdls; j++) { | for(; j<trans->vtable->npdls; j++) { | |||
pdl *child = trans->pdls[j]; | pdl *child = trans->pdls[j]; | |||
PDL_CHKMAGIC(child); | PDL_CHKMAGIC(child); | |||
pdl__removeparenttrans(child,trans,j); | pdl__removeparenttrans(child,trans,j); | |||
if(child->vafftrans) pdl_vafftrans_remove(child); | if(child->vafftrans) pdl_vafftrans_remove(child); | |||
if(!(child->state & PDL_DESTROYING) && !child->sv) | if ((!(child->state & PDL_DESTROYING) && !child->sv) || | |||
(trans->vtable->par_flags[j] & PDL_PARAM_ISTEMP)) | ||||
destbuffer[ndest++] = child; | destbuffer[ndest++] = child; | |||
} | } | |||
} else { | } else { | |||
for(j=trans->vtable->nparents; j<trans->vtable->npdls; j++) { | for(j=trans->vtable->nparents; j<trans->vtable->npdls; j++) { | |||
pdl *child = trans->pdls[j]; | pdl *child = trans->pdls[j]; | |||
if(child->trans_parent == trans) | if(child->trans_parent == trans) | |||
child->trans_parent = 0; | child->trans_parent = 0; | |||
if (trans->vtable->par_flags[j] & PDL_PARAM_ISTEMP) | ||||
destbuffer[ndest++] = child; | ||||
} | } | |||
} | } | |||
FREETRANS(trans, 1); | PDL_ACCUMERROR(PDL_err, pdl_trans_finaldestroy(trans)); | |||
if(trans->vtable->flags & PDL_TRANS_DO_THREAD) | ||||
pdl_freethreadstruct(&trans->pdlthread); | ||||
trans->vtable = 0; /* Make sure no-one uses this */ | ||||
PDLDEBUG_f(printf("call free\n")); | ||||
if (trans->params) free(trans->params); | ||||
free(trans->ind_sizes); | ||||
free(trans->inc_sizes); | ||||
free(trans); | ||||
for(j=0; j<ndest; j++) | for(j=0; j<ndest; j++) | |||
PDL_RETERROR(PDL_err, pdl_destroy(destbuffer[j])); | PDL_ACCUMERROR(PDL_err, pdl_destroy(destbuffer[j])); | |||
PDLDEBUG_f(printf("pdl_destroytransform leaving %p\n", (void*)trans)); | PDLDEBUG_f(printf("pdl_destroytransform leaving %p\n", (void*)trans)); | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
/* | /* | |||
A ndarray may be | A ndarray may be | |||
- a parent of something - just ensure & destroy | - a parent of something - just ensure & destroy | |||
- a child of something - just ensure & destroy | - a child of something - just ensure & destroy | |||
- parent of two pdls which both propagate backwards - mustn't destroy. | - parent of two pdls which both propagate backwards - mustn't destroy. | |||
- both parent and child at same time, to something that propagates. | - both parent and child at same time, to something that propagates. | |||
skipping to change at line 443 | skipping to change at line 469 | |||
if (!it) return it; | if (!it) return it; | |||
it->state = 0; | it->state = 0; | |||
PDLDEBUG_f(printf("pdl_hard_copy (%p): ", src);pdl_dump(it)); | PDLDEBUG_f(printf("pdl_hard_copy (%p): ", src);pdl_dump(it)); | |||
it->datatype = src->datatype; | it->datatype = src->datatype; | |||
PDL_err = pdl_setdims(it,src->dims,src->ndims); | PDL_err = pdl_setdims(it,src->dims,src->ndims); | |||
if (PDL_err.error) { pdl_destroy(it); return NULL; } | if (PDL_err.error) { pdl_destroy(it); return NULL; } | |||
PDL_err = pdl_allocdata(it); | PDL_err = pdl_allocdata(it); | |||
if (PDL_err.error) { pdl_destroy(it); return NULL; } | if (PDL_err.error) { pdl_destroy(it); return NULL; } | |||
if(src->state & PDL_NOMYDIMS) | if(src->state & PDL_NOMYDIMS) | |||
it->state |= PDL_NOMYDIMS; | it->state |= PDL_NOMYDIMS; | |||
PDL_err = pdl_reallocthreadids(it,src->nthreadids); | PDL_err = pdl_reallocbroadcastids(it,src->nbroadcastids); | |||
if (PDL_err.error) { pdl_destroy(it); return NULL; } | if (PDL_err.error) { pdl_destroy(it); return NULL; } | |||
for(i=0; i<src->nthreadids; i++) { | for(i=0; i<src->nbroadcastids; i++) { | |||
it->threadids[i] = src->threadids[i]; | it->broadcastids[i] = src->broadcastids[i]; | |||
} | } | |||
memcpy(it->data,src->data, pdl_howbig(it->datatype) * (size_t)it->nvals); | memcpy(it->data,src->data, pdl_howbig(it->datatype) * (size_t)it->nvals); | |||
return it; | return it; | |||
} | } | |||
/* Reallocate this PDL to have ndims dimensions. */ | /* Reallocate this PDL to have ndims dimensions. */ | |||
pdl_error pdl_reallocdims(pdl *it, PDL_Indx ndims) { | pdl_error pdl_reallocdims(pdl *it, PDL_Indx ndims) { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
if (it->ndims < ndims) { /* Need to realloc for more */ | if (it->ndims < ndims) { /* Need to realloc for more */ | |||
if(it->dims != it->def_dims) free(it->dims); | if(it->dims != it->def_dims) free(it->dims); | |||
skipping to change at line 475 | skipping to change at line 501 | |||
} | } | |||
else { | else { | |||
it->dims = it->def_dims; | it->dims = it->def_dims; | |||
it->dimincs = it->def_dimincs; | it->dimincs = it->def_dimincs; | |||
} | } | |||
} | } | |||
it->ndims = ndims; | it->ndims = ndims; | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
/* Reallocate n threadids. Set the new extra ones to the end */ | /* Reallocate n broadcastids. Set the new extra ones to the end */ | |||
pdl_error pdl_reallocthreadids(pdl *it, PDL_Indx n) { | pdl_error pdl_reallocbroadcastids(pdl *it, PDL_Indx n) { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
PDL_Indx i; | PDL_Indx i; | |||
PDL_Indx *olds; PDL_Indx nold; | PDL_Indx *olds; PDL_Indx nold; | |||
if(n <= it->nthreadids) { | if(n <= it->nbroadcastids) { | |||
it->nthreadids = n; | it->nbroadcastids = n; | |||
it->threadids[n-1] = it->ndims; | it->broadcastids[n-1] = it->ndims; | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
nold = it->nthreadids; olds = it->threadids; | nold = it->nbroadcastids; olds = it->broadcastids; | |||
if(n > PDL_NTHREADIDS) { | if(n > PDL_NBROADCASTIDS) { | |||
it->threadids = malloc(sizeof(*(it->threadids))*n); | it->broadcastids = malloc(sizeof(*(it->broadcastids))*n); | |||
if (!it->threadids) return pdl_make_error_simple(PDL_EFATAL, "Out | if (!it->broadcastids) return pdl_make_error_simple(PDL_EFATAL, " | |||
of Memory\n"); | Out of Memory\n"); | |||
} else { | } else { | |||
it->threadids = it->def_threadids; | it->broadcastids = it->def_broadcastids; | |||
} | } | |||
it->nthreadids = n; | it->nbroadcastids = n; | |||
if(it->threadids != olds) { | if(it->broadcastids != olds) { | |||
for(i=0; i<nold && i<n; i++) | for(i=0; i<nold && i<n; i++) | |||
it->threadids[i] = olds[i]; | it->broadcastids[i] = olds[i]; | |||
} | } | |||
if(olds != it->def_threadids) { free(olds); } | if(olds != it->def_broadcastids) { free(olds); } | |||
for(i=nold; i<it->nthreadids; i++) { | for(i=nold; i<it->nbroadcastids; i++) { | |||
it->threadids[i] = it->ndims; | it->broadcastids[i] = it->ndims; | |||
} | } | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
/* Recalculate default increments */ | /* Recalculate default increments */ | |||
void pdl_resize_defaultincs(pdl *it) { | void pdl_resize_defaultincs(pdl *it) { | |||
PDL_Indx inc = 1, i = 0; | PDL_Indx inc = 1, i = 0; | |||
for(i=0; i<it->ndims; i++) { | for(i=0; i<it->ndims; i++) { | |||
it->dimincs[i] = inc; inc *= it->dims[i]; | it->dimincs[i] = inc; inc *= it->dims[i]; | |||
} | } | |||
skipping to change at line 531 | skipping to change at line 557 | |||
int what = (old_nvals == new_nvals) ? 0 : PDL_PARENTDATACHANGED; | int what = (old_nvals == new_nvals) ? 0 : PDL_PARENTDATACHANGED; | |||
if ((it->state & PDL_NOMYDIMS) || ndims != it->ndims) | if ((it->state & PDL_NOMYDIMS) || ndims != it->ndims) | |||
what |= PDL_PARENTDIMSCHANGED; | what |= PDL_PARENTDIMSCHANGED; | |||
else | else | |||
for (i=0; i<ndims; i++) | for (i=0; i<ndims; i++) | |||
if (dims[i] != it->dims[i]) { what |= PDL_PARENTDIMSCHANGED; break; } | if (dims[i] != it->dims[i]) { what |= PDL_PARENTDIMSCHANGED; break; } | |||
if (!what) { PDLDEBUG_f(printf("pdl_setdims NOOP\n")); return PDL_err; } | if (!what) { PDLDEBUG_f(printf("pdl_setdims NOOP\n")); return PDL_err; } | |||
PDL_RETERROR(PDL_err, pdl_reallocdims(it,ndims)); | PDL_RETERROR(PDL_err, pdl_reallocdims(it,ndims)); | |||
for(i=0; i<ndims; i++) it->dims[i] = dims[i]; | for(i=0; i<ndims; i++) it->dims[i] = dims[i]; | |||
pdl_resize_defaultincs(it); | pdl_resize_defaultincs(it); | |||
PDL_RETERROR(PDL_err, pdl_reallocthreadids(it,1)); | PDL_RETERROR(PDL_err, pdl_reallocbroadcastids(it,1)); | |||
it->threadids[0] = ndims; | it->broadcastids[0] = ndims; | |||
it->state &= ~PDL_NOMYDIMS; | it->state &= ~PDL_NOMYDIMS; | |||
PDL_RETERROR(PDL_err, pdl_changed(it,what,0)); | CHANGED(it,what,0); | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
/* This is *not* careful! */ | /* This is *not* careful! */ | |||
pdl_error pdl_setdims_careful(pdl *it) | pdl_error pdl_setdims_careful(pdl *it) | |||
{ | { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
pdl_resize_defaultincs(it); | pdl_resize_defaultincs(it); | |||
PDL_err = pdl_reallocthreadids(it,1); /* XXX For now */ | PDL_err = pdl_reallocbroadcastids(it,1); /* XXX For now */ | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
PDL_Anyval pdl_get_offs(pdl *it, PDL_Indx offs) { | PDL_Anyval pdl_get_offs(pdl *it, PDL_Indx offs) { | |||
PDL_Indx dummy1=offs+1; PDL_Indx dummy2=1; | PDL_Indx dummy1=offs+1; PDL_Indx dummy2=1; | |||
return pdl_at(it->data, it->datatype, &offs, &dummy1, &dummy2, 0, 1); | return pdl_at(it->data, it->datatype, &offs, &dummy1, &dummy2, 0, 1); | |||
} | } | |||
pdl_error pdl__addchildtrans(pdl *it,pdl_trans *trans) | pdl_error pdl__addchildtrans(pdl *it,pdl_trans *trans) | |||
{ | { | |||
skipping to change at line 596 | skipping to change at line 622 | |||
PDLDEBUG_f(printf("make_physdims %p TRANS:\n",(void*)it); | PDLDEBUG_f(printf("make_physdims %p TRANS:\n",(void*)it); | |||
pdl_dump_trans_fixspace(it->trans_parent,3)); | pdl_dump_trans_fixspace(it->trans_parent,3)); | |||
for(i=0; i<it->trans_parent->vtable->nparents; i++) { | for(i=0; i<it->trans_parent->vtable->nparents; i++) { | |||
PDL_RETERROR(PDL_err, pdl_make_physdims(it->trans_parent->pdls[i] )); | PDL_RETERROR(PDL_err, pdl_make_physdims(it->trans_parent->pdls[i] )); | |||
} | } | |||
/* doesn't this mean that all children of this trans have | /* doesn't this mean that all children of this trans have | |||
now their dims set and accordingly all those flags should | now their dims set and accordingly all those flags should | |||
be reset? Otherwise redodims will be called for them again? */ | be reset? Otherwise redodims will be called for them again? */ | |||
PDLDEBUG_f(printf("make_physdims: calling redodims %p on %p\n", | PDLDEBUG_f(printf("make_physdims: calling redodims %p on %p\n", | |||
(void*)(it->trans_parent),(void*)it)); | (void*)(it->trans_parent),(void*)it)); | |||
REDODIMS(it->trans_parent); | REDODIMS(PDL_RETERROR, it->trans_parent); | |||
/* why this one? will the old allocated data be freed correctly? */ | /* why this one? will the old allocated data be freed correctly? */ | |||
if((c & PDL_PARENTDIMSCHANGED) && (it->state & PDL_ALLOCATED)) { | if((c & PDL_PARENTDIMSCHANGED) && (it->state & PDL_ALLOCATED)) { | |||
it->state &= ~PDL_ALLOCATED; | it->state &= ~PDL_ALLOCATED; | |||
} | } | |||
PDLDEBUG_f(printf("make_physdims exit %p\n",(void*)it)); | PDLDEBUG_f(printf("make_physdims exit %p\n",(void*)it)); | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
static inline pdl_error pdl_trans_flow_checks(pdl_trans *trans, int *ret) { | static inline pdl_error pdl_trans_flow_null_checks(pdl_trans *trans, int *ret) { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
int pfflag=0; | int pfflag=0; | |||
PDL_Indx i; | PDL_Indx i; | |||
pdl_transvtable *vtable = trans->vtable; | pdl_transvtable *vtable = trans->vtable; | |||
/* Then, set our children. This is: */ | /* Then, set our children. This is: */ | |||
/* First, determine whether any of our children already have | /* First, determine whether any of our children already have | |||
* a parent, and whether they need to be updated. If this is | * a parent, and whether they need to be updated. If this is | |||
* the case, we need to do some thinking. */ | * the case, we need to do some thinking. */ | |||
for(i=0; i<vtable->nparents; i++) | for(i=0; i<vtable->nparents; i++) { | |||
if(trans->pdls[i]->state & PDL_DATAFLOW_ANY) pfflag++; | int state = trans->pdls[i]->state; | |||
if (state & PDL_NOMYDIMS) | ||||
return pdl_make_error(PDL_EUSERERROR, | ||||
"Error in %s: input parameter '%s' is null\n", | ||||
vtable->name, vtable->par_names[i] | ||||
); | ||||
if(state & PDL_DATAFLOW_ANY) pfflag++; | ||||
} | ||||
for(; i<vtable->npdls; i++) { | for(; i<vtable->npdls; i++) { | |||
/* If children are flowing, croak. It's too difficult to handle properly */ | /* If children are flowing, croak. It's too difficult to handle properly */ | |||
if(trans->pdls[i]->state & PDL_DATAFLOW_ANY) | if(trans->pdls[i]->state & PDL_DATAFLOW_ANY) | |||
return pdl_make_error_simple(PDL_EUSERERROR, "Sorry, cannot flowing famil ies right now\n"); | return pdl_make_error_simple(PDL_EUSERERROR, "Sorry, cannot flowing famil ies right now\n"); | |||
/* Same, if children have trans yet parents are flowing */ | /* Same, if children have trans yet parents are flowing */ | |||
if(trans->pdls[i]->trans_parent && pfflag) | if(trans->pdls[i]->trans_parent && pfflag) | |||
return pdl_make_error_simple(PDL_EUSERERROR, "Sorry, cannot flowing famil ies right now (2)\n"); | return pdl_make_error_simple(PDL_EUSERERROR, "Sorry, cannot flowing famil ies right now (2)\n"); | |||
} | } | |||
*ret = pfflag; | *ret = pfflag; | |||
return PDL_err; | return PDL_err; | |||
skipping to change at line 642 | skipping to change at line 675 | |||
* that would require families but is not dataflowed. | * that would require families but is not dataflowed. | |||
*/ | */ | |||
pdl_error pdl_make_trans_mutual(pdl_trans *trans) | pdl_error pdl_make_trans_mutual(pdl_trans *trans) | |||
{ | { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
PDLDEBUG_f(printf("make_trans_mutual %p\n",(void*)trans);pdl_dump_trans_fixspa ce(trans,3)); | PDLDEBUG_f(printf("make_trans_mutual %p\n",(void*)trans);pdl_dump_trans_fixspa ce(trans,3)); | |||
pdl_transvtable *vtable = trans->vtable; | pdl_transvtable *vtable = trans->vtable; | |||
PDL_Indx i, npdls=vtable->npdls, nparents=vtable->nparents; | PDL_Indx i, npdls=vtable->npdls, nparents=vtable->nparents; | |||
PDL_TR_CHKMAGIC(trans); | PDL_TR_CHKMAGIC(trans); | |||
int pfflag=0; | int pfflag=0; | |||
PDL_RETERROR(PDL_err, pdl_trans_flow_checks(trans, &pfflag)); | PDL_err = pdl_trans_flow_null_checks(trans, &pfflag); | |||
if (PDL_err.error) { | ||||
PDL_ACCUMERROR(PDL_err, pdl_trans_finaldestroy(trans)); | ||||
return PDL_err; | ||||
} | ||||
char dataflow = !!(pfflag || (trans->flags & PDL_ITRANS_DO_DATAFLOW_ANY)); | char dataflow = !!(pfflag || (trans->flags & PDL_ITRANS_DO_DATAFLOW_ANY)); | |||
if (dataflow) | if (dataflow) | |||
for(i=0; i<nparents; i++) { | for(i=0; i<nparents; i++) { | |||
pdl *parent = trans->pdls[i]; | pdl *parent = trans->pdls[i]; | |||
PDL_RETERROR(PDL_err, pdl__addchildtrans(parent,trans)); | PDL_RETERROR(PDL_err, pdl__addchildtrans(parent,trans)); | |||
if (parent->state & PDL_DATAFLOW_F) trans->flags |= PDL_ITRANS_DO_DATAFLOW _F; | if (parent->state & PDL_DATAFLOW_F) trans->flags |= PDL_ITRANS_DO_DATAFLOW _F; | |||
} | } | |||
int wd[npdls]; | int wd[npdls]; | |||
for(i=nparents; i<npdls; i++) { | for(i=nparents; i<npdls; i++) { | |||
pdl *child = trans->pdls[i]; | pdl *child = trans->pdls[i]; | |||
skipping to change at line 666 | skipping to change at line 703 | |||
/* This is because for "+=" (a = a + b) we must check for | /* This is because for "+=" (a = a + b) we must check for | |||
previous parent transformations and mutate if they exist | previous parent transformations and mutate if they exist | |||
if no dataflow. */ | if no dataflow. */ | |||
child->state |= PDL_PARENTDIMSCHANGED | PDL_PARENTDATACHANGED; | child->state |= PDL_PARENTDIMSCHANGED | PDL_PARENTDATACHANGED; | |||
} | } | |||
if (dataflow || isnull) child->trans_parent = trans; | if (dataflow || isnull) child->trans_parent = trans; | |||
if (isnull) | if (isnull) | |||
child->state = (child->state & ~PDL_NOMYDIMS) | PDL_MYDIMS_TRANS; | child->state = (child->state & ~PDL_NOMYDIMS) | PDL_MYDIMS_TRANS; | |||
} | } | |||
if (!dataflow) | if (!dataflow) | |||
PDL_RETERROR(PDL_err, pdl_destroytransform(trans,1,wd)); | PDL_ACCUMERROR(PDL_err, pdl_destroytransform(trans,1,wd)); | |||
PDLDEBUG_f(printf("make_trans_mutual exit %p\n",(void*)trans)); | PDLDEBUG_f(printf("make_trans_mutual exit %p\n",(void*)trans)); | |||
return PDL_err; | return PDL_err; | |||
} /* pdl_make_trans_mutual() */ | } /* pdl_make_trans_mutual() */ | |||
pdl_error pdl_redodims_default(pdl_trans *trans) { | pdl_error pdl_redodims_default(pdl_trans *trans) { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
PDLDEBUG_f(printf("pdl_redodims_default ");pdl_dump_trans_fixspace(trans,0)); | PDLDEBUG_f(printf("pdl_redodims_default ");pdl_dump_trans_fixspace(trans,0)); | |||
pdl_transvtable *vtable = trans->vtable; | pdl_transvtable *vtable = trans->vtable; | |||
PDL_Indx creating[vtable->npdls]; | PDL_Indx creating[vtable->npdls]; | |||
pdl **pdls = trans->pdls; | pdl **pdls = trans->pdls; | |||
PDL_Indx i; | PDL_Indx i; | |||
for (i=0; i<vtable->npdls; i++) { | for (i=0; i<vtable->npdls; i++) { | |||
short flags = vtable->par_flags[i]; | short flags = vtable->par_flags[i]; | |||
creating[i] = (flags & PDL_PARAM_ISCREAT) && | creating[i] = (flags & PDL_PARAM_ISCREAT) && | |||
PDL_DIMS_FROM_TRANS(trans,pdls[i]); | PDL_DIMS_FROM_TRANS(trans,pdls[i]); | |||
} | } | |||
PDL_RETERROR(PDL_err, pdl_initthreadstruct(2, pdls, | if (vtable->flags & PDL_TRANS_DO_BROADCAST) | |||
vtable->par_realdims, creating, vtable->npdls, vtable, | PDL_RETERROR(PDL_err, pdl_initbroadcaststruct(2, pdls, | |||
&trans->pdlthread, trans->ind_sizes, trans->inc_sizes, | vtable->par_realdims, creating, vtable->npdls, vtable, | |||
vtable->per_pdl_flags, vtable->flags & PDL_TRANS_NO_PARALLEL)); | &trans->broadcast, trans->ind_sizes, trans->inc_sizes, | |||
vtable->per_pdl_flags, vtable->flags & PDL_TRANS_NO_PARALLEL)); | ||||
pdl_hdr_childcopy(trans); | pdl_hdr_childcopy(trans); | |||
trans->dims_redone = 1; | trans->dims_redone = 1; | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
pdl_error pdl_make_physical(pdl *it) { | pdl_error pdl_make_physical(pdl *it) { | |||
pdl_error PDL_err = {0, NULL, 0}; | pdl_error PDL_err = {0, NULL, 0}; | |||
int i, vaffinepar=0; | int i, vaffinepar=0; | |||
DECL_RECURSE_GUARD; | DECL_RECURSE_GUARD; | |||
skipping to change at line 737 | skipping to change at line 775 | |||
/* check if any of the parents is a vaffine */ | /* check if any of the parents is a vaffine */ | |||
vaffinepar = vaffinepar || (it->trans_parent->pdls[i]->d ata != PDL_REPRP(it->trans_parent->pdls[i])); | vaffinepar = vaffinepar || (it->trans_parent->pdls[i]->d ata != PDL_REPRP(it->trans_parent->pdls[i])); | |||
} else | } else | |||
PDL_RETERROR(PDL_err, pdl_make_physical(it->trans_parent- >pdls[i])); | PDL_RETERROR(PDL_err, pdl_make_physical(it->trans_parent- >pdls[i])); | |||
} | } | |||
/* XXX The real question is: why do we need another call to | /* XXX The real question is: why do we need another call to | |||
* redodims if !(it->state & PDL_ALLOCATED)?????? | * redodims if !(it->state & PDL_ALLOCATED)?????? | |||
*/ | */ | |||
if((!(it->state & PDL_ALLOCATED) && vaffinepar) || | if((!(it->state & PDL_ALLOCATED) && vaffinepar) || | |||
it->state & PDL_PARENTDIMSCHANGED) | it->state & PDL_PARENTDIMSCHANGED) | |||
REDODIMS(it->trans_parent); | REDODIMS(PDL_RETERROR, it->trans_parent); | |||
if(!(it->state & PDL_ALLOCATED)) { | if(!(it->state & PDL_ALLOCATED)) { | |||
PDL_RETERROR(PDL_err, pdl_allocdata(it)); | PDL_RETERROR(PDL_err, pdl_allocdata(it)); | |||
} | } | |||
READDATA(it->trans_parent); | READDATA(it->trans_parent); | |||
it->state &= ~(PDL_ANYCHANGED | PDL_OPT_ANY_OK); | it->state &= ~(PDL_ANYCHANGED | PDL_OPT_ANY_OK); | |||
mkphys_end: | mkphys_end: | |||
PDLDEBUG_f(printf("make_physical exit %p\n",(void*)it)); | PDLDEBUG_f(printf("make_physical exit %p\n",(void*)it)); | |||
END_RECURSE_GUARD; | END_RECURSE_GUARD; | |||
return PDL_err; | return PDL_err; | |||
skipping to change at line 768 | skipping to change at line 806 | |||
if (it->state & PDL_TRACEDEBUG) pdl_dump(it); | if (it->state & PDL_TRACEDEBUG) pdl_dump(it); | |||
); | ); | |||
if(recursing) { | if(recursing) { | |||
it->state |= what; | it->state |= what; | |||
if(pdl__ismagic(it)) pdl__call_magic(it,PDL_MAGIC_MARKCHANGED); | if(pdl__ismagic(it)) pdl__call_magic(it,PDL_MAGIC_MARKCHANGED); | |||
} | } | |||
if(it->trans_parent && !recursing && (it->trans_parent->flags & PDL_ITRANS_D O_DATAFLOW_B)) { | if(it->trans_parent && !recursing && (it->trans_parent->flags & PDL_ITRANS_D O_DATAFLOW_B)) { | |||
pdl_trans *trans = it->trans_parent; | pdl_trans *trans = it->trans_parent; | |||
if((trans->flags & PDL_ITRANS_ISAFFINE) && (PDL_VAFFOK(it))) { | if((trans->flags & PDL_ITRANS_ISAFFINE) && (PDL_VAFFOK(it))) { | |||
PDLDEBUG_f(printf("pdl_changed: calling writebackdata_vaffine (pdl %p )\n",(void*)it)); | PDLDEBUG_f(printf("pdl_changed: calling writebackdata_vaffine (pdl %p )\n",(void*)it)); | |||
PDL_RETERROR(PDL_err, pdl_writebackdata_vaffine(it)); | PDL_ACCUMERROR(PDL_err, pdl_writebackdata_vaffine(it)); | |||
PDL_RETERROR(PDL_err, pdl_changed(it->vafftrans->from,what,0)); | CHANGED(it->vafftrans->from,what,0); | |||
} else { | } else { | |||
PDLDEBUG_f(printf("pdl_changed: calling writebackdata from vtable, tr iggered by pdl %p, using trans %p\n",(void*)it,(void*)(trans))); | PDLDEBUG_f(printf("pdl_changed: calling writebackdata from vtable, tr iggered by pdl %p, using trans %p\n",(void*)it,(void*)(trans))); | |||
WRITEDATA(trans); | WRITEDATA(trans); | |||
for(i=0; i<trans->vtable->nparents; i++) { | for(i=0; i<trans->vtable->nparents; i++) { | |||
pdl *pdl = trans->pdls[i]; | pdl *pdl = trans->pdls[i]; | |||
PDL_RETERROR(PDL_err, pdl_changed( | CHANGED( | |||
(VAFFINE_FLAG_OK(trans->vtable->per_pdl_flags,i) && | (VAFFINE_FLAG_OK(trans->vtable->per_pdl_flags,i) && | |||
pdl->trans_parent && | pdl->trans_parent && | |||
(pdl->trans_parent->flags & PDL_ITRANS_ISAFFINE) && | (pdl->trans_parent->flags & PDL_ITRANS_ISAFFINE) && | |||
PDL_VAFFOK(pdl)) | PDL_VAFFOK(pdl)) | |||
? pdl->vafftrans->from | ? pdl->vafftrans->from | |||
: pdl, | : pdl, | |||
what,0)); | what,0); | |||
} | } | |||
} | } | |||
} else { | } else { | |||
PDL_DECL_CHILDLOOP(it); | PDL_DECL_CHILDLOOP(it); | |||
PDL_START_CHILDLOOP(it) | PDL_START_CHILDLOOP(it) | |||
pdl_trans *trans = PDL_CHILDLOOP_THISCHILD(it); | pdl_trans *trans = PDL_CHILDLOOP_THISCHILD(it); | |||
for(j=trans->vtable->nparents; j<trans->vtable->npdls; j++) | for(j=trans->vtable->nparents; j<trans->vtable->npdls; j++) | |||
PDL_RETERROR(PDL_err, pdl_changed(trans->pdls[j],what,1)); | CHANGED(trans->pdls[j],what,1); | |||
PDL_END_CHILDLOOP(it) | PDL_END_CHILDLOOP(it) | |||
} | } | |||
PDLDEBUG_f(printf("pdl_changed: exiting for pdl %p\n",(void*)it)); | PDLDEBUG_f(printf("pdl_changed: exiting for pdl %p\n",(void*)it)); | |||
return PDL_err; | return PDL_err; | |||
} | } | |||
/* Current assumptions: only | /* Current assumptions: only | |||
* "slice" and "diagonal"-type things supported. | * "slice" and "diagonal"-type things supported. | |||
* | * | |||
* We need to do careful testing for clump-type things. | * We need to do careful testing for clump-type things. | |||
skipping to change at line 1027 | skipping to change at line 1065 | |||
PDL_TR_SETMAGIC(it); | PDL_TR_SETMAGIC(it); | |||
if (vtable->structsize) { | if (vtable->structsize) { | |||
it->params = malloc(vtable->structsize); | it->params = malloc(vtable->structsize); | |||
if (!it->params) return NULL; | if (!it->params) return NULL; | |||
memset(it->params, 0, vtable->structsize); | memset(it->params, 0, vtable->structsize); | |||
} | } | |||
it->flags = vtable->iflags; | it->flags = vtable->iflags; | |||
it->dims_redone = 0; | it->dims_redone = 0; | |||
it->bvalflag = 0; | it->bvalflag = 0; | |||
it->vtable = vtable; | it->vtable = vtable; | |||
PDL_THR_CLRMAGIC(&it->pdlthread); | PDL_CLRMAGIC(&it->broadcast); | |||
it->pdlthread.inds = 0; | it->broadcast.inds = 0; | |||
it->ind_sizes = (PDL_Indx *)malloc(sizeof(PDL_Indx) * vtable->ninds); | it->ind_sizes = (PDL_Indx *)malloc(sizeof(PDL_Indx) * vtable->ninds); | |||
if (!it->ind_sizes) return NULL; | if (!it->ind_sizes) return NULL; | |||
int i; for (i=0; i<vtable->ninds; i++) it->ind_sizes[i] = -1; | int i; for (i=0; i<vtable->ninds; i++) it->ind_sizes[i] = -1; | |||
it->inc_sizes = (PDL_Indx *)malloc(sizeof(PDL_Indx) * vtable->nind_ids); | it->inc_sizes = (PDL_Indx *)malloc(sizeof(PDL_Indx) * vtable->nind_ids); | |||
if (!it->inc_sizes) return NULL; | if (!it->inc_sizes) return NULL; | |||
for (i=0; i<vtable->nind_ids; i++) it->inc_sizes[i] = -1; | for (i=0; i<vtable->nind_ids; i++) it->inc_sizes[i] = -1; | |||
it->offs = -1; | it->offs = -1; | |||
it->incs = NULL; | it->incs = NULL; | |||
it->__datatype = PDL_INVALID; | it->__datatype = PDL_INVALID; | |||
return it; | return it; | |||
End of changes. 51 change blocks. | ||||
74 lines changed or deleted | 114 lines changed or added |