/usr/include/casacore/casa/Arrays/ArrayOpsDiffShapes.tcc is in casacore-dev 2.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | //# ArrayOpsDiffShapes.tcc: Operations for 2 Arrays with possibly different shapes.
//# Copyright (C) 2009
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//# This program is distributed in the hope that it will be useful,
//# but WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//# GNU General Public License for more details.
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
//# $Id$
#ifndef CASA_ARRAYOPSDIFFSHAPES_TCC
#define CASA_ARRAYOPSDIFFSHAPES_TCC
#include <casacore/casa/Arrays/ArrayMath.h>
#include <casacore/casa/Arrays/ArrayLogical.h>
//#include <casacore/casa/Arrays/ArrayUtil.h>
#include <casacore/casa/Arrays/IPosition.h>
//#include <casacore/casa/Arrays/Slice.h>
#include <casacore/casa/Arrays/ArrayError.h>
//#include <casacore/casa/BasicSL/String.h>
namespace casacore {
template<typename T>
LogicalArray reformedMask(const Array<T>& data, const T truthvalue,
const IPosition& desiredform)
{
if(data.shape().nelements() == desiredform.nelements()
&& data.shape() == desiredform){
return (data == truthvalue);
}
else if(static_cast<Int>(data.nelements()) == desiredform.product()){
return (data == truthvalue).reform(desiredform);
}
else{
if(rightExpandableToLeft(data.shape(), desiredform)){
uInt n_data_dim = data.shape().nelements();
uInt n_desired_dim = desiredform.nelements();
// Create an array with desiredform's shape,
LogicalArray collapseddata(desiredform);
ReadOnlyArrayIterator<T> data_cursor(data,
IPosition::otherAxes(n_data_dim,
IPosition::makeAxisPath(n_desired_dim)));
IPosition collapsedPos;
// Go through each position in the new array,
for(ArrayPositionIterator positer(desiredform, 0);
!positer.pastEnd(); positer.next()){
collapsedPos = positer.pos();
data_cursor.set(collapsedPos);
collapseddata(collapsedPos) = anyEQ(data_cursor.array(), truthvalue);
}
//// Apparently it would be expensive to put this inside the for statement.
//LogicalArray::iterator iterend(collapseddata.end());
// for(LogicalArray::iterator it = collapseddata.begin(); it != iterend;
// ++it)
// *it = data(it.itsCurPos).anyEQ(truthvalue);
return collapseddata;
}
else{
ostringstream os;
os << "reformedMask(): Could not reconcile the input shape ("
<< data.shape() << ")\n"
<< "with the output shape (" << desiredform << ").";
throw(ArrayConformanceError(os));
}
}
}
// template<typename L, typename R, typename BinaryOperator, typename RES>
// Array<RES> binOpExpandR(const Array<L>& left, const Array<R>& right,
// BinaryOperator op)
// {
// const IPosition leftShape = left.shape();
// Array<RES> res(leftShape);
// if(left.conform(right)){
// arrayContTransform(left, right, res, op);
// }
// else if(left.nelements() == right.nelements()){
// arrayContTransform(left, right.reform(leftShape), res, op);
// }
// else{
// const IPosition rightShape = right.shape();
// if(rightExpandableToLeft(leftShape, rightShape)){
// uInt n_right_dim = rightShape.nelements();
// ArrayIterator<L> left_cursor(left, n_right_dim);
// ArrayIterator<RES> res_cursor(res, n_right_dim);
// IPosition rightPos;
// // Go through each position in the new array,
// for(ArrayPositionIterator positer(rightShape, 0);
// !positer.pastEnd(); positer.next()){
// rightPos = positer.pos();
// left_cursor.set(rightPos);
// res_cursor.set(rightPos);
// // "resChunk op= rightEntry"
// arrayContTransform(left_cursor.array(), right(rightPos),
// res_cursor.array(), op);
// }
// }
// else{
// ostringstream os; // String(rightShape) is not supported.
// os << "binOpExpandR(): right's shape (" << rightShape << ")\n"
// << " has more dimensions than left's (" << leftShape << ")!";
// throw(ArrayConformanceError(os));
// }
// }
// return res;
// }
template<typename L, typename R, typename BinaryOperator>
void binOpExpandInPlace(Array<L>& leftarr, const Array<R>& rightarr, BinaryOperator op)
{
const IPosition leftShape = leftarr.shape();
const IPosition rightShape = rightarr.shape();
// leftarr.conform(rightarr) fails if e.g. L == Double and R == Float.
if(leftShape.nelements() == rightShape.nelements() && leftShape == rightShape){
arrayTransformInPlace(leftarr, rightarr, op); // Autochecks contiguity.
}
else if(leftarr.nelements() == rightarr.nelements()){
arrayTransformInPlace(leftarr, rightarr.reform(leftShape), op);
}
else{
uInt n_right_dim = rightShape.nelements();
if(rightExpandableToLeft(leftShape, rightShape)){
IPosition iteraxes(IPosition::otherAxes(leftShape.nelements(),
IPosition::makeAxisPath(n_right_dim)));
ArrayIterator<L> left_cursor(leftarr, iteraxes);
IPosition rightPos;
// Go through each position in the new array,
for(ArrayPositionIterator positer(rightShape, 0);
!positer.pastEnd(); positer.next()){
rightPos = positer.pos();
left_cursor.set(rightPos);
// "leftChunk op= rightEntry"
arrayTransformInPlace(left_cursor.array(), rightarr(rightPos), op);
}
}
else{
ostringstream os; // String(rightShape) is not supported.
os << "binOpExpandInPlace(): rightarr's shape (" << rightShape << ")\n"
<< " has more dimensions than leftarr's (" << leftShape << ")!";
throw(ArrayConformanceError(os));
}
}
}
} //#End casa namespace
#endif
|