pdlcore.c (PDL-2.082) | : | pdlcore.c (PDL-2.083) | ||
---|---|---|---|---|
skipping to change at line 184 | skipping to change at line 184 | |||
*ndims = (PDL_Indx) av_len(array) + 1; /* Number of dimensions */ | *ndims = (PDL_Indx) av_len(array) + 1; /* Number of dimensions */ | |||
PDL_Indx *dims = (PDL_Indx *) pdl_smalloc( (*ndims) * sizeof(*dims) ); /* Arr ay space */ | PDL_Indx *dims = (PDL_Indx *) pdl_smalloc( (*ndims) * sizeof(*dims) ); /* Arr ay space */ | |||
if (dims == NULL) return NULL; | if (dims == NULL) return NULL; | |||
PDL_Indx i; | PDL_Indx i; | |||
for(i=0; i<(*ndims); i++) { | for(i=0; i<(*ndims); i++) { | |||
dims[i] = (PDL_Indx) SvIV(*(av_fetch( array, i, 0 ))); | dims[i] = (PDL_Indx) SvIV(*(av_fetch( array, i, 0 ))); | |||
} | } | |||
return dims; | return dims; | |||
} | } | |||
/* Pack array of pdl* - returns pdls[] (pdl_smalloced) and npdls */ | ||||
pdl ** pdl_packpdls( SV* sv, PDL_Indx *npdls ) { | ||||
if (!SvOK(sv)) { /* undef is OK, treat as empty */ | ||||
*npdls = 0; | ||||
return NULL; | ||||
} | ||||
if (!SvROK(sv)) pdl_pdl_barf("Gave a non-reference as array-ref of PDLs"); | ||||
if (SvTYPE(SvRV(sv))!=SVt_PVAV) | ||||
pdl_pdl_barf("Gave a non-array-reference as array-ref of PDLs"); | ||||
AV *array = (AV *) SvRV(sv); | ||||
if (!array) pdl_pdl_barf("Failed to get AV from reference"); | ||||
*npdls = (PDL_Indx) av_len(array) + 1; | ||||
if (!*npdls) return NULL; | ||||
pdl **pdls = (pdl **) pdl_smalloc( (*npdls) * sizeof(*pdls) ); | ||||
if (!pdls) pdl_pdl_barf("Failed to allocate memory for pointers to PDLs"); | ||||
PDL_Indx i; | ||||
for(i=0; i<(*npdls); i++) { | ||||
SV **s = av_fetch( array, i, 0 ); | ||||
if (!s) pdl_pdl_barf("Failed to fetch SV #%"IND_FLAG, i); | ||||
pdls[i] = pdl_SvPDLV(*s); | ||||
} | ||||
return pdls; | ||||
} | ||||
/* Unpack array of pdl* into SV* */ | ||||
SV* pdl_unpackpdls( pdl **pdls, PDL_Indx npdls ) { | ||||
AV *array = newAV(); | ||||
if (!array) return NULL; | ||||
av_extend(array, npdls + 1); | ||||
PDL_Indx i; | ||||
for(i=0; i<npdls; i++) { | ||||
SV *sv = newSV(0); | ||||
pdl_SetSV_PDL(sv, pdls[i]); | ||||
av_push(array, sv); | ||||
} | ||||
return sv_2mortal(newRV_noinc((SV *)array)); | ||||
} | ||||
PDL_Indx pdl_safe_indterm( PDL_Indx dsz, PDL_Indx at, char *file, int lineno) | PDL_Indx pdl_safe_indterm( PDL_Indx dsz, PDL_Indx at, char *file, int lineno) | |||
{ | { | |||
if (!(at >= 0 && at < dsz)) | if (!(at >= 0 && at < dsz)) | |||
pdl_pdl_barf("access [%d] out of range [0..%d] (inclusive) at %s line %d", | pdl_pdl_barf("access [%d] out of range [0..%d] (inclusive) at %s line %d", | |||
at, dsz-1, file?file:"?", lineno); | at, dsz-1, file?file:"?", lineno); | |||
return at; | return at; | |||
} | } | |||
/* | /* | |||
pdl_smalloc - utility to get temporary memory space. Uses | pdl_smalloc - utility to get temporary memory space. Uses | |||
skipping to change at line 1166 | skipping to change at line 1204 | |||
* Helmut G. Katzgraber. "Random Numbers in Scientific Computing: | * Helmut G. Katzgraber. "Random Numbers in Scientific Computing: | |||
* An Introduction". <https://arxiv.org/abs/1005.4117v1>. | * An Introduction". <https://arxiv.org/abs/1005.4117v1>. | |||
*/ | */ | |||
uint64_t s, pid; | uint64_t s, pid; | |||
/* Start of Perl-specific symbols */ | /* Start of Perl-specific symbols */ | |||
Time_t seconds; | Time_t seconds; | |||
pid = (uint64_t)PerlProc_getpid(); | pid = (uint64_t)PerlProc_getpid(); | |||
(void)time(&seconds); | (void)time(&seconds); | |||
/* End of Perl-specific symbols */ | /* End of Perl-specific symbols */ | |||
s = (uint64_t)seconds; | s = (uint64_t)seconds; | |||
return abs(((s*181)*((pid-83)*359))%104729); | return ((s*181)*((pid-83)*359))%104729; | |||
} | } | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 39 lines changed or added |