annotate liboctave/array/intNDArray.cc @ 29358:0a5b15007766 stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021.
author John W. Eaton <jwe@octave.org>
date Wed, 10 Feb 2021 09:52:15 -0500
parents bd51beb6205e
children 7854d5752dd2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 // Copyright (C) 2004-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
25
21690
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21562
diff changeset
26 // This file should not include config.h. It is only included in other
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21562
diff changeset
27 // C++ source files that should have included config.h before including
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21562
diff changeset
28 // this file.
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
29
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
30 #include "Array-util.h"
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
31 #include "mx-base.h"
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
32 #include "lo-ieee.h"
8741
008f3985c8c0 use new summation code for native integer summation
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
33 #include "mx-inlines.cc"
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
34
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
35 // unary operations
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
36
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
37 template <typename T>
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
38 boolNDArray
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
39 intNDArray<T>::operator ! (void) const
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
40 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4915
diff changeset
41 boolNDArray b (this->dims ());
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
42
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
43 for (octave_idx_type i = 0; i < this->numel (); i++)
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4915
diff changeset
44 b.elem (i) = ! this->elem (i);
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
45
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
46 return b;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
47 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
48
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
49 template <typename T>
5943
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
50 bool
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
51 intNDArray<T>::any_element_not_one_or_zero (void) const
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
52 {
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
53 octave_idx_type nel = this->numel ();
5943
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
54
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
55 for (octave_idx_type i = 0; i < nel; i++)
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
56 {
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
57 T val = this->elem (i);
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
58
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
59 if (val != 0.0 && val != 1.0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
60 return true;
5943
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
61 }
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
62
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
63 return false;
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
64 }
c038c2947ee1 [project @ 2006-08-18 21:27:03 by jwe]
jwe
parents: 5775
diff changeset
65
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
66 template <typename T>
6979
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6482
diff changeset
67 intNDArray<T>
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6482
diff changeset
68 intNDArray<T>::diag (octave_idx_type k) const
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6482
diff changeset
69 {
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
70 return MArray<T>::diag (k);
6979
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6482
diff changeset
71 }
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6482
diff changeset
72
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
73 template <typename T>
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
74 intNDArray<T>
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
75 intNDArray<T>::diag (octave_idx_type m, octave_idx_type n) const
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
76 {
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
77 return MArray<T>::diag (m, n);
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
78 }
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
79
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
80 // FIXME: this is not quite the right thing.
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
81
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
82 template <typename T>
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
83 boolNDArray
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
84 intNDArray<T>::all (int dim) const
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
85 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
86 return do_mx_red_op<bool, T > (*this, dim, mx_inline_all);
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
87 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
88
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
89 template <typename T>
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
90 boolNDArray
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
91 intNDArray<T>::any (int dim) const
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
92 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
93 return do_mx_red_op<bool, T > (*this, dim, mx_inline_any);
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
94 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
95
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
96 template <typename T>
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
97 void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
98 intNDArray<T>::increment_index (Array<octave_idx_type>& ra_idx,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
99 const dim_vector& dimensions,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
100 int start_dimension)
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
101 {
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
102 ::increment_index (ra_idx, dimensions, start_dimension);
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
103 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
104
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
105 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
106 octave_idx_type
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
107 intNDArray<T>::compute_index (Array<octave_idx_type>& ra_idx,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
108 const dim_vector& dimensions)
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
109 {
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
110 return ::compute_index (ra_idx, dimensions);
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
111 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
112
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
113 template <typename T>
5073
e71be9c548f2 [project @ 2004-11-09 18:31:25 by jwe]
jwe
parents: 4932
diff changeset
114 intNDArray<T>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
115 intNDArray<T>::concat (const intNDArray<T>& rb,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
116 const Array<octave_idx_type>& ra_idx)
5073
e71be9c548f2 [project @ 2004-11-09 18:31:25 by jwe]
jwe
parents: 4932
diff changeset
117 {
6482
7e958a1532c6 [project @ 2007-04-04 02:37:07 by jwe]
jwe
parents: 5943
diff changeset
118 if (rb.numel () > 0)
5073
e71be9c548f2 [project @ 2004-11-09 18:31:25 by jwe]
jwe
parents: 4932
diff changeset
119 insert (rb, ra_idx);
e71be9c548f2 [project @ 2004-11-09 18:31:25 by jwe]
jwe
parents: 4932
diff changeset
120 return *this;
e71be9c548f2 [project @ 2004-11-09 18:31:25 by jwe]
jwe
parents: 4932
diff changeset
121 }
e71be9c548f2 [project @ 2004-11-09 18:31:25 by jwe]
jwe
parents: 4932
diff changeset
122
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
123 template <typename T>
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
124 intNDArray<T>&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
125 intNDArray<T>::insert (const intNDArray<T>& a, octave_idx_type r,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
126 octave_idx_type c)
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
127 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
128 Array<T>::insert (a, r, c);
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
129 return *this;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
130 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
131
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
132 template <typename T>
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
133 intNDArray<T>&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
134 intNDArray<T>::insert (const intNDArray<T>& a,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
135 const Array<octave_idx_type>& ra_idx)
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
136 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
137 Array<T>::insert (a, ra_idx);
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
138 return *this;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
139 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4902
diff changeset
140
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
141 // This contains no information on the array structure !!!
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
142
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
143 template <typename T>
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
144 std::ostream&
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
145 operator << (std::ostream& os, const intNDArray<T>& a)
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
146 {
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
147 octave_idx_type nel = a.numel ();
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
148
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
149 for (octave_idx_type i = 0; i < nel; i++)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23461
diff changeset
150 os << ' ' << a.elem (i) << "\n";
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
151
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
152 return os;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
153 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
154
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
155 template <typename T>
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
156 std::istream&
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
157 operator >> (std::istream& is, intNDArray<T>& a)
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
158 {
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
159 octave_idx_type nel = a.numel ();
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
160
8999
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
161 if (nel > 0)
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
162 {
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
163 T tmp;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
164
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
165 for (octave_idx_type i = 0; i < nel; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
166 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
167 is >> tmp;
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
168
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
169 if (is)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
170 a.elem (i) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
171 else
21169
40051830f89b maint: Replace more instances of goto in liboctave with other constructs.
Rik <rik@octave.org>
parents: 21139
diff changeset
172 return is;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
173 }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
174 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
175
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
176 return is;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
177 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
178
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
179 // FIXME: should abs and signum just be mapper functions?
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
180
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
181 template <typename T>
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
182 intNDArray<T>
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
183 intNDArray<T>::abs (void) const
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
184 {
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
185 octave_idx_type nel = this->numel ();
10577
87f879cf48fd don't alter arg values in call to abs or sign for integer values
John W. Eaton <jwe@octave.org>
parents: 10362
diff changeset
186 intNDArray<T> ret (this->dims ());
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
187
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
188 for (octave_idx_type i = 0; i < nel; i++)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
189 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
190 T val = this->elem (i);
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
191 ret.xelem (i) = val.abs ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
192 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
193
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
194 return ret;
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
195 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
196
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
197 template <typename T>
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
198 intNDArray<T>
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
199 intNDArray<T>::signum (void) const
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
200 {
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
201 octave_idx_type nel = this->numel ();
10577
87f879cf48fd don't alter arg values in call to abs or sign for integer values
John W. Eaton <jwe@octave.org>
parents: 10362
diff changeset
202 intNDArray<T> ret (this->dims ());
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
203
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
204 for (octave_idx_type i = 0; i < nel; i++)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
205 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
206 T val = this->elem (i);
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
207 ret.xelem (i) = val.signum ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
208 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
209
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
210 return ret;
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
211 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7457
diff changeset
212
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
213 template <typename T>
7113
a018c140f8aa [project @ 2007-11-07 00:28:01 by dbateman]
dbateman
parents: 7017
diff changeset
214 intNDArray<T>
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 17769
diff changeset
215 intNDArray<T>::prod (int dim) const
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 17769
diff changeset
216 {
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 17769
diff changeset
217 return do_mx_red_op<T, T> (*this, dim, mx_inline_prod);
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 17769
diff changeset
218 }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 17769
diff changeset
219
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
220 template <typename T>
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 17769
diff changeset
221 intNDArray<T>
7113
a018c140f8aa [project @ 2007-11-07 00:28:01 by dbateman]
dbateman
parents: 7017
diff changeset
222 intNDArray<T>::sum (int dim) const
a018c140f8aa [project @ 2007-11-07 00:28:01 by dbateman]
dbateman
parents: 7017
diff changeset
223 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
224 return do_mx_red_op<T, T> (*this, dim, mx_inline_sum);
7113
a018c140f8aa [project @ 2007-11-07 00:28:01 by dbateman]
dbateman
parents: 7017
diff changeset
225 }
a018c140f8aa [project @ 2007-11-07 00:28:01 by dbateman]
dbateman
parents: 7017
diff changeset
226
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
227 template <typename T>
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
228 NDArray
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
229 intNDArray<T>::dsum (int dim) const
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
230 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
231 return do_mx_red_op<double, T> (*this, dim, mx_inline_dsum);
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
232 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
233
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
234 template <typename T>
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
235 intNDArray<T>
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
236 intNDArray<T>::cumsum (int dim) const
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
237 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
238 return do_mx_cum_op<T, T> (*this, dim, mx_inline_cumsum);
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
239 }
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
240
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
241 template <typename T>
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
242 intNDArray<T>
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
243 intNDArray<T>::max (int dim) const
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
244 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
245 return do_mx_minmax_op<T> (*this, dim, mx_inline_max);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
246 }
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
247
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
248 template <typename T>
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
249 intNDArray<T>
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
250 intNDArray<T>::max (Array<octave_idx_type>& idx_arg, int dim) const
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
251 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
252 return do_mx_minmax_op<T> (*this, idx_arg, dim, mx_inline_max);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
253 }
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
254
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
255 template <typename T>
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
256 intNDArray<T>
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
257 intNDArray<T>::min (int dim) const
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
258 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
259 return do_mx_minmax_op<T> (*this, dim, mx_inline_min);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
260 }
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
261
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
262 template <typename T>
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
263 intNDArray<T>
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
264 intNDArray<T>::min (Array<octave_idx_type>& idx_arg, int dim) const
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
265 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
266 return do_mx_minmax_op<T> (*this, idx_arg, dim, mx_inline_min);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
267 }
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7113
diff changeset
268
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
269 template <typename T>
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
270 intNDArray<T>
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
271 intNDArray<T>::cummax (int dim) const
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
272 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
273 return do_mx_cumminmax_op<T> (*this, dim, mx_inline_cummax);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
274 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
275
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
276 template <typename T>
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
277 intNDArray<T>
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
278 intNDArray<T>::cummax (Array<octave_idx_type>& idx_arg, int dim) const
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
279 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
280 return do_mx_cumminmax_op<T> (*this, idx_arg, dim, mx_inline_cummax);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
281 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
282
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
283 template <typename T>
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
284 intNDArray<T>
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
285 intNDArray<T>::cummin (int dim) const
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
286 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
287 return do_mx_cumminmax_op<T> (*this, dim, mx_inline_cummin);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
288 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
289
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
290 template <typename T>
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
291 intNDArray<T>
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
292 intNDArray<T>::cummin (Array<octave_idx_type>& idx_arg, int dim) const
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
293 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
294 return do_mx_cumminmax_op<T> (*this, idx_arg, dim, mx_inline_cummin);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
295 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
296
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20232
diff changeset
297 template <typename T>
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9227
diff changeset
298 intNDArray<T>
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9227
diff changeset
299 intNDArray<T>::diff (octave_idx_type order, int dim) const
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9227
diff changeset
300 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
301 return do_mx_diff_op<T> (*this, dim, order, mx_inline_diff);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9227
diff changeset
302 }