op-s-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-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, scalar, matrix, scalar, array, +)
00042 DEFNDBINOP_OP (sub, scalar, matrix, scalar, array, -)
00043 DEFNDBINOP_OP (mul, scalar, matrix, scalar, array, *)
00044 
00045 DEFBINOP (div, scalar, matrix)
00046 {
00047   CAST_BINOP_ARGS (const octave_scalar&, const octave_matrix&);
00048 
00049   Matrix m1 = v1.matrix_value ();
00050   Matrix m2 = v2.matrix_value ();
00051   MatrixType typ = v2.matrix_type ();
00052 
00053   Matrix ret = xdiv (m1, m2, typ);
00054 
00055   v2.matrix_type (typ);
00056   return ret;
00057 }
00058 
00059 DEFBINOP_FN (pow, scalar, matrix, xpow)
00060 
00061 DEFBINOP (ldiv, scalar, matrix)
00062 {
00063   CAST_BINOP_ARGS (const octave_scalar&, const octave_matrix&);
00064 
00065   double d = v1.double_value ();
00066 
00067   if (d == 0.0)
00068     gripe_divide_by_zero ();
00069 
00070   return octave_value (v2.array_value () / d);
00071 }
00072 
00073 DEFNDBINOP_FN (lt, scalar, matrix, scalar, array, mx_el_lt)
00074 DEFNDBINOP_FN (le, scalar, matrix, scalar, array, mx_el_le)
00075 DEFNDBINOP_FN (eq, scalar, matrix, scalar, array, mx_el_eq)
00076 DEFNDBINOP_FN (ge, scalar, matrix, scalar, array, mx_el_ge)
00077 DEFNDBINOP_FN (gt, scalar, matrix, scalar, array, mx_el_gt)
00078 DEFNDBINOP_FN (ne, scalar, matrix, scalar, array, mx_el_ne)
00079 
00080 DEFNDBINOP_OP (el_mul, scalar, matrix, scalar, array, *)
00081 DEFNDBINOP_FN (el_div, scalar, matrix, scalar, array, x_el_div)
00082 DEFNDBINOP_FN (el_pow, scalar, matrix, scalar, array, elem_xpow)
00083 
00084 DEFBINOP (el_ldiv, scalar, matrix)
00085 {
00086   CAST_BINOP_ARGS (const octave_scalar&, const octave_matrix&);
00087 
00088   double d = v1.double_value ();
00089 
00090   if (d == 0.0)
00091     gripe_divide_by_zero ();
00092 
00093   return octave_value (v2.array_value () / d);
00094 }
00095 
00096 DEFNDBINOP_FN (el_and, scalar, matrix, scalar, array, mx_el_and)
00097 DEFNDBINOP_FN (el_or,  scalar, matrix, scalar, array, mx_el_or)
00098 
00099 DEFNDCATOP_FN (s_m, scalar, matrix, array, array, concat)
00100 
00101 DEFCONV (matrix_conv, scalar, matrix)
00102 {
00103   CAST_CONV_ARG (const octave_scalar&);
00104 
00105   return new octave_matrix (v.matrix_value ());
00106 }
00107 
00108 void
00109 install_s_m_ops (void)
00110 {
00111   INSTALL_BINOP (op_add, octave_scalar, octave_matrix, add);
00112   INSTALL_BINOP (op_sub, octave_scalar, octave_matrix, sub);
00113   INSTALL_BINOP (op_mul, octave_scalar, octave_matrix, mul);
00114   INSTALL_BINOP (op_div, octave_scalar, octave_matrix, div);
00115   INSTALL_BINOP (op_pow, octave_scalar, octave_matrix, pow);
00116   INSTALL_BINOP (op_ldiv, octave_scalar, octave_matrix, ldiv);
00117   INSTALL_BINOP (op_lt, octave_scalar, octave_matrix, lt);
00118   INSTALL_BINOP (op_le, octave_scalar, octave_matrix, le);
00119   INSTALL_BINOP (op_eq, octave_scalar, octave_matrix, eq);
00120   INSTALL_BINOP (op_ge, octave_scalar, octave_matrix, ge);
00121   INSTALL_BINOP (op_gt, octave_scalar, octave_matrix, gt);
00122   INSTALL_BINOP (op_ne, octave_scalar, octave_matrix, ne);
00123   INSTALL_BINOP (op_el_mul, octave_scalar, octave_matrix, el_mul);
00124   INSTALL_BINOP (op_el_div, octave_scalar, octave_matrix, el_div);
00125   INSTALL_BINOP (op_el_pow, octave_scalar, octave_matrix, el_pow);
00126   INSTALL_BINOP (op_el_ldiv, octave_scalar, octave_matrix, el_ldiv);
00127   INSTALL_BINOP (op_el_and, octave_scalar, octave_matrix, el_and);
00128   INSTALL_BINOP (op_el_or, octave_scalar, octave_matrix, el_or);
00129 
00130   INSTALL_CATOP (octave_scalar, octave_matrix, s_m);
00131 
00132   INSTALL_ASSIGNCONV (octave_scalar, octave_matrix, octave_matrix);
00133   INSTALL_ASSIGNCONV (octave_float_scalar, octave_matrix, octave_float_matrix);
00134 
00135   INSTALL_WIDENOP (octave_scalar, octave_matrix, matrix_conv);
00136 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines