casacore
Loading...
Searching...
No Matches
ArraySampledFunctional.h
Go to the documentation of this file.
1// # ArraySampledFunctional:
2// # Copyright (C) 1996,1997,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 SCIMATH_ARRAYSAMPLEDFUNCTIONAL_H
27#define SCIMATH_ARRAYSAMPLEDFUNCTIONAL_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/scimath/Functionals/SampledFunctional.h>
31#include <casacore/casa/Arrays/Array.h>
32#include <casacore/casa/Arrays/IPosition.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary> Index into an array using the longest axis </summary>
37
38// <use visibility=export>
39
40// <reviewed reviewer="wyoung" date="1996/10/19" tests="tSampledFunctional.cc">
41// </reviewed>
42
43// <prerequisite>
44// <li> SampledFunctional
45// <li> Array
46// </prerequisite>
47
48// <etymology>
49// A SampledFunctional is an interface that allows random access to a fixed
50// size data set. An ArraySampledFunctional allows you to access slices of
51// an an Array<T> object.
52// </etymology>
53
54// <synopsis>
55//
56// An ArraySampledFunctional allows an Array<T> object to be sliced up with
57// each sample being one slice of the original Array. The slices are always
58// the same size and the indexing is always done along the last
59// non-degenerate dimension. For example a(4,3,20,1) is interpreted as a
60// SampledFunctional with 20 elements, each one being a 4 by 3 matrix.
61//
62// The Array that is passed to the constructor is copied by this class but
63// because Arrays themselves use reference symantics, the actual data is not
64// copied but referenced. This means that modifying the data in the original
65// array will correspondingly modify the data accessed by this class.
66//
67// Similarly the Array that is returned for each Slice is a reference to the
68// actual data so that modifying this array really modifies the original
69// data. This is not recommended as the operator() function is not supposed
70// to be used to get a modifiable portion of the data.
71// </synopsis>
72
73// <example>
74// Constructing and using ArraySampledFunctionals
75// <srcblock>
76// Array<Float> a(IPosition(4,4,3,20,1)); // Create an array
77// ... Fill the array any way you like ...
78// ArraySampledFunctional<Array<Float> >fa(a);
79// for(uInt i = 0; i < 20; i++)
80// cout << "f(" << i << ") = " << fa(i) << endl;
81// // Each 'slice' is a 4 by 3 Matrix
82// </srcblock>
83// </example>
84
85// <motivation>
86// I needed a SampledFunctional which could return Arrays of arbitrary (but
87// fixed) size for each index. This could be done using a <src>
88// ScalarSampledFunctional<Array<T> > </src> but is ineffecient as each
89// element is stored as a separate Array. This class is a more efficient way
90// to solve this problem.
91// </motivation>
92
93// <templating arg=T>
94// <li> The template type MUST be an Array of some arbitrary type. This is
95// because this class will return a slice of this Array. The Array template
96// type cannot be subsumed into the class definition because the definition
97// of the inherited operator() function means that the return type must be
98// the template type
99// </templating>
100
101// <thrown>
102// <li> Exceptions are not thrown directly by this class.
103// </thrown>
104
105// <todo asof="1996/10/19">
106// <li> Nothing I can think of.
107// </todo>
108
109template <class T>
111 public:
112 // These constructors copy the array that is passed to them. But because
113 // arrays use reference symantics the data is not copied. The default
114 // constructor is basically useless, as there is no way to add the data
115 // once the class has been constructed.
116 // <group>
119 // </group>
120
121 // The standard copy constructor and assignment operator
122 // <group>
125 // </group>
126
127 // Define the functions for the SampledFunction interface
128 // <group>
129 virtual T operator()(const uInt &index) const;
130 virtual uInt nelements() const;
132 // </group>
133
134 // An alternate version of the sampling function which is more effecient
135 // because it does not need to create as many temporary objects or copy the
136 // Array data.
137 // <group>
138 const T operator()(const uInt &index);
139 // </group>
140
141 private:
146};
147
148} // namespace casacore
149
150#ifndef CASACORE_NO_AUTO_TEMPLATES
151#include <casacore/scimath/Functionals/ArraySampledFunctional.tcc>
152#endif // # CASACORE_NO_AUTO_TEMPLATES
153#endif
ArraySampledFunctional()
These constructors copy the array that is passed to them.
ArraySampledFunctional(ArraySampledFunctional< T > &other)
The standard copy constructor and assignment operator.
virtual uInt nelements() const
Return the total size of the data set.
const T operator()(const uInt &index)
An alternate version of the sampling function which is more effecient because it does not need to cre...
virtual T operator()(const uInt &index) const
Define the functions for the SampledFunction interface.
ArraySampledFunctional< T > & operator=(ArraySampledFunctional< T > &other)
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49