Commit 2f3ea8f4 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

copied to libaff

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1171
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 67c95fa7
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.1 2002-12-06 19:08:22 forbrig Exp $
# $Id: Makefile,v 1.2 2002-12-06 19:21:08 forbrig Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
# how to compile libcontxx tests
# how to compile libaff tests
#
# arguments to test programs can be passed through variable ARG
#
#
# REVISIONS and CHANGES
# 10/05/2002 V1.0 Thomas Forbriger
# 20/11/2002 V1.1 passing arguments
# 06/12/2002 V1.0 Thomas Forbriger (copied from libcontxx)
#
# ============================================================================
#
......
/*! \file arraytest.cc
* \brief test array class template (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: arraytest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $
* \author Thomas Forbriger
* \date 09/06/2002
*
* test array class template (implementation)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 09/06/2002 V1.0 Thomas Forbriger
* - 25/11/2002 V1.1 whole array assign
*
* ============================================================================
*/
/*! \example tests/arraytest.cc
*
* Here you can learn about how to use the contxx::Array class.
*
* \sa \ref sec_main_modules
* \sa tests/arraytest.cc
*/
#define TF_ARRAYTEST_CC_VERSION \
"TF_ARRAYTEST_CC V1.1 "
#define TF_ARRAYTEST_CC_CVSID \
"$Id: arraytest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $"
#define CONT_INDEXCHECK
#include<iostream>
#include <contxx/array.h>
#include <contxx/shape/shaper.h>
#include <contxx/shaper/fortran.h>
using std::cout;
using std::endl;
using namespace contxx::shape;
typedef contxx::Array<float, 3> Tarray;
typedef contxx::shaper::Fortran<3> Tshaper;
void print(const Tarray::Tcontainer_of_const& array, const char* name)
{
cout << endl;
cout << "Array \"" << name << "\"" << endl;
cout << "dimensionality: " << array.dimensionality() << endl;
for (int i=0; i<3; i++) {
cout << "dimension " << i+1 << ": [" <<
array.first(i) << ":" <<
array.last(i) << "]" << endl;
}
for (int i=array.first(2); i<=array.last(2); i++) {
cout << endl;
cout << "slice " << i << ":" << endl;
cout.width(8); cout << " ";
for (int l=array.first(1); l<=array.last(1); l++) {
cout.width(8);
cout << l << " ";
}
cout << endl;
for (int k=array.first(0); k<=array.last(0); k++) {
cout.width(8);
cout << k;
for (int l=array.first(1); l<=array.last(1); l++) {
cout.width(8);
cout << array(k,l,i) << " ";
}
cout << endl;
}
}
}
#define PRINT( array ) print(array, #array);
int main()
{
cout << TF_ARRAYTEST_CC_VERSION << endl;
cout << TF_ARRAYTEST_CC_CVSID << endl;
Tarray::Trange r1(3,6), r2(0,4), r3(-2,2);
Tarray::Tranges rng(tuple(r1, r2, r3));
typedef Tarray::Trange Tr;
Tarray E(tuple(Tr(0,6),Tr(0,2),Tr(0,1)));
Tarray D(tuple(Tarray::Trange(3,6),Tarray::Trange(8,9),Tarray::Trange(1,2)));
Tarray C(tuple(r1,r2,r3));
Tarray A(rng);
PRINT(D)
PRINT(C)
PRINT(A)
A(4,2,1)=10.;
PRINT(A)
PRINT(E)
{ Tarray B(Tshaper(-2,2)); PRINT(B) }
{ Tarray B(Tshaper(-2,2)(4)(0,3)); PRINT(B) }
{ Tarray B(Tshaper(-2,2)(4)(0,3)(1,2)(0,2)); PRINT(B) }
Tarray B(Tshaper(3));
for (int i=1; i<=B.last(0); i++)
{
for (int j=1; j<=B.last(1); j++)
{
for (int k=1; k<=B.last(2); k++)
{
B(i,j,k)=float(100*i+10*j+k);
}
}
}
PRINT(B)
Tarray::Trepresentation RB(B);
for (int i=0; i<int(RB.size()); i++)
{
cout << RB[i] << " ";
}
cout << endl;
{ Tarray copyB(B); }
{ Tarray copyB; copyB=B; }
B=134.2;
PRINT(B)
}
/* ----- END OF arraytest.cc ----- */
/*! \file binarraytest.cc
* \brief test precompiled version of array (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: binarraytest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $
* \author Thomas Forbriger
* \date 13/11/2002
*
* test precompiled version of array (implementation)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 13/11/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_BINARRAYTEST_CC_VERSION \
"TF_BINARRAYTEST_CC V1.0 "
#define TF_BINARRAYTEST_CC_CVSID \
"$Id: binarraytest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $"
#include<iostream>
#include <contxx/binarray.h>
#include <contxx/shape/shaper.h>
using std::cout;
using std::endl;
#ifndef DOXYGEN_MUST_SKIP_THIS
using namespace contxx::prebuilt::shape;
#endif // DOXYGEN_MUST_SKIP_THIS
typedef contxx::prebuilt::Array<float, 3> Tarray;
void print(const Tarray::Tcontainer_of_const& array, const char* name)
{
cout << endl;
cout << "Array \"" << name << "\"" << endl;
cout << "dimensionality: " << array.dimensionality() << endl;
for (int i=0; i<3; i++) {
cout << "dimension: [" <<
array.first(i) << ":" <<
array.last(i) << "]" << endl;
}
for (int i=array.first(2); i<=array.last(2); i++) {
cout << endl;
cout << "slice " << i << ":" << endl;
cout.width(8); cout << " ";
for (int l=array.first(0); l<=array.last(0); l++) {
cout.width(8);
cout << l << " ";
}
cout << endl;
for (int k=array.first(1); k<=array.last(1); k++) {
cout.width(8);
cout << k;
for (int l=array.first(0); l<=array.last(0); l++) {
cout.width(8);
cout << array(l,k,i) << " ";
}
cout << endl;
}
}
}
#define PRINT( array ) print(array, #array);
int main()
{
cout << TF_BINARRAYTEST_CC_VERSION << endl;
cout << TF_BINARRAYTEST_CC_CVSID << endl;
Tarray::Trange r1(3,6), r2(0,4), r3(-2,2);
Tarray::Tranges rng(tuple(r1, r2, r3));
typedef Tarray::Trange Tr;
Tarray E(tuple(Tr(0,6),Tr(0,2),Tr(0,1)));
Tarray D(tuple(Tarray::Trange(3,6),Tarray::Trange(8,9),Tarray::Trange(1,2)));
Tarray C(tuple(r1,r2,r3));
Tarray A(rng);
PRINT(D)
PRINT(C)
PRINT(A)
A(4,2,1)=10.;
PRINT(A)
PRINT(E)
}
/*! \example tests/binarraytest.cc
*
* Here you can learn about how to use the precompiled version of the library.
*
* \sa \ref sec_main_binary
* \sa tests/binarraytest.cc
*/
/* ----- END OF binarraytest.cc ----- */
/*! \file rangetest.cc
* \brief test range class (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: rangetest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $
* \author Thomas Forbriger
* \date 09/06/2002
*
* test range class (implementation)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 09/06/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_RANGETEST_CC_VERSION \
"TF_RANGETEST_CC V1.0 "
#define TF_RANGETEST_CC_CVSID \
"$Id: rangetest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $"
#include <rangetest.h>
/* ----- END OF rangetest.cc ----- */
/*! \file reprtest.cc
* \brief test representation classes (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: reprtest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $
* \author Thomas Forbriger
* \date 10/05/2002
*
* test representation classes (implementation)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 10/05/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_REPRTEST_CC_VERSION \
"TF_REPRTEST_CC V1.0 "
#define TF_REPRTEST_CC_CVSID \
"$Id: reprtest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $"
#include <contxx/repr/sharedheap.h>
#include <iostream>
using std::cout;
using std::endl;
// output function for representation objects
template<class T>
void print(const T& cont, const char* name)
{
using namespace contxx::util;
const int blocksize=15;
cout << name << ":" << endl;
Tsize size=cont.size();
int blocks=size / blocksize + 1;
for (int i=0; i<blocks; i++)
{
Tsize first=i*blocksize;
Tsize last=first+blocksize;
last = ( last > size ? size : last);
cout << " ";
for (Tsize j=first; j<last; j++)
{ cout.width(5); cout << j; }
cout << endl << " ";
for (Tsize j=first; j<last; j++)
{ cout.width(5); cout << cont[j]; }
cout << endl << endl;
}
}
#define PRINT( x ) print(x, #x );
int main()
{
cout << TF_REPRTEST_CC_VERSION << endl;
cout << TF_REPRTEST_CC_CVSID << endl;
using contxx::representation::SharedHeap;
const int N=10;
const int N2=23;
SharedHeap<int> A(N);
SharedHeap<int> B(N2);
SharedHeap<const int> C(N2);
SharedHeap<float> D(N2);
for (int i=0; i<N; i++) { A[i]=(i+1)*10; }
for (int i=0; i<N2; i++) { B[i]=(i+4)*3; }
for (int i=0; i<N2; i++) { D[i]=(i+2.45)*2; }
PRINT(A)
PRINT(B)
C=B;
PRINT(C)
// modify C through B
B[8]=632;
PRINT(C)
// modify C directly - is illegal
#ifdef ILLEGAL1
C[9]=354;
PRINT(C)
#endif
// make B a reference to A
B=A;
// modification should be visible through B
A[5]=453;
PRINT(B)
// test another type
PRINT(D)
cout << endl;
}
/* ----- END OF reprtest.cc ----- */
/*! \file shapetest.cc
* \brief test shape classes (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: shapetest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $
* \author Thomas Forbriger
* \date 25/05/2002
*
* test shape classes (implementation)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 25/05/2002 V1.0 Thomas Forbriger
* - 25/11/2002 V1.1 testing stepper
*
* ============================================================================
*/
#define TF_SHAPETEST_CC_VERSION \
"TF_SHAPETEST_CC V1.1 "
#define TF_SHAPETEST_CC_CVSID \
"$Id: shapetest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $"
#include<iostream>
#include<string>
#include <contxx/shape/shaper.h>
#include <contxx/shape/strided.h>
#include <contxx/shape/densestrided.h>
#include <contxx/shaper/fortran.h>
using std::cout;
using std::endl;
using std::string;
using namespace contxx::shape;
using namespace contxx::util;
/*
* function to print index relation of shape
*/
template<Tdim N, template<Tdim NN> class Shape>
void indexer(const char* name, const Shape<N>& shape)
{
cout << "shape " << name << ":" << endl;
typename Shape<N>::Tlimits index;
for (Tdim i=0; i<shape.dimensionality() ;i++)
{ index[i]=shape.first(i); }
while (index[N-1] < shape.last(N-1))
{
Tsubscript theindex=shape.offset();
for (Tdim i=0; i<shape.dimensionality(); i++)
{ theindex+=index[i]*shape.stride(i); }
cout << name << "(";
for (Tdim i=0; i<shape.dimensionality(); i++)
{ cout << index[i]; if (i+1<shape.dimensionality()) { cout << ","; } }
cout << "): " << theindex << endl;
Tdim i=0;
while (i<N)
{
++index[i];
if (index[i]>shape.last(i))
{
index[i]=shape.first(i);
i++;
}
else
{
i=N;
}
}
}
cout << endl;
}
#define INDEXER( shape ) indexer( #shape , shape );
/*
* function to print values of simple array
*/
template<class S>
void saprint(const char* name, const S& s)
{
cout << "simple array: " << name << ":" << endl;
for (Tsize i=0; i<s.size(); i++)
{
cout << " " << i << ":" << s[i];
}
cout << endl;
}
#define SAPRINTER( array ) saprint( #array , array );
//! print current position of stepper
template<class S>
void position(const S& s)
{
cout << "cur: " << s.current() << " ";
cout << "idx: ";
for (int i=0; i<int(s.index().size()); i++)
{ cout << s.index()[i] << " "; }
}
#define POSITION( S ) cout << " ### " << #S << ": "; position(S)
const char* bvalue(const bool& b)
{ if (b) return("true"); return("false"); }
#define BOOLIS( S ) cout << " *** " << #S << ": " << bvalue(S);
int main()
{
cout << TF_SHAPETEST_CC_VERSION << endl;
cout << TF_SHAPETEST_CC_CVSID << endl << endl;
{
Strided<3> A(tuple<Tsize>(3,3,3));
INDEXER( A )
}
{
cout << endl;
cout << "Test SimpleRigidArray" << endl;
cout << "=====================" << endl;
cout << endl;
SAPRINTER( tuple<Tsize>(5,8,2,5,4) )
SAPRINTER( tuple(6,300,12,-18,2) )
SAPRINTER( tuple(3.31e64,300.,12.,-18.,2.) )
SAPRINTER( tuple(string("Hallo"),
string("das"),
string("klappt"),
string("auch"),
string("so")) )
}
{
cout << endl;
cout << "Test Stepper" << endl;
cout << "============" << endl;
cout << endl;
Strided<3>::Tlimits first(tuple<Tsubscript>(2,1,5));
Strided<3>::Tlimits last(tuple<Tsubscript>(4,4,6));
Strided<3> S1(first,last);
DenseStrided<3> S2(first,last);
Strided<3>::Tstepper ST1(S1.stepper());
DenseStrided<3>::Tstepper ST2(S2.stepper());
POSITION(ST1);
POSITION(ST2);
cout << endl;
cout << "to last:" << endl;
ST1.tolast();
ST2.tolast();
POSITION(ST1);
POSITION(ST2);
cout << endl;
cout << "to first:" << endl;
ST1.tofirst();
ST2.tofirst();
POSITION(ST1);
POSITION(ST2);
cout << endl;
cout << "increment:" << endl;
for (int i=0; i<30; i++)
{
POSITION(ST1.incr());
POSITION(ST2.incr());
cout << endl;
}
cout << "while less:" << endl;
do {
POSITION(ST1.decr());
POSITION(ST2.decr());
cout << endl;
BOOLIS(ST1.less());
BOOLIS(ST2.less());
cout << endl;
} while (ST1.less() && ST2.less());
cout << "to first:" << endl;
ST1.tofirst();
ST2.tofirst();
POSITION(ST1);
POSITION(ST2);
cout << endl;
cout << "to last:" << endl;
ST1.tolast();
ST2.tolast();
POSITION(ST1);
POSITION(ST2);
cout << endl;
cout << "decrement:" << endl;
for (int i=0; i<30; i++)
{
POSITION(ST1.decr());
POSITION(ST2.decr());
cout << endl;
}
cout << "while more:" << endl;
do {
POSITION(ST1.incr());
POSITION(ST2.incr());
cout << endl;
} while (ST1.more() && ST2.more());
}
}
/* ----- END OF shapetest.cc ----- */
/*! \file simplearraytest.cc
* \brief test simple array class (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: simplearraytest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $
* \author Thomas Forbriger
* \date 25/05/2002
*
* test simple array class (implementation)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*