<div dir="ltr"><div><span style="font-size:12.8px">Nasos,</span></div><div><br></div><span style="font-size:12.8px">> In line 850 I see:</span><br style="font-size:12.8px"><span style="font-size:12.8px">> index( ) - it.index()</span><br><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">The error is referring the branch </span><a href="https://github.com/jdurancomas/ublas/tree/warning_promoted_types" style="font-size:12.8px" target="_blank">https://github.com/jdurancomas/ublas/tree/warning_promoted_types</a><span style="font-size:12.8px">.</span><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">> The change you propose may have far reaching consequences. It would be preferable to find another way around it, but I am afraid we may need to mess with the type definitions of the iterators.</span><br style="font-size:12.8px"></div><div><span style="font-size:12.8px"><br></span></div>Yes, there is another option. As the definitions of value_type in E1, E2 could be different of value_type definitions in vector_binary so the local variables that stores values of E1 or E2 should be defined as E1::value_type or E2:value_type. Review the commit <a href="https://github.com/jdurancomas/ublas/commit/bc211a890595790c421055cc47d5c3be160183f7">https://github.com/jdurancomas/ublas/commit/bc211a890595790c421055cc47d5c3be160183f7</a>.<div><br>> Can you please check, that promote_type<char, char>::promote_type is an int (as well as the unsigned char, short, unsigned short), after applying this change?<br><br></div><div>No, the change was introduced to force that when two operands of the same type was promoted then the promoted type was the same as the original one. That is:</div><div><br></div><div>promote_type<char, char>::promote_type is char</div><div>promote_type<short, short>::promote_type is short</div><div>..... </div><div><br></div><div>Thanks and Best Regards,<br>Joaquim Duran<div><span style="font-size:12.8px"><br></span></div><div class="gmail_extra"><br><div class="gmail_quote">2016-01-04 16:09 GMT+01:00 Nasos Iliopoulos <span dir="ltr"><<a href="mailto:nasos_i@hotmail.com" target="_blank">nasos_i@hotmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <div text="#000000" bgcolor="#FFFFFF"> Joaquim,<br> <br> In line 850 I see:<br> index( ) - it.index()<br> <br> Based on the line numbers of the warning text, I cannot trace how the difference operator is called or how the promote_type is called in the vector_expression.hpp in ublas/develop for the particular case. <br> <br> The change you propose may have far reaching consequences. It would be preferable to find another way around it, but I am afraid we may need to mess with the type definitions of the iterators.<br> <br> Can you please check, that promote_type<char, char>::promote_type is an int (as well as the unsigned char, short, unsigned short), after applying this change?<br> <br> <br> In any case I think there is an issue with the promote_traits that are trying to deal with both cases of numerical essence (like as elements of a matrix) and size_types. <br> In the numerical sense the promote_traits should be able to deal with:<br> 1. Subtracting two unsigned integral types should return the proper result (i.e. a signed value)<br> 2. The promoted type should be able to hold the full range of the unpromotted types<br> <br> No. 2 cannot be satisfied in general (for example for the case of unsigned ints, unless an 128-bit is used as the promotion type). This is reflected by the choice that the unsigned int promotions is also an unsigned int instead of just an int.<br> <br> -Nasos<div><div><br> <br> <br> <div>On 01/03/2016 08:43 PM, Joaquim Duran Comas wrote:<br> </div> </div></div><blockquote type="cite"><div><div> <div dir="ltr"> <div>Hello,</div> <div><br> </div> <div>I'm trying to fix a warning that it is shown when the test test_matrix_vector is compiled with mscv with all warnings enabled. The text of the warning is the following:</div> <div><br> </div> <div><b><warning text></b></div> <div>c:\Users\qduran\Documents\development\modular-boost\boost/numeric/ublas/vector_expression.hpp(850) : warning C4244: 'argument' : conversion from 'int' to 'const char', possible loss of data</div> <div> c:\Users\qduran\Documents\development\modular-boost\boost/numeric/ublas/vector_expression.hpp(813) : while compiling class template member function 'int boost::numeric::ublas::vector_binary<E1,E2,F>::const_iterator::dereference(boost::numeric::ublas::sparse_bidirectional_iterator_tag) const'</div> <div> with</div> <div> [</div> <div> E1=boost::numeric::ublas::matrix_column<boost::numeric::ublas::mapped_matrix<char,boost::numeric::ublas::row_major,boost::numeric::ublas::map_std<size_t,char,std::allocator<std::pair<const size_t,char>>>>></div> <div>, E2=boost::numeric::ublas::vector<value_type,boost::numeric::ublas::unbounded_array<value_type,std::allocator<char>>></div> <div>, F=boost::numeric::ublas::scalar_minus<char,value_type></div> <div> ]</div> <div> c:\Users\qduran\Documents\development\modular-boost\boost/numeric/ublas/vector_expression.hpp(884) : see reference to function template instantiation 'int boost::numeric::ublas::vector_binary<E1,E2,F>::const_iterator::dereference(boost::numeric::ublas::sparse_bidirectional_iterator_tag) const' being compiled</div> <div> with</div> <div> [</div> <div> E1=boost::numeric::ublas::matrix_column<boost::numeric::ublas::mapped_matrix<char,boost::numeric::ublas::row_major,boost::numeric::ublas::map_std<size_t,char,std::allocator<std::pair<const size_t,char>>>>></div> <div>, E2=boost::numeric::ublas::vector<value_type,boost::numeric::ublas::unbounded_array<value_type,std::allocator<char>>></div> <div>, F=boost::numeric::ublas::scalar_minus<char,value_type></div> <div> ]</div> <div> c:\Users\qduran\Documents\development\modular-boost\boost/numeric/ublas/vector_expression.hpp(1538) : see reference to class template instantiation 'boost::numeric::ublas::vector_binary<E1,E2,F>::const_iterator' being compiled</div> <div> with</div> <div> [</div> <div> E1=boost::numeric::ublas::matrix_column<boost::numeric::ublas::mapped_matrix<char,boost::numeric::ublas::row_major,boost::numeric::ublas::map_std<size_t,char,std::allocator<std::pair<const size_t,char>>>>></div> <div>, E2=boost::numeric::ublas::vector<value_type,boost::numeric::ublas::unbounded_array<value_type,std::allocator<char>>></div> <div>, F=boost::numeric::ublas::scalar_minus<char,value_type></div> <div> ]</div> <div> c:\Users\qduran\Documents\development\modular-boost\boost/numeric/ublas/vector_expression.hpp(1647) : see reference to class template instantiation 'boost::numeric::ublas::vector_scalar_unary<E,F>' being compiled</div> <div> with</div> <div> [</div> <div> E=boost::numeric::ublas::vector_binary<boost::numeric::ublas::matrix_column<boost::numeric::ublas::mapped_matrix<char,boost::numeric::ublas::row_major,boost::numeric::ublas::map_std<size_t,char,std::allocator<std::pair<const size_t,char>>>>>,boost::numeric::ublas::vector<value_type,boost::numeric::ublas::unbounded_array<value_type,std::allocator<char>>>,boost::numeric::ublas::scalar_minus<char,value_type>></div> <div>, F=boost::numeric::ublas::vector_norm_inf<boost::numeric::ublas::vector_binary<boost::numeric::ublas::matrix_column<boost::numeric::ublas::mapped_matrix<char,boost::numeric::ublas::row_major,boost::numeric::ublas::map_std<size_t,char,std::allocator<std::pair<const size_t,char>>>>>,boost::numeric::ublas::vector<value_type,boost::numeric::ublas::unbounded_array<value_type,std::allocator<char>>>,boost::numeric::ublas::scalar_minus<char,value_type>>></div> <div> ]</div> <div> c:\Users\qduran\Documents\development\modular-boost\boost/numeric/ublas/detail/vector_assign.hpp(33) : see reference to function template instantiation 'int boost::numeric::ublas::norm_inf<boost::numeric::ublas::vector_binary<E1,E2,F>>(const boost::numeric::ublas::vector_expression<boost::numeric::ublas::vector_binary<E1,E2,F>> &)' being compiled</div> <div> with</div> <div> [</div> <div> E1=boost::numeric::ublas::matrix_column<boost::numeric::ublas::mapped_matrix<char,boost::numeric::ublas::row_major,boost::numeric::ublas::map_std<size_t,char,std::allocator<std::pair<const size_t,char>>>>></div> <div>, E2=boost::numeric::ublas::vector<value_type,boost::numeric::ublas::unbounded_array<value_type,std::allocator<char>>></div> <div>, F=boost::numeric::ublas::scalar_minus<char,value_type></div> <div> ]</div> <div> c:\Users\qduran\Documents\development\modular-boost\boost/numeric/ublas/detail/vector_assign.hpp(42) : see reference to function template instantiation 'bool boost::numeric::ublas::detail::equals<boost::numeric::ublas::matrix_column<Matrix>,C,int>(const boost::numeric::ublas::vector_expression<boost::numeric::ublas::matrix_column<Matrix>> &,const boost::numeric::ublas::vector_expression<C> &,S,S)' being compiled</div> <div> with</div> <div> [</div> <div> Matrix=boost::numeric::ublas::mapped_matrix<char,boost::numeric::ublas::row_major,boost::numeric::ublas::map_std<size_t,char,std::allocator<std::pair<const size_t,char>>>></div> <div>, C=boost::numeric::ublas::vector<value_type,boost::numeric::ublas::unbounded_array<value_type,std::allocator<char>>></div> <div>, S=int</div> <div> ]</div> <div> c:\Users\qduran\Documents\development\modular-boost\boost/numeric/ublas/detail/vector_assign.hpp(436) : see reference to function template instantiation 'bool boost::numeric::ublas::detail::expression_type_check<boost::numeric::ublas::matrix_column<Matrix>,C>(const boost::numeric::ublas::vector_expression<boost::numeric::ublas::matrix_column<Matrix>> &,const boost::numeric::ublas::vector_expression<C> &)' being compiled</div> <div> with</div> <div> [</div> <div> Matrix=boost::numeric::ublas::mapped_matrix<char,boost::numeric::ublas::row_major,boost::numeric::ublas::map_std<size_t,char,std::allocator<std::pair<const size_t,char>>>></div> <div>, C=boost::numeric::ublas::vector<value_type,boost::numeric::ublas::unbounded_array<value_type,std::allocator<char>>></div> <div> ]</div> <div><b></warning text></b></div> <div><br> </div> <div>The warning is detected in the function 'boost::numeric::ublas::vector_binary<E1,E2,F>::const_iterator::dereference', when the binary function is called (line of code: return static_cast<value_type>(functor_type::apply (t1, t2));). The binary function requires two parameters of type char, however two parameters of type integer are provided to he function. The parameters provided to the binary function (named t1 and t2, of type integer) are declared with the type vector_binary::const_iterator::value_type.</div> <div>This type is defined from vector_binary::value_type, and this type is defined from F::result_type, where F is the template parameter of the class vector_binary that specifies the functor implementing the binary function. The functor scalar_minus defines the result_type as 'typedef typename promote_traits<T1, T2>::promote_type result_type;', where T1 and T2 are template parameters that specifies the types of the parameters of the binary function.</div> <div><br> </div> <div>The problem is located at promote_type struct, in which the promoted type of two chars, two unsigned chars, two shorts or two unsigned shorts is an integer and not the same type of the template parameters. Following, there are the debug traces of promote_traits (located at file vector_expression.hpp):</div> <div><br> </div> <div>promote_traits<char, char>::promote_type: int</div> <div>promote_traits<unsigned char, unsigned char>::promote_type: int</div> <div>promote_traits<short, short>::promote_type: int</div> <div>promote_traits<unsigned short, unsigned short>::promote_type: int</div> <div>promote_traits<int, int>::promote_type: int</div> <div>promote_traits<unsigned int, unsigned int>::promote_type: unsigned int</div> <div>promote_traits<float, float>::promote_type: float</div> <div>promote_traits<double, double>::promote_type: double</div> <div><br> </div> <div>I could fix the warning by adding the following template specialization of promote_traits in the file traits.hpp:</div> <div><br> </div> <div>template<class X></div> <div>struct promote_traits<X, X> {</div> <div> typedef typename X promote_type;</div> <div>};</div> <div><br> </div> <div>I would like to know if the template specialization is the right way to fix the problem of the promote_type struct should be revised.</div> <div><br> </div> <div>To test it, I've created a reduced version of file test_matrix_vector.cpp.</div> <div><br> </div> <div>All these changes could be downloaded from the branch <a href="https://github.com/jdurancomas/ublas/tree/warning_promoted_types" target="_blank"></a><a href="https://github.com/jdurancomas/ublas/tree/warning_promoted_types" target="_blank">https://github.com/jdurancomas/ublas/tree/warning_promoted_types</a>.</div> <div><br> </div> <div>Thanks and Best Regards,</div> <div>Joaquim Duran</div> <div><br> </div> </div> <div> <table style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(170,171,182);margin-top:10px"> <tbody> <tr> <td style="width:105px;padding-top:15px"> <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank"><img src="https://ipmcdn.avast.com/images/logo-avast-v1.png" style="width: 90px; min-height: 33px;"></a> </td> <td style="width:470px;padding-top:20px;color:rgb(65,66,78);font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Este correo electrónico se ha enviado desde un equipo libre de virus y protegido por Avast. <br> <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" style="color:rgb(68,83,234)" target="_blank">www.avast.com</a> </td> </tr> </tbody> </table> </div> <br> <fieldset></fieldset> <br> </div></div><pre>_______________________________________________ ublas mailing list <a href="mailto:ublas@lists.boost.org" target="_blank">ublas@lists.boost.org</a> <a href="http://lists.boost.org/mailman/listinfo.cgi/ublas" target="_blank">http://lists.boost.org/mailman/listinfo.cgi/ublas</a> Sent to: <a href="mailto:athanasios.iliopoulos.ctr.gr@nrl.navy.mil" target="_blank">athanasios.iliopoulos.ctr.gr@nrl.navy.mil</a></pre> </blockquote> <br> </div> <br>_______________________________________________<br> ublas mailing list<br> <a href="mailto:ublas@lists.boost.org" target="_blank">ublas@lists.boost.org</a><br> <a href="http://lists.boost.org/mailman/listinfo.cgi/ublas" rel="noreferrer" target="_blank">http://lists.boost.org/mailman/listinfo.cgi/ublas</a><br> Sent to: <a href="mailto:jdurancomas@gmail.com" target="_blank">jdurancomas@gmail.com</a><br></blockquote></div><br></div></div><div><table style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(170,171,182);margin-top:10px"> <tbody><tr> <td style="width:105px;padding-top:15px"> <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank"><img src="https://ipmcdn.avast.com/images/logo-avast-v1.png" style="width: 90px; min-height: 33px;"></a> </td> <td style="width:470px;padding-top:20px;color:rgb(65,66,78);font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Este correo electrónico se ha enviado desde un equipo libre de virus y protegido por Avast. <br><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" style="color:rgb(68,83,234)" target="_blank">www.avast.com</a> </td> </tr> </tbody></table> <a href="#1520f0a4bca92457_DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"></a></div></div>