octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: binary operators with new classes.


From: Rik
Subject: Re: binary operators with new classes.
Date: Sun, 14 Jul 2013 07:34:39 -0700

On 07/13/2013 09:46 PM, address@hidden wrote:
> Message: 5
> Date: Sat, 13 Jul 2013 14:48:30 -0700 (PDT)
> From: CdeMills <address@hidden>
> To: address@hidden
> Subject: binary operator '+' not implemented for 'scalar' by
>       'new_type'      operations
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=us-ascii
>
> Hello,
>
> taking inspiration from examples/make_int.cc, I implemented a
> 'octave_multiprec' class which is
> 1) a scalar: it may access mapping func like sin, cos, tan, ...
> 2) a new type: it has unary and binary op
>
> The skeleton found in make_int.cc permits to register the new type; I gave
> the main func the name make_mp (this  is temporary)
>
> Operations like
> x = make_mp(2); y = make_mp(3), z=x+y do work correctly as
> 1) the class as a 'add' member function:
> int add (const octave_multiprec& v1, const octave_multiprec& v2)
>   {
>     return mpfr_add (this->scalar, v1.scalar, v2.scalar, GMP_RNDN);
>   }
> 2) this function is registred and accessed as
> DEFBINOP (add, multiprec, multiprec)
> {
>   CAST_BINOP_ARGS (const octave_multiprec&, const octave_multiprec&);
>
>   octave_multiprec *s = new octave_multiprec ();
>   s->add (v1, v2); 
>   return s;
> }
> INSTALL_BINOP (op_add, octave_multiprec, octave_multiprec, add);
>
> How can I define similar function where only one of the arguments is an
> Octave real scalar ? I tried
>  INSTALL_BINOP (op_add, octave_multiprec, octave_scalar, add);
>  INSTALL_BINOP (op_add, octave_scalar, octave_multiprec, add);
>
> But I keep getting the same error message. Platform: octave-3.6.4
Pascal,

Take a look at the directory libinterp/operators.  For example, op-s-sm.cc
describes operations between scalars and sparse matrices which should be
similar enough in structure to what you want to do.

--Rik



reply via email to

[Prev in Thread] Current Thread [Next in Thread]