开发者

API that handles boost ublas sparse OR dense matrices

开发者 https://www.devze.com 2023-04-02 00:10 出处:网络
I am a bit perplexed by the Boost ublas documentation.It does not seem clear to me that the sparse and dense matrix classes share a common parent class---which I believe is by design.But then how can

I am a bit perplexed by the Boost ublas documentation. It does not seem clear to me that the sparse and dense matrix classes share a common parent class---which I believe is by design. But then how can I design an API that can accept either sparse开发者_StackOverflow or dense matrix, assuming that it need only operate on entries of the matrix using the operator() accessor, say. For example, something like this:

float doMatrixMath(matrix_base<float> m) 
{
  return m(1,1)+m(2,2);
}

Perhaps my thinking about this is wrong-headed. Any guidance regarding how to think about the object modeling of ublas classes would be appreciated!


Templates unfortunately. You can use a very generic type, or dig in and find something more concrete, but the general idea is:

template< typename MatrixType >
float doMatrixMath(MatrixType m) 
{
  return m(1,1)+m(2,2);
}

Of course this can be enhanced with a more concrete type and return value detection...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号