19 #define USELONGDOUBLE 1 21 #include <../../nrnconf.h> 24 #if HAVE_POSIX_MEMALIGN 25 #define HAVE_MEMALIGN 1 29 #define _XOPEN_SOURCE 600 36 #include "shared/sundialsmath.h" 37 #include "shared/sundialstypes.h" 39 #define ZERO RCONST(0.0) 40 #define HALF RCONST(0.5) 41 #define ONE RCONST(1.0) 42 #define ONEPT5 RCONST(1.5) 45 #define ldrealtype long double 47 #define ldrealtype realtype 89 v = (N_Vector) malloc(
sizeof *v);
93 ops = (N_Vector_Ops) malloc(
sizeof(
struct _generic_N_Vector_Ops));
94 if (ops ==
NULL) {free(v);
return(
NULL);}
123 if (content ==
NULL) {free(ops);free(v);
return(
NULL);}
130 v->content = content;
153 nrn_assert(posix_memalign((
void**)&data, 64, length*
sizeof(realtype)) == 0);
155 data = (realtype *) malloc(length *
sizeof(realtype));
181 v = (N_Vector) malloc(
sizeof *v);
185 ops = (N_Vector_Ops) malloc(
sizeof(
struct _generic_N_Vector_Ops));
186 if (ops ==
NULL) {free(v);
return(
NULL);}
188 ops->nvclone = w->ops->nvclone;
189 ops->nvdestroy = w->ops->nvdestroy;
190 ops->nvspace = w->ops->nvspace;
191 ops->nvgetarraypointer = w->ops->nvgetarraypointer;
192 ops->nvsetarraypointer = w->ops->nvsetarraypointer;
193 ops->nvlinearsum = w->ops->nvlinearsum;
194 ops->nvconst = w->ops->nvconst;
195 ops->nvprod = w->ops->nvprod;
196 ops->nvdiv = w->ops->nvdiv;
197 ops->nvscale = w->ops->nvscale;
198 ops->nvabs = w->ops->nvabs;
199 ops->nvinv = w->ops->nvinv;
200 ops->nvaddconst = w->ops->nvaddconst;
201 ops->nvdotprod = w->ops->nvdotprod;
202 ops->nvmaxnorm = w->ops->nvmaxnorm;
203 ops->nvwrmsnormmask = w->ops->nvwrmsnormmask;
204 ops->nvwrmsnorm = w->ops->nvwrmsnorm;
205 ops->nvmin = w->ops->nvmin;
206 ops->nvwl2norm = w->ops->nvwl2norm;
207 ops->nvl1norm = w->ops->nvl1norm;
208 ops->nvcompare = w->ops->nvcompare;
209 ops->nvinvtest = w->ops->nvinvtest;
210 ops->nvconstrmask = w->ops->nvconstrmask;
211 ops->nvminquotient = w->ops->nvminquotient;
215 if (content ==
NULL) {free(ops);free(v);
return(
NULL);}
222 v->content = content;
257 if (count <= 0)
return(
NULL);
259 vs = (N_Vector *) malloc(count *
sizeof(N_Vector));
262 for (j=0; j<count; j++) {
282 if (count <= 0)
return(
NULL);
284 vs = (N_Vector *) malloc(count *
sizeof(N_Vector));
287 for (j=0; j<count; j++) {
323 for (i=0; i < N; i++) {
324 #if defined(SUNDIALS_EXTENDED_PRECISION) 325 printf(
"%11.8Lg\n", *xd++);
326 #elif defined(SUNDIALS_DOUBLE_PRECISION) 327 printf(
"%11.8lg\n", *xd++);
329 printf(
"%11.8g\n", *xd++);
357 nrn_assert(posix_memalign((
void**)&data, 64, length*
sizeof(realtype)) == 0);
359 data = (realtype *) malloc(length *
sizeof(realtype));
404 realtype
c, *xd, *yd, *zd;
408 if ((b ==
ONE) && (z == y)) {
413 if ((a ==
ONE) && (z == x)) {
420 if ((a ==
ONE) && (b ==
ONE)) {
427 if ((test = ((a ==
ONE) && (b == -
ONE))) || ((a == -
ONE) && (b ==
ONE))) {
437 if ((test = (a ==
ONE)) || (b ==
ONE)) {
447 if ((test = (a == -
ONE)) || (b == -
ONE)) {
480 for (i=0; i < N; i++)
481 *zd++ = a * (*xd++) + b * (*yd++);
492 for (i=0; i < N; i++)
499 realtype *xd, *yd, *zd;
506 for (i=0; i < N; i++)
507 *zd++ = (*xd++) * (*yd++);
513 realtype *xd, *yd, *zd;
520 for (i=0; i < N; i++)
521 *zd++ = (*xd++) / (*yd++);
536 }
else if (c == -
ONE) {
542 for (i=0; i < N; i++)
556 for (i=0; i < N; i++, xd++, zd++)
569 for (i=0; i < N; i++)
570 *zd++ =
ONE / (*xd++);
582 for (i=0; i < N; i++)
589 realtype sum =
ZERO, *xd, *yd;
595 for (i=0; i < N; i++)
596 sum += (*xd++) * (*yd++);
609 for (i=0; i < N; i++, xd++) {
610 if (
ABS(*xd) > max) max =
ABS(*xd);
619 realtype prodi, *xd, *wd;
626 for (i=0; i < N; i++) {
627 prodi = (*xd++) * (*wd++);
628 sum += prodi * prodi;
631 return(RSqrt((realtype)sum / N));
637 realtype prodi, *xd, *wd, *idd;
645 for (i=0; i < N; i++) {
647 prodi = xd[
i] * wd[
i];
648 sum += prodi * prodi;
652 return(RSqrt((realtype)sum / N));
666 for (i=1; i < N; i++, xd++) {
667 if ((*xd) < min) min = *xd;
676 realtype prodi, *xd, *wd;
683 for (i=0; i < N; i++) {
684 prodi = (*xd++) * (*wd++);
685 sum += prodi * prodi;
688 return(RSqrt((realtype)sum));
703 return((realtype)sum);
714 for (i=0; i<N; i++,xd++) {
728 for (i=0; i < N; i++, xd++, zd++) {
742 for (i=0; i < N; i++) {
744 *zd++ =
ONE / (*xd++);
754 realtype *cd, *xd, *md;
763 for (i=0; i<N; i++, cd++, xd++, md++) {
765 if (*cd ==
ZERO)
continue;
770 if ( (*cd) >
HALF || (*cd) < -
HALF) {
779 booleantype notEvenOnce;
781 realtype *
nd, *dd,
min=0.0;
789 for (i = 0; i < N; i++, nd++, dd++) {
790 if (*dd ==
ZERO)
continue;
796 else min =
MIN(min, (*nd) / (*dd));
800 if (notEvenOnce || (N == 0)) min = BIG_REAL;
820 for (i=0; i < N; i++)
827 realtype *xd, *yd, *zd;
834 for (i=0; i < N; i++)
835 *zd++ = (*xd++) + (*yd++);
841 realtype *xd, *yd, *zd;
848 for (i=0; i < N; i++)
849 *zd++ = (*xd++) - (*yd++);
861 for (i=0; i < N; i++)
868 realtype *xd, *yd, *zd;
875 for (i=0; i < N; i++)
876 *zd++ = c * ((*xd++) + (*yd++));
882 realtype *xd, *yd, *zd;
889 for (i=0; i < N; i++)
890 *zd++ = c * ((*xd++) - (*yd++));
896 realtype *xd, *yd, *zd;
903 for (i=0; i < N; i++)
904 *zd++ = a * (*xd++) + (*yd++);
910 realtype *xd, *yd, *zd;
917 for (i=0; i < N; i++)
918 *zd++ = a * (*xd++) - (*yd++);
931 for (i=0; i < N; i++)
937 for (i=0; i < N; i++)
942 for (i=0; i < N; i++)
943 *yd++ += a * (*xd++);
954 for (i=0; i < N; i++)
double max(double a, double b)
static void VLin1_NrnSerialLD(realtype a, N_Vector x, N_Vector y, N_Vector z)
static void VNeg_NrnSerialLD(N_Vector x, N_Vector z)
void N_VDiv_NrnSerialLD(N_Vector x, N_Vector y, N_Vector z)
N_Vector N_VClone_NrnSerialLD(N_Vector w)
static void VCopy_NrnSerialLD(N_Vector x, N_Vector z)
static void VScaleDiff_NrnSerialLD(realtype c, N_Vector x, N_Vector y, N_Vector z)
void N_VCompare_NrnSerialLD(realtype c, N_Vector x, N_Vector z)
#define NV_LENGTH_S_LD(v)
void N_VAbs_NrnSerialLD(N_Vector x, N_Vector z)
N_Vector * N_VNewVectorArray_NrnSerialLD(int count, long int length)
void N_VProd_NrnSerialLD(N_Vector x, N_Vector y, N_Vector z)
realtype * N_VGetArrayPointer_NrnSerialLD(N_Vector v)
N_Vector * N_VNewVectorArrayEmpty_NrnSerialLD(int count, long int length)
realtype N_VL1Norm_NrnSerialLD(N_Vector x)
N_Vector N_VCloneEmpty_NrnSerialLD(N_Vector w)
static void VLin2_NrnSerialLD(realtype a, N_Vector x, N_Vector y, N_Vector z)
realtype N_VWL2Norm_NrnSerialLD(N_Vector x, N_Vector w)
static void VScaleSum_NrnSerialLD(realtype c, N_Vector x, N_Vector y, N_Vector z)
static void VSum_NrnSerialLD(N_Vector x, N_Vector y, N_Vector z)
realtype N_VMin_NrnSerialLD(N_Vector x)
realtype N_VMaxNorm_NrnSerialLD(N_Vector x)
struct _N_VectorContent_NrnSerialLD * N_VectorContent_NrnSerialLD
void N_VAddConst_NrnSerialLD(N_Vector x, realtype b, N_Vector z)
booleantype N_VInvTest_NrnSerialLD(N_Vector x, N_Vector z)
N_Vector N_VMake_NrnSerialLD(long int length, realtype *v_data)
void N_VSpace_NrnSerialLD(N_Vector v, long int *lrw, long int *liw)
N_Vector N_VNew_NrnSerialLD(long int length)
void N_VInv_NrnSerialLD(N_Vector x, N_Vector z)
realtype N_VDotProd_NrnSerialLD(N_Vector x, N_Vector y)
void N_VScale_NrnSerialLD(realtype c, N_Vector x, N_Vector z)
realtype N_VWrmsNormMask_NrnSerialLD(N_Vector x, N_Vector w, N_Vector id)
void N_VOneMask_NrnSerialLD(N_Vector x)
void N_VPrint_NrnSerialLD(N_Vector x)
static void VScaleBy_NrnSerialLD(realtype a, N_Vector x)
#define NV_OWN_DATA_S_LD(v)
void N_VDestroy_NrnSerialLD(N_Vector v)
N_Vector N_VNewEmpty_NrnSerialLD(long int length)
realtype N_VWrmsNorm_NrnSerialLD(N_Vector x, N_Vector w)
void N_VSetArrayPointer_NrnSerialLD(realtype *v_data, N_Vector v)
void N_VLinearSum_NrnSerialLD(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z)
void N_VConst_NrnSerialLD(realtype c, N_Vector z)
realtype N_VMinQuotient_NrnSerialLD(N_Vector num, N_Vector denom)
static void VDiff_NrnSerialLD(N_Vector x, N_Vector y, N_Vector z)
booleantype N_VConstrMask_NrnSerialLD(N_Vector c, N_Vector x, N_Vector m)
static void Vaxpy_NrnSerialLD(realtype a, N_Vector x, N_Vector y)
void N_VDestroyVectorArray_NrnSerialLD(N_Vector *vs, int count)