MDiagArray2.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 Copyright (C) 2010 VZLU Prague
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include "MDiagArray2.h"
00029 #include "Array-util.h"
00030 #include "lo-error.h"
00031 
00032 #include "MArray-defs.h"
00033 
00034 template <class T>
00035 bool
00036 MDiagArray2<T>::is_multiple_of_identity (T val) const
00037 {
00038   bool retval = this->rows () == this->cols ();
00039   if (retval)
00040     {
00041       octave_idx_type len = this->length (), i = 0;
00042       for (;i < len; i++)
00043         if (DiagArray2<T>::elem (i, i) != val) break;
00044       retval = i == len;
00045     }
00046 
00047   return retval;
00048 }
00049 
00050 // Two dimensional diagonal array with math ops.
00051 
00052 // Element by element MDiagArray2 by MDiagArray2 ops.
00053 
00054 // Element by element MDiagArray2 by scalar ops.
00055 
00056 #define MARRAY_DAS_OP(OP, FN) \
00057   template <class T> \
00058   MDiagArray2<T> \
00059   operator OP (const MDiagArray2<T>& a, const T& s) \
00060   { \
00061     return MDiagArray2<T> (do_ms_binary_op<T, T, T> (a, s, FN), a.d1, a.d2); \
00062   }
00063 
00064 MARRAY_DAS_OP (*, mx_inline_mul)
00065 MARRAY_DAS_OP (/, mx_inline_div)
00066 
00067 // Element by element scalar by MDiagArray2 ops.
00068 
00069 template <class T>
00070 MDiagArray2<T>
00071 operator * (const T& s, const MDiagArray2<T>& a)
00072 {
00073   return MDiagArray2<T> (do_sm_binary_op<T, T, T> (s, a, mx_inline_mul), a.d1, a.d2);
00074 }
00075 
00076 // Element by element MDiagArray2 by MDiagArray2 ops.
00077 
00078 #define MARRAY_DADA_OP(FCN, OP, FN) \
00079   template <class T> \
00080   MDiagArray2<T> \
00081   FCN (const MDiagArray2<T>& a, const MDiagArray2<T>& b) \
00082   { \
00083     if (a.d1 != b.d1 || a.d2 != b.d2) \
00084       gripe_nonconformant (#FCN, a.d1, a.d2, b.d1, b.d2); \
00085     return MDiagArray2<T> (do_mm_binary_op<T, T, T> (a, b, FN, FN, FN, #FCN), a.d1, a.d2); \
00086   }
00087 
00088 MARRAY_DADA_OP (operator +, +, mx_inline_add)
00089 MARRAY_DADA_OP (operator -, -, mx_inline_sub)
00090 MARRAY_DADA_OP (product,    *, mx_inline_mul)
00091 
00092 // Unary MDiagArray2 ops.
00093 
00094 template <class T>
00095 MDiagArray2<T>
00096 operator + (const MDiagArray2<T>& a)
00097 {
00098   return a;
00099 }
00100 
00101 template <class T>
00102 MDiagArray2<T>
00103 operator - (const MDiagArray2<T>& a)
00104 {
00105   return MDiagArray2<T> (do_mx_unary_op<T, T> (a, mx_inline_uminus), a.d1, a.d2);
00106 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines