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

proceeding with code review

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: 1191
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 50917012
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: array_dec.h,v 1.4 2002-12-12 22:08:19 forbrig Exp $
* $Id: array_dec.h,v 1.5 2002-12-13 22:38:24 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -29,7 +29,7 @@
#define AFF_ARRAY_DEC_H_VERSION \
"AFF_ARRAY_DEC_H V1.0 "
#define AFF_ARRAY_DEC_H_CVSID \
"$Id: array_dec.h,v 1.4 2002-12-12 22:08:19 forbrig Exp $"
"$Id: array_dec.h,v 1.5 2002-12-13 22:38:24 forbrig Exp $"
#include <aff/sharedheap.h>
#include <aff/strided.h>
......@@ -74,12 +74,27 @@ namespace prebuilt {
*
* \todo
* Explain the new concept of multidimensional array indexing
*
* \sa aff::Strided
* \sa aff::SharedHeap<T>
* \sa aff::Array<T>::copyin()
* \sa aff::Array<T>::copyout()
*/
template<class T>
class Array:
public aff::Strided, public aff::SharedHeap<T>
{
public:
/*! \name Various types
*
* In particular due to our concept of const-correctness we need
* several typedefs to declare types derived from the element type of
* the array.
*
* \sa \ref sec_main_constness
* \sa aff::util::Qualified<T>
*/
//@{
//! Type of representation
typedef aff::SharedHeap<T> Trepresentation;
//! Type of subscriptor
......@@ -100,9 +115,40 @@ namespace prebuilt {
typedef Array<T> Tcontainer;
//! Type of the array of const values
typedef Array<Tconst_value> Tcontainer_of_const;
//! short for container of const
/*! \brief short for Tcontainer_of_const
*
* We generally distinguish between constness of the array and
* constness of the contained data (see \ref sec_main_constness).
* There will be situations, when you want to promise that a function
* will not change the contents of an array. In this case you may use
* a declaration (prototype) like
* \code
* typedef aff::Array<int> Tmyarray;
* void myfunction(const Tmyarray::Tcoc& array);
* \endcode
* and you may use this function like
* \code
* Tmyarray A(6,7);
* A=4;
* myfunction(A);
* \endcode
*/
typedef Array<Tconst_value> Tcoc;
//@}
/*-----------------------------------------------------------------*/
/*! \name Constructors
*
* \note
* We use the default copy constructor, which automatically invokes
* the copy constructors of the base classes aff::Strided and
* aff::SharedHeap<T>. This essentially is a shallow copy of the
* array, i.e. the copy will reference to the same elements in memory.
* See aff::Array<T>::copyin() and aff::Array<T>::copyout() for deep
* copy operations.
*/
//@{
//! construct from nothing (empty)
Array() { }
//! construct from shape and representation
......@@ -119,7 +165,13 @@ namespace prebuilt {
//! construct from index range limits
Array(const Tsize& s0, const Tsize& s1,
const Tsize& s2, const Tsize& s3);
//@}
/*-----------------------------------------------------------------*/
/*! \name Access operators
*/
//@{
//! full dimensionality access
Tvalue& operator()(const TIndexVec& index)
{ return(this->Trepresentation::operator[](
......@@ -146,7 +198,19 @@ namespace prebuilt {
const Tsubscript& i3)
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1, i2, i3))); }
//@}
/*-----------------------------------------------------------------*/
/*! \name Const access operators
*
* Although we generally distinguish between the constness of the
* container and the constness of the contained data (see
* \ref sec_main_constness), we provide const element access operators
* the prohibit element modification. We assume that a const version
* of the array is usually meant to be used only for reading.
*/
//@{
//! full dimensionality access
const Tvalue& operator()(const TIndexVec& index) const
{ return(this->Trepresentation::operator[](
......@@ -173,6 +237,9 @@ namespace prebuilt {
const Tsubscript& i3) const
{ return(this->Trepresentation::operator[](
this->Tshape::offset(i0, i1, i2, i3))); }
//@}
/*-----------------------------------------------------------------*/
//! conversion to container of const values
operator Tcontainer_of_const() const
......@@ -181,6 +248,9 @@ namespace prebuilt {
return(retval);
}
/*! \name Shape access
*/
//@{
//! return first index of dimension i
const Tsubscript& f(const Tsubscript& i) const
{ return(this->Tshape::first(i)); }
......@@ -194,17 +264,60 @@ namespace prebuilt {
//! by size we mean the size defined by the shape
Tsize size() const
{ return(this->Tshape::size()); }
//@}
//! set whole array to value
Array& operator=(const T& value);
//! create an identical COPY (deep copy) of this array
/*! \name Deep copy
*/
//@{
/*! \brief create an identical copy (deep copy) of this array
*
* This is mainly used to create a copy of a truely identical array
* (i.e. array with same element type or at least const version of
* same element type). Use this function in conjunction with the
* assignment operator. E.g.:
* \code
* aff::Array<int> A(3,4);
* A=5.;
* aff::Array<int> B, C;
* B=A.copyout();
* C=A;
* \endcode
* Here arrays \c A and \c B have exactly the same contents but use
* different memory. While changes to elements of \c C will also
* affect elements of \c A, this not the case for changes applied to
* \c B.
*/
Array copyout() const;
//! COPY values (deep copy) from other array of convertible type
//! (returns itself)
/*! \brief copy values (deep copy) from other array of convertible type
*
* This member function reads the element values of another array of
* same shape and applies them to this array. In fact the shape needs
* not be the same. The copy is done through sequential access and as
* most number as possible will be copied in increasing memory address
* order.
*
* Example:
* \code
* aff::Array<float> A(24);
* A=15.
* aff::Array<double> B(3,8);
* B.copyin(A);
* \endcode
* \c B will preserve its shape but is filled with the contents of
* \c A (which are not where interesting in this example). Changes
* applied to the contents of B will not affect the contents of A.
*
* \param a other array with element type convertible to element type
* of this array
* \return itself
*/
template<class TT>
Array& copyin(const Array<TT>& a);
//@}
}; // class Array
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: error.h,v 1.1 2002-12-10 19:30:07 forbrig Exp $
* $Id: error.h,v 1.2 2002-12-13 22:38:24 forbrig Exp $
* \author Thomas Forbriger
* \date 27/11/2002
*
......@@ -28,7 +28,7 @@
#define AFF_ERROR_H_VERSION \
"AFF_ERROR_H V1.0 "
#define AFF_ERROR_H_CVSID \
"$Id: error.h,v 1.1 2002-12-10 19:30:07 forbrig Exp $"
"$Id: error.h,v 1.2 2002-12-13 22:38:24 forbrig Exp $"
namespace aff {
......@@ -42,7 +42,7 @@ namespace aff {
* through function report(). This function may be overloaded by a derived
* type. But its functionality is still accessible through base_report().
*
* The standard behaviour is to print ou the message during object
* The standard behaviour is to print out the message during object
* initialization. If you don't like this, call dont_report_on_construct().
*
* \ingroup group_error
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: range.h,v 1.2 2002-12-08 22:33:53 forbrig Exp $
* $Id: range.h,v 1.3 2002-12-13 22:38:24 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -26,7 +26,7 @@
#define AFF_RANGE_H_VERSION \
"AFF_RANGE_H V1.0 "
#define AFF_RANGE_H_CVSID \
"$Id: range.h,v 1.2 2002-12-08 22:33:53 forbrig Exp $"
"$Id: range.h,v 1.3 2002-12-13 22:38:24 forbrig Exp $"
namespace aff {
......@@ -34,14 +34,6 @@ namespace aff {
namespace prebuilt {
#endif
#ifdef AFF_PREBUILT
using namespace aff::prebuilt::util;
using aff::prebuilt::util::Tsubscript;
#else
using namespace aff::util;
using aff::util::Tsubscript;
#endif
/*! \brief Class to hold and manipulate index ranges.
*
* \param T type of value (usually aff::util::Tsubscript, but may differ)
......@@ -54,6 +46,11 @@ template<class T=Tsubscript>
public:
//! element type
typedef T Tvalue;
/*-----------------------------------------------------------------*/
//! \name Constructors
//@{
//! empty range
Range(): Mfirst(0), Mlast(0) { }
//! range containing exactly one element
......@@ -62,6 +59,12 @@ template<class T=Tsubscript>
Range(const Tvalue& first, const Tvalue& last):
Mfirst(first<last ? first:last),
Mlast(last>first ? last:first) { }
//@}
/*-----------------------------------------------------------------*/
//! \name Access and query functions
//@{
//! access start of range
Tvalue& first() { return Mfirst; }
//! access end of range
......@@ -76,6 +79,13 @@ template<class T=Tsubscript>
//! does this range contain the other
bool contains(const Range& other) const
{ return ((Mfirst <= other.first()) && (Mlast >= other.last())); }
//@}
/*-----------------------------------------------------------------*/
/*! \name Operations modifying the range
*/
//@{
//! shrink to smaller of this and the other
Range& shrink(const Range& other)
{
......@@ -99,6 +109,10 @@ template<class T=Tsubscript>
//! shift by -n
Range& operator-=(const Tvalue& n)
{ return this->shift(-n); }
//@}
/*-----------------------------------------------------------------*/
private:
Tvalue Mfirst; //!< start of range.
Tvalue Mlast; //!< end of range.
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sharedheap.h,v 1.5 2002-12-12 22:08:20 forbrig Exp $
* $Id: sharedheap.h,v 1.6 2002-12-13 22:38:24 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -26,7 +26,7 @@
#define AFF_SHAREDHEAP_H_VERSION \
"AFF_SHAREDHEAP_H V1.2 "
#define AFF_SHAREDHEAP_H_CVSID \
"$Id: sharedheap.h,v 1.5 2002-12-12 22:08:20 forbrig Exp $"
"$Id: sharedheap.h,v 1.6 2002-12-13 22:38:24 forbrig Exp $"
#include<new>
#include<aff/lib/error.h>
......@@ -39,11 +39,11 @@ namespace aff {
namespace prebuilt {
#endif
#ifdef AFF_PREBUILT
using namespace aff::prebuilt::util;
#else
using namespace aff::util;
#endif
//#ifdef AFF_PREBUILT
// using namespace aff::prebuilt::util;
//#else
// using namespace aff::util;
//#endif
/*! \brief Exception thrown in case of allocation error
*
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sharedheap_def.h,v 1.3 2002-12-10 19:30:07 forbrig Exp $
* $Id: sharedheap_def.h,v 1.4 2002-12-13 22:38:24 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -11,7 +11,7 @@
*
* \note
* Never include this header directly. Here you find code factored out from
* the aff:SharedHeap class. This code may be compiled into a binary library.
* the aff::SharedHeap class. This code may be compiled into a binary library.
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -31,7 +31,7 @@
#define AFF_SHAREDHEAP_DEF_H_VERSION \
"AFF_SHAREDHEAP_DEF_H V1.0 "
#define AFF_SHAREDHEAP_DEF_H_CVSID \
"$Id: sharedheap_def.h,v 1.3 2002-12-10 19:30:07 forbrig Exp $"
"$Id: sharedheap_def.h,v 1.4 2002-12-13 22:38:24 forbrig Exp $"
namespace aff {
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: simplearray.h,v 1.3 2002-12-11 20:58:10 forbrig Exp $
* $Id: simplearray.h,v 1.4 2002-12-13 22:38:24 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -31,7 +31,7 @@
#define AFF_SIMPLEARRAY_H_VERSION \
"AFF_SIMPLEARRAY_H V1.1 "
#define AFF_SIMPLEARRAY_H_CVSID \
"$Id: simplearray.h,v 1.3 2002-12-11 20:58:10 forbrig Exp $"
"$Id: simplearray.h,v 1.4 2002-12-13 22:38:24 forbrig Exp $"
#include<aff/lib/types.h>
#include<aff/lib/rawarfun.h>
......@@ -90,20 +90,54 @@ namespace prebuilt {
public:
//! element type
typedef T Telement;
/*-----------------------------------------------------------------*/
/*! \name Constructors
*/
//@{
//! construct without initializing
SimpleRigidArray() { }
//! set constructor
explicit SimpleRigidArray(const T& value)
{ inline_set<T,N>(Marray, value); }
template<class TT>
explicit SimpleRigidArray(const TT& value)
{
aff::util::Inline2<T, TT, N>::inline_set(Marray, value);
}
//! copy with deep inline copy
SimpleRigidArray(const SimpleRigidArray<T, N>& array)
{ inline_copy<T,N>(array.Marray, Marray); }
template<class TT>
SimpleRigidArray(const SimpleRigidArray<TT, N>& array)
{
aff::util::Inline2<TT, T, N>::inline_copy(array.Marray, Marray);
}
//@}
/*-----------------------------------------------------------------*/
/*! \name Operators
*/
//@{
//! copy with deep inline copy
SimpleRigidArray& operator=(const SimpleRigidArray<T, N>& array)
{ inline_copy<T,N>(array.Marray, Marray); return(*this); }
template<class TT>
SimpleRigidArray& operator=(const SimpleRigidArray<TT, N>& array)
{
aff::util::Inline2<TT, T, N>::inline_copy(array.Marray, Marray);
return(*this);
}
//! copy a value to all positions
SimpleRigidArray& operator=(const T& value)
{ inline_set<T,N>(Marray, value); return(*this); }
template<class TT>
SimpleRigidArray& operator=(const TT& value)
{
aff::util::Inline2<T, TT, N>::inline_set(Marray, value);
return(*this);
}
//@}
/*-----------------------------------------------------------------*/
/*! \name Access
*/
//@{
//! access
T& operator[](const Tsubscript& i) { return Marray[i]; }
//! const access
......@@ -114,10 +148,17 @@ namespace prebuilt {
const T* pointer() const { return Marray; }
//! size of array
Tsize size() const { return N; }
//@}
/*-----------------------------------------------------------------*/
private:
T Marray[N];
}; // Simple Array
/*======================================================================*/
// inlined operations
//! Product of all elements
template<typename T, Tsize N>
inline T inline_product(const SimpleRigidArray<T, N>& array)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: strided.h,v 1.6 2002-12-13 14:56:03 forbrig Exp $
* $Id: strided.h,v 1.7 2002-12-13 22:38:24 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -32,6 +32,8 @@
* - documentation is still missing
* - 13/12/2002 V1.3 (thof)
* - correct definition of mapping formula
* - provides enough basic functionality
* (including access needed by stepper)
*
* ============================================================================
*/
......@@ -42,7 +44,7 @@
#define AFF_STRIDED_H_VERSION \
"AFF_STRIDED_H V1.3"
#define AFF_STRIDED_H_CVSID \
"$Id: strided.h,v 1.6 2002-12-13 14:56:03 forbrig Exp $"
"$Id: strided.h,v 1.7 2002-12-13 22:38:24 forbrig Exp $"
#include<aff/lib/types.h>
#include<aff/lib/simplearray.h>
......@@ -90,13 +92,16 @@ namespace prebuilt {
* operator. In formula \f$ f_k \f$ are the elements of \c Mfirst,
* \f$ s_k \f$ are the elements of \c Mstride,
* \f$ b_l \f$ are the elements of \c Mbase, and
* \f$ o \f$ is \c Moffset (i.e. the first accessible position within the
* \f$ o \f$ is \c Mbase[0] (i.e. the first accessible position within the
* representation.
*
*/
class Strided {
public:
//! maximum dimensionality
/*! maximum dimensionality
* \note
* Some parts of the code rely on \c Mmax_dimen>=2.
*/
static const Tdim Mmax_dimen=4;
//! type of size and stride array (always positive)
......@@ -104,6 +109,11 @@ namespace prebuilt {
//! type of limit arrays (any sign)
typedef SimpleRigidArray<Tsubscript, Mmax_dimen> TIndexVec;
/*-----------------------------------------------------------------*/
/*! \name Constructors
*/
//@{
//! construct and initialize to zero
Strided(): Mstride(0), Mfirst(0), Msize(0), Mbase(0), Moffset(0) { }
/*! \brief construct do given size and first index
......@@ -124,6 +134,9 @@ namespace prebuilt {
*/
Strided(const TIndexVec& first, const TIndexVec& last,
const Tsubscript& shift=0);
//@}
/*-----------------------------------------------------------------*/
/*! \name Access to shape
*
......@@ -133,29 +146,42 @@ namespace prebuilt {
Tsize memory_size() const
{ return (offset(Mlast)-offset(Mfirst)+1); }
//! total number of mapped elements
Tsize size() const
{ return inline_product(Msize); }
Tsize size() const;
//! first mapped position
const Tsubscript& first_offset() const
{ return offset(Mfirst[0]); }
//! last mapped position
const Tsubscript& last_offset() const
{ return offset(Mlast); }
//! first index of dimension \par i
const Tsubscript& first(const Tsubscript& i) const
{ return Mfirst[i]; }
//! last index of dimension \par i
Tsubscript last(const Tsubscript& i) const
{ return (Mfirst[i]+Msize[i]-1); }
{ return (Mlast[i]); }
//! size of dimension \par i
const Tsize& size(const Tsubscript& i) const
{ return Msize[i]; }
{ return (static_cast<Tsize>(Mlast[i]-Mfirst[i]+1)); }
//! stride of dimension \par i
const Tsize& stride(const Tsubscript& i) const
{ return Mstride[i]; }
//! return vector of first index values
const TIndexVec& first() const { return(Mfirst); }
//! return vector of last index values
const TIndexVec& last() const { return(Mlast); }
//! return vector of stride values
const TSizeVec& stride() const { return(Mstride); }
//@}
/*-----------------------------------------------------------------*/
/*! \name Map index values to linear representation range
*
*/
//@{
//! full dimensionality access
Tsubscript offset()(const TIndexVec& index) const
{ return(inner_product(index,Mstride)+Moffset); }
{ return(inner_product(index,Mstride)+Mbase[Mmax_dimen-1]); }
//! offset from 1 index value
Tsubscript offset()(const Tsubscript& i0) const
{ return(i0*Mstride[0]+Mbase[0]); }
......@@ -177,32 +203,35 @@ namespace prebuilt {
i3*Mstride[3]+Mbase[3]); }
//@}
/*-----------------------------------------------------------------*/
/*! \name Support for slices and subarrays
*
*/
//@{
//! subarrays
//! subarray
void shrink(const TIndexVec& last);
//! subarrays
//! subarray
void shrink(const TIndexVec& first, const TIndexVec& last);
//! subarrays
//! subarray
void shrink(const Tdim& i,
const Tsubscript& first, const Tsubscript& last);
//! subarrays
//! subarray
void shrink(const Tdim& i,
const Tsubscript& last);
//! slice
void collapse(const Tdim& i, const Tsubscript& index);
//@}
/*-----------------------------------------------------------------*/
private:
void calculate_base() const;
void calculate_base(const Tsubscript& offset) const;
TSizeVec Mstride; //<! strides for each dimension
TIndexVec Mfirst; //<! first index of each dimension
TSizeVec Msize; //<! size of each dimension
TIndexVec Mlast; //<! last index of each dimension
TIndexVec Mbase; //<! base for each dimension (see index operators)
Tsubscript Moffset; //<! total offset for indexing
};
#ifdef AFF_PREBUILT
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: strided_def.h,v 1.4 2002-12-12 22:08:20 forbrig Exp $
* $Id: strided_def.h,v 1.5 2002-12-13 22:38:24 forbrig Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*