Mercurial > hg > octave-nkf
annotate liboctave/oct-cmplx.h @ 14557:e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
* Array.h, Array.cc (Array<T>::diag (octave_idx_type, octave_idx_type)
const): New function.
* CMatrix.h, CMatrix.cc (ComplexMatrix::diag (octave_idx_type,
octave_idx_type) const): New function.
* dMatrix.h, dMatrix.cc (Matrix::diag (octave_idx_type,
octave_idx_type) const): New function.
* fCMatrix.h, fCMatrix.cc (FloatComplexMatrix::diag (octave_idx_type,
octave_idx_type) const): New function.
* fMatrix.h, fMatrix.cc (FloatMatrix::diag (octave_idx_type,
octave_idx_type) const): New function.
* CNDArray.cc, CNDArray.h (ComplexNDArray::diag (octave_idx_type,
octave_idx_type) const): New forwarding function.
* boolNDArray.cc, boolNDArray.h (boolNDArray::diag (octave_idx_type,
octave_idx_type) const): New forwarding function.
* chNDArray.cc, chNDArray.h (charNDArray::diag (octave_idx_type,
octave_idx_type) const): New forwarding function.
* dNDArray.cc, dNDArray.h (NDArray::diag (octave_idx_type,
octave_idx_type) const): New forwarding function.
* fCNDArray.cc, fCNDArray.h (FloatComplexNDArray::diag
(octave_idx_type, octave_idx_type) const): New forwarding function.
* fNDArray.cc, fNDArray.h (FloatNDArray::diag (octave_idx_type,
octave_idx_type) const): New forwarding function.
* intNDArray.cc, intNDArray.h (intNDArray<T>::diag (octave_idx_type,
octave_idx_type) const): New forwarding function.
* Cell.cc, Cell.h (Cell::diag (octave_idx_type, octave_idx_type)
const): New function.
* ov.h (octave_value::diag (octave_idx_type, octave_idx_type)):
New function.
* ov-base.h, ov-base.cc (octave_base_value::diag (octave_idx_type,
octave_idx_type) const): New virtual function and default implementation.
* ov-base-mat.h (octave_base_matrix<T>::diag (octave_idx_type,
octave_idx_type) const): New function.
* ov-base-scalar.cc, ov-base-scalar.h (octave_base_scalar<T>::diag
(octave_idx_type, octave_idx_type)): New function.
* ov-complex.cc, ov-complex.h (octave_complex::diag (octave_idx_type,
octave_idx_type) const): New function.
* ov-cx-mat.cc, ov-complex.h (octave_complex_matrix::diag
(octave_idx_type, octave_idx_type) const): New function.
* ov-float.cc, ov-float.h (octave_float_scalar::diag (octave_idx_type,
octave_idx_type) const): New function.
* ov-flt-complex.cc, ov-flt-complex.h (octave_float_complex::diag
(octave_idx_type, octave_idx_type) const): New function.
* ov-flt-cx-mat.cc, ov-flt-cx-mat.h (octave_float_complex_matrix::diag
(octave_idx_type, octave_idx_type) const): New function.
* ov-flt-re-mat.cc, ov-flt-re-mat.h (octave_float_matrix::diag
(octave_idx_type, octave_idx_type) const): New function.
* ov-range.cc, ov-range.h (octave_range::diag (octave_idx_type,
octave_idx_type) const): New function.
* ov-re-mat.cc, ov-re-mat.h (octave_matrix::diag (octave_idx_type,
octave_idx_type) const): New function.
* ov-scalar.cc, ov-scalar.h (octave_scalar::diag (octave_idx_type,
octave_idx_type) const): New function.
* data.cc (Fdiag): Use two-arg octave_value::diag method for
dispatching. New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 12 Apr 2012 16:27:39 -0400 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
1648 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3 Copyright (C) 1995-2012 John W. Eaton |
9603
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague, a.s. |
1648 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1648 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1648 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_oct_cmplx_h) | |
25 #define octave_oct_cmplx_h 1 | |
26 | |
27 #include <complex> | |
28 | |
3504 | 29 typedef std::complex<double> Complex; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
30 typedef std::complex<float> FloatComplex; |
1648 | 31 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
32 // For complex-complex and complex-real comparisons, we use the following ordering: |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
33 // compare absolute values first; if they match, compare phase angles. |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
34 // This is partially inconsistent with M*b, which compares complex numbers only |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
35 // by their real parts; OTOH, it uses the same definition for max/min and sort. |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
36 // The abs/arg comparison is definitely more useful (the other one is emulated rather |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
37 // trivially), so let's be consistent and use that all over. |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
38 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
39 #define DEF_COMPLEXR_COMP(OP, OPS) \ |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
40 template <class T> \ |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
41 inline bool operator OP (const std::complex<T>& a, const std::complex<T>& b) \ |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
42 { \ |
9603
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
43 FLOAT_TRUNCATE const T ax = std::abs (a), bx = std::abs (b); \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
44 if (ax == bx) \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
45 { \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
46 FLOAT_TRUNCATE const T ay = std::arg (a), by = std::arg (b); \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
47 return ay OP by; \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
48 } \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
49 else \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
50 return ax OPS bx; \ |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
51 } \ |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
52 template <class T> \ |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
53 inline bool operator OP (const std::complex<T>& a, T b) \ |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
54 { \ |
9667
641a788c82a4
fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
9603
diff
changeset
|
55 FLOAT_TRUNCATE const T ax = std::abs (a), bx = std::abs (b); \ |
641a788c82a4
fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
9603
diff
changeset
|
56 if (ax == bx) \ |
9603
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
57 { \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
58 FLOAT_TRUNCATE const T ay = std::arg (a); \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
59 return ay OP 0; \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
60 } \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
61 else \ |
9667
641a788c82a4
fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
9603
diff
changeset
|
62 return ax OPS bx; \ |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
63 } \ |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
64 template <class T> \ |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
65 inline bool operator OP (T a, const std::complex<T>& b) \ |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
66 { \ |
9667
641a788c82a4
fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
9603
diff
changeset
|
67 FLOAT_TRUNCATE const T ax = std::abs (a), bx = std::abs (b); \ |
641a788c82a4
fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
9603
diff
changeset
|
68 if (ax == bx) \ |
9603
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
69 { \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
70 FLOAT_TRUNCATE const T by = std::arg (b); \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
71 return 0 OP by; \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
72 } \ |
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
73 else \ |
9667
641a788c82a4
fix complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
9603
diff
changeset
|
74 return ax OPS bx; \ |
9603
8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
Jaroslav Hajek <highegg@gmail.com>
parents:
9594
diff
changeset
|
75 } |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
76 |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
77 DEF_COMPLEXR_COMP (>, >) |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
78 DEF_COMPLEXR_COMP (<, <) |
9594
01004c3cde2c
fix non-strict complex comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
9578
diff
changeset
|
79 DEF_COMPLEXR_COMP (<=, <) |
01004c3cde2c
fix non-strict complex comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
9578
diff
changeset
|
80 DEF_COMPLEXR_COMP (>=, >) |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
81 |
1648 | 82 #endif |