Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • jcarpent/eigenpy
  • gsaurel/eigenpy
  • stack-of-tasks/eigenpy
3 results
Show changes
Showing
with 681 additions and 71 deletions
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/deprecation-policy.hpp"
#include <iostream>
namespace bp = boost::python;
using eigenpy::DeprecationType;
void some_deprecated_function() {
std::cout << "Calling this should produce a warning" << std::endl;
}
void some_future_deprecated_function() {
std::cout
<< "Calling this should produce a warning about a future deprecation"
<< std::endl;
}
class X {
public:
void deprecated_member_function() {}
};
BOOST_PYTHON_MODULE(deprecation_policy) {
bp::def("some_deprecated_function", some_deprecated_function,
eigenpy::deprecated_function<DeprecationType::DEPRECATION>());
bp::def("some_future_deprecated_function", some_future_deprecated_function,
eigenpy::deprecated_function<DeprecationType::FUTURE>());
bp::class_<X>("X", bp::init<>(bp::args("self")))
.def("deprecated_member_function", &X::deprecated_member_function,
eigenpy::deprecated_member<>());
}
/*
* Copyright 2014-2019, CNRS
* Copyright 2018-2022, INRIA
*/
#include <iostream>
#include "eigenpy/eigenpy.hpp"
#include "eigenpy/eigen-from-python.hpp"
using namespace Eigen;
using namespace eigenpy;
template <typename MatType>
void printMatrix(const Eigen::Ref<const MatType> mat) {
if (MatType::IsVectorAtCompileTime) std::cout << "isVector" << std::endl;
std::cout << "input size: cols " << mat.cols() << " rows " << mat.rows()
<< std::endl;
std::cout << mat << std::endl;
}
template <typename VecType>
void printVector(const Eigen::Ref<const VecType>& vec) {
EIGEN_STATIC_ASSERT_VECTOR_ONLY(VecType);
printMatrix(vec);
}
template <typename MatType>
void setOnes(Eigen::Ref<MatType> mat) {
mat.setOnes();
}
template <typename VecType>
VecType copyVectorFromConstRef(const Eigen::Ref<const VecType> vec) {
std::cout << "copyVectorFromConstRef::vec: " << vec.transpose() << std::endl;
return VecType(vec);
}
template <typename MatType>
Eigen::Ref<MatType> getBlock(Eigen::Ref<MatType> mat, Eigen::DenseIndex i,
Eigen::DenseIndex j, Eigen::DenseIndex n,
Eigen::DenseIndex m) {
return mat.block(i, j, n, m);
}
template <typename MatType>
Eigen::Ref<MatType> editBlock(Eigen::Ref<MatType> mat, Eigen::DenseIndex i,
Eigen::DenseIndex j, Eigen::DenseIndex n,
Eigen::DenseIndex m) {
typename Eigen::Ref<MatType>::BlockXpr B = mat.block(i, j, n, m);
int k = 0;
for (int i = 0; i < B.rows(); ++i) {
for (int j = 0; j < B.cols(); ++j) {
B(i, j) = k++;
}
}
std::cout << "B:\n" << B << std::endl;
return mat;
}
template <typename MatType>
void fill(Eigen::Ref<MatType> mat, const typename MatType::Scalar& value) {
mat.fill(value);
}
/// Get ref to a static matrix of size ( @p rows, @p cols )
template <typename MatType>
Eigen::Ref<MatType> getRefToStatic(const int rows, const int cols) {
static MatType mat(rows, cols);
std::cout << "create ref to matrix of size (" << rows << "," << cols << ")\n";
return mat;
}
template <typename MatType>
Eigen::Ref<MatType> asRef(Eigen::Ref<MatType> mat) {
std::cout << "create Ref to input mutable Ref\n";
return Eigen::Ref<MatType>(mat);
}
template <typename MatType>
const Eigen::Ref<const MatType> asConstRef(Eigen::Ref<const MatType> mat) {
return Eigen::Ref<const MatType>(mat);
}
struct modify_block {
MatrixXd J;
modify_block() : J(10, 10) { J.setZero(); }
void modify(int n, int m) { call(J.topLeftCorner(n, m)); }
virtual void call(Eigen::Ref<MatrixXd> mat) = 0;
};
struct modify_block_wrap : modify_block, bp::wrapper<modify_block> {
modify_block_wrap() : modify_block() {}
void call(Eigen::Ref<MatrixXd> mat) { this->get_override("call")(mat); }
};
struct has_ref_member {
MatrixXd J;
Eigen::Ref<MatrixXd> Jref;
has_ref_member() : J(4, 4), Jref(J.topRightCorner(3, 3)) { J.setZero(); }
};
BOOST_PYTHON_MODULE(eigen_ref) {
namespace bp = boost::python;
eigenpy::enableEigenPy();
bp::def("printMatrix", printMatrix<Vector3d>);
bp::def("printMatrix", printMatrix<VectorXd>);
bp::def("printMatrix", printMatrix<MatrixXd>);
bp::def("printVector", printVector<VectorXd>);
bp::def("printRowVector", printVector<RowVectorXd>);
bp::def("setOnes", setOnes<Vector3d>);
bp::def("setOnes", setOnes<VectorXd>);
bp::def("setOnes", setOnes<MatrixXd>);
bp::def("fillVec3", fill<Vector3d>);
bp::def("fillVec", fill<VectorXd>);
bp::def("fill", fill<MatrixXd>);
bp::def("getRefToStatic", getRefToStatic<MatrixXd>);
bp::def("asRef", asRef<MatrixXd>);
bp::def("asConstRef", asConstRef<MatrixXd>);
bp::def("getBlock", &getBlock<MatrixXd>);
bp::def("editBlock", &editBlock<MatrixXd>);
bp::def("copyVectorFromConstRef", &copyVectorFromConstRef<VectorXd>);
bp::def("copyRowVectorFromConstRef", &copyVectorFromConstRef<RowVectorXd>);
bp::class_<modify_block_wrap, boost::noncopyable>("modify_block",
bp::init<>())
.def_readonly("J", &modify_block::J)
.def("modify", &modify_block::modify)
.def("call", bp::pure_virtual(&modify_block_wrap::call));
bp::class_<has_ref_member, boost::noncopyable>("has_ref_member", bp::init<>())
.def_readonly("J", &has_ref_member::J)
.add_property(
"Jref",
bp::make_getter(&has_ref_member::Jref,
bp::return_value_policy<bp::return_by_value>()));
// can't return Eigen::Ref by reference but by value
// (def_readonly creates a by-reference getter)
}
/* /*
* Copyright 2014-2019, CNRS * Copyright 2014-2019, CNRS
* Copyright 2018-2019, INRIA * Copyright 2018-2023, INRIA
*/ */
#include "eigenpy/eigenpy.hpp" #include "eigenpy/eigenpy.hpp"
#include "eigenpy/geometry.hpp" #include "eigenpy/geometry.hpp"
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <iostream>
#include <boost/python.hpp>
namespace bp = boost::python; namespace bp = boost::python;
Eigen::AngleAxisd testOutAngleAxis() Eigen::AngleAxisd testOutAngleAxis() {
{ return Eigen::AngleAxisd(.1, Eigen::Vector3d::UnitZ());
return Eigen::AngleAxisd(.1,Eigen::Vector3d::UnitZ());
} }
double testInAngleAxis(Eigen::AngleAxisd aa) double testInAngleAxis(Eigen::AngleAxisd aa) { return aa.angle(); }
{
return aa.angle();
}
Eigen::Quaterniond testOutQuaternion() Eigen::Quaterniond testOutQuaternion() {
{ Eigen::Quaterniond res(1, 2, 3, 4);
Eigen::Quaterniond res(1,2,3,4);
return res; return res;
} }
double testInQuaternion( Eigen::Quaterniond q ) double testInQuaternion(Eigen::Quaterniond q) { return q.norm(); }
{
return q.norm();
}
BOOST_PYTHON_MODULE(geometry) BOOST_PYTHON_MODULE(geometry) {
{
eigenpy::enableEigenPy(); eigenpy::enableEigenPy();
eigenpy::exposeAngleAxis(); eigenpy::exposeAngleAxis();
eigenpy::exposeQuaternion(); eigenpy::exposeQuaternion();
bp::def("testOutAngleAxis",&testOutAngleAxis); bp::def("testOutAngleAxis", &testOutAngleAxis);
bp::def("testInAngleAxis",&testInAngleAxis); bp::def("testInAngleAxis", &testInAngleAxis);
bp::def("testOutQuaternion",&testOutQuaternion);
bp::def("testInQuaternion",&testInQuaternion);
bp::def("testOutQuaternion", &testOutQuaternion);
bp::def("testInQuaternion", &testInQuaternion);
} }
/*
* Copyright 2021, CNRS
*/
// Including this header should not raise a build error
#include "eigenpy/registration.hpp"
BOOST_PYTHON_MODULE(include) {}
/* /*
* Copyright 2014-2019, CNRS * Copyright 2014-2022 CNRS INRIA
* Copyright 2018-2019, INRIA
*/ */
#include "eigenpy/eigenpy.hpp"
#include <iostream> #include <iostream>
Eigen::VectorXd emptyVector() #include "eigenpy/eigenpy.hpp"
{
template <typename Scalar>
Eigen::Matrix<Scalar, Eigen::Dynamic, 1> vector1x1(const Scalar& value) {
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> ReturnType;
return ReturnType::Constant(1, value);
}
template <typename Scalar>
Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> matrix1x1(
const Scalar& value) {
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> ReturnType;
return ReturnType::Constant(1, 1, value);
}
template <typename Scalar>
void matrix1x1_input(const Eigen::Matrix<Scalar, 1, 1>& mat) {
std::cout << mat << std::endl;
}
Eigen::VectorXd emptyVector() {
Eigen::VectorXd vec; Eigen::VectorXd vec;
vec.resize(0); vec.resize(0);
return vec; return vec;
} }
Eigen::MatrixXd emptyMatrix() Eigen::MatrixXd emptyMatrix() { return Eigen::MatrixXd(0, 0); }
{
return Eigen::MatrixXd(0,0);
}
Eigen::MatrixXd naturals(int R,int C,bool verbose) Eigen::MatrixXd naturals(int R, int C, bool verbose) {
{ Eigen::MatrixXd mat(R, C);
Eigen::MatrixXd mat(R,C); for (int r = 0; r < R; ++r)
for(int r=0;r<R;++r) for (int c = 0; c < C; ++c) mat(r, c) = r * C + c;
for(int c=0;c<C;++c)
mat(r,c) = r*C+c;
if(verbose) if (verbose) std::cout << "EigenMat = " << mat << std::endl;
std::cout << "EigenMat = " << mat << std::endl;
return mat; return mat;
} }
Eigen::VectorXd naturals(int R,bool verbose) Eigen::VectorXd naturals(int R, bool verbose) {
{
Eigen::VectorXd mat(R); Eigen::VectorXd mat(R);
for(int r=0;r<R;++r) for (int r = 0; r < R; ++r) mat[r] = r;
mat[r] = r;
if(verbose) if (verbose) std::cout << "EigenMat = " << mat << std::endl;
std::cout << "EigenMat = " << mat << std::endl;
return mat; return mat;
} }
Eigen::Matrix3d naturals(bool verbose) Eigen::Matrix3d naturals(bool verbose) {
{
Eigen::Matrix3d mat; Eigen::Matrix3d mat;
for(int r=0;r<3;++r) for (int r = 0; r < 3; ++r)
for(int c=0;c<3;++c) for (int c = 0; c < 3; ++c) mat(r, c) = r * 3 + c;
mat(r,c) = r*3+c;
if(verbose) if (verbose) std::cout << "EigenMat = " << mat << std::endl;
std::cout << "EigenMat = " << mat << std::endl;
return mat; return mat;
} }
template<typename MatType> template <typename MatType>
Eigen::MatrixXd reflex(const MatType & M, bool verbose) Eigen::MatrixXd reflex(const MatType& M, bool verbose) {
{ if (verbose) std::cout << "EigenMat = " << M << std::endl;
if(verbose)
std::cout << "EigenMat = " << M << std::endl;
return Eigen::MatrixXd(M); return Eigen::MatrixXd(M);
} }
template<typename MatrixDerived> template <typename MatrixDerived>
MatrixDerived base(const Eigen::MatrixBase<MatrixDerived> & m) MatrixDerived base(const Eigen::MatrixBase<MatrixDerived>& m) {
{ return m.derived();
}
template <typename MatrixDerived>
MatrixDerived plain(const Eigen::PlainObjectBase<MatrixDerived>& m) {
return m.derived(); return m.derived();
} }
BOOST_PYTHON_MODULE(matrix) template <typename Scalar>
{ Eigen::Matrix<Scalar, 6, 6> matrix6(const Scalar& value) {
typedef Eigen::Matrix<Scalar, 6, 6> ReturnType;
return ReturnType::Constant(value);
}
template <typename Scalar>
Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
generateRowMajorMatrix(const Eigen::DenseIndex rows,
const Eigen::DenseIndex cols) {
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
RowMajorMatrix;
RowMajorMatrix A(rows, cols);
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
Eigen::Map<Vector>(A.data(), A.size()) =
Vector::LinSpaced(A.size(), 1, static_cast<Scalar>(A.size()));
std::cout << "Matrix values:\n" << A << std::endl;
return A;
}
template <typename Scalar>
Eigen::Matrix<Scalar, 1, Eigen::Dynamic, Eigen::RowMajor>
generateRowMajorVector(const Eigen::DenseIndex size) {
typedef Eigen::Matrix<Scalar, 1, Eigen::Dynamic, Eigen::RowMajor>
RowMajorVector;
RowMajorVector A(size);
A.setLinSpaced(size, 1, static_cast<Scalar>(size));
std::cout << "Vector values: " << A.transpose() << std::endl;
return A;
}
template <typename Scalar>
Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> generateColMajorMatrix(
const Eigen::DenseIndex rows, const Eigen::DenseIndex cols) {
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> ColMajorMatrix;
ColMajorMatrix A(rows, cols);
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector;
Eigen::Map<Vector>(A.data(), A.size()) =
Vector::LinSpaced(A.size(), 1, static_cast<Scalar>(A.size()));
std::cout << "Matrix values:\n" << A << std::endl;
return A;
}
template <typename Scalar>
Eigen::Matrix<Scalar, 1, Eigen::Dynamic> generateColMajorVector(
const Eigen::DenseIndex size) {
typedef Eigen::Matrix<Scalar, 1, Eigen::Dynamic> ColMajorVector;
ColMajorVector A(size);
A.setLinSpaced(size, 1, static_cast<Scalar>(size));
std::cout << "Vector values: " << A.transpose() << std::endl;
return A;
}
template <typename Matrix, typename ReturnMatrix>
ReturnMatrix copy(const Eigen::MatrixBase<Matrix>& mat) {
return mat;
}
template <typename Matrix>
Matrix copy_same(const Eigen::MatrixBase<Matrix>& mat) {
return mat;
}
BOOST_PYTHON_MODULE(matrix) {
using namespace Eigen; using namespace Eigen;
namespace bp = boost::python; namespace bp = boost::python;
eigenpy::enableEigenPy(); eigenpy::enableEigenPy();
Eigen::MatrixXd (*naturalsXX)(int,int,bool) = naturals; // Square matrix
Eigen::VectorXd (*naturalsX)(int,bool) = naturals; typedef Eigen::Matrix<double, 6, 6> Matrix6;
eigenpy::enableEigenPySpecific<Matrix6>();
// Non-square matrix
typedef Eigen::Matrix<double, 4, 6> Matrix46;
eigenpy::enableEigenPySpecific<Matrix46>();
Eigen::MatrixXd (*naturalsXX)(int, int, bool) = naturals;
Eigen::VectorXd (*naturalsX)(int, bool) = naturals;
Eigen::Matrix3d (*naturals33)(bool) = naturals; Eigen::Matrix3d (*naturals33)(bool) = naturals;
bp::def("vector1x1", vector1x1<double>);
bp::def("matrix1x1", matrix1x1<double>);
bp::def("matrix1x1", matrix1x1_input<double>);
bp::def("matrix1x1_int", matrix1x1_input<int>);
bp::def("naturals", naturalsXX); bp::def("naturals", naturalsXX);
bp::def("naturalsX", naturalsX); bp::def("naturalsX", naturalsX);
bp::def("naturals33", naturals33); bp::def("naturals33", naturals33);
...@@ -88,7 +170,64 @@ BOOST_PYTHON_MODULE(matrix) ...@@ -88,7 +170,64 @@ BOOST_PYTHON_MODULE(matrix)
bp::def("emptyVector", emptyVector); bp::def("emptyVector", emptyVector);
bp::def("emptyMatrix", emptyMatrix); bp::def("emptyMatrix", emptyMatrix);
bp::def("base", base<VectorXd>); bp::def("base", base<VectorXd>);
bp::def("base", base<MatrixXd>); bp::def("base", base<MatrixXd>);
bp::def("plain", plain<VectorXd>);
bp::def("plain", plain<MatrixXd>);
bp::def("matrix6", matrix6<double>);
bp::def("generateRowMajorMatrix", generateRowMajorMatrix<double>);
bp::def("generateRowMajorVector", generateRowMajorVector<double>);
bp::def("generateColMajorMatrix", generateColMajorMatrix<double>);
bp::def("generateColMajorVector", generateColMajorVector<double>);
typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
RowMajorMatrixXd;
bp::def("asRowMajorFromColMajorMatrix",
copy<Eigen::MatrixXd, RowMajorMatrixXd>);
bp::def("asRowMajorFromColMajorVector",
copy<Eigen::VectorXd, Eigen::RowVectorXd>);
bp::def("asRowMajorFromRowMajorMatrix",
copy<RowMajorMatrixXd, RowMajorMatrixXd>);
bp::def("asRowMajorFromRowMajorVector",
copy<Eigen::RowVectorXd, Eigen::RowVectorXd>);
bp::def("copyBoolToBool", copy_same<Eigen::Matrix<bool, -1, -1> >);
bp::def("copyInt8ToInt8", copy_same<Eigen::Matrix<int8_t, -1, -1> >);
bp::def("copyCharToChar", copy_same<Eigen::Matrix<char, -1, -1> >);
bp::def("copyUCharToUChar", copy_same<Eigen::Matrix<unsigned char, -1, -1> >);
bp::def("copyInt16ToInt16", copy_same<Eigen::Matrix<int16_t, -1, -1> >);
bp::def("copyUInt16ToUInt16", copy_same<Eigen::Matrix<uint16_t, -1, -1> >);
bp::def("copyInt32ToInt32", copy_same<Eigen::Matrix<int32_t, -1, -1> >);
bp::def("copyUInt32ToUInt32", copy_same<Eigen::Matrix<uint32_t, -1, -1> >);
bp::def("copyInt64ToInt64", copy_same<Eigen::Matrix<int64_t, -1, -1> >);
bp::def("copyUInt64ToUInt64", copy_same<Eigen::Matrix<uint64_t, -1, -1> >);
bp::def("copyLongToLong", copy_same<Eigen::Matrix<long, -1, -1> >);
bp::def("copyULongToULong", copy_same<Eigen::Matrix<unsigned long, -1, -1> >);
bp::def("copyLongLongToLongLong",
copy_same<Eigen::Matrix<long long, -1, -1> >);
bp::def("copyULongLongToULongLong",
copy_same<Eigen::Matrix<unsigned long long, -1, -1> >);
bp::def("copyFloatToFloat", copy_same<Eigen::Matrix<float, -1, -1> >);
bp::def("copyDoubleToDouble", copy_same<Eigen::Matrix<double, -1, -1> >);
bp::def("copyLongDoubleToLongDouble",
copy_same<Eigen::Matrix<long double, -1, -1> >);
bp::def("copyCFloatToCFloat",
copy_same<Eigen::Matrix<std::complex<float>, -1, -1> >);
bp::def("copyCDoubleToCDouble",
copy_same<Eigen::Matrix<std::complex<double>, -1, -1> >);
bp::def("copyCLongDoubleToCLongDouble",
copy_same<Eigen::Matrix<std::complex<long double>, -1, -1> >);
} }
#include "eigenpy/registration.hpp"
#include <cstdio>
namespace bp = boost::python;
class X {
public:
X() {}
void operator()() { printf("DOOT\n"); }
};
class X_wrapper : public X, bp::wrapper<X> {
public:
static void expose() {
if (!eigenpy::register_symbolic_link_to_registered_type<X>()) {
bp::class_<X>("X", bp::init<>()).def("__call__", &X::operator());
}
}
};
BOOST_PYTHON_MODULE(multiple_registration) {
X_wrapper::expose();
X_wrapper::expose();
X_wrapper::expose();
X_wrapper::expose();
X_wrapper::expose();
X_wrapper::expose();
}
cmake_minimum_required(VERSION 2.6)
project(ExtraLib CXX)
find_package(eigenpy REQUIRED)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
include_directories(SYSTEM ${EIGENPY_INCLUDE_DIRS})
add_executable(extra_lib extra_lib.cpp)
target_link_libraries(extra_lib PUBLIC ${eigenpy_LIBRARIES} ${PYTHON_LIBRARIES})
#include <eigenpy/version.hpp>
int main(int /*argc*/, char** /*argv*/) {
eigenpy::checkVersionAtLeast(0, 0, 0);
return 0;
}
cmake_minimum_required(VERSION 2.6)
project(ExtraLib CXX)
find_package(eigenpy REQUIRED)
add_executable(extra_lib extra_lib.cpp)
target_link_libraries(extra_lib PUBLIC eigenpy::eigenpy)
#include <eigenpy/version.hpp>
int main(int /*argc*/, char** /*argv*/) {
eigenpy::checkVersionAtLeast(0, 0, 0);
return 0;
}
cmake_minimum_required(VERSION 2.6)
project(ExtraLib CXX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(EIGENPY REQUIRED eigenpy)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
include_directories(SYSTEM ${EIGENPY_INCLUDE_DIRS})
add_executable(extra_lib extra_lib.cpp)
target_link_libraries(extra_lib PUBLIC ${EIGENPY_LDFLAGS} ${PYTHON_LIBRARIES})
#include <eigenpy/version.hpp>
int main(int /*argc*/, char** /*argv*/) {
eigenpy::checkVersionAtLeast(0, 0, 0);
return 0;
}
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
llt = eigenpy.CholmodSimplicialLDLT(A)
assert llt.info() == eigenpy.ComputationInfo.Success
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)
llt.analyzePattern(A)
llt.factorize(A)
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
llt = eigenpy.CholmodSimplicialLLT(A)
assert llt.info() == eigenpy.ComputationInfo.Success
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)
llt.analyzePattern(A)
llt.factorize(A)
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
llt = eigenpy.CholmodSupernodalLLT(A)
assert llt.info() == eigenpy.ComputationInfo.Success
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)
llt.analyzePattern(A)
llt.factorize(A)
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
rng = np.random.default_rng()
def test(SolverType: type):
dim = 100
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
llt = SolverType(A)
assert llt.info() == eigenpy.ComputationInfo.Success
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
# import pdb; pdb.set_trace()
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)
llt.analyzePattern(A)
llt.factorize(A)
test(eigenpy.AccelerateLLT)
test(eigenpy.AccelerateLDLT)
test(eigenpy.AccelerateLDLTUnpivoted)
test(eigenpy.AccelerateLDLTSBK)
test(eigenpy.AccelerateLDLTTPP)
test(eigenpy.AccelerateQR)
# test(eigenpy.AccelerateCholeskyAtA) # This test is not passing. Seems there is a bug in Eigen with the support of Accelerate.
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
ldlt = eigenpy.SimplicialLDLT(A)
assert ldlt.info() == eigenpy.ComputationInfo.Success
L = ldlt.matrixL()
U = ldlt.matrixU()
D = csc_matrix(np.diag(ldlt.vectorD()))
LDU = L @ D @ U
assert eigenpy.is_approx(LDU.toarray(), A.toarray())
X = rng.random((dim, 20))
B = A.dot(X)
X_est = ldlt.solve(B)
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)
ldlt.analyzePattern(A)
ldlt.factorize(A)
permutation = ldlt.permutationP()
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
llt = eigenpy.SimplicialLLT(A)
assert llt.info() == eigenpy.ComputationInfo.Success
L = llt.matrixL()
U = llt.matrixU()
LU = L @ U
assert eigenpy.is_approx(LU.toarray(), A.toarray())
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)
llt.analyzePattern(A)
llt.factorize(A)
permutation = llt.permutationP()
import numpy as np
import eigenpy
dim = 100
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
ldlt = eigenpy.LDLT(A)
L = ldlt.matrixL()
D = ldlt.vectorD()
P = ldlt.transpositionsP()
assert eigenpy.is_approx(
np.transpose(P).dot(L.dot(np.diag(D).dot(np.transpose(L).dot(P)))), A
)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = ldlt.solve(B)
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)
import numpy as np
import eigenpy
dim = 100
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
llt = eigenpy.LLT(A)
L = llt.matrixL()
assert eigenpy.is_approx(L.dot(np.transpose(L)), A)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
assert eigenpy.is_approx(A.dot(X_est), B)