| 1 |
|
| #include "pdl.h" |
| 2 |
|
| #define PDL_IN_CORE |
| 3 |
|
| #include "pdlcore.h" |
| 4 |
|
| |
| 5 |
|
| /* also in pdlconv.c */ |
| 6 |
|
| #define PDL_ALL_GENTYPES { PDL_SB, PDL_B, PDL_S, PDL_US, PDL_L, PDL_UL, PDL_IND, PDL_ULL, PDL_LL, PDL_F, PDL_D, PDL_LD, PDL_CF, PDL_CD, PDL_CLD, -1 } |
| 7 |
|
| |
| 8 |
|
| /* delete these in CORE21 */ |
| 9 |
0 |
| pdl_error pdl_readdata_affine(pdl_trans *trans) { |
| 10 |
0 |
| return pdl_make_error(PDL_EUSERERROR, "%s: readdata called with no vtable entry", trans->vtable->name); |
| 11 |
|
| } |
| 12 |
0 |
| pdl_error pdl_writebackdata_affine(pdl_trans *trans) { |
| 13 |
0 |
| return pdl_make_error(PDL_EUSERERROR, "%s: writebackdata called with no vtable entry", trans->vtable->name); |
| 14 |
|
| } |
| 15 |
|
| |
| 16 |
|
| /* generated from: |
| 17 |
|
| pp_def( 'affine', |
| 18 |
|
| P2Child => 1, |
| 19 |
|
| AffinePriv => 1, |
| 20 |
|
| GlobalNew => 'affine_new', |
| 21 |
|
| OtherPars => 'PDL_Indx offset; PDL_Indx dims[]; PDL_Indx incs[]', |
| 22 |
|
| Comp => 'PDL_Indx nd; PDL_Indx sdims[$COMP(nd)]; |
| 23 |
|
| PDL_Indx sincs[$COMP(nd)];', |
| 24 |
|
| MakeComp => ' |
| 25 |
|
| PDL_Indx i = 0; |
| 26 |
|
| $COMP(nd) = dims_count; |
| 27 |
|
| if ($COMP(nd) < 0) |
| 28 |
|
| $CROAK("Affine: can not have negative no of dims"); |
| 29 |
|
| if ($COMP(nd) != incs_count) |
| 30 |
|
| $CROAK("Affine: number of incs does not match dims"); |
| 31 |
|
| $DOCOMPALLOC(); |
| 32 |
|
| for (i=0; i<$COMP(nd); i++) { |
| 33 |
|
| $COMP(sdims)[i] = dims[i]; |
| 34 |
|
| $COMP(sincs)[i] = incs[i]; |
| 35 |
|
| } |
| 36 |
|
| ', |
| 37 |
|
| RedoDims => ' |
| 38 |
|
| PDL_Indx i; |
| 39 |
|
| $SETNDIMS($COMP(nd)); |
| 40 |
|
| $DOPRIVALLOC(); |
| 41 |
|
| $PRIV(offs) = $COMP(offset); |
| 42 |
|
| for (i=0;i<$PDL(CHILD)->ndims;i++) { |
| 43 |
|
| $PRIV(incs)[i] = $COMP(sincs)[i]; |
| 44 |
|
| $PDL(CHILD)->dims[i] = $COMP(sdims)[i]; |
| 45 |
|
| } |
| 46 |
|
| $SETDIMS(); |
| 47 |
|
| ', |
| 48 |
|
| Doc => undef, |
| 49 |
|
| ); |
| 50 |
|
| */ |
| 51 |
|
| |
| 52 |
|
| typedef struct pdl_params_affine { |
| 53 |
|
| PDL_Indx nd; |
| 54 |
|
| PDL_Indx offset; |
| 55 |
|
| PDL_Indx *sdims; |
| 56 |
|
| PDL_Indx *sincs; |
| 57 |
|
| } pdl_params_affine; |
| 58 |
|
| |
| 59 |
201 |
| pdl_error pdl_affine_redodims(pdl_trans *trans) { |
| 60 |
201 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 61 |
201 |
| pdl_params_affine *params = trans->params; |
| 62 |
201 |
| pdl *__it = trans->pdls[1]; |
| 63 |
201 |
| pdl_hdr_childcopy(trans); |
| 64 |
|
| PDL_Indx i; |
| 65 |
201 |
▶ | PDL_RETERROR(PDL_err, pdl_reallocdims(__it, params->nd)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, pdl_reallocdims(__it, params->nd)); |
0 |
201 |
201 |
|
| 66 |
201 |
| trans->incs = malloc(sizeof(*trans->incs) * trans->pdls[1]->ndims); |
| 67 |
201 |
▶ | if (!trans->incs) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!trans->incs) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
0 |
201 |
201 |
|
| 68 |
201 |
| trans->offs = params->offset; |
| 69 |
354 |
▶ | for (i=0;i<trans->pdls[1]->ndims;i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0;i<trans->pdls[1]->ndims;i++) { |
153 |
201 |
354 |
|
| 70 |
153 |
| trans->incs[i] = params->sincs[i]; |
| 71 |
153 |
| trans->pdls[1]->dims[i] = params->sdims[i]; |
| 72 |
|
| } |
| 73 |
201 |
▶ | PDL_RETERROR(PDL_err, pdl_setdims_careful(__it)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, pdl_setdims_careful(__it)); |
0 |
201 |
201 |
|
| 74 |
201 |
| trans->dims_redone = 1; |
| 75 |
201 |
| return PDL_err; |
| 76 |
|
| } |
| 77 |
|
| |
| 78 |
1219 |
| pdl_error pdl_affine_free(pdl_trans *trans, char destroy) { |
| 79 |
1219 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 80 |
1219 |
| pdl_params_affine *params = trans->params; |
| 81 |
1219 |
▶ | if (destroy) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (destroy) { |
1219 |
0 |
1219 |
|
| 82 |
1219 |
| free(params->sdims); |
| 83 |
1219 |
| free(params->sincs); |
| 84 |
|
| } |
| 85 |
1219 |
▶ | if ((trans)->dims_redone) free(trans->incs); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((trans)->dims_redone) free(trans->incs); |
201 |
1018 |
1219 |
|
| 86 |
1219 |
| return PDL_err; |
| 87 |
|
| } |
| 88 |
|
| |
| 89 |
|
| static pdl_datatypes pdl_affine_vtable_gentypes[] = PDL_ALL_GENTYPES; |
| 90 |
|
| static char pdl_affine_vtable_flags[] = { 0, 0 }; /*CORE21*/ |
| 91 |
|
| static PDL_Indx pdl_affine_vtable_realdims[] = { 0, 0 }; |
| 92 |
|
| static char *pdl_affine_vtable_parnames[] = { "PARENT","CHILD" }; |
| 93 |
|
| static short pdl_affine_vtable_parflags[] = { |
| 94 |
|
| 0, |
| 95 |
|
| PDL_PARAM_ISCREAT|PDL_PARAM_ISCREATEALWAYS|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE |
| 96 |
|
| }; |
| 97 |
|
| static pdl_datatypes pdl_affine_vtable_partypes[] = { -1, -1 }; |
| 98 |
|
| static PDL_Indx pdl_affine_vtable_realdims_starts[] = { 0, 0 }; |
| 99 |
|
| static PDL_Indx pdl_affine_vtable_realdims_ind_ids[] = { 0 }; |
| 100 |
|
| static char *pdl_affine_vtable_indnames[] = { "" }; |
| 101 |
|
| pdl_transvtable pdl_affine_vtable = { |
| 102 |
|
| 0, PDL_ITRANS_ISAFFINE|PDL_ITRANS_DO_DATAFLOW_ANY, pdl_affine_vtable_gentypes, 1, 2, pdl_affine_vtable_flags /*CORE21*/, |
| 103 |
|
| pdl_affine_vtable_realdims, pdl_affine_vtable_parnames, |
| 104 |
|
| pdl_affine_vtable_parflags, pdl_affine_vtable_partypes, |
| 105 |
|
| pdl_affine_vtable_realdims_starts, pdl_affine_vtable_realdims_ind_ids, 0, |
| 106 |
|
| 0, pdl_affine_vtable_indnames, |
| 107 |
|
| pdl_affine_redodims, NULL, NULL, |
| 108 |
|
| pdl_affine_free, |
| 109 |
|
| sizeof(pdl_params_affine),"affine_new" |
| 110 |
|
| }; |
| 111 |
|
| |
| 112 |
1219 |
| pdl_error pdl_affine_new(pdl *PARENT,pdl *CHILD,PDL_Indx offset,PDL_Indx *dims,PDL_Indx dims_count, PDL_Indx *incs, PDL_Indx incs_count) { |
| 113 |
1219 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 114 |
1219 |
| pdl_trans *trans = pdl_create_trans(&pdl_affine_vtable); |
| 115 |
1219 |
| pdl_params_affine *params = trans->params; |
| 116 |
1219 |
| trans->pdls[0] = PARENT; |
| 117 |
1219 |
| trans->pdls[1] = CHILD; |
| 118 |
1219 |
| pdl_type_coerce((pdl_trans *)trans); |
| 119 |
1219 |
| PARENT = trans->pdls[0]; |
| 120 |
1219 |
| CHILD = trans->pdls[1]; |
| 121 |
1219 |
| PDL_Indx i = 0; |
| 122 |
1219 |
| params->nd = dims_count; |
| 123 |
1219 |
▶ | if (params->nd < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (params->nd < 0) |
0 |
1219 |
1219 |
|
| 124 |
0 |
| return pdl_make_error_simple(PDL_EUSERERROR, "Error in affine: can not have negative no of dims"); |
| 125 |
1219 |
▶ | if (params->nd != incs_count) |
Branch: 1 branch
| Branch | True | False | Total |
| if (params->nd != incs_count) |
0 |
1219 |
1219 |
|
| 126 |
0 |
| return pdl_make_error_simple(PDL_EUSERERROR, "Error in affine: number of incs does not match dims"); |
| 127 |
1219 |
| params->sdims = malloc(sizeof(* params->sdims) * params->nd); |
| 128 |
1219 |
▶ | if (!params->sdims) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!params->sdims) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
0 |
1219 |
1219 |
|
| 129 |
1219 |
| params->sincs = malloc(sizeof(* params->sincs) * params->nd); |
| 130 |
1219 |
▶ | if (!params->sincs) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!params->sincs) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); |
0 |
1219 |
1219 |
|
| 131 |
1219 |
| params->offset = offset; |
| 132 |
2385 |
▶ | for (i=0; i<params->nd; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i<params->nd; i++) { |
1166 |
1219 |
2385 |
|
| 133 |
1166 |
| params->sdims[i] = dims[i]; |
| 134 |
1166 |
| params->sincs[i] = incs[i]; |
| 135 |
|
| } |
| 136 |
1219 |
▶ | PDL_RETERROR(PDL_err, pdl_make_trans_mutual((pdl_trans *)trans)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, pdl_make_trans_mutual((pdl_trans *)trans)); |
0 |
1219 |
1219 |
|
| 137 |
1219 |
| return PDL_err; |
| 138 |
|
| } |