19 #include <../../nrnconf.h>
22 #if HAVE_POSIX_MEMALIGN
23 #define HAVE_MEMALIGN 1
27 #define _XOPEN_SOURCE 600
34 #include "shared/sundialsmath.h"
35 #include "shared/sundialstypes.h"
37 #define ZERO RCONST(0.0)
38 #define HALF RCONST(0.5)
39 #define ONE RCONST(1.0)
40 #define ONEPT5 RCONST(1.5)
80 v = (N_Vector) malloc(
sizeof *
v);
85 ops = (N_Vector_Ops) malloc(
sizeof(
struct _generic_N_Vector_Ops));
118 if (content ==
NULL) {
129 v->content = content;
151 nrn_assert(posix_memalign((
void**) &
data, 64, length *
sizeof(realtype)) == 0);
153 data = (realtype*) malloc(length *
sizeof(realtype));
181 v = (N_Vector) malloc(
sizeof *
v);
186 ops = (N_Vector_Ops) malloc(
sizeof(
struct _generic_N_Vector_Ops));
192 ops->nvclone = w->ops->nvclone;
193 ops->nvdestroy = w->ops->nvdestroy;
194 ops->nvspace = w->ops->nvspace;
195 ops->nvgetarraypointer = w->ops->nvgetarraypointer;
196 ops->nvsetarraypointer = w->ops->nvsetarraypointer;
197 ops->nvlinearsum = w->ops->nvlinearsum;
198 ops->nvconst = w->ops->nvconst;
199 ops->nvprod = w->ops->nvprod;
200 ops->nvdiv = w->ops->nvdiv;
201 ops->nvscale = w->ops->nvscale;
202 ops->nvabs = w->ops->nvabs;
203 ops->nvinv = w->ops->nvinv;
204 ops->nvaddconst = w->ops->nvaddconst;
205 ops->nvdotprod = w->ops->nvdotprod;
206 ops->nvmaxnorm = w->ops->nvmaxnorm;
207 ops->nvwrmsnormmask = w->ops->nvwrmsnormmask;
208 ops->nvwrmsnorm = w->ops->nvwrmsnorm;
209 ops->nvmin = w->ops->nvmin;
210 ops->nvwl2norm = w->ops->nvwl2norm;
211 ops->nvl1norm = w->ops->nvl1norm;
212 ops->nvcompare = w->ops->nvcompare;
213 ops->nvinvtest = w->ops->nvinvtest;
214 ops->nvconstrmask = w->ops->nvconstrmask;
215 ops->nvminquotient = w->ops->nvminquotient;
219 if (content ==
NULL) {
230 v->content = content;
267 vs = (N_Vector*) malloc(count *
sizeof(N_Vector));
271 for (
j = 0;
j < count;
j++) {
293 vs = (N_Vector*) malloc(count *
sizeof(N_Vector));
297 for (
j = 0;
j < count;
j++) {
315 for (
j = 0;
j < count;
j++)
332 for (
i = 0;
i < N;
i++) {
333 printf(
"%11.8lg\n", *xd++);
359 nrn_assert(posix_memalign((
void**) &
data, 64, length *
sizeof(realtype)) == 0);
361 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++);
491 for (
i = 0;
i < N;
i++)
497 realtype *xd, *yd, *zd;
504 for (
i = 0;
i < N;
i++)
505 *zd++ = (*xd++) * (*yd++);
510 realtype *xd, *yd, *zd;
517 for (
i = 0;
i < N;
i++)
518 *zd++ = (*xd++) / (*yd++);
532 }
else if (
c == -
ONE) {
538 for (
i = 0;
i < N;
i++)
551 for (
i = 0;
i < N;
i++, xd++, zd++)
563 for (
i = 0;
i < N;
i++)
564 *zd++ =
ONE / (*xd++);
575 for (
i = 0;
i < N;
i++)
581 realtype sum =
ZERO, *xd, *yd;
587 for (
i = 0;
i < N;
i++)
588 sum += (*xd++) * (*yd++);
595 realtype max =
ZERO, *xd;
600 for (
i = 0;
i < N;
i++, xd++) {
618 for (
i = 0;
i < N;
i++) {
619 auto const prodi = (*xd++) * (*wd++);
620 auto const y = prodi * prodi -
c;
621 auto const t = sum + y;
626 return RSqrt(sum / N);
631 realtype *xd, *wd, *idd;
640 for (
i = 0;
i < N;
i++) {
642 auto const prodi = xd[
i] * wd[
i];
643 auto const y = prodi * prodi -
c;
644 auto const t = sum + y;
650 return RSqrt(sum / N);
663 for (
i = 1;
i < N;
i++, xd++) {
681 for (
i = 0;
i < N;
i++) {
682 auto const prodi = (*xd++) * (*wd++);
683 auto const y = prodi * prodi -
c;
684 auto const t = sum + y;
701 for (
i = 0;
i < N;
i++) {
702 auto const y =
ABS(xd[
i]) -
c;
703 auto const t = sum + y;
718 for (
i = 0;
i < N;
i++, xd++) {
732 for (
i = 0;
i < N;
i++, xd++, zd++) {
745 for (
i = 0;
i < N;
i++) {
748 *zd++ =
ONE / (*xd++);
757 realtype *cd, *xd, *md;
766 for (
i = 0;
i < N;
i++, cd++, xd++, md++) {
771 if ((*xd) * (*cd) <=
ZERO) {
777 if ((*cd) >
HALF || (*cd) < -
HALF) {
778 if ((*xd) * (*cd) <
ZERO) {
788 booleantype notEvenOnce;
790 realtype *nd, *dd, min = 0.0;
798 for (
i = 0;
i < N;
i++, nd++, dd++) {
806 min =
MIN(min, (*nd) / (*dd));
810 if (notEvenOnce || (N == 0))
830 for (
i = 0;
i < N;
i++)
836 realtype *xd, *yd, *zd;
843 for (
i = 0;
i < N;
i++)
844 *zd++ = (*xd++) + (*yd++);
849 realtype *xd, *yd, *zd;
856 for (
i = 0;
i < N;
i++)
857 *zd++ = (*xd++) - (*yd++);
868 for (
i = 0;
i < N;
i++)
874 realtype *xd, *yd, *zd;
881 for (
i = 0;
i < N;
i++)
882 *zd++ =
c * ((*xd++) + (*yd++));
887 realtype *xd, *yd, *zd;
894 for (
i = 0;
i < N;
i++)
895 *zd++ =
c * ((*xd++) - (*yd++));
900 realtype *xd, *yd, *zd;
907 for (
i = 0;
i < N;
i++)
908 *zd++ = a * (*xd++) + (*yd++);
913 realtype *xd, *yd, *zd;
920 for (
i = 0;
i < N;
i++)
921 *zd++ = a * (*xd++) - (*yd++);
933 for (
i = 0;
i < N;
i++)
939 for (
i = 0;
i < N;
i++)
944 for (
i = 0;
i < N;
i++)
945 *yd++ += a * (*xd++);
955 for (
i = 0;
i < N;
i++)
#define nrn_assert(x)
assert()-like macro, independent of NDEBUG status
void N_VCompare_NrnSerialLD(realtype c, N_Vector x, N_Vector z)
N_Vector N_VCloneEmpty_NrnSerialLD(N_Vector w)
realtype N_VWL2Norm_NrnSerialLD(N_Vector x, N_Vector w)
N_Vector N_VMake_NrnSerialLD(long int length, realtype *v_data)
void N_VScale_NrnSerialLD(realtype c, N_Vector x, N_Vector z)
N_Vector N_VNewEmpty_NrnSerialLD(long int length)
void N_VSpace_NrnSerialLD(N_Vector v, long int *lrw, long int *liw)
static void VScaleSum_NrnSerialLD(realtype c, N_Vector x, N_Vector y, N_Vector z)
void N_VLinearSum_NrnSerialLD(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z)
static void VDiff_NrnSerialLD(N_Vector x, N_Vector y, N_Vector z)
realtype N_VWrmsNormMask_NrnSerialLD(N_Vector x, N_Vector w, N_Vector id)
booleantype N_VConstrMask_NrnSerialLD(N_Vector c, N_Vector x, N_Vector m)
static void VSum_NrnSerialLD(N_Vector x, N_Vector y, N_Vector z)
realtype N_VDotProd_NrnSerialLD(N_Vector x, N_Vector y)
void N_VPrint_NrnSerialLD(N_Vector x)
static void VCopy_NrnSerialLD(N_Vector x, N_Vector z)
N_Vector N_VClone_NrnSerialLD(N_Vector w)
static void VLin2_NrnSerialLD(realtype a, N_Vector x, N_Vector y, N_Vector z)
booleantype N_VInvTest_NrnSerialLD(N_Vector x, N_Vector z)
realtype N_VWrmsNorm_NrnSerialLD(N_Vector x, N_Vector w)
static void VScaleBy_NrnSerialLD(realtype a, N_Vector x)
void N_VDiv_NrnSerialLD(N_Vector x, N_Vector y, N_Vector z)
void N_VDestroyVectorArray_NrnSerialLD(N_Vector *vs, int count)
realtype N_VMaxNorm_NrnSerialLD(N_Vector x)
static void VLin1_NrnSerialLD(realtype a, N_Vector x, N_Vector y, N_Vector z)
realtype N_VL1Norm_NrnSerialLD(N_Vector x)
N_Vector * N_VNewVectorArray_NrnSerialLD(int count, long int length)
realtype N_VMin_NrnSerialLD(N_Vector x)
void N_VOneMask_NrnSerialLD(N_Vector x)
static void Vaxpy_NrnSerialLD(realtype a, N_Vector x, N_Vector y)
static void VScaleDiff_NrnSerialLD(realtype c, N_Vector x, N_Vector y, N_Vector z)
realtype * N_VGetArrayPointer_NrnSerialLD(N_Vector v)
N_Vector N_VNew_NrnSerialLD(long int length)
static void VNeg_NrnSerialLD(N_Vector x, N_Vector z)
void N_VAbs_NrnSerialLD(N_Vector x, N_Vector z)
void N_VSetArrayPointer_NrnSerialLD(realtype *v_data, N_Vector v)
void N_VDestroy_NrnSerialLD(N_Vector v)
N_Vector * N_VNewVectorArrayEmpty_NrnSerialLD(int count, long int length)
void N_VInv_NrnSerialLD(N_Vector x, N_Vector z)
void N_VAddConst_NrnSerialLD(N_Vector x, realtype b, N_Vector z)
realtype N_VMinQuotient_NrnSerialLD(N_Vector num, N_Vector denom)
void N_VProd_NrnSerialLD(N_Vector x, N_Vector y, N_Vector z)
void N_VConst_NrnSerialLD(realtype c, N_Vector z)
struct _N_VectorContent_NrnSerialLD * N_VectorContent_NrnSerialLD
#define NV_OWN_DATA_S_LD(v)
#define NV_LENGTH_S_LD(v)