help-octave
[Top][All Lists]
Advanced

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

Re: new types and INSTALL_BINOP


From: adler
Subject: Re: new types and INSTALL_BINOP
Date: Mon, 5 Mar 2001 22:11:20 -0500 (EST)

On Thu, 1 Mar 2001, John W. Eaton wrote:
> On  1-Mar-2001, address@hidden <address@hidden> wrote:
> | 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 ov-bool-mat.h:
> 
>   class
>   octave_bool_matrix : public octave_base_matrix<boolMatrix>
>   {
>   public:
>     ...
>     type_conv_fcn numeric_conversion_function (void) const;
>     ...
>   };
> 
> and in ov-bool-mat.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;
>   }

Thanks John,

This works well. I have defined a conversion
functions for sparse -> Matrix and
      complex_sparse -> ComplexMatrix.

Here is a patch to provide this functionality for 
examples/make_int.cc. I recommend this be included
in the distribution, so that others can more
easily see how to use this feature.

_______________________________________
Andy Adler,                address@hidden


--- make_int.cc.orig    Mon Mar  5 21:27:57 2001
+++ make_int.cc Mon Mar  5 22:02:48 2001
@@ -42,6 +42,7 @@
 #include <octave/ov-typeinfo.h>
 #include <octave/ov.h>
 #include <octave/ov-scalar.h>
+#include <octave/ov-re-mat.h>
 #include <octave/pager.h>
 #include <octave/pr-output.h>
 #include <octave/symtab.h>
@@ -52,6 +53,9 @@
 
 class tree_walker;
 
+static octave_value *
+default_numeric_conversion_function (const octave_value& a);
+ 
 // Integer values.
 
 class
@@ -127,6 +131,12 @@
 
   void print (ostream& os, bool pr_as_read_syntax = false) const;
 
+  type_conv_fcn numeric_conversion_function (void) const
+  {
+    return default_numeric_conversion_function;
+  }
+ 
+
 private:
 
   int scalar;
@@ -336,6 +346,15 @@
 
 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_integer, "integer");
 
+static octave_value *
+default_numeric_conversion_function (const octave_value& a)
+{
+  CAST_CONV_ARG (const octave_integer &);
+
+  Matrix M( v.integer_value () ); 
+  return new octave_matrix (M);
+}
+ 
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***




-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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