AFF --- A container for numbers (array) by Friederich and Forbriger.
dump.cc
Go to the documentation of this file.
1 
40 #define AFF_DUMP_CC_VERSION \
41  "AFF_DUMP_CC V1.1"
42 
43 #include <aff/lib/dump_strided.h>
44 #include <aff/lib/error.h>
45 
46 namespace aff {
47 
49 void dump(const Strided& shape, std::ostream& os)
50 {
51  os << "dump of a Strided object:" << endl;
52  os << " index ranges: ";
53  for (Tsize i=0; i<Strided::Mmax_dimen; i++)
54  {
55  os << "[" << shape.first(i) << ":" << shape.last(i) << "]";
56  }
57  os << endl;
58  os << " strides: ";
59  for (Tsize i=0; i<Strided::Mmax_dimen; i++)
60  {
61  if (i>0) os << ", ";
62  os << shape.stride(i);
63  }
64  os << endl;
65  os << " total number of mapped elements: "
66  << shape.size() << endl;
67  os << " total address range in memory: ["
68  << shape.first_offset() << ":" << shape.last_offset() << "] = "
69  << shape.memory_size() << " positions" << endl;
70 }
71 
72 /*----------------------------------------------------------------------*/
73 
74 namespace {
75 
80  void dump_map_helper(const Strided& shape, const Tdim& i, const Tdim& j,
81  Strided::TIndexVec& index, std::ostream& os)
82  {
83  if (i>1)
84  {
85  for (index[i]=shape.first(i); index[i]<=shape.last(i); index[i]++)
86  {
87  os << " dimension ";
88  os << i << ": [" << index[i] << "]";
89  dump_map_helper(shape, i-1, j, index, os);
90  }
91  }
92  else if (i>0)
93  {
94  if (i<j) os << endl;
95  os.width(5); os << " ";
96  for (int k=shape.first(1); k<=shape.last(1); k++)
97  {
98  os.width(6); os << k;
99  }
100  os << endl;
101  for (index[0]=shape.first(0); index[0]<=shape.last(0); index[0]++)
102  {
103  os.width(5); os << index[0];
104  for (index[1]=shape.first(1); index[1]<=shape.last(1); index[1]++)
105  {
106  os.width(5);
107  if (j==0)
108  { os << shape.offset(index[0]); }
109  else if (j==1)
110  { os << shape.offset(index[0], index[1]); }
111  else if (j==2)
112  { os << shape.offset(index[0], index[1], index[2]); }
113  else if (j==3)
114  { os << shape.offset(index[0], index[1], index[2], index[3]); }
115  else
116  { os << shape.offset(index); }
117  os << "#";
118  }
119  os << endl;
120  }
121  }
122  else
123  {
124  for (index[0]=shape.first(0); index[0]<=shape.last(0); index[0]++)
125  {
126  os.width(5); os << index[0];
127  os.width(5);
128  if (j==0)
129  { os << shape.offset(index[0]); }
130  else if (j==1)
131  { os << shape.offset(index[0], index[1]); }
132  else if (j==2)
133  { os << shape.offset(index[0], index[1], index[2]); }
134  else if (j==3)
135  { os << shape.offset(index[0], index[1], index[2], index[3]); }
136  else
137  { os << shape.offset(index); }
138  os << "#" << endl;
139  }
140  }
141  }
142 }
143 
145 void dump_map(const Strided& shape, const Tdim& i, std::ostream& os)
146 {
148  "ERROR (dump_map): illegal dimensionality");
149  dump(shape);
150  os << " index mapping for " << i+1 << " dimensional access:" << endl;
151  Strided::TIndexVec index(shape.first());
152  dump_map_helper(shape, i, i, index, os);
153 }
154 
155 } // namespace aff
156 
157 /* ----- END OF dump.cc ----- */
Root namespace of library.
Definition: array.h:148
Shape for a rectangular array layout.
Definition: strided.h:117
void dump(const Strided &shape, std::ostream &os)
dump shape
Definition: dump.cc:49
factored out Strided dump function (prototypes)
Tsubscript last_offset() const
last mapped position
Definition: strided.h:191
void dump_map(const Strided &shape, const Tdim &i, std::ostream &os)
dump index mapping of shape
Definition: dump.cc:145
const Tsubscript & first(const Tsubscript &i) const
first index of dimension
Definition: strided.h:194
const Tsize & stride(const Tsubscript &i) const
stride of dimension
Definition: strided.h:203
exceptions and error handling macros (prototypes)
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
Tsize memory_size() const
total size of mapped memory range
Definition: strided.h:183
Tsize size() const
total number of mapped elements
Definition: strided.cc:140
Tsubscript first_offset() const
first mapped position
Definition: strided.h:188
unsigned short int Tdim
Type to hold an array dimensionality.
Definition: types.h:49
void dump_map_helper(const Strided &shape, const Tdim &i, const Tdim &j, Strided::TIndexVec &index, std::ostream &os)
recursive usage tests all offset functions
Definition: dump.cc:80
const Tsubscript & last(const Tsubscript &i) const
last index of dimension
Definition: strided.h:197
Tsubscript offset(const TIndexVec &index) const
full dimensionality access
Definition: strided.h:220
size_t Tsize
Type to hold the size of an array dimension.
Definition: types.h:51