casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArrayOpsDiffShapes.h
Go to the documentation of this file.
1 //# ArrayOpsDiffShapes.h: Operations for 2 Arrays with possibly different shapes.
2 //# Copyright (C) 2009
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This program is free software; you can redistribute it and/or modify
6 //# it under the terms of the GNU General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or
8 //# (at your option) any later version.
9 //#
10 //# This program is distributed in the hope that it will be useful,
11 //# but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 //# GNU General Public License for more details.
14 //#
15 //# You should have received a copy of the GNU General Public License
16 //# along with this program; if not, write to the Free Software
17 //# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@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 //# $Id$
27 
28 #ifndef CASA_ARRAYOPSDIFFSHAPES_H
29 #define CASA_ARRAYOPSDIFFSHAPES_H
30 
31 #include <casacore/casa/aips.h>
34 //#include <casacore/casa/Arrays/ArrayUtil.h>
36 //#include <casacore/casa/Arrays/Slice.h>
37 //#include <casacore/casa/BasicSL/String.h>
38 
39 // Don't forget a .tcc file is included at the end!
40 
41 namespace casacore { //# NAMESPACE CASACORE - BEGIN
42 
43 // <summary>
44 // Operations for 2 Arrays with possibly different shapes.
45 // </summary>
46 // <!-- <reviewed reviewer="UNKNOWN" date="" tests=""> -->
47 //
48 // <prerequisite>
49 // <li> <linkto class=Array>Array</linkto>
50 // <li> <linkto>ArrayMath</linkto>
51 // </prerequisite>
52 //
53 // <etymology>
54 // This file contains global functions that attempt binary operations with
55 // arrays that have possibly differing shapes.
56 // </etymology>
57 //
58 // <synopsis>
59 // These functions perform operations on two arrays, left and right, which go
60 // chunk by chunk in left and element by element in right, as long as right
61 // spans a subspace of left. If left's shape has more dimensions than right's,
62 // each entry in right will effectively be replicated as necessary to act on
63 // each entry in the corresponding chunk of left.
64 // e.g. if left's shape is (256, 256, 1, 4), and right's is (256, 256),
65 // left(i, j, 1, l) will be operated on with right(i, j) for i & j from 0 to
66 // 255 and l from 0 to 3. Note that right must be either reformable to left's
67 // shape (same # of elements) or its shape must equal left's shape "as far as
68 // it goes", i.e. where right's dimensions are defined.
69 // </synopsis>
70 //
71 // <example>
72 // <srcblock>
73 // Array<Complex> a(10, 6);
74 // Vector<Int> b(10);
75 // Array<Complex> c(10, 6);
76 //
77 // c = binOpExpandR(a, b, std::plus<Complex>());
78 // </srcblock>
79 // This example sets c(i, j) to a(i, j) + b(i). It checks that either b's
80 // shape can be reformed to a's (same # of elements) or that a's shape is the
81 // same as b's where b's dimensions are defined.
82 // The result of this operation is an Array.
83 // </example>
84 
85 // <group name=OpsDiff_functions>
86 
87 // Returns a LogicalArray with elements (at pos) set to (data(pos) ==
88 // truthvalue). data is effectively collapsed using anyEQ if necessary to
89 // fit desiredform. Throws an exception if that does not work.
90 template<typename T>
91 LogicalArray reformedMask(const Array<T>& data, const T truthvalue,
92  const IPosition& desiredform);
93 
94 // Can arrays left and right with respective shapes leftShape and rightShape be
95 // used in function(left, right, ...) for the other functions declared here?
96 Bool rightExpandableToLeft(const IPosition& leftShape, const IPosition& rightShape);
97 
98 // Apply op elementwise to left and right, replicating elements of right as
99 // necessary (see example above). Throws an ArrayConformanceError exception if
100 // that cannot be done.
101 //
102 // Currently assumes that it is the trailing axes of left that right will be
103 // replicated along. e.g. if left's shape is (1, 2, 4) and right's is (1, 2),
104 // the result will be left(i, j, k) op right(i, j) for all (i, j, k).
105 //
106 //# template<typename L, typename R, typename BinaryOperator, typename RES>
107 //# Array<RES> binOpExpandR(const Array<L>& left, const Array<R>& right,
108 //# BinaryOperator op);
109 
110 // Like binOpExpandR(left, right, res, op), but work on left in place.
111 template<typename L, typename R, typename BinaryOperator>
112 void binOpExpandInPlace(Array<L>& left, const Array<R>& right, BinaryOperator op);
113 
114 // </group>
115 
116 } //#End casa namespace
117 
118 #ifndef CASACORE_NO_AUTO_TEMPLATES
119 #include <casacore/casa/Arrays/ArrayOpsDiffShapes.tcc>
120 #endif //# CASACORE_NO_AUTO_TEMPLATES
121 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42