lib/PDL/Core/pdlapi.c

filter: Statementstmt 94.0% 834 / 887 Branchbran 74.5% 881 / 1182 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 82.8% 1715 / 2069 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/PDL/Slices-pp-splitdim.c ↑ Summary lib/PDL/Core/pdl.h.PL »
1 /* pdlapi.c - functions for manipulating pdl structs */
2  
3 #include "pdl.h" /* Data structure declarations */
4 #define PDL_IN_CORE
5 #include "pdlcore.h" /* Core declarations */
6  
7 extern Core PDL; /* for PDL_TYPENAME */
8  
9 #define VTABLE_OR_DEFAULT(errcall, trans, is_fwd, func) \
10 do { \
11 pdl_transvtable *vtable = (trans)->vtable; \
12 PDLDEBUG_f(printf("VTOD call " #func "(trans=%p/%s)\n", trans, vtable->name)); \
13 PDL_Indx i, istart = is_fwd ? vtable->nparents : 0, iend = is_fwd ? vtable->npdls : vtable->nparents; \
14 if (is_fwd) \
15 for (i = istart; i < iend; i++) \
16 if (trans->pdls[i]->trans_parent == trans) \
17 PDL_ENSURE_ALLOCATED(trans->pdls[i]); \
18 PDL_Indx ncheck = iend - istart + 1; \
19 PDL_BITFIELD_ENT had_badflag[PDL_BITFIELD_SIZE(ncheck)]; \
20 PDL_BITFIELD_ZEROISE(had_badflag, ncheck); \
21 for (i = istart; i < iend; i++) \
22 if ((trans)->pdls[i] && (trans)->pdls[i]->state & PDL_BADVAL) \
23 PDL_BITFIELD_SET(had_badflag, i-istart); \
24 PDLDEBUG_f(printf("had_badflag bitfield: 0b"); for (i = iend-istart; i >= 0; i--) { printf("%d", PDL_BITFIELD_ISSET(had_badflag, i)); } printf("\n");); \
25 errcall(PDL_err, (vtable->func \
26 ? vtable->func(trans) \
27 : pdl_make_error(PDL_EUSERERROR, "%s: " #func " called with no vtable entry", vtable->name))); \
28 for (i = istart; i < iend; i++) { \
29 pdl *child = (trans)->pdls[i]; \
30 PDLDEBUG_f(printf("VTOD " #func " child=%p turning off datachanged, before=", child); pdl_dump_flags_fixspace(child->state, 0, PDL_FLAGS_PDL)); \
31 if (is_fwd) child->state &= ~PDL_PARENTDATACHANGED; \
32 if (child && \
33 !!(child->state & PDL_BADVAL) != !!PDL_BITFIELD_ISSET(had_badflag, i-istart) \
34 ) \
35 pdl_propagate_badflag_dir(child, !!(child->state & PDL_BADVAL), is_fwd, 1); \
36 } \
37 } while (0)
38 #define READDATA(trans) VTABLE_OR_DEFAULT(PDL_ACCUMERROR, trans, 1, readdata)
39 #define WRITEDATA(trans) VTABLE_OR_DEFAULT(PDL_ACCUMERROR, trans, 0, writebackdata)
40  
41 #define REDODIMS(errcall, trans) do { \
42 pdl_transvtable *vtable = (trans)->vtable; \
43 if (vtable->redodims) { \
44 PDL_Indx creating[vtable->npdls]; \
45 pdl **pdls = (trans)->pdls; \
46 PDL_Indx i; \
47 for (i=0; i<vtable->npdls; i++) \
48 creating[i] = (vtable->par_flags[i] & PDL_PARAM_ISCREAT) && \
49 PDL_DIMS_FROM_TRANS(trans,pdls[i]); \
50 errcall(PDL_err, pdl_dim_checks( \
51 vtable, pdls, \
52 NULL, trans->broadcast.nimpl, creating, \
53 (trans)->ind_sizes, 1)); \
54 } \
55 if ((trans)->dims_redone) { \
56 FREETRANS(trans, 0); \
57 if (PDL_err.error) return PDL_err; \
58 (trans)->dims_redone = 0; \
59 } \
60 errcall(PDL_err, (vtable->redodims \
61 ? vtable->redodims \
62 : pdl_redodims_default)(trans)); \
63 PDL_Indx i; \
64 for (i = 0; i < vtable->ninds; i++) \
65 if (trans->ind_sizes[i] < 0) \
66 PDL_ACCUMERROR(PDL_err, pdl_make_error(PDL_EUSERERROR, \
67 "%s: RedoDims gave size < 0 for dim %s", \
68 trans->vtable->name, trans->vtable->ind_names[i])); \
69 if (PDL_err.error) errcall(PDL_err, PDL_err); \
70 for (i = vtable->nparents; i < vtable->npdls; i++) { \
71 pdl *child = (trans)->pdls[i]; \
72 PDLDEBUG_f(printf("REDODIMS child=%p turning off dimschanged, before=", child); pdl_dump_flags_fixspace(child->state, 0, PDL_FLAGS_PDL)); \
73 child->state &= ~PDL_PARENTDIMSCHANGED; \
74 } \
75 } while (0)
76 #define FREETRANS(trans, destroy) \
77 if (trans->vtable->freetrans) { \
78 PDLDEBUG_f(printf("call freetrans\n")); \
79 PDL_ACCUMERROR(PDL_err, trans->vtable->freetrans(trans, destroy)); \
80 /* ignore error for now as need to still free rest */ \
81 if (destroy) PDL_CLRMAGIC(trans); \
82 }
83 #define CHANGED(...) \
84 PDL_ACCUMERROR(PDL_err, pdl_changed(__VA_ARGS__))
85  
86 extern Core PDL;
87  
88 pdl_error pdl__make_physical_recprotect(pdl *it, int recurse_count);
89 pdl_error pdl__make_physvaffine_recprotect(pdl *it, int recurse_count);
90 /* Make sure transformation is done */
91 74677 pdl_error pdl__ensure_trans(pdl_trans *trans, int what, char inputs_only, int recurse_count)
92 {
93 74677 pdl_error PDL_err = {0, NULL, 0};
94 74677 ▶ PDLDEBUG_f(printf("pdl__ensure_trans %p what=", trans); pdl_dump_flags_fixspace(what, 0, PDL_FLAGS_PDL));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl__ensure_trans %p what=", trans); pdl_dump_flags_fixspace(what, 0, PDL_FLAGS_PDL)); 0 74677 74677
95 74677 ▶ PDL_TR_CHKMAGIC(trans);
Branch: 2 branches
BranchTrueFalseTotal
PDL_TR_CHKMAGIC(trans); 0 74677 74677
PDL_TR_CHKMAGIC(trans); 0 0 0
96 74677 pdl_transvtable *vtable = trans->vtable;
97 74677 ▶ if (trans->flags & PDL_ITRANS_ISAFFINE) {
Branch: 1 branch
BranchTrueFalseTotal
if (trans->flags & PDL_ITRANS_ISAFFINE) { 3888 70789 74677
98 3888 ▶ if (!(vtable->nparents == 1 && vtable->npdls == 2))
Branch: 2 branches
BranchTrueFalseTotal
if (!(vtable->nparents == 1 && vtable->npdls == 2)) 3888 0 3888
if (!(vtable->nparents == 1 && vtable->npdls == 2)) 0 3888 3888
99 0 return pdl_make_error_simple(PDL_EUSERERROR, "Affine trans other than 1 input 1 output");
100 3888 return pdl__make_physical_recprotect(trans->pdls[1], recurse_count+1);
101 }
102 70789 ▶ PDL_Indx j, flag=what, par_pvaf=0, j_end = inputs_only ? vtable->nparents : vtable->npdls;
Branch: 1 branch
BranchTrueFalseTotal
PDL_Indx j, flag=what, par_pvaf=0, j_end = inputs_only ? vtable->nparents : vtable->npdls; 32497 38292 70789
103 193785 ▶ for (j=0; j<j_end; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j=0; j<j_end; j++) { 122996 70789 193785
104 122996 ▶ if (vtable->par_flags[j] & PDL_PARAM_ISPHYS)
Branch: 1 branch
BranchTrueFalseTotal
if (vtable->par_flags[j] & PDL_PARAM_ISPHYS) 41448 81548 122996
105 41448 ▶ PDL_RETERROR(PDL_err, pdl__make_physical_recprotect(trans->pdls[j], recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__make_physical_recprotect(trans->pdls[j], recurse_count+1)); 0 41448 41448
106 else {
107 81548 ▶ PDL_RETERROR(PDL_err, pdl__make_physvaffine_recprotect(trans->pdls[j], recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__make_physvaffine_recprotect(trans->pdls[j], recurse_count+1)); 0 81548 81548
108 81548 ▶ if (PDL_VAFFOK(trans->pdls[j])) par_pvaf++;
Branch: 1 branch
BranchTrueFalseTotal
if (PDL_VAFFOK(trans->pdls[j])) par_pvaf++; 16071 65477 81548
109 }
110 }
111 143037 ▶ for (j=vtable->nparents; j<vtable->npdls; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (j=vtable->nparents; j<vtable->npdls; j++) 72248 70789 143037
112 72248 flag |= trans->pdls[j]->state & PDL_ANYCHANGED;
113 70789 ▶ PDLDEBUG_f(printf("pdl__ensure_trans after accum, par_pvaf=%"IND_FLAG" flag=", par_pvaf); pdl_dump_flags_fixspace(flag, 0, PDL_FLAGS_PDL));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl__ensure_trans after accum, par_pvaf=%"IND_FLAG" flag=", par_pvaf); pdl_dump_flags_fixspace(flag, 0, PDL_FLAGS_PDL)); 0 70789 70789
114 70789 ▶ if (par_pvaf || flag & PDL_PARENTDIMSCHANGED)
Branch: 2 branches
BranchTrueFalseTotal
if (par_pvaf || flag & PDL_PARENTDIMSCHANGED) 56413 14376 70789
if (par_pvaf || flag & PDL_PARENTDIMSCHANGED) 27838 28575 56413
115 138636 ▶ REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */
Branch: 20 branches
BranchTrueFalseTotal
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 12279 29935 42214
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 6766 12673 19439
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 6707 59 6766
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 6692 15 6707
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 19439 12279 31718
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 0 12279 12279
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 6487 35727 42214
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 0 6487 6487
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 0 0 0
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 0 0 0
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 0 6487 6487
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 12279 29935 42214
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 32 42182 42214
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 1 21073 21074
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 1 0 1
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 21074 42182 63256
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 1 42181 42182
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 1 0 1
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 0 43630 43630
REDODIMS(PDL_RETERROR, trans); /* CORE21 change to make_physdims_recetc */ 43630 42181 85811
116 70756 ▶ if (flag & PDL_ANYCHANGED)
Branch: 1 branch
BranchTrueFalseTotal
if (flag & PDL_ANYCHANGED) 62299 8457 70756
117 315842 ▶ READDATA(trans);
Branch: 17 branches
BranchTrueFalseTotal
READDATA(trans); 0 62299 62299
READDATA(trans); 56846 6902 63748
READDATA(trans); 48536 8310 56846
READDATA(trans); 0 48536 48536
READDATA(trans); 63748 62299 126047
READDATA(trans); 62299 62299 124598
READDATA(trans); 63748 0 63748
READDATA(trans); 2370 61378 63748
READDATA(trans); 63748 62299 126047
READDATA(trans); 0 62299 62299
READDATA(trans); 0 0 0
READDATA(trans); 62299 0 62299
READDATA(trans); 9 62290 62299
READDATA(trans); 0 63748 63748
READDATA(trans); 63748 0 63748
READDATA(trans); 238 63510 63748
READDATA(trans); 63748 62299 126047
118 70756 return PDL_err;
119 }
120  
121 0 pdl *pdl_null(void) {
122 0 ▶ PDLDEBUG_f(printf("pdl_null\n"));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_null\n")); 0 0 0
123 0 return pdl_pdlnew();
124 }
125  
126 10020 pdl *pdl_scalar(PDL_Anyval anyval) {
127 10020 ▶ PDLDEBUG_f(printf("pdl_scalar type=%d val=", anyval.type); pdl_dump_anyval(anyval); printf("\n"););
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_scalar type=%d val=", anyval.type); pdl_dump_anyval(anyval); printf("\n");); 0 10020 10020
128 10020 pdl *it = pdl_pdlnew();
129 10020 ▶ if (!it) return it;
Branch: 1 branch
BranchTrueFalseTotal
if (!it) return it; 0 10020 10020
130 10020 it->datatype = anyval.type;
131 10020 it->broadcastids[0] = it->ndims = 0; /* 0 dims in a scalar */
132 10020 pdl_resize_defaultincs(it);
133 10020 pdl_error PDL_err = pdl_allocdata(it);
134 10020 ▶ if (PDL_err.error) { pdl_destroy(it); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (PDL_err.error) { pdl_destroy(it); return NULL; } 0 10020 10020
135 10020 it->value = anyval.value;
136 10020 it->state &= ~(PDL_NOMYDIMS); /* has dims */
137 10020 return it;
138 }
139  
140 pdl_error pdl__converttypei_new_recprotect(pdl *PARENT, pdl *CHILD, pdl_datatypes totype, pdl_datatypes force_intype, int recurse_count);
141 15283 pdl_error pdl__get_convertedpdl_recprotect(pdl *old, pdl **retval, pdl_datatypes type, char switch_sense, int recurse_count) {
142 15283 pdl_error PDL_err = {0, NULL, 0};
143 15283 ▶ PDL_RECURSE_CHECK(recurse_count);
Branch: 1 branch
BranchTrueFalseTotal
PDL_RECURSE_CHECK(recurse_count); 0 15283 15283
144 15283 ▶ PDLDEBUG_f(printf("pdl_get_convertedpdl switch_sense=%d\n", (int)switch_sense));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_get_convertedpdl switch_sense=%d\n", (int)switch_sense)); 0 15283 15283
145 15283 ▶ if (old->datatype == type) { *retval = old; return PDL_err; }
Branch: 1 branch
BranchTrueFalseTotal
if (old->datatype == type) { *retval = old; return PDL_err; } 0 15283 15283
146 15283 char was_flowing = (old->state & PDL_DATAFLOW_F);
147 15283 pdl *it = pdl_pdlnew();
148 15283 ▶ if (!it) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
Branch: 1 branch
BranchTrueFalseTotal
if (!it) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); 0 15283 15283
149 15283 ▶ if (switch_sense) {
Branch: 1 branch
BranchTrueFalseTotal
if (switch_sense) { 22 15261 15283
150 22 PDL_err = pdl__converttypei_new_recprotect(it, old, old->datatype, type, recurse_count + 1);
151 22 ▶ if (PDL_err.error) { pdl_destroy(it); return PDL_err; }
Branch: 1 branch
BranchTrueFalseTotal
if (PDL_err.error) { pdl_destroy(it); return PDL_err; } 0 22 22
152 22 PDL_err = pdl_setdims(it, old->dims, old->ndims);
153 22 ▶ if (!PDL_err.error && switch_sense > 1 && old->data) { /* NULL data = unallocated "zeroes" */
Branch: 3 branches
BranchTrueFalseTotal
if (!PDL_err.error && switch_sense > 1 && old->data) { /* NULL data = unallocated "zeroes" */ 22 0 22
if (!PDL_err.error && switch_sense > 1 && old->data) { /* NULL data = unallocated "zeroes" */ 12 10 22
if (!PDL_err.error && switch_sense > 1 && old->data) { /* NULL data = unallocated "zeroes" */ 12 0 12
154 12 ▶ PDLDEBUG_f(printf("pdl_get_convertedpdl back-pump because inplace\n"));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_get_convertedpdl back-pump because inplace\n")); 0 12 12
155 12 PDL_err = pdl__make_physical_recprotect(it, recurse_count + 1);
156 48 ▶ if (!PDL_err.error) WRITEDATA(old->trans_parent);
Branch: 14 branches
BranchTrueFalseTotal
if (!PDL_err.error) WRITEDATA(old->trans_parent); 12 0 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 0 12 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 12 12 24
if (!PDL_err.error) WRITEDATA(old->trans_parent); 12 0 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 0 12 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 12 12 24
if (!PDL_err.error) WRITEDATA(old->trans_parent); 0 12 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 0 0 0
if (!PDL_err.error) WRITEDATA(old->trans_parent); 12 0 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 0 12 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 0 12 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 12 0 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 0 12 12
if (!PDL_err.error) WRITEDATA(old->trans_parent); 12 12 24
157 }
158 } else
159 15261 PDL_err = pdl__converttypei_new_recprotect(old, it, type, old->datatype, recurse_count + 1);
160 15283 ▶ if (PDL_err.error) { pdl_destroy(it); return PDL_err; }
Branch: 1 branch
BranchTrueFalseTotal
if (PDL_err.error) { pdl_destroy(it); return PDL_err; } 0 15283 15283
161 15283 ▶ if (was_flowing)
Branch: 1 branch
BranchTrueFalseTotal
if (was_flowing) 5 15278 15283
162 5 it->state |= PDL_DATAFLOW_F;
163 15283 *retval = it;
164 15283 return PDL_err;
165 }
166 381 pdl *pdl_get_convertedpdl(pdl *old, pdl_datatypes type) {
167 pdl *retval;
168 381 pdl_error PDL_err = pdl__get_convertedpdl_recprotect(old, &retval, type, 0, 0);
169 381 ▶ return PDL_err.error ? NULL : retval;
Branch: 1 branch
BranchTrueFalseTotal
return PDL_err.error ? NULL : retval; 381 0 381
170 }
171  
172 99988 pdl_error pdl_allocdata(pdl *it) {
173 99988 pdl_error PDL_err = {0, NULL, 0};
174 99988 ▶ PDLDEBUG_f(printf("pdl_allocdata %p, %"IND_FLAG", %d\n",it, it->nvals,
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_allocdata %p, %"IND_FLAG", %d\n",it, it->nvals, 0 99988 99988
175 it->datatype));
176 99988 ▶ if (it->nvals < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (it->nvals < 0) 0 99988 99988
177 0 return pdl_make_error(PDL_EUSERERROR, "Tried to allocdata with %"IND_FLAG" values", it->nvals);
178 99988 PDL_Indx nbytes = it->nvals * pdl_howbig(it->datatype);
179 99988 PDL_Indx ncurr = it->nbytes;
180 99988 ▶ if (ncurr == nbytes)
Branch: 1 branch
BranchTrueFalseTotal
if (ncurr == nbytes) 18023 81965 99988
181 18023 return PDL_err; /* Nothing to be done */
182 81965 ▶ if (it->state & PDL_DONTTOUCHDATA)
Branch: 1 branch
BranchTrueFalseTotal
if (it->state & PDL_DONTTOUCHDATA) 1 81964 81965
183 1 return pdl_make_error_simple(PDL_EUSERERROR, "Trying to touch data of an untouchable (mmapped?) pdl");
184 81964 char was_useheap = (ncurr > sizeof(it->value)),
185 81964 will_useheap = (nbytes > sizeof(it->value));
186 81964 ▶ if (!was_useheap && !will_useheap) {
Branch: 2 branches
BranchTrueFalseTotal
if (!was_useheap && !will_useheap) { 81959 5 81964
if (!was_useheap && !will_useheap) { 67091 14868 81959
187 67091 it->data = &it->value;
188 14873 ▶ } else if (!will_useheap) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (!will_useheap) { 4 14869 14873
189 /* was heap, now not */
190 4 void *data_old = it->data;
191 4 memmove(it->data = &it->value, data_old, PDLMIN(ncurr, nbytes));
192 4 SvREFCNT_dec((SV*)it->datasv);
193 4 it->datasv = NULL;
194 } else {
195 /* now change to be heap */
196 14869 ▶ if (it->datasv == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (it->datasv == NULL) 14868 1 14869
197 14868 it->datasv = newSVpvn("", 0);
198 14869 ▶ (void)SvGROW((SV*)it->datasv, nbytes);
Branch: 2 branches
BranchTrueFalseTotal
(void)SvGROW((SV*)it->datasv, nbytes); 14869 0 14869
(void)SvGROW((SV*)it->datasv, nbytes); 14869 0 14869
199 14869 SvCUR_set((SV*)it->datasv, nbytes);
200 14869 ▶ if (it->data && !was_useheap)
Branch: 2 branches
BranchTrueFalseTotal
if (it->data && !was_useheap) 30 14839 14869
if (it->data && !was_useheap) 29 1 30
201 58 memmove(SvPV_nolen((SV*)it->datasv), it->data, PDLMIN(ncurr, nbytes));
202 29738 it->data = SvPV_nolen((SV*)it->datasv);
203 }
204 81964 ▶ if (nbytes > ncurr) memset(it->data + ncurr, 0, nbytes - ncurr);
Branch: 1 branch
BranchTrueFalseTotal
if (nbytes > ncurr) memset(it->data + ncurr, 0, nbytes - ncurr); 81939 25 81964
205 81964 it->nbytes = nbytes;
206 81964 it->state |= PDL_ALLOCATED;
207 81964 ▶ PDLDEBUG_f(pdl_dump(it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(pdl_dump(it)); 0 81964 81964
208 81964 return PDL_err;
209 }
210  
211 102187 pdl* pdl_pdlnew(void) {
212 102187 pdl *it = (pdl*) malloc(sizeof(pdl));
213 102187 ▶ if (!it) return it;
Branch: 1 branch
BranchTrueFalseTotal
if (!it) return it; 0 102187 102187
214 102187 memset(it, 0, sizeof(pdl));
215 102187 it->magicno = PDL_MAGICNO;
216 102187 it->datatype = PDL_D;
217 102187 it->trans_parent = NULL;
218 102187 it->vafftrans = NULL;
219 102187 it->data = it->datasv = it->sv = NULL;
220 102187 it->has_badvalue = 0;
221 102187 it->state = PDL_NOMYDIMS;
222 102187 it->dims = it->def_dims;
223 102187 it->nbytes = it->nvals = it->dims[0] = 0;
224 102187 it->dimincs = it->def_dimincs;
225 102187 it->dimincs[0] = 1;
226 102187 it->nbroadcastids = 1;
227 102187 it->broadcastids = it->def_broadcastids;
228 102187 it->broadcastids[0] = it->ndims = 1;
229 102187 it->trans_children = it->def_trans_children;
230 102187 it->ntrans_children_allocated = PDL_NCHILDREN;
231 102187 it->ntrans_children = 0;
232 102187 it->magic = 0;
233 102187 it->hdrsv = 0;
234 102187 ▶ PDLDEBUG_f(printf("pdl_pdlnew %p (size=%zu)\n",it,sizeof(pdl)));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_pdlnew %p (size=%zu)\n",it,sizeof(pdl))); 0 102187 102187
235 102187 return it;
236 }
237  
238 22787 void pdl_vafftrans_free(pdl *it)
239 {
240 22787 ▶ if (it->vafftrans && it->vafftrans->incs)
Branch: 2 branches
BranchTrueFalseTotal
if (it->vafftrans && it->vafftrans->incs) 22774 13 22787
if (it->vafftrans && it->vafftrans->incs) 22774 0 22774
241 22774 free(it->vafftrans->incs);
242 22787 ▶ if (it->vafftrans)
Branch: 1 branch
BranchTrueFalseTotal
if (it->vafftrans) 22774 13 22787
243 22774 free(it->vafftrans);
244 22787 it->vafftrans=0;
245 22787 it->state &= ~PDL_OPT_VAFFTRANSOK;
246 22787 }
247  
248 22776 pdl_error pdl_vafftrans_alloc(pdl *it)
249 {
250 22776 pdl_error PDL_err = {0, NULL, 0};
251 22776 ▶ if (!it->vafftrans) {
Branch: 1 branch
BranchTrueFalseTotal
if (!it->vafftrans) { 22774 2 22776
252 22774 it->vafftrans = malloc(sizeof(*(it->vafftrans)));
253 22774 ▶ if (!it->vafftrans) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
Branch: 1 branch
BranchTrueFalseTotal
if (!it->vafftrans) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); 0 22774 22774
254 22774 it->vafftrans->incs = 0;
255 22774 it->vafftrans->ndims = 0;
256 }
257 22776 ▶ if (!it->vafftrans->incs || it->vafftrans->ndims < it->ndims ) {
Branch: 2 branches
BranchTrueFalseTotal
if (!it->vafftrans->incs || it->vafftrans->ndims < it->ndims ) { 2 22774 22776
if (!it->vafftrans->incs || it->vafftrans->ndims < it->ndims ) { 2 0 2
258 22776 ▶ if (it->vafftrans->incs) free(it->vafftrans->incs);
Branch: 1 branch
BranchTrueFalseTotal
if (it->vafftrans->incs) free(it->vafftrans->incs); 2 22774 22776
259 22776 it->vafftrans->incs = malloc(sizeof(*(it->vafftrans->incs))
260 22776 * (size_t)it->ndims);
261 22776 ▶ if (!it->vafftrans->incs) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
Branch: 1 branch
BranchTrueFalseTotal
if (!it->vafftrans->incs) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); 0 22776 22776
262 22776 it->vafftrans->ndims = it->ndims;
263 }
264 22776 return PDL_err;
265 }
266  
267 /* Recursive! */
268 29111 void pdl_vafftrans_remove(pdl * it, char this_one)
269 {
270 29111 ▶ PDLDEBUG_f(printf("pdl_vafftrans_remove: %p, this_one=%d\n", it, (int)this_one));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_vafftrans_remove: %p, this_one=%d\n", it, (int)this_one)); 0 29111 29111
271 PDL_Indx i, j;
272 203777 ▶ for (i = 0; i < it->ntrans_children_allocated; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < it->ntrans_children_allocated; i++) { 174666 29111 203777
273 174666 pdl_trans *t = it->trans_children[i];
274 174666 ▶ if (!t || !(t->flags & PDL_ITRANS_ISAFFINE)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!t || !(t->flags & PDL_ITRANS_ISAFFINE)) continue; 2541 172125 174666
if (!t || !(t->flags & PDL_ITRANS_ISAFFINE)) continue; 2515 26 2541
275 52 ▶ for (j=t->vtable->nparents; j<t->vtable->npdls; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (j=t->vtable->nparents; j<t->vtable->npdls; j++) 26 26 52
276 26 pdl_vafftrans_remove(t->pdls[j], 1);
277 }
278 29111 ▶ if (this_one) pdl_vafftrans_free(it);
Branch: 1 branch
BranchTrueFalseTotal
if (this_one) pdl_vafftrans_free(it); 22787 6324 29111
279 29111 }
280  
281 /* Explicit free. Do not use, use destroy instead, which causes this
282 to be called when the time is right */
283 102125 pdl_error pdl__free(pdl *it) {
284 102125 pdl_error PDL_err = {0, NULL, 0};
285 102125 ▶ PDLDEBUG_f(printf("pdl__free %p\n",it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl__free %p\n",it)); 0 102125 102125
286 102125 ▶ PDL_CHKMAGIC(it);
Branch: 2 branches
BranchTrueFalseTotal
PDL_CHKMAGIC(it); 0 102125 102125
PDL_CHKMAGIC(it); 0 0 0
287 /* now check if magic is still there */
288 102125 ▶ if (pdl__ismagic(it))
Branch: 1 branch
BranchTrueFalseTotal
if (pdl__ismagic(it)) 65 102060 102125
289 65 ▶ PDLDEBUG_f(printf("%p is still magic\n",it);pdl__print_magic(it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("%p is still magic\n",it);pdl__print_magic(it)); 0 65 65
290 102125 it->magicno = 0x42424245;
291 102125 ▶ if (it->dims != it->def_dims) free(it->dims);
Branch: 1 branch
BranchTrueFalseTotal
if (it->dims != it->def_dims) free(it->dims); 5 102120 102125
292 102125 ▶ if (it->dimincs != it->def_dimincs) free(it->dimincs);
Branch: 1 branch
BranchTrueFalseTotal
if (it->dimincs != it->def_dimincs) free(it->dimincs); 5 102120 102125
293 102125 ▶ if (it->broadcastids != it->def_broadcastids) free(it->broadcastids);
Branch: 1 branch
BranchTrueFalseTotal
if (it->broadcastids != it->def_broadcastids) free(it->broadcastids); 0 102125 102125
294 102125 ▶ if (it->trans_children != it->def_trans_children) free(it->trans_children);
Branch: 1 branch
BranchTrueFalseTotal
if (it->trans_children != it->def_trans_children) free(it->trans_children); 51 102074 102125
295 102125 ▶ if (it->vafftrans) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->vafftrans) { 0 102125 102125
296 0 pdl_vafftrans_free(it);
297 }
298 /* Call special freeing magic, if exists */
299 102125 ▶ if (PDL_ISMAGIC(it)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PDL_ISMAGIC(it)) { 65 102060 102125
300 65 pdl__call_magic(it, PDL_MAGIC_DELETEDATA);
301 65 pdl__magic_free(it);
302 }
303 102125 ▶ if (it->datasv) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->datasv) { 16964 85161 102125
304 16964 ▶ PDLDEBUG_f(printf("SvREFCNT_dec datasv=%p\n",it->datasv));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("SvREFCNT_dec datasv=%p\n",it->datasv)); 0 16964 16964
305 16964 SvREFCNT_dec(it->datasv);
306 16964 it->data=0;
307 }
308 102125 ▶ if (it->hdrsv) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->hdrsv) { 3678 98447 102125
309 3678 ▶ PDLDEBUG_f(printf("SvREFCNT_dec hdrsv=%p\n",it->hdrsv));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("SvREFCNT_dec hdrsv=%p\n",it->hdrsv)); 0 3678 3678
310 3678 SvREFCNT_dec(it->hdrsv);
311 3678 it->hdrsv = 0;
312 }
313 102125 ▶ PDLDEBUG_f(printf("pdl__free end %p\n",it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl__free end %p\n",it)); 0 102125 102125
314 102125 free(it);
315 102125 return PDL_err;
316 }
317  
318 /* NULL out the pdl from the trans's inputs, and the trans from the
319 pdl's trans_children */
320 98706 void pdl__remove_pdl_as_trans_input(pdl *it,pdl_trans *trans, PDL_Indx param_ind)
321 {
322 98706 pdl_transvtable *vtable = trans->vtable;
323 98706 ▶ PDLDEBUG_f(printf("pdl__remove_pdl_as_trans_input(%s=%p, pdl=%p, param_ind=%td): \n",
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl__remove_pdl_as_trans_input(%s=%p, pdl=%p, param_ind=%td): \n", 0 98706 98706
324 vtable->name, trans, it, param_ind));
325 98706 PDL_Indx trans_children_index = trans->ind_sizes[vtable->ninds + param_ind];
326 98706 ▶ if (it->trans_children[trans_children_index] != trans) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->trans_children[trans_children_index] != trans) { 0 98706 98706
327 /* this might be due to a croak when performing the trans; so
328 warn only for now, otherwise we leave trans undestructed ! */
329 0 pdl_pdl_warn("Child not found for pdl %p, trans %p=%s\n",it, trans, vtable->name);
330 0 return;
331 }
332 98706 it->trans_children[trans_children_index] = NULL;
333 98706 it->ntrans_children--;
334 98706 ▶ if (trans_children_index < it->first_trans_child_available)
Branch: 1 branch
BranchTrueFalseTotal
if (trans_children_index < it->first_trans_child_available) 3012 95694 98706
335 3012 it->first_trans_child_available = trans_children_index;
336 }
337  
338 /* NULL out the trans's nth pdl in/output, and this trans as pdl's
339 trans_parent */
340 88152 void pdl__remove_pdl_as_trans_output(pdl *it, pdl_trans *trans, PDL_Indx nth)
341 {
342 88152 ▶ PDLDEBUG_f(printf("pdl__remove_pdl_as_trans_output from %p (%s=%p): %"IND_FLAG"\n",
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl__remove_pdl_as_trans_output from %p (%s=%p): %"IND_FLAG"\n", 0 88152 88152
343 it, trans->vtable->name, trans, nth));
344 88152 trans->pdls[nth] = 0;
345 88152 ▶ if (it->trans_parent != trans) return; /* only do rest if trans is parent */
Branch: 1 branch
BranchTrueFalseTotal
if (it->trans_parent != trans) return; /* only do rest if trans is parent */ 6906 81246 88152
346 81246 it->trans_parent = 0;
347 81246 ▶ PDLDEBUG_f(printf("pdl__remove_pdl_as_trans_output turning off MYDIMS_TRANS and ANYCHANGED, was: "); pdl_dump_flags_fixspace(it->state, 0, PDL_FLAGS_PDL));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl__remove_pdl_as_trans_output turning off MYDIMS_TRANS and ANYCHANGED, was: "); pdl_dump_flags_fixspace(it->state, 0, PDL_FLAGS_PDL)); 0 81246 81246
348 81246 it->state &= ~(PDL_MYDIMS_TRANS | PDL_ANYCHANGED);
349 }
350  
351 86699 pdl_error pdl_trans_finaldestroy(pdl_trans *trans)
352 {
353 86699 pdl_error PDL_err = {0, NULL, 0};
354 86699 ▶ PDLDEBUG_f(printf("pdl_trans_finaldestroy %p\n", trans));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_trans_finaldestroy %p\n", trans)); 0 86699 86699
355 111685 ▶ FREETRANS(trans, 1);
Branch: 3 branches
BranchTrueFalseTotal
FREETRANS(trans, 1); 24986 61713 86699
FREETRANS(trans, 1); 0 24986 24986
FREETRANS(trans, 1); 0 24986 24986
356 86699 ▶ if (trans->vtable->flags & PDL_TRANS_DO_BROADCAST)
Branch: 1 branch
BranchTrueFalseTotal
if (trans->vtable->flags & PDL_TRANS_DO_BROADCAST) 38029 48670 86699
357 38029 pdl_freebroadcaststruct(&trans->broadcast);
358 86699 trans->vtable = 0; /* Make sure no-one uses this */
359 86699 ▶ PDLDEBUG_f(printf("call free\n"));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("call free\n")); 0 86699 86699
360 86699 ▶ if (trans->params) free(trans->params);
Branch: 1 branch
BranchTrueFalseTotal
if (trans->params) free(trans->params); 50893 35806 86699
361 86699 free(trans->ind_sizes);
362 86699 free(trans->inc_sizes);
363 86699 free(trans);
364 86699 return PDL_err;
365 }
366  
367 pdl_error pdl__destroy_recprotect(pdl *it, int recurse_count);
368 86693 pdl_error pdl_destroytransform(pdl_trans *trans, int ensure, int recurse_count)
369 86693 {
370 86693 pdl_error PDL_err = {0, NULL, 0};
371 86693 ▶ PDL_TR_CHKMAGIC(trans);
Branch: 2 branches
BranchTrueFalseTotal
PDL_TR_CHKMAGIC(trans); 0 86693 86693
PDL_TR_CHKMAGIC(trans); 0 0 0
372 PDL_Indx j;
373 86693 pdl_transvtable *vtable = trans->vtable;
374 86693 ▶ if (!vtable)
Branch: 1 branch
BranchTrueFalseTotal
if (!vtable) 0 86693 86693
375 0 return pdl_make_error(PDL_EFATAL, "ZERO VTABLE DESTTRAN 0x%p %d\n",trans,ensure);
376 86693 char ismutual = (trans->flags & PDL_ITRANS_DO_DATAFLOW_ANY);
377 86693 ▶ PDLDEBUG_f(printf("pdl_destroytransform %s=%p (ensure=%d ismutual=%d)\n",
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_destroytransform %s=%p (ensure=%d ismutual=%d)\n", 0 86693 86693
378 vtable->name,trans,ensure,(int)ismutual));
379 86693 ▶ if (ensure)
Branch: 1 branch
BranchTrueFalseTotal
if (ensure) 12345 74348 86693
380 12345 ▶ PDL_ACCUMERROR(PDL_err, pdl__ensure_trans(trans, ismutual ? 0 : PDL_PARENTDIMSCHANGED, 0, recurse_count+1));
Branch: 2 branches
BranchTrueFalseTotal
PDL_ACCUMERROR(PDL_err, pdl__ensure_trans(trans, ismutual ? 0 : PDL_PARENTDIMSCHANGED, 0, recurse_count+1)); 12345 0 12345
PDL_ACCUMERROR(PDL_err, pdl__ensure_trans(trans, ismutual ? 0 : PDL_PARENTDIMSCHANGED, 0, recurse_count+1)); 0 12345 12345
381 86693 pdl *destbuffer[vtable->npdls];
382 86693 int ndest = 0;
383 185399 ▶ for (j=0; j<vtable->nparents; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j=0; j<vtable->nparents; j++) { 98706 86693 185399
384 98706 pdl *parent = trans->pdls[j];
385 98706 ▶ if (!parent) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!parent) continue; 0 98706 98706
386 98706 ▶ PDL_CHKMAGIC(parent);
Branch: 2 branches
BranchTrueFalseTotal
PDL_CHKMAGIC(parent); 0 98706 98706
PDL_CHKMAGIC(parent); 0 0 0
387 98706 pdl__remove_pdl_as_trans_input(parent,trans,j);
388 98706 ▶ if (!(parent->state & PDL_DESTROYING) && !parent->sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (!(parent->state & PDL_DESTROYING) && !parent->sv) { 92651 6055 98706
if (!(parent->state & PDL_DESTROYING) && !parent->sv) { 38625 54026 92651
389 38625 parent->state |= PDL_DESTROYING; /* so no mark twice */
390 38625 destbuffer[ndest++] = parent;
391 }
392 }
393 174845 ▶ for (j=vtable->nparents; j<vtable->npdls; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j=vtable->nparents; j<vtable->npdls; j++) { 88152 86693 174845
394 88152 pdl *child = trans->pdls[j];
395 88152 ▶ PDL_CHKMAGIC(child);
Branch: 2 branches
BranchTrueFalseTotal
PDL_CHKMAGIC(child); 0 88152 88152
PDL_CHKMAGIC(child); 0 0 0
396 88152 pdl__remove_pdl_as_trans_output(child,trans,j);
397 88152 ▶ if (ismutual && child->vafftrans) pdl_vafftrans_remove(child, 1);
Branch: 2 branches
BranchTrueFalseTotal
if (ismutual && child->vafftrans) pdl_vafftrans_remove(child, 1); 56858 31294 88152
if (ismutual && child->vafftrans) pdl_vafftrans_remove(child, 1); 22761 34097 56858
398 88152 ▶ if ((!(child->state & PDL_DESTROYING) && !child->sv) ||
Branch: 2 branches
BranchTrueFalseTotal
if ((!(child->state & PDL_DESTROYING) && !child->sv) || 43632 44520 88152
if ((!(child->state & PDL_DESTROYING) && !child->sv) || 37548 6084 43632
399 82068 ▶ (vtable->par_flags[j] & PDL_PARAM_ISTEMP)) {
Branch: 1 branch
BranchTrueFalseTotal
(vtable->par_flags[j] & PDL_PARAM_ISTEMP)) { 0 82068 82068
400 6084 child->state |= PDL_DESTROYING; /* so no mark twice */
401 6084 destbuffer[ndest++] = child;
402 }
403 }
404 86693 ▶ PDL_ACCUMERROR(PDL_err, pdl_trans_finaldestroy(trans));
Branch: 1 branch
BranchTrueFalseTotal
PDL_ACCUMERROR(PDL_err, pdl_trans_finaldestroy(trans)); 0 86693 86693
405 131402 ▶ for (j=0; j<ndest; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j=0; j<ndest; j++) { 44709 86693 131402
406 44709 destbuffer[j]->state &= ~PDL_DESTROYING; /* safe, set by us */
407 44709 ▶ PDL_ACCUMERROR(PDL_err, pdl__destroy_recprotect(destbuffer[j], recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_ACCUMERROR(PDL_err, pdl__destroy_recprotect(destbuffer[j], recurse_count+1)); 0 44709 44709
408 }
409 86693 ▶ PDLDEBUG_f(printf("pdl_destroytransform leaving %p\n", trans));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_destroytransform leaving %p\n", trans)); 0 86693 86693
410 86693 return PDL_err;
411 }
412  
413 /*
414 A ndarray may be
415 - a parent of something - just ensure & destroy
416 - a child of something - just ensure & destroy
417 - parent of two pdls which both propagate backwards - mustn't destroy.
418 - both parent and child at same time, to something that propagates.
419 Therefore, simple rules:
420 - allowed to destroy if
421 1. a parent with max. 1 backwards propagating transformation
422 2. a child with no trans_children
423 When an ndarray is destroyed, it must tell its trans_children and/or
424 parent.
425 */
426 122282 pdl_error pdl__destroy_recprotect(pdl *it, int recurse_count) {
427 122282 pdl_error PDL_err = {0, NULL, 0};
428 122282 int nback=0,nback2=0,nforw=0,nforw2=0;
429 122282 int nafn=0;
430 122282 ▶ PDL_CHKMAGIC(it);
Branch: 2 branches
BranchTrueFalseTotal
PDL_CHKMAGIC(it); 0 122282 122282
PDL_CHKMAGIC(it); 0 0 0
431 122282 ▶ PDLDEBUG_f(printf("pdl_destroy: ");pdl_dump(it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_destroy: ");pdl_dump(it)); 0 122282 122282
432 122282 ▶ if (it->state & PDL_DESTROYING) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->state & PDL_DESTROYING) { 0 122282 122282
433 0 ▶ PDLDEBUG_f(printf(" already destroying, returning\n"));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf(" already destroying, returning\n")); 0 0 0
434 0 return PDL_err;
435 }
436 122282 it->state |= PDL_DESTROYING;
437 /* Clear the sv field so that there will be no dangling ptrs */
438 122282 ▶ if (it->sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->sv) { 77499 44783 122282
439 77499 mg_free((SV *)it->sv);
440 77499 sv_setiv(it->sv, 0);
441 77499 it->sv = NULL;
442 }
443 /* 1. count the trans_children that do flow */
444 PDL_Indx i;
445 857316 ▶ for (i = 0; i < it->ntrans_children_allocated; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < it->ntrans_children_allocated; i++) { 735034 122282 857316
446 735034 pdl_trans *curt = it->trans_children[i];
447 735034 ▶ if (!curt) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!curt) continue; 708737 26297 735034
448 26297 ▶ PDL_TR_CHKMAGIC(curt);
Branch: 2 branches
BranchTrueFalseTotal
PDL_TR_CHKMAGIC(curt); 0 26297 26297
PDL_TR_CHKMAGIC(curt); 0 0 0
449 26297 ▶ if (curt->flags & PDL_ITRANS_DO_DATAFLOW_F) {
Branch: 1 branch
BranchTrueFalseTotal
if (curt->flags & PDL_ITRANS_DO_DATAFLOW_F) { 26297 0 26297
450 26297 nforw++;
451 /* where more than two inputs must always be soft-destroyed */
452 26297 ▶ if (curt->vtable->nparents > 1) nforw2++;
Branch: 1 branch
BranchTrueFalseTotal
if (curt->vtable->nparents > 1) nforw2++; 12816 13481 26297
453 }
454 26297 ▶ if (curt->flags & PDL_ITRANS_DO_DATAFLOW_B) {
Branch: 1 branch
BranchTrueFalseTotal
if (curt->flags & PDL_ITRANS_DO_DATAFLOW_B) { 26267 30 26297
455 26267 nback++;
456 /* where more than two in relationship must always be soft-destroyed */
457 26267 ▶ if (curt->vtable->npdls > 2) nback2++;
Branch: 1 branch
BranchTrueFalseTotal
if (curt->vtable->npdls > 2) nback2++; 12786 13481 26267
458 }
459 26297 ▶ if ((curt->flags & PDL_ITRANS_ISAFFINE) && !(curt->pdls[1]->state & PDL_ALLOCATED))
Branch: 2 branches
BranchTrueFalseTotal
if ((curt->flags & PDL_ITRANS_ISAFFINE) && !(curt->pdls[1]->state & PDL_ALLOCATED)) 7522 18775 26297
if ((curt->flags & PDL_ITRANS_ISAFFINE) && !(curt->pdls[1]->state & PDL_ALLOCATED)) 7277 245 7522
460 7277 nafn++;
461 }
462 122282 char soft_destroy = 0;
463 122282 ▶ PDLDEBUG_f(printf(" nba(%d, %d), nforw(%d, %d), tra(%p=%s), nafn(%d)\n",
Branch: 2 branches
BranchTrueFalseTotal
PDLDEBUG_f(printf(" nba(%d, %d), nforw(%d, %d), tra(%p=%s), nafn(%d)\n", 0 122282 122282
PDLDEBUG_f(printf(" nba(%d, %d), nforw(%d, %d), tra(%p=%s), nafn(%d)\n", 0 0 0
464 nback, nback2, nforw, nforw2, it->trans_parent, it->trans_parent?it->trans_parent->vtable->name:"", nafn));
465 122282 ▶ if (nback2 > 0) { PDLDEBUG_f(printf(" soft_destroy: nback2=%d\n", nback2)); soft_destroy = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if (nback2 > 0) { PDLDEBUG_f(printf(" soft_destroy: nback2=%d\n", nback2)); soft_destroy = 1; } 12762 109520 122282
if (nback2 > 0) { PDLDEBUG_f(printf(" soft_destroy: nback2=%d\n", nback2)); soft_destroy = 1; } 0 12762 12762
466 122282 ▶ if (nback > 1) { PDLDEBUG_f(printf(" soft_destroy: nback=%d\n", nback)); soft_destroy = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if (nback > 1) { PDLDEBUG_f(printf(" soft_destroy: nback=%d\n", nback)); soft_destroy = 1; } 64 122218 122282
if (nback > 1) { PDLDEBUG_f(printf(" soft_destroy: nback=%d\n", nback)); soft_destroy = 1; } 0 64 64
467 122282 ▶ if (it->trans_parent && nforw) { PDLDEBUG_f(printf(" soft_destroy: has parent and nforw=%d\n", nforw)); soft_destroy = 1; }
Branch: 3 branches
BranchTrueFalseTotal
if (it->trans_parent && nforw) { PDLDEBUG_f(printf(" soft_destroy: has parent and nforw=%d\n", nforw)); soft_destroy = 1; } 57658 64624 122282
if (it->trans_parent && nforw) { PDLDEBUG_f(printf(" soft_destroy: has parent and nforw=%d\n", nforw)); soft_destroy = 1; } 13145 44513 57658
if (it->trans_parent && nforw) { PDLDEBUG_f(printf(" soft_destroy: has parent and nforw=%d\n", nforw)); soft_destroy = 1; } 0 13145 13145
468 122282 ▶ if (nforw2 > 0) { PDLDEBUG_f(printf(" soft_destroy: nforw2=%d\n", nforw2)); soft_destroy = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if (nforw2 > 0) { PDLDEBUG_f(printf(" soft_destroy: nforw2=%d\n", nforw2)); soft_destroy = 1; } 12792 109490 122282
if (nforw2 > 0) { PDLDEBUG_f(printf(" soft_destroy: nforw2=%d\n", nforw2)); soft_destroy = 1; } 0 12792 12792
469 /* Also, we do not wish to destroy if the trans_children would be larger
470 * than the parent and are currently not allocated (e.g. lags).
471 * Because this is too much work to check, we refrain from destroying
472 * for now if there is an affine child that is not allocated
473 */
474 122282 ▶ if (nafn) { PDLDEBUG_f(printf(" soft_destroy: nafn=%d\n", nafn)); soft_destroy = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if (nafn) { PDLDEBUG_f(printf(" soft_destroy: nafn=%d\n", nafn)); soft_destroy = 1; } 7225 115057 122282
if (nafn) { PDLDEBUG_f(printf(" soft_destroy: nafn=%d\n", nafn)); soft_destroy = 1; } 0 7225 7225
475 122282 ▶ if (pdl__magic_isundestroyable(it)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pdl__magic_isundestroyable(it)) { 0 122282 122282
476 0 ▶ PDLDEBUG_f(printf(" not destroying as magic %p\n", it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf(" not destroying as magic %p\n", it)); 0 0 0
477 0 soft_destroy = 1;
478 }
479 122282 ▶ if (soft_destroy) {
Branch: 1 branch
BranchTrueFalseTotal
if (soft_destroy) { 20157 102125 122282
480 20157 it->state &= ~PDL_DESTROYING;
481 20157 return PDL_err;
482 }
483 716035 ▶ for (i = 0; i < it->ntrans_children_allocated; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < it->ntrans_children_allocated; i++) { 613910 102125 716035
484 613910 pdl_trans *t = it->trans_children[i];
485 613910 ▶ if (!t) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!t) continue; 607855 6055 613910
486 6055 ▶ PDL_RETERROR(PDL_err, pdl_destroytransform(t, 1, recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_destroytransform(t, 1, recurse_count+1)); 0 6055 6055
487 }
488 102125 pdl_trans *trans = it->trans_parent;
489 102125 ▶ if (trans)
Branch: 1 branch
BranchTrueFalseTotal
if (trans) 44513 57612 102125
490 /* Ensure only if there are other children! */
491 44513 ▶ PDL_RETERROR(PDL_err, pdl_destroytransform(trans,
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_destroytransform(trans, 0 44513 44513
492 trans->vtable->npdls - trans->vtable->nparents > 1, recurse_count+1));
493 /* Here, this is a child but has no children - fall through to hard_destroy */
494 102125 ▶ PDL_RETERROR(PDL_err, pdl__free(it));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__free(it)); 0 102125 102125
495 102125 ▶ PDLDEBUG_f(printf("pdl_destroy end %p\n",it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_destroy end %p\n",it)); 0 102125 102125
496 102125 return PDL_err;
497 }
498  
499 77573 pdl_error pdl_destroy(pdl *it) {
500 77573 return pdl__destroy_recprotect(it, 0);
501 }
502  
503 /* Straight copy, no dataflow */
504 74 pdl *pdl_hard_copy(pdl *src) {
505 74 ▶ PDLDEBUG_f(printf("pdl_hard_copy (src=%p): ", src));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_hard_copy (src=%p): ", src)); 0 74 74
506 74 pdl *it = pdl_pdlnew();
507 74 ▶ if (!it) return it;
Branch: 1 branch
BranchTrueFalseTotal
if (!it) return it; 0 74 74
508 74 pdl_error PDL_err = {0, NULL, 0};
509 74 ▶ PDL_RETERROR2(PDL_err, pdl_affine_new(src, it, 0, src->dims, src->ndims, src->dimincs, src->ndims), pdl_destroy(it); return NULL;);
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR2(PDL_err, pdl_affine_new(src, it, 0, src->dims, src->ndims, src->dimincs, src->ndims), pdl_destroy(it); return NULL;); 0 74 74
510 74 ▶ PDLDEBUG_f(printf("pdl_hard_copy (src=%p): ", src);pdl_dump(it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_hard_copy (src=%p): ", src);pdl_dump(it)); 0 74 74
511 74 it->sv = (void *)1; /* stop sever from tidying it up */
512 74 ▶ PDL_RETERROR2(PDL_err, pdl_sever(it), pdl_destroy(it); return NULL;);
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR2(PDL_err, pdl_sever(it), pdl_destroy(it); return NULL;); 0 74 74
513 74 it->sv = NULL; /* destroyable again */
514 74 return it;
515 }
516  
517 /* Reallocate this PDL to have ndims dimensions. */
518 96905 pdl_error pdl_reallocdims(pdl *it, PDL_Indx ndims) {
519 96905 pdl_error PDL_err = {0, NULL, 0};
520 96905 ▶ if (it->ndims < ndims) { /* Need to realloc for more */
Branch: 1 branch
BranchTrueFalseTotal
if (it->ndims < ndims) { /* Need to realloc for more */ 13229 83676 96905
521 13229 ▶ if (it->dims != it->def_dims) free(it->dims);
Branch: 1 branch
BranchTrueFalseTotal
if (it->dims != it->def_dims) free(it->dims); 0 13229 13229
522 13229 ▶ if (it->dimincs != it->def_dimincs) free(it->dimincs);
Branch: 1 branch
BranchTrueFalseTotal
if (it->dimincs != it->def_dimincs) free(it->dimincs); 0 13229 13229
523 13229 ▶ if (ndims>PDL_NDIMS) { /* Need to malloc */
Branch: 1 branch
BranchTrueFalseTotal
if (ndims>PDL_NDIMS) { /* Need to malloc */ 5 13224 13229
524 5 ▶ if (!(it->dims = malloc(ndims*sizeof(*(it->dims)))))
Branch: 1 branch
BranchTrueFalseTotal
if (!(it->dims = malloc(ndims*sizeof(*(it->dims))))) 0 5 5
525 0 return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
526 5 ▶ if (!(it->dimincs = malloc(ndims*sizeof(*(it->dimincs))))) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(it->dimincs = malloc(ndims*sizeof(*(it->dimincs))))) { 0 5 5
527 0 free(it->dims);
528 0 return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
529 }
530 }
531 else {
532 13224 it->dims = it->def_dims;
533 13224 it->dimincs = it->def_dimincs;
534 }
535 }
536 96905 it->ndims = ndims;
537 96905 return PDL_err;
538 }
539  
540 /* Reallocate n broadcastids. Set the new extra ones to the end */
541 103439 pdl_error pdl_reallocbroadcastids(pdl *it, PDL_Indx n) {
542 103439 pdl_error PDL_err = {0, NULL, 0};
543 PDL_Indx i;
544 PDL_Indx *olds; PDL_Indx nold;
545 103439 ▶ if (n <= it->nbroadcastids) {
Branch: 1 branch
BranchTrueFalseTotal
if (n <= it->nbroadcastids) { 103342 97 103439
546 103342 it->nbroadcastids = n;
547 103342 it->broadcastids[n-1] = it->ndims;
548 103342 return PDL_err;
549 }
550 97 nold = it->nbroadcastids; olds = it->broadcastids;
551 97 ▶ if (n > PDL_NBROADCASTIDS) {
Branch: 1 branch
BranchTrueFalseTotal
if (n > PDL_NBROADCASTIDS) { 0 97 97
552 0 it->broadcastids = malloc(sizeof(*(it->broadcastids))*n);
553 0 ▶ if (!it->broadcastids) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
Branch: 1 branch
BranchTrueFalseTotal
if (!it->broadcastids) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); 0 0 0
554 } else {
555 97 it->broadcastids = it->def_broadcastids;
556 }
557 97 it->nbroadcastids = n;
558 97 ▶ if (it->broadcastids != olds) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->broadcastids != olds) { 0 97 97
559 0 ▶ for (i=0; i<nold && i<n; i++)
Branch: 2 branches
BranchTrueFalseTotal
for (i=0; i<nold && i<n; i++) 0 0 0
for (i=0; i<nold && i<n; i++) 0 0 0
560 0 it->broadcastids[i] = olds[i];
561 }
562 97 ▶ if (olds != it->def_broadcastids) { free(olds); }
Branch: 1 branch
BranchTrueFalseTotal
if (olds != it->def_broadcastids) { free(olds); } 0 97 97
563 195 ▶ for (i=nold; i<it->nbroadcastids; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=nold; i<it->nbroadcastids; i++) { 98 97 195
564 98 it->broadcastids[i] = it->ndims;
565 }
566 97 return PDL_err;
567 }
568  
569 /* Recalculate default increments */
570 106872 void pdl_resize_defaultincs(pdl *it) {
571 106872 PDL_Indx inc = 1, i = 0;
572 188939 ▶ for (i=0; i<it->ndims; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<it->ndims; i++) { 82067 106872 188939
573 82067 it->dimincs[i] = inc; inc *= it->dims[i];
574 }
575 106872 ▶ if (it->nvals != inc) /* Need to realloc only if nvals changed */
Branch: 1 branch
BranchTrueFalseTotal
if (it->nvals != inc) /* Need to realloc only if nvals changed */ 99242 7630 106872
576 99242 it->state &= ~PDL_ALLOCATED;
577 106872 it->nvals = inc;
578 106872 }
579  
580 /* Init dims & incs - if *incs is NULL ignored (but space is always same for both) */
581 18239 pdl_error pdl_setdims(pdl* it, PDL_Indx * dims, PDL_Indx ndims) {
582 18239 pdl_error PDL_err = {0, NULL, 0};
583 18239 ▶ PDLDEBUG_f(printf("pdl_setdims %p: ", it);pdl_print_iarr(dims, ndims);printf("\n"));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_setdims %p: ", it);pdl_print_iarr(dims, ndims);printf("\n")); 0 18239 18239
584 18239 ▶ if (it->trans_parent)
Branch: 1 branch
BranchTrueFalseTotal
if (it->trans_parent) 1 18238 18239
585 1 return pdl_make_error(PDL_EUSERERROR,
586 "setdims called on %p but has trans_parent %s",
587 1 it, it->trans_parent->vtable->name
588 );
589 18238 PDL_Indx i, old_nvals = it->nvals, new_nvals = 1;
590 30813 ▶ for (i=0; i<ndims; i++) new_nvals *= dims[i];
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<ndims; i++) new_nvals *= dims[i]; 12575 18238 30813
591 18238 ▶ int what = (old_nvals == new_nvals) ? 0 : PDL_PARENTDATACHANGED;
Branch: 1 branch
BranchTrueFalseTotal
int what = (old_nvals == new_nvals) ? 0 : PDL_PARENTDATACHANGED; 668 17570 18238
592 18238 ▶ if ((it->state & PDL_NOMYDIMS) || ndims != it->ndims)
Branch: 2 branches
BranchTrueFalseTotal
if ((it->state & PDL_NOMYDIMS) || ndims != it->ndims) 267 17971 18238
if ((it->state & PDL_NOMYDIMS) || ndims != it->ndims) 200 67 267
593 18171 what |= PDL_PARENTDIMSCHANGED;
594 else
595 140 ▶ for (i=0; i<ndims; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<ndims; i++) 93 47 140
596 93 ▶ if (dims[i] != it->dims[i]) { what |= PDL_PARENTDIMSCHANGED; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (dims[i] != it->dims[i]) { what |= PDL_PARENTDIMSCHANGED; break; } 20 73 93
597 18238 ▶ if (!what) { PDLDEBUG_f(printf("pdl_setdims NOOP\n")); return PDL_err; }
Branch: 2 branches
BranchTrueFalseTotal
if (!what) { PDLDEBUG_f(printf("pdl_setdims NOOP\n")); return PDL_err; } 47 18191 18238
if (!what) { PDLDEBUG_f(printf("pdl_setdims NOOP\n")); return PDL_err; } 0 47 47
598 18191 ▶ PDL_RETERROR(PDL_err, pdl_reallocdims(it,ndims));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_reallocdims(it,ndims)); 0 18191 18191
599 30701 ▶ for (i=0; i<ndims; i++) it->dims[i] = dims[i];
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<ndims; i++) it->dims[i] = dims[i]; 12510 18191 30701
600 18191 pdl_resize_defaultincs(it);
601 18191 ▶ PDL_RETERROR(PDL_err, pdl_reallocbroadcastids(it,1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_reallocbroadcastids(it,1)); 0 18191 18191
602 18191 it->broadcastids[0] = ndims;
603 18191 it->state &= ~PDL_NOMYDIMS;
604 18191 ▶ CHANGED(it,what,0);
Branch: 1 branch
BranchTrueFalseTotal
CHANGED(it,what,0); 0 18191 18191
605 18191 return PDL_err;
606 }
607  
608 /* This is *not* careful! */
609 47417 pdl_error pdl_setdims_careful(pdl *it)
610 {
611 47417 pdl_error PDL_err = {0, NULL, 0};
612 47417 pdl_resize_defaultincs(it);
613 47417 PDL_err = pdl_reallocbroadcastids(it,1); /* XXX For now */
614 47417 return PDL_err;
615 }
616  
617 /*CORE21 unused*/
618 0 PDL_Anyval pdl_get_offs(pdl *it, PDL_Indx offs) {
619 0 PDL_Anyval result = { PDL_INVALID, {0} };
620 0 ANYVAL_FROM_CTYPE_OFFSET(result, it->datatype, it->data, offs);
621 0 return result;
622 }
623  
624 98713 pdl_error pdl__add_pdl_as_trans_input(pdl *it,pdl_trans *trans, PDL_Indx param_ind)
625 {
626 98713 pdl_error PDL_err = {0, NULL, 0};
627 98713 pdl_transvtable *vtable = trans->vtable;
628 98713 ▶ PDLDEBUG_f(printf("pdl__add_pdl_as_trans_input add to %p trans=%s param_ind=%td\n", it, vtable->name, param_ind));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl__add_pdl_as_trans_input add to %p trans=%s param_ind=%td\n", it, vtable->name, param_ind)); 0 98713 98713
629 98713 PDL_Indx i, trans_children_index = 0;
630 101892 ▶ for (trans_children_index = it->first_trans_child_available; trans_children_index < it->ntrans_children_allocated; trans_children_index++)
Branch: 1 branch
BranchTrueFalseTotal
for (trans_children_index = it->first_trans_child_available; trans_children_index < it->ntrans_children_allocated; trans_children_index++) 101885 7 101892
631 101885 ▶ if (!it->trans_children[trans_children_index]) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!it->trans_children[trans_children_index]) break; 98706 3179 101885
632 98713 ▶ if (trans_children_index >= it->ntrans_children_allocated) {
Branch: 1 branch
BranchTrueFalseTotal
if (trans_children_index >= it->ntrans_children_allocated) { 7 98706 98713
633 7 ▶ if (it->trans_children == it->def_trans_children) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->trans_children == it->def_trans_children) { 7 0 7
634 7 it->trans_children = malloc(
635 7 sizeof(pdl_trans*) * (it->ntrans_children_allocated += PDL_NCHILDREN)
636 );
637 7 ▶ if (!it->trans_children) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
Branch: 1 branch
BranchTrueFalseTotal
if (!it->trans_children) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); 0 7 7
638 49 ▶ for (i = 0; i < PDL_NCHILDREN; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < PDL_NCHILDREN; i++) 42 7 49
639 42 it->trans_children[i] = it->def_trans_children[i];
640 49 ▶ for (; i < it->ntrans_children_allocated; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (; i < it->ntrans_children_allocated; i++) 42 7 49
641 42 it->trans_children[i] = NULL;
642 } else {
643 0 it->trans_children = realloc(it->trans_children,
644 0 sizeof(pdl_trans*) * (it->ntrans_children_allocated += PDL_NCHILDREN)
645 );
646 0 ▶ if (!it->trans_children) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
Branch: 1 branch
BranchTrueFalseTotal
if (!it->trans_children) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); 0 0 0
647 0 ▶ for (i = trans_children_index+1; i < it->ntrans_children_allocated; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = trans_children_index+1; i < it->ntrans_children_allocated; i++) 0 0 0
648 0 it->trans_children[i] = NULL;
649 }
650 }
651 98713 ▶ if (trans_children_index > it->first_trans_child_available)
Branch: 1 branch
BranchTrueFalseTotal
if (trans_children_index > it->first_trans_child_available) 3177 95536 98713
652 3177 it->first_trans_child_available = trans_children_index;
653 98713 it->ntrans_children++;
654 98713 trans->ind_sizes[vtable->ninds + param_ind] = trans_children_index;
655 98713 it->trans_children[trans_children_index] = trans;
656 98713 return PDL_err;
657 }
658  
659 47 pdl_error pdl_prealloc_trans_children(pdl *it, PDL_Indx howmany) {
660 47 pdl_error PDL_err = {0, NULL, 0};
661 47 PDL_Indx i, oldval = it->ntrans_children_allocated;
662 47 ▶ if (howmany > oldval) {
Branch: 1 branch
BranchTrueFalseTotal
if (howmany > oldval) { 47 0 47
663 47 ▶ if (it->trans_children == it->def_trans_children) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->trans_children == it->def_trans_children) { 44 3 47
664 44 it->trans_children = malloc(
665 44 sizeof(pdl_trans*) * (it->ntrans_children_allocated = howmany)
666 );
667 44 ▶ if (!it->trans_children) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
Branch: 1 branch
BranchTrueFalseTotal
if (!it->trans_children) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); 0 44 44
668 308 ▶ for (i = 0; i < PDL_NCHILDREN; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < PDL_NCHILDREN; i++) 264 44 308
669 264 it->trans_children[i] = it->def_trans_children[i];
670 } else {
671 3 it->trans_children = realloc(it->trans_children,
672 3 sizeof(pdl_trans*) * (it->ntrans_children_allocated = howmany)
673 );
674 3 ▶ if (!it->trans_children) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n");
Branch: 1 branch
BranchTrueFalseTotal
if (!it->trans_children) return pdl_make_error_simple(PDL_EFATAL, "Out of Memory\n"); 0 3 3
675 }
676 1165 ▶ for (i = oldval; i < howmany; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = oldval; i < howmany; i++) 1118 47 1165
677 1118 it->trans_children[i] = NULL;
678 }
679 47 return PDL_err;
680 }
681  
682 192461 pdl_error pdl__make_physdims_recprotect(pdl *it, int recurse_count) {
683 192461 pdl_error PDL_err = {0, NULL, 0};
684 192461 ▶ PDL_RECURSE_CHECK(recurse_count);
Branch: 1 branch
BranchTrueFalseTotal
PDL_RECURSE_CHECK(recurse_count); 0 192461 192461
685 192461 ▶ if (!it) return pdl_make_error_simple(PDL_EFATAL, "make_physdims called with NULL");
Branch: 1 branch
BranchTrueFalseTotal
if (!it) return pdl_make_error_simple(PDL_EFATAL, "make_physdims called with NULL"); 0 192461 192461
686 192461 ▶ PDLDEBUG_f(printf("make_physdims %p state=", it);pdl_dump_flags_fixspace(it->state, 0, PDL_FLAGS_PDL));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physdims %p state=", it);pdl_dump_flags_fixspace(it->state, 0, PDL_FLAGS_PDL)); 0 192461 192461
687 192461 ▶ PDL_CHKMAGIC(it);
Branch: 2 branches
BranchTrueFalseTotal
PDL_CHKMAGIC(it); 0 192461 192461
PDL_CHKMAGIC(it); 0 0 0
688 192461 ▶ if (!(it->state & PDL_PARENTDIMSCHANGED)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(it->state & PDL_PARENTDIMSCHANGED)) { 142688 49773 192461
689 142688 ▶ PDLDEBUG_f(printf("make_physdims exit (NOP) %p\n", it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physdims exit (NOP) %p\n", it)); 0 142688 142688
690 142688 return PDL_err;
691 }
692 49773 pdl_trans *trans = it->trans_parent;
693 49773 ▶ PDLDEBUG_f(printf("make_physdims %p TRANS: ",it);pdl_dump_trans_fixspace(trans,3));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physdims %p TRANS: ",it);pdl_dump_trans_fixspace(trans,3)); 0 49773 49773
694 PDL_Indx i;
695 107767 ▶ for (i=0; i<trans->vtable->nparents; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<trans->vtable->nparents; i++) 57994 49773 107767
696 57994 ▶ if (trans->pdls[i]->state & PDL_PARENTDIMSCHANGED)
Branch: 1 branch
BranchTrueFalseTotal
if (trans->pdls[i]->state & PDL_PARENTDIMSCHANGED) 15215 42779 57994
697 15215 ▶ PDL_RETERROR(PDL_err, pdl__make_physdims_recprotect(trans->pdls[i], recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__make_physdims_recprotect(trans->pdls[i], recurse_count+1)); 0 15215 15215
698 49773 ▶ PDLDEBUG_f(printf("make_physdims: calling redodims trans=%p on pdl=%p\n", trans, it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physdims: calling redodims trans=%p on pdl=%p\n", trans, it)); 0 49773 49773
699 238882 ▶ REDODIMS(PDL_RETERROR, trans);
Branch: 20 branches
BranchTrueFalseTotal
REDODIMS(PDL_RETERROR, trans); 41727 8046 49773
REDODIMS(PDL_RETERROR, trans); 41727 41808 83535
REDODIMS(PDL_RETERROR, trans); 41725 2 41727
REDODIMS(PDL_RETERROR, trans); 41725 0 41725
REDODIMS(PDL_RETERROR, trans); 83535 41727 125262
REDODIMS(PDL_RETERROR, trans); 0 41727 41727
REDODIMS(PDL_RETERROR, trans); 36 49737 49773
REDODIMS(PDL_RETERROR, trans); 34 2 36
REDODIMS(PDL_RETERROR, trans); 0 34 34
REDODIMS(PDL_RETERROR, trans); 0 34 34
REDODIMS(PDL_RETERROR, trans); 0 36 36
REDODIMS(PDL_RETERROR, trans); 41727 8046 49773
REDODIMS(PDL_RETERROR, trans); 58 49715 49773
REDODIMS(PDL_RETERROR, trans); 0 14098 14098
REDODIMS(PDL_RETERROR, trans); 0 0 0
REDODIMS(PDL_RETERROR, trans); 14098 49715 63813
REDODIMS(PDL_RETERROR, trans); 0 49715 49715
REDODIMS(PDL_RETERROR, trans); 0 0 0
REDODIMS(PDL_RETERROR, trans); 0 49715 49715
REDODIMS(PDL_RETERROR, trans); 49715 49715 99430
700 49715 ▶ PDLDEBUG_f(printf("make_physdims exit pdl=%p\n", it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physdims exit pdl=%p\n", it)); 0 49715 49715
701 49715 return PDL_err;
702 }
703 45789 pdl_error pdl_make_physdims(pdl *it) {
704 45789 return pdl__make_physdims_recprotect(it, 0);
705 }
706  
707 186881 static inline char _trans_forward_only(pdl *p) {
708 186881 pdl_trans *tp = p->trans_parent;
709 186881 ▶ return !!(tp && (tp->flags & PDL_ITRANS_DO_DATAFLOW_ANY) == PDL_ITRANS_DO_DATAFLOW_F);
Branch: 2 branches
BranchTrueFalseTotal
return !!(tp && (tp->flags & PDL_ITRANS_DO_DATAFLOW_ANY) == PDL_ITRANS_DO_DATAFLOW_F); 49777 137104 186881
return !!(tp && (tp->flags & PDL_ITRANS_DO_DATAFLOW_ANY) == PDL_ITRANS_DO_DATAFLOW_F); 27 49750 49777
710 }
711 86703 static inline pdl_error pdl_trans_flow_null_checks(pdl_trans *trans, char *disable_back) {
712 86703 pdl_error PDL_err = {0, NULL, 0};
713 PDL_Indx i;
714 86703 pdl_transvtable *vtable = trans->vtable;
715 86703 char input_forward_only = 0;
716 185422 ▶ for (i=0; i<vtable->nparents; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<vtable->nparents; i++) { 98721 86701 185422
717 98721 pdl *parent = trans->pdls[i];
718 98721 ▶ if (_trans_forward_only(parent))
Branch: 1 branch
BranchTrueFalseTotal
if (_trans_forward_only(parent)) 24 98697 98721
719 24 input_forward_only = 1;
720 98721 ▶ if (parent->state & PDL_NOMYDIMS && !(vtable->par_flags[i] & PDL_PARAM_ALLOW_NULL))
Branch: 2 branches
BranchTrueFalseTotal
if (parent->state & PDL_NOMYDIMS && !(vtable->par_flags[i] & PDL_PARAM_ALLOW_NULL)) 24 98697 98721
if (parent->state & PDL_NOMYDIMS && !(vtable->par_flags[i] & PDL_PARAM_ALLOW_NULL)) 2 22 24
721 2 return pdl_make_error(PDL_EUSERERROR,
722 "Error in %s: input parameter '%s' is null",
723 2 vtable->name, vtable->par_names[i]
724 );
725 }
726 174857 ▶ for (; i<vtable->npdls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (; i<vtable->npdls; i++) { 88160 86697 174857
727 88160 pdl *child = trans->pdls[i];
728 88160 ▶ if (_trans_forward_only(child))
Branch: 1 branch
BranchTrueFalseTotal
if (_trans_forward_only(child)) 3 88157 88160
729 3 return pdl_make_error(PDL_EUSERERROR, "%s: cannot output to parameter '%s' with inward but no backward flow", vtable->name, vtable->par_names[i]);
730 88157 ▶ if (child->state & PDL_NOMYDIMS && !(vtable->par_flags[i] & PDL_PARAM_ISCREAT))
Branch: 2 branches
BranchTrueFalseTotal
if (child->state & PDL_NOMYDIMS && !(vtable->par_flags[i] & PDL_PARAM_ISCREAT)) 73402 14755 88157
if (child->state & PDL_NOMYDIMS && !(vtable->par_flags[i] & PDL_PARAM_ISCREAT)) 1 73401 73402
731 1 return pdl_make_error(PDL_EUSERERROR,
732 "Error in %s: io parameter '%s' is null",
733 1 vtable->name, vtable->par_names[i]
734 );
735 }
736 86697 *disable_back = input_forward_only;
737 86697 return PDL_err;
738 }
739  
740 /* Called with a filled pdl_trans struct.
741 * Sets the parent and trans fields of the ndarrays correctly,
742 * creating families and the like if necessary.
743 * Alternatively may just execute transformation
744 * that would require families but is not dataflowed.
745 */
746 86703 pdl_error pdl_make_trans_mutual(pdl_trans *trans)
747 86703 {
748 86703 pdl_error PDL_err = {0, NULL, 0};
749 86703 ▶ PDLDEBUG_f(printf("make_trans_mutual ");pdl_dump_trans_fixspace(trans,0));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_trans_mutual ");pdl_dump_trans_fixspace(trans,0)); 0 86703 86703
750 86703 pdl_transvtable *vtable = trans->vtable;
751 if (((vtable->iflags & PDL_ITRANS_DO_DATAFLOW_B|PDL_ITRANS_ISAFFINE)
752 == PDL_ITRANS_DO_DATAFLOW_B) &&
753 !vtable->writebackdata
754 )
755 return pdl_make_error(PDL_EUSERERROR, "%s: backward dataflow flag but not affine or given writebackdata", vtable->name);
756 86703 pdl **pdls = trans->pdls;
757 86703 PDL_Indx i, npdls=vtable->npdls, nparents=vtable->nparents;
758 86703 ▶ PDL_TR_CHKMAGIC(trans);
Branch: 2 branches
BranchTrueFalseTotal
PDL_TR_CHKMAGIC(trans); 0 86703 86703
PDL_TR_CHKMAGIC(trans); 0 0 0
759 86703 char disable_back = 0, inputs_bad = 0;
760 268215 ▶ for (i=0; i<npdls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<npdls; i++) { 183939 84276 268215
761 183939 pdl *pdl = pdls[i];
762 183939 ▶ if ((vtable->par_flags[i] & (PDL_PARAM_ISOUT|PDL_PARAM_ISTEMP)) ||
Branch: 1 branch
BranchTrueFalseTotal
if ((vtable->par_flags[i] & (PDL_PARAM_ISOUT|PDL_PARAM_ISTEMP)) || 104367 79572 183939
763 183939 ▶ !(pdl->state & PDL_BADVAL)) continue;
Branch: 1 branch
BranchTrueFalseTotal
!(pdl->state & PDL_BADVAL)) continue; 101940 2427 104367
764 2427 inputs_bad = trans->bvalflag = 1;
765 2427 break;
766 }
767 86703 ▶ if (trans->bvalflag && (vtable->flags & PDL_TRANS_BADIGNORE)) {
Branch: 2 branches
BranchTrueFalseTotal
if (trans->bvalflag && (vtable->flags & PDL_TRANS_BADIGNORE)) { 2427 84276 86703
if (trans->bvalflag && (vtable->flags & PDL_TRANS_BADIGNORE)) { 0 2427 2427
768 0 pdl_pdl_warn("WARNING: %s does not handle bad values", vtable->name);
769 0 trans->bvalflag = 0; /* but still return true */
770 }
771 86703 PDL_err = pdl_trans_flow_null_checks(trans, &disable_back);
772 86703 ▶ if (PDL_err.error) {
Branch: 1 branch
BranchTrueFalseTotal
if (PDL_err.error) { 6 86697 86703
773 6 ▶ PDL_ACCUMERROR(PDL_err, pdl_trans_finaldestroy(trans));
Branch: 1 branch
BranchTrueFalseTotal
PDL_ACCUMERROR(PDL_err, pdl_trans_finaldestroy(trans)); 0 6 6
774 6 return PDL_err;
775 }
776 185410 ▶ for (i=0; i<nparents; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<nparents; i++) { 98713 86697 185410
777 98713 pdl *parent = pdls[i];
778 98713 ▶ PDL_RETERROR(PDL_err, pdl__add_pdl_as_trans_input(parent,trans,i));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__add_pdl_as_trans_input(parent,trans,i)); 0 98713 98713
779 98713 ▶ if (parent->state & PDL_DATAFLOW_F) {
Branch: 1 branch
BranchTrueFalseTotal
if (parent->state & PDL_DATAFLOW_F) { 25 98688 98713
780 25 parent->state &= ~PDL_DATAFLOW_F;
781 25 trans->flags |= PDL_ITRANS_DO_DATAFLOW_F;
782 }
783 }
784 86697 char dataflow = !!(trans->flags & PDL_ITRANS_DO_DATAFLOW_ANY);
785 86697 ▶ PDLDEBUG_f(printf("make_trans_mutual dataflow=%d disable_back=%d\n", (int)dataflow, (int)disable_back));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_trans_mutual dataflow=%d disable_back=%d\n", (int)dataflow, (int)disable_back)); 0 86697 86697
786 86697 ▶ if (dataflow && disable_back)
Branch: 2 branches
BranchTrueFalseTotal
if (dataflow && disable_back) 56862 29835 86697
if (dataflow && disable_back) 3 56859 56862
787 3 trans->flags &= ~PDL_ITRANS_DO_DATAFLOW_B;
788 86697 PDL_BITFIELD_ENT wasnull[PDL_BITFIELD_SIZE(npdls)];
789 173397 ▶ PDL_BITFIELD_ZEROISE(wasnull, npdls);
Branch: 1 branch
BranchTrueFalseTotal
PDL_BITFIELD_ZEROISE(wasnull, npdls); 86700 86697 173397
790 174853 ▶ for (i=nparents; i<npdls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=nparents; i<npdls; i++) { 88156 86697 174853
791 88156 pdl *child = pdls[i];
792 88156 ▶ if (child->state & PDL_NOMYDIMS) PDL_BITFIELD_SET(wasnull, i);
Branch: 1 branch
BranchTrueFalseTotal
if (child->state & PDL_NOMYDIMS) PDL_BITFIELD_SET(wasnull, i); 73401 14755 88156
793 88156 ▶ PDLDEBUG_f(printf("make_trans_mutual child=%p wasnull[%"IND_FLAG"]=%d\n", child, i, PDL_BITFIELD_ISSET(wasnull, i)));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_trans_mutual child=%p wasnull[%"IND_FLAG"]=%d\n", child, i, PDL_BITFIELD_ISSET(wasnull, i))); 0 88156 88156
794 88156 ▶ if (dataflow) {
Branch: 1 branch
BranchTrueFalseTotal
if (dataflow) { 56862 31294 88156
795 /* This is because for "+=" (a = a + b) we must check for
796 previous parent transformations and mutate if they exist
797 if no dataflow. */
798 56862 ▶ PDLDEBUG_f(printf("make_trans_mutual turning on allchanged, before="); pdl_dump_flags_fixspace(child->state, 0, PDL_FLAGS_PDL));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_trans_mutual turning on allchanged, before="); pdl_dump_flags_fixspace(child->state, 0, PDL_FLAGS_PDL)); 0 56862 56862
799 56862 ▶ child->state |= PDL_PARENTDIMSCHANGED | ((trans->flags & PDL_ITRANS_ISAFFINE) ? 0 : PDL_PARENTDATACHANGED);
Branch: 1 branch
BranchTrueFalseTotal
child->state |= PDL_PARENTDIMSCHANGED | ((trans->flags & PDL_ITRANS_ISAFFINE) ? 0 : PDL_PARENTDATACHANGED); 24823 32039 56862
800 56862 ▶ PDLDEBUG_f(printf("make_trans_mutual after change="); pdl_dump_flags_fixspace(child->state, 0, PDL_FLAGS_PDL));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_trans_mutual after change="); pdl_dump_flags_fixspace(child->state, 0, PDL_FLAGS_PDL)); 0 56862 56862
801 }
802 88156 ▶ if (!child->trans_parent || PDL_BITFIELD_ISSET(wasnull, i)) child->trans_parent = trans;
Branch: 2 branches
BranchTrueFalseTotal
if (!child->trans_parent || PDL_BITFIELD_ISSET(wasnull, i)) child->trans_parent = trans; 6909 81247 88156
if (!child->trans_parent || PDL_BITFIELD_ISSET(wasnull, i)) child->trans_parent = trans; 0 6909 6909
803 88156 ▶ if (PDL_BITFIELD_ISSET(wasnull, i))
Branch: 1 branch
BranchTrueFalseTotal
if (PDL_BITFIELD_ISSET(wasnull, i)) 73401 14755 88156
804 73401 child->state = (child->state & ~PDL_NOMYDIMS) | PDL_MYDIMS_TRANS;
805 }
806 86697 ▶ if (inputs_bad)
Branch: 1 branch
BranchTrueFalseTotal
if (inputs_bad) 2427 84270 86697
807 4927 ▶ for (i=nparents; i<npdls; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=nparents; i<npdls; i++) 2500 2427 4927
808 2500 pdl_propagate_badflag_dir(pdls[i], 1, 1, 1);
809 86697 ▶ if (!dataflow) {
Branch: 1 branch
BranchTrueFalseTotal
if (!dataflow) { 29835 56862 86697
810 29835 ▶ PDL_ACCUMERROR(PDL_err, pdl__ensure_trans(trans, PDL_PARENTDIMSCHANGED, 0, 0));
Branch: 1 branch
BranchTrueFalseTotal
PDL_ACCUMERROR(PDL_err, pdl__ensure_trans(trans, PDL_PARENTDIMSCHANGED, 0, 0)); 41 29794 29835
811 29835 ▶ if (PDL_err.error)
Branch: 1 branch
BranchTrueFalseTotal
if (PDL_err.error) 41 29794 29835
812 41 ▶ PDLDEBUG_f(printf("make_trans_mutual got error in ensure, not calling CHANGED on children\n"));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_trans_mutual got error in ensure, not calling CHANGED on children\n")); 0 41 41
813 else
814 61029 ▶ for (i=vtable->nparents; i<vtable->npdls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=vtable->nparents; i<vtable->npdls; i++) { 31235 29794 61029
815 31235 pdl *child = trans->pdls[i];
816 31235 char isvaffine = !!PDL_VAFFOK(child);
817 31235 ▶ PDLDEBUG_f(printf("make_trans_mutual isvaffine=%d wasnull=%d\n", (int)isvaffine, PDL_BITFIELD_ISSET(wasnull, i)));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_trans_mutual isvaffine=%d wasnull=%d\n", (int)isvaffine, PDL_BITFIELD_ISSET(wasnull, i))); 0 31235 31235
818 31235 ▶ if (!isvaffine || PDL_BITFIELD_ISSET(wasnull, i))
Branch: 2 branches
BranchTrueFalseTotal
if (!isvaffine || PDL_BITFIELD_ISSET(wasnull, i)) 5308 25927 31235
if (!isvaffine || PDL_BITFIELD_ISSET(wasnull, i)) 0 5308 5308
819 25927 ▶ CHANGED(child, PDL_BITFIELD_ISSET(wasnull, i) ? PDL_PARENTDIMSCHANGED : PDL_PARENTDATACHANGED, 0);
Branch: 2 branches
BranchTrueFalseTotal
CHANGED(child, PDL_BITFIELD_ISSET(wasnull, i) ? PDL_PARENTDIMSCHANGED : PDL_PARENTDATACHANGED, 0); 16555 9372 25927
CHANGED(child, PDL_BITFIELD_ISSET(wasnull, i) ? PDL_PARENTDIMSCHANGED : PDL_PARENTDATACHANGED, 0); 0 25927 25927
820 31235 ▶ if (isvaffine)
Branch: 1 branch
BranchTrueFalseTotal
if (isvaffine) 5308 25927 31235
821 5308 ▶ CHANGED(child->vafftrans->from,PDL_PARENTDATACHANGED,0);
Branch: 1 branch
BranchTrueFalseTotal
CHANGED(child->vafftrans->from,PDL_PARENTDATACHANGED,0); 0 5308 5308
822 }
823 29835 ▶ PDL_ACCUMERROR(PDL_err, pdl_destroytransform(trans,0,0));
Branch: 1 branch
BranchTrueFalseTotal
PDL_ACCUMERROR(PDL_err, pdl_destroytransform(trans,0,0)); 0 29835 29835
824 }
825 86697 ▶ PDLDEBUG_f(printf("make_trans_mutual exit %p\n",trans));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_trans_mutual exit %p\n",trans)); 0 86697 86697
826 86697 return PDL_err;
827 } /* pdl_make_trans_mutual() */
828  
829 44510 pdl_error pdl_redodims_default(pdl_trans *trans) {
830 44510 pdl_error PDL_err = {0, NULL, 0};
831 44510 ▶ PDLDEBUG_f(printf("pdl_redodims_default ");pdl_dump_trans_fixspace(trans,0));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_redodims_default ");pdl_dump_trans_fixspace(trans,0)); 0 44510 44510
832 44510 pdl_transvtable *vtable = trans->vtable;
833 44510 ▶ if (vtable->flags & PDL_TRANS_DO_BROADCAST) {
Branch: 1 branch
BranchTrueFalseTotal
if (vtable->flags & PDL_TRANS_DO_BROADCAST) { 44506 4 44510
834 44506 PDL_Indx creating[vtable->npdls], i, j;
835 44506 pdl **pdls = trans->pdls;
836 153481 ▶ for (i=0; i<vtable->npdls; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<vtable->npdls; i++) 108975 44506 153481
837 148851 ▶ creating[i] = (vtable->par_flags[i] & PDL_PARAM_ISCREAT) &&
Branch: 1 branch
BranchTrueFalseTotal
creating[i] = (vtable->par_flags[i] & PDL_PARAM_ISCREAT) && 39876 69099 108975
838 39876 ▶ PDL_DIMS_FROM_TRANS(trans,pdls[i]);
Branch: 2 branches
BranchTrueFalseTotal
PDL_DIMS_FROM_TRANS(trans,pdls[i]); 38072 1804 39876
PDL_DIMS_FROM_TRANS(trans,pdls[i]); 31240 6832 38072
839 44523 ▶ PDL_RETERROR(PDL_err, pdl_initbroadcaststruct(2, pdls,
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_initbroadcaststruct(2, pdls, 13 44493 44506
840 vtable->par_realdims, creating, vtable->npdls, vtable,
841 &trans->broadcast, NULL, NULL,
842 NULL, vtable->flags & PDL_TRANS_NO_PARALLEL));
843 44493 ▶ PDL_RETERROR(PDL_err, pdl_dim_checks(vtable, pdls, &trans->broadcast, trans->broadcast.nimpl, creating, trans->ind_sizes, 0));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_dim_checks(vtable, pdls, &trans->broadcast, trans->broadcast.nimpl, creating, trans->ind_sizes, 0)); 17 44476 44493
844 153361 ▶ for (i=0; i<vtable->npdls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<vtable->npdls; i++) { 108885 44476 153361
845 108885 PDL_Indx ninds = vtable->par_realdims[i];
846 108885 short flags = vtable->par_flags[i];
847 108885 ▶ if (!creating[i]) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!creating[i]) continue; 77649 31236 108885
848 31236 PDL_Indx dims[PDLMAX(ninds+1, 1)];
849 45446 ▶ for (j=0; j<ninds; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (j=0; j<ninds; j++) 14210 31236 45446
850 14210 dims[j] = trans->ind_sizes[PDL_IND_ID(vtable, i, j)];
851 31236 ▶ if (flags & PDL_PARAM_ISTEMP)
Branch: 1 branch
BranchTrueFalseTotal
if (flags & PDL_PARAM_ISTEMP) 253 30983 31236
852 253 dims[ninds] = 1;
853 31236 ▶ PDL_RETERROR(PDL_err, pdl_broadcast_create_parameter(
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_broadcast_create_parameter( 0 31236 31236
854 &trans->broadcast,i,dims,
855 flags & PDL_PARAM_ISTEMP
856 ));
857 }
858 153361 ▶ for (i=0; i<vtable->npdls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<vtable->npdls; i++) { 108885 44476 153361
859 108885 pdl *pdl = pdls[i];
860 158917 ▶ for (j=0; j<vtable->par_realdims[i]; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (j=0; j<vtable->par_realdims[i]; j++) 50032 108885 158917
861 50032 trans->inc_sizes[PDL_INC_ID(vtable,i,j)] =
862 50032 ▶ (pdl->ndims <= j || pdl->dims[j] <= 1) ? 0 :
Branch: 2 branches
BranchTrueFalseTotal
(pdl->ndims <= j || pdl->dims[j] <= 1) ? 0 : 38437 11595 50032
(pdl->ndims <= j || pdl->dims[j] <= 1) ? 0 : 24387 14050 38437
863 24387 ▶ PDL_REPRINC(pdl,j);
Branch: 1 branch
BranchTrueFalseTotal
PDL_REPRINC(pdl,j); 7886 16501 24387
864 }
865 }
866 44480 pdl_hdr_childcopy(trans);
867 44480 trans->dims_redone = 1;
868 44480 return PDL_err;
869 }
870  
871 198861 pdl_error pdl__make_physical_recprotect(pdl *it, int recurse_count) {
872 198861 pdl_error PDL_err = {0, NULL, 0};
873 198861 ▶ PDL_RECURSE_CHECK(recurse_count);
Branch: 1 branch
BranchTrueFalseTotal
PDL_RECURSE_CHECK(recurse_count); 0 198861 198861
874 198861 ▶ PDLDEBUG_f(printf("make_physical %p\n",it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physical %p\n",it)); 0 198861 198861
875 198861 pdl_trans *trans = it->trans_parent;
876 198861 ▶ PDL_CHKMAGIC(it);
Branch: 2 branches
BranchTrueFalseTotal
PDL_CHKMAGIC(it); 0 198861 198861
PDL_CHKMAGIC(it); 0 0 0
877 198861 if (
878 198861 ▶ !(it->state & PDL_ANYCHANGED) && /* unchanged and */
Branch: 2 branches
BranchTrueFalseTotal
!(it->state & PDL_ANYCHANGED) && /* unchanged and */ 166135 32726 198861
!(it->state & PDL_ANYCHANGED) && /* unchanged and */ 39055 127080 166135
879 39055 ▶ !(trans && !(it->state & PDL_ALLOCATED) && (trans->flags & PDL_ITRANS_ISAFFINE)) /* not pure vaffine in waiting */
Branch: 2 branches
BranchTrueFalseTotal
!(trans && !(it->state & PDL_ALLOCATED) && (trans->flags & PDL_ITRANS_ISAFFINE)) /* not pure vaffine in waiting */ 23397 15658 39055
!(trans && !(it->state & PDL_ALLOCATED) && (trans->flags & PDL_ITRANS_ISAFFINE)) /* not pure vaffine in waiting */ 17227 6170 23397
880 ) {
881 159965 ▶ PDL_ENSURE_ALLOCATED(it);
Branch: 2 branches
BranchTrueFalseTotal
PDL_ENSURE_ALLOCATED(it); 27289 132676 159965
PDL_ENSURE_ALLOCATED(it); 1 27288 27289
882 } else {
883 38896 ▶ if (!trans)
Branch: 1 branch
BranchTrueFalseTotal
if (!trans) 0 38896 38896
884 0 return pdl_make_error_simple(PDL_EFATAL, "PDL Not physical but doesn't have parent");
885 38896 ▶ if (trans->flags & PDL_ITRANS_ISAFFINE) {
Branch: 1 branch
BranchTrueFalseTotal
if (trans->flags & PDL_ITRANS_ISAFFINE) { 6399 32497 38896
886 6399 ▶ PDLDEBUG_f(printf("make_physical: affine\n"));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physical: affine\n")); 0 6399 6399
887 6399 trans->pdls[1]->state |= PDL_PARENTDATACHANGED;
888 6399 ▶ PDL_RETERROR(PDL_err, pdl__make_physvaffine_recprotect(it, recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__make_physvaffine_recprotect(it, recurse_count+1)); 4 6395 6399
889 } else
890 32497 ▶ PDL_RETERROR(PDL_err, pdl__ensure_trans(trans,0,1,recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__ensure_trans(trans,0,1,recurse_count+1)); 1 32496 32497
891 }
892 198855 ▶ PDLDEBUG_f(printf("make_physical exiting: "); pdl_dump(it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physical exiting: "); pdl_dump(it)); 0 198855 198855
893 198855 return PDL_err;
894 }
895  
896 22076 pdl_error pdl_make_physical(pdl *it) {
897 22076 return pdl__make_physical_recprotect(it, 0);
898 }
899  
900 /* recursing = 0 when heading upwards, 1 when it reaches top and starts going downwards */
901 95076 pdl_error pdl_changed(pdl *it, int what, int recursing) {
902 95076 pdl_error PDL_err = {0, NULL, 0};
903 PDL_Indx i, j;
904 95076 ▶ PDLDEBUG_f(
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f( 0 95076 95076
905 printf("pdl_changed: entry for pdl %p recursing: %d, what=",it,recursing);
906 pdl_dump_flags_fixspace(what,0,PDL_FLAGS_PDL);
907 );
908 95076 pdl_trans *trans = it->trans_parent;
909 95076 ▶ if (recursing) {
Branch: 1 branch
BranchTrueFalseTotal
if (recursing) { 17956 77120 95076
910 17956 ▶ PDLDEBUG_f(printf("pdl_changed: adding what to state except pure vaff, currently="); pdl_dump_flags_fixspace(it->state,0,PDL_FLAGS_PDL));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_changed: adding what to state except pure vaff, currently="); pdl_dump_flags_fixspace(it->state,0,PDL_FLAGS_PDL)); 0 17956 17956
911 7434 ▶ it->state |= !( /* neither */
Branch: 1 branch
BranchTrueFalseTotal
it->state |= !( /* neither */ 7434 0 7434
912 17956 ((it->state & (PDL_OPT_VAFFTRANSOK|PDL_ALLOCATED)) == PDL_OPT_VAFFTRANSOK) || /* already pure vaff nor */
913 7434 ▶ (trans && !(it->state & PDL_ALLOCATED) && (trans->flags & PDL_ITRANS_ISAFFINE)) /* pure vaffine in waiting */
Branch: 2 branches
BranchTrueFalseTotal
(trans && !(it->state & PDL_ALLOCATED) && (trans->flags & PDL_ITRANS_ISAFFINE)) /* pure vaffine in waiting */ 486 6948 7434
(trans && !(it->state & PDL_ALLOCATED) && (trans->flags & PDL_ITRANS_ISAFFINE)) /* pure vaffine in waiting */ 360 126 486
914 25390 ▶ ) ? what : what & ~PDL_PARENTDATACHANGED;
Branch: 1 branch
BranchTrueFalseTotal
) ? what : what & ~PDL_PARENTDATACHANGED; 7434 10522 17956
915 17956 ▶ if (pdl__ismagic(it)) pdl__call_magic(it,PDL_MAGIC_MARKCHANGED);
Branch: 1 branch
BranchTrueFalseTotal
if (pdl__ismagic(it)) pdl__call_magic(it,PDL_MAGIC_MARKCHANGED); 1 17955 17956
916 }
917 95076 ▶ if (trans && !recursing && (trans->flags & PDL_ITRANS_DO_DATAFLOW_B)
Branch: 3 branches
BranchTrueFalseTotal
if (trans && !recursing && (trans->flags & PDL_ITRANS_DO_DATAFLOW_B) 49172 45904 95076
if (trans && !recursing && (trans->flags & PDL_ITRANS_DO_DATAFLOW_B) 31216 17956 49172
if (trans && !recursing && (trans->flags & PDL_ITRANS_DO_DATAFLOW_B) 6882 24334 31216
918 6882 ▶ && (what & PDL_PARENTDATACHANGED)) {
Branch: 1 branch
BranchTrueFalseTotal
&& (what & PDL_PARENTDATACHANGED)) { 6882 0 6882
919 6882 ▶ if (it->vafftrans) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->vafftrans) { 147 6735 6882
920 147 ▶ if (it->state & PDL_ALLOCATED) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->state & PDL_ALLOCATED) { 146 1 147
921 146 ▶ PDLDEBUG_f(printf("pdl_changed: calling writebackdata_vaffine (pdl %p)\n",it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_changed: calling writebackdata_vaffine (pdl %p)\n",it)); 0 146 146
922 146 ▶ PDL_ACCUMERROR(PDL_err, pdl_writebackdata_vaffine(it));
Branch: 1 branch
BranchTrueFalseTotal
PDL_ACCUMERROR(PDL_err, pdl_writebackdata_vaffine(it)); 0 146 146
923 }
924 147 ▶ CHANGED(it->vafftrans->from,what,0);
Branch: 1 branch
BranchTrueFalseTotal
CHANGED(it->vafftrans->from,what,0); 0 147 147
925 } else {
926 6735 ▶ PDLDEBUG_f(printf("pdl_changed: calling writebackdata from vtable, triggered by pdl %p, using trans %p\n",it,trans));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_changed: calling writebackdata from vtable, triggered by pdl %p, using trans %p\n",it,trans)); 0 6735 6735
927 37704 ▶ WRITEDATA(trans);
Branch: 13 branches
BranchTrueFalseTotal
WRITEDATA(trans); 0 6735 6735
WRITEDATA(trans); 6735 6735 13470
WRITEDATA(trans); 12117 0 12117
WRITEDATA(trans); 14 12103 12117
WRITEDATA(trans); 12117 6735 18852
WRITEDATA(trans); 0 6735 6735
WRITEDATA(trans); 0 0 0
WRITEDATA(trans); 6735 0 6735
WRITEDATA(trans); 0 6735 6735
WRITEDATA(trans); 0 12117 12117
WRITEDATA(trans); 12117 0 12117
WRITEDATA(trans); 0 12117 12117
WRITEDATA(trans); 12117 6735 18852
928 18852 ▶ for (i=0; i<trans->vtable->nparents; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<trans->vtable->nparents; i++) { 12117 6735 18852
929 12117 pdl *pdl = trans->pdls[i];
930 12117 ▶ CHANGED(PDL_VAFFOK(pdl) ? pdl->vafftrans->from : pdl, what, 0);
Branch: 2 branches
BranchTrueFalseTotal
CHANGED(PDL_VAFFOK(pdl) ? pdl->vafftrans->from : pdl, what, 0); 4057 8060 12117
CHANGED(PDL_VAFFOK(pdl) ? pdl->vafftrans->from : pdl, what, 0); 0 12117 12117
931 }
932 }
933 } else {
934 PDL_Indx i;
935 617603 ▶ for (i = 0; i < it->ntrans_children_allocated; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < it->ntrans_children_allocated; i++) { 529409 88194 617603
936 529409 pdl_trans *trans = it->trans_children[i];
937 529409 ▶ if (!trans || !(trans->flags & PDL_ITRANS_DO_DATAFLOW_F)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!trans || !(trans->flags & PDL_ITRANS_DO_DATAFLOW_F)) continue; 26542 502867 529409
if (!trans || !(trans->flags & PDL_ITRANS_DO_DATAFLOW_F)) continue; 2918 23624 26542
938 47248 ▶ for (j=trans->vtable->nparents; j<trans->vtable->npdls; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (j=trans->vtable->nparents; j<trans->vtable->npdls; j++) 23624 23624 47248
939 23624 ▶ if (trans->pdls[j] != it && (trans->pdls[j]->state & what) != what)
Branch: 2 branches
BranchTrueFalseTotal
if (trans->pdls[j] != it && (trans->pdls[j]->state & what) != what) 23624 0 23624
if (trans->pdls[j] != it && (trans->pdls[j]->state & what) != what) 17956 5668 23624
940 17956 ▶ CHANGED(trans->pdls[j],what,1);
Branch: 1 branch
BranchTrueFalseTotal
CHANGED(trans->pdls[j],what,1); 0 17956 17956
941 }
942 }
943 95076 ▶ PDLDEBUG_f(printf("pdl_changed: exiting for pdl %p\n", it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_changed: exiting for pdl %p\n", it)); 0 95076 95076
944 95076 return PDL_err;
945 }
946  
947 /* pdl_make_physvaffine can be called on *any* pdl -- vaffine or not --
948 it will call make_physical as needed on those
949 this function is the right one to call in any case if you want to
950 make only those physical (i.e. allocating their own data, etc) which
951 have to be and leave those vaffine with updated dims, etc, that do
952 have an appropriate transformation of which they are a child.
953 should probably have been called make_physcareful to point out what
954 it really does
955 */
956 131457 pdl_error pdl__make_physvaffine_recprotect(pdl *it, int recurse_count)
957 {
958 131457 pdl_error PDL_err = {0, NULL, 0};
959 PDL_Indx i,j;
960 131457 ▶ PDLDEBUG_f(printf("make_physvaffine %p calling ",it)); PDL_RETERROR(PDL_err, pdl__make_physdims_recprotect(it, recurse_count+1));
Branch: 2 branches
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physvaffine %p calling ",it)); PDL_RETERROR(PDL_err, pdl__make_physdims_recprotect(it, recurse_count+1)); 0 131457 131457
PDLDEBUG_f(printf("make_physvaffine %p calling ",it)); PDL_RETERROR(PDL_err, pdl__make_physdims_recprotect(it, recurse_count+1)); 20 131437 131457
961 131437 ▶ if (!it->trans_parent || !(it->trans_parent->flags & PDL_ITRANS_ISAFFINE)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!it->trans_parent || !(it->trans_parent->flags & PDL_ITRANS_ISAFFINE)) { 76510 54927 131437
if (!it->trans_parent || !(it->trans_parent->flags & PDL_ITRANS_ISAFFINE)) { 47101 29409 76510
962 102028 ▶ PDLDEBUG_f(printf("make_physvaffine handing off to make_physical %p\n",it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physvaffine handing off to make_physical %p\n",it)); 0 102028 102028
963 102028 return pdl__make_physical_recprotect(it, recurse_count+1);
964 }
965 29409 ▶ if (!it->vafftrans || it->vafftrans->ndims < it->ndims) {
Branch: 2 branches
BranchTrueFalseTotal
if (!it->vafftrans || it->vafftrans->ndims < it->ndims) { 6635 22774 29409
if (!it->vafftrans || it->vafftrans->ndims < it->ndims) { 2 6633 6635
966 22776 ▶ PDL_RETERROR(PDL_err, pdl_vafftrans_alloc(it));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_vafftrans_alloc(it)); 0 22776 22776
967 51742 ▶ for (i=0; i<it->ndims; i++) it->vafftrans->incs[i] = it->dimincs[i];
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<it->ndims; i++) it->vafftrans->incs[i] = it->dimincs[i]; 28966 22776 51742
968 22776 it->vafftrans->offs = 0;
969 22776 pdl *current = it;
970 22776 pdl_trans *t=it->trans_parent;
971 26165 do {
972 26165 ▶ if (!t->incs)
Branch: 1 branch
BranchTrueFalseTotal
if (!t->incs) 0 26165 26165
973 0 return pdl_make_error(PDL_EUSERERROR, "make_physvaffine: affine trans %p has NULL incs\n", t);
974 26165 pdl *parent = t->pdls[0];
975 26165 PDL_Indx incsleft[it->ndims];
976 /* For all dimensions of the childest ndarray */
977 61553 ▶ for (i=0; i<it->ndims; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<it->ndims; i++) { 35388 26165 61553
978 /* inc = the increment at the current stage */
979 35388 ▶ PDL_Indx inc = it->vafftrans->incs[i], incsign = (inc >= 0 ? 1:-1), newinc = 0;
Branch: 1 branch
BranchTrueFalseTotal
PDL_Indx inc = it->vafftrans->incs[i], incsign = (inc >= 0 ? 1:-1), newinc = 0; 35385 3 35388
980 35388 inc *= incsign;
981 /* For all dimensions of the current ndarray */
982 94484 ▶ for (j=current->ndims-1; j>=0 && current->dimincs[j] != 0; j--) {
Branch: 2 branches
BranchTrueFalseTotal
for (j=current->ndims-1; j>=0 && current->dimincs[j] != 0; j--) { 59178 35306 94484
for (j=current->ndims-1; j>=0 && current->dimincs[j] != 0; j--) { 59096 82 59178
983 /* If the absolute value > this so */
984 /* we have a contribution from this dimension */
985 59096 ▶ if (inc < current->dimincs[j]) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (inc < current->dimincs[j]) continue; 23856 35240 59096
986 /* We used this many of this dim */
987 35240 PDL_Indx ninced = inc / current->dimincs[j];
988 35240 newinc += t->incs[j]*ninced;
989 35240 inc %= current->dimincs[j];
990 }
991 35388 incsleft[i] = incsign*newinc;
992 }
993 61553 ▶ for (i=0; i<it->ndims; i++) it->vafftrans->incs[i] = incsleft[i];
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<it->ndims; i++) it->vafftrans->incs[i] = incsleft[i]; 35388 26165 61553
994 26165 PDL_Indx offset_left = it->vafftrans->offs;
995 26165 PDL_Indx newinc = 0;
996 61813 ▶ for (j=current->ndims-1; j>=0 && current->dimincs[j] != 0; j--) {
Branch: 2 branches
BranchTrueFalseTotal
for (j=current->ndims-1; j>=0 && current->dimincs[j] != 0; j--) { 35688 26125 61813
for (j=current->ndims-1; j>=0 && current->dimincs[j] != 0; j--) { 35648 40 35688
997 35648 PDL_Indx cur_offset = offset_left / current->dimincs[j];
998 35648 offset_left -= cur_offset * current->dimincs[j];
999 35648 newinc += t->incs[j]*cur_offset;
1000 }
1001 26165 it->vafftrans->offs = newinc + t->offs;
1002 26165 t = (current = parent)->trans_parent;
1003 26165 ▶ } while (t && (t->flags & PDL_ITRANS_ISAFFINE) && !(current->state & PDL_ALLOCATED));
Branch: 3 branches
BranchTrueFalseTotal
} while (t && (t->flags & PDL_ITRANS_ISAFFINE) && !(current->state & PDL_ALLOCATED)); 9863 16302 26165
} while (t && (t->flags & PDL_ITRANS_ISAFFINE) && !(current->state & PDL_ALLOCATED)); 3459 6404 9863
} while (t && (t->flags & PDL_ITRANS_ISAFFINE) && !(current->state & PDL_ALLOCATED)); 3389 70 3459
1004 22776 it->vafftrans->from = current;
1005 22776 it->state |= PDL_OPT_VAFFTRANSOK;
1006 }
1007 29409 ▶ PDLDEBUG_f(printf("make_physvaffine %p, physicalising final parent=%p\n", it, it->vafftrans->from));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physvaffine %p, physicalising final parent=%p\n", it, it->vafftrans->from)); 0 29409 29409
1008 29409 ▶ PDL_RETERROR(PDL_err, pdl__make_physical_recprotect(it->vafftrans->from, recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__make_physical_recprotect(it->vafftrans->from, recurse_count+1)); 0 29409 29409
1009 29409 ▶ if (it->state & PDL_PARENTDATACHANGED) {
Branch: 1 branch
BranchTrueFalseTotal
if (it->state & PDL_PARENTDATACHANGED) { 6459 22950 29409
1010 6459 char already_allocated = (it->state & PDL_ALLOCATED);
1011 6459 ▶ PDL_ENSURE_ALLOCATED(it);
Branch: 2 branches
BranchTrueFalseTotal
PDL_ENSURE_ALLOCATED(it); 6324 135 6459
PDL_ENSURE_ALLOCATED(it); 0 6324 6324
1012 6459 ▶ PDL_RETERROR(PDL_err, pdl_readdata_vaffine(it));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_readdata_vaffine(it)); 0 6459 6459
1013 6459 ▶ PDLDEBUG_f(printf("make_physvaffine pdl=%p turning off datachanged and OPT_VAFFTRANSOK, before=", it); pdl_dump_flags_fixspace(it->state, 0, PDL_FLAGS_PDL));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physvaffine pdl=%p turning off datachanged and OPT_VAFFTRANSOK, before=", it); pdl_dump_flags_fixspace(it->state, 0, PDL_FLAGS_PDL)); 0 6459 6459
1014 6459 it->state &= ~(PDL_PARENTDATACHANGED|PDL_OPT_VAFFTRANSOK);
1015 6459 ▶ if (!already_allocated) pdl_vafftrans_remove(it, 0);
Branch: 1 branch
BranchTrueFalseTotal
if (!already_allocated) pdl_vafftrans_remove(it, 0); 6324 135 6459
1016 }
1017 29409 ▶ PDLDEBUG_f(printf("make_physvaffine exit %p\n", it));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("make_physvaffine exit %p\n", it)); 0 29409 29409
1018 29409 return PDL_err;
1019 }
1020  
1021 43510 pdl_error pdl_make_physvaffine(pdl *it)
1022 {
1023 43510 return pdl__make_physvaffine_recprotect(it, 0);
1024 }
1025  
1026 8884 pdl_error pdl_set_datatype(pdl *a, pdl_datatypes datatype)
1027 {
1028 8884 pdl_error PDL_err = {0, NULL, 0};
1029 PDL_Indx i;
1030 62182 ▶ for (i = 0; i < a->ntrans_children_allocated; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < a->ntrans_children_allocated; i++) { 53299 8883 62182
1031 53299 ▶ if (a->trans_children[i])
Branch: 1 branch
BranchTrueFalseTotal
if (a->trans_children[i]) 1 53298 53299
1032 1 return pdl_make_error_simple(PDL_EUSERERROR, "set_datatype: ndarray has child transform");
1033 }
1034 8883 ▶ if (a->trans_parent)
Branch: 1 branch
BranchTrueFalseTotal
if (a->trans_parent) 1 8882 8883
1035 1 ▶ PDL_RETERROR(PDL_err, pdl_destroytransform(a->trans_parent,1,0));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_destroytransform(a->trans_parent,1,0)); 0 1 1
1036 8883 ▶ if (a->state & PDL_NOMYDIMS)
Branch: 1 branch
BranchTrueFalseTotal
if (a->state & PDL_NOMYDIMS) 8798 85 8883
1037 8798 a->datatype = datatype;
1038 else
1039 85 ▶ PDL_RETERROR(PDL_err, pdl_converttype( a, datatype ));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_converttype( a, datatype )); 0 85 85
1040 8883 return PDL_err;
1041 }
1042  
1043 6427 pdl_error pdl_sever(pdl *src)
1044 {
1045 6427 pdl_error PDL_err = {0, NULL, 0};
1046 6427 ▶ if (!src->trans_parent) return PDL_err;
Branch: 1 branch
BranchTrueFalseTotal
if (!src->trans_parent) return PDL_err; 138 6289 6427
1047 6289 ▶ PDL_RETERROR(PDL_err, pdl_make_physvaffine(src));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_make_physvaffine(src)); 0 6289 6289
1048 6289 ▶ PDL_RETERROR(PDL_err, pdl_destroytransform(src->trans_parent,1,0));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl_destroytransform(src->trans_parent,1,0)); 0 6289 6289
1049 6289 return PDL_err;
1050 }
1051  
1052 /* this resembles the pdl_changed logic and maybe should be in that */
1053 #define PDL_MAYBE_PROPAGATE_BADFLAG(t, newval, is_fwd) do { \
1054 pdl_transvtable *vtable = (t)->vtable; \
1055 PDL_Indx i, istart = is_fwd ? vtable->nparents : 0, iend = is_fwd ? vtable->npdls : vtable->nparents; \
1056 for (i = istart; i < iend; i++) { \
1057 pdl *tpdl = (t)->pdls[i]; \
1058 /* make sure we propagate if changed */ \
1059 if (!!newval != !!(tpdl->state & PDL_BADVAL)) \
1060 pdl_propagate_badflag_dir(tpdl, newval, is_fwd, recurse_count + 1); \
1061 } \
1062 } while (0)
1063 /* newval = 1 means set flag, 0 means clear it */
1064 3374 pdl_error pdl_propagate_badflag_dir(pdl *it, int newval, char is_fwd, int recurse_count) {
1065 3374 ▶ PDL_RECURSE_CHECK(recurse_count);
Branch: 1 branch
BranchTrueFalseTotal
PDL_RECURSE_CHECK(recurse_count); 0 3374 3374
1066 3374 ▶ PDLDEBUG_f(printf("pdl_propagate_badflag_dir pdl=%p newval=%d is_fwd=%d already=%d\n", it, newval, (int)is_fwd, !!(it->state & PDL_BADVAL)));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_propagate_badflag_dir pdl=%p newval=%d is_fwd=%d already=%d\n", it, newval, (int)is_fwd, !!(it->state & PDL_BADVAL))); 0 3374 3374
1067 3374 pdl_error PDL_err = {0, NULL, 0};
1068 3374 ▶ if (newval)
Branch: 1 branch
BranchTrueFalseTotal
if (newval) 2902 472 3374
1069 2902 it->state |= PDL_BADVAL;
1070 else
1071 472 it->state &= ~PDL_BADVAL;
1072 3374 pdl_trans *tp = it->trans_parent;
1073 3374 ▶ if (!is_fwd) {
Branch: 1 branch
BranchTrueFalseTotal
if (!is_fwd) { 7 3367 3374
1074 7 ▶ if (tp)
Branch: 1 branch
BranchTrueFalseTotal
if (tp) 2 5 7
1075 4 ▶ PDL_MAYBE_PROPAGATE_BADFLAG(tp, newval, 0);
Branch: 2 branches
BranchTrueFalseTotal
PDL_MAYBE_PROPAGATE_BADFLAG(tp, newval, 0); 2 0 2
PDL_MAYBE_PROPAGATE_BADFLAG(tp, newval, 0); 2 2 4
1076 } else {
1077 3367 ▶ PDLDEBUG_f(printf("pdl_propagate_badflag_dir forward pdl state="); pdl_dump_flags_fixspace(it->state, 0, PDL_FLAGS_PDL));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_propagate_badflag_dir forward pdl state="); pdl_dump_flags_fixspace(it->state, 0, PDL_FLAGS_PDL)); 0 3367 3367
1078 PDL_Indx j;
1079 3367 if ((
1080 3367 ▶ (it->state & (PDL_OPT_VAFFTRANSOK|PDL_ALLOCATED)) == PDL_OPT_VAFFTRANSOK || /* pure vaff */
Branch: 2 branches
BranchTrueFalseTotal
(it->state & (PDL_OPT_VAFFTRANSOK|PDL_ALLOCATED)) == PDL_OPT_VAFFTRANSOK || /* pure vaff */ 3366 1 3367
(it->state & (PDL_OPT_VAFFTRANSOK|PDL_ALLOCATED)) == PDL_OPT_VAFFTRANSOK || /* pure vaff */ 2746 620 3366
1081 2746 ▶ (tp && !(it->state & PDL_ALLOCATED) && (tp->flags & PDL_ITRANS_ISAFFINE)) /* pure vaffine in waiting */
Branch: 2 branches
BranchTrueFalseTotal
(tp && !(it->state & PDL_ALLOCATED) && (tp->flags & PDL_ITRANS_ISAFFINE)) /* pure vaffine in waiting */ 2432 314 2746
(tp && !(it->state & PDL_ALLOCATED) && (tp->flags & PDL_ITRANS_ISAFFINE)) /* pure vaffine in waiting */ 191 2241 2432
1082 192 ▶ ) && newval) /* expansive - if slice gets badflag, whole does */
Branch: 1 branch
BranchTrueFalseTotal
) && newval) /* expansive - if slice gets badflag, whole does */ 190 2 192
1083 380 ▶ PDL_MAYBE_PROPAGATE_BADFLAG(tp, newval, 0);
Branch: 2 branches
BranchTrueFalseTotal
PDL_MAYBE_PROPAGATE_BADFLAG(tp, newval, 0); 4 186 190
PDL_MAYBE_PROPAGATE_BADFLAG(tp, newval, 0); 190 190 380
1084 23577 ▶ for (j = 0; j < it->ntrans_children_allocated; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < it->ntrans_children_allocated; j++) { 20210 3367 23577
1085 20210 pdl_trans *trans = it->trans_children[j];
1086 20210 ▶ if (!trans) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!trans) continue; 19982 228 20210
1087 456 ▶ PDL_MAYBE_PROPAGATE_BADFLAG(trans, newval, 1);
Branch: 2 branches
BranchTrueFalseTotal
PDL_MAYBE_PROPAGATE_BADFLAG(trans, newval, 1); 8 220 228
PDL_MAYBE_PROPAGATE_BADFLAG(trans, newval, 1); 228 228 456
1088 }
1089 }
1090 3374 return PDL_err;
1091 }
1092 0 void pdl_propagate_badflag(pdl *it, int newval) { /* CORE21 get rid */
1093 0 return; /* nerfed as replaced with directional version */
1094 }
1095  
1096 /*CORE21 use pdl_error, replace fprintf*/
1097 44 void pdl_propagate_badvalue( pdl *it ) {
1098 PDL_Indx j;
1099 308 ▶ for (j = 0; j < it->ntrans_children_allocated; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < it->ntrans_children_allocated; j++) { 264 44 308
1100 264 pdl_trans *trans = it->trans_children[j];
1101 264 ▶ if (!trans) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!trans) continue; 262 2 264
1102 PDL_Indx i;
1103 4 ▶ for ( i = trans->vtable->nparents; i < trans->vtable->npdls; i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
for ( i = trans->vtable->nparents; i < trans->vtable->npdls; i++ ) { 2 2 4
1104 2 pdl *child = trans->pdls[i];
1105 PDL_Anyval typedval;
1106 2 ANYVAL_TO_ANYVAL_NEWTYPE(it->badvalue, typedval, child->datatype);
1107 2 ▶ if (typedval.type < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (typedval.type < 0) { 0 2 2
1108 0 fprintf(stderr, "propagate_badvalue: error making typedval\n");
1109 0 return;
1110 }
1111 2 child->has_badvalue = 1;
1112 2 child->badvalue = typedval;
1113 /* make sure we propagate to grandchildren, etc */
1114 2 pdl_propagate_badvalue( child );
1115 } /* for: i */
1116 }
1117 } /* pdl_propagate_badvalue */
1118  
1119 /*CORE21 unused*/
1120 0 PDL_Anyval pdl_get_badvalue( pdl_datatypes datatype ) {
1121 0 PDL_Anyval retval = { PDL_INVALID, {0} };
1122 #define X(datatype, ctype, ppsym, ...) \
1123 retval.type = datatype; retval.value.ppsym = PDL.bvals.ppsym;
1124 0 PDL_GENERICSWITCH(PDL_TYPELIST_ALL, datatype, X, return retval)
1125 #undef X
1126 0 return retval;
1127 }
1128  
1129 /*CORE21 unused*/
1130 0 PDL_Anyval pdl_get_pdl_badvalue( pdl *it ) {
1131 0 ▶ if (it->has_badvalue && it->badvalue.type != it->datatype)
Branch: 2 branches
BranchTrueFalseTotal
if (it->has_badvalue && it->badvalue.type != it->datatype) 0 0 0
if (it->has_badvalue && it->badvalue.type != it->datatype) 0 0 0
1132 0 return (PDL_Anyval){ PDL_INVALID, {0} };
1133 0 ▶ return it->has_badvalue ? it->badvalue : pdl_get_badvalue( it->datatype );
Branch: 1 branch
BranchTrueFalseTotal
return it->has_badvalue ? it->badvalue : pdl_get_badvalue( it->datatype ); 0 0 0
1134 }
1135  
1136 86716 pdl_trans *pdl_create_trans(pdl_transvtable *vtable) {
1137 86716 size_t it_sz = sizeof(pdl_trans)+(sizeof(pdl *) * vtable->npdls);
1138 86716 pdl_trans *it = malloc(it_sz);
1139 86716 ▶ if (!it) return it;
Branch: 1 branch
BranchTrueFalseTotal
if (!it) return it; 0 86716 86716
1140 86716 memset(it, 0, it_sz);
1141 86716 PDL_TR_SETMAGIC(it);
1142 86716 ▶ if (vtable->structsize) {
Branch: 1 branch
BranchTrueFalseTotal
if (vtable->structsize) { 50899 35817 86716
1143 50899 it->params = malloc(vtable->structsize);
1144 50899 ▶ if (!it->params) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!it->params) return NULL; 0 50899 50899
1145 50899 memset(it->params, 0, vtable->structsize);
1146 }
1147 86716 it->flags = vtable->iflags;
1148 86716 it->dims_redone = 0;
1149 86716 it->bvalflag = 0;
1150 86716 it->vtable = vtable;
1151 86716 PDL_CLRMAGIC(&it->broadcast);
1152 86716 it->broadcast.inds = 0;
1153 86716 it->broadcast.gflags = 0;
1154 86716 it->ind_sizes = (PDL_Indx *)malloc(sizeof(PDL_Indx) * (
1155 86716 vtable->ninds +
1156 86716 vtable->nparents /* CORE21 make separate member "trans_children_indices" */
1157 ));
1158 86716 ▶ if (!it->ind_sizes) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!it->ind_sizes) return NULL; 0 86716 86716
1159 208335 ▶ int i; for (i=0; i<vtable->ninds + vtable->nparents; i++) it->ind_sizes[i] = -1;
Branch: 1 branch
BranchTrueFalseTotal
int i; for (i=0; i<vtable->ninds + vtable->nparents; i++) it->ind_sizes[i] = -1; 121619 86716 208335
1160 86716 it->inc_sizes = (PDL_Indx *)malloc(sizeof(PDL_Indx) * vtable->nind_ids);
1161 86716 ▶ if (!it->inc_sizes) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!it->inc_sizes) return NULL; 0 86716 86716
1162 118586 ▶ for (i=0; i<vtable->nind_ids; i++) it->inc_sizes[i] = -1;
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<vtable->nind_ids; i++) it->inc_sizes[i] = -1; 31870 86716 118586
1163 86716 it->offs = -1;
1164 86716 it->incs = NULL;
1165 86716 it->__datatype = PDL_INVALID;
1166 86716 return it;
1167 }
1168  
1169 #define PDL_TYPE_ADJUST_FROM_SUPPLIED(type, f) ( \
1170 /* opposite test/actions from convert, complex only */ \
1171 ((f) & PDL_PARAM_ISREAL && (type) < PDL_CF) ? PDLMAX(PDL_CF,(type)+PDL_CF-PDL_F) : \
1172 ((f) & PDL_PARAM_ISCOMPLEX && (type) >= PDL_CF) ? (type)-PDL_CF+PDL_F : \
1173 (type))
1174 #define PDL_TYPE_ADJUST_FROM_TRANS(ttype, f, par_type) ( \
1175 ((f) & PDL_PARAM_ISTYPED) ? \
1176 (!((f) & PDL_PARAM_ISTPLUS) ? (par_type) : PDLMAX((par_type), (ttype))) : \
1177 ((f) & (PDL_PARAM_ISREAL|PDL_PARAM_ISNOTCOMPLEX) && (ttype) >= PDL_CF) ? \
1178 (ttype) - PDL_CF + PDL_F : \
1179 ((f) & PDL_PARAM_ISCOMPLEX && (ttype) < PDL_CF) ? \
1180 PDLMAX(PDL_CF, trans_dtype + PDL_CF - PDL_F) : \
1181 (ttype))
1182 71431 static inline pdl_error pdl__transtype_select(
1183 pdl_trans *trans, pdl_datatypes *retval
1184 ) {
1185 71431 pdl_error PDL_err = {0, NULL, 0};
1186 71431 *retval = PDL_INVALID;
1187 71431 pdl_transvtable *vtable = trans->vtable;
1188 71431 PDL_Indx i, nparents = vtable->nparents;
1189 227764 ▶ for (i=0; i<vtable->npdls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<vtable->npdls; i++) { 156340 71424 227764
1190 156340 pdl *pdl = trans->pdls[i];
1191 156340 ▶ if (i >= nparents && pdl->state & PDL_READONLY)
Branch: 2 branches
BranchTrueFalseTotal
if (i >= nparents && pdl->state & PDL_READONLY) 72887 83453 156340
if (i >= nparents && pdl->state & PDL_READONLY) 2 72885 72887
1192 2 return pdl_make_error(PDL_EUSERERROR,
1193 "%s error: output parameter %s is read-only",
1194 2 vtable->name, vtable->par_names[i]);
1195 156338 ▶ if (pdl->state & PDL_NOMYDIMS)
Branch: 1 branch
BranchTrueFalseTotal
if (pdl->state & PDL_NOMYDIMS) 58150 98188 156338
1196 58150 continue;
1197 98188 short flags = vtable->par_flags[i];
1198 98188 pdl_datatypes dtype = pdl->datatype;
1199 98188 ▶ if (flags & PDL_PARAM_ISNOTREAL && dtype < PDL_CF)
Branch: 2 branches
BranchTrueFalseTotal
if (flags & PDL_PARAM_ISNOTREAL && dtype < PDL_CF) 4 98184 98188
if (flags & PDL_PARAM_ISNOTREAL && dtype < PDL_CF) 1 3 4
1200 2 return pdl_make_error(PDL_EUSERERROR,
1201 "%s: ndarray %s must be complex, but is type %s",
1202 2 ▶ vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype));
Branch: 3 branches
BranchTrueFalseTotal
vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype)); 1 0 1
vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype)); 1 0 1
vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype)); 1 0 1
1203 98187 ▶ if (flags & PDL_PARAM_ISNOTCOMPLEX && dtype >= PDL_CF)
Branch: 2 branches
BranchTrueFalseTotal
if (flags & PDL_PARAM_ISNOTCOMPLEX && dtype >= PDL_CF) 242 97945 98187
if (flags & PDL_PARAM_ISNOTCOMPLEX && dtype >= PDL_CF) 4 238 242
1204 8 return pdl_make_error(PDL_EUSERERROR,
1205 "%s: ndarray %s must be real, but is type %s",
1206 8 ▶ vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype));
Branch: 3 branches
BranchTrueFalseTotal
vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype)); 4 0 4
vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype)); 4 0 4
vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype)); 4 0 4
1207 }
1208 PDL_BITFIELD_ENT type_avail[PDL_BITFIELD_SIZE(PDL_NTYPES)];
1209 214272 ▶ PDL_BITFIELD_ZEROISE(type_avail, PDL_NTYPES);
Branch: 1 branch
BranchTrueFalseTotal
PDL_BITFIELD_ZEROISE(type_avail, PDL_NTYPES); 142848 71424 214272
1210 71424 pdl_datatypes last_dtype = PDL_INVALID;
1211 1102663 ▶ for (i=0; vtable->gentypes[i] != PDL_INVALID; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; vtable->gentypes[i] != PDL_INVALID; i++) 1031239 71424 1102663
1212 1031239 PDL_BITFIELD_SET(type_avail, last_dtype = vtable->gentypes[i]);
1213 71424 ▶ if (vtable->gentypes[0] == last_dtype) {
Branch: 1 branch
BranchTrueFalseTotal
if (vtable->gentypes[0] == last_dtype) { 109 71315 71424
1214 109 *retval = vtable->gentypes[0]; /* only one allowed type, use that */
1215 109 return PDL_err;
1216 }
1217 71315 char use_last_dtype = 0;
1218 202296 ▶ for (i=vtable->npdls-1; i>= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=vtable->npdls-1; i>= 0; i--) { 145595 56701 202296
1219 145595 pdl *pdl = trans->pdls[i];
1220 145595 short flags = vtable->par_flags[i];
1221 145595 ▶ if (!(pdl->state & PDL_NOMYDIMS) &&
Branch: 1 branch
BranchTrueFalseTotal
if (!(pdl->state & PDL_NOMYDIMS) && 87712 57883 145595
1222 87712 ▶ !(flags & (PDL_PARAM_ISIGNORE|PDL_PARAM_ISTYPED|PDL_PARAM_ISCREATEALWAYS))
Branch: 1 branch
BranchTrueFalseTotal
!(flags & (PDL_PARAM_ISIGNORE|PDL_PARAM_ISTYPED|PDL_PARAM_ISCREATEALWAYS)) 79342 8370 87712
1223 ) {
1224 79342 ▶ pdl_datatypes new_transtype = PDL_TYPE_ADJUST_FROM_SUPPLIED(pdl->datatype, flags);
Branch: 4 branches
BranchTrueFalseTotal
pdl_datatypes new_transtype = PDL_TYPE_ADJUST_FROM_SUPPLIED(pdl->datatype, flags); 0 79342 79342
pdl_datatypes new_transtype = PDL_TYPE_ADJUST_FROM_SUPPLIED(pdl->datatype, flags); 0 0 0
pdl_datatypes new_transtype = PDL_TYPE_ADJUST_FROM_SUPPLIED(pdl->datatype, flags); 11 79331 79342
pdl_datatypes new_transtype = PDL_TYPE_ADJUST_FROM_SUPPLIED(pdl->datatype, flags); 11 0 11
1225 79342 char newtype_is_avail = PDL_BITFIELD_ISSET(type_avail, new_transtype);
1226 79342 ▶ if (!newtype_is_avail && new_transtype > last_dtype)
Branch: 2 branches
BranchTrueFalseTotal
if (!newtype_is_avail && new_transtype > last_dtype) 476 78866 79342
if (!newtype_is_avail && new_transtype > last_dtype) 138 338 476
1227 138 use_last_dtype = 1;
1228 79342 ▶ if (new_transtype != PDL_INVALID && newtype_is_avail && *retval < new_transtype)
Branch: 3 branches
BranchTrueFalseTotal
if (new_transtype != PDL_INVALID && newtype_is_avail && *retval < new_transtype) 79342 0 79342
if (new_transtype != PDL_INVALID && newtype_is_avail && *retval < new_transtype) 78866 476 79342
if (new_transtype != PDL_INVALID && newtype_is_avail && *retval < new_transtype) 72713 6153 78866
1229 72713 *retval = new_transtype;
1230 }
1231 145595 ▶ if (i == nparents && *retval != PDL_INVALID) return PDL_err;
Branch: 2 branches
BranchTrueFalseTotal
if (i == nparents && *retval != PDL_INVALID) return PDL_err; 71256 74339 145595
if (i == nparents && *retval != PDL_INVALID) return PDL_err; 14614 56642 71256
1232 }
1233 56701 ▶ if (use_last_dtype || *retval == PDL_INVALID || !PDL_BITFIELD_ISSET(type_avail, *retval))
Branch: 3 branches
BranchTrueFalseTotal
if (use_last_dtype || *retval == PDL_INVALID || !PDL_BITFIELD_ISSET(type_avail, *retval)) 56615 86 56701
if (use_last_dtype || *retval == PDL_INVALID || !PDL_BITFIELD_ISSET(type_avail, *retval)) 56442 173 56615
if (use_last_dtype || *retval == PDL_INVALID || !PDL_BITFIELD_ISSET(type_avail, *retval)) 0 56442 56442
1234 259 *retval = last_dtype;
1235 56701 return PDL_err;
1236 }
1237  
1238 #define PDL_HAS_OTHER_PARENT(p, t) \
1239 ((p)->trans_parent && (p)->trans_parent != (t))
1240 86707 pdl_error pdl__set_output_type_badvalue(pdl_trans *trans, int recurse_count) {
1241 86707 pdl_error PDL_err = {0, NULL, 0};
1242 86707 ▶ PDL_RECURSE_CHECK(recurse_count);
Branch: 1 branch
BranchTrueFalseTotal
PDL_RECURSE_CHECK(recurse_count); 0 86707 86707
1243 86707 pdl_datatypes trans_dtype = trans->__datatype;
1244 86707 pdl_transvtable *vtable = trans->vtable;
1245 86707 pdl **pdls = trans->pdls;
1246 PDL_Indx i;
1247 61973 ▶ char p2child_has_badvalue = (vtable->npdls == 2 && pdls[0]->has_badvalue
Branch: 1 branch
BranchTrueFalseTotal
char p2child_has_badvalue = (vtable->npdls == 2 && pdls[0]->has_badvalue 19 61954 61973
1248 148680 ▶ && (vtable->par_flags[1] & PDL_PARAM_ISCREATEALWAYS));
Branch: 2 branches
BranchTrueFalseTotal
&& (vtable->par_flags[1] & PDL_PARAM_ISCREATEALWAYS)); 61973 24734 86707
&& (vtable->par_flags[1] & PDL_PARAM_ISCREATEALWAYS)); 10 9 19
1249 86707 ▶ PDL_Anyval parent_badvalue = p2child_has_badvalue ? pdls[0]->badvalue : (PDL_Anyval){PDL_INVALID, {0}};
Branch: 1 branch
BranchTrueFalseTotal
PDL_Anyval parent_badvalue = p2child_has_badvalue ? pdls[0]->badvalue : (PDL_Anyval){PDL_INVALID, {0}}; 10 86697 86707
1250 273601 ▶ for (i=0; i<vtable->npdls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<vtable->npdls; i++) { 186894 86707 273601
1251 186894 short flags = vtable->par_flags[i];
1252 186894 ▶ if (flags & PDL_PARAM_ISIGNORE) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (flags & PDL_PARAM_ISIGNORE) continue; 15283 171611 186894
1253 171611 pdl *pdl = pdls[i];
1254 171611 ▶ if (!(pdl->state & PDL_NOMYDIMS) || PDL_HAS_OTHER_PARENT(pdl, trans)) continue;
Branch: 3 branches
BranchTrueFalseTotal
if (!(pdl->state & PDL_NOMYDIMS) || PDL_HAS_OTHER_PARENT(pdl, trans)) continue; 58172 113439 171611
if (!(pdl->state & PDL_NOMYDIMS) || PDL_HAS_OTHER_PARENT(pdl, trans)) continue; 0 58172 58172
if (!(pdl->state & PDL_NOMYDIMS) || PDL_HAS_OTHER_PARENT(pdl, trans)) continue; 0 0 0
1255 58172 pdl->badvalue = parent_badvalue;
1256 58172 pdl->has_badvalue = p2child_has_badvalue;
1257 58172 ▶ pdl->datatype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]);
Branch: 6 branches
BranchTrueFalseTotal
pdl->datatype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 5556 52616 58172
pdl->datatype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 4333 1223 5556
pdl->datatype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 207 52409 52616
pdl->datatype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 98 109 207
pdl->datatype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 96 52422 52518
pdl->datatype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 88 8 96
1258 }
1259 86707 return PDL_err;
1260 }
1261  
1262 71424 pdl_error pdl__type_convert(pdl_trans *trans, int recurse_count) {
1263 71424 pdl_error PDL_err = {0, NULL, 0};
1264 71424 ▶ PDL_RECURSE_CHECK(recurse_count);
Branch: 1 branch
BranchTrueFalseTotal
PDL_RECURSE_CHECK(recurse_count); 0 71424 71424
1265 71424 pdl_datatypes trans_dtype = trans->__datatype;
1266 71424 pdl_transvtable *vtable = trans->vtable;
1267 71424 pdl **pdls = trans->pdls;
1268 71424 PDL_Indx i, nparents = vtable->nparents, nchildren = vtable->npdls - nparents;
1269 71424 PDL_Indx j, inplace_input_ind = -1, inplace_output_ind = -1;
1270 71424 PDL_BITFIELD_ENT is_inout[PDL_BITFIELD_SIZE(nchildren)];
1271 142782 ▶ PDL_BITFIELD_ZEROISE(is_inout, nchildren);
Branch: 1 branch
BranchTrueFalseTotal
PDL_BITFIELD_ZEROISE(is_inout, nchildren); 71358 71424 142782
1272 144309 ▶ for (i=0; i < nchildren; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < nchildren; i++) { 72885 71424 144309
1273 72885 ▶ if (!(vtable->par_flags[i + nparents] & PDL_PARAM_ISCREAT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(vtable->par_flags[i + nparents] & PDL_PARAM_ISCREAT)) { 6095 66790 72885
1274 6095 PDL_BITFIELD_SET(is_inout, i);
1275 6095 continue;
1276 }
1277 66790 pdl *child = trans->pdls[i + nparents];
1278 147752 ▶ for (j=0; j < nparents; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j=0; j < nparents; j++) { 83648 64104 147752
1279 83648 pdl *parent = trans->pdls[j];
1280 83648 ▶ if (parent != child) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (parent != child) continue; 80962 2686 83648
1281 2686 PDL_BITFIELD_SET(is_inout, i);
1282 2686 inplace_output_ind = nparents + i, inplace_input_ind = j;
1283 2686 break;
1284 }
1285 }
1286 227749 ▶ for (i=vtable->npdls-1; i>=0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=vtable->npdls-1; i>=0; i--) { 156326 71423 227749
1287 156326 short flags = vtable->par_flags[i];
1288 297749 ▶ if (flags & PDL_PARAM_ISIGNORE) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (flags & PDL_PARAM_ISIGNORE) continue; 0 156326 156326
1289 156326 pdl *pdl = pdls[i];
1290 156326 ▶ if ((pdl->state & PDL_NOMYDIMS) && !PDL_HAS_OTHER_PARENT(pdl, trans)) continue;
Branch: 3 branches
BranchTrueFalseTotal
if ((pdl->state & PDL_NOMYDIMS) && !PDL_HAS_OTHER_PARENT(pdl, trans)) continue; 58150 98176 156326
if ((pdl->state & PDL_NOMYDIMS) && !PDL_HAS_OTHER_PARENT(pdl, trans)) continue; 0 58150 58150
if ((pdl->state & PDL_NOMYDIMS) && !PDL_HAS_OTHER_PARENT(pdl, trans)) continue; 0 0 0
1291 98176 ▶ pdl_datatypes new_dtype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]);
Branch: 6 branches
BranchTrueFalseTotal
pdl_datatypes new_dtype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 8399 89777 98176
pdl_datatypes new_dtype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 8389 10 8399
pdl_datatypes new_dtype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 236 89541 89777
pdl_datatypes new_dtype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 2 234 236
pdl_datatypes new_dtype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 11 89764 89775
pdl_datatypes new_dtype = PDL_TYPE_ADJUST_FROM_TRANS(trans_dtype, flags, vtable->par_types[i]); 11 0 11
1292 98176 ▶ if (new_dtype == pdl->datatype) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (new_dtype == pdl->datatype) continue; 83273 14903 98176
1293 14903 ▶ PDLDEBUG_f(printf("pdl_type_coerce (%s) pdl=%"IND_FLAG" from %d to %d\n", vtable->name, i, pdl->datatype, new_dtype));
Branch: 1 branch
BranchTrueFalseTotal
PDLDEBUG_f(printf("pdl_type_coerce (%s) pdl=%"IND_FLAG" from %d to %d\n", vtable->name, i, pdl->datatype, new_dtype)); 0 14903 14903
1294 14903 ▶ if (i >= nparents && PDL_HAS_OTHER_PARENT(pdl, trans))
Branch: 3 branches
BranchTrueFalseTotal
if (i >= nparents && PDL_HAS_OTHER_PARENT(pdl, trans)) 23 14880 14903
if (i >= nparents && PDL_HAS_OTHER_PARENT(pdl, trans)) 1 22 23
if (i >= nparents && PDL_HAS_OTHER_PARENT(pdl, trans)) 1 0 1
1295 3 return pdl_make_error(PDL_EUSERERROR,
1296 "%s: cannot convert output ndarray %s from type %s to %s with parent",
1297 1 vtable->name, vtable->par_names[i],
1298 2 ▶ PDL_TYPENAME(pdl->datatype), PDL_TYPENAME(new_dtype));
Branch: 6 branches
BranchTrueFalseTotal
PDL_TYPENAME(pdl->datatype), PDL_TYPENAME(new_dtype)); 1 0 1
PDL_TYPENAME(pdl->datatype), PDL_TYPENAME(new_dtype)); 1 0 1
PDL_TYPENAME(pdl->datatype), PDL_TYPENAME(new_dtype)); 1 0 1
PDL_TYPENAME(pdl->datatype), PDL_TYPENAME(new_dtype)); 1 0 1
PDL_TYPENAME(pdl->datatype), PDL_TYPENAME(new_dtype)); 1 0 1
PDL_TYPENAME(pdl->datatype), PDL_TYPENAME(new_dtype)); 1 0 1
1299 14902 ▶ PDL_RETERROR(PDL_err, pdl__get_convertedpdl_recprotect(
Branch: 3 branches
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__get_convertedpdl_recprotect( 22 14880 14902
PDL_RETERROR(PDL_err, pdl__get_convertedpdl_recprotect( 12 10 22
PDL_RETERROR(PDL_err, pdl__get_convertedpdl_recprotect( 0 14902 14902
1300 pdl, &pdl, new_dtype,
1301 (i < nparents) ? 0 : 1 + PDL_BITFIELD_ISSET(is_inout, i-nparents),
1302 recurse_count + 1
1303 ));
1304 14902 ▶ if (pdl->datatype != new_dtype)
Branch: 1 branch
BranchTrueFalseTotal
if (pdl->datatype != new_dtype) 0 14902 14902
1305 0 return pdl_make_error_simple(PDL_EFATAL, "type not expected value after get_convertedpdl\n");
1306 14902 ▶ if (i == inplace_output_ind)
Branch: 1 branch
BranchTrueFalseTotal
if (i == inplace_output_ind) 7 14895 14902
1307 7 pdls[inplace_input_ind] = pdl;
1308 14902 pdls[i] = pdl;
1309 }
1310 71423 return PDL_err;
1311 }
1312  
1313 pdl_error pdl__trans_check_pdls_actual(pdl_trans *trans);
1314 71433 pdl_error pdl__type_coerce_recprotect(pdl_trans *trans, int recurse_count) {
1315 71433 pdl_error PDL_err = {0, NULL, 0};
1316 71433 ▶ PDL_RECURSE_CHECK(recurse_count);
Branch: 1 branch
BranchTrueFalseTotal
PDL_RECURSE_CHECK(recurse_count); 0 71433 71433
1317 71433 ▶ PDL_RETERROR(PDL_err, pdl__trans_check_pdls_actual(trans));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__trans_check_pdls_actual(trans)); 2 71431 71433
1318 pdl_datatypes trans_dtype;
1319 71431 ▶ PDL_RETERROR(PDL_err, pdl__transtype_select(trans, &trans_dtype));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__transtype_select(trans, &trans_dtype)); 7 71424 71431
1320 71424 trans->__datatype = trans_dtype;
1321 71424 ▶ PDL_RETERROR(PDL_err, pdl__set_output_type_badvalue(trans, recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__set_output_type_badvalue(trans, recurse_count+1)); 0 71424 71424
1322 71424 ▶ PDL_RETERROR(PDL_err, pdl__type_convert(trans, recurse_count+1));
Branch: 1 branch
BranchTrueFalseTotal
PDL_RETERROR(PDL_err, pdl__type_convert(trans, recurse_count+1)); 1 71423 71424
1323 71423 return PDL_err;
1324 }
1325 71433 pdl_error pdl_type_coerce(pdl_trans *trans) {
1326 71433 return pdl__type_coerce_recprotect(trans, 0);
1327 }
1328  
1329 0 char pdl_trans_badflag_from_inputs(pdl_trans *trans) {
1330 0 return 0; /* CORE21 get rid */
1331 }
1332  
1333 71433 pdl_error pdl__trans_check_pdls_actual(pdl_trans *trans) {
1334 71433 pdl_error PDL_err = {0, NULL, 0};
1335 PDL_Indx i;
1336 71433 pdl_transvtable *vtable = trans->vtable;
1337 71433 pdl **pdls = trans->pdls;
1338 227789 ▶ for (i=0; i<vtable->npdls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<vtable->npdls; i++) { 156356 71433 227789
1339 156356 ▶ if (vtable->par_flags[i] & PDL_PARAM_ISTEMP)
Branch: 1 branch
BranchTrueFalseTotal
if (vtable->par_flags[i] & PDL_PARAM_ISTEMP) 253 156103 156356
1340 253 ▶ if (!(pdls[i] = pdl_pdlnew()))
Branch: 1 branch
BranchTrueFalseTotal
if (!(pdls[i] = pdl_pdlnew())) 0 253 253
1341 0 return pdl_make_error_simple(PDL_EFATAL, "Error in pdlnew");
1342 156356 ▶ if (!pdls[i])
Branch: 1 branch
BranchTrueFalseTotal
if (!pdls[i]) 0 156356 156356
1343 0 return pdl_make_error(PDL_EFATAL, "%s got NULL pointer on param %s", vtable->name, vtable->par_names[i]);
1344 }
1345 71433 ▶ if (vtable->flags & PDL_TRANS_OUTPUT_OTHERPAR)
Branch: 1 branch
BranchTrueFalseTotal
if (vtable->flags & PDL_TRANS_OUTPUT_OTHERPAR) 11 71422 71433
1346 23 ▶ for (i = 0; i < vtable->npdls; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < vtable->npdls; i++) 14 9 23
1347 14 ▶ if (!(trans->pdls[i]->state & PDL_NOMYDIMS) && trans->pdls[i]->ndims > vtable->par_realdims[i])
Branch: 2 branches
BranchTrueFalseTotal
if (!(trans->pdls[i]->state & PDL_NOMYDIMS) && trans->pdls[i]->ndims > vtable->par_realdims[i]) 9 5 14
if (!(trans->pdls[i]->state & PDL_NOMYDIMS) && trans->pdls[i]->ndims > vtable->par_realdims[i]) 2 7 9
1348 2 return pdl_make_error(PDL_EUSERERROR,
1349 "Can't broadcast with output OtherPars but par '%s' has %"IND_FLAG" dims, > %"IND_FLAG"!",
1350 2 vtable->par_names[i], trans->pdls[i]->ndims, vtable->par_realdims[i]
1351 );
1352 71431 return PDL_err;
1353 }
1354 0 pdl_error pdl_trans_check_pdls(pdl_trans *trans) {
1355 0 pdl_error PDL_err = {0, NULL, 0};
1356 0 return PDL_err; /* CORE21 get rid */
1357 }
« lib/PDL/Slices-pp-splitdim.c ↑ Summary lib/PDL/Core/pdl.h.PL »