Opened 7 years ago
Closed 7 years ago
#4410 closed Patches (worksforme)
Sparse/Packed matrix assignment needs type conversion
Reported by: | Owned by: | David Bellot | |
---|---|---|---|
Milestone: | To Be Determined | Component: | uBLAS |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | Cc: |
Description
In file boost/detail/matrix_assign.hpp there are two possible source of type-conversion error interesting both sparse and packed matrices.
Let:
typedef typename M::value_type value_type; typedef F<typename M::..., typename E::value_type> functor_type;
Then:
- Comparison of an
E::value_type
with anM::value_type
if (v != value_type/*zero*/()) // where v is of type E::value_type
E.g.,
E::value_type
isstd::complex<float>
andM::value_type
isstd::complex<double>
.
- Assignment of an
M::value_type
to anE::value_type
E.g.,functor_type::apply(*it, value_type/*zero*/());
E::value_type
isfloat
andM::value_type
isstd::complex<float>
.
Attachments (3)
Change History (8)
Changed 7 years ago by
Attachment: | matrix_assign_problem.cpp added |
---|
comment:1 Changed 7 years ago by
I propose a possible patch (see attachment: matrix_assign-packed_sparse_storage-type_conversion.patch).
Essentially,
- Expressions of the first type might be changed by casting an
E::value_type
to aM::value_type
, like in this way:if (static_cast<value_type>(v) != value_type/*zero*/())
Obviously, this does not work when E::value_type
and M::value_type
are not castable (e.g., std::complex
and double
, respectively).
- Expressions of the second type might be changed in 2 ways:
- Option A (the one used in the proposed patch)
typedef typename matrix_traits<E>::value_type expr_value_type; functor_type::apply(*it, expr_value_type/*zero*/()); // NOTE: use of E::value_type in place of M::value_type
- Option B
typedef F<typename M::..., value_type> functor_type; // NOTE: use M::value_type instead of E::value_type functor_type::apply(*it, value_type/*zero*/()); // unchanged
Changed 7 years ago by
Attachment: | matrix_assign-packed_sparse_storage-type_conversion.patch added |
---|
Possible solution.
comment:3 Changed 7 years ago by
Owner: | changed from Gunter to David Bellot |
---|---|
Status: | new → assigned |
comment:4 Changed 7 years ago by
applied patch from Marco Guazzone. Should be OK, however it raises a concern about a possible security hole with static_cast<>, only when people are crazy enough to use ublas as a data storage having nothing to do with linear algebra (like I did once ;-) )
comment:5 Changed 7 years ago by
Resolution: | → worksforme |
---|---|
Status: | assigned → closed |
Changed 7 years ago by
Attachment: | test_ticket4410.cpp added |
---|
Test case: test copy-construction/-assignement of a sparse (symmetric) matrix. The test fails to compile if the patch is not applied.
A sample program for showing the problem (the program should not compile).