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<class T1, class T2>
struct vector_vector_binary_functor {
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef typename promote_traits<T1, T2>::promote_type promote_type;
typedef promote_type value_type;
typedef vector<promote_type> result_type;
};
template<class T1, class T2>
struct vector_vector_prod:
public vector_vector_binary_functor<T1, T2> {
typedef typename vector_vector_binary_functor<T1,
T2>::size_type size_type;
typedef typename vector_vector_binary_functor<T1,
T2>::difference_type difference_type;
typedef typename vector_vector_binary_functor<T1,
T2>::value_type value_type;
typedef typename vector_vector_binary_functor<T1,
T2>::result_type result_type;
template<class E1, class E2>
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<class E1, class E2>
BOOST_UBLAS_INLINE
typename vector_binary_traits<E1, E2,
vector_vector_prod<typename E1::value_type,
typename E2::value_type> >::result_type
vect_prod(const vector_expression<E1> &e1,
const vector_expression<E2> &e2) {
typedef typename vector_binary_traits<E1, E2,
vector_vector_prod<typename E1::value_type,
typename E2::value_type> >::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<T1,
T2>::operator()(boost::numeric::ublas::scalar_binary_assign_functor<T1,
T2>::argument1_type,
boost::numeric::ublas::scalar_binary_assign_functor<T1,
T2>::argument2_type) const [with T1 = double, T2 =
boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> >]':
/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<double,
boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > >, V =
boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >, E =
boost::numeric::ublas::vector<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::unbounded_array<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > > >]'
/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<double,
boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > >, V =
boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >, E =
boost::numeric::ublas::vector<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::unbounded_array<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > > >]'
/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<double,
boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > >, V =
boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >, E =
boost::numeric::ublas::vector<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::unbounded_array<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > > >]'
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector.hpp:77:
instantiated from `boost::numeric::ublas::vector<T, A>::vector(const
boost::numeric::ublas::vector_expression<E>&) [with AE =
boost::numeric::ublas::vector<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::unbounded_array<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > > >, T = double, A =
boost::numeric::ublas::bounded_array<double, 3>]'
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<double,
boost::numeric::ublas::unbounded_array<double> >' 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<E1, E2,
F>::operator()(boost::numeric::ublas::promote_traits<E1::size_type,
E2::size_type>::promote_type) const [with E1 =
boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >, E2 =
boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >, F =
boost::numeric::ublas::vector_vector_prod<double, double>]':
/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<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > >, V =
boost::numeric::ublas::vector<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::unbounded_array<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > > >, E =
boost::numeric::ublas::vector_binary<boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >,
boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >,
boost::numeric::ublas::vector_vector_prod<double, double> >]'
/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<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > >, V =
boost::numeric::ublas::vector<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::unbounded_array<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double>
> > >, E =
boost::numeric::ublas::vector_binary<boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >,
boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >,
boost::numeric::ublas::vector_vector_prod<double, double> >]'
/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<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > >, V =
boost::numeric::ublas::vector<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> >,
boost::numeric::ublas::unbounded_array<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > > >, E =
boost::numeric::ublas::vector_binary<boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >,
boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >,
boost::numeric::ublas::vector_vector_prod<double, double> >]'
/home/matt/code/c++/pkg/boost_1_30_0/boost/numeric/ublas/vector.hpp:77:
instantiated from `boost::numeric::ublas::vector<T, A>::vector(const
boost::numeric::ublas::vector_expression<E>&) [with AE =
boost::numeric::ublas::vector_binary<boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double,
3> >, boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >,
boost::numeric::ublas::vector_vector_prod<double, double> >, T =
boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> >, A =
boost::numeric::ublas::unbounded_array<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double> > >]'
src/GLWireVisitor/GLWireVisitor.cpp:70: instantiated from
`boost::numeric::ublas::vector_binary_traits<E1, E2,
boost::numeric::ublas::vector_vector_prod<E1::value_type,
E2::value_type> >::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<double,
boost::numeric::ublas::bounded_array<double, 3> >, E2 =
boost::numeric::ublas::vector<double,
boost::numeric::ublas::bounded_array<double, 3> >]'
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>) (double, double)'
make: *** [obj/GLWireVisitor/GLWireVisitor.o] Error 1