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

array resolution within deepcopy

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.
and thoughts about Barton and Nackman trick


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1272
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 46f5e99f
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.17 2003-01-03 17:24:58 forbrig Exp $
# $Id: Makefile,v 1.18 2003-01-04 11:10:22 forbrig Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -23,6 +23,7 @@
# 06/12/2002 V1.0 Thomas Forbriger
# 27/12/2002 V1.1 doxygen reads Fortran code and files generated by f2c
# 03/01/2003 V1.2 improved white-space-eating awk-script
# 04/01/2003 V1.3 corrected yesterday's change
#
# ============================================================================
#
......@@ -237,7 +238,7 @@ binarray_%.d: binarray.cc
/^#/ { hot=0; } \
{ if (hot==2) { print ""; } else if (hot) { print; } }' $< > $@
$(REMCMMNT) $< | awk 'BEGIN {hot=0;} \
/^ *$$/ { if ((hot) && ($(EMPTYPRINT))) { print "\n"; } next; } \
/^ *$$/ { if ((hot) && ($(EMPTYPRINT))) { print ""; } next; } \
/^#/ { hot=1; } { if (hot) print; }' >> $@
#----------------------------------------------------------------------
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README,v 1.20 2003-01-02 11:57:55 forbrig Exp $
* $Id: README,v 1.21 2003-01-04 11:10:22 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -40,6 +40,9 @@
* - reflect changes to Subarray and Slice
* - tell about class hierarchies and member data vs.
* inheritance
* - 04/01/2003 V1.4 (thof)
* - added section about Tcontainer typedef
* (\ref sec_design_interface_tcontainer)
*
* ============================================================================
*/
......@@ -65,7 +68,7 @@ namespace aff {
\since December 2002
\date December 2002
\version V1.0
$Id: README,v 1.20 2003-01-02 11:57:55 forbrig Exp $
$Id: README,v 1.21 2003-01-04 11:10:22 forbrig Exp $
Contents of this page:
- \ref sec_main_aims
......@@ -203,6 +206,7 @@ See also "\ref sec_design_multidimensional".
- \ref sec_design_interface
- \ref sec_design_interface_sparse
- \ref sec_design_interface_typedef
- \ref sec_design_interface_tcontainer
- \ref sec_design_interface_internals
- \ref sec_design_hierarchy
- \ref sec_design_replicated
......@@ -291,6 +295,102 @@ See also "\ref sec_design_multidimensional".
need not modify all your shell scripts. Now consider one day your shape
class might be renamed...
\subsection sec_design_interface_tcontainer Member typedef Tcontainer
\par Design decision:
Every class that can be converted to a container type, should provide a
member typedef \c Tcontainer and an appropriate conversion operator.
\sa aff::util::Slice
\sa aff::util::Subarray
\sa aff::deepcopy
\par Background
aff::deepcopy is a good example for function designed to deal with any
container. There may be others in the future, like global arithmetic
operators or sum-reduction. Due to its generality the function template puts
no restrictions on its template arguments. You may instantiate that template
for any class. In some sense this is bad practice and we have to resolve
ambiguities and support type conversions. In particular, think of feeding a
subarray (class aff::util::Subarray) to one of these whole-array functions
(this might be one of the most interesting uses). aff::util::Subarray easily
matches the template parameter, but does not offer the member functions
necessary for element access.
\par
Hence we must ensure conversion of the aff::util::Subarray to its container
class. In our concept this is done with in aff::deepcopy. It looks for a
Tcontainer typedef in the argument class definitions and converts the class
objects to its corresponding container class before the copy operation.
\par
Barton and Nackman propose another concept. Using their scheme we would
introduce a general Container class,
\code
template<class C>
class Container {
public:
typedef C& Tcontainer_reference;
Container(Tcontainer_reference c): M(c) { }
operator Tcontainer_reference() { return(M); }
private:
Tcontainer_reference M;
};
\endcode
that takes a special container class as
a template argument and initializes a member data reference to an object of
this class in its constructors. We would then derive aff::Array from this
class by
\code
template<class T>
class Array: public Container<Array <T> > { };
\endcode
This way any reference to a container (aff::Array, aff:Series,
aff::ConstArray, etc.) can be converted to a Container class object, which
agein offers a conversion operator to a reference to its leaf class.
Container-specific functions then are declared
\code
template<class S, class T>
void deecopy(const Container<S>& source, Container<T>& target);
\endcode
deepcopy than can only be called for objects that are derived from
Container.
\par Trade-offs
The Barton and Nackman trick involves another member data field in each
container class to hold the reference in the Container base class.
aff::Array would have to extra member data fields, because aff::Array and
aff::ConstArray both must inherit from Container. I regard this as a partial
violation to our concept of sparse interfaces. and small data types and
discard this option.
\par
However, our concept requires to create a full copy of at least the target
container in each whole-array operation. This would not be necessary
generally. Generally we would operate directly on the aff::Array reference
passed as target of the operation.
\par
With the Barton and Nackman trick this copy operation would only be
necessary with class objects, that are not directly derived from Container,
as are aff::util::Subarray and companions. However, for those we would have
to introduce specializations (overloaded functions) of whole-array
operations, that first perform the conversion (creating an aff::Array or
else) and then call the function that takes Container arguments.
\par Alternative
The cheapest alternative (with respect to runtime overhead in the
whole-array function and in the container classes aff::Array, etc.) is to
delegate the problem to aff::util::Subarray and companions. We could
introduce a member data field in them of type Tarray. This would allow for a
member function returning a reference to this member. There should be no
runtime overhead, since every subarray must once be converted to an array to
be useful (now this conversion takes place outside aff::util::Subarray).
But this would involve the inconvenience to call an extra member function in
Subarray, when passing to a whole-array function.
The template argument type of the corresponding whole-array function remains
unrestricted (totally unchecked).
\subsection sec_design_interface_internals Accessing internals
Providing extended functionality outside of aff::Array (see
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.33 2003-01-03 22:20:21 forbrig Exp $
* $Id: README.changelog,v 1.34 2003-01-04 11:10:23 forbrig Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -21,12 +21,17 @@
/*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.33 2003-01-03 22:20:21 forbrig Exp $
$Id: README.changelog,v 1.34 2003-01-04 11:10:23 forbrig Exp $
\sa \ref page_project_status
Major changes in the interface of the library are marked by \b !!.
- \b 04/01/2003 (thof)
- aff::deepcopy now converts to Tcontainer. And aff::util::Subarray
and aff::util::Slice therefore provide a Tcontainer typedef. See also
"\ref sec_design_interface_tcontainer".
- \b 03/01/2003 (thof)
- introduced lib/checkedcast.h and aff::util::SizeCheckedCast
- \b !! aff::FortranArray now takes container type as template argument
......@@ -158,7 +163,7 @@
/*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.33 2003-01-03 22:20:21 forbrig Exp $
$Id: README.changelog,v 1.34 2003-01-04 11:10:23 forbrig Exp $
\sa \ref page_changelog
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: deepcopy.h,v 1.2 2003-01-03 22:20:28 forbrig Exp $
* $Id: deepcopy.h,v 1.3 2003-01-04 11:10:23 forbrig Exp $
* \author Thomas Forbriger
* \date 29/12/2002
*
......@@ -17,7 +17,11 @@
*
* REVISIONS and CHANGES
* - 29/12/2002 V1.0 Thomas Forbriger
* - 03/01/2003 V1.1 placed deepcopy in namespace aff
* - 03/01/2003 V1.1 (thof)
* - placed deepcopy in namespace aff
* - 04/01/2003 V1.2 (thof)
* - now is able to handle slice and subarray classes
* if they provide an appropriate Tcontainer typedef
*
* ============================================================================
*/
......@@ -26,9 +30,9 @@
#ifndef AFF_DEEPCOPY_H_VERSION
#define AFF_DEEPCOPY_H_VERSION \
"AFF_DEEPCOPY_H V1.1"
"AFF_DEEPCOPY_H V1.2"
#define AFF_DEEPCOPY_H_CVSID \
"$Id: deepcopy.h,v 1.2 2003-01-03 22:20:28 forbrig Exp $"
"$Id: deepcopy.h,v 1.3 2003-01-04 11:10:23 forbrig Exp $"
namespace aff {
......@@ -47,20 +51,22 @@ namespace aff {
void deepcopy(const S& source, T& target)
{
// acces source through container of const (read only access)
typedef typename S::Tcoc Tscoc;
typedef typename S::Tcontainer::Tcoc Tscoc;
typedef typename Tscoc::Trepresentation Tsrep;
typedef typename Tscoc::Tstepper Tsstp;
// access types for target
typedef typename T::Trepresentation Ttrep;
typedef typename T::Tstepper Ttstp;
// alias for source
Tscoc csource(source);
typedef typename S::Tcontainer Ttcon;
typedef typename Ttcon::Trepresentation Ttrep;
typedef typename Ttcon::Tstepper Ttstp;
// alias for source and target
const Tscoc& csource(source);
Ttcon ctarget(target);
// representations
Tsrep srep(csource.representation());
Ttrep trep(target.representation());
Ttrep trep(ctarget.representation());
// steppers
Tsstp sstp(csource.shape());
Ttstp tstp(target.shape());
Ttstp tstp(ctarget.shape());
sstp.tofirst();
tstp.tofirst();
while (sstp.valid() && tstp.valid())
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: slice.h,v 1.4 2003-01-02 11:50:54 forbrig Exp $
* $Id: slice.h,v 1.5 2003-01-04 11:10:23 forbrig Exp $
* \author Thomas Forbriger
* \date 19/12/2002
*
......@@ -20,6 +20,9 @@
* operator
* - 02/01/2003 V1.2 (thof)
* - function slice was placed outside namespace aff
* - 04/01/2003 V1.3 (thof)
* - now provides a Tcontainer typedef (see
* aff::deepcopy)
*
* ============================================================================
*/
......@@ -28,9 +31,9 @@
#ifndef AFF_SLICE_H_VERSION
#define AFF_SLICE_H_VERSION \
"AFF_SLICE_H V1.2"
"AFF_SLICE_H V1.3"
#define AFF_SLICE_H_CVSID \
"$Id: slice.h,v 1.4 2003-01-02 11:50:54 forbrig Exp $"
"$Id: slice.h,v 1.5 2003-01-04 11:10:23 forbrig Exp $"
#include<aff/array.h>
......@@ -50,6 +53,8 @@ namespace util {
public:
//! Type of array to be handled
typedef C Tarray;
//! Type of array to be handled
typedef C Tcontainer;
//! Type of const element
typedef typename Tarray::Tconst_value Tconst_value;
//! Type of reference to const element
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: subarray.h,v 1.3 2002-12-29 16:57:28 forbrig Exp $
* $Id: subarray.h,v 1.4 2003-01-04 11:10:23 forbrig Exp $
* \author Thomas Forbriger
* \date 19/12/2002
*
......@@ -18,6 +18,9 @@
* - removed default constructor and bracket operator
* of container object
* - introduced aff::subarray
* - 04/01/2003 V1.2 (thof)
* - now provides a Tcontainer typedef (see
* aff::deepcopy)
*
* ============================================================================
*/
......@@ -26,9 +29,9 @@
#ifndef AFF_SUBARRAY_H_VERSION
#define AFF_SUBARRAY_H_VERSION \
"AFF_SUBARRAY_H V1.0 "
"AFF_SUBARRAY_H V1.2"
#define AFF_SUBARRAY_H_CVSID \
"$Id: subarray.h,v 1.3 2002-12-29 16:57:28 forbrig Exp $"
"$Id: subarray.h,v 1.4 2003-01-04 11:10:23 forbrig Exp $"
#include<aff/array.h>
......@@ -55,6 +58,8 @@ namespace util {
public:
//! Type of array to be handled
typedef C Tarray;
//! Type of array to be handled
typedef C Tcontainer;
//! Type of const element
typedef typename Tarray::Tconst_value Tconst_value;
//! Type of reference to const element
......
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