9 #ifndef OPENVDB_MATH_CONJGRADIENT_HAS_BEEN_INCLUDED
10 #define OPENVDB_MATH_CONJGRADIENT_HAS_BEEN_INCLUDED
17 #include <tbb/parallel_for.h>
18 #include <tbb/parallel_reduce.h>
37 template<
typename ValueType>
class Vector;
55 template<
typename ValueType>
63 s.
absoluteError = std::numeric_limits<ValueType>::epsilon() * 100.0;
90 template<
typename PositiveDefMatrix>
93 const PositiveDefMatrix&
A,
94 const Vector<typename PositiveDefMatrix::ValueType>&
b,
95 Vector<typename PositiveDefMatrix::ValueType>&
x,
96 Preconditioner<typename PositiveDefMatrix::ValueType>& preconditioner,
97 const State& termination = terminationDefaults<typename PositiveDefMatrix::ValueType>());
122 template<
typename PositiveDefMatrix,
typename Interrupter>
125 const PositiveDefMatrix& A,
126 const Vector<typename PositiveDefMatrix::ValueType>& b,
127 Vector<typename PositiveDefMatrix::ValueType>& x,
128 Preconditioner<typename PositiveDefMatrix::ValueType>& preconditioner,
129 Interrupter& interrupter,
130 const State& termination = terminationDefaults<typename PositiveDefMatrix::ValueType>());
151 ~Vector() { mSize = 0;
delete[] mData; mData =
nullptr; }
161 bool empty()
const {
return (mSize == 0); }
175 template<
typename Scalar>
void scale(
const Scalar&
s);
192 template<
typename OtherValueType>
210 inline const T*
data()
const {
return mData; }
216 template<
typename Scalar>
struct ScaleOp;
217 struct DeterministicDotProductOp;
219 template<
typename OtherValueType>
struct EqOp;
236 template<
typename ValueType_, SizeType STENCIL_SIZE>
244 class ConstValueIter;
283 template<
typename Scalar>
void scale(
const Scalar&
s);
284 template<
typename Scalar>
291 template<
typename VecValueType>
298 template<
typename VecValueType>
299 void vectorMultiply(
const VecValueType* inVec, VecValueType* resultVec)
const;
303 template<
typename OtherValueType>
319 struct ConstRowData {
321 mVals(v), mCols(c), mSize(s) {}
326 template<
typename DataType_ = RowData>
332 static SizeType capacity() {
return STENCIL_SIZE; }
336 bool empty()
const {
return (mData.mSize == 0); }
343 ConstValueIter cbegin()
const;
347 template<
typename OtherDataType>
348 bool eq(
const RowBase<OtherDataType>& other,
354 template<
typename VecValueType>
355 VecValueType
dot(
const VecValueType* inVec,
SizeType vecSize)
const;
358 template<
typename VecValueType>
359 VecValueType
dot(
const Vector<VecValueType>& inVec)
const;
365 friend class ConstValueIter;
379 using ConstRowBase = RowBase<ConstRowData>;
389 return mData.mVals[mCursor];
396 operator bool()
const {
return (mCursor < mData.mSize); }
402 ConstValueIter(
const RowData& d): mData(d.mVals, d.mCols, d.mSize), mCursor(0) {}
405 const ConstRowData mData;
433 template<
typename Scalar>
void scale(
const Scalar&);
434 template<
typename Scalar>
445 template<
typename VecValueType>
struct VecMultOp;
446 template<
typename Scalar>
struct RowScaleOp;
450 template<
typename OtherValueType>
struct EqOp;
453 std::unique_ptr<ValueType[]> mValueArray;
454 std::unique_ptr<SizeType[]> mColumnIdxArray;
455 std::unique_ptr<SizeType[]> mRowSizeArray;
522 LinearOp(
const T& a_,
const T* x_,
const T* y_, T* out_):
a(a_), x(x_),
y(y_),
out(out_) {}
547 os << (state.
success ?
"succeeded with " :
"")
572 if (mSize != other.mSize) {
575 mData =
new T[mSize];
607 template<
typename Scalar>
610 ScaleOp(T* data_,
const Scalar& s_):
data(data_),
s(s_) {}
622 template<
typename Scalar>
635 a(a_), b(b_), binCount(binCount_), arraySize(arraySize_), reducetmp(reducetmp_) {}
639 const SizeType binSize = arraySize / binCount;
644 const SizeType end = (
n == binCount-1) ? arraySize : begin + binSize;
647 T sum = zeroVal<T>();
648 for (
SizeType i = begin; i <
end; ++i) { sum +=
a[i] * b[i]; }
666 assert(this->
size() == other.size());
668 const T* aData = this->
data();
669 const T* bData = other.data();
675 if (arraySize < 1024) {
680 result += aData[
n] * bData[
n];
696 result += partialSums[
n];
741 if (!std::isfinite(
data[
n]))
return false;
756 bool finite = tbb::parallel_reduce(
SizeRange(0, this->
size()),
true,
758 [](
bool finite1,
bool finite2) {
return (finite1 && finite2); });
764 template<
typename OtherValueType>
767 EqOp(
const T* a_,
const OtherValueType* b_, T e):
a(a_), b(b_), eps(e) {}
780 const OtherValueType*
b;
786 template<
typename OtherValueType>
790 if (this->
size() != other.size())
return false;
791 bool equal = tbb::parallel_reduce(
SizeRange(0, this->
size()),
true,
792 EqOp<OtherValueType>(this->
data(), other.data(), eps),
793 [](
bool eq1,
bool eq2) {
return (eq1 && eq2); });
802 std::ostringstream ostr;
806 ostr << sep << (*this)[
n];
817 template<
typename ValueType, SizeType STENCIL_SIZE>
821 , mValueArray(new
ValueType[mNumRows * STENCIL_SIZE])
822 , mColumnIdxArray(new
SizeType[mNumRows * STENCIL_SIZE])
823 , mRowSizeArray(new
SizeType[mNumRows])
831 template<
typename ValueType, SizeType STENCIL_SIZE>
835 from(&from_), to(&to_) {}
839 const ValueType* fromVal = from->mValueArray.get();
840 const SizeType* fromCol = from->mColumnIdxArray.get();
841 ValueType* toVal = to->mValueArray.get();
842 SizeType* toCol = to->mColumnIdxArray.get();
844 toVal[
n] = fromVal[
n];
845 toCol[
n] = fromCol[
n];
853 template<
typename ValueType, SizeType STENCIL_SIZE>
856 : mNumRows(other.mNumRows)
857 , mValueArray(new
ValueType[mNumRows * STENCIL_SIZE])
858 , mColumnIdxArray(new
SizeType[mNumRows * STENCIL_SIZE])
859 , mRowSizeArray(new
SizeType[mNumRows])
872 template<
typename ValueType, SizeType STENCIL_SIZE>
877 assert(row < mNumRows);
878 this->getRowEditor(row).setValue(col, val);
882 template<
typename ValueType, SizeType STENCIL_SIZE>
886 assert(row < mNumRows);
887 return this->getConstRow(row).getValue(col);
891 template<
typename ValueType, SizeType STENCIL_SIZE>
899 template<
typename ValueType, SizeType STENCIL_SIZE>
900 template<
typename Scalar>
908 RowEditor
row = mat->getRowEditor(
n);
918 template<
typename ValueType, SizeType STENCIL_SIZE>
919 template<
typename Scalar>
928 template<
typename ValueType, SizeType STENCIL_SIZE>
929 template<
typename VecValueType>
933 mat(&m), in(i), out(o) {}
937 for (
SizeType n = range.begin(), N = range.end();
n <
N; ++
n) {
938 ConstRow
row = mat->getConstRow(
n);
939 out[
n] = row.dot(in, mat->numRows());
944 const VecValueType* in;
949 template<
typename ValueType, SizeType STENCIL_SIZE>
950 template<
typename VecValueType>
955 if (inVec.size() != mNumRows) {
956 OPENVDB_THROW(ArithmeticError,
"matrix and input vector have incompatible sizes ("
957 << mNumRows <<
"x" << mNumRows <<
" vs. " << inVec.size() <<
")");
959 if (resultVec.size() != mNumRows) {
960 OPENVDB_THROW(ArithmeticError,
"matrix and result vector have incompatible sizes ("
961 << mNumRows <<
"x" << mNumRows <<
" vs. " << resultVec.size() <<
")");
964 vectorMultiply(inVec.data(), resultVec.data());
968 template<
typename ValueType, SizeType STENCIL_SIZE>
969 template<
typename VecValueType>
972 const VecValueType* inVec, VecValueType* resultVec)
const
976 VecMultOp<VecValueType>(*
this, inVec, resultVec));
980 template<
typename ValueType, SizeType STENCIL_SIZE>
981 template<
typename OtherValueType>
986 a(&a_), b(&b_), eps(e) {}
991 for (
SizeType n = range.begin(), N = range.end();
n <
N; ++
n) {
992 if (!
a->getConstRow(
n).eq(b->getConstRow(
n), eps))
return false;
999 const SparseStencilMatrix<OtherValueType, STENCIL_SIZE>*
b;
1004 template<
typename ValueType, SizeType STENCIL_SIZE>
1005 template<
typename OtherValueType>
1010 if (this->numRows() != other.
numRows())
return false;
1011 bool equal = tbb::parallel_reduce(
SizeRange(0, this->numRows()),
true,
1012 EqOp<OtherValueType>(*
this, other, eps),
1013 [](
bool eq1,
bool eq2) {
return (eq1 && eq2); });
1018 template<
typename ValueType, SizeType STENCIL_SIZE>
1026 for (
SizeType n = range.begin(), N = range.end();
n <
N; ++
n) {
1029 if (!std::isfinite(*it))
return false;
1040 template<
typename ValueType, SizeType STENCIL_SIZE>
1045 bool finite = tbb::parallel_reduce(
SizeRange(0, this->numRows()),
true,
1046 IsFiniteOp(*
this), [](
bool finite1,
bool finite2) {
return (finite1&&finite2); });
1051 template<
typename ValueType, SizeType STENCIL_SIZE>
1055 std::ostringstream ostr;
1057 ostr <<
n <<
": " << this->getConstRow(
n).str() <<
"\n";
1063 template<
typename ValueType, SizeType STENCIL_SIZE>
1067 assert(i < mNumRows);
1069 return RowEditor(&mValueArray[head], &mColumnIdxArray[head], mRowSizeArray[i], mNumRows);
1073 template<
typename ValueType, SizeType STENCIL_SIZE>
1077 assert(i < mNumRows);
1079 return ConstRow(&mValueArray[head], &mColumnIdxArray[head], mRowSizeArray[i]);
1083 template<
typename ValueType, SizeType STENCIL_SIZE>
1084 template<
typename DataType>
1088 if (this->empty())
return mData.mSize;
1092 const SizeType* colPtr = std::lower_bound(mData.mCols, mData.mCols + mData.mSize, columnIdx);
1094 return static_cast<SizeType>(colPtr - mData.mCols);
1098 template<
typename ValueType, SizeType STENCIL_SIZE>
1099 template<
typename DataType>
1106 if (idx < this->
size() && this->
column(idx) == columnIdx) {
1108 return this->
value(idx);
1113 template<
typename ValueType, SizeType STENCIL_SIZE>
1114 template<
typename DataType>
1119 if (idx < this->
size() && this->
column(idx) == columnIdx) {
1120 return this->
value(idx);
1126 template<
typename ValueType, SizeType STENCIL_SIZE>
1127 template<
typename DataType>
1128 inline typename SparseStencilMatrix<ValueType, STENCIL_SIZE>::ConstValueIter
1129 SparseStencilMatrix<ValueType, STENCIL_SIZE>::RowBase<DataType>::cbegin()
const
1131 return ConstValueIter(mData);
1135 template<
typename ValueType, SizeType STENCIL_SIZE>
1136 template<
typename DataType>
1137 template<
typename OtherDataType>
1140 const RowBase<OtherDataType>& other,
ValueType eps)
const
1142 if (this->
size() != other.size())
return false;
1143 for (ConstValueIter it = cbegin(), oit = other.cbegin(); it || oit; ++it, ++oit) {
1144 if (it.column() != oit.column())
return false;
1151 template<
typename ValueType, SizeType STENCIL_SIZE>
1152 template<
typename DataType>
1153 template<
typename VecValueType>
1156 const VecValueType* inVec,
SizeType vecSize)
const
1158 VecValueType
result = zeroVal<VecValueType>();
1160 result +=
static_cast<VecValueType
>(this->
value(idx) * inVec[this->
column(idx)]);
1165 template<
typename ValueType, SizeType STENCIL_SIZE>
1166 template<
typename DataType>
1167 template<
typename VecValueType>
1170 const Vector<VecValueType>& inVec)
const
1172 return dot(inVec.data(), inVec.size());
1176 template<
typename ValueType, SizeType STENCIL_SIZE>
1177 template<
typename DataType>
1181 std::ostringstream ostr;
1184 ostr << sep <<
"(" << this->
column(
n) <<
", " << this->
value(
n) <<
")";
1191 template<
typename ValueType, SizeType STENCIL_SIZE>
1195 ConstRowBase(ConstRowData(const_cast<
ValueType*>(valueHead),
1201 template<
typename ValueType, SizeType STENCIL_SIZE>
1205 RowBase<>(RowData(valueHead, columnHead, rowSize)), mNumColumns(colSize)
1210 template<
typename ValueType, SizeType STENCIL_SIZE>
1215 RowBase<>::mData.mSize = 0;
1219 template<
typename ValueType, SizeType STENCIL_SIZE>
1224 assert(column < mNumColumns);
1226 RowData&
data = RowBase<>::mData;
1232 if (offset < data.mSize && data.mCols[offset] == column) {
1239 assert(data.mSize <
this->capacity());
1241 if (offset >= data.mSize) {
1243 data.mVals[data.mSize] =
value;
1244 data.mCols[data.mSize] =
column;
1247 for (
SizeType i = data.mSize; i > offset; --i) {
1248 data.mVals[i] = data.mVals[i - 1];
1249 data.mCols[i] = data.mCols[i - 1];
1260 template<
typename ValueType, SizeType STENCIL_SIZE>
1261 template<
typename Scalar>
1265 for (
int idx = 0, N = this->
size(); idx <
N; ++idx) {
1266 RowBase<>::mData.mVals[idx] *=
s;
1275 template<
typename MatrixType>
1300 assert(r.size() == z.size());
1301 assert(r.size() ==
size);
1313 InitOp(
const MatrixType& m,
ValueType*
v): mat(&m), vec(v) {}
1315 for (
SizeType n = range.begin(), N = range.end();
n <
N; ++
n) {
1328 x(x_),
y(y_), out(out_) {}
1330 for (
SizeType n = range.begin(), N = range.end();
n <
N; ++
n) out[
n] = x[
n] *
y[
n];
1341 template<
typename MatrixType>
1342 class IncompleteCholeskyPreconditioner:
public Preconditioner<typename MatrixType::ValueType>
1345 struct CopyToLowerOp;
1359 , mLowerTriangular(matrix.
numRows())
1360 , mUpperTriangular(matrix.
numRows())
1387 mPassedCompatibilityCondition =
true;
1392 ValueType diagonalValue = crow_k.getValue(k);
1395 if (diagonalValue < 1.e-5) {
1396 mPassedCompatibilityCondition =
false;
1400 diagonalValue =
Sqrt(diagonalValue);
1403 row_k.setValue(k, diagonalValue);
1406 typename MatrixType::ConstRow srcRow = matrix.getConstRow(k);
1407 typename MatrixType::ConstValueIter citer = srcRow.cbegin();
1408 for ( ; citer; ++citer) {
1410 if (ii < k+1)
continue;
1414 row_ii.setValue(k, *citer / diagonalValue);
1419 for ( ; citer; ++citer) {
1421 if (j < k+1)
continue;
1428 typename MatrixType::ConstRow
mask = matrix.getConstRow(j);
1429 typename MatrixType::ConstValueIter maskIter = mask.cbegin();
1430 for ( ; maskIter; ++maskIter) {
1432 if (i < j)
continue;
1438 a_ij -= a_ik * a_jk;
1440 row_i.setValue(j, a_ij);
1447 TransposeOp(matrix, mLowerTriangular, mUpperTriangular));
1452 bool isValid()
const override {
return mPassedCompatibilityCondition; }
1456 if (!mPassedCompatibilityCondition) {
1457 OPENVDB_THROW(ArithmeticError,
"invalid Cholesky decomposition");
1464 zVec.fill(zeroVal<ValueType>());
1467 if (size == 0)
return;
1469 assert(rVec.size() ==
size);
1470 assert(zVec.size() ==
size);
1473 mTempVec.fill(zeroVal<ValueType>());
1479 typename TriangularMatrix::ConstRow
row = mLowerTriangular.getConstRow(i);
1482 tmpData[i] = (rData[i] -
dot) / diagonal;
1483 if (!std::isfinite(tmpData[i])) {
1492 typename TriangularMatrix::ConstRow
row = mUpperTriangular.getConstRow(i);
1495 zData[i] = (tmpData[i] -
dot) / diagonal;
1496 if (!std::isfinite(zData[i])) {
1507 struct CopyToLowerOp
1509 CopyToLowerOp(
const MatrixType& m, TriangularMatrix& l): mat(&m),
lower(&l) {}
1511 for (
SizeType n = range.begin(), N = range.end();
n <
N; ++
n) {
1512 typename TriangularMatrix::RowEditor outRow =
lower->getRowEditor(
n);
1514 typename MatrixType::ConstRow inRow = mat->getConstRow(
n);
1515 for (
typename MatrixType::ConstValueIter it = inRow.cbegin(); it; ++it) {
1516 if (it.column() >
n)
continue;
1517 outRow.setValue(it.column(), *it);
1521 const MatrixType* mat; TriangularMatrix*
lower;
1527 TransposeOp(
const MatrixType& m,
const TriangularMatrix& l, TriangularMatrix& u):
1530 for (
SizeType n = range.begin(), N = range.end();
n <
N; ++
n) {
1531 typename TriangularMatrix::RowEditor outRow =
upper->getRowEditor(
n);
1534 typename MatrixType::ConstRow inRow = mat->getConstRow(
n);
1535 for (
typename MatrixType::ConstValueIter it = inRow.cbegin(); it; ++it) {
1537 if (column <
n)
continue;
1538 outRow.setValue(column,
lower->getValue(column,
n));
1542 const MatrixType* mat;
const TriangularMatrix*
lower; TriangularMatrix*
upper;
1545 TriangularMatrix mLowerTriangular;
1546 TriangularMatrix mUpperTriangular;
1547 Vector<ValueType> mTempVec;
1548 bool mPassedCompatibilityCondition;
1555 namespace internal {
1558 template<
typename T>
1566 template<
typename T>
1570 assert(xVec.size() == yVec.size());
1571 assert(xVec.size() == result.size());
1572 axpy(a, xVec.data(), yVec.data(), result.data(), xVec.size());
1577 template<
typename MatrixOperator,
typename VecValueType>
1580 const VecValueType* b, VecValueType*
r)
1583 A.vectorMultiply(x, r);
1589 template<
typename MatrixOperator,
typename T>
1593 assert(x.size() == b.size());
1594 assert(x.size() == r.size());
1595 assert(x.size() == A.numRows());
1606 template<
typename PositiveDefMatrix>
1609 const PositiveDefMatrix& Amat,
1613 const State& termination)
1616 return solve(Amat, bVec, xVec, precond, interrupter, termination);
1620 template<
typename PositiveDefMatrix,
typename Interrupter>
1623 const PositiveDefMatrix& Amat,
1627 Interrupter& interrupter,
1628 const State& termination)
1644 if (size != bVec.size()) {
1645 OPENVDB_THROW(ArithmeticError,
"A and b have incompatible sizes"
1646 << size <<
"x" << size <<
" vs. " << bVec.size() <<
")");
1648 if (size != xVec.size()) {
1649 OPENVDB_THROW(ArithmeticError,
"A and x have incompatible sizes"
1650 << size <<
"x" << size <<
" vs. " << xVec.size() <<
")");
1667 assert(rVec.isFinite());
1686 for ( ; iteration < termination.
iterations; ++iteration) {
1688 if (interrupter.wasInterrupted()) {
1689 OPENVDB_THROW(RuntimeError,
"conjugate gradient solver was interrupted");
1698 precond.apply(rVec, zVec);
1702 assert(std::isfinite(rDotZ));
1704 if (0 == iteration) {
1708 const ValueType beta = rDotZ / rDotZPrev;
1714 Amat.vectorMultiply(pVec, qVec);
1718 assert(std::isfinite(pAp));
1730 l2Error = rVec.l2Norm();
1731 minL2Error =
Min(l2Error, minL2Error);
1736 if (l2Error > 2 * minL2Error) {
1767 #endif // OPENVDB_MATH_CONJGRADIENT_HAS_BEEN_INCLUDED
void operator()(const SizeRange &range) const
SharedPtr< JacobiPreconditioner > Ptr
bool isFinite() const
Return true if every element of this matrix has a finite value.
void apply(const Vector< ValueType > &rVec, Vector< ValueType > &zVec) override
void parallel_for(int64_t start, int64_t end, std::function< void(int64_t index)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
std::string upper(string_view a)
Return an all-upper case version of a (locale-independent).
void scale(const Scalar &s)
Multiply each element of this vector by s.
RowEditor getRowEditor(SizeType row)
Return a read/write view onto the given row of this matrix.
void scale(const Scalar &)
Scale all of the entries in this row.
Lightweight, variable-length vector.
void resize(SizeType n)
Reset this vector to have n elements, with uninitialized values.
T * data()
Return a pointer to this vector's elements.
const ValueType & operator()(SizeType row, SizeType col) const
Return the value at the given coordinates.
void axpy(const T &a, const T *xVec, const T *yVec, T *resultVec, SizeType size)
Compute ax + y.
bool eq(const Vector< OtherValueType > &other, ValueType eps=Tolerance< ValueType >::value()) const
Return true if this vector is equivalent to the given vector to within the specified tolerance...
const ValueType & getValue(SizeType row, SizeType col) const
Return the value at the given coordinates.
const TriangularMatrix & lowerMatrix() const
bool eq(const SparseStencilMatrix< OtherValueType, STENCIL_SIZE > &other, ValueType eps=Tolerance< ValueType >::value()) const
Return true if this matrix is equivalent to the given matrix to within the specified tolerance...
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
void apply(const Vector< ValueType > &r, Vector< ValueType > &z) override
void computeResidual(const MatrixOperator &A, const Vector< T > &x, const Vector< T > &b, Vector< T > &r)
Compute r = b − Ax.
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
IncompleteCholeskyPreconditioner(const MatrixType &matrix)
void axpy(const T &a, const Vector< T > &xVec, const Vector< T > &yVec, Vector< T > &result)
Compute ax + y.
UT_StringArray JOINTS head
JacobiPreconditioner(const MatrixType &A)
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
ConstRow(const ValueType *valueHead, const SizeType *columnHead, const SizeType &rowSize)
Read-only accessor to a row of this matrix.
GLdouble GLdouble GLdouble z
#define OPENVDB_LOG_WARN(mesg)
GLboolean GLboolean GLboolean GLboolean a
#define OPENVDB_USE_VERSION_NAMESPACE
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
**But if you need a or simply need to know when the task has note that the like this
Iterator over the stored values in a row of this matrix.
**But if you need a result
Information about the state of a conjugate gradient solution.
InfNormOp(const T *data_)
SizeType size() const
Return the number of rows in this matrix.
Base class for interrupters.
std::string str() const
Return a string representation of this vector.
Tolerance for floating-point comparison.
SizeType numRows() const
Return the number of rows in this matrix.
const T * data() const
Return a pointer to this vector's elements.
const T & at(SizeType i) const
Return the value of this vector's ith element.
ValueType l2Norm() const
Return the L2 norm of this vector.
__hostdev__ float getValue(uint32_t i) const
DeterministicDotProductOp(const T *a_, const T *b_, const SizeType binCount_, const SizeType arraySize_, T *reducetmp_)
Sparse, square matrix representing a 3D stencil operator of size STENCIL_SIZE.
tbb::blocked_range< SizeType > SizeRange
Read/write accessor to a row of this matrix.
std::shared_ptr< T > SharedPtr
typename TriangularMatrix::RowEditor TriangleRowEditor
T & operator[](SizeType i)
Return the value of this vector's ith element.
SYS_FORCE_INLINE const_iterator end() const
SharedPtr< Preconditioner > Ptr
bool operator()(const SizeRange &range, bool finite) const
T & at(SizeType i)
Return the value of this vector's ith element.
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
void operator()(const SizeRange &range) const
std::ostream & operator<<(std::ostream &os, const State &state)
Preconditioner using incomplete Cholesky factorization.
Coord Abs(const Coord &xyz)
ValueType dot(const Vector &) const
Return the dot product of this vector with the given vector, which must be the same size...
SparseStencilMatrix(SizeType n)
Construct an n x n matrix with at most STENCIL_SIZE nonzero elements per row.
bool empty() const
Return true if this vector has no elements.
State solve(const PositiveDefMatrix &A, const Vector< typename PositiveDefMatrix::ValueType > &b, Vector< typename PositiveDefMatrix::ValueType > &x, Preconditioner< typename PositiveDefMatrix::ValueType > &preconditioner, const State &termination=terminationDefaults< typename PositiveDefMatrix::ValueType >())
Solve Ax = b via the preconditioned conjugate gradient method.
MatrixCopyOp(const SparseStencilMatrix &from_, SparseStencilMatrix &to_)
Vector(SizeType n)
Construct a vector of n elements, with uninitialized values.
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
const SparseStencilMatrix * mat
void clear()
Set the number of entries in this row to zero.
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Base class for conjugate gradient preconditioners.
const T * constData() const
Return a pointer to this vector's elements.
void computeResidual(const MatrixOperator &A, const VecValueType *x, const VecValueType *b, VecValueType *r)
Compute r = b − Ax.
float Sqrt(float x)
Return the square root of a floating-point value.
const TriangularMatrix & upperMatrix() const
Vector & operator*=(const Scalar &s)
Multiply each element of this vector by s.
CopyOp(const T *from_, T *to_)
GLfloat GLfloat GLfloat alpha
void swap(Vector &other)
Swap internal storage with another vector, which need not be the same size.
void operator()(const SizeRange &range) const
bool operator()(const SizeRange &range, bool finite) const
ValueType infNorm() const
Return the infinity norm of this vector.
Vector< ValueType > VectorType
const T & operator[](SizeType i) const
Return the value of this vector's ith element.
RowEditor(ValueType *valueHead, SizeType *columnHead, SizeType &rowSize, SizeType colSize)
Vector()
Construct an empty vector.
bool isApproxZero(const Type &x)
Return true if x is equal to zero to within the default floating-point comparison tolerance...
GLboolean GLboolean GLboolean b
void setValue(SizeType row, SizeType col, const ValueType &)
Set the value at the given coordinates.
Vector & operator=(const Vector &)
Deep copy the given vector.
FillOp(T *data_, const T &val_)
void fill(const ValueType &value)
Set all elements of this vector to value.
virtual ~Preconditioner()=default
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
SizeType size() const
Return the number of elements in this vector.
void scale(const Scalar &s)
Multiply all elements in the matrix by s;.
typename MatrixType::ValueType ValueType
SharedPtr< SparseStencilMatrix > Ptr
SharedPtr< IncompleteCholeskyPreconditioner > Ptr
void vectorMultiply(const Vector< VecValueType > &inVec, Vector< VecValueType > &resultVec) const
Multiply this matrix by inVec and return the result in resultVec.
SparseStencilMatrix & operator*=(const Scalar &s)
Multiply all elements in the matrix by s;.
ConstRow getConstRow(SizeType row) const
Return a read-only view onto the given row of this matrix.
SizeType setValue(SizeType column, const ValueType &value)
Set the value of the entry in the specified column.
std::string lower(string_view a)
Return an all-upper case version of a (locale-independent).
static constexpr ValueType sZeroValue
#define OPENVDB_LOG_DEBUG_RUNTIME(mesg)
virtual bool isValid() const
Preconditioner(const SparseStencilMatrix< T, STENCIL_SIZE > &)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
RowEditor & operator*=(const Scalar &s)
Scale all of the entries in this row.
const Type & Min(const Type &a, const Type &b)
Return the minimum of two values.
GA_API const UT_StringHolder N
bool isFinite() const
Return true if all values along the diagonal are finite.
const ValueType & operator*() const
T operator()(const SizeRange &range, T maxValue) const
bool isValid() const override
bool isFinite() const
Return true if every element of this vector has a finite value.
GLenum GLenum GLsizei void * row
IsFiniteOp(const T *data_)
std::string str() const
Return a string representation of this matrix.
void operator()(const SizeRange &range) const
GLenum GLenum GLsizei void GLsizei void * column
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
virtual void apply(const Vector< T > &r, Vector< T > &z)=0
Apply this preconditioner to a residue vector: z = M−1r
typename TriangularMatrix::ConstRow TriangleConstRow
State terminationDefaults()
Return default termination conditions for a conjugate gradient solver.
const Type & Max(const Type &a, const Type &b)
Return the maximum of two values.
LinearOp(const T &a_, const T *x_, const T *y_, T *out_)
typename MatrixType::ValueType ValueType
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Vector(SizeType n, const ValueType &val)
Construct a vector of n elements and initialize each element to the given value.
#define OPENVDB_THROW(exception, message)
ConstValueIter & operator++()
IsFiniteOp(const SparseStencilMatrix &m)
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
void operator()(const SizeRange &range) const
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.