op-fm-fs.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-flt-re-mat.h"
00031 #include "ov-float.h"
00032 #include "ov-scalar.h"
00033 #include "ov-typeinfo.h"
00034 #include "ops.h"
00035 #include "xdiv.h"
00036 #include "xpow.h"
00037 
00038 // matrix by scalar ops.
00039 
00040 DEFNDBINOP_OP (add, float_matrix, float_scalar, float_array, float_scalar, +)
00041 DEFNDBINOP_OP (sub, float_matrix, float_scalar, float_array, float_scalar, -)
00042 DEFNDBINOP_OP (mul, float_matrix, float_scalar, float_array, float_scalar, *)
00043 
00044 DEFBINOP (div, float_matrix, float)
00045 {
00046   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_scalar&);
00047 
00048   float d = v2.float_value ();
00049 
00050   if (d == 0.0)
00051     gripe_divide_by_zero ();
00052 
00053   return octave_value (v1.float_array_value () / d);
00054 }
00055 
00056 DEFBINOP_FN (pow, float_matrix, float_scalar, xpow)
00057 
00058 DEFBINOP (ldiv, float_matrix, float)
00059 {
00060   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_scalar&);
00061 
00062   FloatMatrix m1 = v1.float_matrix_value ();
00063   FloatMatrix m2 = v2.float_matrix_value ();
00064   MatrixType typ = v1.matrix_type ();
00065 
00066   FloatMatrix ret = xleftdiv (m1, m2, typ);
00067 
00068   v1.matrix_type (typ);
00069   return ret;
00070 }
00071 
00072 DEFNDBINOP_FN (lt, float_matrix, float_scalar, float_array,
00073                float_scalar, mx_el_lt)
00074 DEFNDBINOP_FN (le, float_matrix, float_scalar, float_array,
00075                float_scalar, mx_el_le)
00076 DEFNDBINOP_FN (eq, float_matrix, float_scalar, float_array,
00077                float_scalar, mx_el_eq)
00078 DEFNDBINOP_FN (ge, float_matrix, float_scalar, float_array,
00079                float_scalar, mx_el_ge)
00080 DEFNDBINOP_FN (gt, float_matrix, float_scalar, float_array,
00081                float_scalar, mx_el_gt)
00082 DEFNDBINOP_FN (ne, float_matrix, float_scalar, float_array,
00083                float_scalar, mx_el_ne)
00084 
00085 DEFNDBINOP_OP (el_mul, float_matrix, float_scalar, float_array, float_scalar, *)
00086 
00087 DEFBINOP (el_div, float_matrix, float)
00088 {
00089   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_scalar&);
00090 
00091   float d = v2.float_value ();
00092 
00093   if (d == 0.0)
00094     gripe_divide_by_zero ();
00095 
00096   return octave_value (v1.float_array_value () / d);
00097 }
00098 
00099 DEFNDBINOP_FN (el_pow, float_matrix, float_scalar, float_array,
00100                float_scalar, elem_xpow)
00101 
00102 DEFBINOP (el_ldiv, float_matrix, float)
00103 {
00104   CAST_BINOP_ARGS (const octave_float_matrix&, const octave_float_scalar&);
00105 
00106   return x_el_div (v2.float_value (), v1.float_array_value ());
00107 }
00108 
00109 DEFNDBINOP_FN (el_and, float_matrix, float_scalar, float_array,
00110                float_scalar, mx_el_and)
00111 DEFNDBINOP_FN (el_or, float_matrix, float_scalar, float_array,
00112                float_scalar, mx_el_or)
00113 
00114 DEFNDCATOP_FN (fm_fs, float_matrix, float_scalar, float_array,
00115                float_array, concat)
00116 
00117 DEFNDCATOP_FN (m_fs, matrix, float_scalar, float_array, float_array, concat)
00118 
00119 DEFNDCATOP_FN (fm_s, float_matrix, scalar, float_array, float_array, concat)
00120 
00121 DEFNDASSIGNOP_FN (assign, float_matrix, float_scalar, float_scalar, assign)
00122 DEFNDASSIGNOP_FN (dbl_assign, matrix, float_scalar, scalar, assign)
00123 
00124 DEFNDASSIGNOP_OP (assign_add, float_matrix, float_scalar, float_scalar, +=)
00125 DEFNDASSIGNOP_OP (assign_sub, float_matrix, float_scalar, float_scalar, -=)
00126 DEFNDASSIGNOP_OP (assign_mul, float_matrix, float_scalar, float_scalar, *=)
00127 DEFNDASSIGNOP_OP (assign_div, float_matrix, float_scalar, float_scalar, /=)
00128 
00129 void
00130 install_fm_fs_ops (void)
00131 {
00132   INSTALL_BINOP (op_add, octave_float_matrix, octave_float_scalar, add);
00133   INSTALL_BINOP (op_sub, octave_float_matrix, octave_float_scalar, sub);
00134   INSTALL_BINOP (op_mul, octave_float_matrix, octave_float_scalar, mul);
00135   INSTALL_BINOP (op_div, octave_float_matrix, octave_float_scalar, div);
00136   INSTALL_BINOP (op_pow, octave_float_matrix, octave_float_scalar, pow);
00137   INSTALL_BINOP (op_ldiv, octave_float_matrix, octave_float_scalar, ldiv);
00138   INSTALL_BINOP (op_lt, octave_float_matrix, octave_float_scalar, lt);
00139   INSTALL_BINOP (op_le, octave_float_matrix, octave_float_scalar, le);
00140   INSTALL_BINOP (op_eq, octave_float_matrix, octave_float_scalar, eq);
00141   INSTALL_BINOP (op_ge, octave_float_matrix, octave_float_scalar, ge);
00142   INSTALL_BINOP (op_gt, octave_float_matrix, octave_float_scalar, gt);
00143   INSTALL_BINOP (op_ne, octave_float_matrix, octave_float_scalar, ne);
00144   INSTALL_BINOP (op_el_mul, octave_float_matrix, octave_float_scalar, el_mul);
00145   INSTALL_BINOP (op_el_div, octave_float_matrix, octave_float_scalar, el_div);
00146   INSTALL_BINOP (op_el_pow, octave_float_matrix, octave_float_scalar, el_pow);
00147   INSTALL_BINOP (op_el_ldiv, octave_float_matrix, octave_float_scalar, el_ldiv);
00148   INSTALL_BINOP (op_el_and, octave_float_matrix, octave_float_scalar, el_and);
00149   INSTALL_BINOP (op_el_or, octave_float_matrix, octave_float_scalar, el_or);
00150 
00151   INSTALL_CATOP (octave_float_matrix, octave_float_scalar, fm_fs);
00152   INSTALL_CATOP (octave_matrix, octave_float_scalar, m_fs);
00153   INSTALL_CATOP (octave_float_matrix, octave_scalar, fm_s);
00154 
00155   INSTALL_ASSIGNOP (op_asn_eq, octave_float_matrix, octave_float_scalar, assign);
00156   INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_float_scalar, dbl_assign);
00157 
00158   INSTALL_ASSIGNOP (op_add_eq, octave_float_matrix, octave_float_scalar, assign_add);
00159   INSTALL_ASSIGNOP (op_sub_eq, octave_float_matrix, octave_float_scalar, assign_sub);
00160   INSTALL_ASSIGNOP (op_mul_eq, octave_float_matrix, octave_float_scalar, assign_mul);
00161   INSTALL_ASSIGNOP (op_div_eq, octave_float_matrix, octave_float_scalar, assign_div);
00162 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines