GNU Octave  9.1.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-2024 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), \
63  a.m_d1, a.m_d2); \
64  }
65 
68 
69 // Element by element scalar by MDiagArray2 ops.
70 
71 template <typename T>
72 MDiagArray2<T>
73 operator * (const T& s, const MDiagArray2<T>& a)
74 {
75  return MDiagArray2<T> (do_sm_binary_op<T, T, T> (s, a, mx_inline_mul),
76  a.m_d1, a.m_d2);
77 }
78 
79 // Element by element MDiagArray2 by MDiagArray2 ops.
80 
81 #define MARRAY_DADA_OP(FCN, OP, FN) \
82  template <typename T> \
83  MDiagArray2<T> \
84  FCN (const MDiagArray2<T>& a, const MDiagArray2<T>& b) \
85  { \
86  if (a.m_d1 != b.m_d1 || a.m_d2 != b.m_d2) \
87  octave::err_nonconformant (#FCN, a.m_d1, a.m_d2, b.m_d1, b.m_d2); \
88  \
89  return MDiagArray2<T> (do_mm_binary_op<T, T, T> (a, b, FN, FN, FN, #FCN), \
90  a.m_d1, a.m_d2); \
91  }
92 
93 MARRAY_DADA_OP (operator +, +, mx_inline_add)
94 MARRAY_DADA_OP (operator -, -, mx_inline_sub)
96 
97 // Unary MDiagArray2 ops.
98 
99 template <typename T>
100 MDiagArray2<T>
101 operator + (const MDiagArray2<T>& a)
102 {
103  return a;
104 }
105 
106 template <typename T>
109 {
110  return MDiagArray2<T> (do_mx_unary_op<T, T> (a, mx_inline_uminus),
111  a.m_d1, a.m_d2);
112 }
#define MARRAY_DADA_OP(FCN, OP, FN)
Definition: MDiagArray2.cc:81
#define MARRAY_DAS_OP(OP, FN)
Definition: MDiagArray2.cc:57
MDiagArray2< T > operator-(const MDiagArray2< T > &a, const MDiagArray2< T > &b)
Definition: MDiagArray2.cc:94
MDiagArray2< T > product(const MDiagArray2< T > &a, const MDiagArray2< T > &b)
Definition: MDiagArray2.cc:95
octave_idx_type m_d1
Definition: DiagArray2.h:45
octave_idx_type m_d2
Definition: DiagArray2.h:45
Template for two dimensional diagonal array with math operators.
Definition: MDiagArray2.h:56
bool is_multiple_of_identity(T val) const
Definition: MDiagArray2.cc:36
void mx_inline_sub(std::size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:109
void mx_inline_uminus(std::size_t n, R *r, const X *x)
Definition: mx-inlines.cc:56
void mx_inline_div(std::size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:111
void mx_inline_add(std::size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:108
void mx_inline_mul(std::size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:110
F77_RET_T len
Definition: xerbla.cc:61