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

array test now works

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.
factored out header files for dump


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1218
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 3bb2bccf
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README,v 1.5 2002-12-17 19:19:54 forbrig Exp $
* $Id: README,v 1.6 2002-12-19 18:30:01 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -48,7 +48,7 @@ namespace aff {
\since December 2002
\date December 2002
\version V1.0
$Id: README,v 1.5 2002-12-17 19:19:54 forbrig Exp $
$Id: README,v 1.6 2002-12-19 18:30:01 forbrig Exp $
Contents of this page:
- \ref sec_main_aims
......@@ -433,6 +433,7 @@ Tell about usefull header files.
\section sec_nameing_macros Preprocessor macros
Preprocessor macros like include-guards should have the prefix "AFF_".
The macros in the \ref group_helpers are an exception to this rule.
\section sec_nameing_files Filenames
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.7 2002-12-19 12:03:40 forbrig Exp $
* $Id: README.changelog,v 1.8 2002-12-19 18:30:01 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -27,6 +27,10 @@
- \b 19/12/2002 (thof)
- \b !! aff::Array provides access to base classes through access
functions and not through conversion operators.
- Factored out header files for dump functions for different classes.
This is necessary to use the SimpleRigidArray dump function within the
Array class definition.
- introduced function aff::util::StridedStepper::valid()
- \b 18/12/2002 (thof)
- defined dump function for Strided
......@@ -131,6 +135,24 @@
<TR><TD>libaff/lib/types.h</TD>
<TD>13/12/02</TD><TD> </TD><TD>15/12/02</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/dump_macros.h</TD>
<TD>19/12/02</TD><TD>19/12/02</TD><TD>19/12/02</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/dump_sharedheap.h</TD>
<TD>19/12/02</TD><TD> </TD><TD>19/12/02</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/dump_series.h</TD>
<TD>19/12/02</TD><TD> </TD><TD>19/12/02</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/dump_array.h</TD>
<TD>19/12/02</TD><TD> </TD><TD>19/12/02</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/dump_strided.h</TD>
<TD>19/12/02</TD><TD> </TD><TD>19/12/02</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/dump_simplerigidarray.h</TD>
<TD>19/12/02</TD><TD> </TD><TD>19/12/02</TD><TD> </TD>
</TR>
<TR><TD>libaff/tests/arraytest.cc</TD>
<TD> </TD><TD> </TD><TD> </TD>
<TD> </TD>
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: array_dec.h,v 1.11 2002-12-19 12:03:41 forbrig Exp $
* $Id: array_dec.h,v 1.12 2002-12-19 18:30:01 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -26,6 +26,10 @@
* - provide read access to base classes
* and read/write access to representation of
* non-const array
* - replaced four size-argument constructors by one
* constructor with default arguments
* - distinguish between mutable and non-mutable
* representation
*
* ============================================================================
*/
......@@ -36,7 +40,7 @@
#define AFF_ARRAY_DEC_H_VERSION \
"AFF_ARRAY_DEC_H V1.3"
#define AFF_ARRAY_DEC_H_CVSID \
"$Id: array_dec.h,v 1.11 2002-12-19 12:03:41 forbrig Exp $"
"$Id: array_dec.h,v 1.12 2002-12-19 18:30:01 forbrig Exp $"
#include <aff/lib/sharedheap.h>
#include <aff/lib/strided.h>
......@@ -161,18 +165,9 @@ namespace prebuilt {
//! construct from shape (defines size and layout)
explicit Array(const Tshape& shape):
Tbase(shape) { }
//! construct from index range limit
explicit Array(const Tsize& s0):
Tbase(s0) { }
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1):
Tbase(s0, s1) { }
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1, const Tsize& s2):
Tbase(s0, s1, s2) { }
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1,
const Tsize& s2, const Tsize& s3):
explicit Array(const Tsize& s0, const Tsize& s1=1,
const Tsize& s2=1, const Tsize& s3=1):
Tbase(s0, s1, s2, s3) { }
//@}
......@@ -188,8 +183,14 @@ namespace prebuilt {
//@}
//! return full access representation
Trepresentation& representation()
{ return (this->Tbase::representation); }
const Trepresentation& representation()
{ return (this->Tbase::mutable_representation()); }
private:
//! reimplement copy operator for base class to override access
//! declaration
Tcontainer& operator=(const Tcoc& array)
{ AFF_abort("illegal call"); return(*this); }
}; // class Array
......@@ -213,7 +214,9 @@ namespace prebuilt {
*/
//@{
//! Type of representation
typedef aff::SharedHeap<T> Trepresentation;
typedef aff::SharedHeap<T> Tmutable_representation;
//! Type of representation
typedef aff::SharedHeap<const T> Trepresentation;
//! Type of subscriptor
typedef aff::Strided Tshape;
//! Element type
......@@ -264,18 +267,12 @@ namespace prebuilt {
Array() { }
//! construct from shape and representation
Array(const Tshape& shape,
const Trepresentation& representation);
const Tmutable_representation& representation);
//! construct from shape (defines size and layout)
explicit Array(const Tshape& shape);
//! construct from index range limit
explicit Array(const Tsize& s0);
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1);
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1, const Tsize& s2);
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1,
const Tsize& s2, const Tsize& s3);
explicit Array(const Tsize& s0, const Tsize& s1=1,
const Tsize& s2=1, const Tsize& s3=1);
//@}
/*-----------------------------------------------------------------*/
......@@ -363,7 +360,7 @@ namespace prebuilt {
{ return(*this); }
//! provide restricted access representation
const SharedHeap<const T>& representation()
const SharedHeap<const T>& representation() const
{ return (*this); }
/*-----------------------------------------------------------------*/
......@@ -408,36 +405,36 @@ namespace prebuilt {
//@{
//! full dimensionality access
T& operator()(const TIndexVec& index)
{ return(this->Trepresentation::operator[](
{ return(this->Tmutable_representation::operator[](
this->Tshape::offset(index))); }
//! access from 1 index value
T& operator()(const Tsubscript& i0)
{ return(this->Trepresentation::operator[](
{ return(this->Tmutable_representation::operator[](
this->Tshape::offset(i0))); }
//! access from 2 index values
T& operator()(const Tsubscript& i0,
const Tsubscript& i1)
{ return(this->Trepresentation::operator[](
{ return(this->Tmutable_representation::operator[](
this->Tshape::offset(i0, i1))); }
//! access from 3 index values
T& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2)
{ return(this->Trepresentation::operator[](
{ return(this->Tmutable_representation::operator[](
this->Tshape::offset(i0, i1, i2))); }
//! access from 4 index values
T& operator()(const Tsubscript& i0,
const Tsubscript& i1,
const Tsubscript& i2,
const Tsubscript& i3)
{ return(this->Trepresentation::operator[](
{ return(this->Tmutable_representation::operator[](
this->Tshape::offset(i0, i1, i2, i3))); }
//@}
/*-----------------------------------------------------------------*/
//! return full access representation
Trepresentation& representation()
const SharedHeap<T>& mutable_representation()
{ return (*this); }
}; // class Array<const T>
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: array_def.h,v 1.8 2002-12-19 12:03:41 forbrig Exp $
* $Id: array_def.h,v 1.9 2002-12-19 18:30:02 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -27,6 +27,12 @@
* - added standard constructors
* - 18/12/2002 V1.2 (thof)
* - added stepper code to scalar assignment operator
* - 19/12/2002 V1.3 (thof)
* - size constructors did not work
* - replaced four size-argument constructors by one
* constructor with default arguments
* - distinguish between mutable and non-mutable
* representation
*
* ============================================================================
*/
......@@ -39,9 +45,9 @@
#ifndef AFF_ARRAY_DEF_H_VERSION
#define AFF_ARRAY_DEF_H_VERSION \
"AFF_ARRAY_DEF_H V1.2"
"AFF_ARRAY_DEF_H V1.3"
#define AFF_ARRAY_DEF_H_CVSID \
"$Id: array_def.h,v 1.8 2002-12-19 12:03:41 forbrig Exp $"
"$Id: array_def.h,v 1.9 2002-12-19 18:30:02 forbrig Exp $"
#include<aff/lib/error.h>
#include<aff/lib/stridedstepper.h>
......@@ -58,39 +64,6 @@ namespace prebuilt {
#endif
#endif
/*----------------------------------------------------------------------*/
//! construct array from given size
template<class T>
Array<const T>::Array(const Tsize& s0): Tshape(s0)
{
this->Trepresentation::operator=(
Trepresentation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
//! construct array from given dimension sizes
template<class T>
Array<const T>::Array(const Tsize& s0,
const Tsize& s1): Tshape(s0, s1)
{
this->Trepresentation::operator=(
Trepresentation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
//! construct array from given dimension sizes
template<class T>
Array<const T>::Array(const Tsize& s0,
const Tsize& s1,
const Tsize& s2): Tshape(s0, s1, s2)
{
this->Trepresentation::operator=(
Trepresentation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
//! construct array from given dimension sizes
......@@ -98,10 +71,16 @@ namespace prebuilt {
Array<const T>::Array(const Tsize& s0,
const Tsize& s1,
const Tsize& s2,
const Tsize& s3): Tshape(s0, s1, s2, s3)
const Tsize& s3)
{
this->Trepresentation::operator=(
Trepresentation(this->Tshape::memory_size()));
Tshape::TSizeVec size;
size[0]=s0;
size[1]=s1;
size[2]=s2;
size[3]=s3;
this->Tshape::operator=(Tshape(size));
this->Tmutable_representation::operator=(
Tmutable_representation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
......@@ -109,14 +88,14 @@ namespace prebuilt {
//! construct array from shape and representation
template<class T>
Array<const T>::Array(const Tshape& shape,
const Trepresentation& representation)
const Tmutable_representation& representation)
{
AFF_assert((shape.first_offset()>=0),
"ERROR (Array): invalid shape in constructor");
AFF_assert((shape.last_offset()<representation.size()),
"ERROR (Array): shape and representation are inconsistent");
this->Tshape::operator=(shape);
this->Trepresentation::operator=(representation);
this->Tmutable_representation::operator=(representation);
}
/*----------------------------------------------------------------------*/
......@@ -125,8 +104,8 @@ namespace prebuilt {
template<class T>
Array<const T>::Array(const Tshape& shape): Tshape(shape)
{
this->Trepresentation::operator=(
Trepresentation(this->Tshape::memory_size()));
this->Tmutable_representation::operator=(
Tmutable_representation(this->Tshape::memory_size()));
}
/*----------------------------------------------------------------------*/
......@@ -136,9 +115,8 @@ namespace prebuilt {
Array<const T>& Array<const T>::operator=(const T& value)
{
aff::util::StridedStepper st(*this);
st.tofirst();
for (st.tofirst(); st.more(); st.incr())
{ this->Trepresentation::operator[](st.current())=value; }
for(st.tofirst(); st.valid(); st.incr())
{ this->Tmutable_representation::operator[](st.current())=value; }
return(*this);
}
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: dump.cc,v 1.5 2002-12-18 18:43:43 uid1201 Exp $
* $Id: dump.cc,v 1.6 2002-12-19 18:30:02 forbrig Exp $
* \author Thomas Forbriger
* \date 12/12/2002
*
......@@ -21,7 +21,7 @@
#define AFF_DUMP_CC_VERSION \
"AFF_DUMP_CC V1.1"
#define AFF_DUMP_CC_CVSID \
"$Id: dump.cc,v 1.5 2002-12-18 18:43:43 uid1201 Exp $"
"$Id: dump.cc,v 1.6 2002-12-19 18:30:02 forbrig Exp $"
#include <aff/dump.h>
......@@ -55,7 +55,10 @@ void dump(const Strided& shape, std::ostream& os)
namespace {
//! recursive usage tests all offset functions
/*! \brief recursive usage tests all offset functions
*
* \ingroup group_helpers
*/
void dump_map_helper(const Strided& shape, const Tdim& i, const Tdim& j,
Strided::TIndexVec& index, std::ostream& os)
{
......@@ -71,10 +74,10 @@ namespace {
else if (i>0)
{
if (i<j) os << endl;
os.width(6); os << " ";
os.width(5); os << " ";
for (int k=shape.first(1); k<=shape.last(1); k++)
{
os.width(5); os << k;
os.width(6); os << k;
}
os << endl;
for (index[0]=shape.first(0); index[0]<=shape.last(0); index[0]++)
......
......@@ -3,15 +3,13 @@
*
* ----------------------------------------------------------------------------
*
* $Id: dump.h,v 1.9 2002-12-19 12:03:41 forbrig Exp $
* $Id: dump.h,v 1.10 2002-12-19 18:30:02 forbrig Exp $
* \author Thomas Forbriger
* \date 12/12/2002
*
* debug helpers (prototypes)
*
* \note
* You should include aff/array.h or aff/binarray.h just before including this
* file.
* This file just collects other header files.
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -23,6 +21,10 @@
* - introduced dump for class Series
* - 19/12/2002 V1.3 (thof)
* - added array dump functions
* - Factored out declarations to different header
* files. This file just collects them. This is
* essential to make the SimpleRigidArray dump
* function useable in the Array definition (e.g.).
*
* ============================================================================
*/
......@@ -31,218 +33,19 @@
#ifndef AFF_DUMP_H_VERSION
#define AFF_DUMP_H_VERSION \
"AFF_DUMP_H V1.1"
"AFF_DUMP_H V1.3"
#define TF_DUMP_H_CVSID \
"$Id: dump.h,v 1.9 2002-12-19 12:03:41 forbrig Exp $"
#include<iostream>
#include<aff/array.h>
#include<aff/series.h>
namespace aff {
using std::endl;
"$Id: dump.h,v 1.10 2002-12-19 18:30:02 forbrig Exp $"
/*! \defgroup group_helpers Debug functions
*/
/*----------------------------------------------------------------------*/
/*! \brief Dump series contents
*
* \ingroup group_helpers
*/
template<typename T>
void dump(const aff::Series<const T>& series,
std::ostream& os=std::cout)
{
os << "dump of a Series object:" << endl;
os << " size: " << series.size() << endl;
os << " index range: [" << series.f() << ":" << series.l() << "]" << endl;
os << " elements:" << endl;
int i=0;
for (aff::Tsubscript k=series.f(); k<=series.l(); k++)
{
if (!i) { os << " "; }
os.width(8);
os << series(k) << " ";
if (++i>7) { i=0; os << endl; }
}
os << endl;
}
/*----------------------------------------------------------------------*/
/*! \brief Dump heap contents
*
* \ingroup group_helpers
*/
template<typename T>
void dump(const aff::SharedHeap<const T>& sharedheap,
std::ostream& os=std::cout)
{
os << "dump of a SharedHeap object:" << endl;
os << " size: " << sharedheap.size() << endl;
os << " elements:" << endl;
int i=0;
for (aff::Tsize k=0; k<sharedheap.size(); k++)
{
if (!i) { os << " "; }
os.width(8);
os << sharedheap[k] << " ";
if (++i>7) { i=0; os << endl; }
}
os << endl;
}
/*----------------------------------------------------------------------*/
/*! \brief Dump aff::SimpleRigidArray
*
* \ingroup group_helpers
*/
template<class T, int N>
void dump(const SimpleRigidArray<T,N>& array, std::ostream& os=std::cout)
{
int i=0;
for (aff::Tsize k=0; k<N; k++)
{
if (!i) { os << " "; }
os.width(9);
os << array[k] << " ";
if (++i>7) { i=0; os << endl; }
}
os << endl;
}
/*----------------------------------------------------------------------*/
namespace {
//! recursive usage tests all access functions
template<class T>
void dump_array_helper(const aff::Array<const T>& array,
const Tdim& i, const Tdim& j,
Strided::TIndexVec& index,
std::ostream& os)
{
if (i>1)
{
for (index[i]=array.f(i); index[i]<=array.l(i); index[i]++)
{
os << " dimension ";
os << i << ": [" << index[i] << "]";
dump_map_helper(array, i-1, j, index, os);
}
}
else if (i>0)
{
if (i<j) os << endl;
os.width(6); os << " ";
for (int k=array.f(1); k<=array.l(1); k++)
{
os.width(5); os << k;
}
os << endl;
for (index[0]=array.f(0); index[0]<=array.l(0); index[0]++)
{
os.width(5); os << index[0];
for (index[1]=array.f(1); index[1]<=array.l(1); index[1]++)
{
os.width(5);
if (j==0)
{ os << array(index[0]); }
else if (j==1)
{ os << array(index[0], index[1]); }
else if (j==2)
{ os << array(index[0], index[1], index[2]); }
else if (j==3)
{ os << array(index[0], index[1], index[2], index[3]); }
else
{ os << array(index); }
os << "#";
}
os << endl;
}
}
else
{
for (index[0]=array.f(0); index[0]<=array.l(0); index[0]++)
{
os.width(5); os << index[0];
os.width(5);
if (j==0)
{ os << array(index[0]); }
else if (j==1)
{ os << array(index[0], index[1]); }
else if (j==2)
{ os << array(index[0], index[1], index[2]); }
else if (j==3)
{ os << array(index[0], index[1], index[2], index[3]); }
else
{ os << array(index); }
os << "#" << endl;
}
}
}
}
/*! \brief Dump array values
*
* \ingroup group_helpers
*/
template<class T>
void dump_array(const Array<const T>& array,
const Tdim& i=(Strided::Mmax_dimen-1),
std::ostream& os=std::cout)
{
AFF_assert((i<Strided::Mmax_dimen),
"ERROR (dump_map): illegal dimensionality");
dump(array);
os << " elements through " << i+1 << "dimensional access:" << endl;
Strided::TIndexVec index(array.first());
dump_array_helper(array, i, i, index, os);
}
/*! \brief Dump array shape
*
* \ingroup group_helpers
*/
template<class T>
void dump(const Array<const T>& array, std::ostream& os=std::cout)
{
os << "dump of a Array object layout:" << endl;
os << "=============================:" << endl;
dump(array.shape());
dump(array.representation());
}
/*----------------------------------------------------------------------*/
/*! \brief Dump array shape information
*
* \ingroup group_helpers
*/
void dump(const Strided& shape, std::ostream& os=std::cout);