//# TVecMath.cc: Global helper functions for table vector mathematics //# Copyright (C) 1994,1995,1997 //# 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 TABLES_TVECMATH_TCC #define TABLES_TVECMATH_TCC #include #include #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN //# Add, subtract, multiply, divide table vector. //# Define it for a vector and scalar, 2 vectors, 2 vectors with assign. #define TVECMATHOPER(NAME,OP,OPA) \ template \ TabVecRep& aips_name2(tabVecRepvalr,NAME) (const TabVecRep& tv, \ const T& val) \ { \ rownr_t nr = tv.nelements(); \ TabVecTemp& vec = *(TabVecTemp*)tv.newVec(); \ for (rownr_t i=0; i \ TabVecRep& aips_name2(tabVecRepvall,NAME) (const T& val, \ const TabVecRep& tv) \ { \ rownr_t nr = tv.nelements(); \ TabVecTemp& vec = *(TabVecTemp*)tv.newVec(); \ T tmp; \ for (rownr_t i=0; i \ TabVecRep& aips_name2(tabVecReptv,NAME) (const TabVecRep& tvl, \ const TabVecRep& tvr) \ { \ rownr_t nr = tvr.nelements(); \ tvl.validateConformance(nr); \ TabVecTemp& vec = *(TabVecTemp*)tvl.newVec(); \ for (rownr_t i=0; i \ void aips_name2(tabVecRepvalass,NAME) (TabVecRep& tv, const T& val) \ { \ rownr_t nr = tv.nelements(); \ T tmp; \ for (rownr_t i=0; i \ void aips_name2(tabVecReptvass,NAME) (TabVecRep& tvl, \ const TabVecRep& tvr) \ { \ rownr_t nr = tvr.nelements(); \ tvl.validateConformance(nr); \ T tmp; \ for (rownr_t i=0; i TabVecRep& tabVecRepnegate(const TabVecRep& tv) { rownr_t nr = tv.nelements(); TabVecTemp& vec = *(TabVecTemp*)tv.newVec(); T tmp; for (rownr_t i=0; i void tabVecRepminmax (T& min, T& max, const TabVecRep& tv) { rownr_t nr = tv.nelements(); if (nr == 0) { throw(ArrayError("void minMax(T& min, T& max, const TabVecRep&) - " "TabVecRep has no elements")); } T tmp; tv.getVal (0, min); max = min; for (rownr_t i=1; i max) max = tmp; } } template void tabVecRepindgen(TabVecRep& tv, T start, T inc) { rownr_t nr = tv.nelements(); for (rownr_t i=0; i \ TabVecRep& aips_name2(tabVecRep,NAME) (const TabVecRep& tv) \ { \ rownr_t nr = tv.nelements(); \ TabVecTemp& vec = *(TabVecTemp*)tv.newVec(); \ T tmp; \ for (rownr_t i=0; i \ TabVecRep& aips_name2(tabVecRep,NAME) (const TabVecRep& tvl, \ const TabVecRep& tvr) \ { \ rownr_t nr = tvr.nelements(); \ tvl.validateConformance(nr); \ TabVecTemp& vec = *(TabVecTemp*)tvl.newVec(); \ T tmpl, tmpr; \ for (rownr_t i=0; i TabVecRep& tabVecReppowd (const TabVecRep& tv, const double& exp) { rownr_t nr = tv.nelements(); TabVecTemp& vec = *(TabVecTemp*)tv.newVec(); T tmp; for (rownr_t i=0; i T tabVecRepsum (const TabVecRep& tv) { rownr_t nr = tv.nelements(); if (nr == 0) { throw(ArrayError("T sum(const TabVecRep&) - " "TabVecRep has no elements")); } T tmp, res; tv.getVal (0, res); for (rownr_t i=1; i T tabVecRepproduct (const TabVecRep& tv) { rownr_t nr = tv.nelements(); if (nr == 0) { throw(ArrayError("T product(const TabVecRep&) - " "TabVecRep has no elements")); } T tmp, res; tv.getVal (0, res); for (rownr_t i=1; i T tabVecRepinnerproduct (const TabVecRep& tvl, const TabVecRep& tvr) { rownr_t nr = tvr.nelements(); tvl.validateConformance(nr); T res = 0; for (rownr_t i=0; i T tabVecRepnorm (const TabVecRep& tv) { rownr_t nr = tv.nelements(); T tmp; T res = 0; for (rownr_t i=0; i TabVecRep& tabVecRepcrossproduct (const TabVecRep& tvl, const TabVecRep& tvr) { tvl.validateConformance(3); tvr.validateConformance(3); TabVecTemp& vec = *(TabVecTemp*)tvl.newVec(); vec(0) = tvl.value(1) * tvr.value(2) - tvl.value(2) * tvr.value(1); vec(1) = tvl.value(2) * tvr.value(0) - tvl.value(0) * tvr.value(2); vec(2) = tvl.value(0) * tvr.value(1) - tvl.value(1) * tvr.value(0); return vec; } } //# NAMESPACE CASACORE - END #endif