GNU Octave  4.0.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-2015 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 ();
42  octave_idx_type i = 0;
43  for (; i < len; i++)
44  if (DiagArray2<T>::elem (i, i) != val) break;
45  retval = i == len;
46  }
47 
48  return retval;
49 }
50 
51 // Two dimensional diagonal array with math ops.
52 
53 // Element by element MDiagArray2 by MDiagArray2 ops.
54 
55 // Element by element MDiagArray2 by scalar ops.
56 
57 #define MARRAY_DAS_OP(OP, FN) \
58  template <class T> \
59  MDiagArray2<T> \
60  operator OP (const MDiagArray2<T>& a, const T& s) \
61  { \
62  return MDiagArray2<T> (do_ms_binary_op<T, T, T> (a, s, FN), a.d1, a.d2); \
63  }
64 
67 
68 // Element by element scalar by MDiagArray2 ops.
69 
70 template <class T>
71 MDiagArray2<T>
72 operator * (const T& s, const MDiagArray2<T>& a)
73 {
74  return MDiagArray2<T> (do_sm_binary_op<T, T, T> (s, a, mx_inline_mul),
75  a.d1, a.d2);
76 }
77 
78 // Element by element MDiagArray2 by MDiagArray2 ops.
79 
80 #define MARRAY_DADA_OP(FCN, OP, FN) \
81  template <class T> \
82  MDiagArray2<T> \
83  FCN (const MDiagArray2<T>& a, const MDiagArray2<T>& b) \
84  { \
85  if (a.d1 != b.d1 || a.d2 != b.d2) \
86  gripe_nonconformant (#FCN, a.d1, a.d2, b.d1, b.d2); \
87  return MDiagArray2<T> (do_mm_binary_op<T, T, T> (a, b, FN, FN, FN, #FCN), a.d1, a.d2); \
88  }
89 
90 MARRAY_DADA_OP (operator +, +, mx_inline_add)
91 MARRAY_DADA_OP (operator -, -, mx_inline_sub)
93 
94 // Unary MDiagArray2 ops.
95 
96 template <class T>
97 MDiagArray2<T>
98 operator + (const MDiagArray2<T>& a)
99 {
100  return a;
101 }
102 
103 template <class T>
106 {
107  return MDiagArray2<T> (do_mx_unary_op<T, T> (a, mx_inline_uminus),
108  a.d1, a.d2);
109 }
octave_idx_type cols(void) const
Definition: Sparse.h:264
octave_idx_type rows(void) const
Definition: Sparse.h:263
#define MARRAY_DADA_OP(FCN, OP, FN)
Definition: MDiagArray2.cc:80
void mx_inline_mul(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:84
MDiagArray2< T > operator-(const MDiagArray2< T > &a, const MDiagArray2< T > &b)
Definition: MDiagArray2.cc:91
void mx_inline_sub(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:83
void mx_inline_uminus(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:54
octave_idx_type d1
Definition: DiagArray2.h:42
octave_idx_type d2
Definition: DiagArray2.h:42
#define MARRAY_DAS_OP(OP, FN)
Definition: MDiagArray2.cc:57
bool is_multiple_of_identity(T val) const
Definition: MDiagArray2.cc:36
void mx_inline_add(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:82
void mx_inline_div(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:85
MDiagArray2< T > product(const MDiagArray2< T > &a, const MDiagArray2< T > &b)
Definition: MDiagArray2.cc:92