GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-fm-fm.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2023 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 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "errwarn.h"
31 #include "ovl.h"
32 #include "ov.h"
33 #include "ov-re-mat.h"
34 #include "ov-flt-re-mat.h"
35 #include "ov-typeinfo.h"
36 #include "ov-null-mat.h"
37 #include "ops.h"
38 #include "xdiv.h"
39 #include "xpow.h"
40 
42 
43 // matrix unary ops.
44 
45 DEFNDUNOP_OP (not, float_matrix, float_array, !)
46 DEFNDUNOP_OP (uplus, float_matrix, float_array, /* no-op */)
47 DEFNDUNOP_OP (uminus, float_matrix, float_array, -)
48 
49 DEFUNOP (transpose, float_matrix)
50 {
51  const octave_float_matrix& v = dynamic_cast<const octave_float_matrix&> (a);
52 
53  if (v.ndims () > 2)
54  error ("transpose not defined for N-D objects");
55 
56  return octave_value (v.float_matrix_value ().transpose ());
57 }
58 
59 DEFNCUNOP_METHOD (incr, float_matrix, increment)
60 DEFNCUNOP_METHOD (decr, float_matrix, decrement)
61 DEFNCUNOP_METHOD (changesign, float_matrix, changesign)
62 
63 // matrix by matrix ops.
64 
65 DEFNDBINOP_OP (add, float_matrix, float_matrix, float_array, float_array, +)
66 DEFNDBINOP_OP (sub, float_matrix, float_matrix, float_array, float_array, -)
67 
68 DEFBINOP_OP (mul, float_matrix, float_matrix, *)
69 
70 DEFBINOP (div, float_matrix, float_matrix)
71 {
72  const octave_float_matrix& v1 = dynamic_cast<const octave_float_matrix&> (a1);
73  const octave_float_matrix& v2 = dynamic_cast<const octave_float_matrix&> (a2);
74  MatrixType typ = v2.matrix_type ();
75 
76  FloatMatrix ret = xdiv (v1.float_matrix_value (),
77  v2.float_matrix_value (), typ);
78 
79  v2.matrix_type (typ);
80  return ret;
81 }
82 
83 DEFBINOPX (pow, float_matrix, float_matrix)
84 {
85  error ("can't do A ^ B for A and B both matrices");
86 }
87 
88 DEFBINOP (ldiv, float_matrix, float_matrix)
89 {
90  const octave_float_matrix& v1 = dynamic_cast<const octave_float_matrix&> (a1);
91  const octave_float_matrix& v2 = dynamic_cast<const octave_float_matrix&> (a2);
92  MatrixType typ = v1.matrix_type ();
93 
95  v2.float_matrix_value (), typ);
96 
97  v1.matrix_type (typ);
98  return ret;
99 }
100 
101 DEFBINOP (trans_mul, float_matrix, float_matrix)
102 {
103  const octave_float_matrix& v1 = dynamic_cast<const octave_float_matrix&> (a1);
104  const octave_float_matrix& v2 = dynamic_cast<const octave_float_matrix&> (a2);
105  return octave_value(xgemm (v1.float_matrix_value (),
108 }
109 
110 DEFBINOP (mul_trans, float_matrix, float_matrix)
111 {
112  const octave_float_matrix& v1 = dynamic_cast<const octave_float_matrix&> (a1);
113  const octave_float_matrix& v2 = dynamic_cast<const octave_float_matrix&> (a2);
114  return octave_value(xgemm (v1.float_matrix_value (),
117 }
118 
119 DEFBINOP (trans_ldiv, float_matrix, float_matrix)
120 {
121  const octave_float_matrix& v1 = dynamic_cast<const octave_float_matrix&> (a1);
122  const octave_float_matrix& v2 = dynamic_cast<const octave_float_matrix&> (a2);
123  MatrixType typ = v1.matrix_type ();
124 
126  v2.float_matrix_value (), typ, blas_trans);
127 
128  v1.matrix_type (typ);
129  return ret;
130 }
131 
132 DEFNDBINOP_FN (lt, float_matrix, float_matrix, float_array,
133  float_array, mx_el_lt)
134 DEFNDBINOP_FN (le, float_matrix, float_matrix, float_array,
135  float_array, mx_el_le)
136 DEFNDBINOP_FN (eq, float_matrix, float_matrix, float_array,
137  float_array, mx_el_eq)
138 DEFNDBINOP_FN (ge, float_matrix, float_matrix, float_array,
139  float_array, mx_el_ge)
140 DEFNDBINOP_FN (gt, float_matrix, float_matrix, float_array,
141  float_array, mx_el_gt)
142 DEFNDBINOP_FN (ne, float_matrix, float_matrix, float_array,
143  float_array, mx_el_ne)
144 
145 DEFNDBINOP_FN (el_mul, float_matrix, float_matrix, float_array,
146  float_array, product)
147 DEFNDBINOP_FN (el_div, float_matrix, float_matrix, float_array,
148  float_array, quotient)
149 DEFNDBINOP_FN (el_pow, float_matrix, float_matrix, float_array,
150  float_array, elem_xpow)
151 
152 DEFBINOP (el_ldiv, float_matrix, float_matrix)
153 {
154  const octave_float_matrix& v1 = dynamic_cast<const octave_float_matrix&> (a1);
155  const octave_float_matrix& v2 = dynamic_cast<const octave_float_matrix&> (a2);
156 
158  v1.float_array_value ()));
159 }
160 
161 DEFNDBINOP_FN (el_and, float_matrix, float_matrix, float_array,
162  float_array, mx_el_and)
163 DEFNDBINOP_FN (el_or, float_matrix, float_matrix, float_array,
164  float_array, mx_el_or)
165 DEFNDBINOP_FN (el_not_and, float_matrix, float_matrix, float_array,
166  float_array, mx_el_not_and)
167 DEFNDBINOP_FN (el_not_or, float_matrix, float_matrix, float_array,
168  float_array, mx_el_not_or)
169 DEFNDBINOP_FN (el_and_not, float_matrix, float_matrix, float_array,
170  float_array, mx_el_and_not)
171 DEFNDBINOP_FN (el_or_not, float_matrix, float_matrix, float_array,
172  float_array, mx_el_or_not)
173 
174 DEFNDCATOP_FN (fm_fm, float_matrix, float_matrix, float_array,
175  float_array, concat)
176 
177 DEFNDCATOP_FN (m_fm, matrix, float_matrix, float_array, float_array, concat)
178 
179 DEFNDCATOP_FN (fm_m, float_matrix, matrix, float_array, float_array, concat)
180 
181 DEFNDASSIGNOP_FN (assign, float_matrix, float_matrix, float_array, assign)
182 
183 DEFNDASSIGNOP_FN (dbl_assign, matrix, float_matrix, array, assign)
184 
185 DEFNULLASSIGNOP_FN (null_assign, float_matrix, delete_elements)
186 
187 DEFNDASSIGNOP_OP (assign_add, float_matrix, float_matrix, float_array, +=)
188 DEFNDASSIGNOP_OP (assign_sub, float_matrix, float_matrix, float_array, -=)
189 DEFNDASSIGNOP_FNOP (assign_el_mul, float_matrix, float_matrix, float_array,
191 DEFNDASSIGNOP_FNOP (assign_el_div, float_matrix, float_matrix, float_array,
193 
194 void
196 {
202 
203  INSTALL_NCUNOP_TI (ti, op_incr, octave_float_matrix, incr);
204  INSTALL_NCUNOP_TI (ti, op_decr, octave_float_matrix, decr);
206 
220  el_mul);
222  el_div);
224  el_pow);
226  el_ldiv);
228  el_and);
230  el_or);
232  el_and_not);
234  el_or_not);
236  el_not_and);
238  el_not_or);
240  trans_mul);
242  mul_trans);
244  trans_mul);
246  mul_trans);
248  trans_ldiv);
250  trans_ldiv);
251 
255 
257  octave_float_matrix, assign);
258  INSTALL_ASSIGNOP_TI (ti, op_asn_eq, octave_matrix,
259  octave_float_matrix, dbl_assign);
260 
262  null_assign);
264  null_assign);
266  null_assign);
267 
269  assign_add);
271  assign_sub);
273  assign_el_mul);
275  assign_el_div);
276 }
277 
OCTAVE_END_NAMESPACE(octave)
ComplexColumnVector quotient(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:156
ComplexColumnVector product_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:156
ComplexColumnVector product(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:156
ComplexColumnVector quotient_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:156
ComplexMatrix xgemm(const ComplexMatrix &a, const ComplexMatrix &b, blas_trans_type transa, blas_trans_type transb)
Definition: CMatrix.cc:3346
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:418
ComplexMatrix mul_trans(const ComplexMatrix &m, const SparseComplexMatrix &a)
Definition: CSparse.cc:7511
ComplexMatrix trans_mul(const SparseComplexMatrix &m, const ComplexMatrix &a)
Definition: CSparse.cc:7541
boolMatrix mx_el_le(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_or(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:88
boolMatrix mx_el_and(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:88
boolMatrix mx_el_gt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_eq(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_lt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_ge(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolNDArray mx_el_or_not(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:122
boolNDArray mx_el_and_not(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:122
boolNDArray mx_el_not_and(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:122
boolNDArray mx_el_not_or(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:122
FloatMatrix transpose(void) const
Definition: fMatrix.h:140
MatrixType matrix_type(void) const
Definition: ov-base-mat.h:136
int ndims(void) const
Definition: ov-base-mat.h:121
FloatNDArray float_array_value(bool=false) const
Definition: ov-ch-mat.h:123
FloatMatrix float_matrix_value(bool=false) const
Definition: ov-ch-mat.h:117
FloatNDArray float_array_value(bool=false) const
FloatMatrix float_matrix_value(bool=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition: error.cc:979
@ blas_no_trans
Definition: mx-defs.h:81
@ blas_trans
Definition: mx-defs.h:82
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
void install_fm_fm_ops(octave::type_info &ti)
Definition: op-fm-fm.cc:195
const octave_base_value & a2
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
const octave_char_matrix & v2
#define DEFNDASSIGNOP_FN(name, t1, t2, e, f)
Definition: ops.h:112
#define DEFNDBINOP_OP(name, t1, t2, e1, e2, op)
Definition: ops.h:276
#define INSTALL_NCUNOP_TI(ti, op, t, f)
Definition: ops.h:51
#define DEFNULLASSIGNOP_FN(name, t, f)
Definition: ops.h:100
#define DEFNDBINOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:301
#define DEFBINOPX(name, t1, t2)
Definition: ops.h:225
#define DEFNDASSIGNOP_FNOP(name, t1, t2, f, fnop)
Definition: ops.h:141
#define DEFBINOP(name, t1, t2)
Definition: ops.h:230
#define DEFNDUNOP_OP(name, t, e, op)
Definition: ops.h:191
#define DEFBINOP_OP(name, t1, t2, op)
Definition: ops.h:235
#define DEFNCUNOP_METHOD(name, t, method)
Definition: ops.h:217
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:55
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:349
#define DEFUNOP(name, t)
Definition: ops.h:179
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:60
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:47
#define DEFNDASSIGNOP_OP(name, t1, t2, f, op)
Definition: ops.h:126
#define INSTALL_ASSIGNOP_TI(ti, op, t1, t2, f)
Definition: ops.h:64
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1881
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1886
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1839
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1868
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1880
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1840
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1884
octave_value op_mul_herm(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1902
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1842
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1888
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1869
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1870
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1843
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1877
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1887
octave_value op_herm_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1901
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1878
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1885
octave_value op_not(const octave_value &a)
Definition: ov.h:1838
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1874
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1873
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1879
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1883
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1871
octave_value op_trans_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1899
octave_value op_mul_trans(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1900
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1876
Matrix xdiv(const Matrix &a, const SparseMatrix &b, MatrixType &typ)
Definition: sparse-xdiv.cc:137
Matrix xleftdiv(const SparseMatrix &a, const Matrix &b, MatrixType &typ)
Definition: sparse-xdiv.cc:468
octave_value elem_xpow(double a, const SparseMatrix &b)
Definition: sparse-xpow.cc:347
static void transpose(octave_idx_type N, const octave_idx_type *ridx, const octave_idx_type *cidx, octave_idx_type *ridx2, octave_idx_type *cidx2)
Definition: symrcm.cc:391