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