1 line
7.7 KiB
C++
1 line
7.7 KiB
C++
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* */
/* */
/* MV++ Numerical Matrix/Vector C++ Library */
/* MV++ Version 1.5 */
/* */
/* R. Pozo */
/* National Institute of Standards and Technology */
/* */
/* NOTICE */
/* */
/* Permission to use, copy, modify, and distribute this software and */
/* its documentation for any purpose and without fee is hereby granted */
/* provided that this permission notice appear in all copies and */
/* supporting documentation. */
/* */
/* Neither the Institution (National Institute of Standards and Technology) */
/* nor the author makes any representations about the suitability of this */
/* software for any purpose. This software is provided ``as is''without */
/* expressed or implied warranty. */
/* */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//
// tvec.cc Testing routine for MV++ vector class
//
// Usage: <length> <block-index start> <block-index end>
//
// (Suggest these to be relatively small positive numbers, as
// output is proportional to "length".)
//
// This test program is self-explanatory (there are diagnostics
// output message of what each step is performing)and excercise
// most of the MV_Vector methods, thus providing examples of how
// these are used.
//
#include <iostream.h>
#include <stdlib.h>
#include "vecdefs.h"
#include VECTOR_H
// example function to zero-out a vector: illustrates how to pass
// vectors by "reference" (modifiable), as opposed to by "value"
//
void foo(VECTOR_float *Aptr)
{
VECTOR_float &A = *Aptr;
A = (float) 0;
}
// example funciton to return MV_Vectors: (returns vector + scalar)
//
VECTOR_float fexample(const VECTOR_float A, float s)
{
int N = A.size();
VECTOR_float B(N);
for (int i=0; i<N; i++)
B(i) = A(i) + s;
return B;
}
int TestVec_float(int N, int start, int End)
{
int i;
cout << endl;
cout << "TestVec_float :" << endl;
cout << "Using N = " << N << " start = " << start << " End = "
<< End << endl;
VECTOR_float C;
cout << " Test null constructor: MV_Vector C() " << endl;
cout << C << endl;
VECTOR_float A(N);
cout << " Test MV_Vector(int) constructor: MV_Vector A(N) " << endl;
cout << " values should be uninitalized.. " << endl;
cout << A << endl;
VECTOR_float B(N, 3);
cout << " Test MV_Vector(int, val) constructor: MV_Vector B(N, 3.0) " << endl;
cout << " all values should be 3.0: " << endl;
cout << B << endl;
cout << " Test A(i) indexing, set A(i) = i, and B(i) = -i " << endl;
for (i=0; i<N; i++)
{
A(i) = i;
B(i) = -i;
}
cout << " A " << endl;
cout << A << endl;
cout << " B " << endl;
cout << B << endl;
cout << "Test opeator= : C = A " << endl;
cout << " C is a new copy of A " << endl;
C = A;
cout << " C : " << endl;
cout << C << endl;
cout << "Testing MV_VecIndexI(start, End) " << endl;
//
MV_VecIndex I(start, End);
//
cout << "I = (" << start << ":"<< End <<") " <
|