Boost logo

Ublas :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2007-04-13 11:45:24


It seems to me to be useful to make algorithms for matrixes that are
generic. This is generally possible for vectors. Using boost::range, we
can write generic algorithms which use the range free functions size(),
begin(), and end() to accept args that are more general than ublas::vector.

For matrix there is no equivalent. However, by writing free functions for
size1(), size2(), begin1(), begin2(), etc. at least some generic
functionality is possible.

I think this might be a useful area to pursue. Any thoughts? Here are some
examples:

template<typename T>
inline size_t size1 (stlsoft::fixed_array_2d<T> const& a) {
  return a.dimension0();
}

template<typename T>
inline size_t size1 (std::vector<std::vector<T> > const& a) {
  return a.size();
}

template<typename T>
inline size_t size1 (ublas::matrix<T> const& a) {
  return a.size1();
}

template<typename T>
inline size_t size2 (ublas::matrix<T> const& a) {
  return a.size2();
}

template<typename T>
inline size_t size2 (std::vector<std::vector<T> > const& a) {
  return a[0].size();
}

template<typename T>
inline std::vector<T>& row (std::vector<std::vector<T> >& v, size_t r) {
  return v[r];
}

template<typename T>
inline std::vector<T>const & row (std::vector<std::vector<T> > const& v,
size_t r) {
  return v[r];
}

template<typename T>
inline typename stlsoft::fixed_array_2d<T>::dimension_element_type row
(stlsoft::fixed_array_2d<T>& v, size_t r) {
  return v[r];
}

template<typename T>
inline typename stlsoft::fixed_array_2d<T>::dimension_element_type const row
(stlsoft::fixed_array_2d<T> const& v, size_t r) {
  return v[r];
}