| // This file is part of Eigen, a lightweight C++ template library | |
| // for linear algebra. | |
| // | |
| // Copyright (C) 2008-2010 Gael Guennebaud <g.gael@free.fr> | |
| // | |
| // This Source Code Form is subject to the terms of the Mozilla | |
| // Public License v. 2.0. If a copy of the MPL was not distributed | |
| // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
| // SPDX-License-Identifier: MPL-2.0 | |
| #include <cstdlib> | |
| #include <string> | |
| #ifndef _WIN32 | |
| #include <sys/stat.h> | |
| #endif | |
| #include "sparse.h" | |
| #ifdef min | |
| #undef min | |
| #endif | |
| #ifdef max | |
| #undef max | |
| #endif | |
| #include <Eigen/SparseExtra> | |
| #include <Eigen/ArpackSupport> | |
| // Read from an environment variable TEST_TMPDIR, if available, | |
| // and append the provided filename. Defaults to local directory. | |
| std::string GetTestTempFilename(const char* filename) { | |
| const char* test_tmpdir = std::getenv("TEST_TMPDIR"); | |
| if (test_tmpdir == nullptr) { | |
| return std::string(filename); | |
| } | |
| return std::string(test_tmpdir) + std::string("/") + std::string(filename); | |
| } | |
| template <typename SetterType, typename DenseType, typename Scalar, int Options> | |
| bool test_random_setter(SparseMatrix<Scalar, Options>& sm, const DenseType& ref, | |
| const std::vector<Vector2i>& nonzeroCoords) { | |
| { | |
| sm.setZero(); | |
| SetterType w(sm); | |
| std::vector<Vector2i> remaining = nonzeroCoords; | |
| while (!remaining.empty()) { | |
| int i = internal::random<int>(0, static_cast<int>(remaining.size()) - 1); | |
| w(remaining[i].x(), remaining[i].y()) = ref.coeff(remaining[i].x(), remaining[i].y()); | |
| remaining[i] = remaining.back(); | |
| remaining.pop_back(); | |
| } | |
| } | |
| return sm.isApprox(ref); | |
| } | |
| template <typename SparseMatrixType> | |
| void sparse_extra(const SparseMatrixType& ref) { | |
| const Index rows = ref.rows(); | |
| const Index cols = ref.cols(); | |
| using Scalar = typename SparseMatrixType::Scalar; | |
| double density = (std::max)(8. / (rows * cols), 0.01); | |
| using DenseMatrix = Matrix<Scalar, Dynamic, Dynamic>; | |
| SparseMatrixType m(rows, cols); | |
| DenseMatrix refMat = DenseMatrix::Zero(rows, cols); | |
| std::vector<Vector2i> zeroCoords; | |
| std::vector<Vector2i> nonzeroCoords; | |
| initSparse<Scalar>(density, refMat, m, 0, &zeroCoords, &nonzeroCoords); | |
| if (zeroCoords.empty() || nonzeroCoords.empty()) return; | |
| // random setter | |
| // { | |
| // m.setZero(); | |
| // VERIFY_IS_NOT_APPROX(m, refMat); | |
| // SparseSetter<SparseMatrixType, RandomAccessPattern> w(m); | |
| // std::vector<Vector2i> remaining = nonzeroCoords; | |
| // while(!remaining.empty()) | |
| // { | |
| // int i = internal::random<int>(0,remaining.size()-1); | |
| // w->coeffRef(remaining[i].x(),remaining[i].y()) = refMat.coeff(remaining[i].x(),remaining[i].y()); | |
| // remaining[i] = remaining.back(); | |
| // remaining.pop_back(); | |
| // } | |
| // } | |
| // VERIFY_IS_APPROX(m, refMat); | |
| VERIFY((test_random_setter<RandomSetter<SparseMatrixType, StdMapTraits> >(m, refMat, nonzeroCoords))); | |
| VERIFY((test_random_setter<RandomSetter<SparseMatrixType, StdUnorderedMapTraits> >(m, refMat, nonzeroCoords))); | |
| #ifdef EIGEN_GOOGLEHASH_SUPPORT | |
| VERIFY((test_random_setter<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits> >(m, refMat, nonzeroCoords))); | |
| VERIFY((test_random_setter<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits> >(m, refMat, nonzeroCoords))); | |
| #endif | |
| // test RandomSetter | |
| /*{ | |
| SparseMatrixType m1(rows,cols), m2(rows,cols); | |
| DenseMatrix refM1 = DenseMatrix::Zero(rows, rows); | |
| initSparse<Scalar>(density, refM1, m1); | |
| { | |
| Eigen::RandomSetter<SparseMatrixType > setter(m2); | |
| for (int j=0; j<m1.outerSize(); ++j) | |
| for (typename SparseMatrixType::InnerIterator i(m1,j); i; ++i) | |
| setter(i.index(), j) = i.value(); | |
| } | |
| VERIFY_IS_APPROX(m1, m2); | |
| }*/ | |
| } | |
| // The setter imports the target's coefficients and writes the result back, so the target may be in either storage | |
| // mode, with or without coefficients, when the setter is constructed. | |
| template <typename SetterType, typename SparseMatrixType> | |
| void check_random_setter_target_modes() { | |
| using Scalar = typename SparseMatrixType::Scalar; | |
| using DenseMatrix = Matrix<Scalar, Dynamic, Dynamic>; | |
| const Index n = 70; | |
| for (int prefill = 0; prefill < 2; ++prefill) { | |
| for (int uncompressed = 0; uncompressed < 2; ++uncompressed) { | |
| SparseMatrixType m(n, n); | |
| DenseMatrix ref = DenseMatrix::Zero(n, n); | |
| if (prefill) { | |
| for (Index i = 0; i < n; i += 3) { | |
| m.insert(i, (i * 7) % n) = Scalar(1 + i); | |
| ref(i, (i * 7) % n) = Scalar(1 + i); | |
| } | |
| if (!uncompressed) m.makeCompressed(); | |
| } else if (uncompressed) { | |
| m.reserve(Matrix<int, Dynamic, 1>::Constant(n, 4)); | |
| } | |
| VERIFY_IS_EQUAL(m.isCompressed(), !uncompressed); | |
| { | |
| SetterType w(m); | |
| for (Index k = 0; k < 200; ++k) { | |
| const Index i = (k * 37) % n, j = (k * 11 + 5) % n; | |
| w(i, j) += Scalar(k + 1); | |
| ref(i, j) += Scalar(k + 1); | |
| } | |
| } | |
| VERIFY(m.isCompressed()); | |
| VERIFY(m.innerIndicesAreSorted()); | |
| VERIFY_IS_EQUAL(m.nonZeros(), (ref.array() != Scalar(0)).count()); | |
| VERIFY_IS_EQUAL(DenseMatrix(m), ref); | |
| } | |
| } | |
| } | |
| template <typename SparseMatrixType> | |
| void check_random_setter_target_modes() { | |
| check_random_setter_target_modes<RandomSetter<SparseMatrixType, StdMapTraits>, SparseMatrixType>(); | |
| check_random_setter_target_modes<RandomSetter<SparseMatrixType, StdUnorderedMapTraits>, SparseMatrixType>(); | |
| check_random_setter_target_modes<RandomSetter<SparseMatrixType>, SparseMatrixType>(); | |
| #ifdef EIGEN_GOOGLEHASH_SUPPORT | |
| check_random_setter_target_modes<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits>, SparseMatrixType>(); | |
| check_random_setter_target_modes<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits>, SparseMatrixType>(); | |
| #endif | |
| } | |
| template <typename SparseMatrixType> | |
| void check_marketio() { | |
| using DenseMatrix = Matrix<typename SparseMatrixType::Scalar, Dynamic, Dynamic>; | |
| Index rows = internal::random<Index>(1, 100); | |
| Index cols = internal::random<Index>(1, 100); | |
| SparseMatrixType m1, m2; | |
| m1 = DenseMatrix::Random(rows, cols).sparseView(); | |
| std::string filename = GetTestTempFilename("sparse_extra.mtx"); | |
| saveMarket(m1, filename); | |
| loadMarket(m2, filename); | |
| VERIFY_IS_EQUAL(DenseMatrix(m1), DenseMatrix(m2)); | |
| } | |
| template <typename VectorType> | |
| void check_marketio_vector() { | |
| Index size = internal::random<Index>(1, 100); | |
| VectorType v1, v2; | |
| v1 = VectorType::Random(size); | |
| std::string filename = GetTestTempFilename("vector_extra.mtx"); | |
| saveMarketVector(v1, filename); | |
| loadMarketVector(v2, filename); | |
| VERIFY_IS_EQUAL(v1, v2); | |
| } | |
| template <typename DenseMatrixType> | |
| void check_marketio_dense() { | |
| Index rows = DenseMatrixType::MaxRowsAtCompileTime; | |
| if (DenseMatrixType::MaxRowsAtCompileTime == Dynamic) { | |
| rows = internal::random<Index>(1, 100); | |
| } else if (DenseMatrixType::RowsAtCompileTime == Dynamic) { | |
| rows = internal::random<Index>(1, DenseMatrixType::MaxRowsAtCompileTime); | |
| } | |
| Index cols = DenseMatrixType::MaxColsAtCompileTime; | |
| if (DenseMatrixType::MaxColsAtCompileTime == Dynamic) { | |
| cols = internal::random<Index>(1, 100); | |
| } else if (DenseMatrixType::ColsAtCompileTime == Dynamic) { | |
| cols = internal::random<Index>(1, DenseMatrixType::MaxColsAtCompileTime); | |
| } | |
| DenseMatrixType m1, m2; | |
| m1 = DenseMatrixType::Random(rows, cols); | |
| std::string filename = GetTestTempFilename("dense_extra.mtx"); | |
| saveMarketDense(m1, filename); | |
| loadMarketDense(m2, filename); | |
| VERIFY_IS_EQUAL(m1, m2); | |
| } | |
| // The dimensions come from the file. A destination that cannot be resized has to reject the ones it does not have | |
| // already, without storing anything. | |
| void check_marketio_dense_views() { | |
| std::string filename = GetTestTempFilename("dense_extra_views.mtx"); | |
| VectorXd storage = VectorXd::Zero(4); | |
| Map<VectorXd> map(storage.data(), 4); | |
| Ref<VectorXd> ref(storage); | |
| Map<MatrixXd> square(storage.data(), 2, 2); | |
| MatrixXd columns = MatrixXd::Zero(4, 2); | |
| Block<MatrixXd, Dynamic, 1, true> column(columns, 0); | |
| Transpose<Map<MatrixXd>> transposed_square(square); | |
| VectorXd too_long = VectorXd::Constant(8, 7.0); | |
| saveMarketDense(too_long, filename); | |
| VERIFY(!loadMarketDense(map, filename)); | |
| VERIFY(!loadMarketDense(ref, filename)); | |
| VERIFY(!loadMarketDense(column, filename)); | |
| VERIFY(!loadMarketVector(map, filename)); | |
| // The right number of coefficients in another shape. | |
| RowVectorXd wrong_shape = RowVectorXd::Constant(4, 7.0); | |
| saveMarketDense(wrong_shape, filename); | |
| VERIFY(!loadMarketDense(map, filename)); | |
| VERIFY(!loadMarketDense(square, filename)); | |
| VERIFY(!loadMarketDense(transposed_square, filename)); | |
| VERIFY(storage.isZero(0.0)); | |
| VERIFY(columns.isZero(0.0)); | |
| VectorXd v = VectorXd::LinSpaced(4, 1.0, 4.0); | |
| saveMarketDense(v, filename); | |
| VERIFY(loadMarketDense(map, filename)); | |
| VERIFY_IS_EQUAL(storage, v); | |
| storage.setZero(); | |
| VERIFY(loadMarketDense(ref, filename)); | |
| VERIFY_IS_EQUAL(storage, v); | |
| VERIFY(loadMarketDense(column, filename)); | |
| VERIFY_IS_EQUAL(columns.col(0), v); | |
| VERIFY(columns.col(1).isZero(0.0)); | |
| // These forward resize() to the matrix they wrap. | |
| MatrixXd m; | |
| Transpose<MatrixXd> transposed(m); | |
| ArrayWrapper<MatrixXd> array(m); | |
| MatrixXd expected = MatrixXd::Constant(3, 2, 7.0); | |
| saveMarketDense(expected, filename); | |
| VERIFY(loadMarketDense(transposed, filename)); | |
| VERIFY_IS_EQUAL(m, expected.transpose()); | |
| VERIFY(loadMarketDense(array, filename)); | |
| VERIFY_IS_EQUAL(m, expected); | |
| } | |
| // A size line that the file does not back with coefficients is a parsing error, whatever it would take to allocate. | |
| void check_marketio_dense_malformed() { | |
| std::string filename = GetTestTempFilename("dense_extra_malformed.mtx"); | |
| { | |
| std::ofstream out(filename.c_str()); | |
| out << "%%MatrixMarket matrix array real general\n2 1\n4\nnot-a-number\n"; | |
| } | |
| const VectorXd untouched = VectorXd::Constant(3, 7.0); | |
| VectorXd v = untouched; | |
| VERIFY(!loadMarketDense(v, filename)); | |
| VERIFY_IS_EQUAL(v, untouched); | |
| { | |
| std::ofstream out(filename.c_str()); | |
| out << "%%MatrixMarket matrix array complex general\n2 1\n4 1\n3 x\n"; | |
| } | |
| const VectorXcd untouched_complex = VectorXcd::Constant(3, std::complex<double>(7.0, 1.0)); | |
| VectorXcd c = untouched_complex; | |
| VERIFY(!loadMarketDense(c, filename)); | |
| VERIFY_IS_EQUAL(c, untouched_complex); | |
| } | |
| void check_marketio_dense_truncated() { | |
| std::string filename = GetTestTempFilename("dense_extra_truncated.mtx"); | |
| const MatrixXd untouched = MatrixXd::Constant(2, 2, 7.0); | |
| // The product of the third pair does not fit a 64-bit Index. | |
| for (const char* sizes : {"30000000 30000000", "900000000000000 1", "2305843009213693953 8", "3 3"}) { | |
| std::ofstream out(filename.c_str()); | |
| out << "%%MatrixMarket matrix array real general\n" << sizes << "\n1.0\n"; | |
| out.close(); | |
| MatrixXd m = untouched; | |
| VERIFY(!loadMarketDense(m, filename)); | |
| VERIFY_IS_EQUAL(m, untouched); | |
| } | |
| } | |
| #ifndef _WIN32 | |
| // The rhs and the reference solution of MatrixMarketIterator come from files of their own, which declare their own | |
| // sizes: rhs().size() == matrix().rows() and refX().size() is matrix().cols() or 0, whatever these files say. | |
| void check_marketiterator_vector_sizes() { | |
| const std::string folder = GetTestTempFilename("sparse_extra_iterator"); | |
| mkdir(folder.c_str(), 0700); | |
| const std::string rhs_file = folder + "/system_b.mtx"; | |
| const std::string refx_file = folder + "/system_x.mtx"; | |
| const Index rows = 4, cols = 3; | |
| SparseMatrix<double> mat = MatrixXd::Random(rows, cols).sparseView(); | |
| VERIFY(saveMarket(mat, folder + "/system.mtx")); | |
| for (Index size = 2; size <= 5; ++size) { | |
| VectorXd vec = VectorXd::Random(size); | |
| VERIFY(saveMarketDense(vec, rhs_file)); | |
| VERIFY(saveMarketDense(vec, refx_file)); | |
| // Neither iterator has loaded its matrix when it is asked for a vector. | |
| MatrixMarketIterator<double> rhs_first(folder); | |
| VERIFY(bool(rhs_first)); | |
| VERIFY_IS_EQUAL(rhs_first.rhs().size(), rows); | |
| if (size == rows) VERIFY_IS_EQUAL(rhs_first.rhs(), vec); | |
| VERIFY_IS_EQUAL(rhs_first.matrix().rows(), rows); | |
| MatrixMarketIterator<double> refx_first(folder); | |
| VERIFY(bool(refx_first)); | |
| VERIFY_IS_EQUAL(refx_first.refX().size(), size == cols ? cols : Index(0)); | |
| VERIFY_IS_EQUAL(refx_first.hasrefX(), size == cols); | |
| if (size == cols) VERIFY_IS_EQUAL(refx_first.refX(), vec); | |
| VERIFY_IS_EQUAL(refx_first.matrix().cols(), cols); | |
| } | |
| // Files that declare the right size and end before their last entry. | |
| const char* header = "%%MatrixMarket matrix array real general\n"; | |
| { | |
| std::ofstream rhs_out(rhs_file.c_str()), refx_out(refx_file.c_str()); | |
| rhs_out << header << rows << " 1\n1\n"; | |
| refx_out << header << cols << " 1\n1\n"; | |
| } | |
| MatrixMarketIterator<double> truncated(folder); | |
| VERIFY(bool(truncated)); | |
| VERIFY_IS_EQUAL(truncated.refX().size(), Index(0)); | |
| VERIFY(!truncated.hasrefX()); | |
| // The rhs is generated together with the solution it belongs to. | |
| VERIFY_IS_EQUAL(truncated.rhs().size(), rows); | |
| VERIFY_IS_EQUAL(truncated.refX().size(), cols); | |
| VERIFY_IS_APPROX(truncated.rhs(), mat * truncated.refX()); | |
| } | |
| #endif | |
| template <typename Scalar> | |
| void check_sparse_inverse() { | |
| using MatrixType = SparseMatrix<Scalar>; | |
| using RowMatrixType = SparseMatrix<Scalar, RowMajor>; | |
| Matrix<Scalar, -1, -1> A; | |
| A.resize(1000, 1000); | |
| A.fill(0); | |
| A.setIdentity(); | |
| A.col(0).array() += 1; | |
| A.row(0).array() += 2; | |
| A.col(2).array() += 3; | |
| A.row(7).array() += 3; | |
| A.col(9).array() += 3; | |
| A.block(3, 4, 4, 2).array() += 9; | |
| A.middleRows(10, 50).array() += 3; | |
| A.middleCols(50, 50).array() += 40; | |
| A.block(500, 300, 40, 20).array() += 10; | |
| A.transposeInPlace(); | |
| Eigen::SparseLU<MatrixType> slu; | |
| slu.compute(A.sparseView()); | |
| Matrix<Scalar, -1, -1> Id(A.rows(), A.cols()); | |
| Id.setIdentity(); | |
| Matrix<Scalar, -1, -1> inv = slu.solve(Id); | |
| const MatrixType sparseInv = Eigen::SparseInverse<Scalar>().compute(A.sparseView()).inverse(); | |
| // The two inverses are computed independently (SparseLU solve against the identity vs the Takahashi | |
| // recurrence), so entrywise and summed deviations scale with n * eps for this 1000x1000 matrix. The input is | |
| // deterministic, but the deviation still moves by a factor of three with the accumulation order that the compiler, | |
| // the ISA and the buffer alignment happen to produce, so these factors are the smallest powers of two at or above | |
| // the long-standing 1e-11 and 1e-10 bounds rather than a tight fit to a single host. | |
| Scalar sumdiff = 0; // Check the diff only of the non-zero elements | |
| for (Eigen::Index j = 0; j < A.cols(); j++) { | |
| for (typename MatrixType::InnerIterator iter(sparseInv, j); iter; ++iter) { | |
| const Scalar diff = std::abs(inv(iter.row(), iter.col()) - iter.value()); | |
| VERIFY_IS_APPROX_OR_LESS_THAN(diff, Scalar(65536) * NumTraits<Scalar>::epsilon()); | |
| if (iter.value() != 0) { | |
| sumdiff += diff; | |
| } | |
| } | |
| } | |
| VERIFY_IS_APPROX_OR_LESS_THAN(sumdiff, Scalar(524288) * NumTraits<Scalar>::epsilon()); | |
| RowMatrixType DU = slu.matrixU().toSparse(); | |
| Matrix<Scalar, Dynamic, 1> invD = DU.diagonal().cwiseInverse(); | |
| RowMatrixType scaled_before_view = (invD.asDiagonal() * DU).template triangularView<StrictlyUpper>(); | |
| RowMatrixType view_before_scaled = invD.asDiagonal() * DU.template triangularView<StrictlyUpper>(); | |
| VERIFY_IS_APPROX(scaled_before_view, view_before_scaled); | |
| } | |
| // The Takahashi recurrence uses bilinear (unconjugated) sums, so this needs entries with nonzero imaginary parts to | |
| // tell a conjugated dot product from the right one. | |
| template <typename Scalar> | |
| void check_sparse_inverse_random_entries() { | |
| using RealScalar = typename NumTraits<Scalar>::Real; | |
| using MatrixType = SparseMatrix<Scalar>; | |
| const Index n = 40; | |
| std::vector<Triplet<Scalar> > triplets; | |
| for (Index i = 0; i < n; ++i) { | |
| triplets.emplace_back(i, i, Scalar(RealScalar(8)) + internal::random<Scalar>()); | |
| for (int k = 0; k < 4; ++k) { | |
| const Index j = internal::random<Index>(0, n - 1); | |
| if (j != i) triplets.emplace_back(i, j, internal::random<Scalar>()); | |
| } | |
| if (i + 1 < n) triplets.emplace_back(i, i + 1, internal::random<Scalar>()); | |
| } | |
| MatrixType A(n, n); | |
| A.setFromTriplets(triplets.begin(), triplets.end()); | |
| const MatrixType sparseInv = SparseInverse<Scalar>().compute(A).inverse(); | |
| const Matrix<Scalar, Dynamic, Dynamic> inv = Matrix<Scalar, Dynamic, Dynamic>(A).inverse(); | |
| VERIFY_IS_EQUAL(sparseInv.rows(), n); | |
| VERIFY(sparseInv.nonZeros() >= A.nonZeros()); | |
| const RealScalar tolerance = | |
| RealScalar(64) * RealScalar(n) * NumTraits<Scalar>::epsilon() * inv.cwiseAbs().maxCoeff(); | |
| for (Index j = 0; j < sparseInv.outerSize(); ++j) { | |
| for (typename MatrixType::InnerIterator it(sparseInv, j); it; ++it) { | |
| VERIFY(numext::abs(it.value() - inv(it.row(), it.col())) <= tolerance); | |
| } | |
| } | |
| } | |
| // ARPACK is not linked into the tests. These stand-ins for its double precision entry points write the last element | |
| // of resid(n), v(ldv, ncv), workd(3 * n) and workl(lworkl), the arrays that dsaupd_ documents, and report an error. | |
| // dsaupd_ is not inlined, so that the compiler cannot drop these writes together with the allocations. | |
| static int arpack_calls = 0; | |
| extern "C" EIGEN_DONT_INLINE void dsaupd_(int* ido, char*, int* n, char*, int*, double*, double* resid, int* ncv, | |
| double* v, int* ldv, int*, int*, double* workd, double* workl, int* lworkl, | |
| int* info) { | |
| ++arpack_calls; | |
| resid[*n - 1] = 0; | |
| v[std::size_t(*ldv) * std::size_t(*ncv) - 1] = 0; | |
| workd[3 * std::size_t(*n) - 1] = 0; | |
| workl[*lworkl - 1] = 0; | |
| *ido = 99; | |
| *info = -9999; | |
| } | |
| extern "C" void dseupd_(int*, char*, int*, double*, double*, int*, double*, char*, int*, char*, int*, double*, double*, | |
| int*, double*, int*, int*, int*, double*, double*, int*, int*) {} | |
| template <typename SparseMatrixType> | |
| void check_arpack_workspaces() { | |
| ArpackGeneralizedSelfAdjointEigenSolver<SparseMatrixType> eigs; | |
| arpack_calls = 0; | |
| eigs.compute(SparseMatrixType(50, 50), 5, "LM", EigenvaluesOnly); | |
| VERIFY_IS_EQUAL(arpack_calls, 1); | |
| // ARPACK's int arguments cannot express ncv = 2 * 30000, for which lworkl = ncv^2 + 8 ncv > INT_MAX, or nev >= n. | |
| arpack_calls = 0; | |
| eigs.compute(SparseMatrixType(100000, 100000), 30000, "LM", EigenvaluesOnly); | |
| VERIFY_IS_EQUAL(arpack_calls, 0); | |
| eigs.compute(SparseMatrixType(50, 50), 50, "LM", EigenvaluesOnly); | |
| VERIFY_IS_EQUAL(arpack_calls, 0); | |
| // v has n * ncv coefficients, counted in Index. The boundary is checked on the size calculation, which does not | |
| // allocate. | |
| const Index max_index = NumTraits<Index>::highest(); | |
| VERIFY(internal::arpack_workspace_fits(max_index / 2000, 2000)); | |
| VERIFY(!internal::arpack_workspace_fits(max_index / 2000 + 1, 2000)); | |
| VERIFY(internal::arpack_workspace_fits(1000, 20)); | |
| VERIFY(!internal::arpack_workspace_fits(1000, 60000)); | |
| // With a 32-bit Index the guard is reached through compute(), before anything is allocated: 2147484 * 2000 | |
| // exceeds 2^31 - 1. With a 64-bit Index the same request would need 34 GB, so it is not made. | |
| if (sizeof(Index) == 4) { | |
| arpack_calls = 0; | |
| eigs.compute(SparseMatrixType(2147484, 2147484), 1000, "LM", EigenvaluesOnly); | |
| VERIFY_IS_EQUAL(arpack_calls, 0); | |
| } | |
| } | |
| EIGEN_DECLARE_TEST(sparse_extra) { | |
| for (int i = 0; i < g_repeat; i++) { | |
| int s = Eigen::internal::random<int>(1, 50); | |
| CALL_SUBTEST_1(sparse_extra(SparseMatrix<double>(8, 8))); | |
| CALL_SUBTEST_2(sparse_extra(SparseMatrix<std::complex<double> >(s, s))); | |
| CALL_SUBTEST_1(sparse_extra(SparseMatrix<double>(s, s))); | |
| CALL_SUBTEST_3((check_marketio<SparseMatrix<float, ColMajor, int> >())); | |
| CALL_SUBTEST_3((check_marketio<SparseMatrix<double, ColMajor, int> >())); | |
| CALL_SUBTEST_3((check_marketio<SparseMatrix<std::complex<float>, ColMajor, int> >())); | |
| CALL_SUBTEST_3((check_marketio<SparseMatrix<std::complex<double>, ColMajor, int> >())); | |
| CALL_SUBTEST_3((check_marketio<SparseMatrix<float, ColMajor, long int> >())); | |
| CALL_SUBTEST_3((check_marketio<SparseMatrix<double, ColMajor, long int> >())); | |
| CALL_SUBTEST_3((check_marketio<SparseMatrix<std::complex<float>, ColMajor, long int> >())); | |
| CALL_SUBTEST_3((check_marketio<SparseMatrix<std::complex<double>, ColMajor, long int> >())); | |
| CALL_SUBTEST_4((check_marketio_dense<Matrix<float, Dynamic, Dynamic> >())); | |
| CALL_SUBTEST_4((check_marketio_dense<Matrix<float, Dynamic, Dynamic, RowMajor> >())); | |
| CALL_SUBTEST_4((check_marketio_dense<Matrix<double, Dynamic, Dynamic> >())); | |
| CALL_SUBTEST_4((check_marketio_dense<Matrix<std::complex<float>, Dynamic, Dynamic> >())); | |
| CALL_SUBTEST_4((check_marketio_dense<Matrix<std::complex<double>, Dynamic, Dynamic> >())); | |
| CALL_SUBTEST_4((check_marketio_dense<Matrix<float, Dynamic, 3> >())); | |
| CALL_SUBTEST_4((check_marketio_dense<Matrix<double, 3, Dynamic> >())); | |
| CALL_SUBTEST_4((check_marketio_dense<Matrix<double, 3, 4> >())); | |
| CALL_SUBTEST_4((check_marketio_dense<Matrix<double, Dynamic, Dynamic, ColMajor, 5, 5> >())); | |
| CALL_SUBTEST_4(check_marketio_dense_views()); | |
| CALL_SUBTEST_5((check_marketio_vector<Matrix<float, 1, Dynamic> >())); | |
| CALL_SUBTEST_5((check_marketio_vector<Matrix<double, 1, Dynamic> >())); | |
| CALL_SUBTEST_5((check_marketio_vector<Matrix<std::complex<float>, 1, Dynamic> >())); | |
| CALL_SUBTEST_5((check_marketio_vector<Matrix<std::complex<double>, 1, Dynamic> >())); | |
| CALL_SUBTEST_5((check_marketio_vector<Matrix<float, Dynamic, 1> >())); | |
| CALL_SUBTEST_5((check_marketio_vector<Matrix<double, Dynamic, 1> >())); | |
| CALL_SUBTEST_5((check_marketio_vector<Matrix<std::complex<float>, Dynamic, 1> >())); | |
| CALL_SUBTEST_5((check_marketio_vector<Matrix<std::complex<double>, Dynamic, 1> >())); | |
| CALL_SUBTEST_6((check_sparse_inverse<double>())); | |
| CALL_SUBTEST_6((check_sparse_inverse_random_entries<double>())); | |
| CALL_SUBTEST_6((check_sparse_inverse_random_entries<std::complex<double> >())); | |
| CALL_SUBTEST_6((check_sparse_inverse_random_entries<std::complex<float> >())); | |
| CALL_SUBTEST_7((check_random_setter_target_modes<SparseMatrix<double, ColMajor, int> >())); | |
| CALL_SUBTEST_7((check_random_setter_target_modes<SparseMatrix<double, RowMajor, int> >())); | |
| CALL_SUBTEST_7((check_random_setter_target_modes<SparseMatrix<std::complex<float>, ColMajor, long int> >())); | |
| CALL_SUBTEST_7((check_random_setter_target_modes<SparseMatrix<float, RowMajor, long int> >())); | |
| CALL_SUBTEST_7((check_arpack_workspaces<SparseMatrix<double>>())); | |
| TEST_SET_BUT_UNUSED_VARIABLE(s); | |
| } | |
| CALL_SUBTEST_4(check_marketio_dense_truncated()); | |
| CALL_SUBTEST_4(check_marketio_dense_malformed()); | |
| #ifndef _WIN32 | |
| CALL_SUBTEST_4(check_marketiterator_vector_sizes()); | |
| #endif | |
| } |