Boost logo

Ublas :

Subject: Re: [ublas] vector/matrix_assign do not work for integral types (bug?)
From: Nasos Iliopoulos (nasos_i_at_[hidden])
Date: 2010-08-16 11:15:59


Marco,
indeed it seems that uBlas was designed without integral types in mind and I think that some things can be tweaked to correct for this. Tweaking the inequality should not affect anything important, as it only compares with the epsilon.

There is only one thing to consider, that in this case uBlas will be comparing an integral type with a floating type, introducing an inconsistency. I don't know if it is better to use mpl::is_integral to get rid of this inconsistency (and hence complicate the code), or go with the solution you propose. The way I see it though the <= will not create any trouble so I vote going for it atm and just make a note for future reference.

Best
Nasos

> Date: Mon, 16 Aug 2010 09:54:38 +0200
> From: marco.guazzone_at_[hidden]
> To: ublas_at_[hidden]
> Subject: [ublas] vector/matrix_assign do not work for integral types (bug?)
>
> Dear all,
>
> I found a possible problem in vector_assign / matrix_assign when
> values have integral type.
> For instance, try to run the following program:
>
> --- [sample] ---
> #include <boost/numeric/ublas/io.hpp>
> #include <boost/numeric/ublas/vector.hpp>
> #include <cstddef>
> #include <iostream>
>
> namespace ublas = boost::numeric::ublas;
>
> int main()
> {
> typedef int value_type;
>
> std::size_t n(5);
>
> ublas::vector<value_type> v1;
> ublas::zero_vector<value_type> v2(n);
>
> v1 = v2;
>
> std::cerr << "NEW V1: " << v1 << std::endl;
> }
> --- [/sample] ---
>
> You will end up with a failed assertion:
> --- [error] ---
> Check failed in file
> /home/marco/tmp/boost-trunk/boost/numeric/ublas/detail/vector_assign.hpp
> at line 370:
> detail::expression_type_check (v, cv)
> terminate called after throwing an instance of
> 'boost::numeric::ublas::external_logic'
> what(): external logic or bad condition of inputs
> Aborted (core dumped)
> --- [/error] ---
>
> I have identified two possible issues:
> 1) In detail/vector_assign.hpp and detail/matrix_assign.hpp, the check
> in function detail::equals should replace "<" with "<=".
>
> 2) In detail/config.hpp, macro BOOST_UBLAS_TYPE_CHECK_MIN should get
> zero for integral types.
>
> Unless someone has a different opinion, I will try to create a patch
> and open a new trac ticket.
>
> Thank you very much!
>
> Best,
>
> -- Marco
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: nasos_i_at_[hidden]