op-m-m.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, matrix, array, !)
00041 DEFNDUNOP_OP (uplus, matrix, array, /* no-op */)
00042 DEFNDUNOP_OP (uminus, matrix, array, -)
00043 
00044 DEFUNOP (transpose, matrix)
00045 {
00046   CAST_UNOP_ARG (const octave_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.matrix_value().transpose ());
00055 }
00056 
00057 DEFNCUNOP_METHOD (incr, matrix, increment)
00058 DEFNCUNOP_METHOD (decr, matrix, decrement)
00059 DEFNCUNOP_METHOD (changesign, matrix, changesign)
00060 
00061 // matrix by matrix ops.
00062 
00063 DEFNDBINOP_OP (add, matrix, matrix, array, array, +)
00064 DEFNDBINOP_OP (sub, matrix, matrix, array, array, -)
00065 
00066 DEFBINOP_OP (mul, matrix, matrix, *)
00067 
00068 DEFBINOP (div, matrix, matrix)
00069 {
00070   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
00071   MatrixType typ = v2.matrix_type ();
00072 
00073   Matrix ret = xdiv (v1.matrix_value (), v2.matrix_value (), typ);
00074 
00075   v2.matrix_type (typ);
00076   return ret;
00077 }
00078 
00079 DEFBINOPX (pow, matrix, matrix)
00080 {
00081   error ("can't do A ^ B for A and B both matrices");
00082   return octave_value ();
00083 }
00084 
00085 DEFBINOP (ldiv, matrix, matrix)
00086 {
00087   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
00088   MatrixType typ = v1.matrix_type ();
00089 
00090   Matrix ret = xleftdiv (v1.matrix_value (), v2.matrix_value (), typ);
00091 
00092   v1.matrix_type (typ);
00093   return ret;
00094 }
00095 
00096 DEFBINOP (trans_mul, matrix, matrix)
00097 {
00098   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
00099   return octave_value(xgemm (v1.matrix_value (), v2.matrix_value (),
00100                              blas_trans, blas_no_trans));
00101 }
00102 
00103 DEFBINOP (mul_trans, matrix, matrix)
00104 {
00105   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
00106   return octave_value(xgemm (v1.matrix_value (), v2.matrix_value (),
00107                              blas_no_trans, blas_trans));
00108 }
00109 
00110 DEFBINOP (trans_ldiv, matrix, matrix)
00111 {
00112   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
00113   MatrixType typ = v1.matrix_type ();
00114 
00115   Matrix ret = xleftdiv (v1.matrix_value (), v2.matrix_value (), typ, blas_trans);
00116 
00117   v1.matrix_type (typ);
00118   return ret;
00119 }
00120 
00121 DEFNDBINOP_FN (lt, matrix, matrix, array, array, mx_el_lt)
00122 DEFNDBINOP_FN (le, matrix, matrix, array, array, mx_el_le)
00123 DEFNDBINOP_FN (eq, matrix, matrix, array, array, mx_el_eq)
00124 DEFNDBINOP_FN (ge, matrix, matrix, array, array, mx_el_ge)
00125 DEFNDBINOP_FN (gt, matrix, matrix, array, array, mx_el_gt)
00126 DEFNDBINOP_FN (ne, matrix, matrix, array, array, mx_el_ne)
00127 
00128 DEFNDBINOP_FN (el_mul, matrix, matrix, array, array, product)
00129 DEFNDBINOP_FN (el_div, matrix, matrix, array, array, quotient)
00130 DEFNDBINOP_FN (el_pow, matrix, matrix, array, array, elem_xpow)
00131 
00132 DEFBINOP (el_ldiv, matrix, matrix)
00133 {
00134   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
00135 
00136   return octave_value (quotient (v2.array_value (), v1.array_value ()));
00137 }
00138 
00139 DEFNDBINOP_FN (el_and, matrix, matrix, array, array, mx_el_and)
00140 DEFNDBINOP_FN (el_or,  matrix, matrix, array, array, mx_el_or)
00141 DEFNDBINOP_FN (el_not_and, matrix, matrix, array, array, mx_el_not_and)
00142 DEFNDBINOP_FN (el_not_or,  matrix, matrix, array, array, mx_el_not_or)
00143 DEFNDBINOP_FN (el_and_not, matrix, matrix, array, array, mx_el_and_not)
00144 DEFNDBINOP_FN (el_or_not,  matrix, matrix, array, array, mx_el_or_not)
00145 
00146 
00147 DEFNDCATOP_FN (m_m, matrix, matrix, array, array, concat)
00148 
00149 DEFNDASSIGNOP_FN (assign, matrix, matrix, array, assign)
00150 DEFNDASSIGNOP_FN (sgl_assign, float_matrix, matrix, float_array, assign)
00151 
00152 DEFNULLASSIGNOP_FN (null_assign, matrix, delete_elements)
00153 
00154 DEFNDASSIGNOP_OP (assign_add, matrix, matrix, array, +=)
00155 DEFNDASSIGNOP_OP (assign_sub, matrix, matrix, array, -=)
00156 DEFNDASSIGNOP_FNOP (assign_el_mul, matrix, matrix, array, product_eq)
00157 DEFNDASSIGNOP_FNOP (assign_el_div, matrix, matrix, array, quotient_eq)
00158 
00159 CONVDECL (matrix_to_float_matrix)
00160 {
00161   CAST_CONV_ARG (const octave_matrix&);
00162 
00163   return new octave_float_matrix (FloatNDArray (v.array_value ()));
00164 }
00165 
00166 void
00167 install_m_m_ops (void)
00168 {
00169   INSTALL_UNOP (op_not, octave_matrix, not);
00170   INSTALL_UNOP (op_uplus, octave_matrix, uplus);
00171   INSTALL_UNOP (op_uminus, octave_matrix, uminus);
00172   INSTALL_UNOP (op_transpose, octave_matrix, transpose);
00173   INSTALL_UNOP (op_hermitian, octave_matrix, transpose);
00174 
00175   INSTALL_NCUNOP (op_incr, octave_matrix, incr);
00176   INSTALL_NCUNOP (op_decr, octave_matrix, decr);
00177   INSTALL_NCUNOP (op_uminus, octave_matrix, changesign);
00178 
00179   INSTALL_BINOP (op_add, octave_matrix, octave_matrix, add);
00180   INSTALL_BINOP (op_sub, octave_matrix, octave_matrix, sub);
00181   INSTALL_BINOP (op_mul, octave_matrix, octave_matrix, mul);
00182   INSTALL_BINOP (op_div, octave_matrix, octave_matrix, div);
00183   INSTALL_BINOP (op_pow, octave_matrix, octave_matrix, pow);
00184   INSTALL_BINOP (op_ldiv, octave_matrix, octave_matrix, ldiv);
00185   INSTALL_BINOP (op_lt, octave_matrix, octave_matrix, lt);
00186   INSTALL_BINOP (op_le, octave_matrix, octave_matrix, le);
00187   INSTALL_BINOP (op_eq, octave_matrix, octave_matrix, eq);
00188   INSTALL_BINOP (op_ge, octave_matrix, octave_matrix, ge);
00189   INSTALL_BINOP (op_gt, octave_matrix, octave_matrix, gt);
00190   INSTALL_BINOP (op_ne, octave_matrix, octave_matrix, ne);
00191   INSTALL_BINOP (op_el_mul, octave_matrix, octave_matrix, el_mul);
00192   INSTALL_BINOP (op_el_div, octave_matrix, octave_matrix, el_div);
00193   INSTALL_BINOP (op_el_pow, octave_matrix, octave_matrix, el_pow);
00194   INSTALL_BINOP (op_el_ldiv, octave_matrix, octave_matrix, el_ldiv);
00195   INSTALL_BINOP (op_el_and, octave_matrix, octave_matrix, el_and);
00196   INSTALL_BINOP (op_el_or, octave_matrix, octave_matrix, el_or);
00197   INSTALL_BINOP (op_el_and_not, octave_matrix, octave_matrix, el_and_not);
00198   INSTALL_BINOP (op_el_or_not, octave_matrix, octave_matrix, el_or_not);
00199   INSTALL_BINOP (op_el_not_and, octave_matrix, octave_matrix, el_not_and);
00200   INSTALL_BINOP (op_el_not_or, octave_matrix, octave_matrix, el_not_or);
00201   INSTALL_BINOP (op_trans_mul, octave_matrix, octave_matrix, trans_mul);
00202   INSTALL_BINOP (op_mul_trans, octave_matrix, octave_matrix, mul_trans);
00203   INSTALL_BINOP (op_herm_mul, octave_matrix, octave_matrix, trans_mul);
00204   INSTALL_BINOP (op_mul_herm, octave_matrix, octave_matrix, mul_trans);
00205   INSTALL_BINOP (op_trans_ldiv, octave_matrix, octave_matrix, trans_ldiv);
00206   INSTALL_BINOP (op_herm_ldiv, octave_matrix, octave_matrix, trans_ldiv);
00207 
00208   INSTALL_CATOP (octave_matrix, octave_matrix, m_m);
00209 
00210   INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_matrix, assign);
00211   INSTALL_ASSIGNOP (op_asn_eq, octave_float_matrix, octave_matrix, sgl_assign);
00212 
00213   INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_null_matrix, null_assign);
00214   INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_null_str, null_assign);
00215   INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_null_sq_str, null_assign);
00216 
00217   INSTALL_ASSIGNOP (op_add_eq, octave_matrix, octave_matrix, assign_add);
00218   INSTALL_ASSIGNOP (op_sub_eq, octave_matrix, octave_matrix, assign_sub);
00219   INSTALL_ASSIGNOP (op_el_mul_eq, octave_matrix, octave_matrix, assign_el_mul);
00220   INSTALL_ASSIGNOP (op_el_div_eq, octave_matrix, octave_matrix, assign_el_div);
00221 
00222   INSTALL_CONVOP (octave_matrix, octave_float_matrix, matrix_to_float_matrix);
00223 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines