PDL
view release on metacpan or search on metacpan
lib/PDL/API.pod view on Meta::CPAN
__C__
static pdl* new_pdl(int datatype, PDL_Indx dims[], int ndims)
{
pdl *p = PDL->pdlnew();
if (!p) return p;
pdl_error err = PDL->setdims(p, dims, ndims); /* set dims */
if (err.error) { PDL->destroy(p); return NULL; }
p->datatype = datatype; /* and data type */
err = PDL->allocdata (p); /* allocate the data chunk */
if (err.error) { PDL->destroy(p); return NULL; }
return p;
}
pdl* myfloatseq()
{
PDL_Indx dims[] = {5,5,5};
pdl *p = new_pdl(PDL_F,dims,3);
if (!p) return p;
PDL_Float *dataf = (PDL_Float *) p->data;
lib/PDL/API.pod view on Meta::CPAN
=item *
C<int howbig(int pdl_datatype)>
=item *
C<pdl_error add_deletedata_magic(pdl *p, void (*func)(pdl*, int), int param)>
=item *
C<pdl_error allocdata(pdl *p)>
=item *
C<pdl_error make_physical(pdl *p)>
=item *
C<pdl_error make_physdims(pdl *p)>
=item *
lib/PDL/Core.pm view on Meta::CPAN
set_c($new, [0], $value);
} elsif (! $CAN_PACK_D && $pack[$new->get_datatype] =~ /^(\QD*\E|\Q(DD)*\E)$/ ) {
# if "D" is not available for pack(),
# it dies with error: "Invalid type 'D' in pack".
$new->setdims([]);
set_c($new, [0], $value);
} else {
$new->setdims([]);
if ($value) {
$new->update_data_from( pack $pack[$new->get_datatype], $value );
} else { # do nothing if 0 - allocdata already memsets to 0
$new->make_physical;
}
}
}
elsif (blessed($value)) { # Object
$new = $value->copy;
}
else {
barf("Can not interpret argument $value of type ".ref($value) );
}
lib/PDL/Core/pdl.h.PL view on Meta::CPAN
do { rv = expr; if (rv.error) { iferr } } while (0)
#define PDL_RETERROR(rv, expr) PDL_RETERROR2(rv, expr, return rv;)
#define PDL_ACCUMERROR(rv, expr) \
do { \
pdl_error rv##_local = expr; \
if (rv##_local.error) rv = pdl_error_accumulate(rv, rv##_local); \
} while (0)
#define PDL_ENSURE_ALLOCATED(it) \
if (!(it->state & PDL_ALLOCATED)) { \
PDL_RETERROR(PDL_err, pdl_allocdata(it)); \
}
/* for use with PDL_TYPELIST_REAL */
#define PDL_QSORT(symbol, ctype, ppsym, ...) \
static inline void qsort_ ## ppsym(ctype* xx, PDL_Indx a, PDL_Indx b) { \
PDL_Indx i,j; \
ctype t, median; \
i = a; j = b; \
median = xx[(i+j) / 2]; \
do { \
lib/PDL/Core/pdlapi.c view on Meta::CPAN
return pdl_pdlnew();
}
pdl *pdl_scalar(PDL_Anyval anyval) {
PDLDEBUG_f(printf("pdl_scalar type=%d val=", anyval.type); pdl_dump_anyval(anyval); printf("\n"););
pdl *it = pdl_pdlnew();
if (!it) return it;
it->datatype = anyval.type;
it->broadcastids[0] = it->ndims = 0; /* 0 dims in a scalar */
pdl_resize_defaultincs(it);
pdl_error PDL_err = pdl_allocdata(it);
if (PDL_err.error) { pdl_destroy(it); return NULL; }
it->value = anyval.value;
it->state &= ~(PDL_NOMYDIMS); /* has dims */
return it;
}
pdl_error pdl__converttypei_new_recprotect(pdl *PARENT, pdl *CHILD, pdl_datatypes totype, pdl_datatypes force_intype, int recurse_count);
pdl_error pdl__get_convertedpdl_recprotect(pdl *old, pdl **retval, pdl_datatypes type, char switch_sense, int recurse_count) {
pdl_error PDL_err = {0, NULL, 0};
PDL_RECURSE_CHECK(recurse_count);
lib/PDL/Core/pdlapi.c view on Meta::CPAN
it->state |= PDL_DATAFLOW_F;
*retval = it;
return PDL_err;
}
pdl *pdl_get_convertedpdl(pdl *old, pdl_datatypes type) {
pdl *retval;
pdl_error PDL_err = pdl__get_convertedpdl_recprotect(old, &retval, type, 0, 0);
return PDL_err.error ? NULL : retval;
}
pdl_error pdl_allocdata(pdl *it) {
pdl_error PDL_err = {0, NULL, 0};
PDLDEBUG_f(printf("pdl_allocdata %p, %"IND_FLAG", %d\n",it, it->nvals,
it->datatype));
if (it->nvals < 0)
return pdl_make_error(PDL_EUSERERROR, "Tried to allocdata with %"IND_FLAG" values", it->nvals);
PDL_Indx nbytes = it->nvals * pdl_howbig(it->datatype);
PDL_Indx ncurr = it->nbytes;
if (ncurr == nbytes)
return PDL_err; /* Nothing to be done */
if (it->state & PDL_DONTTOUCHDATA)
return pdl_make_error_simple(PDL_EUSERERROR, "Trying to touch data of an untouchable (mmapped?) pdl");
char was_useheap = (ncurr > sizeof(it->value)),
will_useheap = (nbytes > sizeof(it->value));
if (!was_useheap && !will_useheap) {
it->data = &it->value;
lib/PDL/Core/pdlcore.c view on Meta::CPAN
}
if (dest_pdl == NULL)
dest_pdl = pdl_pdlnew();
if (!dest_pdl) return dest_pdl;
pdl_error err = pdl_setdims (dest_pdl, dest_dims, ndims);
if (err.error) return NULL;
if (dtype == -1) {
dtype = _detect_datatype(av);
}
dest_pdl->datatype = dtype;
err = pdl_allocdata (dest_pdl);
if (err.error) return NULL;
err = pdl_make_physical(dest_pdl);
if (err.error) return NULL;
/******
* Copy the undefval to fill empty spots in the ndarray...
*/
PDLDEBUG_f(printf("pdl_from_array type: %d\n", dtype));
ANYVAL_FROM_SV(undefval, NULL, TRUE, dtype, FALSE);
#define X(dtype_dest, ctype_dest, ppsym_dest, ...) \
pdl_setav_ ## ppsym_dest(dest_pdl->data,av,dest_dims,ndims,level, undefval.value.ppsym_dest, dest_pdl);
lib/PDL/Core/pdlcore.h view on Meta::CPAN
X(create_trans, pdl_trans *, (pdl_transvtable *vtable)) \
X(type_coerce, pdl_error, (pdl_trans *trans)) \
X(trans_badflag_from_inputs, char, (pdl_trans *trans)) \
X(get_convertedpdl, pdl *, (pdl *pdl, pdl_datatypes type)) \
X(make_trans_mutual, pdl_error, (pdl_trans *trans)) \
X(make_physical, pdl_error, (pdl *it)) \
X(make_physdims, pdl_error, (pdl *it)) \
X(pdl_barf, void, (const char* pat,...)) \
X(pdl_warn, void, (const char* pat,...)) \
X(make_physvaffine, pdl_error, (pdl *it)) \
X(allocdata, pdl_error, (pdl *it)) \
X(safe_indterm, PDL_Indx, (PDL_Indx dsz, PDL_Indx at, char *file, int lineno)) \
X(propagate_badflag, void, (pdl *it, int newval)) \
X(propagate_badvalue, void, (pdl *it)) \
X(changed, pdl_error, (pdl *it, int what, int recursing)) \
X(get_pdl_badvalue, PDL_Anyval, (pdl *it)) /*CORE21*/ \
X(get_badvalue, PDL_Anyval, (pdl_datatypes datatype)) /*CORE21*/ \
X(set_datatype, pdl_error, (pdl *a, pdl_datatypes datatype)) \
X(hdr_copy, SV *, (SV *hdrp)) \
X(hdr_childcopy, void, (pdl_trans *trans)) \
X(readdata_affine, pdl_error, (pdl_trans *trans)) \
t/01-pptest.t view on Meta::CPAN
pdl **outs = malloc(($COMP(outs_count) = $COMP(howmany)) * sizeof(pdl*));
$COMP(outs) = outs;
PDL_Indx i, ndims = $PDL(in)->ndims, dims[ndims];
for (i = 0; i < ndims; i++) dims[i] = $PDL(in)->dims[i];
for (i = 0; i < $COMP(outs_count); i++) {
pdl *o = outs[i] = PDL->pdlnew();
if (!o) { for (i--; i >= 0; i--) PDL->destroy(outs[i]); free(outs); $CROAK("Failed to create ndarray"); }
o->datatype = $PDL(in)->datatype;
PDL_err = PDL->setdims(o, dims, ndims);
if (PDL_err.error) { for (; i >= 0; i--) PDL->destroy(outs[i]); free(outs); return PDL_err; }
PDL_err = PDL->allocdata(o);
if (PDL_err.error) { for (; i >= 0; i--) PDL->destroy(outs[i]); free(outs); return PDL_err; }
PDL_DECLARE_PARAMETER_BADVAL($GENERIC(in), o, (o), 1, $PPSYM(in))
loop(n) %{ o_datap[n] = $in(); %}
}
EOC
);
pp_def('index_prec', # check $a(n=>x+1) works
Pars => 'in(n); [o]out()',
GenericTypes => ['F'],
t/inline-with.t view on Meta::CPAN
#use Inline 'INFO'; # use to generate lots of info
use_ok 'Inline', with => 'PDL' or skip 'with PDL failed', 3;
eval { Inline->bind(C => <<'EOF') };
static pdl* new_pdl(int datatype, PDL_Indx dims[], int ndims)
{
pdl *p = PDL->pdlnew();
if (!p) return p;
pdl_error err = PDL->setdims(p, dims, ndims); /* set dims */
if (err.error) { PDL->destroy(p); return NULL; }
p->datatype = datatype; /* and data type */
err = PDL->allocdata(p); /* allocate the data chunk */
if (err.error) { PDL->destroy(p); return NULL; }
return p;
}
pdl* myfloatseq()
{
PDL_Indx dims[] = {5,5,5};
pdl *p = new_pdl(PDL_F,dims,3);
if (!p) return p;
PDL_Float *dataf = (PDL_Float *) p->data;
( run in 0.976 second using v1.01-cache-2.11-cpan-454fe037f31 )