本文整理汇总了C++中BaseMatrix类的典型用法代码示例。如果您正苦于以下问题:C++ BaseMatrix类的具体用法?C++ BaseMatrix怎么用?C++ BaseMatrix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void SymmetricBandMatrix<TYPE>::operator<<(const BaseMatrix<TYPE>& bm)
{
if (&bm == this)
{
return;
}
assert(bm.Nrows() == GeneralMatrix<TYPE>::nrows && bm.Ncols() == GeneralMatrix<TYPE>::ncols);
int n = GeneralMatrix<TYPE>::nrows, lb = this->BandWidth().Lower();
if (bm.Search(*this) == 0)
{
for (int i = 0; i <= lb; ++i)
{
for (int j = 1; j <= n - i; ++j)
{
operator()(j + i, j) = bm(j + i, j);
}
}
}
else
{
SymmetricBandMatrix<TYPE> t(n, lb);
t << bm;
this->Swap(t);
}
}
示例2: assert
void MICAcceleratorMatrixHYB<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) {
const MICAcceleratorMatrixHYB<ValueType> *mic_cast_mat;
const HostMatrix<ValueType> *host_cast_mat;
// copy only in the same format
assert(this->get_mat_format() == src.get_mat_format());
// MIC to MIC copy
if ((mic_cast_mat = dynamic_cast<const MICAcceleratorMatrixHYB<ValueType>*> (&src)) != NULL) {
if (this->get_nnz() == 0)
this->AllocateHYB(mic_cast_mat->get_ell_nnz(), mic_cast_mat->get_coo_nnz(), mic_cast_mat->get_ell_max_row(),
mic_cast_mat->get_nrow(), mic_cast_mat->get_ncol());
assert((this->get_nnz() == src.get_nnz()) &&
(this->get_nrow() == src.get_nrow()) &&
(this->get_ncol() == src.get_ncol()) );
if (this->get_ell_nnz() > 0) {
copy_mic_mic(this->local_backend_.MIC_dev,
mic_cast_mat->mat_.ELL.val, this->mat_.ELL.val, this->get_ell_nnz());
copy_mic_mic(this->local_backend_.MIC_dev,
mic_cast_mat->mat_.ELL.col, this->mat_.ELL.col, this->get_ell_nnz());
}
if (this->get_coo_nnz() > 0) {
copy_mic_mic(this->local_backend_.MIC_dev,
mic_cast_mat->mat_.COO.row, this->mat_.COO.row, this->get_coo_nnz());
copy_mic_mic(this->local_backend_.MIC_dev,
mic_cast_mat->mat_.COO.col, this->mat_.COO.col, this->get_coo_nnz());
copy_mic_mic(this->local_backend_.MIC_dev,
mic_cast_mat->mat_.COO.val, this->mat_.COO.val, this->get_coo_nnz());
}
} else {
//CPU to MIC
if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) {
this->CopyFromHost(*host_cast_mat);
} else {
LOG_INFO("Error unsupported MIC matrix type");
this->info();
src.info();
FATAL_ERROR(__FILE__, __LINE__);
}
}
}
示例3: assert
void IdentityMatrix<TYPE>::Solve(const BaseMatrix<TYPE>& in, BaseMatrix<TYPE>& out) const
{
int n = GeneralMatrix<TYPE>::nrows;
assert(n == in.Nrows());
assert(in.Ncols() == out.Ncols() && in.Nrows() == out.Nrows());
std::shared_ptr<LinearEquationSolver<TYPE> > solver = this->MakeSolver();
solver->Solve(in, out);
}
示例4: InvalidVectorMath
Matrix<T> SymMatrix<T>::operator*(const BaseMatrix<T>& rhs) const
{
if(Matrix<T>::numCols() != rhs.numRows())
throw InvalidVectorMath("Trying to multiply two incompatable matrices");
Matrix<T> retval(Matrix<T>::numRows(), rhs.numCols());
for(unsigned long i = 0; i < Matrix<T>::numRows(); i++)
for(unsigned long j = 0; j < rhs.numCols(); j++)
for(unsigned long k = 0; k < rhs.numCols(); k++)
retval.at(i,j) += (*this)(i,k) * rhs(k, j);
return retval;
}
示例5: assert
void MICAcceleratorMatrixDIA<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) {
const MICAcceleratorMatrixDIA<ValueType> *mic_cast_mat;
const HostMatrix<ValueType> *host_cast_mat;
// copy only in the same format
assert(this->get_mat_format() == src.get_mat_format());
// MIC to MIC copy
if ((mic_cast_mat = dynamic_cast<const MICAcceleratorMatrixDIA<ValueType>*> (&src)) != NULL) {
if (this->get_nnz() == 0)
this->AllocateDIA(mic_cast_mat->get_nnz(), mic_cast_mat->get_nrow(), mic_cast_mat->get_ncol(), mic_cast_mat->get_ndiag());
assert((this->get_nnz() == src.get_nnz()) &&
(this->get_nrow() == src.get_nrow()) &&
(this->get_ncol() == src.get_ncol()) );
if (this->get_nnz() > 0) {
copy_mic_mic(mic_cast_mat->mat_.val, this->mat_.val, this->get_nnz());
copy_mic_mic(mic_cast_mat->mat_.offset, this->mat_.offset, this->mat_.num_diag);
/*
// TODO
for (int j=0; j<this->get_nnz(); ++j)
this->mat_.val[j] = mic_cast_mat->mat_.val[j];
for (int j=0; j<this->mat_.num_diag; ++j)
this->mat_.offset[j] = mic_cast_mat->mat_.offset[j];
*/
}
} else {
//CPU to MIC
if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) {
this->CopyFromHost(*host_cast_mat);
} else {
LOG_INFO("Error unsupported MIC matrix type");
this->info();
src.info();
FATAL_ERROR(__FILE__, __LINE__);
}
}
}
示例6: assert
void OCLAcceleratorMatrixCOO<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) {
const OCLAcceleratorMatrixCOO<ValueType> *ocl_cast_mat;
const HostMatrix<ValueType> *host_cast_mat;
// copy only in the same format
assert(this->get_mat_format() == src.get_mat_format());
// OCL to OCL copy
if ((ocl_cast_mat = dynamic_cast<const OCLAcceleratorMatrixCOO<ValueType>*> (&src)) != NULL) {
if (this->get_nnz() == 0)
this->AllocateCOO(src.get_nnz(), src.get_nrow(), src.get_ncol() );
assert((this->get_nnz() == src.get_nnz()) &&
(this->get_nrow() == src.get_nrow()) &&
(this->get_ncol() == src.get_ncol()) );
if (this->get_nnz() > 0) {
// Copy object from device to device memory (internal copy)
ocl_dev2dev<int>(this->get_nnz(), // size
ocl_cast_mat->mat_.row, // src
this->mat_.row, // dst
OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue );
// Copy object from device to device memory (internal copy)
ocl_dev2dev<int>(this->get_nnz(), // size
ocl_cast_mat->mat_.col, // src
this->mat_.col, // dst
OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue );
// Copy object from device to device memory (internal copy)
ocl_dev2dev<ValueType>(this->get_nnz(), // size
ocl_cast_mat->mat_.val, // src
this->mat_.val, // dst
OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue );
}
} else {
//CPU to OCL
if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) {
this->CopyFromHost(*host_cast_mat);
} else {
LOG_INFO("Error unsupported OCL matrix type");
this->info();
src.info();
FATAL_ERROR(__FILE__, __LINE__);
}
}
}
示例7: lm
BandLUsolverPartialPivot<TYPE>::BandLUsolverPartialPivot(const BaseMatrix<TYPE> &bm, const TYPE &e) :
BandLUsolver<TYPE>(bm, bm.BandWidth().Lower(), std::min(bm.BandWidth().Lower() + bm.BandWidth().Upper(), bm.Nrows() - 1), e),
lm(bm.Nrows()), um(bm.Nrows(), BandLUsolver<TYPE>::ubw),
combine(lm, um)
{
lm << bm;
um << bm;
static const TYPE one(1);
for (int i = 1; i <= bm.Nrows(); ++i)
{
lm(i, i) = one;
}
BandLUdecomposion();
}
示例8:
bool HostMatrixCOO<ValueType>::ConvertFrom(const BaseMatrix<ValueType> &mat) {
this->Clear();
// empty matrix is empty matrix
if (mat.get_nnz() == 0)
return true;
if (const HostMatrixCOO<ValueType> *cast_mat = dynamic_cast<const HostMatrixCOO<ValueType>*> (&mat)) {
this->CopyFrom(*cast_mat);
return true;
}
if (const HostMatrixCSR<ValueType> *cast_mat = dynamic_cast<const HostMatrixCSR<ValueType>*> (&mat)) {
this->Clear();
csr_to_coo(this->local_backend_.OpenMP_threads,
cast_mat->get_nnz(), cast_mat->get_nrow(), cast_mat->get_ncol(),
cast_mat->mat_, &this->mat_);
this->nrow_ = cast_mat->get_nrow();
this->ncol_ = cast_mat->get_ncol();
this->nnz_ = cast_mat->get_nnz();
return true;
}
return false;
}
示例9: assert
void HostMatrixCOO<ValueType>::CopyFrom(const BaseMatrix<ValueType> &mat) {
// copy only in the same format
assert(this->get_mat_format() == mat.get_mat_format());
if (const HostMatrixCOO<ValueType> *cast_mat = dynamic_cast<const HostMatrixCOO<ValueType>*> (&mat)) {
if (this->nnz_ == 0)
this->AllocateCOO(cast_mat->nnz_, cast_mat->nrow_, cast_mat->ncol_ );
assert((this->nnz_ == cast_mat->nnz_) &&
(this->nrow_ == cast_mat->nrow_) &&
(this->ncol_ == cast_mat->ncol_) );
if (this->nnz_ > 0) {
_set_omp_backend_threads(this->local_backend_, this->nnz_);
#pragma omp parallel for
for (int j=0; j<this->nnz_; ++j)
this->mat_.row[j] = cast_mat->mat_.row[j];
#pragma omp parallel for
for (int j=0; j<this->nnz_; ++j)
this->mat_.col[j] = cast_mat->mat_.col[j];
#pragma omp parallel for
for (int j=0; j<this->nnz_; ++j)
this->mat_.val[j] = cast_mat->mat_.val[j];
}
} else {
// Host matrix knows only host matrices
// -> dispatching
mat.CopyTo(this);
}
}
示例10: assert
void CholeskySolver<TYPE>::CholeskyDecomposition(const BaseMatrix<TYPE> &bm)
{
assert(bm.Nrows() == bm.Ncols());
int n = lm.Nrows();
const TYPE &e = SimpleSolver<TYPE>::epsilon;
TYPE temp;
for (int i = 1; i <= n; ++i)
{
if (i == 1)
{
temp = bm(i, i);
}
else
{
temp = bm(i, i) - (c_sub(lm, i, i, 1, i - 1) * t(c_sub(lm, i, i, 1, i - 1)))(1, 1);
}
if (temp <= e)
{
LinearEquationSolver<TYPE>::fail = true;
return;
}
else
{
lm(i, i) = std::sqrt(temp);
for (int j = i + 1; j <= n; ++j)
{
if (i == 1)
{
lm(j, i) = bm(j, i) / lm(i, i);
}
else
{
lm(j, i) = (bm(j, i) - (c_sub(lm, i, i, 1, i - 1) * t(c_sub(lm, j, j, 1, i - 1)))(1, 1)) / lm(i, i);
}
}
}
}
}
示例11: SingularException
void ConstantSolver<TYPE>::Solve(const BaseMatrix<TYPE> &in, BaseMatrix<TYPE> &out) const
{
if (LinearEquationSolver<TYPE>::IsFailed())
{
Singleton<Tracer>::Instance()->AddMessage("ConstantSolver::Solve");
throw SingularException(SimpleSolver<TYPE>::mat);
}
int r = SimpleSolver<TYPE>::mat.Nrows();
int c = SimpleSolver<TYPE>::mat.Ncols();
assert(r == 1 && c == 1 && c == in.Nrows());
assert(in.Ncols() == out.Ncols() && in.Nrows() == out.Nrows());
const BaseMatrix<TYPE> &m = SimpleSolver<TYPE>::mat;
for (int i = 1; i <= c; ++i)
{
for (int j = r; j >= 1; --j)
{
out(j, i) = in(j, i) / m(j, j);
}
}
}
示例12: addTo
void SparseRowCpuMatrix::addTo(BaseMatrix& dest,
std::vector<uint32_t>& ids,
size_t tid,
size_t numThreads) {
CHECK(!dest.useGpu_);
CHECK_EQ(dest.height_ * dest.width_, this->height_ * this->width_);
std::vector<unsigned int>& localIndices = indexDictHandle_->localIndices;
for (size_t i = 0; i < localIndices.size(); ++i) {
uint32_t id = localIndices[i];
if (id % numThreads == tid) {
simd::addTo(dest.rowBuf(id), getLocalRow(i), this->width_);
ids.push_back(id);
}
}
}
示例13: assert
void OCLAcceleratorMatrixBCSR<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) {
const OCLAcceleratorMatrixBCSR<ValueType> *ocl_cast_mat;
const HostMatrix<ValueType> *host_cast_mat;
// copy only in the same format
assert(this->get_mat_format() == src.get_mat_format());
// OCL to OCL copy
if ((ocl_cast_mat = dynamic_cast<const OCLAcceleratorMatrixBCSR<ValueType>*> (&src)) != NULL) {
if (this->get_nnz() == 0)
this->AllocateBCSR(src.get_nnz(), src.get_nrow(), src.get_ncol() );
assert((this->get_nnz() == src.get_nnz()) &&
(this->get_nrow() == src.get_nrow()) &&
(this->get_ncol() == src.get_ncol()) );
ocl_cast_mat->get_nnz();
FATAL_ERROR(__FILE__, __LINE__);
} else {
//CPU to OCL
if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) {
this->CopyFromHost(*host_cast_mat);
} else {
LOG_INFO("Error unsupported OCL matrix type");
this->info();
src.info();
FATAL_ERROR(__FILE__, __LINE__);
}
}
}
示例14: NPDException
void CholeskySolver<TYPE>::Solve(const BaseMatrix<TYPE> &in, BaseMatrix<TYPE> &out) const
{
assert(in.Nrows() == lm.Ncols());
assert(in.Nrows() == out.Nrows() && in.Ncols() == out.Ncols());
if (LinearEquationSolver<TYPE>::fail)
{
Singleton<Tracer>::Instance()->AddMessage("CholeskySolver::Solve(in, out)");
throw NPDException(SimpleSolver<TYPE>::mat);
}
Matrix<TYPE> temp(out.Nrows(), out.Ncols());
lm.Solve(in, temp);
t(lm).Solve(temp, out);
}
示例15: LogicError
void LUsolverNoPivot<TYPE>::Solve(const BaseMatrix<TYPE> &in, BaseMatrix<TYPE> &out) const
{
assert(in.Nrows() == combine.Ncols());
assert(in.Nrows() == out.Nrows() && in.Ncols() == out.Ncols());
if (LinearEquationSolver<TYPE>::IsFailed())
{
Singleton<Tracer>::Instance()->AddMessage("LUsolverNoPivot::Solve");
throw LogicError("LUsolverNoPivot: LU decomposition is failed");
}
Matrix<TYPE> t(in.Nrows(), in.Ncols());
LUsolver<TYPE>::lm.Solve(in, t);
LUsolver<TYPE>::um.Solve(t, out);
}