Boost logo

Ublas :

From: Robbie Vogt (r.vogt_at_[hidden])
Date: 2005-02-17 03:30:00


Is there much call for assigning to a scalar vector or matrix?  They seem so light-weight that it is often best to work with temporaries.  I find that helper functions help with this, i.e. something along the lines,

template <typename _T>
scalar_vector<_T>
scalar (typename scalar_vector::size_type size, _T value)
{
  return scalar_vector<_T>(size,value);
}
template <typename _T>
scalar_matrix<_T>
scalar (typename scalar_matrix::size_type size1,
        typename scalar_matrix::size_type size2,
        _T value)
{
  return scalar_matrix<_T>(size1,size2,value);
}


so the compiler can work out the type implicitly for you and you can just write

myVec += scalar(10, 1.0);
myMat = scalar(10,10, 0.1);

This also works for identity_matrix and zero_vector/matrix to a lesser extent.  Pretty obvious, but maybe it helps someone...

Robbie.

Michael Stevens wrote:
On Thursday 17 February 2005 08:01, Kresimir Fresl wrote:
  
Michael Stevens wrote:
    
I think this is a good way to go. If you like the = syntax you can define
	operator= (scalar_vector<double> v, double s)
	{
		v = scalar_vector<double> (v.size(), s);
	}
A good compiler should turn this into efficient code.
      
Unfortunately, operator=() must be a member function.

fres
    

Blush Blush. It must have been late! That only leaves an ordinary named 
function to do the job. Something like 'set' or 'set_scalar' would seem like 
a nice name.

Michael
___________________________________
Michael Stevens Systems Engineering

Navigation Systems, Estimation  and
                 Bayesian Filtering
    http://bayesclasses.sf.net
___________________________________
_______________________________________________
ublas mailing list
ublas@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/ublas