Mercurial > hg > octave-nkf
comparison liboctave/idx-vector.cc @ 2500:e39839e18edc
[project @ 1996-11-12 17:13:53 by jwe]
author | jwe |
---|---|
date | Tue, 12 Nov 1996 17:13:53 +0000 |
parents | 4fc9fd1424a9 |
children | f8d5dbbbc50a |
comparison
equal
deleted
inserted
replaced
2499:20db7604d5c6 | 2500:e39839e18edc |
---|---|
36 #include "dColVector.h" | 36 #include "dColVector.h" |
37 #include "dMatrix.h" | 37 #include "dMatrix.h" |
38 | 38 |
39 #include "idx-vector.h" | 39 #include "idx-vector.h" |
40 #include "lo-error.h" | 40 #include "lo-error.h" |
41 #include "lo-mappers.h" | |
41 | 42 |
42 #define IDX_VEC_REP idx_vector::idx_vector_rep | 43 #define IDX_VEC_REP idx_vector::idx_vector_rep |
43 | 44 |
44 IDX_VEC_REP::idx_vector_rep (const IDX_VEC_REP& a) | 45 IDX_VEC_REP::idx_vector_rep (const IDX_VEC_REP& a) |
45 { | 46 { |
71 } | 72 } |
72 | 73 |
73 static inline int | 74 static inline int |
74 tree_to_mat_idx (double x) | 75 tree_to_mat_idx (double x) |
75 { | 76 { |
76 if (x > 0) | 77 return (x > 0) ? ((int) (x + 0.5) - 1) : ((int) (x - 0.5) - 1); |
77 return ((int) (x + 0.5) - 1); | 78 } |
78 else | 79 |
79 return ((int) (x - 0.5) - 1); | 80 static inline bool |
81 idx_is_inf_or_nan (double x) | |
82 { | |
83 bool retval = false; | |
84 | |
85 if (xisnan (x)) | |
86 { | |
87 (*current_liboctave_error_handler) ("NaN invalid as index"); | |
88 retval = true; | |
89 } | |
90 else if (xisinf (x)) | |
91 { | |
92 (*current_liboctave_error_handler) ("Inf invalid as index"); | |
93 retval = true; | |
94 } | |
95 | |
96 return retval; | |
80 } | 97 } |
81 | 98 |
82 IDX_VEC_REP::idx_vector_rep (const ColumnVector& v) | 99 IDX_VEC_REP::idx_vector_rep (const ColumnVector& v) |
83 { | 100 { |
84 data = 0; | 101 data = 0; |
104 return; | 121 return; |
105 } | 122 } |
106 else | 123 else |
107 { | 124 { |
108 data = new int [len]; | 125 data = new int [len]; |
126 | |
109 for (int i = 0; i < len; i++) | 127 for (int i = 0; i < len; i++) |
110 data[i] = tree_to_mat_idx (v.elem (i)); | 128 { |
129 double d = v.elem (i); | |
130 | |
131 if (idx_is_inf_or_nan (d)) | |
132 return; | |
133 else | |
134 data[i] = tree_to_mat_idx (d); | |
135 } | |
111 } | 136 } |
112 | 137 |
113 init_state (); | 138 init_state (); |
114 } | 139 } |
115 | 140 |
139 } | 164 } |
140 else | 165 else |
141 { | 166 { |
142 int k = 0; | 167 int k = 0; |
143 data = new int [len]; | 168 data = new int [len]; |
169 | |
144 for (int j = 0; j < orig_nc; j++) | 170 for (int j = 0; j < orig_nc; j++) |
145 for (int i = 0; i < orig_nr; i++) | 171 for (int i = 0; i < orig_nr; i++) |
146 data[k++] = tree_to_mat_idx (m.elem (i, j)); | 172 { |
173 double d = m.elem (i, j); | |
174 | |
175 if (idx_is_inf_or_nan (d)) | |
176 return; | |
177 else | |
178 data[k++] = tree_to_mat_idx (d); | |
179 } | |
147 } | 180 } |
148 | 181 |
149 init_state (); | 182 init_state (); |
150 } | 183 } |
151 | 184 |
161 len = 1; | 194 len = 1; |
162 | 195 |
163 orig_nr = 1; | 196 orig_nr = 1; |
164 orig_nc = 1; | 197 orig_nc = 1; |
165 | 198 |
166 data = new int [len]; | 199 if (idx_is_inf_or_nan (d)) |
167 | 200 return; |
168 data[0] = tree_to_mat_idx (d); | 201 else |
169 | 202 { |
170 init_state (); | 203 data = new int [len]; |
204 | |
205 data[0] = tree_to_mat_idx (d); | |
206 } | |
171 } | 207 } |
172 | 208 |
173 IDX_VEC_REP::idx_vector_rep (const Range& r) | 209 IDX_VEC_REP::idx_vector_rep (const Range& r) |
174 { | 210 { |
175 data = 0; | 211 data = 0; |
206 data = new int [len]; | 242 data = new int [len]; |
207 | 243 |
208 for (int i = 0; i < len; i++) | 244 for (int i = 0; i < len; i++) |
209 { | 245 { |
210 double val = b + i * step; | 246 double val = b + i * step; |
211 data[i] = tree_to_mat_idx (val); | 247 |
248 if (idx_is_inf_or_nan (val)) | |
249 return; | |
250 else | |
251 data[i] = tree_to_mat_idx (val); | |
212 } | 252 } |
213 | 253 |
214 init_state (); | 254 init_state (); |
215 } | 255 } |
216 | 256 |