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