Hi Guys,
After a significantly long break from using uBLAS, I have now been
lucky enough to find myself in a new role where I can again use it!
Having noted that there was no vector cross product in uBLAS, I
thought I would implement my own. To make it really efficient and work
in with the other uBLAS features, I thought I would try to make a
compatible routine that eliminates temporaries and uses the other cool
uBLAS features. So far so good.
To start, I decided to use a simple case that I could easily check: a
3d vector. I also decided to copy some other routines as required to
get going. For this reason I copied "scalar_plus".
Now that I have written the short piece code, it doesn't quite get
there. So far not so good. ;-)
I am hoping that a reader please review the short code and output
below and give some quick pointers about what I can do better...?
Perhaps I need to get some better knowledge about the relevant tricks
-- I was hoping to emulate another developer in the first instance.
Thanks,
Matt
--- Code Follows ---
namespace boost {
namespace numeric {
namespace ublas {
// Binary returning vector
template
struct vector_vector_binary_functor {
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef typename promote_traits::promote_type promote_type;
typedef promote_type value_type;
typedef vector result_type;
};
template
struct vector_vector_prod:
public vector_vector_binary_functor {
typedef typename vector_vector_binary_functor::size_type size_type;
typedef typename vector_vector_binary_functor::difference_type difference_type;
typedef typename vector_vector_binary_functor::value_type value_type;
typedef typename vector_vector_binary_functor::result_type result_type;
template
BOOST_UBLAS_INLINE
result_type operator () (const vector_expression<E1> &e1,
const vector_expression<E2> &e2) const {
// why use t() and e1() ?
result_type t(3);
t () (0) = e1 () (1) * e2 () (2) - e2 () (1) * e1 () (2);
t () (1) = - e1 () (0) * e2 () (2) + e2 () (0) * e1 () (2);
t () (2) = e1 () (0) * e2 () (1) - e2 () (0) * e1 () (1);
return t;
}
};
template
BOOST_UBLAS_INLINE
typename vector_binary_traits >::result_type
vect_prod(const vector_expression<E1> &e1,
const vector_expression<E2> &e2) {
typedef typename vector_binary_traits >::expression_type expression_type;
return expression_type(e1 (), e2 ());
}
}
}
}
--- Error Follows ---
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/functional.hpp:
In
member function `void boost::numeric::ublas::scalar_assign::operator()(boost::numeric::ublas::scalar_binary_assign_functor::argument1_type,
boost::numeric::ublas::scalar_binary_assign_functor::argument2_type) const [with T1 = double, T2 =
boost::numeric::ublas::vector]':
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector_assign.hpp:252:
instantiated from `void
boost::numeric::ublas::indexing_vector_assign(const F&, V&, const
boost::numeric::ublas::vector_expression<E>&) [with F =
boost::numeric::ublas::scalar_assign >, V =
boost::numeric::ublas::vector >, E =
boost::numeric::ublas::vector,
boost::numeric::ublas::unbounded_array > >]'
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector_assign.hpp:266:
instantiated from `void boost::numeric::ublas::vector_assign(const
F&, V&, const boost::numeric::ublas::vector_expression<E>&,
boost::numeric::ublas::dense_proxy_tag) [with F =
boost::numeric::ublas::scalar_assign >, V =
boost::numeric::ublas::vector >, E =
boost::numeric::ublas::vector,
boost::numeric::ublas::unbounded_array > >]'
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector_assign.hpp:423:
instantiated from `void boost::numeric::ublas::vector_assign(const
F&, V&, const boost::numeric::ublas::vector_expression<E>&) [with F =
boost::numeric::ublas::scalar_assign >, V =
boost::numeric::ublas::vector >, E =
boost::numeric::ublas::vector,
boost::numeric::ublas::unbounded_array > >]'
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector.hpp:77:
instantiated from `boost::numeric::ublas::vector::vector(const
boost::numeric::ublas::vector_expression<E>&) [with AE =
boost::numeric::ublas::vector,
boost::numeric::ublas::unbounded_array > >, T = double, A =
boost::numeric::ublas::bounded_array]'
src/GLWireVisitor/GLWireVisitor.cpp:121: instantiated from here
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/functional.hpp:182:
cannot
convert `const boost::numeric::ublas::vector' to `double' in
assignment
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector_expression.hpp:
In
member function `F::result_type
boost::numeric::ublas::vector_binary::operator()(boost::numeric::ublas::promote_traits::promote_type) const [with E1 =
boost::numeric::ublas::vector >, E2 =
boost::numeric::ublas::vector >, F =
boost::numeric::ublas::vector_vector_prod]':
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector_assign.hpp:252:
instantiated from `void
boost::numeric::ublas::indexing_vector_assign(const F&, V&, const
boost::numeric::ublas::vector_expression<E>&) [with F =
boost::numeric::ublas::scalar_assign,
boost::numeric::ublas::vector >, V =
boost::numeric::ublas::vector,
boost::numeric::ublas::unbounded_array > >, E =
boost::numeric::ublas::vector_binary >,
boost::numeric::ublas::vector >,
boost::numeric::ublas::vector_vector_prod >]'
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector_assign.hpp:266:
instantiated from `void boost::numeric::ublas::vector_assign(const
F&, V&, const boost::numeric::ublas::vector_expression<E>&,
boost::numeric::ublas::dense_proxy_tag) [with F =
boost::numeric::ublas::scalar_assign,
boost::numeric::ublas::vector >, V =
boost::numeric::ublas::vector,
boost::numeric::ublas::unbounded_array
, E =
boost::numeric::ublas::vector_binary >,
boost::numeric::ublas::vector >,
boost::numeric::ublas::vector_vector_prod >]'
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector_assign.hpp:423:
instantiated from `void boost::numeric::ublas::vector_assign(const
F&, V&, const boost::numeric::ublas::vector_expression<E>&) [with F =
boost::numeric::ublas::scalar_assign,
boost::numeric::ublas::vector >, V =
boost::numeric::ublas::vector,
boost::numeric::ublas::unbounded_array > >, E =
boost::numeric::ublas::vector_binary >,
boost::numeric::ublas::vector >,
boost::numeric::ublas::vector_vector_prod >]'
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector.hpp:77:
instantiated from `boost::numeric::ublas::vector::vector(const
boost::numeric::ublas::vector_expression<E>&) [with AE =
boost::numeric::ublas::vector_binary >, boost::numeric::ublas::vector >,
boost::numeric::ublas::vector_vector_prod >, T =
boost::numeric::ublas::vector, A =
boost::numeric::ublas::unbounded_array >]'
src/GLWireVisitor/GLWireVisitor.cpp:70: instantiated from
`boost::numeric::ublas::vector_binary_traits >::result_type boost::numeric::ublas::vect_prod(const
boost::numeric::ublas::vector_expression<E>&, const
boost::numeric::ublas::vector_expression<E2>&) [with E1 =
boost::numeric::ublas::vector >, E2 =
boost::numeric::ublas::vector >]'
src/GLWireVisitor/GLWireVisitor.cpp:121: instantiated from here
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector_expression.hpp:775:
no
match for call to `(boost::numeric::ublas::vector_vector_prod) (double, double)'
make: *** [obj/GLWireVisitor/GLWireVisitor.o] Error 1