help-octave
[Top][All Lists]
Advanced

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

Re: Automatic Type Conversion


From: r-j-k
Subject: Re: Automatic Type Conversion
Date: Sun, 19 Jul 2009 17:52:08 -0700 (PDT)

I think I solved it. I had to provide the following methods in my type (ver
3.0.3):
bool is_single_type(void) const {return true;}
bool is_real_type(void) const {return true;}
bool is_matrix_type(void) const {return true;}
NDArray array_value(bool = false) const { ... }

and the built-in's I've tried seem to give correct results. One thing I
noticed in my poking around is the INSTALL_CONVOP macro (as well as
DEFDBLCONVFN, as per op-double-conv.cc). It doesn't seem to make a
difference whether or not I call this macro upon installation of my type.
What is the use of this macro?

Thanks.


r-j-k wrote:
> 
> Thanks for the reply. I implemented this method however it only seems to
> perform the conversion for operators, not built-in functions:
> 
> octave:13> x = my_matrix([1 2; 3 4]);
> octave:14> y = [5 6; 7 8];
> octave:15> x + y
> ans =
> 
>     6    8
>    10   12
> 
> octave:16> log(x);
> error: mapper: wrong type argument `my_matrix'
> octave:16> eig(x);
> error: eig: wrong type argument `matrix'
> 
> Is it possible for the conversion to occur for functions as well or is
> this impossible?
> 
> Thanks.
> 
> 
> 
> 
> 
> John W. Eaton-3 wrote:
>> 
>> On 16-Jul-2009, r-j-k wrote:
>> 
>> | I have a special matrix type, my_matrix, defined in an oct file. I want
>> my
>> | my_matrix to be automatically converted to an octave matrix when a
>> function
>> | is called expecting an octave matrix. Is this possible? I have
>> implemented
>> | the matrix_value() and is_real_matrix() methods. Currently, I get the
>> | following when I attempt to use such functions:
>> | 
>> | octave:6> x = my_matrix(1);
>> | octave:7> log(x);
>> | error: mapper: wrong type argument `my_matrix'
>> | octave:7> eig(x);
>> | error: eig: wrong type argument `matrix'
>> | 
>> | Any tips?
>> 
>> Look at the octave_base_value::numeric_conversion_function method.
>> There are examples in several of the classes that are part of Octave.
>> 
>> jwe
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Automatic-Type-Conversion-tp24537852p24562392.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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