39 template <
class nr_type_t>
48 template <
class nr_type_t>
53 data =
new nr_type_t[
s];
54 memset (
data, 0,
sizeof (nr_type_t) * s);
61 template <
class nr_type_t>
77 template <
class nr_type_t>
78 const tvector<nr_type_t>&
94 template <
class nr_type_t>
96 if (
data && !external)
delete[]
data;
100 template <
class nr_type_t>
102 assert (i >= 0 && i <
size);
107 template <
class nr_type_t>
109 assert (i >= 0 && i <
size);
114 template <
class nr_type_t>
120 template <
class nr_type_t>
126 template <
class nr_type_t>
128 if (
size >= capacity) {
132 data = (nr_type_t *) realloc (
data, capacity *
sizeof (nr_type_t));
137 data = (nr_type_t *) malloc (capacity *
sizeof (nr_type_t));
144 template <
class nr_type_t>
154 template <
class nr_type_t>
163 template <
class nr_type_t>
170 template <
class nr_type_t>
173 for (
int i = 0;
i <
size;
i++)
if (
abs (
data[
i] - val) <= eps) count++;
178 template <
class nr_type_t>
184 template <
class nr_type_t>
186 if (
data && !external)
delete[]
data;
189 capacity =
size = len;
193 template <
class nr_type_t>
195 assert (r1 >= 0 && r2 >= 0 && r1 <
size && r2 <
size);
196 nr_type_t
s =
data[r1];
202 template <
class nr_type_t>
203 tvector<nr_type_t>
operator + (tvector<nr_type_t> a, tvector<nr_type_t> b) {
204 assert (a.getSize () == b.getSize ());
205 int n = a.getSize ();
206 tvector<nr_type_t> res (n);
207 for (
int i = 0;
i <
n;
i++) res.set (
i, a.get (
i) + b.get (
i));
212 template <
class nr_type_t>
215 nr_type_t * src = a.
getData ();
216 nr_type_t * dst =
data;
217 for (
int i = 0;
i <
size;
i++) *dst++ += *src++;
222 template <
class nr_type_t>
223 tvector<nr_type_t>
operator - (tvector<nr_type_t> a, tvector<nr_type_t> b) {
224 assert (a.getSize () == b.getSize ());
225 int n = a.getSize ();
226 tvector<nr_type_t> res (n);
227 for (
int i = 0;
i <
n;
i++) res.set (
i, a.get (
i) - b.get (
i));
232 template <
class nr_type_t>
235 nr_type_t * src = a.
getData ();
236 nr_type_t * dst =
data;
237 for (
int i = 0;
i <
size;
i++) *dst++ -= *src++;
242 template <
class nr_type_t>
244 nr_type_t * dst =
data;
245 for (
int i = 0;
i <
size;
i++) *dst++ *= s;
250 template <
class nr_type_t>
252 nr_type_t * dst =
data;
253 for (
int i = 0;
i <
size;
i++) *dst++ /= s;
258 template <
class nr_type_t>
259 tvector<nr_type_t>
operator * (nr_double_t
s, tvector<nr_type_t> a) {
260 int n = a.getSize ();
261 tvector<nr_type_t> res (n);
262 for (
int i = 0;
i <
n;
i++) res.set (
i, s * a.get (
i));
266 template <
class nr_type_t>
267 tvector<nr_type_t>
operator * (tvector<nr_type_t> a, nr_double_t
s) {
272 template <
class nr_type_t>
273 tvector<nr_type_t>
operator * (tvector<nr_type_t> a, tvector<nr_type_t> b) {
274 assert (a.getSize () == b.getSize ());
275 int n = a.getSize ();
276 tvector<nr_type_t> res (n);
277 for (
int i = 0;
i <
n;
i++) res.set (
i, a.get (
i) * b.get (
i));
282 template <
class nr_type_t>
283 nr_type_t
scalar (tvector<nr_type_t> a, tvector<nr_type_t> b) {
284 assert (a.getSize () == b.getSize ());
286 for (
int i = 0;
i < a.getSize ();
i++) n += a.get (
i) * b.get (
i);
291 template <
class nr_type_t>
298 template <
class nr_type_t>
299 nr_type_t
sum (tvector<nr_type_t> a) {
301 for (
int i = 0;
i < a.getSize ();
i++) res += a.get (
i);
306 template <
class nr_type_t>
308 int n = a.getSize ();
309 tvector<nr_type_t> res (n);
310 for (
int i = 0;
i <
n;
i++) res.set (
i, -a.get (
i));
315 template <
class nr_type_t>
316 bool operator < (tvector<nr_type_t> a, tvector<nr_type_t> b) {
317 assert (a.getSize () == b.getSize ());
318 int n = a.getSize ();
319 for (
int i = 0;
i <
n;
i++)
if (a.get (
i) >= b.get (
i))
return false;
324 template <
class nr_type_t>
325 bool operator > (tvector<nr_type_t> a, tvector<nr_type_t> b) {
326 assert (a.getSize () == b.getSize ());
327 int n = a.getSize ();
328 for (
int i = 0;
i <
n;
i++)
if (a.get (
i) <= b.get (
i))
return false;
333 template <
class nr_type_t>
334 tvector<nr_type_t>
operator + (nr_type_t
s, tvector<nr_type_t> a) {
335 int n = a.getSize ();
336 tvector<nr_type_t> res (n);
337 for (
int i = 0;
i <
n;
i++) res.set (
i, s + a.get (
i));
341 template <
class nr_type_t>
342 tvector<nr_type_t>
operator + (tvector<nr_type_t> a, nr_type_t
s) {
347 template <
class nr_type_t>
348 nr_double_t
norm (tvector<nr_type_t> a) {
351 for (
int i = 0;
i < a.getSize ();
i++) k +=
norm (a.get (
i));
354 nr_double_t
scale = 0,
n = 1,
x, ax;
355 for (
int i = 0;
i < a.getSize ();
i++) {
356 if ((
x =
real (a (
i))) != 0) {
368 if ((
x =
imag (a (
i))) != 0) {
381 return scale * scale *
n;
386 template <
class nr_type_t>
388 nr_double_t nMax = 0,
n;
389 for (
int i = 0;
i < a.getSize ();
i++) {
391 if (
n > nMax) nMax =
n;
397 template <
class nr_type_t>
398 tvector<nr_type_t>
conj (tvector<nr_type_t> a) {
399 int n = a.getSize ();
400 tvector<nr_type_t> res (n);
401 for (
int i = 0;
i <
n;
i++) res.set (
i,
conj (a.get (
i)));
406 template <
class nr_type_t>
409 if (!std::isfinite (
real (
data[
i])))
return 0;
414 template <
class nr_type_t>
422 template <
class nr_type_t>
424 for (
int r = 0;
r <
size;
r++) {
425 fprintf (stderr,
"%+.2e%+.2ei\n", (
double)
real (
get (
r)),
426 (
double)
imag (
get (
r)));
void setData(nr_type_t *, int)
matrix real(matrix a)
Real part matrix.
matrix abs(matrix a)
Computes magnitude of each matrix element.
tvector operator-=(tvector)
nr_type_t scalar(tvector< nr_type_t > a, tvector< nr_type_t > b)
matrix operator*(matrix a, nr_complex_t z)
Matrix scaling complex version.
tvector operator*=(nr_double_t)
void exchangeRows(int, int)
bool operator>(const nr_complex_t z1, const nr_complex_t z2)
Superior.
nr_double_t maxnorm(tvector< nr_type_t > a)
matrix imag(matrix a)
Imaginary part matrix.
matrix operator-(matrix a, matrix b)
Matrix subtraction.
tvector operator+=(tvector)
const tvector & operator=(const tvector &)
Declaration sizeof(struct vcd_scope))
matrix operator+(matrix a, matrix b)
Matrix addition.
tvector operator/=(nr_double_t)
nr_double_t norm(const nr_complex_t z)
Compute euclidian norm of complex number.
matrix conj(matrix a)
Conjugate complex matrix.
int contains(nr_type_t, nr_double_t eps=NR_EPSI)
nr_type_t * getData(void)