Boost logo

Ublas :

From: Leopoldo Peralta (lperalta_at_[hidden])
Date: 2007-08-23 18:12:47


Additionally to complex types, should boost::rational numbers (which is a
boost type) be included?

Regards

Leopoldo Peralta

-----Mensaje original-----
De: ublas-bounces_at_[hidden] [mailto:ublas-bounces_at_[hidden]] En
nombre de Neal Becker
Enviado el: Thursday, August 23, 2007 1:35 PM
Para: ublas_at_[hidden]
Asunto: [ublas] [patch] improve type deduction

This patch does 2 things:
1) enable mixed int/complex arith
2) use boost typeof for return type deduction

diff -r 1be5d7eb10aa boost/numeric/ublas/traits.hpp
--- a/boost/numeric/ublas/traits.hpp Mon Aug 20 09:58:57 2007 -0400
+++ b/boost/numeric/ublas/traits.hpp Thu Aug 23 14:34:22 2007 -0400
@@ -27,8 +27,44 @@
 
 #include <boost/type_traits.hpp>
 #include <complex>
+#include <boost/typeof/typeof.hpp>
 
 namespace boost { namespace numeric { namespace ublas {
+
+typedef std::complex<double> complex_t;
+
+inline complex_t operator+ (int in1, complex_t in2) {
+ return double(in1) + in2;
+}
+
+inline complex_t operator+ (complex_t in1, int in2) {
+ return in1 + double(in2);
+}
+
+inline complex_t operator- (int in1, complex_t in2) {
+ return double(in1) - in2;
+}
+
+inline complex_t operator- (complex_t in1, int in2) {
+ return in1 - double(in2);
+}
+
+inline complex_t operator* (int in1, complex_t in2) {
+ return double(in1) * in2;
+}
+
+inline complex_t operator* (complex_t in1, int in2) {
+ return in1 * double(in2);
+}
+
+inline complex_t operator/ (int in1, complex_t in2) {
+ return double(in1) / in2;
+}
+
+inline complex_t operator/ (complex_t in1, int in2) {
+ return in1 / double(in2);
+}
+
 
     // Use Joel de Guzman's return type deduction
     // uBLAS assumes a common return type for all binary arithmetic
operators
@@ -37,17 +73,19 @@ namespace boost { namespace numeric { na
         typedef type_deduction_detail::base_result_of<X, Y> base_type;
         static typename base_type::x_type x;
         static typename base_type::y_type y;
- static const std::size_t size = sizeof (
- type_deduction_detail::test<
- typename base_type::x_type
- , typename base_type::y_type
- >(x + y) // Use x+y to stand of all the arithmetic
actions
- );
-
- static const std::size_t index = (size / sizeof (char)) - 1;
- typedef typename mpl::at_c<
- typename base_type::types, index>::type id;
- typedef typename id::type promote_type;
+// static const std::size_t size = sizeof (
+// type_deduction_detail::test<
+// typename base_type::x_type
+// , typename base_type::y_type
+// >(x + y) // Use x+y to stand of all the arithmetic
actions
+// );
+
+// static const std::size_t index = (size / sizeof (char)) - 1;
+// typedef typename mpl::at_c<
+// typename base_type::types, index>::type id;
+ // typedef typename id::type promote_type;
+ // typedef typeof (X() + Y()) promote_type;
+ typedef BOOST_TYPEOF (X() + Y()) promote_type;
     };
 

_______________________________________________
ublas mailing list
ublas_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/ublas