GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 // This file should not include config.h. It is only included in other
27 // C++ source files that should have included config.h before including
28 // this file.
29 
30 #include "MDiagArray2.h"
31 #include "Array-util.h"
32 #include "lo-error.h"
33 
34 template <typename 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 <typename 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 <typename 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 <typename 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  octave::err_nonconformant (#FCN, a.d1, a.d2, b.d1, b.d2); \
87  \
88  return MDiagArray2<T> (do_mm_binary_op<T, T, T> (a, b, FN, FN, FN, #FCN), a.d1, a.d2); \
89  }
90 
91 MARRAY_DADA_OP (operator +, +, mx_inline_add)
92 MARRAY_DADA_OP (operator -, -, mx_inline_sub)
94 
95 // Unary MDiagArray2 ops.
96 
97 template <typename T>
98 MDiagArray2<T>
99 operator + (const MDiagArray2<T>& a)
100 {
101  return a;
102 }
103 
104 template <typename T>
107 {
108  return MDiagArray2<T> (do_mx_unary_op<T, T> (a, mx_inline_uminus),
109  a.d1, a.d2);
110 }
#define MARRAY_DADA_OP(FCN, OP, FN)
Definition: MDiagArray2.cc:80
#define MARRAY_DAS_OP(OP, FN)
Definition: MDiagArray2.cc:57
MDiagArray2< T > operator-(const MDiagArray2< T > &a, const MDiagArray2< T > &b)
Definition: MDiagArray2.cc:92
MDiagArray2< T > product(const MDiagArray2< T > &a, const MDiagArray2< T > &b)
Definition: MDiagArray2.cc:93
octave_idx_type d1
Definition: DiagArray2.h:44
octave_idx_type d2
Definition: DiagArray2.h:44
Template for two dimensional diagonal array with math operators.
Definition: MDiagArray2.h:55
bool is_multiple_of_identity(T val) const
Definition: MDiagArray2.cc:36
void mx_inline_div(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:110
void mx_inline_uminus(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:55
void mx_inline_mul(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:109
void mx_inline_add(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:107
void mx_inline_sub(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:108
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
F77_RET_T len
Definition: xerbla.cc:61