![]() |
Blitz Support : |
From: Julian C. Cummings (cummings_at_[hidden])
Date: 2004-07-19 13:31:22
Hi Steve,
Blitz Array class does something unusual with operator=() in order to
support initialization of an Array with a comma-separated list of values.
You probably need to explicitly cast the result of the vec_t::operator=()
call to a vec_t& and then let the copy constructor move the result to the
vector object. Also, I think you should be using const references in your
constructor methods.
Regards, Julian C.
Dr. Julian C. Cummings
Staff Scientist, CACR/Caltech
(626) 395-2543
cummings_at_[hidden]
> -----Original Message-----
> From: blitz-support-bounces_at_[hidden]
> [mailto:blitz-support-bounces_at_[hidden]] On Behalf Of
> Scott, Steven
> Sent: Wednesday, July 14, 2004 3:24 PM
> To: Blitz-support_at_[hidden]
> Subject: [Blitz-support] I need help deriving an interface to blitz
>
>
> I'd like to develop an interface class that inherits from
> blitz::Array, but which provides methods that my existing
> code expects. For example,
>
> double ans=0;
> vector x(1, 10);
> for(i=x.lo(); i<=x.hi(); ++i) ans+= h(x[i]); //
> h(double) defined elsewhere
>
> I'd like to do something like:
>
> class vector : public blitz::Array<double, 1>{
> // some constructors
> // operator=()
> int lo(){return lbound(firstDim);}
> int hi(){return ubound(firstDim);}
> //... only a few other methods need to be defined
> };
>
> In theory, my old code would still work, I could continue to
> write code using familiar syntax (e.g. lo() and hi()), but I
> could have Blitz do the heavy lifting on my future code:
>
> vector x(10), y(10), z(10);
> x = z*y + y/cos(exp(z)); // or some such nonsense
>
> THE PROBLEM:
>
> I can't seem to define the correct constructors or
> operator=(). I'd like to just pass the RHS of operator= to
> the blitz operator=. I don't know how to do this, I think
> because the RHS is an Array Expression, which I don't know
> how to manipulate.
>
> My current attempt at a class definition, a sample program
> that breaks it, and the compiler errors, are provided below.
>
> Thanks for the help!
>
> Steve
>
>
> -----------------------------------------
> namespace lin_alg{
> class vector : public blitz::Array<double, 1>{
> public:
> typedef blitz::Array<double, 1> vec_t;
> typedef blitz::Range Range;
>
> // constructors: call blitz constructors
> // empty
> vector(){}
> // construct from blitz vector
> vector(vec_t &x) : vec_t::Array(x) {}
> // copy
> vector(vector &x) : vec_t::Array( static_cast<vec_t&>(x)){}
> // extent parameters
> vector(int dim) : vec_t::Array(dim) {}
> // Range argument
> vector(Range r) : vec_t::Array(r) {}
> // from double data
> vector(double *dat, int len) :
> vec_t::Array(dat, blitz::shape(len), blitz::neverDeleteData) {}
>
> vector & operator=(const double &x){
> return vector(vec_t::operator=(x));}
>
> int lo(){return vec_t::lbound(blitz::firstDim);}
> int hi(){return vec_t::ubound(blitz::firstDim);}
> //... only a few other methods need to be defined
>
> };
> }
> ------------------------------------------------
> int main(){
> lin_alg::vector x(4);
> x=10;
> }
> -------------------------------------------
> /home/sls/cpplib/lin_alg/vector.h: In member function
> `lin_alg::vector&
> lin_alg::vector::operator=(const double&)':
> /home/sls/cpplib/lin_alg/vector.h:35: error: no matching
> function for call to `
>
> lin_alg::vector::vector(blitz::ListInitializationSwitch<blitz:
> :Array<dou
> ble,
> 1>, double*>)'
> /home/sls/cpplib/lin_alg/vector.h:31: error: candidates are:
> lin_alg::vector::vector(double*, int)
> /home/sls/cpplib/lin_alg/vector.h:29: error:
> lin_alg::vector::vector(blitz::Range)
> /home/sls/cpplib/lin_alg/vector.h:27: error:
> lin_alg::vector::vector(int)
> /home/sls/cpplib/lin_alg/vector.h:25: error:
> lin_alg::vector::vector(steve::vector&)
> /home/sls/cpplib/lin_alg/vector.h:23: error:
> lin_alg::vector::vector(blitz::Array<double, 1>&)
> /home/sls/cpplib/lin_alg/vector.h:21: error:
> lin_alg::vector::vector()
>
> _______________________________________________
> Blitz-support mailing list
> Blitz-support_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>