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

started testing shape

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: 1208
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 04f99286
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.2 2002-12-17 19:41:21 forbrig Exp $
* $Id: README.changelog,v 1.3 2002-12-18 09:58:50 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -20,9 +20,15 @@
/*! \page page_changelog ChangeLog
- 17/12/2002 (thof)
Major changes in the interface of the library are marked by \b !!.
- \b 18/12/2002 (thof)
- defined dump function for Strided
- started with tests/shapetest.cc
- \b 17/12/2002 (thof)
- introduced class Series
- Array now inherits privately from Strided
- \b !! Array now inherits privately from Strided
- use access declarations to declare base class functions that should be
visible in the public interface of aff::Array and aff::SharedHeap
- introduced tests/seriestest.cc
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: dump.cc,v 1.3 2002-12-16 21:03:25 uid1201 Exp $
* $Id: dump.cc,v 1.4 2002-12-18 09:58:50 forbrig Exp $
* \author Thomas Forbriger
* \date 12/12/2002
*
......@@ -13,18 +13,53 @@
*
* REVISIONS and CHANGES
* - 12/12/2002 V1.0 Thomas Forbriger
* - 18/12/2002 V1.1 (thof)
* - stated definitions
*
* ============================================================================
*/
#define AFF_DUMP_CC_VERSION \
"AFF_DUMP_CC V1.0 "
#define TF_DUMP_CC_CVSID \
"$Id: dump.cc,v 1.3 2002-12-16 21:03:25 uid1201 Exp $"
"AFF_DUMP_CC V1.1"
#define AFF_DUMP_CC_CVSID \
"$Id: dump.cc,v 1.4 2002-12-18 09:58:50 forbrig Exp $"
#include <aff/dump.h>
namespace aff {
//! dump shape
void dump(const Strided& shape, std::ostream& os)
{
os << "dump of a Strided object:" << endl;
os << " index ranges: ";
for (Tsize i=0; i<Strided::Mmax_dimen; i++)
{
os << "[" << shape.first(i) << ":" << shape.last(i) << "]";
}
os << endl;
os << " strides: ";
for (Tsize i=0; i<Strided::Mmax_dimen; i++)
{
if (i>0) os << ", ";
os << shape.stride(i);
}
os << endl;
os << " total number of mapped elements: "
<< shape.size() << endl;
os << " total address range in memory: ["
<< shape.first_offset() << ":" << shape.last_offset() << "] = "
<< shape.memory_size() << " positions" << endl;
}
/*----------------------------------------------------------------------*/
//! dump index mapping of shape
void dump_map(const Strided& shape, std::ostream& os)
{
dump(shape);
os << " index mapping:" << endl;
}
} // namespace aff
/* ----- END OF dump.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: dump.h,v 1.6 2002-12-17 19:41:21 forbrig Exp $
* $Id: dump.h,v 1.7 2002-12-18 09:58:50 forbrig Exp $
* \author Thomas Forbriger
* \date 12/12/2002
*
......@@ -31,10 +31,11 @@
#define AFF_DUMP_H_VERSION \
"AFF_DUMP_H V1.1"
#define TF_DUMP_H_CVSID \
"$Id: dump.h,v 1.6 2002-12-17 19:41:21 forbrig Exp $"
"$Id: dump.h,v 1.7 2002-12-18 09:58:50 forbrig Exp $"
#include<iostream>
#include<aff/lib/simplearray.h>
#include<aff/lib/strided.h>
#include<aff/series.h>
namespace aff {
......@@ -130,9 +131,7 @@ void dump(const Array<T>::Tcoc& array, std::ostream& os=std::cout);
*
* \ingroup group_helpers
*/
/*
void dump(const Strided& shape, std::ostream& os=std::cout);
*/
/*----------------------------------------------------------------------*/
......@@ -140,9 +139,7 @@ void dump(const Strided& shape, std::ostream& os=std::cout);
*
* \ingroup group_helpers
*/
/*
void dump_map(const Strided& shape, std::ostream& os=std::cout);
*/
/*----------------------------------------------------------------------*/
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: shaper.h,v 1.5 2002-12-15 20:48:01 forbrig Exp $
* $Id: shaper.h,v 1.6 2002-12-18 09:58:50 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -20,6 +20,8 @@
* - documentation ist still missing
* - 15/12/2002 V1.3 (thof)
* - never place in namspace prebuilt
* - 18/12/2002 V1.4 (thof)
* - small but essential correction in operator()
*
* ============================================================================
*/
......@@ -28,9 +30,9 @@
#ifndef AFF_SHAPER_H_VERSION
#define AFF_SHAPER_H_VERSION \
"AFF_SHAPER_H V1.3"
"AFF_SHAPER_H V1.4"
#define AFF_SHAPER_H_CVSID \
"$Id: shaper.h,v 1.5 2002-12-15 20:48:01 forbrig Exp $"
"$Id: shaper.h,v 1.6 2002-12-18 09:58:50 forbrig Exp $"
#include<aff/lib/strided.h>
#include<aff/lib/error.h>
......@@ -73,7 +75,7 @@ class Shaper
Mmaxlast[0]=last;
}
//! First dimension is defined by constructor
Shaper(const Tsubscript& first, const Tsubscript& last)
Shaper(const Tsubscript& first, const Tsubscript& last):
Mfirst(1), Mlast(1), Mmaxlast(1), Mdim(1)
{
AFF_assert((last>=first), "ERROR (shaper): invalid index range");
......@@ -98,6 +100,7 @@ class Shaper
AFF_assert((last>=1), "ERROR (shaper): invalid limit");
Mfirst[Mdim]=1;
Mlast[Mdim]=last;
Mmaxlast[Mdim]=last;
// foolproof
if (Mdim<(Tshape::Mmax_dimen-1)) Mdim++;
return(*this);
......@@ -135,10 +138,10 @@ class Shaper
}
private:
//! limits
Tshape::TLimitVec Mfirst, Mlast, Mmaxlast;
Tshape::TIndexVec Mfirst, Mlast, Mmaxlast;
//! next dimension to set
Tdim Mdim;
};
}; // Shaper
} // namespace aff
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: reprtest.cc,v 1.5 2002-12-16 21:03:29 uid1201 Exp $
* $Id: reprtest.cc,v 1.6 2002-12-18 09:58:52 forbrig Exp $
* \author Thomas Forbriger
* \date 10/05/2002
*
......@@ -24,7 +24,7 @@
#define AFF_REPRTEST_CC_VERSION \
"AFF_REPRTEST_CC V1.1"
#define AFF_REPRTEST_CC_CVSID \
"$Id: reprtest.cc,v 1.5 2002-12-16 21:03:29 uid1201 Exp $"
"$Id: reprtest.cc,v 1.6 2002-12-18 09:58:52 forbrig Exp $"
#include <aff/lib/sharedheap.h>
#include <aff/dump.h>
......@@ -32,6 +32,13 @@
using std::cout;
using std::endl;
/*! \example tests/reprtest.cc
*
* Test representation class aff::SharedHeap.
*
* \sa tests/reprtest.cc
*/
//! echo
#define CODE( C ) cout << #C << endl; C
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: seriestest.cc,v 1.1 2002-12-17 19:41:23 forbrig Exp $
* $Id: seriestest.cc,v 1.2 2002-12-18 09:58:52 forbrig Exp $
* \author Thomas Forbriger
* \date 17/12/2002
*
......@@ -19,7 +19,7 @@
#define AFF_SERIESTEST_CC_VERSION \
"AFF_SERIESTEST_CC V1.1"
#define AFF_SERIESTEST_CC_CVSID \
"$Id: seriestest.cc,v 1.1 2002-12-17 19:41:23 forbrig Exp $"
"$Id: seriestest.cc,v 1.2 2002-12-18 09:58:52 forbrig Exp $"
#include <aff/series.h>
#include <aff/dump.h>
......@@ -27,6 +27,13 @@
using std::cout;
using std::endl;
/*! \example tests/seriestest.cc
*
* Test series class aff::Series.
*
* \sa tests/seriestest.cc
*/
//! echo
#define CODE( C ) cout << #C << endl; C
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: shapetest.cc,v 1.1 2002-12-06 19:21:08 forbrig Exp $
* $Id: shapetest.cc,v 1.2 2002-12-18 09:58:52 forbrig Exp $
* \author Thomas Forbriger
* \date 25/05/2002
*
......@@ -13,198 +13,81 @@
*
* REVISIONS and CHANGES
* - 25/05/2002 V1.0 Thomas Forbriger
* - 25/11/2002 V1.1 testing stepper
* - 18/12/2002 V1.1 started test of Strided (aff)
*
* ============================================================================
*/
#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 $"
#define AFF_SHAPETEST_CC_VERSION \
"AFF_SHAPETEST_CC V1.1"
#define AFF_SHAPETEST_CC_CVSID \
"$Id: shapetest.cc,v 1.2 2002-12-18 09:58:52 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>
#include<aff/dump.h>
#include<aff/shaper.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
using namespace aff;
/*! \example tests/shapetest.cc
*
* Test shape aff::Strided, the shaper class aff::Shaper,
* and the helper class aff::util::StridedStepper
*
* \sa tests/shapetest.cc
*/
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 );
//! echo
#define CODE( C ) cout << #C << endl; C
/*
* function to print values of simple array
*/
template<class S>
void saprint(const char* name, const S& s)
//! print headline
void section(const char* s, const char l='-')
{
cout << "simple array: " << name << ":" << endl;
for (Tsize i=0; i<s.size(); i++)
{
cout << " " << i << ":" << s[i];
}
cout << endl << s << endl;
const char* p=s;
while (*p) { cout << l; ++p; }
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)
//! print value of a bool
const char* bvalue(const bool& b)
{ if (b) return("true"); return("false"); }
//! print value of a bool
#define BOOLIS( S ) cout << " *** " << #S << ": " << bvalue(S);
//! test shape class
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());
}
cout << AFF_SHAPETEST_CC_VERSION << endl;
cout << AFF_SHAPETEST_CC_CVSID << endl << endl;
section("Test shape class Strided", '=');
section("Test shaper class Shaper");
cout << endl << "Basic usage:" << endl;
DUMP( Shaper(10)(12) );
cout << endl << "Fool proof with limited dimensionality:" << endl;
DUMP( Shaper(2,10)(-12,12)(9)(2,7)(3,4) );
cout << endl << "Usage for an external Fortran shape:" << endl;
DUMP( Shaper(1,6,10)(1,12,30)(1,10) );
section("Test subarrays and slicing");
DUMP( Shaper(10)(10)(10) );
cout << endl;
DUMP( Strided(Shaper(10)(10)(10)).shrink(0,2,5) );
cout << endl;
DUMP( Strided(Shaper(10)(10)(10)).shrink(2,5) );
cout << endl;
DUMP( Strided(Shaper(10)(15)(20)).collapse(1,5) );
}
/* ----- END OF shapetest.cc ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment