File Coverage

lib/PDL/Slices-pp-broadcastI.c
Criterion Covered Total %
statement 28 28 100.0
branch 9 16 56.2
condition n/a
subroutine n/a
pod n/a
total 37 44 84.0


line stmt bran cond sub pod time code
1              
2             #line 453 "lib/PDL/PP.pm"
3             /*
4             * THIS FILE WAS GENERATED BY PDL::PP from lib/PDL/Slices.pd! Do not modify!
5             */
6              
7             #define PDL_FREE_CODE(trans, destroy, comp_free_code, ntpriv_free_code) \
8             if (destroy) { \
9             comp_free_code \
10             } \
11             if ((trans)->dims_redone) { \
12             ntpriv_free_code \
13             }
14              
15             #include "EXTERN.h"
16             #include "perl.h"
17             #include "XSUB.h"
18             #include "pdl.h"
19             #include "pdlcore.h"
20             #define PDL PDL_Slices
21             extern Core* PDL; /* Structure hold core C functions */
22              
23             #line 1846 "lib/PDL/PP.pm"
24             typedef struct pdl_params_broadcastI {
25             #line 26 "lib/PDL/Slices-pp-broadcastI.c"
26             PDL_Indx id;
27             PDL_Indx *whichdims;
28             PDL_Indx whichdims_count;
29             PDL_Indx nrealwhichdims;
30             } pdl_params_broadcastI;
31              
32              
33             #line 1857 "lib/PDL/PP.pm"
34             pdl_error pdl_broadcastI_redodims(pdl_trans *__privtrans) {
35             pdl_error PDL_err = {0, NULL, 0};
36             #line 37 "lib/PDL/Slices-pp-broadcastI.c"
37 940           pdl_params_broadcastI *__params = __privtrans->params; (void)__params;
38 940           pdl *__it = __privtrans->pdls[1]; (void) __it;
39 940           PDL->hdr_childcopy(__privtrans); __privtrans->dims_redone = 1;
40              
41             #line 1880 "lib/PDL/Slices.pd"
42             PDL_Indx nthc,i,j,flag;
43             PDL_RETERROR(PDL_err, PDL->reallocdims(__it,__privtrans->pdls[0]->ndims));;
44             __privtrans->incs = malloc(sizeof(*__privtrans->incs) * __privtrans->pdls[1]->ndims); /* CType.get_malloc */
45             ;
46             __privtrans->offs = 0;
47             nthc=0;
48             for(i=0; i<__privtrans->pdls[0]->ndims; i++) {
49             flag=0;
50             if(__privtrans->pdls[0]->nbroadcastids > __params->id && __params->id >= 0 &&
51             i == __privtrans->pdls[0]->broadcastids[__params->id]) {
52             nthc += __params->whichdims_count;
53             }
54             for(j=0; j<__params->whichdims_count; j++) {
55             if(__params->whichdims[j] == i) {flag=1; break;}
56             }
57             if(flag) {
58             continue;
59             }
60             __privtrans->pdls[1]->dims[nthc] = __privtrans->pdls[0]->dims[i];
61             __privtrans->incs[nthc] = __privtrans->pdls[0]->dimincs[i];
62             nthc++;
63             }
64             for(i=0; i<__params->whichdims_count; i++) {
65             PDL_Indx cdim,pdim;
66             cdim = i +
67             (__privtrans->pdls[0]->nbroadcastids > __params->id && __params->id >= 0?
68             __privtrans->pdls[0]->broadcastids[__params->id] : __privtrans->pdls[0]->ndims)
69             - __params->nrealwhichdims;
70             pdim = __params->whichdims[i];
71             if(pdim == -1) {
72             __privtrans->pdls[1]->dims[cdim] = 1;
73             __privtrans->incs[cdim] = 0;
74             } else {
75             __privtrans->pdls[1]->dims[cdim] = __privtrans->pdls[0]->dims[pdim];
76             __privtrans->incs[cdim] = __privtrans->pdls[0]->dimincs[pdim];
77             }
78             }
79             PDL_RETERROR(PDL_err, PDL->setdims_careful(__it));;
80             PDL_RETERROR(PDL_err, PDL->reallocbroadcastids(__privtrans->pdls[1],
81             PDLMAX(__params->id+1, __privtrans->pdls[0]->nbroadcastids)));
82             for(i=0; i<__privtrans->pdls[1]->nbroadcastids-1; i++) {
83             __privtrans->pdls[1]->broadcastids[i] =
84             (__privtrans->pdls[0]->nbroadcastids > i ?
85             __privtrans->pdls[0]->broadcastids[i] : __privtrans->pdls[0]->ndims) +
86             (i <= __params->id ? - __params->nrealwhichdims :
87             __params->whichdims_count - __params->nrealwhichdims);
88             }
89             __privtrans->pdls[1]->broadcastids[__privtrans->pdls[1]->nbroadcastids-1] = __privtrans->pdls[1]->ndims;
90             #line 91 "lib/PDL/Slices-pp-broadcastI.c"
91 940           return PDL_err;
92             }
93              
94              
95             #line 1857 "lib/PDL/PP.pm"
96             pdl_error pdl_broadcastI_free(pdl_trans *__privtrans, char destroy) {
97             pdl_error PDL_err = {0, NULL, 0};
98             #line 99 "lib/PDL/Slices-pp-broadcastI.c"
99 940           pdl_params_broadcastI *__params = __privtrans->params; (void)__params;
100 940           pdl *__it = __privtrans->pdls[1]; (void) __it;
101 940 50         PDL_FREE_CODE(__privtrans, destroy, free(__params->whichdims); /* CType.get_free */
    50          
102             , free(__privtrans->incs); /* CType.get_free */
103 940           ) return PDL_err;
104             }
105              
106             static pdl_datatypes pdl_broadcastI_vtable_gentypes[] = { PDL_SB, PDL_B, PDL_S, PDL_US, PDL_L, PDL_UL, PDL_IND, PDL_ULL, PDL_LL, PDL_F, PDL_D, PDL_LD, PDL_CF, PDL_CD, PDL_CLD, -1 };
107             static PDL_Indx pdl_broadcastI_vtable_realdims[] = { 0, 0 };
108             static char *pdl_broadcastI_vtable_parnames[] = { "PARENT","CHILD" };
109             static short pdl_broadcastI_vtable_parflags[] = {
110             0,
111             PDL_PARAM_ISCREAT|PDL_PARAM_ISCREATEALWAYS|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE
112             };
113             static pdl_datatypes pdl_broadcastI_vtable_partypes[] = { -1, -1 };
114             static PDL_Indx pdl_broadcastI_vtable_realdims_starts[] = { 0, 0 };
115             static PDL_Indx pdl_broadcastI_vtable_realdims_ind_ids[] = { 0 };
116             static char *pdl_broadcastI_vtable_indnames[] = { "" };
117             pdl_transvtable pdl_broadcastI_vtable = {
118             0, PDL_ITRANS_ISAFFINE|PDL_ITRANS_TWOWAY|PDL_ITRANS_DO_DATAFLOW_ANY, pdl_broadcastI_vtable_gentypes, 1, 2, NULL /*CORE21*/,
119             pdl_broadcastI_vtable_realdims, pdl_broadcastI_vtable_parnames,
120             pdl_broadcastI_vtable_parflags, pdl_broadcastI_vtable_partypes,
121             pdl_broadcastI_vtable_realdims_starts, pdl_broadcastI_vtable_realdims_ind_ids, 0,
122             0, pdl_broadcastI_vtable_indnames,
123             pdl_broadcastI_redodims, NULL, NULL,
124             pdl_broadcastI_free,
125             sizeof(pdl_params_broadcastI),"PDL::Slices::broadcastI"
126             };
127              
128              
129 940           pdl_error pdl_run_broadcastI(pdl *PARENT,pdl *CHILD,PDL_Indx id,PDL_Indx *whichdims,PDL_Indx whichdims_count) {
130 940           pdl_error PDL_err = {0, NULL, 0};
131 940 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
132 940           pdl_trans *__privtrans = PDL->create_trans(&pdl_broadcastI_vtable);
133 940 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
134 940           pdl_params_broadcastI *__params = __privtrans->params;
135 940           __privtrans->pdls[0] = PARENT;
136 940           __privtrans->pdls[1] = CHILD;
137 940 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
138 940           PARENT = __privtrans->pdls[0];
139 940           CHILD = __privtrans->pdls[1];
140 940           (__params->id) = (id); /* CType.get_copy */
141 940           __params->whichdims = malloc(sizeof(*__params->whichdims) * whichdims_count); /* CType.get_malloc */
142              
143 940 50         if(!whichdims) {__params->whichdims=0;} /* CType.get_copy */
144             else {int __malloc_ind_1;
145 940           for(__malloc_ind_1 = 0;
146 1076 100         __malloc_ind_1 < whichdims_count;
147 136           __malloc_ind_1 ++) { __params->whichdims[__malloc_ind_1] = whichdims[__malloc_ind_1]; }}
148 940           (__params->whichdims_count) = (whichdims_count); /* CType.get_copy */
149              
150              
151             #line 1865 "lib/PDL/Slices.pd"
152             PDL_Indx i,j;
153             __params->nrealwhichdims = 0;
154             for(i=0; i<__params->whichdims_count; i++) {
155             for(j=i+1; j<__params->whichdims_count; j++)
156             if(__params->whichdims[i] == __params->whichdims[j] &&
157             __params->whichdims[i] != -1) {
158             return PDL->make_error(PDL_EUSERERROR, "Error in broadcastI:" "duplicate arg %"IND_FLAG" %"IND_FLAG" %"IND_FLAG"",i,j,__params->whichdims[i]);
159             }
160             if(__params->whichdims[i] != -1) {
161             __params->nrealwhichdims ++;
162             }
163             }
164             #line 165 "lib/PDL/Slices-pp-broadcastI.c"
165 940 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
166 940           return PDL_err;
167             }