Mercurial > octave
changeset 22281:0f9ab4f1f4b3
new function __dump_typeinfo__
* ov-typeinfo.h, ov-typeinfo.cc (F__dump_typeinfo__): New function.
(octave_value_typeinfo::do_installed_type_names): Now const.
(as_bool_nd_array, as_nd_array): New static functions.
(octave_value_typeinfo::unary_ops_map,
octave_value_typeinfo::non_const_unary_ops_map,
octave_value_typeinfo::binary_ops_map,
octave_value_typeinfo::compound_binary_ops_map,
octave_value_typeinfo::assign_ops_map,
octave_value_typeinfo::assignany_ops_map,
octave_value_typeinfo::do_installed_type_info,
octave_value_typeinfo::installed_type_info): New member functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 13 Aug 2016 17:39:29 -0400 |
parents | 26109cce022e |
children | cd2e24983670 |
files | libinterp/octave-value/ov-typeinfo.cc libinterp/octave-value/ov-typeinfo.h |
diffstat | 2 files changed, 218 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-typeinfo.cc Sat Aug 13 15:35:58 2016 +0100 +++ b/libinterp/octave-value/ov-typeinfo.cc Sat Aug 13 17:39:29 2016 -0400 @@ -595,7 +595,7 @@ } string_vector -octave_value_typeinfo::do_installed_type_names (void) +octave_value_typeinfo::do_installed_type_names (void) const { string_vector retval (num_types); @@ -723,3 +723,204 @@ ## Test input validation %!error typeinfo ("foo", 1) */ + +static boolNDArray +as_bool_nd_array (const Array<void *>& x) +{ + boolNDArray retval (x.dims ()); + + for (octave_idx_type i = 0; i < x.numel (); i++) + retval.xelem (i) = x(i); + + return retval; +} + +octave_scalar_map +octave_value_typeinfo::unary_ops_map (void) const +{ + octave_scalar_map retval; + + int len = std::min (non_const_unary_ops.columns (), num_types); + + dim_vector tab_dims (1, len); + + for (int j = 0; j < octave_value::num_unary_ops; j++) + { + boolNDArray tab (tab_dims); + + for (int i = 0; i < len; i++) + tab.xelem (i) = (unary_ops(j,i) != 0); + + octave_value::unary_op op_id = static_cast<octave_value::unary_op> (j); + + retval.setfield (octave_value::unary_op_as_string (op_id), tab); + } + + return retval; +} + +octave_scalar_map +octave_value_typeinfo::non_const_unary_ops_map (void) const +{ + octave_scalar_map retval; + + int len = std::min (non_const_unary_ops.columns (), num_types); + + dim_vector tab_dims (1, len); + + for (int j = 0; j < octave_value::num_unary_ops; j++) + { + boolNDArray tab (tab_dims); + + for (int i = 0; i < len; i++) + tab.xelem (i) = (non_const_unary_ops(j,i) != 0); + + octave_value::unary_op op_id = static_cast<octave_value::unary_op> (j); + + retval.setfield (octave_value::unary_op_as_string (op_id), tab); + } + + return retval; +} + +octave_scalar_map +octave_value_typeinfo::binary_ops_map (void) const +{ + octave_scalar_map retval; + + int len = std::min (binary_ops.columns (), num_types); + + dim_vector tab_dims (len, len); + + for (int k = 0; k < octave_value::num_binary_ops; k++) + { + boolNDArray tab (tab_dims); + + for (int j = 0; j < len; j++) + for (int i = 0; i < len; i++) + tab.xelem (j,i) = (binary_ops(k,j,i) != 0); + + octave_value::binary_op op_id = static_cast<octave_value::binary_op> (k); + + retval.setfield (octave_value::binary_op_as_string (op_id), tab); + } + + return retval; +} + +octave_scalar_map +octave_value_typeinfo::compound_binary_ops_map (void) const +{ + octave_scalar_map retval; + + int len = std::min (compound_binary_ops.columns (), num_types); + + dim_vector tab_dims (len, len); + + for (int k = 0; k < octave_value::num_compound_binary_ops; k++) + { + boolNDArray tab (tab_dims); + + for (int j = 0; j < len; j++) + for (int i = 0; i < len; i++) + tab.xelem (j,i) = (compound_binary_ops(k,j,i) != 0); + + octave_value::compound_binary_op op_id = static_cast<octave_value::compound_binary_op> (k); + + retval.setfield (octave_value::binary_op_fcn_name (op_id), tab); + } + + return retval; +} + +octave_scalar_map +octave_value_typeinfo::assign_ops_map (void) const +{ + octave_scalar_map retval; + + int len = std::min (assign_ops.columns (), num_types); + + dim_vector tab_dims (len, len); + + for (int k = 0; k < octave_value::num_assign_ops; k++) + { + boolNDArray tab (tab_dims); + + for (int j = 0; j < len; j++) + for (int i = 0; i < len; i++) + tab.xelem (j,i) = (assign_ops(k,j,i) != 0); + + octave_value::assign_op op_id = static_cast<octave_value::assign_op> (k); + + retval.setfield (octave_value::assign_op_as_string (op_id), tab); + } + + return retval; +} + +octave_scalar_map +octave_value_typeinfo::assignany_ops_map (void) const +{ + octave_scalar_map retval; + + int len = std::min (assignany_ops.columns (), num_types); + + dim_vector tab_dims (1, len); + + for (int j = 0; j < octave_value::num_assign_ops; j++) + { + boolNDArray tab (tab_dims); + + for (int i = 0; i < len; i++) + tab.xelem (i) = (assignany_ops(j,i) != 0); + + octave_value::assign_op op_id = static_cast<octave_value::assign_op> (j); + + retval.setfield (octave_value::assign_op_as_string (op_id), tab); + } + + return retval; +} + +static NDArray +as_nd_array (const Array<int>& x) +{ + NDArray retval (x.dims ()); + + for (int i = 0; i < x.numel (); i++) + retval.xelem(i) = x(i); + + return retval; +} + +octave_scalar_map +octave_value_typeinfo::do_installed_type_info (void) const +{ + octave_scalar_map retval; + + retval.setfield ("types", octave_value (Cell (do_installed_type_names ()))); + retval.setfield ("unary_ops", unary_ops_map ()); + retval.setfield ("non_const_unary_ops", non_const_unary_ops_map ()); + retval.setfield ("binary_ops", binary_ops_map ()); + retval.setfield ("compound_unary_ops", compound_binary_ops_map ()); + retval.setfield ("cat_ops", as_bool_nd_array (cat_ops)); + retval.setfield ("assign_ops", assign_ops_map ()); + retval.setfield ("assignany_ops", assignany_ops_map ()); + retval.setfield ("pref_assign_conv", as_nd_array (pref_assign_conv)); + retval.setfield ("type_conv_ops", as_bool_nd_array (type_conv_ops)); + retval.setfield ("widening_ops", as_bool_nd_array (widening_ops)); + + return retval; +} + +DEFUN (__dump_typeinfo__, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __dump_typeinfo__ () +Undocumented internal function. +@end deftypefn */) +{ + if (args.length () > 0) + print_usage (); + + return ovl (octave_value_typeinfo::installed_type_info ()); +}
--- a/libinterp/octave-value/ov-typeinfo.h Sat Aug 13 15:35:58 2016 +0100 +++ b/libinterp/octave-value/ov-typeinfo.h Sat Aug 13 17:39:29 2016 -0400 @@ -29,6 +29,7 @@ #include "Array.h" +#include "oct-map.h" #include "ov.h" class string_vector; @@ -191,6 +192,11 @@ return instance->do_installed_type_names (); } + static octave_scalar_map installed_type_info (void) + { + return instance->do_installed_type_info (); + } + protected: octave_value_typeinfo (void) @@ -318,7 +324,16 @@ octave_base_value::type_conv_fcn do_lookup_widening_op (int, int); - string_vector do_installed_type_names (void); + string_vector do_installed_type_names (void) const; + + octave_scalar_map do_installed_type_info (void) const; + + octave_scalar_map unary_ops_map (void) const; + octave_scalar_map non_const_unary_ops_map (void) const; + octave_scalar_map binary_ops_map (void) const; + octave_scalar_map compound_binary_ops_map (void) const; + octave_scalar_map assign_ops_map (void) const; + octave_scalar_map assignany_ops_map (void) const; // No copying!