| 1 |
|
| |
| 2 |
|
| #line 453 "lib/PDL/PP.pm" |
| 3 |
|
| /* |
| 4 |
|
| * THIS FILE WAS GENERATED BY PDL::PP from lib/PDL/Slices.pd! Do not modify! |
| 5 |
|
| */ |
| 6 |
|
| |
| 7 |
|
| #define PDL_FREE_CODE(trans, destroy, comp_free_code, ntpriv_free_code) \ |
| 8 |
|
| if (destroy) { \ |
| 9 |
|
| comp_free_code \ |
| 10 |
|
| } \ |
| 11 |
|
| if ((trans)->dims_redone) { \ |
| 12 |
|
| ntpriv_free_code \ |
| 13 |
|
| } |
| 14 |
|
| |
| 15 |
|
| #include "EXTERN.h" |
| 16 |
|
| #include "perl.h" |
| 17 |
|
| #include "XSUB.h" |
| 18 |
|
| #include "pdl.h" |
| 19 |
|
| #include "pdlcore.h" |
| 20 |
|
| #define PDL PDL_Slices |
| 21 |
|
| extern Core* PDL; /* Structure hold core C functions */ |
| 22 |
|
| #line 23 "lib/PDL/Slices-pp-diagonal.c" |
| 23 |
370 |
| static int cmp_pdll(const void *a_,const void *b_) { |
| 24 |
370 |
| PDL_Indx *a = (PDL_Indx *)a_; PDL_Indx *b=(PDL_Indx *)b_; |
| 25 |
370 |
▶ | if (*a>*b) return 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*a>*b) return 1; |
0 |
370 |
370 |
|
| 26 |
370 |
▶ | if (*a==*b) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*a==*b) return 0; |
1 |
369 |
370 |
|
| 27 |
369 |
| return -1; |
| 28 |
|
| } |
| 29 |
|
| |
| 30 |
|
| |
| 31 |
|
| |
| 32 |
|
| #line 1877 "lib/PDL/PP.pm" |
| 33 |
|
| typedef struct pdl_params_diagonal { |
| 34 |
|
| #line 35 "lib/PDL/Slices-pp-diagonal.c" |
| 35 |
|
| PDL_Indx *whichdims; |
| 36 |
|
| PDL_Indx whichdims_count; |
| 37 |
|
| } pdl_params_diagonal; |
| 38 |
|
| |
| 39 |
|
| |
| 40 |
|
| #line 1888 "lib/PDL/PP.pm" |
| 41 |
|
| pdl_error pdl_diagonal_redodims(pdl_trans *__privtrans) { |
| 42 |
|
| pdl_error PDL_err = {0, NULL, 0}; |
| 43 |
|
| #line 44 "lib/PDL/Slices-pp-diagonal.c" |
| 44 |
369 |
| pdl_params_diagonal *__params = __privtrans->params; (void)__params; |
| 45 |
369 |
| pdl *__it = __privtrans->pdls[1]; (void) __it; |
| 46 |
369 |
▶ | PDL->hdr_childcopy(__privtrans); __privtrans->dims_redone = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| PDL->hdr_childcopy(__privtrans); __privtrans->dims_redone = 1; |
0 |
369 |
369 |
|
| 47 |
|
| |
| 48 |
|
| #line 2434 "lib/PDL/Slices.pd" |
| 49 |
|
| if (__params->whichdims[__params->whichdims_count-1] >= __privtrans->pdls[0]->ndims) |
| 50 |
|
| return PDL->make_error(PDL_EUSERERROR, "Error in diagonal:" "last given dim out of range: %"IND_FLAG" > %"IND_FLAG,__params->whichdims[__params->whichdims_count-1],__privtrans->pdls[0]->ndims-1); |
| 51 |
|
| PDL_Indx nthp, nthc=0, nthd=0, cd = __params->whichdims[0], |
| 52 |
|
| *pdims = __privtrans->pdls[0]->dims, *cdims = __privtrans->pdls[1]->dims; |
| 53 |
|
| for (nthd = 1; nthd < __params->whichdims_count; nthd++) |
| 54 |
|
| if (pdims[__params->whichdims[nthd]] != pdims[cd]) |
| 55 |
|
| return PDL->make_error(PDL_EUSERERROR, "Error in diagonal:" "Different dims indexes %"IND_FLAG" and %"IND_FLAG": %"IND_FLAG" != %"IND_FLAG,cd,__params->whichdims[nthd],pdims[cd],pdims[__params->whichdims[nthd]]); |
| 56 |
|
| PDL_RETERROR(PDL_err, PDL->reallocdims(__it,__privtrans->pdls[0]->ndims-__params->whichdims_count+1));; |
| 57 |
|
| __privtrans->incs = malloc(sizeof(*__privtrans->incs) * __privtrans->pdls[1]->ndims); /* CType.get_malloc */ |
| 58 |
|
| ; |
| 59 |
|
| __privtrans->offs = 0; |
| 60 |
|
| for (nthd = 0, nthp = 0; nthp < __privtrans->pdls[0]->ndims; nthp++) { |
| 61 |
|
| if (!(nthd < __params->whichdims_count && nthp == __params->whichdims[nthd])) { |
| 62 |
|
| /* not a diagonalised dim, preserve */ |
| 63 |
|
| __privtrans->incs[nthc] = __privtrans->pdls[0]->dimincs[nthp]; |
| 64 |
|
| cdims[nthc] = pdims[nthp]; |
| 65 |
|
| nthc++; |
| 66 |
|
| continue; |
| 67 |
|
| } |
| 68 |
|
| if (!nthd) { |
| 69 |
|
| /* first diagonalised dim, turn into dummy */ |
| 70 |
|
| __privtrans->incs[cd] = 0; |
| 71 |
|
| cdims[cd] = pdims[cd]; |
| 72 |
|
| nthc++; |
| 73 |
|
| } |
| 74 |
|
| nthd++; /* advance pointer into whichdims */ |
| 75 |
|
| __privtrans->incs[cd] += __privtrans->pdls[0]->dimincs[nthp]; |
| 76 |
|
| } |
| 77 |
|
| PDL_RETERROR(PDL_err, PDL->setdims_careful(__it));; |
| 78 |
|
| #line 79 "lib/PDL/Slices-pp-diagonal.c" |
| 79 |
368 |
| return PDL_err; |
| 80 |
|
| } |
| 81 |
|
| |
| 82 |
|
| |
| 83 |
|
| #line 1888 "lib/PDL/PP.pm" |
| 84 |
|
| pdl_error pdl_diagonal_free(pdl_trans *__privtrans, char destroy) { |
| 85 |
|
| pdl_error PDL_err = {0, NULL, 0}; |
| 86 |
|
| #line 87 "lib/PDL/Slices-pp-diagonal.c" |
| 87 |
369 |
| pdl_params_diagonal *__params = __privtrans->params; (void)__params; |
| 88 |
369 |
| pdl *__it = __privtrans->pdls[1]; (void) __it; |
| 89 |
369 |
▶ | PDL_FREE_CODE(__privtrans, destroy, free(__params->whichdims); /* CType.get_free */ |
Branch: 2 branches
| Branch | True | False | Total |
| PDL_FREE_CODE(__privtrans, destroy, free(__params->whichdims); /* CType.get_free */ |
369 |
0 |
369 |
| PDL_FREE_CODE(__privtrans, destroy, free(__params->whichdims); /* CType.get_free */ |
369 |
0 |
369 |
|
| 90 |
|
| , free(__privtrans->incs); /* CType.get_free */ |
| 91 |
369 |
| ) return PDL_err; |
| 92 |
|
| } |
| 93 |
|
| |
| 94 |
|
| static pdl_datatypes pdl_diagonal_vtable_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 }; |
| 95 |
|
| static PDL_Indx pdl_diagonal_vtable_realdims[] = { 0, 0 }; |
| 96 |
|
| static char *pdl_diagonal_vtable_parnames[] = { "PARENT","CHILD" }; |
| 97 |
|
| static short pdl_diagonal_vtable_parflags[] = { |
| 98 |
|
| 0, |
| 99 |
|
| PDL_PARAM_ISCREAT|PDL_PARAM_ISCREATEALWAYS|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE |
| 100 |
|
| }; |
| 101 |
|
| static pdl_datatypes pdl_diagonal_vtable_partypes[] = { -1, -1 }; |
| 102 |
|
| static PDL_Indx pdl_diagonal_vtable_realdims_starts[] = { 0, 0 }; |
| 103 |
|
| static PDL_Indx pdl_diagonal_vtable_realdims_ind_ids[] = { 0 }; |
| 104 |
|
| static char *pdl_diagonal_vtable_indnames[] = { "" }; |
| 105 |
|
| pdl_transvtable pdl_diagonal_vtable = { |
| 106 |
|
| 0, PDL_ITRANS_ISAFFINE|PDL_ITRANS_DO_DATAFLOW_ANY, pdl_diagonal_vtable_gentypes, 1, 2, NULL /*CORE21*/, |
| 107 |
|
| pdl_diagonal_vtable_realdims, pdl_diagonal_vtable_parnames, |
| 108 |
|
| pdl_diagonal_vtable_parflags, pdl_diagonal_vtable_partypes, |
| 109 |
|
| pdl_diagonal_vtable_realdims_starts, pdl_diagonal_vtable_realdims_ind_ids, 0, |
| 110 |
|
| 0, pdl_diagonal_vtable_indnames, |
| 111 |
|
| pdl_diagonal_redodims, NULL, NULL, |
| 112 |
|
| pdl_diagonal_free, |
| 113 |
|
| sizeof(pdl_params_diagonal),"PDL::Slices::diagonal" |
| 114 |
|
| }; |
| 115 |
|
| |
| 116 |
|
| |
| 117 |
372 |
| pdl_error pdl_run_diagonal(pdl *PARENT,pdl *CHILD,PDL_Indx *whichdims,PDL_Indx whichdims_count) { |
| 118 |
372 |
| pdl_error PDL_err = {0, NULL, 0}; |
| 119 |
372 |
▶ | if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0}; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0}; |
0 |
372 |
372 |
|
| 120 |
372 |
| pdl_trans *__privtrans = PDL->create_trans(&pdl_diagonal_vtable); |
| 121 |
372 |
▶ | if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans"); |
0 |
372 |
372 |
|
| 122 |
372 |
| pdl_params_diagonal *__params = __privtrans->params; |
| 123 |
372 |
| __privtrans->pdls[0] = PARENT; |
| 124 |
372 |
| __privtrans->pdls[1] = CHILD; |
| 125 |
372 |
▶ | PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans)); |
0 |
372 |
372 |
|
| 126 |
372 |
| PARENT = __privtrans->pdls[0]; |
| 127 |
372 |
| CHILD = __privtrans->pdls[1]; |
| 128 |
372 |
| __params->whichdims = malloc(sizeof(*__params->whichdims) * whichdims_count); /* CType.get_malloc */ |
| 129 |
|
| |
| 130 |
372 |
▶ | if(!whichdims) {__params->whichdims=0;} /* CType.get_copy */ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!whichdims) {__params->whichdims=0;} /* CType.get_copy */ |
0 |
372 |
372 |
|
| 131 |
|
| else {int __malloc_ind_1; |
| 132 |
372 |
| for(__malloc_ind_1 = 0; |
| 133 |
1113 |
▶ | __malloc_ind_1 < whichdims_count; |
Branch: 1 branch
| Branch | True | False | Total |
| __malloc_ind_1 < whichdims_count; |
741 |
372 |
1113 |
|
| 134 |
741 |
| __malloc_ind_1 ++) { __params->whichdims[__malloc_ind_1] = whichdims[__malloc_ind_1]; }} |
| 135 |
372 |
▶ | (__params->whichdims_count) = (whichdims_count); /* CType.get_copy */ |
Branch: 1 branch
| Branch | True | False | Total |
| (__params->whichdims_count) = (whichdims_count); /* CType.get_copy */ |
1 |
371 |
372 |
|
| 136 |
|
| |
| 137 |
|
| |
| 138 |
|
| #line 2413 "lib/PDL/Slices.pd" |
| 139 |
|
| |
| 140 |
|
| if (__params->whichdims_count < 1) |
| 141 |
|
| return PDL->make_error(PDL_EUSERERROR, "Error in diagonal:" "must have at least 1 dimension"); |
| 142 |
|
| qsort(__params->whichdims, __params->whichdims_count, sizeof(PDL_Indx), cmp_pdll); |
| 143 |
|
| if (__params->whichdims[0] < 0) |
| 144 |
|
| return PDL->make_error(PDL_EUSERERROR, "Error in diagonal:" "first given dim out of range: %"IND_FLAG" < 0",__params->whichdims[0]); |
| 145 |
|
| PDL_Indx i; |
| 146 |
|
| for (i = 1; i < __params->whichdims_count; i++) { |
| 147 |
|
| if (__params->whichdims[i] == __params->whichdims[i-1]) |
| 148 |
|
| return PDL->make_error(PDL_EUSERERROR, "Error in diagonal:" "dims must be unique: both dims %"IND_FLAG" and %"IND_FLAG" were %"IND_FLAG,i-1,i,__params->whichdims[i]); |
| 149 |
|
| } |
| 150 |
|
| |
| 151 |
|
| #line 152 "lib/PDL/Slices-pp-diagonal.c" |
| 152 |
369 |
▶ | PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans)); |
Branch: 1 branch
| Branch | True | False | Total |
| PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans)); |
0 |
369 |
369 |
|
| 153 |
369 |
| return PDL_err; |
| 154 |
|
| } |