mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-22 22:33:15 +08:00
Properly adjust precision when saving to Market format.
This commit is contained in:
parent
e2f4ee1c2b
commit
e8d6862f14
@ -231,12 +231,13 @@ template<typename SparseMatrixType>
|
|||||||
bool saveMarket(const SparseMatrixType& mat, const std::string& filename, int sym = 0)
|
bool saveMarket(const SparseMatrixType& mat, const std::string& filename, int sym = 0)
|
||||||
{
|
{
|
||||||
typedef typename SparseMatrixType::Scalar Scalar;
|
typedef typename SparseMatrixType::Scalar Scalar;
|
||||||
|
typedef typename SparseMatrixType::RealScalar RealScalar;
|
||||||
std::ofstream out(filename.c_str(),std::ios::out);
|
std::ofstream out(filename.c_str(),std::ios::out);
|
||||||
if(!out)
|
if(!out)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
out.flags(std::ios_base::scientific);
|
out.flags(std::ios_base::scientific);
|
||||||
out.precision(64);
|
out.precision(std::numeric_limits<RealScalar>::digits10 + 2);
|
||||||
std::string header;
|
std::string header;
|
||||||
internal::putMarketHeader<Scalar>(header, sym);
|
internal::putMarketHeader<Scalar>(header, sym);
|
||||||
out << header << std::endl;
|
out << header << std::endl;
|
||||||
@ -247,7 +248,6 @@ bool saveMarket(const SparseMatrixType& mat, const std::string& filename, int sy
|
|||||||
{
|
{
|
||||||
++ count;
|
++ count;
|
||||||
internal::PutMatrixElt(it.value(), it.row()+1, it.col()+1, out);
|
internal::PutMatrixElt(it.value(), it.row()+1, it.col()+1, out);
|
||||||
// out << it.row()+1 << " " << it.col()+1 << " " << it.value() << "\n";
|
|
||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
return true;
|
return true;
|
||||||
@ -256,13 +256,14 @@ bool saveMarket(const SparseMatrixType& mat, const std::string& filename, int sy
|
|||||||
template<typename VectorType>
|
template<typename VectorType>
|
||||||
bool saveMarketVector (const VectorType& vec, const std::string& filename)
|
bool saveMarketVector (const VectorType& vec, const std::string& filename)
|
||||||
{
|
{
|
||||||
typedef typename VectorType::Scalar Scalar;
|
typedef typename VectorType::Scalar Scalar;
|
||||||
|
typedef typename VectorType::RealScalar RealScalar;
|
||||||
std::ofstream out(filename.c_str(),std::ios::out);
|
std::ofstream out(filename.c_str(),std::ios::out);
|
||||||
if(!out)
|
if(!out)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
out.flags(std::ios_base::scientific);
|
out.flags(std::ios_base::scientific);
|
||||||
out.precision(64);
|
out.precision(std::numeric_limits<RealScalar>::digits10 + 2);
|
||||||
if(internal::is_same<Scalar, std::complex<float> >::value || internal::is_same<Scalar, std::complex<double> >::value)
|
if(internal::is_same<Scalar, std::complex<float> >::value || internal::is_same<Scalar, std::complex<double> >::value)
|
||||||
out << "%%MatrixMarket matrix array complex general\n";
|
out << "%%MatrixMarket matrix array complex general\n";
|
||||||
else
|
else
|
||||||
|
@ -139,7 +139,7 @@ void check_marketio()
|
|||||||
m1 = DenseMatrix::Random(rows, cols).sparseView();
|
m1 = DenseMatrix::Random(rows, cols).sparseView();
|
||||||
saveMarket(m1, "sparse_extra.mtx");
|
saveMarket(m1, "sparse_extra.mtx");
|
||||||
loadMarket(m2, "sparse_extra.mtx");
|
loadMarket(m2, "sparse_extra.mtx");
|
||||||
VERIFY_IS_APPROX(m1,m2);
|
VERIFY_IS_EQUAL(DenseMatrix(m1),DenseMatrix(m2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_sparse_extra()
|
void test_sparse_extra()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user