booleantype is_square(SUNMatrix A) { if (SUNDenseMatrix_Rows(A) == SUNDenseMatrix_Columns(A)) return SUNTRUE; else return SUNFALSE; }
CAMLprim value sunml_lsolver_dense(value vnvec, value vdmat) { CAMLparam2(vnvec, vdmat); #if SUNDIALS_LIB_VERSION >= 300 SUNMatrix dmat = MAT_VAL(vdmat); SUNLinearSolver ls = SUNDenseLinearSolver(NVEC_VAL(vnvec), dmat); if (ls == NULL) { if (SUNDenseMatrix_Rows(dmat) != SUNDenseMatrix_Columns(dmat)) caml_raise_constant(LSOLVER_EXN(MatrixNotSquare)); if (SUNDenseMatrix_Rows(dmat) != NV_LENGTH_S(NVEC_VAL(vnvec))) caml_raise_constant(LSOLVER_EXN(MatrixVectorMismatch)); caml_raise_out_of_memory(); } CAMLreturn(alloc_lsolver(ls)); #else CAMLreturn(Val_unit); #endif }
SUNLinearSolver SUNLinSol_LapackDense(N_Vector y, SUNMatrix A) { SUNLinearSolver S; SUNLinearSolver_Ops ops; SUNLinearSolverContent_LapackDense content; sunindextype MatrixRows, VecLength; /* Check compatibility with supplied SUNMatrix and N_Vector */ if (SUNMatGetID(A) != SUNMATRIX_DENSE) return(NULL); if (SUNDenseMatrix_Rows(A) != SUNDenseMatrix_Columns(A)) return(NULL); MatrixRows = SUNDenseMatrix_Rows(A); if ( (N_VGetVectorID(y) != SUNDIALS_NVEC_SERIAL) && (N_VGetVectorID(y) != SUNDIALS_NVEC_OPENMP) && (N_VGetVectorID(y) != SUNDIALS_NVEC_PTHREADS) ) return(NULL); /* optimally this function would be replaced with a generic N_Vector routine */ VecLength = GlobalVectorLength_LapDense(y); if (MatrixRows != VecLength) return(NULL); /* Create linear solver */ S = NULL; S = (SUNLinearSolver) malloc(sizeof *S); if (S == NULL) return(NULL); /* Create linear solver operation structure */ ops = NULL; ops = (SUNLinearSolver_Ops) malloc(sizeof(struct _generic_SUNLinearSolver_Ops)); if (ops == NULL) { free(S); return(NULL); } /* Attach operations */ ops->gettype = SUNLinSolGetType_LapackDense; ops->initialize = SUNLinSolInitialize_LapackDense; ops->setup = SUNLinSolSetup_LapackDense; ops->solve = SUNLinSolSolve_LapackDense; ops->lastflag = SUNLinSolLastFlag_LapackDense; ops->space = SUNLinSolSpace_LapackDense; ops->free = SUNLinSolFree_LapackDense; ops->setatimes = NULL; ops->setpreconditioner = NULL; ops->setscalingvectors = NULL; ops->numiters = NULL; ops->resnorm = NULL; ops->resid = NULL; /* Create content */ content = NULL; content = (SUNLinearSolverContent_LapackDense) malloc(sizeof(struct _SUNLinearSolverContent_LapackDense)); if (content == NULL) { free(ops); free(S); return(NULL); } /* Fill content */ content->N = MatrixRows; content->last_flag = 0; content->pivots = NULL; content->pivots = (sunindextype *) malloc(MatrixRows * sizeof(sunindextype)); if (content->pivots == NULL) { free(content); free(ops); free(S); return(NULL); } /* Attach content and ops */ S->content = content; S->ops = ops; return(S); }