GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
MDiagArray2.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 // This file should not include config.h. It is only included in other
25 // C++ source files that should have included config.h before including
26 // this file.
27 
28 #include "MDiagArray2.h"
29 #include "Array-util.h"
30 #include "lo-error.h"
31 
32 template <typename T>
33 bool
35 {
36  bool retval = this->rows () == this->cols ();
37  if (retval)
38  {
39  octave_idx_type len = this->length ();
40  octave_idx_type i = 0;
41  for (; i < len; i++)
42  if (DiagArray2<T>::elem (i, i) != val) break;
43  retval = i == len;
44  }
45 
46  return retval;
47 }
48 
49 // Two dimensional diagonal array with math ops.
50 
51 // Element by element MDiagArray2 by MDiagArray2 ops.
52 
53 // Element by element MDiagArray2 by scalar ops.
54 
55 #define MARRAY_DAS_OP(OP, FN) \
56  template <typename T> \
57  MDiagArray2<T> \
58  operator OP (const MDiagArray2<T>& a, const T& s) \
59  { \
60  return MDiagArray2<T> (do_ms_binary_op<T, T, T> (a, s, FN), a.d1, a.d2); \
61  }
62 
65 
66 // Element by element scalar by MDiagArray2 ops.
67 
68 template <typename T>
69 MDiagArray2<T>
70 operator * (const T& s, const MDiagArray2<T>& a)
71 {
72  return MDiagArray2<T> (do_sm_binary_op<T, T, T> (s, a, mx_inline_mul),
73  a.d1, a.d2);
74 }
75 
76 // Element by element MDiagArray2 by MDiagArray2 ops.
77 
78 #define MARRAY_DADA_OP(FCN, OP, FN) \
79  template <typename T> \
80  MDiagArray2<T> \
81  FCN (const MDiagArray2<T>& a, const MDiagArray2<T>& b) \
82  { \
83  if (a.d1 != b.d1 || a.d2 != b.d2) \
84  octave::err_nonconformant (#FCN, a.d1, a.d2, b.d1, b.d2); \
85  \
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 <typename T>
96 MDiagArray2<T>
97 operator + (const MDiagArray2<T>& a)
98 {
99  return a;
100 }
101 
102 template <typename T>
105 {
106  return MDiagArray2<T> (do_mx_unary_op<T, T> (a, mx_inline_uminus),
107  a.d1, a.d2);
108 }
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
bool is_multiple_of_identity(T val) const
Definition: MDiagArray2.cc:34
#define MARRAY_DADA_OP(FCN, OP, FN)
Definition: MDiagArray2.cc:78
s
Definition: file-io.cc:2729
void mx_inline_mul(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:108
Template for two dimensional diagonal array with math operators.
Definition: MDiagArray2.h:32
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
MDiagArray2< T > operator-(const MDiagArray2< T > &a, const MDiagArray2< T > &b)
Definition: MDiagArray2.cc:90
void mx_inline_sub(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:107
void mx_inline_uminus(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:54
octave_value retval
Definition: data.cc:6246
octave_idx_type cols(void) const
Definition: Sparse.h:259
#define MARRAY_DAS_OP(OP, FN)
Definition: MDiagArray2.cc:55
for i
Definition: data.cc:5264
void mx_inline_add(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:106
void mx_inline_div(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:109
MDiagArray2< T > product(const MDiagArray2< T > &a, const MDiagArray2< T > &b)
Definition: MDiagArray2.cc:91
octave_idx_type rows(void) const
Definition: Sparse.h:258