op-fm-fm.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "gripes.h"
00028 #include "oct-obj.h"
00029 #include "ov.h"
00030 #include "ov-re-mat.h"
00031 #include "ov-flt-re-mat.h"
00032 #include "ov-typeinfo.h"
00033 #include "ov-null-mat.h"
00034 #include "ops.h"
00035 #include "xdiv.h"
00036 #include "xpow.h"
00037 
00038 // matrix unary ops.
00039 
00040 DEFNDUNOP_OP (not, float_matrix, float_array, !)
00041 DEFNDUNOP_OP (uplus, float_matrix, float_array, /* no-op */)
00042 DEFNDUNOP_OP (uminus, float_matrix, float_array, -)
00043 
00044 DEFUNOP (transpose, float_matrix)
00045 {
00046   CAST_UNOP_ARG (const octave_float_matrix&);
00047 
00048   if (v.ndims () > 2)
00049     {
00050       error ("transpose not defined for N-d objects");
00051       return octave_value ();
00052     }
00053   else
00054     return octave_value (v.float_matrix_value().transpose ());
00055 }
00056 
00057 DEFNCUNOP_METHOD (incr, float_matrix, increment)
00058 DEFNCUNOP_METHOD (decr, float_matrix, decrement)
00059 DEFNCUNOP_METHOD (changesign, float_matrix, changesign)
00060 
00061 // matrix by matrix ops.
00062 
00063 DEFNDBINOP_OP (add, float_matrix, float_matrix, float_array, float_array, +)
00064 DEFNDBINOP_OP (sub, float_matrix, float_matrix, float_array, float_array, -)
00065 
00066 DEFBINOP_OP (mul, float_matrix, float_matrix, *)
00067 
00068 DEFBINOP (div, float_matrix, float_matrix)
00069 {
00070   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_matrix&);
00071   MatrixType typ = v2.matrix_type ();
00072 
00073   FloatMatrix ret = xdiv (v1.float_matrix_value (),
00074                           v2.float_matrix_value (), typ);
00075 
00076   v2.matrix_type (typ);
00077   return ret;
00078 }
00079 
00080 DEFBINOPX (pow, float_matrix, float_matrix)
00081 {
00082   error ("can't do A ^ B for A and B both matrices");
00083   return octave_value ();
00084 }
00085 
00086 DEFBINOP (ldiv, float_matrix, float_matrix)
00087 {
00088   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_matrix&);
00089   MatrixType typ = v1.matrix_type ();
00090 
00091   FloatMatrix ret = xleftdiv (v1.float_matrix_value (),
00092                               v2.float_matrix_value (), typ);
00093 
00094   v1.matrix_type (typ);
00095   return ret;
00096 }
00097 
00098 DEFBINOP (trans_mul, float_matrix, float_matrix)
00099 {
00100   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_matrix&);
00101   return octave_value(xgemm (v1.float_matrix_value (),
00102                              v2.float_matrix_value (),
00103                              blas_trans, blas_no_trans));
00104 }
00105 
00106 DEFBINOP (mul_trans, float_matrix, float_matrix)
00107 {
00108   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_matrix&);
00109   return octave_value(xgemm (v1.float_matrix_value (),
00110                              v2.float_matrix_value (),
00111                              blas_no_trans, blas_trans));
00112 }
00113 
00114 DEFBINOP (trans_ldiv, float_matrix, float_matrix)
00115 {
00116   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_matrix&);
00117   MatrixType typ = v1.matrix_type ();
00118 
00119   FloatMatrix ret = xleftdiv (v1.float_matrix_value (),
00120                               v2.float_matrix_value (), typ, blas_trans);
00121 
00122   v1.matrix_type (typ);
00123   return ret;
00124 }
00125 
00126 DEFNDBINOP_FN (lt, float_matrix, float_matrix, float_array,
00127                float_array, mx_el_lt)
00128 DEFNDBINOP_FN (le, float_matrix, float_matrix, float_array,
00129                float_array, mx_el_le)
00130 DEFNDBINOP_FN (eq, float_matrix, float_matrix, float_array,
00131                float_array, mx_el_eq)
00132 DEFNDBINOP_FN (ge, float_matrix, float_matrix, float_array,
00133                float_array, mx_el_ge)
00134 DEFNDBINOP_FN (gt, float_matrix, float_matrix, float_array,
00135                float_array, mx_el_gt)
00136 DEFNDBINOP_FN (ne, float_matrix, float_matrix, float_array,
00137                float_array, mx_el_ne)
00138 
00139 DEFNDBINOP_FN (el_mul, float_matrix, float_matrix, float_array,
00140                float_array, product)
00141 DEFNDBINOP_FN (el_div, float_matrix, float_matrix, float_array,
00142                float_array, quotient)
00143 DEFNDBINOP_FN (el_pow, float_matrix, float_matrix, float_array,
00144                float_array, elem_xpow)
00145 
00146 DEFBINOP (el_ldiv, float_matrix, float_matrix)
00147 {
00148   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_matrix&);
00149 
00150   return octave_value (quotient (v2.float_array_value (),
00151                                  v1.float_array_value ()));
00152 }
00153 
00154 DEFNDBINOP_FN (el_and, float_matrix, float_matrix, float_array,
00155                float_array, mx_el_and)
00156 DEFNDBINOP_FN (el_or,  float_matrix, float_matrix, float_array,
00157                float_array, mx_el_or)
00158 DEFNDBINOP_FN (el_not_and, float_matrix, float_matrix, float_array,
00159                float_array, mx_el_not_and)
00160 DEFNDBINOP_FN (el_not_or,  float_matrix, float_matrix, float_array,
00161                float_array, mx_el_not_or)
00162 DEFNDBINOP_FN (el_and_not, float_matrix, float_matrix, float_array,
00163                float_array, mx_el_and_not)
00164 DEFNDBINOP_FN (el_or_not,  float_matrix, float_matrix, float_array,
00165                float_array, mx_el_or_not)
00166 
00167 
00168 
00169 DEFNDCATOP_FN (fm_fm, float_matrix, float_matrix, float_array,
00170                float_array, concat)
00171 
00172 DEFNDCATOP_FN (m_fm, matrix, float_matrix, float_array, float_array, concat)
00173 
00174 DEFNDCATOP_FN (fm_m, float_matrix, matrix, float_array, float_array, concat)
00175 
00176 DEFNDASSIGNOP_FN (assign, float_matrix, float_matrix, float_array, assign)
00177 
00178 DEFNDASSIGNOP_FN (dbl_assign, matrix, float_matrix, array, assign)
00179 
00180 DEFNULLASSIGNOP_FN (null_assign, float_matrix, delete_elements)
00181 
00182 DEFNDASSIGNOP_OP (assign_add, float_matrix, float_matrix, float_array, +=)
00183 DEFNDASSIGNOP_OP (assign_sub, float_matrix, float_matrix, float_array, -=)
00184 DEFNDASSIGNOP_FNOP (assign_el_mul, float_matrix, float_matrix, float_array, product_eq)
00185 DEFNDASSIGNOP_FNOP (assign_el_div, float_matrix, float_matrix, float_array, quotient_eq)
00186 
00187 CONVDECL (float_matrix_to_matrix)
00188 {
00189   CAST_CONV_ARG (const octave_float_matrix&);
00190 
00191   return new octave_matrix (v.array_value ());
00192 }
00193 
00194 void
00195 install_fm_fm_ops (void)
00196 {
00197   INSTALL_UNOP (op_not, octave_float_matrix, not);
00198   INSTALL_UNOP (op_uplus, octave_float_matrix, uplus);
00199   INSTALL_UNOP (op_uminus, octave_float_matrix, uminus);
00200   INSTALL_UNOP (op_transpose, octave_float_matrix, transpose);
00201   INSTALL_UNOP (op_hermitian, octave_float_matrix, transpose);
00202 
00203   INSTALL_NCUNOP (op_incr, octave_float_matrix, incr);
00204   INSTALL_NCUNOP (op_decr, octave_float_matrix, decr);
00205   INSTALL_NCUNOP (op_uminus, octave_float_matrix, changesign);
00206 
00207   INSTALL_BINOP (op_add, octave_float_matrix, octave_float_matrix, add);
00208   INSTALL_BINOP (op_sub, octave_float_matrix, octave_float_matrix, sub);
00209   INSTALL_BINOP (op_mul, octave_float_matrix, octave_float_matrix, mul);
00210   INSTALL_BINOP (op_div, octave_float_matrix, octave_float_matrix, div);
00211   INSTALL_BINOP (op_pow, octave_float_matrix, octave_float_matrix, pow);
00212   INSTALL_BINOP (op_ldiv, octave_float_matrix, octave_float_matrix, ldiv);
00213   INSTALL_BINOP (op_lt, octave_float_matrix, octave_float_matrix, lt);
00214   INSTALL_BINOP (op_le, octave_float_matrix, octave_float_matrix, le);
00215   INSTALL_BINOP (op_eq, octave_float_matrix, octave_float_matrix, eq);
00216   INSTALL_BINOP (op_ge, octave_float_matrix, octave_float_matrix, ge);
00217   INSTALL_BINOP (op_gt, octave_float_matrix, octave_float_matrix, gt);
00218   INSTALL_BINOP (op_ne, octave_float_matrix, octave_float_matrix, ne);
00219   INSTALL_BINOP (op_el_mul, octave_float_matrix, octave_float_matrix, el_mul);
00220   INSTALL_BINOP (op_el_div, octave_float_matrix, octave_float_matrix, el_div);
00221   INSTALL_BINOP (op_el_pow, octave_float_matrix, octave_float_matrix, el_pow);
00222   INSTALL_BINOP (op_el_ldiv, octave_float_matrix, octave_float_matrix, el_ldiv);
00223   INSTALL_BINOP (op_el_and, octave_float_matrix, octave_float_matrix, el_and);
00224   INSTALL_BINOP (op_el_or, octave_float_matrix, octave_float_matrix, el_or);
00225   INSTALL_BINOP (op_el_and_not, octave_float_matrix, octave_float_matrix, el_and_not);
00226   INSTALL_BINOP (op_el_or_not, octave_float_matrix, octave_float_matrix, el_or_not);
00227   INSTALL_BINOP (op_el_not_and, octave_float_matrix, octave_float_matrix, el_not_and);
00228   INSTALL_BINOP (op_el_not_or, octave_float_matrix, octave_float_matrix, el_not_or);
00229   INSTALL_BINOP (op_trans_mul, octave_float_matrix, octave_float_matrix, trans_mul);
00230   INSTALL_BINOP (op_mul_trans, octave_float_matrix, octave_float_matrix, mul_trans);
00231   INSTALL_BINOP (op_herm_mul, octave_float_matrix, octave_float_matrix, trans_mul);
00232   INSTALL_BINOP (op_mul_herm, octave_float_matrix, octave_float_matrix, mul_trans);
00233   INSTALL_BINOP (op_trans_ldiv, octave_float_matrix, octave_float_matrix, trans_ldiv);
00234   INSTALL_BINOP (op_herm_ldiv, octave_float_matrix, octave_float_matrix, trans_ldiv);
00235 
00236   INSTALL_CATOP (octave_float_matrix, octave_float_matrix, fm_fm);
00237   INSTALL_CATOP (octave_matrix, octave_float_matrix, m_fm);
00238   INSTALL_CATOP (octave_float_matrix, octave_matrix, fm_m);
00239 
00240   INSTALL_ASSIGNOP (op_asn_eq, octave_float_matrix,
00241                     octave_float_matrix, assign);
00242   INSTALL_ASSIGNOP (op_asn_eq, octave_matrix,
00243                     octave_float_matrix, dbl_assign);
00244 
00245   INSTALL_ASSIGNOP (op_asn_eq, octave_float_matrix, octave_null_matrix, null_assign);
00246   INSTALL_ASSIGNOP (op_asn_eq, octave_float_matrix, octave_null_str, null_assign);
00247   INSTALL_ASSIGNOP (op_asn_eq, octave_float_matrix, octave_null_sq_str, null_assign);
00248 
00249   INSTALL_ASSIGNOP (op_add_eq, octave_float_matrix, octave_float_matrix, assign_add);
00250   INSTALL_ASSIGNOP (op_sub_eq, octave_float_matrix, octave_float_matrix, assign_sub);
00251   INSTALL_ASSIGNOP (op_el_mul_eq, octave_float_matrix, octave_float_matrix, assign_el_mul);
00252   INSTALL_ASSIGNOP (op_el_div_eq, octave_float_matrix, octave_float_matrix, assign_el_div);
00253 
00254   INSTALL_CONVOP (octave_float_matrix, octave_matrix, float_matrix_to_matrix);
00255 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines