Category : C++ Source Code
Archive   : BLFMATH.ZIP
Filename : TSTMAT2.CPP

 
Output of file : TSTMAT2.CPP contained in archive : BLFMATH.ZIP
/////////////////////////////////////////////////////////////
// tstmat2.cpp: Matrix test program using shape elements.
// Copyright(c) 1993 Azarona Software. All rights reserved.
/////////////////////////////////////////////////////////////
#include
#include
#include "matrix.h"
#include "shape.h"

template
void PrtMat(const Matrix &m)
// We'll test 2D subscripting here while we're at it.
{
for (int i = 0; i for (int j = 0; j cout << setw(3) << m(i,j) << ' ';
}
cout << '\n';
}
}

template
void PrtVec(const Vector &v)
{
VecPtr elemptr(v.PtrToAll());
unsigned i, len = v.Length();
for (i = 0; i cout << *elemptr << ' ';
elemptr++;
}
cout << '\n';
}

// BC++ needs the next statements

void PrtMat(const Matrix &m);
void PrtVec(const Vector &v);

// You need one of these statements for each type of vector:

INITNULLVEC(Shape);

#ifdef ONE_WAY
// A low-level C array we'll copy and transform into matrix
const int arr_size = 56;
Shape arr[arr_size];
#endif

void test()
{
int i;

#ifdef ONE_WAY
// Set up low level array to be transformed to a matrix
for (i = 0; i #endif

cout << "Creating a matrix\n";

#ifdef ONE_WAY
Matrix mymat(7, 8, arr);
#else
Matrix mymat(7, 8);
Vector myvec(mymat.All());
// Testing 1D vector subscripting too
for (i = 0; i #endif
cout << "mymat: \n";
PrtMat(mymat); cout << '\n';

cout << "Creating copy of the matrix\n";

#ifdef ONE_WAY
Matrix matii(mymat, COPIED);
#else
Matrix matii(mymat.Clone());
#endif
cout << "matii: \n";
PrtMat(matii); cout << '\n';


cout << "Creating a share of the diagonal\n";

Vector Diag = mymat.Diag();
PrtVec(Diag);

cout << "Setting shared diagonal = 1\n";
Diag = Shape(1,1);
cout << "mymat: \n";
PrtMat(mymat); cout << '\n';

cout << "Creating a copy of the diagonal\n";

Vector Diag2 = mymat.Diag(COPIED);
PrtVec(Diag2);

cout << "Setting copied diagonal = 99\n";
Diag2 = Shape(99,99);
PrtVec(Diag2); cout << '\n';
cout << "mymat: \n";
PrtMat(mymat); cout << '\n';


cout << "Creating a share of row 3\n";
Vector Row = mymat.Row(3);
PrtVec(Row);

cout << "Setting row 3 to 17's\n";
Row = Shape(17, 17);
cout << "mymat: \n";
PrtMat(mymat); cout << '\n';

cout << "Creating a share of col 5\n";
Vector Col = mymat.Col(5);
PrtVec(Col);

cout << "Setting col 5 to 42's\n";
Col = Shape(42,42);
cout << "mymat: \n";
PrtMat(mymat);

cout << "\nUsing the copy of the original matrix\n";
cout << "matii: \n";
PrtMat(matii); cout << '\n';

cout << "Transposing this copy\n";
matii = matii.Transpose();
cout << "matii: \n";
PrtMat(matii); cout << '\n';

cout << "Set row 2 to 55's\n";
matii.Row(2) = Shape(55,55);
cout << "matii: \n";
PrtMat(matii); cout << '\n';

cout << "Set col 3 to 77's\n";
matii.Col(3) = Shape(77,77);
cout << "matii: \n";
PrtMat(matii); cout << '\n';

cout << "Creating shared submatrix of transpose\n";

Matrix submat(matii, SHARED, 2, 1, 3, 4);
cout << "submat: \n";
PrtMat(submat); cout << '\n';

cout << "Transposing the submatrix\n";
submat = submat.Transpose();
cout << "submat: \n";
PrtMat(submat); cout << '\n';

cout << "\nTesting a[][] form of subscripting\n";
cout << "submat[3][2] = " << submat[3][2] << "\n\n";

cout << "Setting diagonal of submatrix to 0\n";
submat.Diag() = Shape(0,0);
cout << "submat: \n";
PrtMat(submat); cout << '\n';

cout << "Setting second row of submatrix to 99's\n";
submat.Row(1) = Shape(99,99);
cout << "submat: \n";
PrtMat(submat); cout << '\n';

cout << "matii: \n";
PrtMat(matii); cout << '\n';

cout << "Creating sub-sub-matrix\n";

Matrix subsubmat(submat, SHARED, 1, 1, 3, 2);
cout << "subsubmat: \n";
PrtMat(subsubmat); cout << '\n';

cout << "Set rows of subsubmatrix to 91's, 92's, and 93's\n";

subsubmat.Row(0) = Shape(91,91);
subsubmat.Row(1) = Shape(92,92);
subsubmat.Row(2) = Shape(93,93);
cout << "subsubmat: \n";
PrtMat(subsubmat); cout << '\n';
cout << "matii: \n";
PrtMat(matii); cout << '\n';

cout << "Set diagonal of subsubmatrix to 77's\n";

subsubmat.Diag() = Shape(77,77);
cout << "subsubmat: \n";
PrtMat(subsubmat); cout << '\n';
cout << "matii: \n";
PrtMat(matii); cout << '\n';

cout << "Testing sub-matrix transpose\n";

cout << "subsubmat transposed: \n";
subsubmat = subsubmat.Transpose();
PrtMat(subsubmat); cout << '\n';

cout << "Set all elements of sub-sub-matrix to 42's\n";
subsubmat = Shape(42, 42);
cout << "subsubmat: \n";
PrtMat(subsubmat); cout << '\n';
cout << "matii: \n";
PrtMat(matii); cout << '\n';

}

#include "tstmain.cpp"


  3 Responses to “Category : C++ Source Code
Archive   : BLFMATH.ZIP
Filename : TSTMAT2.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/