Bugzilla – Attachment 604 Details for
Bug 1064
Question regarding Ref<SparseVector>
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
Test with Ref<SparseMatrix/SparseVector>
test.cc (text/x-c++src), 1.85 KB, created by
Benjamin Chretien
on 2015-09-15 03:03:37 UTC
(
hide
)
Description:
Test with Ref<SparseMatrix/SparseVector>
Filename:
MIME Type:
Creator:
Benjamin Chretien
Created:
2015-09-15 03:03:37 UTC
Size:
1.85 KB
patch
obsolete
>#define EIGEN_RUNTIME_NO_MALLOC > >#include <Eigen/Core> >#include <Eigen/Sparse> >#include <iostream> > >using namespace Eigen; >using namespace Eigen::internal; > >template <typename U> >void foo(const Ref<const U>& r) >{ > // Allocation may be required for printing > set_is_malloc_allowed(true); > std::cout << "const Ref print:\n" << r << std::endl; > set_is_malloc_allowed(false); >} > >template <typename U> >void bar(Ref<U> r) >{ > r *= 2.; > > // Allocation may be required for printing > set_is_malloc_allowed(true); > std::cout << "Ref print:\n" << r << std::endl; > set_is_malloc_allowed(false); >} > >int main(int argc, char *argv[]) >{ > // Dense vector > { > typedef VectorXd test_t; > > test_t v(3); > v.setZero(); > v[2] = 12.; > std::cout << "Direct print:\n" << v << std::endl; > > set_is_malloc_allowed(false); > foo<test_t>(v); > bar<test_t>(v); > set_is_malloc_allowed(true); > } > std::cout << std::endl; > > // Dense matrix > { > typedef MatrixXd test_t; > > test_t m(3,3); > m.setZero(); > m(1,1) = 33.; > std::cout << "Direct print:\n" << m << std::endl; > > set_is_malloc_allowed(false); > foo<test_t>(m); > bar<test_t>(m); > set_is_malloc_allowed(true); > } > std::cout << std::endl; > > // Sparse vector > { > typedef SparseVector<double> test_t; > > test_t v (5); > v.insert (3) = 42.; > std::cout << "Direct print:\n" << v << std::endl; > > set_is_malloc_allowed(false); > // TODO: report problem here > //foo<test_t>(v); > //bar<test_t>(v); > set_is_malloc_allowed(true); > } > std::cout << std::endl; > > > // Sparse matrix > { > typedef SparseMatrix<double> test_t; > > test_t m(3,3); > m.setZero(); > m.insert(1,1) = 33.; > m.makeCompressed (); > std::cout << "Direct print:\n" << m << std::endl; > > set_is_malloc_allowed(false); > foo<test_t>(m); > bar<test_t>(m); > set_is_malloc_allowed(true); > } > > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1064
: 604