casacore
 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_2_H
29 #define CASA_ARRAYOPSDIFFSHAPES_2_H
30 
31 #include "ArrayMath.h"
32 #include "ArrayLogical.h"
33 #include "IPosition.h"
34 
35 //# Don't forget a .tcc file is included at the end!
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 // <summary>
40 // Operations for 2 Arrays with possibly different shapes.
41 // </summary>
42 // <!-- <reviewed reviewer="UNKNOWN" date="" tests=""> -->
43 //
44 // <prerequisite>
45 // <li> <linkto class=Array>Array</linkto>
46 // <li> <linkto>ArrayMath</linkto>
47 // </prerequisite>
48 //
49 // <etymology>
50 // This file contains global functions that attempt binary operations with
51 // arrays that have possibly differing shapes.
52 // </etymology>
53 //
54 // <synopsis>
55 // These functions perform operations on two arrays, left and right, which go
56 // chunk by chunk in left and element by element in right, as long as right
57 // spans a subspace of left. If left's shape has more dimensions than right's,
58 // each entry in right will effectively be replicated as necessary to act on
59 // each entry in the corresponding chunk of left.
60 // e.g. if left's shape is (256, 256, 1, 4), and right's is (256, 256),
61 // left(i, j, 1, l) will be operated on with right(i, j) for i & j from 0 to
62 // 255 and l from 0 to 3. Note that right must be either reformable to left's
63 // shape (same # of elements) or its shape must equal left's shape "as far as
64 // it goes", i.e. where right's dimensions are defined.
65 // </synopsis>
66 //
67 // <example>
68 // <srcblock>
69 // Array<Complex> a(10, 6);
70 // Vector<int> b(10);
71 // Array<Complex> c(10, 6);
72 //
73 // c = binOpExpandR(a, b, std::plus<Complex>());
74 // </srcblock>
75 // This example sets c(i, j) to a(i, j) + b(i). It checks that either b's
76 // shape can be reformed to a's (same # of elements) or that a's shape is the
77 // same as b's where b's dimensions are defined.
78 // The result of this operation is an Array.
79 // </example>
80 
81 // <group name=OpsDiff_functions>
82 
83 // Returns a LogicalArray with elements (at pos) set to (data(pos) ==
84 // truthvalue). data is effectively collapsed using anyEQ if necessary to
85 // fit desiredform. Throws an exception if that does not work.
86 template<typename T, typename Alloc>
87 LogicalArray reformedMask(const Array<T, Alloc>& data, const T truthvalue,
88  const IPosition& desiredform);
89 
90 // Can arrays left and right with respective shapes leftShape and rightShape be
91 // used in function(left, right, ...) for the other functions declared here?
92 bool rightExpandableToLeft(const IPosition& leftShape, const IPosition& rightShape);
93 
94 // Apply op elementwise to left and right, replicating elements of right as
95 // necessary (see example above). Throws an ArrayConformanceError exception if
96 // that cannot be done.
97 //
98 // Currently assumes that it is the trailing axes of left that right will be
99 // replicated along. e.g. if left's shape is (1, 2, 4) and right's is (1, 2),
100 // the result will be left(i, j, k) op right(i, j) for all (i, j, k).
101 //
102 //# template<typename L, typename R, typename BinaryOperator, typename RES>
103 //# Array<RES> binOpExpandR(const Array<L>& left, const Array<R>& right,
104 //# BinaryOperator op);
105 
106 // Like binOpExpandR(left, right, res, op), but work on left in place.
107 template<typename L, typename AllocL, typename R, typename AllocR, typename BinaryOperator>
108 void binOpExpandInPlace(Array<L, AllocL>& left, const Array<R, AllocR>& right, BinaryOperator op);
109 
110 // </group>
111 
112 } //#End casa namespace
113 
114 #include "ArrayOpsDiffShapes.tcc"
115 
116 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:118
A templated N-D Array class with zero origin. Array&lt;T, Alloc&gt; is a templated, N-dimensional, Array class. The origin is zero, but by default indices are zero-based. This Array class is the base class for the Vector, Matrix, and Cube subclasses.
Definition: Array.h:156