casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Arrays.h
Go to the documentation of this file.
00001 //# Arrays.h:  A module implementing multidimensional arrays and operations
00002 //# Copyright (C) 1995,1999,2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: Arrays.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $
00027 
00028 #ifndef CASA_ARRAYS_H
00029 #define CASA_ARRAYS_H
00030 
00031 #include <casa/Arrays/IPosition.h>
00032 #include <casa/Arrays/Slicer.h>
00033 #include <casa/Arrays/Slice.h>
00034 
00035 #include <casa/Arrays/Array.h>
00036 #include <casa/Arrays/Vector.h>
00037 #include <casa/Arrays/Matrix.h>
00038 #include <casa/Arrays/Cube.h>
00039 
00040 #include <casa/Arrays/ArrayIter.h>
00041 #include <casa/Arrays/MatrixIter.h>
00042 #include <casa/Arrays/VectorIter.h>
00043 
00044 #include <casa/Arrays/ArrayMath.h>
00045 #include <casa/Arrays/ArrayPartMath.h>
00046 #include <casa/Arrays/MatrixMath.h>
00047 #include <casa/Arrays/ArrayLogical.h>
00048 #include <casa/Arrays/ArrayIO.h>
00049 #include <casa/Arrays/ArrayError.h>
00050 
00051 #include <casa/Arrays/LogiArray.h>
00052 #include <casa/Arrays/LogiVector.h>
00053 #include <casa/Arrays/LogiMatrix.h>
00054 #include <casa/Arrays/LogiCube.h>
00055 
00056 #include <casa/Arrays/MaskedArray.h>
00057 #include <casa/Arrays/MaskArrMath.h>
00058 #include <casa/Arrays/MaskArrLogi.h>
00059 #include <casa/Arrays/MaskArrIO.h>
00060 #include <casa/Arrays/MaskLogiArr.h>
00061 
00062 
00063 namespace casa { //# NAMESPACE CASA - BEGIN
00064 
00065 // <module>
00066 //
00067 // <summary>
00068 // A module implementing multidimensional arrays and operations.
00069 // </summary>
00070 
00071 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" demos="">
00072 // </reviewed>
00073 
00074 // <etymology>
00075 // This module provides classes and global functions for multidimensional
00076 // arrays.
00077 // </etymology>
00078 //
00079 // <synopsis>
00080 // Arrays have traditionally played an important role in scientific
00081 // computation. While it is certainly true that some of the reliance on
00082 // arrays was due to the paucity of other data structures in FORTRAN, it
00083 // is also true that computation on arrays reflects the common occurrence
00084 // of regularly sampled multi-dimensioned data in science.
00085 //
00086 // The <linkto module=Lattices>Lattices</linkto> are a generalization
00087 // of Arrays. They can handle memory- and disk-based arrays as well
00088 // as other types of arrays (eg. expressions).
00089 //
00090 // The module consists of various parts:
00091 // <ul>
00092 
00093 // <li>
00094 // <linkto class=Array>Array</linkto> is the basic array class. It is
00095 // only templated on data type, not on dimensionality like the array
00096 // classes in Blitz and boost.
00097 // It has a non-templated base class ArrayBase.
00098 //
00099 // <linkto class=Vector>Vector</linkto>,
00100 // <linkto class=Matrix>Matrix</linkto>, and
00101 // <linkto class=Cube>Cube</linkto>
00102 // are the one, two, and three dimensional specializations respectively of
00103 // Array.
00104 //
00105 // <li>
00106 // <linkto class=MaskedArray>MaskedArray</linkto> is the class used to mask
00107 // an Array for operations on that Array.
00108 //
00109 // <li>
00110 // <linkto class=ArrayError>ArrayError</linkto> is the base class for all
00111 // Array exception classes.
00112 //
00113 // <li>
00114 // There are several ways o iterate through an array:
00115 // <ul>
00116 //  <li> The STL-style Array iterators can be used to iterate
00117 //    element by element through an array. This is the fastest way.
00118 //    They also make it possible to virtually extend an array (called
00119 //    shape broadcasting in numpy) and to reorder the iteration axes.
00120 //  <li> <linkto class=ArrayIterator>ArrayIterator</linkto> can be used to
00121 //    iterate line by line, plane by plane, etc. through an array.
00122 //    Each subset is an array in itself, thus can be iterated again.
00123 //  <li> The Array function operators () can be used to get a subset from
00124 //    an array. They can be used for iteration, but that is slower than
00125 //    the ways mentioned above.
00126 //  <li> The array operator[] can be used to get the i-th subset. It can
00127 //    be used for iteration, but ArrayIterator does the same and is faster.
00128 //  <li> ArrayAccessor is useful when neighbours of an array element have
00129 //    to be visited.
00130 //  <li> <linkto class=LatticeIterator>LatticeIterator</linkto> can be used on
00131 //    a <linkto class=ArrayLattice>ArrayLattice</linkto> object for more
00132 //    advanced iteration. However, they are part of the lattices packages.
00133 // </ul>
00134 //
00135 // <li>
00136 // <linkto group="ArrayMath.h#Array mathematical operations">Mathematical</linkto>,
00137 // <linkto group="ArrayLogical.h#Array logical operations">logical</linkto>,
00138 // <linkto group="ArrayPartMath.h#Array partial operations">chunked mathematical and logical</linkto>,
00139 // <linkto group="ArrayIO.h#Array IO">IO</linkto>,
00140 // and other useful operations are provided for
00141 // Arrays and MaskedArrays.
00142 // 
00143 // ArrayMath also defines various STL-style transform functions that use the
00144 // Array iterators and functors like Plus to apply the mathematical and logical
00145 // operations. They can, however, also be used directly on arrays of
00146 // different types making it possible to, say, add a Complex and double array
00147 // with a DComplex result.
00148 // <br>It also has a <src>transformInPlace</src> to avoid needless incrementing
00149 // of iterators which have to be done when using <src>std::transform</src>
00150 // for in-place operations.
00151 //
00152 // <li>
00153 // Orthogonal n-space descriptors - useful when a shape of an Array is
00154 // needed or when a sub-region within an Array is required.
00155 // <ul>
00156 //   <li> The <linkto class="IPosition">IPosition</linkto> class name is a
00157 //   concatenation of "Integer Position."  IPosition objects are normally
00158 //   used to index into, and define the shapes of, Arrays and Lattices. For
00159 //   example, if you have a 5-dimensional array, you need an IPosition of
00160 //   length 5 to index into the array (or to define its shape, etc.).  It is
00161 //   essentially a vector of integers.  The IPosition vector may point to
00162 //   the "top right corner" of some shape, or it may be an indicator of a
00163 //   specific position in n-space.  The interpretation is context dependent.
00164 //   The constructor consists of an initial argument which specifies the
00165 //   number of axes, followed by the appropriate number of respective axis
00166 //   lengths.  Thus the constructor needs N+1 arguments for an IPosition
00167 //   of length N. IPositions have the standard integer math relationships
00168 //   defined. The dimensionality of the operator arguments must be the
00169 //   same.
00170 //<srcblock>
00171 // // Make a shape with three axes, x = 24, y = 48, z = 16;
00172 // IPosition threeSpace(3, 24, 48, 16);
00173 //
00174 // // get the value of the ith axis (note: C++ is zero based!)
00175 // Int xShape = threeSpace(0);
00176 // Int zShape = threeSpace(2);
00177 //
00178 // // construct another with all three axes values equal to 666;
00179 // IPosition threeSpaceAlso(3,666);
00180 //
00181 // // do math with the IPositions...
00182 // threeSpace += threeSpaceAlso;
00183 // AlwaysAssert(threeSpace(1) == 714, AipsError);
00184 // </srcblock>
00185 //
00186 //   <li> The <linkto class="Slicer">Slicer</linkto> class name may be
00187 //   thought of as a short form of "n-Dimensional Slice Specifier."  
00188 //   This object is used to bundle into one place all the information
00189 //   necessary to specify a regular subregion within an Array or Lattice.
00190 //   In other words, Slicer holds the location of a "slice" of a
00191 //   greater whole.  Construction is with up to 3 IPositions: the start 
00192 //   location of the subspace within the greater space; the shape or end
00193 //   location of the subspace within the greater space; and the stride,
00194 //   or multiplier to be used for each axis.  The stride gives the user
00195 //   the chance to use every i-th piece of data, rather than every
00196 //   position on the axis.
00197 //   <br>
00198 //   It is possible to leave some values in the given start or end/length
00199 //   unspecified. Such unspecified values default to the boundaries of the
00200 //   array to which the slicer will be applied.
00201 //   It is also possible to use a non-zero origin when applying the slicer
00202 //   to an array.
00203 //
00204 // <srcblock>
00205 // // Define the shape of an array.
00206 // IPosition shape(2,20,30);
00207 //
00208 // // Also define an origin.
00209 // IPosition origin(2,-5,15);
00210 //
00211 // // Now define some Slicers, initially only specify the start
00212 // // Its length and stride will be 1.
00213 // Slicer ns0(IPosition(2,0,24));
00214 //
00215 // // make some IPositions as holders for the rest of the information
00216 // IPosition blc,trc,inc;
00217 //
00218 // // Use the shape and origin to fill our holders assuming we want to use
00219 // // as much of the Array as possible.
00220 // ns0.inferShapeFromSource (shape, origin, blc,trc,inc);
00221 //
00222 // // print out the new info ie. blc=[5,9],trc=[5,9],inc=[1,1]
00223 // cout << blc << trc << inc << endl;
00224 //
00225 // // Build a slicer with temporaries for arguments. The arguments are:
00226 // // start position, end position and step increment. The Slicer::endIsLast
00227 // // argument specifies that the end position is the trc. The alternative
00228 // // is Slicer::endIsLength which specifies that the end argument is the
00229 // // shape of the resulting subregion.
00230 // //
00231 // Slicer ns1(IPosition(2,3,5), IPosition(2,13,21), IPosition(2,3,2),
00232 //            Slicer::endIsLast);
00233 // IPosition shp = ns1.inferShapeFromSource (shape, blc,trc,inc);
00234 // //
00235 // // print out the new info ie. shp=[4,9],blc=[3,5],trc=[12,21],inc=[3,2]
00236 // cout << shp << blc << trc << inc << endl;
00237 // </srcblock>
00238 //   </ul>
00239 // </ul>
00240 
00241 // The <linkto module=Arrays:classes>detailed discussions</linkto> for the
00242 // classes and global functions will describe how to use them.
00243 // </synopsis>
00244 //
00245 // </module>
00246 
00247 
00248 } //# NAMESPACE CASA - END
00249 
00250 #endif