void rSparseMatrix::setIdentity(double scalar) { if (nRow != nCol) { rError("rSparseMatrix:: Identity matrix must be square matrix"); } int length,step,index=0; switch(Sp_De_Di) { case SPARSE: if (nCol > NonZeroNumber) { rError("rSparseMatrix:: cannot store over NonZeroNumber"); // the number of Diagonal elements equals nCol. } NonZeroCount = nCol; NonZeroEffect = nCol; for (index=0; index< NonZeroCount; ++index) { row_index[index] = index; column_index[index] = index; sp_ele[index] = scalar; } break; case DENSE: length = nRow*nCol; catlas_dset(length,DZERO,de_ele,IONE); step = nCol+1; catlas_dset(nCol,scalar,de_ele,step); // only diagonal elements are the value of scalar. break; case DIAGONAL: catlas_dset(nCol,scalar,di_ele,IONE); break; } }
void rDenseMatrix:: initialize(int nRow, int nCol, rDenseMatrix::rDeMat_De_Di De_Di) { // rMessage("rDenseMatrix::initialize"); rDenseMatrix(); if (nRow<=0 || nCol<=0) { rError("rDenseMatrix:: Dimensions are nonpositive"); } int old_length = this->nRow*this->nCol; if (this->De_Di==DIAGONAL) { old_length = this->nRow; } this->nRow = nRow; this->nCol = nCol; this->De_Di = De_Di; int length; switch(De_Di) { case DENSE: length = nRow*nCol; if (de_ele && old_length!=length) { delete[] de_ele; de_ele = NULL; } if (de_ele==NULL) { rNewCheck(); de_ele = new double[length]; if (de_ele==NULL) { rError("rDenseMatrix:: memory exhausted"); } } catlas_dset(length,DZERO,de_ele,IONE); break; case DIAGONAL: if (nRow!=nCol) { rError("rDenseMatrix:: Diagonal must be Square matrix"); } if (di_ele && old_length!=nRow) { delete[] di_ele; di_ele = NULL; } if (di_ele==NULL) { rNewCheck(); di_ele = new double[nCol]; if (di_ele==NULL) { rError("rDenseMatrix:: memory exhausted"); } } catlas_dset(nCol,DZERO,di_ele,IONE); break; } }
void setA(double *du, double *dc, double *dl, int m, int n, double mu) { catlas_dset(m-1, -mu, du, 1); catlas_dset(m, (1+2*mu), dc, 1); catlas_dset(m-1, -mu, dl, 1); dc[0] = 1; du[0] = 0; dc[m-1] = 1; dl[m-2] = -1; }
void rDenseMatrix::setZero() { int length; switch(De_Di) { case DENSE: length = nRow*nCol; catlas_dset(length,DZERO,de_ele,IONE); break; case DIAGONAL: catlas_dset(nCol,DZERO,di_ele,IONE); break; } }
void rDenseMatrix::setIdentity(double scalar) { if (nRow != nCol) { rError("rSparseMatrix:: Identity matrix must be square matrix"); } int length,step; switch(De_Di) { case DENSE: length = nRow*nCol; catlas_dset(length,DZERO,de_ele,IONE); step = nCol+1; catlas_dset(nCol,scalar,de_ele,step); break; case DIAGONAL: catlas_dset(nCol,scalar,di_ele,IONE); break; } }
void rSparseMatrix::setZero() { int length; switch(Sp_De_Di) { case SPARSE: NonZeroCount = 0; NonZeroEffect = 0; // No element is stored. break; case DENSE: length = nRow*nCol; catlas_dset(length,DZERO,de_ele,IONE); break; case DIAGONAL: catlas_dset(nCol,DZERO,di_ele,IONE); break; } }
void rVector::initialize(double value) { if (nDim<=0) { rError("rVector:: nDim is nonpositive"); } if (ele==NULL) { rNewCheck(); ele = new double[nDim]; if (ele==NULL) { rError("rVector:: memory exhausted"); } } catlas_dset(nDim,value,ele,IONE); }
void rSparseMatrix::changeToDense(bool forceChange) { if (Sp_De_Di!=SPARSE) { return; } // if (false) // rMessage(" NonZeroCount " << NonZeroCount); // rMessage(" nRow*nCol*0.2 " << nRow*nCol*0.2); if (forceChange == false && NonZeroCount < (nRow*nCol) * 0.20) { // if the number of elements are less than 20 percent, // we don't change to Dense. return; } // rMessage("change"); Sp_De_Di = DENSE; de_ele = NULL; int length = nRow*nCol; rNewCheck(); de_ele = new double[length]; if (de_ele==NULL) { rError("rSparseMatrix:: memory exhausted"); } catlas_dset(length,DZERO,de_ele,IONE); // all elements are set 0. for (int index=0; index<NonZeroCount; ++index) { int i = row_index[index]; int j = column_index[index]; double value = sp_ele[index]; if (i==j) { de_ele[i+nCol*j] = value; } else { de_ele[i+nCol*j] = de_ele[j+nCol*i] = value; } } NonZeroCount = NonZeroNumber = NonZeroEffect = length; if (row_index != NULL) { delete[] row_index; } if (column_index != NULL) { delete[] column_index; } if (sp_ele != NULL) { delete[] sp_ele; } row_index = NULL; column_index = NULL; sp_ele = NULL; }
void rVector::initialize(int nDim,double value) { // rMessage("rVector initialize"); if (ele && this->nDim!=nDim) { if (ele) { delete[] ele; ele = NULL; } if (nDim<=0) { rError("rVector:: nDim is nonpositive"); } } this->nDim = nDim; if (ele==NULL) { ele = NULL; rNewCheck(); ele = new double[nDim]; if (ele==NULL) { rError("rVector:: memory exhausted"); } } catlas_dset(nDim,value,ele,IONE); }
JNIEXPORT void JNICALL Java_uncomplicate_neanderthal_CBLAS_dset (JNIEnv *env, jclass clazz, jint N, jdouble alpha, jobject X, jint offsetX, jint incX) { double *cX = (double *) (*env)->GetDirectBufferAddress(env, X); catlas_dset(N, alpha, cX + offsetX, incX); };
bool rDenseMatrix::copyFrom(rSparseMatrix& other) { int length,index=0; switch(other.Sp_De_Di) { case rSparseMatrix::SPARSE: De_Di = DENSE; if (de_ele) { delete[] de_ele; } de_ele = NULL; nRow = other.nRow; nCol = other.nCol; rNewCheck(); de_ele = new double[nRow*nCol]; if (de_ele==NULL) { rError("rDenseMatrix:: memory exhausted"); } length = nRow*nCol; catlas_dset(length,DZERO,de_ele,IONE); for (index = 0; index<other.NonZeroCount; ++index) { int i = other.row_index[index]; int j = other.column_index[index]; double value = other.sp_ele[index]; de_ele[i+nCol*j] = de_ele[j+nCol*i] = value; } break; case rSparseMatrix::DENSE: De_Di = DENSE; if (de_ele && (other.nRow!=nRow || other.nCol!=nCol)) { delete[] de_ele; de_ele = NULL; } nRow = other.nRow; nCol = other.nCol; rNewCheck(); de_ele = new double[nRow*nCol]; if (de_ele==NULL) { rError("rDenseMatrix:: memory exhausted"); } length = nRow*nCol; dcopy(&length,other.de_ele,&IONE,de_ele,&IONE); break; case rSparseMatrix::DIAGONAL: De_Di = DIAGONAL; if (di_ele && (other.nRow!=nRow || other.nCol!=nCol)) { delete[] di_ele; di_ele = NULL; } nRow = other.nRow; nCol = other.nCol; if (di_ele==NULL) { rNewCheck(); di_ele = new double[nCol]; if (di_ele==NULL) { rError("rDenseMatrix:: memory exhausted"); } } dcopy(&nCol,other.di_ele,&IONE,di_ele,&IONE); break; } return _SUCCESS; }
void rSparseMatrix:: initialize(int nRow, int nCol, rSparseMatrix::rSpMat_Sp_De_Di Sp_De_Di, int NonZeroNumber) { // rMessage("rSparseMatrix initialize"); rSparseMatrix(); if (nRow<=0 || nCol<=0) { rError("rSparseMatrix:: Dimensions are nonpositive"); } this->nRow = nRow; this->nCol = nCol; this->Sp_De_Di = Sp_De_Di; int length; row_index = NULL; column_index = NULL; sp_ele = NULL; switch(Sp_De_Di) { case SPARSE: this->NonZeroNumber = NonZeroNumber; this->NonZeroCount = 0; this->NonZeroEffect = 0; if (NonZeroNumber > 0) { rNewCheck(); row_index = new int[NonZeroNumber]; rNewCheck(); column_index = new int[NonZeroNumber]; rNewCheck(); sp_ele = new double[NonZeroNumber]; if (row_index==NULL || column_index==NULL || sp_ele==NULL) { rError("rSparseMatrix:: memory exhausted"); } } break; case DENSE: this->NonZeroNumber = nRow*nCol; this->NonZeroCount = nRow*nCol; this->NonZeroEffect = nRow*nCol; rNewCheck(); de_ele = new double[NonZeroNumber]; if (de_ele==NULL) { rError("rSparseMatrix:: memory exhausted"); } length = nRow*nCol; catlas_dset(length,DZERO,de_ele,IONE); // all elements are 0. break; case DIAGONAL: if (nRow!=nCol) { rError("rSparseMatrix:: Diagonal must be Square matrix"); } this->NonZeroNumber = nCol; this->NonZeroCount = nCol; this->NonZeroEffect = nCol; if (di_ele==NULL) { rNewCheck(); di_ele = new double[NonZeroNumber]; if (di_ele==NULL) { rError("rSparseMatrix:: memory exhausted"); } } catlas_dset(nCol,DZERO,di_ele,IONE); // all elements are 0. break; } }
void SGVector<float64_t>::set_const(float64_t const_elem) { catlas_dset(vlen, const_elem, vector, 1); }
/* * Force boundary conditions */ void forceBoundaryConditions(double *U, int m, int n, double x) { catlas_dset((R+1), x, U, 1); catlas_dset((R+1), x, &U[R*(R+1)], 1); catlas_dset((R+1), x, U, (R+1)); catlas_dset((R+1), x, &U[R], (R+1)); }
void SGVector<float64_t>::set_const(float64_t const_elem) { assert_on_cpu(); catlas_dset(vlen, const_elem, vector, 1); }