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

array interface to raw memory is available

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/branches/libfourier
SVN Revision: 3945
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent a5a48831
......@@ -89,6 +89,8 @@ namespace aff {
* not reference counted.
* Make sure to keep an instance of one of the arrays maintining the
* underlying memory allocation as long as these pointers are in use.
*
* \sa helpertest.cc
*/
template<class T>
class ConstCArray
......@@ -105,25 +107,25 @@ namespace aff {
*/
//@{
//! Type of array to be interfaced
typedef aff::ConstArray<T> Tarray;
typedef ConstArray<T> Tarray;
//! Type of representation
typedef Tarray::Trepresentation Trepresentation;
typedef typename Tarray::Trepresentation Trepresentation;
//! Type of shape
typedef Tarray::Tshape Tshape;
typedef typename Tarray::Tshape Tshape;
//! we use this for one of the access operators
typedef Tshape::TSizeVec TSizeVec;
typedef typename Tshape::TSizeVec TSizeVec;
//! Element type
typedef Tarray::Tvalue Tvalue;
typedef typename Tarray::Tvalue Tvalue;
//! Type of pointer to element
typedef Tarray::Tpointer Tpointer;
typedef typename Tarray::Tpointer Tpointer;
//! Type of reference to element
typedef Tarray::Treference Treference;
typedef typename Tarray::Treference Treference;
//! const element type
typedef Tarray::Tconst_value Tconst_value;
typedef typename Tarray::Tconst_value Tconst_value;
//! Type of pointer to const element
typedef Tarray::Tconst_pointer Tconst_pointer;
typedef typename Tarray::Tconst_pointer Tconst_pointer;
//! Type of reference to const element
typedef Tarray::Tconst_reference Tconst_reference;
typedef typename Tarray::Tconst_reference Tconst_reference;
//! Type of this array
typedef ConstCArray<T> Tcontainer;
//! Type of the array of const values
......@@ -146,14 +148,14 @@ namespace aff {
{
Tshape shape=array.shape();
// index range is zero based
shape.setfirst(Tshape::TIndexVec(0));
shape.setfirst(typename Tshape::TIndexVec(0));
// offset to first element in represented memory
Moffset=shape.first_offset();
// strides
Mstride=shape.stride();
// sizes
Msize=shape.last();
for (int i=0; i<Msize.size(); ++i)
for (unsigned i=0; i<Msize.size(); ++i)
{
++Msize[i];
}
......@@ -204,7 +206,7 @@ namespace aff {
protected:
//! pass offset to derived class
const TSizeVec::Tvalue& offset() const { return Moffset; }
const typename TSizeVec::Tvalue& offset() const { return Moffset; }
private:
//! representation member
......@@ -214,7 +216,7 @@ namespace aff {
//! strides of dimensions
TSizeVec Mstride;
//! offset to first index
TSizeVec::Tvalue Moffset;
typename TSizeVec::Tvalue Moffset;
}; // class ConstCArray
......@@ -246,23 +248,23 @@ namespace aff {
//! Base class
typedef aff::ConstCArray<T> Tbase;
//! Type of representation
typedef Tarray::Trepresentation Trepresentation;
typedef typename Tarray::Trepresentation Trepresentation;
//! Type of shape
typedef Tarray::Tshape Tshape;
typedef typename Tarray::Tshape Tshape;
//! we use this for one of the access operators
typedef Tshape::TSizeVec TSizeVec;
typedef typename Tshape::TSizeVec TSizeVec;
//! Element type
typedef Tarray::Tvalue Tvalue;
typedef typename Tarray::Tvalue Tvalue;
//! Type of pointer to element
typedef Tarray::Tpointer Tpointer;
typedef typename Tarray::Tpointer Tpointer;
//! Type of reference to element
typedef Tarray::Treference Treference;
typedef typename Tarray::Treference Treference;
//! const element type
typedef Tarray::Tconst_value Tconst_value;
typedef typename Tarray::Tconst_value Tconst_value;
//! Type of pointer to const element
typedef Tarray::Tconst_pointer Tconst_pointer;
typedef typename Tarray::Tconst_pointer Tconst_pointer;
//! Type of reference to const element
typedef Tarray::Tconst_reference Tconst_reference;
typedef typename Tarray::Tconst_reference Tconst_reference;
//! Type of this array
typedef CArray<T> Tcontainer;
//! Type of the array of const values
......@@ -280,7 +282,7 @@ namespace aff {
*/
//@{
//! construct from shape and representation
Array(const Tarray& array)
CArray(const Tarray& array)
: Tbase(array), Mrepresentation(array.representation())
{ }
//@}
......
......@@ -283,14 +283,18 @@
The HOWTO page needs a revision and many more examples.
</TD>
</TR>
<TR><TD>libaff/README.groups</TD>
<TD>has no code</TD><TD> </TD><TD>has no code</TD>
<TD>proper grouping of documentation still needs to be done </TD>
</TR>
<TR><TD>libaff/array.h</TD>
<TD>8/12/02</TD><TD>20/12/02</TD><TD>19/12/02</TD><TD> </TD>
</TR>
<TR><TD>libaff/arrayoperators.h</TD>
<TD>10/02/2004</TD><TD> </TD><TD>10/02/2004 </TD><TD> </TD>
<TD>10/02/2004</TD><TD>15/05/2011 </TD><TD>10/02/2004 </TD><TD> </TD>
</TR>
<TR><TD>libaff/Carray.h</TD>
<TD>14/05/2011 </TD><TD>14/05/2011 </TD><TD> </TD><TD> </TD>
<TD>14/05/2011 </TD><TD>14/05/2011 </TD><TD>15/05/2011 </TD><TD> </TD>
</TR>
<TR><TD>libaff/dump.cc</TD>
<TD>18/12/2002</TD><TD>20/12/2002</TD><TD>18/12/2002</TD><TD> </TD>
......@@ -315,7 +319,7 @@
<TD> </TD>
</TR>
<TR><TD>libaff/seriesoperators.h</TD>
<TD>10/02/2004</TD><TD> </TD><TD>10/02/2004 </TD><TD> </TD>
<TD>10/02/2004</TD><TD>15/05/2011 </TD><TD>10/02/2004 </TD><TD> </TD>
</TR>
<TR><TD>libaff/shaper.h</TD>
<TD>12/12/02</TD><TD> </TD><TD>18/12/02</TD><TD> </TD>
......@@ -355,7 +359,7 @@
<TD>23/12/2003</TD><TD>27/04/2006</TD><TD>23/12/2003 </TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/operators.h</TD>
<TD>10/02/2004</TD><TD> </TD><TD>10/02/2004 </TD><TD> </TD>
<TD>10/02/2004</TD><TD>15/05/2011 </TD><TD>10/02/2004 </TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/rawarfun.h</TD>
<TD>13/12/02</TD><TD> </TD><TD>15/12/02</TD><TD> </TD>
......
......@@ -98,6 +98,10 @@ using namespace aff::util;
public:
//! element type
typedef T Telement;
/*! element type with different name to be consistent with other
* container classes
*/
typedef T Tvalue;
/*-----------------------------------------------------------------*/
......
......@@ -40,11 +40,13 @@
* are experienced anymore
* - 10/12/2007 V1.3 (thof)
* - scanning a const array requires a Browser
* - 15/05/2011 V1.4 (thof)
* - test aff::CArray
*
* ============================================================================
*/
#define AFF_HELPERTEST_CC_VERSION \
"AFF_HELPERTEST_CC V1.3"
"AFF_HELPERTEST_CC V1.4"
#define AFF_HELPERTEST_CC_CVSID \
"$Id$"
......@@ -54,6 +56,7 @@
*
* This test program gives an example of the usage of the following classes,
* functions, and preprocessor macros:
* - aff::CArray
* - aff::Iterator
* - aff::util::Subarray
* - aff::subarray
......@@ -76,6 +79,7 @@
#include <aff/iterator.h>
#include <aff/subarray.h>
#include <aff/slice.h>
#include <aff/Carray.h>
using std::cout;
using std::endl;
......@@ -238,6 +242,47 @@ int main()
CODE(Array<int> C=B.copyout());
CODE(dump_array(C));
}
/*----------------------------------------------------------------------*/
section("Test external access interfaces", '=');
section("Test interface to raw memory array: aff::CArray");
{
CODE( Array<int> A(Shaper(2)(10,16)(-2,2)(-1,0)); );
section("fill array");
for(int i=A.f(0); i<=A.l(0); i++)
{
for(int j=A.f(1); j<=A.l(1); j++)
{
for(int k=A.f(2); k<=A.l(2); k++)
{
for(int l=A.f(3); l<=A.l(3); l++)
{
A(i,j,k,l)=(i-A.f(0)+1)+(j-A.f(1)+1)*10
+(k-A.f(2)+1)*100+(l-A.f(3)+1)*1000;
}
}
}
}
CODE( dump_array(A,3); );
CODE( Array<int> B=aff::slice(A)(0,2)(2,-1); )
CODE( printarray(B) );
CODE( CArray<int> C(B); )
section("fill C array");
CODE( int* p=C.pointer(); )
CODE(
for (unsigned i=0; i<C.size(0); ++i)
{
for (unsigned j=0; j<C.size(1); ++j)
{
p[i*C.stride(0)+j*C.stride(1)]=i+10*j;
}
}
)
CODE( printarray(B) );
CODE( printarray(A) );
}
}
/* ----- END OF helpertest.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