casacore
Loading...
Searching...
No Matches
TSMShape.h
Go to the documentation of this file.
1//# TSMShape.h: Expanded IPosition for shapes
2//# Copyright (C) 1994,1995,1996,1999
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef TABLES_TSMSHAPE_H
27#define TABLES_TSMSHAPE_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/IPosition.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35//# Forward Declarations
36
37
38// <summary>
39// Expanded IPosition for shapes.
40// </summary>
41
42// <use visibility=local>
43
44// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
45// </reviewed>
46
47// <prerequisite>
48//# Classes you should understand before using this one.
49// <li> <linkto class=IPosition>IPosition</linkto>
50// </prerequisite>
51
52// <etymology>
53// TSMShape handles the shapes for the Tiled Storage Manager.
54// </etymology>
55
56// <synopsis>
57// TSMShape is an extension of class
58// <linkto class=IPosition>IPosition</linkto>
59// to handle shapes.
60// It contains some precalculated values to speed up the calculation
61// of an array offset from an array index (and vice-versa).
62// </synopsis>
63
64// <motivation>
65// The Tiled Hypercube Storage Manager is heavily using array shapes
66// and determining offsets from array indices. This class makes these
67// calculations more efficient.
68// </motivation>
69
70// <todo asof="$DATE:$">
71// <li> Integrate in a class like LatticeLayout.
72// </todo>
73
74
76{
77public:
78 // A zero-length TSMShape.
80
81 // Construct from a shape and precalculate some values.
83
84 // Copy constructor (copy semantics).
85 TSMShape (const TSMShape& that);
86
87 // Assignment (copy semantics).
88 // "this" and "that" must either be conformant (same size)
89 // or "this" must be 0-length, in which case it will
90 // resize itself to be the same length as "that".
92
94
95 // Index into the TSMShape. Indices are zero-based. If the preprocessor
96 // symbol AIPS_ARRAY_INDEX_CHECK is defined, "index" will be
97 // checked to ensure it is not out of bounds. If this check fails, an
98 // AipsError will be thrown.
99 Int operator() (uInt index) const;
100
101 // The number of elements in this TSMShape. Since TSMShape
102 // objects use zero-based indexing, the maximum available index is
103 // nelements() - 1.
104 uInt nelements() const;
105
106 // conform returns true if nelements() == other.nelements().
107 Bool conform (const TSMShape& other) const;
108
109 // Calculate the offset for a given position.
110 // <group>
111 size_t offset (const IPosition& position) const;
112 size_t offset (const IPosition& position, const IPosition& origin) const;
113 // </group>
114
115 // Calculate the position for a given offset.
116 // <group>
117 IPosition position (size_t offset) const;
118 IPosition position (size_t offset, const IPosition& origin) const;
119 // </group>
120
121 // Calculate the increments when stepping through an array in
122 // a linear way. This can be used to update the array offset
123 // without recalculating it after each step.
124 // For example:
125 // <srcblock>
126 // template<class T>
127 // Array<T> someFunc (const Array<T>& array,
128 // const IPosition& subArrayShape,
129 // const IPosition& subArrayStart) const
130 // {
131 // TSMShape TSM (array.shape());
132 // IPosition offsetIncr = TSM.offsetIncrement (subArrayShape);
133 // Array<T> subArray(subArrayShape);
134 // Bool deleteMain;
135 // const T* mainData = array.getStorage (deleteMain);
136 // mainData += TSM.offset (subArrayStart)
137 // Bool deleteSub;
138 // T* subData = subArray.getStorage (deleteSub);
139 // for (uInt i=0; i<subArrayShape(2); i++) {
140 // for (uInt j=0; j<subArrayShape(1); j++) {
141 // for (uInt k=0; k<subArrayShape(0); k++) {
142 // *subData++ = *mainData++;
143 // }
144 // mainData += offsetIncr(1);
145 // }
146 // mainData += offSetIncr(2);
147 // }
148 // }
149 // </srcblock>
150 // <group>
151 IPosition offsetIncrement (const IPosition& subShape) const;
153 const IPosition& stride) const;
154 // </group>
155
156private:
158 uInt size_p; //# Not necessary, but done for speedup
159};
160
161
163{
164 return size_p;
165}
166
167inline Int TSMShape::operator()(uInt index) const
168{
169 return data_p(index);
170}
171
172inline Bool TSMShape::conform (const TSMShape& other) const
173{
174 return data_p.conform (other.data_p);
175}
176
177
178
179} //# NAMESPACE CASACORE - END
180
181#endif
bool conform(const IPosition &other) const
conform returns true if nelements() == other.nelements().
Definition IPosition.h:634
TSMShape(const TSMShape &that)
Copy constructor (copy semantics).
size_t offset(const IPosition &position, const IPosition &origin) const
size_t offset(const IPosition &position) const
Calculate the offset for a given position.
TSMShape()
A zero-length TSMShape.
IPosition offsetIncrement(const IPosition &subShape) const
Calculate the increments when stepping through an array in a linear way.
IPosition position(size_t offset, const IPosition &origin) const
TSMShape & operator=(const TSMShape &that)
Assignment (copy semantics).
uInt nelements() const
The number of elements in this TSMShape.
Definition TSMShape.h:162
IPosition data_p
Definition TSMShape.h:157
IPosition position(size_t offset) const
Calculate the position for a given offset.
IPosition offsetIncrement(const IPosition &subShape, const IPosition &stride) const
TSMShape(const IPosition &shape)
Construct from a shape and precalculate some values.
Bool conform(const TSMShape &other) const
conform returns true if nelements() == other.nelements().
Definition TSMShape.h:172
Int operator()(uInt index) const
Index into the TSMShape.
Definition TSMShape.h:167
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40