/usr/include/casacore/lattices/LEL/LatticeExpr.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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | //# LatticeExpr.cc: this defines LatticeExpr.cc
//# Copyright (C) 1997,1998,1999,2000,2003
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library 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 Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts 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 LATTICES_LATTICEEXPR_TCC
#define LATTICES_LATTICEEXPR_TCC
#include <casacore/lattices/LEL/LatticeExpr.h>
#include <casacore/lattices/LEL/LELArray.h>
#include <casacore/lattices/Lattices/LatticeIterator.h>
#include <casacore/casa/Arrays/Array.h>
#include <casacore/casa/Arrays/Slicer.h>
#include <casacore/casa/Arrays/ArrayMath.h>
#include <casacore/casa/Utilities/Assert.h>
#include <casacore/casa/Exceptions/Error.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
template <class T>
LatticeExpr<T>::LatticeExpr()
: lastChunkPtr_p (0)
{}
template <class T>
LatticeExpr<T>::LatticeExpr (const LatticeExprNode& expr)
: shape_p (expr.shape()),
lastChunkPtr_p (0)
{
// Check if an expression array has a shape.
if (!expr.isScalar() && shape_p.nelements() == 0) {
throw AipsError ("LatticeExpr cannot be constructed from a lattice "
"expression with an undefined shape");
}
init (expr);
}
template <class T>
LatticeExpr<T>::LatticeExpr (const LatticeExprNode& expr,
const IPosition& latticeShape)
: shape_p (latticeShape),
lastChunkPtr_p (0)
//
// Construct from a LatticeExprNode object. The LEN type is
// converted to match the template type if possible
//
{
// Check if the expression has a shape.
if (!expr.isScalar() && expr.shape().nelements() > 0
&& !(shape_p.isEqual(expr.shape()))) {
throw AipsError ("LatticeExpr::constructor - "
"given shape mismatches expression's shape");
}
init (expr);
}
template <class T>
void LatticeExpr<T>::init (const LatticeExprNode& expr)
{
DataType thisDT = whatType (static_cast<T*>(0));
if (expr.dataType() == thisDT) {
expr_p = expr;
} else {
if (expr.dataType() == TpBool) {
throw (AipsError ("LatticeExpr::constructor - "
"Bool expression cannot be converted to "
"a numeric type"));
}
switch (thisDT) {
case TpFloat:
expr_p = expr.makeFloat();
break;
case TpDouble:
expr_p = expr.makeDouble();
break;
case TpComplex:
expr_p = expr.makeComplex();
break;
case TpDComplex:
expr_p = expr.makeDComplex();
break;
default:
throw (AipsError ("LatticeExpr::constructor - "
"A numeric type cannot be converted to Bool"));
}
}
}
template <class T>
LatticeExpr<T>::~LatticeExpr()
{
delete lastChunkPtr_p;
}
template <class T>
LatticeExpr<T>::LatticeExpr (const LatticeExpr<T>& other)
: MaskedLattice<T>(),
expr_p (other.expr_p),
shape_p (other.shape_p),
lastChunkPtr_p (0)
{}
template <class T>
LatticeExpr<T>& LatticeExpr<T>::operator=(const LatticeExpr<T>& other)
{
if (this != &other) {
expr_p = other.expr_p;
shape_p = other.shape_p;
delete lastChunkPtr_p;
lastChunkPtr_p = 0;
lastSlicer_p = Slicer();
}
return *this;
}
template <class T>
MaskedLattice<T>* LatticeExpr<T>::cloneML() const
{
return new LatticeExpr (*this);
}
template <class T>
Bool LatticeExpr<T>::isMasked() const
{
return expr_p.isMasked();
}
template <class T>
const LatticeRegion* LatticeExpr<T>::getRegionPtr() const
{
return 0;
}
template <class T>
Bool LatticeExpr<T>::isWritable() const
{
return False;
}
template<class T>
Bool LatticeExpr<T>::lock (FileLocker::LockType type, uInt nattempts)
{
return expr_p.lock (type, nattempts);
}
template<class T>
void LatticeExpr<T>::unlock()
{
expr_p.unlock();
}
template<class T>
Bool LatticeExpr<T>::hasLock (FileLocker::LockType type) const
{
return expr_p.hasLock (type);
}
template<class T>
void LatticeExpr<T>::resync()
{
expr_p.resync();
}
template <class T>
IPosition LatticeExpr<T>::shape() const
{
return shape_p;
}
template <class T>
IPosition LatticeExpr<T>::doNiceCursorShape (uInt) const
{
return expr_p.getAttribute().tileShape();
}
template <class T>
LELCoordinates LatticeExpr<T>::lelCoordinates() const
{
return expr_p.getAttribute().coordinates();
}
template <class T>
Bool LatticeExpr<T>::doGetSlice (Array<T>& buffer,
const Slicer& section)
{
// Evaluate the expression if not accessing the same section again.
if (!(section==lastSlicer_p)) {
delete lastChunkPtr_p;
lastChunkPtr_p = new LELArray<T> (section.length());
lastSlicer_p = section;
expr_p.eval (*lastChunkPtr_p, section);
}
buffer.reference (lastChunkPtr_p->value());
return True;
}
template <class T>
Bool LatticeExpr<T>::doGetMaskSlice (Array<Bool>& buffer,
const Slicer& section)
{
// Evaluate if masked and if different section.
if (expr_p.isMasked()) {
if (!(section==lastSlicer_p)) {
delete lastChunkPtr_p;
lastChunkPtr_p = new LELArray<T> (section.length());
lastSlicer_p = section;
expr_p.eval (*lastChunkPtr_p, section);
}
if (lastChunkPtr_p->isMasked()) {
buffer.reference (lastChunkPtr_p->mask());
return True;
}
}
// Not masked, so we can simply fill the buffer with True values.
buffer.resize (section.length());
buffer = True;
return False;
}
template <class T>
void LatticeExpr<T>::doPutSlice (const Array<T>&, const IPosition&,
const IPosition&)
{
throw (AipsError ("LatticeExpr::putSlice - is not possible"));
}
template<class T>
void LatticeExpr<T>::copyDataTo (Lattice<T>& to) const
{
// If a scalar, set lattice to its value.
// Otherwise use the Lattice copyDataTo function.
if (expr_p.isScalar()) {
// Check the lattice is writable.
AlwaysAssert (to.isWritable(), AipsError);
T value;
expr_p.eval (value);
to.set (value);
} else {
Lattice<T>::copyDataTo (to);
}
}
template<class T>
void LatticeExpr<T>::handleMathTo (Lattice<T>& to, int oper) const
{
// If a scalar, apply its value to the lattice.
// Otherwise use the Lattice handleMathTo function.
if (expr_p.isScalar()) {
T value;
expr_p.eval (value);
// Check the lattice is writable.
AlwaysAssert (to.isWritable(), AipsError);
// Create an iterator for the output.
// If possible, use reference semantics in the iterator.
LatticeIterator<T> iter(to, True);
switch (oper) {
case 0:
for (iter.reset(); !iter.atEnd(); iter++) {
iter.rwCursor() += value;
}
break;
case 1:
for (iter.reset(); !iter.atEnd(); iter++) {
iter.rwCursor() -= value;
}
break;
case 2:
for (iter.reset(); !iter.atEnd(); iter++) {
iter.rwCursor() *= value;
}
break;
case 3:
for (iter.reset(); !iter.atEnd(); iter++) {
iter.rwCursor() /= value;
}
break;
default:
throw AipsError ("LatticeExpr::handleMathTo - Unknown operator");
}
} else {
Lattice<T>::handleMathTo (to, oper);
}
}
} //# NAMESPACE CASACORE - END
#endif
|