File Coverage

lib/PDL/Slices-pp-xchg.c
Criterion Covered Total %
statement 30 30 100.0
branch 11 18 61.1
condition n/a
subroutine n/a
pod n/a
total 41 48 85.4


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_xchg {
25             #line 26 "lib/PDL/Slices-pp-xchg.c"
26             PDL_Indx n1;
27             PDL_Indx n2;
28             } pdl_params_xchg;
29              
30              
31             #line 1857 "lib/PDL/PP.pm"
32             pdl_error pdl_xchg_redodims(pdl_trans *__privtrans) {
33             pdl_error PDL_err = {0, NULL, 0};
34             #line 35 "lib/PDL/Slices-pp-xchg.c"
35 349           pdl_params_xchg *__params = __privtrans->params; (void)__params;
36 349           pdl *__it = __privtrans->pdls[1]; (void) __it;
37 349 50         PDL->hdr_childcopy(__privtrans); __privtrans->dims_redone = 1;
38             PDL_Indx i,cor;
39            
40             #line 1423 "lib/PDL/Slices.pd"
41             if (__params->n1 <0)
42             __params->n1 += __privtrans->pdls[0]->broadcastids[0];
43             if (__params->n2 <0)
44             __params->n2 += __privtrans->pdls[0]->broadcastids[0];
45             if (PDLMIN(__params->n1,__params->n2) <0 ||
46             PDLMAX(__params->n1,__params->n2) >= __privtrans->pdls[0]->broadcastids[0])
47             return PDL->make_error(PDL_EUSERERROR, "Error in xchg:" "One of dims %"IND_FLAG", %"IND_FLAG" out of range: should be 0<=dim<%"IND_FLAG"",__params->n1,__params->n2,__privtrans->pdls[0]->broadcastids[0]);
48             #line 49 "lib/PDL/Slices-pp-xchg.c"
49              
50 349 50         PDL_RETERROR(PDL_err, PDL->reallocdims(__it,__privtrans->pdls[0]->ndims));;
51 349           __privtrans->incs = malloc(sizeof(*__privtrans->incs) * __privtrans->pdls[1]->ndims); /* CType.get_malloc */
52             ;
53 349           __privtrans->offs = 0;
54 1145 100         for(i=0; i<__privtrans->pdls[1]->ndims; i++) {
55 796           cor =
56             #line 1433 "lib/PDL/Slices.pd"
57             ((i == __params->n1) ? __params->n2 : (i == __params->n2) ? __params->n1 : i)
58             #line 59 "lib/PDL/Slices-pp-xchg.c"
59             ;
60 796           __privtrans->pdls[1]->dims[i] = __privtrans->pdls[0]->dims[cor];
61 796           __privtrans->incs[i] = __privtrans->pdls[0]->dimincs[cor];
62             }
63 349 50         PDL_RETERROR(PDL_err, PDL->setdims_careful(__it));;
64            
65             #line 384 "lib/PDL/PP.pm"
66             {int __ind; PDL_RETERROR(PDL_err, PDL->reallocbroadcastids(__privtrans->pdls[1], __privtrans->pdls[0]->nbroadcastids));
67             for(__ind=0; __ind<__privtrans->pdls[0]->nbroadcastids; __ind++)
68             __privtrans->pdls[1]->broadcastids[__ind] = __privtrans->pdls[0]->broadcastids[__ind] + (0);
69             }
70             #line 71 "lib/PDL/Slices-pp-xchg.c"
71             ;
72 349           __privtrans->dims_redone = 1;
73 349           return PDL_err;
74             }
75              
76              
77             #line 1857 "lib/PDL/PP.pm"
78             pdl_error pdl_xchg_free(pdl_trans *__privtrans, char destroy) {
79             pdl_error PDL_err = {0, NULL, 0};
80             #line 81 "lib/PDL/Slices-pp-xchg.c"
81 351           pdl_params_xchg *__params = __privtrans->params; (void)__params;
82 351           pdl *__it = __privtrans->pdls[1]; (void) __it;
83 351 100         PDL_FREE_CODE(__privtrans, destroy, , free(__privtrans->incs); /* CType.get_free */
84 351           ) return PDL_err;
85             }
86              
87             static pdl_datatypes pdl_xchg_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 };
88             static PDL_Indx pdl_xchg_vtable_realdims[] = { 0, 0 };
89             static char *pdl_xchg_vtable_parnames[] = { "PARENT","CHILD" };
90             static short pdl_xchg_vtable_parflags[] = {
91             0,
92             PDL_PARAM_ISCREAT|PDL_PARAM_ISCREATEALWAYS|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE
93             };
94             static pdl_datatypes pdl_xchg_vtable_partypes[] = { -1, -1 };
95             static PDL_Indx pdl_xchg_vtable_realdims_starts[] = { 0, 0 };
96             static PDL_Indx pdl_xchg_vtable_realdims_ind_ids[] = { 0 };
97             static char *pdl_xchg_vtable_indnames[] = { "" };
98             pdl_transvtable pdl_xchg_vtable = {
99             0, PDL_ITRANS_ISAFFINE|PDL_ITRANS_TWOWAY|PDL_ITRANS_DO_DATAFLOW_ANY, pdl_xchg_vtable_gentypes, 1, 2, NULL /*CORE21*/,
100             pdl_xchg_vtable_realdims, pdl_xchg_vtable_parnames,
101             pdl_xchg_vtable_parflags, pdl_xchg_vtable_partypes,
102             pdl_xchg_vtable_realdims_starts, pdl_xchg_vtable_realdims_ind_ids, 0,
103             0, pdl_xchg_vtable_indnames,
104             pdl_xchg_redodims, NULL, NULL,
105             pdl_xchg_free,
106             sizeof(pdl_params_xchg),"PDL::Slices::xchg"
107             };
108              
109              
110 351           pdl_error pdl_run_xchg(pdl *PARENT,pdl *CHILD,PDL_Indx n1,PDL_Indx n2) {
111 351           pdl_error PDL_err = {0, NULL, 0};
112 351 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
113 351           pdl_trans *__privtrans = PDL->create_trans(&pdl_xchg_vtable);
114 351 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
115 351           pdl_params_xchg *__params = __privtrans->params;
116 351           __privtrans->pdls[0] = PARENT;
117 351           __privtrans->pdls[1] = CHILD;
118 351 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
119 351           (__params->n1) = (n1); /* CType.get_copy */
120 351           (__params->n2) = (n2); /* CType.get_copy */
121 351 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
122 351           return PDL_err;
123             }