[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new types and INSTALL_BINOP
From: 
John W. Eaton 
Subject: 
Re: new types and INSTALL_BINOP 
Date: 
Thu, 1 Mar 2001 20:28:00 0600 
On 1Mar2001, address@hidden <address@hidden> wrote:
 Great, that makes a lot of sense for my case, because this
 is the best way to handle most operators.

 For example:
 sparse_matrix + 1
 is best handled by converting it to a "full" matrix

 Unfortunately, I don't understand the details of how to make
 this work.

 I have conversion methods for this, eg:
 Matrix octave_sparse::matrix_value (bool = false) const {
 Matrix M= oct_sparse_to_full( X );
 return M;
 }
(I'd write the body of this function as just
return oct_sparse_to_full (X);
since there is no need to have the declaration/initialization
statement here.)
 How do I register this with do_binary_op so that it can
 call my function?
Here is how it is done for the bool_matrix class. In ovboolmat.h:
class
octave_bool_matrix : public octave_base_matrix<boolMatrix>
{
public:
...
type_conv_fcn numeric_conversion_function (void) const;
...
};
and in ovboolmat.cc:
static octave_value *
default_numeric_conversion_function (const octave_value& a)
{
CAST_CONV_ARG (const octave_bool_matrix&);
return new octave_matrix (Matrix (v.bool_matrix_value ()));
}
type_conv_fcn
octave_bool_matrix::numeric_conversion_function (void) const
{
return default_numeric_conversion_function;
}
Your conversion function would be
static octave_value *
default_numeric_conversion_function (const octave_value& a)
{
CAST_CONV_ARG (const octave_sparse&);
return new octave_matrix (v.matrix_value ());
}
(I should probably define an octave_bool_matrix::matrix_value member
function.)
The reason for having the function that returns the address of the
conversion function is to avoid headaches with pointers to member
functions and at the same time keep the conversion function out of the
global namespace.
jwe

Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
