GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MDiagArray2.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 Copyright (C) 2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include "MDiagArray2.h"
29 #include "Array-util.h"
30 #include "lo-error.h"
31 
32 #include "MArray-defs.h"
33 
34 template <class T>
35 bool
37 {
38  bool retval = this->rows () == this->cols ();
39  if (retval)
40  {
41  octave_idx_type len = this->length (), i = 0;
42  for (; i < len; i++)
43  if (DiagArray2<T>::elem (i, i) != val) break;
44  retval = i == len;
45  }
46 
47  return retval;
48 }
49 
50 // Two dimensional diagonal array with math ops.
51 
52 // Element by element MDiagArray2 by MDiagArray2 ops.
53 
54 // Element by element MDiagArray2 by scalar ops.
55 
56 #define MARRAY_DAS_OP(OP, FN) \
57  template <class T> \
58  MDiagArray2<T> \
59  operator OP (const MDiagArray2<T>& a, const T& s) \
60  { \
61  return MDiagArray2<T> (do_ms_binary_op<T, T, T> (a, s, FN), a.d1, a.d2); \
62  }
63 
66 
67 // Element by element scalar by MDiagArray2 ops.
68 
69 template <class T>
70 MDiagArray2<T>
71 operator * (const T& s, const MDiagArray2<T>& a)
72 {
73  return MDiagArray2<T> (do_sm_binary_op<T, T, T> (s, a, mx_inline_mul),
74  a.d1, a.d2);
75 }
76 
77 // Element by element MDiagArray2 by MDiagArray2 ops.
78 
79 #define MARRAY_DADA_OP(FCN, OP, FN) \
80  template <class T> \
81  MDiagArray2<T> \
82  FCN (const MDiagArray2<T>& a, const MDiagArray2<T>& b) \
83  { \
84  if (a.d1 != b.d1 || a.d2 != b.d2) \
85  gripe_nonconformant (#FCN, a.d1, a.d2, b.d1, b.d2); \
86  return MDiagArray2<T> (do_mm_binary_op<T, T, T> (a, b, FN, FN, FN, #FCN), a.d1, a.d2); \
87  }
88 
89 MARRAY_DADA_OP (operator +, +, mx_inline_add)
90 MARRAY_DADA_OP (operator -, -, mx_inline_sub)
92 
93 // Unary MDiagArray2 ops.
94 
95 template <class T>
96 MDiagArray2<T>
97 operator + (const MDiagArray2<T>& a)
98 {
99  return a;
100 }
101 
102 template <class T>
105 {
106  return MDiagArray2<T> (do_mx_unary_op<T, T> (a, mx_inline_uminus),
107  a.d1, a.d2);
108 }