annotate liboctave/array/chMatrix.cc @ 23219:3ac9f9ecfae5 stable

maint: Update copyright dates.
author John W. Eaton <jwe@octave.org>
date Wed, 22 Feb 2017 12:39:29 -0500
parents e9a0469dedd9
children 092078913d54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1993
1b57120c997b [project @ 1996-03-03 01:16:15 by jwe]
jwe
parents: 1948
diff changeset
1 // Matrix manipulations.
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
2 /*
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
3
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
4 Copyright (C) 1995-2017 John W. Eaton
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10362
diff changeset
5 Copyright (C) 2010 VZLU Prague
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
6
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
8
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6979
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6979
diff changeset
12 option) any later version.
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
13
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
17 for more details.
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
18
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6979
diff changeset
20 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6979
diff changeset
21 <http://www.gnu.org/licenses/>.
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
22
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
23 */
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
24
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
25 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
26 # include "config.h"
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
27 #endif
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
28
7048
845ca0affec0 [project @ 2007-10-22 16:55:41 by jwe]
jwe
parents: 7017
diff changeset
29 #include <cstring>
845ca0affec0 [project @ 2007-10-22 16:55:41 by jwe]
jwe
parents: 7017
diff changeset
30
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3225
diff changeset
31 #include <iostream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1573
diff changeset
32 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1573
diff changeset
33
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
34 #include "lo-error.h"
2349
b369227ce3d2 [project @ 1996-07-27 07:59:20 by jwe]
jwe
parents: 2255
diff changeset
35 #include "str-vec.h"
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
36 #include "mx-base.h"
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
37 #include "mx-inlines.cc"
8774
b756ce0002db split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents: 8750
diff changeset
38 #include "mx-op-defs.h"
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
39
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
40 // charMatrix class.
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
41
2384
d9147efd1a93 [project @ 1996-10-12 17:56:38 by jwe]
jwe
parents: 2350
diff changeset
42 bool
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
43 charMatrix::operator == (const charMatrix& a) const
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
44 {
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
45 if (rows () != a.rows () || cols () != a.cols ())
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
46 return 0;
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
47
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
48 return mx_inline_equal (numel (), data (), a.data ());
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
49 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
50
2384
d9147efd1a93 [project @ 1996-10-12 17:56:38 by jwe]
jwe
parents: 2350
diff changeset
51 bool
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
52 charMatrix::operator != (const charMatrix& a) const
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
53 {
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
54 return !(*this == a);
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
55 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
56
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
57 charMatrix&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
58 charMatrix::insert (const char *s, octave_idx_type r, octave_idx_type c)
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
59 {
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
60 if (s)
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
61 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
62 octave_idx_type s_len = strlen (s);
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
63
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
64 if (r < 0 || r >= rows () || c < 0 || c + s_len - 1 > cols ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20232
diff changeset
65 (*current_liboctave_error_handler) ("range error for insert");
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
66
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
67 for (octave_idx_type i = 0; i < s_len; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
68 elem (r, c+i) = s[i];
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
69 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
70 return *this;
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
71 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
72
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
73 charMatrix&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
74 charMatrix::insert (const charMatrix& a, octave_idx_type r, octave_idx_type c)
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
75 {
10351
5150ceb4dbb4 base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
76 Array<char>::insert (a, r, c);
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
77 return *this;
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
78 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
79
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
80 std::string
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
81 charMatrix::row_as_string (octave_idx_type r, bool strip_ws) const
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
82 {
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
83 std::string retval;
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
84
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
85 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
86 octave_idx_type nc = cols ();
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
87
14012
4faef552363d charMatrix::row_as_string: return early if r is 0 and either nr or nc is 0
John W. Eaton <jwe@octave.org>
parents: 12959
diff changeset
88 if (r == 0 && (nr == 0 || nc == 0))
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
89 return retval;
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
90
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
91 if (r < 0 || r >= nr)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20232
diff changeset
92 (*current_liboctave_error_handler) ("range error for row_as_string");
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
93
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
94 retval.resize (nc, '\0');
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
95
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
96 for (octave_idx_type i = 0; i < nc; i++)
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
97 retval[i] = elem (r, i);
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
98
11265
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
99 if (strip_ws)
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents: 2384
diff changeset
100 {
11265
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
101 while (--nc >= 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
102 {
11265
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
103 char c = retval[nc];
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
104 if (c && c != ' ')
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
105 break;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
106 }
3836
b8c1cb5b9fd9 [project @ 2001-05-31 19:30:49 by jwe]
jwe
parents: 3769
diff changeset
107
b8c1cb5b9fd9 [project @ 2001-05-31 19:30:49 by jwe]
jwe
parents: 3769
diff changeset
108 retval.resize (nc+1);
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents: 2384
diff changeset
109 }
1780
6101360af703 [project @ 1996-01-24 07:55:06 by jwe]
jwe
parents: 1733
diff changeset
110
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
111 return retval;
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
112 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
113
2255
fb9611cfc9d2 [project @ 1996-05-22 19:31:32 by jwe]
jwe
parents: 1993
diff changeset
114 charMatrix
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
115 charMatrix::extract (octave_idx_type r1, octave_idx_type c1,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
116 octave_idx_type r2, octave_idx_type c2) const
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
117 {
17663
7975d75f933c Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents: 15271
diff changeset
118 if (r1 > r2) { std::swap (r1, r2); }
7975d75f933c Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents: 15271
diff changeset
119 if (c1 > c2) { std::swap (c1, c2); }
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
120
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
121 octave_idx_type new_r = r2 - r1 + 1;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
122 octave_idx_type new_c = c2 - c1 + 1;
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
123
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
124 charMatrix result (new_r, new_c);
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
125
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
126 for (octave_idx_type j = 0; j < new_c; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
127 for (octave_idx_type i = 0; i < new_r; i++)
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
128 result.elem (i, j) = elem (r1+i, c1+j);
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
129
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
130 return result;
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
131 }
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
132
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
133 MS_CMP_OPS (charMatrix, char)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9370
diff changeset
134 MS_BOOL_OPS (charMatrix, char)
6456
7f5316cadaa2 [project @ 2007-03-26 16:18:26 by jwe]
jwe
parents: 5775
diff changeset
135
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
136 SM_CMP_OPS (char, charMatrix)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9370
diff changeset
137 SM_BOOL_OPS (char, charMatrix)
6456
7f5316cadaa2 [project @ 2007-03-26 16:18:26 by jwe]
jwe
parents: 5775
diff changeset
138
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
139 MM_CMP_OPS (charMatrix, charMatrix)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9370
diff changeset
140 MM_BOOL_OPS (charMatrix, charMatrix)