AFF --- A container for numbers (array) by Friederich and Forbriger.

◆ FortranShape()

aff::util::FortranShape::FortranShape ( const Tshape shape,
const bool &  BaseOne = true 
)
explicit

construct from shape

all calculations are done herein

Definition at line 44 of file fortranshape.cc.

References AFF_assert, aff::Strided::first(), aff::Strided::first_offset(), aff::Strided::last(), Mdimlast, Mfirst, Mlast, aff::Strided::Mmax_dimen, Moffset, aff::Strided::setfirst(), and aff::Strided::stride().

45  {
46  // create a local copy of the shape
47  Tshape shape(inshape);
48  // set first index as required
49  if (BaseOne) shape.setfirst(TIndexVec(1));
50  // extract first and last index
51  Mfirst=shape.first();
52  Mlast=shape.last();
53  // extract offset to first element
54  Moffset=shape.first_offset();
55  // first test for Fortran memory layout
56  for (Tdim i=1; i<Tshape::Mmax_dimen; i++)
57  {
58  AFF_assert((shape.stride(i-1)<=shape.stride(i)),
59  "ERROR (FortranShape): no Fortran layout!");
60  }
61  // native Fortran arrays have stride 1 in base dimension
62  // In case we ever want to pass a slice, we have to think about how to
63  // pass strides to the Fortran subroutine
64  AFF_assert((shape.stride(0)==1),
65  "ERROR (FortranShape): No native Fortran array layout!");
66  // We assume that every properly sliced array has strides that are integer
67  // multiples of the stride of the lower dimension. Just for safety, we
68  // test for that assumption.
69  for (Tdim i=1; i<Tshape::Mmax_dimen; i++)
70  {
71  Tsize mult=shape.stride(i)/shape.stride(i-1);
72  AFF_assert((shape.stride(i)==(mult*shape.stride(i-1))),
73  "ERROR (FortranShape): Stride is no integer multiple!");
74  }
75  // calculate dimensioned last
76  for (Tdim i=1; i<Tshape::Mmax_dimen; i++)
77  {
78  Mdimlast[i-1]=shape.stride(i)/shape.stride(i-1)+Mfirst[i-1]-1;
79  }
81  // check bounds (just in case...)
82  for (Tdim i=0; i<Tshape::Mmax_dimen; i++)
83  {
84  AFF_assert((Mlast[i]<=Mdimlast[i]),
85  "ERROR (FortranShape): illegal index range in shape!");
86  }
87  // that's it...
88  }
Tsubscript Moffset
offset of first element in representation
Definition: fortranshape.h:96
TIndexVec Mfirst
first index
Definition: fortranshape.h:90
TIndexVec Mdimlast
last index as dimensioned in memory
Definition: fortranshape.h:94
Tshape::TIndexVec TIndexVec
Vector of index values.
Definition: fortranshape.h:69
static const Tdim Mmax_dimen
instantiate static member (otherwise the linker won&#39;t find it)
Definition: strided.h:123
#define AFF_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:162
TIndexVec Mlast
last index
Definition: fortranshape.h:92
unsigned short int Tdim
Type to hold an array dimensionality.
Definition: types.h:49
aff::Strided Tshape
This is coded for Strided shapes.
Definition: fortranshape.h:67
size_t Tsize
Type to hold the size of an array dimension.
Definition: types.h:51
Here is the call graph for this function: