/usr/include/casacore/casa/Arrays/Vector.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 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | //# Vector.cc: A 1-D Specialization of the Array Class
//# Copyright (C) 1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,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 CASA_VECTOR_TCC
#define CASA_VECTOR_TCC
#include <casacore/casa/Arrays/Vector.h>
#include <casacore/casa/Arrays/ArrayError.h>
#include <casacore/casa/Arrays/Slice.h>
#include <casacore/casa/Arrays/MaskedArray.h>
#include <casacore/casa/BasicMath/Math.h>
#include <casacore/casa/Utilities/Copy.h>
#include <casacore/casa/Utilities/Assert.h>
#include <casacore/casa/iostream.h>
namespace casacore { //#Begin casa namespace
template<class T> Vector<T>::Vector()
: Array<T>(IPosition(1,0))
{
DebugAssert(ok(), ArrayError);
}
template<class T> Vector<T>::Vector(size_t Length)
: Array<T>(IPosition(1, Length))
{
DebugAssert(ok(), ArrayError);
}
template<class T> Vector<T>::Vector(size_t Length, ArrayInitPolicy initPolicy)
: Array<T>(IPosition(1, Length), initPolicy)
{
DebugAssert(ok(), ArrayError);
}
template<class T> Vector<T>::Vector(const IPosition& len)
: Array<T>(len)
{
if (len.nelements() != 1) this->throwNdimVector();
}
template<class T> Vector<T>::Vector(const IPosition& len, ArrayInitPolicy initPolicy)
: Array<T>(len, initPolicy)
{
if (len.nelements() != 1) this->throwNdimVector();
}
template<class T> Vector<T>::Vector(size_t Length, const T &initialValue)
: Array<T>(IPosition(1, Length), initialValue)
{
DebugAssert(ok(), ArrayError);
}
template<class T> Vector<T>::Vector(const IPosition& len, const T &initialValue)
: Array<T>(len, initialValue)
{
if (len.nelements() != 1) this->throwNdimVector();
}
template<class T> Vector<T>::Vector(const Block<T> &other, Int64 nr)
: Array<T>(IPosition(1, other.nelements()), ArrayInitPolicy::INIT)
{
initVector (other, nr);
DebugAssert(ok(), ArrayError);
}
template<class T> Vector<T>::Vector(const Block<T> &other)
: Array<T>(IPosition(1, other.nelements()), const_cast<T *>(other.storage()), COPY)
{
DebugAssert(ok(), ArrayError);
}
// Copy from the block. Copy the number of elements specified or
// the number of elements in the block if nr <= 0.
// <thrown>
// <item> ArrayError
// </thrown>
template<class T> void Vector<T>::initVector(const Block<T> &other, Int64 nr)
{
size_t n = nr;
if (nr <= 0) {
n = other.nelements();
}
if (n > other.nelements())
throw(ArrayError("Vector<T>::initVector(const Block<T> &other"
", Int64 nr) - nr > other.nelements()"));
if (this->nelements() != n) {
this->resize(n);
}
for (size_t i=0; i < n; i++) {
this->begin_p[i] = other[i];
}
return;
}
template<class T> Vector<T>::Vector(const Vector<T> &other)
: Array<T>(other)
{
DebugAssert(ok(), ArrayError);
}
// <thrown>
// <item> ArrayNDimError
// </thrown>
template<class T> Vector<T>::Vector(const Array<T> &other)
: Array<T>(other)
{
// If not 1 dimension, adjust shape if possible.
if (this->ndim() != 1) {
this->checkVectorShape();
}
DebugAssert(ok(), ArrayError);
}
template<class T>
Vector<T>::Vector(const IPosition &shape, T *storage,
StorageInitPolicy policy)
: Array<T>(shape, storage, policy)
{
if (shape.nelements() != 1) this->throwNdimVector();
}
template<class T>
Vector<T>::Vector(const IPosition &shape, T *storage,
StorageInitPolicy policy, AbstractAllocator<T> const &allocator)
: Array<T>(shape, storage, policy, allocator)
{
if (shape.nelements() != 1) this->throwNdimVector();
}
template<class T>
Vector<T>::Vector(const IPosition &shape, const T *storage)
: Array<T>(shape, storage)
{
if (shape.nelements() != 1) this->throwNdimVector();
}
template<class T> Vector<T>::~Vector()
{
// Nothing
}
template<class T> void Vector<T>::resize()
{
resize (IPosition(1,0), False);
}
// <thrown>
// <item> ArrayConformanceError
// </thrown>
template<class T> void Vector<T>::resize(const IPosition &l, Bool copyValues, ArrayInitPolicy policy)
{
DebugAssert(ok(), ArrayError);
if (l.nelements() != 1) this->throwNdimVector();
if (copyValues) {
Vector<T> oldref(*this);
Array<T>::resize(l, False, policy);
size_t minNels = std::min(this->nelements(), oldref.nelements());
objcopy(this->begin_p, oldref.begin_p, minNels,
this->inc_p(0), oldref.inc_p(0));
} else {
Array<T>::resize(l, False, policy);
}
DebugAssert(ok(), ArrayError);
}
// <thrown>
// <item> ArrayError
// </thrown>
template<class T> void Vector<T>::assign (const Array<T>& other)
{
DebugAssert(ok(), ArrayError);
if (other.ndim() != 1) this->throwNdimVector();
Array<T>::assign (other);
}
// <thrown>
// <item> ArrayError
// </thrown>
template<class T> void Vector<T>::reference(const Array<T> &other)
{
DebugAssert(ok(), ArrayError);
if (other.ndim() != 1) this->throwNdimVector();
Array<T>::reference(other);
}
template<class T> Vector<T> &Vector<T>::operator=(const Vector<T> &other)
{
DebugAssert(ok(), ArrayError);
if (this != &other) {
if (! this->copyVectorHelper (other)) {
// Block was empty, so allocate new block.
this->data_p = new Block<T> (this->length_p(0));
this->begin_p = this->data_p->storage();
}
this->setEndIter();
objcopy (this->begin_p, other.begin_p, this->nels_p,
this->inc_p(0), other.inc_p(0));
}
return *this;
}
// Copy a vector to a block.
template<class T> void Vector<T>::toBlock(Block<T> & other) const
{
DebugAssert(ok(), ArrayError);
size_t vec_length = this->nelements();
// Make sure the block has enough space, but there is no need to copy elements
other.resize(vec_length, True, False);
objcopy(other.storage(), this->begin_p, this->nels_p, 1U, this->inc_p(0));
}
template<class T> Array<T> &Vector<T>::operator=(const Array<T> &a)
{
DebugAssert(ok(), ArrayError);
Vector<T> tmp(a);
(*this) = tmp;
return *this;
}
// <thrown>
// <item> ArrayError
// </thrown>
template<class T> Vector<T> Vector<T>::operator()(const Slice &slice)
{
DebugAssert(ok(), ArrayError);
Int64 b, l, s; // begin length step
if (slice.all()) {
b = 0;
l = this->length_p(0);
s = 1;
} else {
b = slice.start();
l = slice.length();
s = slice.inc();
}
// Check that the selected slice is valid
if (s < 1) {
throw(ArrayError("Vector<T>::operator()(Slice) : step < 1"));
} else if (l < 0) {
throw(ArrayError("Vector<T>::operator()(Slice) : length < 0"));
} else if (b+(l-1)*s >= this->length_p(0)) {
throw(ArrayError("Vector<T>::operator()(Slice) : Desired slice extends"
" beyond the end of the array"));
} else if (b < 0) {
throw(ArrayError("Vector<T>::operator()(Slice) : start of slice before "
"beginning of vector"));
}
// Create the slice. This could also be done with the Array<T>::operator()
// slice functions, however it's simple for vectors, and this will be
// more efficient.
// Create the vector that will be the slice into this
Vector<T> vp(*this);
// Increment vp's begin so that it is at the selected position
vp.begin_p += b*this->steps()[0];
vp.inc_p(0) *= s;
vp.length_p(0) = l;
vp.nels_p = l;
vp.contiguous_p = vp.isStorageContiguous();
vp.makeSteps();
return vp;
}
template<class T> const Vector<T> Vector<T>::operator()
(const Slice &slice) const
{
return const_cast<Vector<T>*>(this)->operator() (slice);
}
template<class T>
void Vector<T>::doNonDegenerate (const Array<T> &other,
const IPosition &ignoreAxes)
{
Array<T> tmp(*this);
tmp.nonDegenerate (other, ignoreAxes);
if (tmp.ndim() != 1) this->throwNdimVector();
reference (tmp);
}
template<class T>
void Vector<T>::preTakeStorage(const IPosition &shape)
{
Array<T>::preTakeStorage(shape);
if (shape.nelements() != 1)
this->throwNdimVector();
}
template<class T> Bool Vector<T>::ok() const
{
return this->ndim() == 1 && Array<T>::ok();
}
} //#End casa namespace
#endif
|