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

series constructors now useable

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: 1413
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent b668c0cf
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.37 2003-06-27 18:25:13 tforb Exp $
* $Id: README.changelog,v 1.38 2003-12-19 14:38:14 tforb Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -21,12 +21,17 @@
/*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.37 2003-06-27 18:25:13 tforb Exp $
$Id: README.changelog,v 1.38 2003-12-19 14:38:14 tforb Exp $
\sa \ref page_project_status
Major changes in the interface of the library are marked by \b !!.
- \b 19/12/2003 (thof)
- TConstSharedHeap now allocates one element in the default constructor.
- \b !! cleaned all constructors of aff::ConstSeries and aff::Series
- \b !! parameters of constructor of aff::LinearShape have a new meaning
- \b 27/06/2003 (thof)
- introduced aff::Iteratable
- documentation now works for doxygen-1.3.2
......@@ -172,7 +177,7 @@
/*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.37 2003-06-27 18:25:13 tforb Exp $
$Id: README.changelog,v 1.38 2003-12-19 14:38:14 tforb Exp $
\sa \ref page_changelog
......@@ -218,10 +223,8 @@
<TD> </TD>
</TR>
<TR><TD>libaff/series.h</TD>
<TD>17/12/02</TD><TD> </TD><TD> </TD>
<TD>There is a constructor resolution conflict due to default
arguments. <B>Resolving this will affect the interface
definition</B></TD>
<TD>19/12/2003</TD><TD> </TD><TD> </TD>
<TD> </TD>
</TR>
<TR><TD>libaff/shaper.h</TD>
<TD>12/12/02</TD><TD> </TD><TD>18/12/02</TD><TD> </TD>
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: dump_macros.h,v 1.4 2003-01-02 10:33:43 forbrig Exp $
* $Id: dump_macros.h,v 1.5 2003-12-19 14:38:16 tforb Exp $
* \author Thomas Forbriger
* \date 19/12/2002
*
......@@ -22,6 +22,9 @@
* - 19/12/2002 V1.0 Thomas Forbriger
* - 02/01/2003 V1.1 (thof)
* - did not resolve cout and endl in namespace std
* - 19/12/2003 V1.2 (thof)
* - there was a redundant semicolon in the output of
* the CODE macro
*
* ============================================================================
*/
......@@ -32,7 +35,7 @@
#define AFF_DUMP_MACROS_H_VERSION \
"AFF_DUMP_MACROS_H V1.1"
#define AFF_DUMP_MACROS_H_CVSID \
"$Id: dump_macros.h,v 1.4 2003-01-02 10:33:43 forbrig Exp $"
"$Id: dump_macros.h,v 1.5 2003-12-19 14:38:16 tforb Exp $"
#include<iostream>
......@@ -60,7 +63,7 @@
*
* \ingroup group_helpers
*/
#define CODE( C ) std::cout << #C << ";" << std::endl; C
#define CODE( C ) std::cout << #C << std::endl; C
#endif // AFF_DUMP_MACROS_H_VERSION (includeguard)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sharedheap_def.h,v 1.12 2002-12-31 17:19:47 forbrig Exp $
* $Id: sharedheap_def.h,v 1.13 2003-12-19 14:38:16 tforb Exp $
* \author Thomas Forbriger
* \since 08/12/2002
*
......@@ -25,6 +25,9 @@
* - 31/12/2002 V1.3 (thof)
* - NULL is deprecated as pointed out by Wolfgang
* - removed constructor from Theadstruct
* - 19/12/2003 V1.4 (thof)
* - allocate at least one element (default
* constructor)
*
* ============================================================================
*/
......@@ -37,9 +40,9 @@
#ifndef AFF_SHAREDHEAP_DEF_H_VERSION
#define AFF_SHAREDHEAP_DEF_H_VERSION \
"AFF_SHAREDHEAP_DEF_H V1.3"
"AFF_SHAREDHEAP_DEF_H V1.4"
#define AFF_SHAREDHEAP_DEF_H_CVSID \
"$Id: sharedheap_def.h,v 1.12 2002-12-31 17:19:47 forbrig Exp $"
"$Id: sharedheap_def.h,v 1.13 2003-12-19 14:38:16 tforb Exp $"
namespace aff {
......@@ -102,7 +105,7 @@ namespace util {
template <typename T>
inline
ConstSharedHeap<T>::ConstSharedHeap()
: Mheapstruct(new Theapstruct(0)) { }
: Mheapstruct(new Theapstruct(1)) { }
/*----------------------------------------------------------------------*/
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: series.h,v 1.10 2002-12-31 17:19:47 forbrig Exp $
* $Id: series.h,v 1.11 2003-12-19 14:38:15 tforb Exp $
* \author Thomas Forbriger
* \date 17/12/2002
*
......@@ -33,6 +33,10 @@
* ConstSeries (except default constructor, which is
* needed, when object is a container element) as
* suggested by Wolfgang.
* - 19/12/2003 V1.5 (thof)
* - cleaning all constructors and parts of the
* documentation
* - some changes in LinearShape
*
* ============================================================================
*/
......@@ -41,9 +45,9 @@
#ifndef AFF_SERIES_H_VERSION
#define AFF_SERIES_H_VERSION \
"AFF_SERIES_H V1.4"
"AFF_SERIES_H V1.5"
#define AFF_SERIES_H_CVSID \
"$Id: series.h,v 1.10 2002-12-31 17:19:47 forbrig Exp $"
"$Id: series.h,v 1.11 2003-12-19 14:38:15 tforb Exp $"
#include <aff/lib/sharedheap.h>
#include <aff/lib/seriesstepper.h>
......@@ -56,16 +60,25 @@ namespace aff {
*
* aff::Series needs its own shape class to provide an Array compatible
* interface to Iterator.
*
* The shape ist defined by three parameters, which are
* \a first, \a last, and \a base.
* The index \a k of the corresponding series must be in
* (\a first, \a last).
* While the range acessed within the representation is
* (\a first-base, \a last-base).
* Thus the element \a k of the series will be found at index \a k-base
* in the representation.
*/
class LinearShape
{
public:
typedef aff::util::SeriesStepper Tstepper;
LinearShape(): Mfirst(1), Mlast(1), Mbase(1) { }
LinearShape(): Mfirst(0), Mlast(0), Mbase(0) { }
LinearShape(const Tsubscript& first,
const Tsubscript& last,
const Tsize& base):
Mfirst(first), Mlast(last), Mbase(base)
const Tsubscript& firstinrepr):
Mfirst(first), Mlast(last), Mbase(first-firstinrepr)
{
AFF_assert((Mlast>Mfirst),
"ERROR (LinearShape): inconsistent constructor arguments");
......@@ -77,8 +90,9 @@ namespace aff {
//! by size we mean the size defined by the shape
Tsize size() const
{ return(static_cast<Tsize>(Mlast-Mfirst+1)); }
Tsize memory_size() const { return(this->size()); }
private:
Tsubscript Mfirst; //!< first valie index
Tsubscript Mfirst; //!< first valid index
Tsubscript Mlast; //!< last valid index
Tsize Mbase; //!< base for access to representation
}; // LinearShape
......@@ -136,26 +150,17 @@ namespace aff {
/*! \name Constructors
*
* In the shape&representation constructor the argument order is taken
* to be the same as in array. So the rpresentation is the second
* argument. In all other constructors (except the default) the
* representation is first to allow default arguments for the rest.
* There is no reason to construct an aff::ConstSeries from scratch,
* since you can only read from ist. The only three reasons might be:
*
* \warning
* Constructors maybe subject to changes. The third and the fourth are
* indistinguishable from their argument list due to default
* arguments.
* 1. As an element in another container. In that case we will use the
* default constructor.
*
* \todo
* resolve resolution conflicts for constructor selection
* 2. Within a constructor of aff::Series. In that case we will pass a
* shape and a representation.
*
* \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.
* 3. To construct a series from an aff::SharedHeap just to read it
* with tools of aff::ConstSeries.
*/
//@{
//! construct from nothing (empty)
......@@ -165,16 +170,9 @@ namespace aff {
const Trepresentation& representation):
Tshape(shape), Mrepresentation(representation)
{ check_consistency(); }
//! construct from shape definition and representation
ConstSeries(const Trepresentation& representation,
const Tsubscript& first=1):
Tshape(first,representation.size()+first-1,first),
Mrepresentation(representation) { }
//! construct from shape definition and representation
ConstSeries(const Trepresentation& representation,
const Tsize& size, const Tsize& shift=0,
const Tsubscript& first=1):
Tshape(first, (representation.size()-shift+first-1), first-shift),
//! construct from representation
ConstSeries(const Trepresentation& representation):
Tshape(0,representation.size()-1,0),
Mrepresentation(representation) { }
//@}
......@@ -290,48 +288,44 @@ namespace aff {
/*-----------------------------------------------------------------*/
/*! \name Constructors
*
* In the shape&representation constructor the argument order is taken
* to be the same as in array. So the rpresentation is the second
* argument. In all other constructors (except the default) the
* representation is first to allow default arguments for the rest.
*
* \warning
* Constructors maybe subject to changes. The third and the fourth are
* indistinguishable from their argument list due to default
* arguments.
*
* \todo
* resolve resolution conflicts for constructor selection
*
* \note
* We use the default copy constructor, which automatically invokes
* the copy constructors of the base classes aff::Strided and
* the copy constructors of the base classes aff::LinearShape 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
* See aff::Series<T>::copyin() and aff::Series<T>::copyout() for deep
* copy operations.
*/
//@{
//! construct from nothing (empty)
Series() { }
//! construct for a given size
Series(const Tsize& size)
{
Tshape newshape(0, size-1, 0);
Mrepresentation=Trepresentation(newshape.memory_size());
Tbase::operator=(Tbase(newshape, Mrepresentation));
}
//! construct from index range limits
Series(const Tsubscript& first, const Tsubscript& last)
{
Tshape newshape(first, last, 0);
Mrepresentation=Trepresentation(newshape.memory_size());
Tbase::operator=(Tbase(newshape, Mrepresentation));
}
//! construct from shape and representation
Series(const Trepresentation& representation,
const Tsubscript& first=1):
Tbase(representation, first),
Mrepresentation(representation) { }
//! construct from shape and representation
Series(const Trepresentation& representation,
const Tsize& size, const Tsize& shift=0,
const Tsubscript& first=1):
Tbase(representation, size, shift, first),
Mrepresentation(representation) { }
//! construct from index range limit
explicit Series(const Tsize& size, const Tsubscript& first=1)
Series(const Tshape& shape,
const Trepresentation& representation):
Tshape(shape), Mrepresentation(representation)
{ Tbase::operator=(Tbase(shape, Mrepresentation)); }
//! construct from representation
Series(const Trepresentation& representation,
const Tsubscript& shift=0)
{
Tshape shape(first, size+first-1, first);
Mrepresentation=Trepresentation(size);
Tbase::operator=(Tbase(shape, Mrepresentation));
Tshape newshape(shift, shift+representation.size()-1, 0);
Mrepresentation=representation;
Tbase::operator=(Tbase(newshape, Mrepresentation));
}
//@}
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: seriestest.cc,v 1.3 2002-12-29 00:09:07 forbrig Exp $
* $Id: seriestest.cc,v 1.4 2003-12-19 14:38:17 tforb Exp $
* \author Thomas Forbriger
* \date 17/12/2002
*
......@@ -15,13 +15,15 @@
* - 17/12/2002 V1.0 Thomas Forbriger
* - 28/12/2002 V1.1 (thof)
* - new term for containers of const elements
* - 19/12/2003 V1.2 (thof)
* - working on series container
*
* ============================================================================
*/
#define AFF_SERIESTEST_CC_VERSION \
"AFF_SERIESTEST_CC V1.1"
"AFF_SERIESTEST_CC V1.2"
#define AFF_SERIESTEST_CC_CVSID \
"$Id: seriestest.cc,v 1.3 2002-12-29 00:09:07 forbrig Exp $"
"$Id: seriestest.cc,v 1.4 2003-12-19 14:38:17 tforb Exp $"
#include <aff/series.h>
#include <aff/dump.h>
......@@ -36,9 +38,6 @@ using std::endl;
* \sa tests/seriestest.cc
*/
//! echo
#define CODE( C ) cout << #C << endl; C
//! print headline
void section(const char* s)
{
......@@ -60,49 +59,23 @@ int main()
section("array dimensions");
CODE( const int N=10; )
CODE( const int N2=23; )
section("instantiate arrays");
CODE( aff::SharedHeap<int> A(N); )
CODE( aff::SharedHeap<int> B(N2); )
CODE( aff::ConstSharedHeap<int> C(N2); )
CODE( aff::SharedHeap<float> D(N2); )
section("create a const reference to D");
CODE( aff::SharedHeap<float>::Tcoc E(D); )
CODE( const int N2=-5; )
section("const int array should share memory with int array");
CODE( C=B; )
section("fill arrays");
CODE( for (int i=0; i<N; i++) { A[i]=(i+1)*10; } )
CODE( for (int i=0; i<N2; i++) { B[i]=(i+4)*3; } )
CODE( for (int i=0; i<N2; i++) { D[i]=(i+2.45)*2; } )
section("dump contents - C is filled through B and E is filled through D");
DUMP( aff::SharedHeap<int>::Tcontainer_of_const(A) );
section("create a series container");
CODE( aff::Series<int> A; )
CODE( aff::Series<int> B(4); )
CODE( aff::Series<int> C(-5,5); )
DUMP( A );
DUMP( B );
DUMP( C );
DUMP( E );
section("modify C through B");
CODE( B[8]=632; )
DUMP( C );
CODE( A=B; )
DUMP( A );
CODE( aff::ConstSeries<int> D(C); )
CODE( for (int i=C.first(); i<=C.last(); i++) { C(i)=i; } )
DUMP( D );
#ifdef ILLEGAL1
// you may activate this section by passing -DILLEGAL1 to the compiler
section("modify C directly - is illegal");
C[9]=354;
DUMP( C );
CODE( D(6)=10; )
#endif
section("make B a reference to A");
CODE( B=A; )
section("modification should be visible through B");
CODE( A[5]=453; )
DUMP( B );
section("but C holds the original values");
DUMP( C );
}
/* ----- END OF seriestest.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