Skip to content

Commit

Permalink
Squashed 'externals/coda-oss/' changes from c5111f4..ba5cb1d
Browse files Browse the repository at this point in the history
ba5cb1d Merge pull request #185 from mdaus/numpyTypes
64e84d3 Fix merge conflict
e431254 Add consts
9d5bf82 Merge pull request #188 from mdaus/mathMisc
681e019 Add math utilities to support SICD validation
bc69e0b Fix space
cd7c72f Add comments
8fecda5 Move function implementation to hpp file
fbee286 Add conversion of Poly2D
d6fc5d2 Check in working progress
3fded3d Test conversion functions

git-subtree-dir: externals/coda-oss
git-subtree-split: ba5cb1d337677474ba980dd2089045cb43bdb5f0
  • Loading branch information
asylvest committed Nov 23, 2016
1 parent c22d44b commit caafcc0
Show file tree
Hide file tree
Showing 14 changed files with 892 additions and 184 deletions.
54 changes: 19 additions & 35 deletions modules/c++/math.poly/include/math/poly/OneD.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* =========================================================================
* This file is part of math.poly-c++
* This file is part of math.poly-c++
* =========================================================================
*
*
* (C) Copyright 2004 - 2014, MDA Information Systems LLC
*
* math.poly-c++ is free software; you can redistribute it and/or modify
Expand All @@ -14,8 +14,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/
Expand All @@ -33,7 +33,7 @@ namespace math
{
namespace poly
{
/*!
/*!
* \class OneD
* \brief 1-D polynomial evaluation
*
Expand All @@ -46,14 +46,15 @@ namespace poly
*
* It supports evaluating the integral over a specified interval (a...b)
*
* It supports computing the derivative and
* It supports computing the derivative and
* the multiplication/addition/subtraction of 1-D polynomials.
*/
template<typename _T>
class OneD
{
protected:
std::vector<_T> mCoef;
template<typename Vector_T> bool equalImpl(const Vector_T& p) const;

public:
/*!
Expand Down Expand Up @@ -225,39 +226,21 @@ class OneD

template<typename Vector_T> bool operator==(const Vector_T& p) const
{
size_t sz = size();
size_t psz = p.size();
size_t minSize = std::min<size_t>(sz, psz);

// guard against uninitialized
if (minSize == 0 && (sz != psz))
return false;

for (size_t i = 0; i < minSize; i++)
if (!math::linear::equals(mCoef[i], p[i]))
return false;

_T dflt(0.0);
return equalImpl(p);
}

// Cover case where one polynomial has more
// coefficients than the other.
if (sz > psz)
{
for (size_t i = minSize; i < sz; i++)
if (!math::linear::equals(mCoef[i], dflt))
return false;
}
else if (sz < psz)
{
for (size_t i = minSize; i < psz; i++)
if (!math::linear::equals(p[i], dflt))
return false;
}
template<typename Vector_T> bool operator!=(const Vector_T& p) const
{
return !(*this == p);
}

return true;
// Explicit overload to make SWIG wrap it
bool operator==(const OneD<_T>& p)
{
return equalImpl(p);
}

template<typename Vector_T> bool operator!=(const Vector_T& p) const
bool operator!=(const OneD<_T>& p)
{
return !(*this == p);
}
Expand All @@ -272,6 +255,7 @@ class OneD
}
};


} // poly
} // math
#include "math/poly/OneD.hpp"
Expand Down
114 changes: 82 additions & 32 deletions modules/c++/math.poly/include/math/poly/OneD.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* =========================================================================
* This file is part of math.poly-c++
* This file is part of math.poly-c++
* =========================================================================
*
*
* (C) Copyright 2004 - 2014, MDA Information Systems LLC
*
* math.poly-c++ is free software; you can redistribute it and/or modify
Expand All @@ -14,8 +14,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/
Expand All @@ -32,7 +32,7 @@ namespace poly
{

template<typename _T>
_T
_T
OneD<_T>::operator () (double at) const
{
_T ret(0.0);
Expand All @@ -46,7 +46,7 @@ OneD<_T>::operator () (double at) const
}

template<typename _T>
_T
_T
OneD<_T>::integrate(double start, double end) const
{
_T ret(0.0);
Expand Down Expand Up @@ -157,11 +157,11 @@ _T
OneD<_T>::acceleration(double x) const
{
return derivative().derivative()(x);

}

template<typename _T>
_T&
_T&
OneD<_T>::operator [] (size_t i)
{
if (i < mCoef.size())
Expand All @@ -180,7 +180,7 @@ OneD<_T>::operator [] (size_t i)


template<typename _T>
_T
_T
OneD<_T>::operator [] (size_t i) const
{
_T ret(0.0);
Expand All @@ -199,7 +199,7 @@ OneD<_T>::operator [] (size_t i) const
}

template<typename _T>
std::ostream&
std::ostream&
operator << (std::ostream& out, const OneD<_T>& p)
{
for (size_t i = 0 ; i < p.mCoef.size() ; i++)
Expand All @@ -210,18 +210,18 @@ operator << (std::ostream& out, const OneD<_T>& p)
}

template<typename _T>
OneD<_T>&
OneD<_T>::operator *= (double cv)
OneD<_T>&
OneD<_T>::operator *= (double cv)
{
for (size_t i = 0, sz = mCoef.size() ; i < sz; i++)
{
mCoef[i] *= cv;
}
return *this;
}

template<typename _T>
OneD<_T>
OneD<_T>
OneD<_T>::operator * (double cv) const
{
OneD<_T> ret(*this);
Expand All @@ -230,15 +230,15 @@ OneD<_T>::operator * (double cv) const
}

template<typename _T>
OneD<_T>
operator * (double cv, const OneD<_T>& p)
OneD<_T>
operator * (double cv, const OneD<_T>& p)
{
return p*cv;
}

template<typename _T>
OneD<_T>&
OneD<_T>::operator *= (const OneD<_T>& p)
OneD<_T>&
OneD<_T>::operator *= (const OneD<_T>& p)
{
OneD<_T> tmp(order()+p.order());
for (size_t i = 0, xsz = mCoef.size(); i < xsz; i++)
Expand All @@ -251,9 +251,9 @@ OneD<_T>::operator *= (const OneD<_T>& p)
*this = tmp;
return *this;
}

template<typename _T>
OneD<_T>
OneD<_T>
OneD<_T>::operator * (const OneD<_T>& p) const
{
OneD<_T> ret(*this);
Expand All @@ -262,8 +262,8 @@ OneD<_T>::operator * (const OneD<_T>& p) const
}

template<typename _T>
OneD<_T>&
OneD<_T>::operator += (const OneD<_T>& p)
OneD<_T>&
OneD<_T>::operator += (const OneD<_T>& p)
{
OneD<_T> tmp(std::max<size_t>(order(), p.order()));
for (size_t i = 0, sz = mCoef.size() ; i < sz; i++)
Expand All @@ -279,17 +279,17 @@ OneD<_T>::operator += (const OneD<_T>& p)
}

template<typename _T>
OneD<_T>
OneD<_T>
OneD<_T>::operator + (const OneD<_T>& p) const
{
OneD<_T> ret(*this);
ret += p;
return ret;
}

template<typename _T>
OneD<_T>&
OneD<_T>::operator -= (const OneD<_T>& p)
OneD<_T>&
OneD<_T>::operator -= (const OneD<_T>& p)
{
OneD<_T> tmp(std::max<size_t>(order(), p.order()));
for (size_t i = 0, sz = mCoef.size(); i < sz; i++)
Expand All @@ -305,7 +305,7 @@ OneD<_T>::operator -= (const OneD<_T>& p)
}

template<typename _T>
OneD<_T>
OneD<_T>
OneD<_T>::operator - (const OneD<_T>& p) const
{
OneD<_T> ret(*this);
Expand All @@ -314,8 +314,8 @@ OneD<_T>::operator - (const OneD<_T>& p) const
}

template<typename _T>
OneD<_T>&
OneD<_T>::operator /= (double cv)
OneD<_T>&
OneD<_T>::operator /= (double cv)
{
double recipCV = 1.0/cv;
for (unsigned int i = 0, sz = mCoef.size() ; i < sz; i++)
Expand All @@ -326,7 +326,7 @@ OneD<_T>::operator /= (double cv)
}

template<typename _T>
OneD<_T>
OneD<_T>
OneD<_T>::operator / (double cv) const
{
OneD<_T> ret(*this);
Expand All @@ -352,8 +352,8 @@ OneD<_T> OneD<_T>::power(size_t toThe) const
if (toThe == 1)
return rv;

// Otherwise, we have to raise it

// Otherwise, we have to raise it
for (size_t i = 2; i <= toThe; i++)
{
rv *= *this;
Expand Down Expand Up @@ -443,6 +443,56 @@ void OneD<_T>::copyFrom(const OneD<_T>& p)
std::copy(p.mCoef.begin(), p.mCoef.begin() + numCopy, mCoef.begin());
}

template<typename _T>
template<typename Vector_T>
bool OneD<_T>::equalImpl(const Vector_T& p) const
{
size_t sz = size();
size_t psz = p.size();
size_t minSize = std::min<size_t>(sz, psz);

// guard against uninitialized
if (minSize == 0 && (sz != psz))
{
return false;
}

for (size_t ii = 0; ii < minSize; ++ii)
{
if (!math::linear::equals(mCoef[ii], p[ii]))
{
return false;
}
}

_T defaultValue(0.0);

// Cover case where one polynomial has more
// coefficients than the other
if (sz > psz)
{
for (size_t ii = minSize; ii < sz; ++ii)
{
if (!math::linear::equals(mCoef[ii], defaultValue))
{
return false;
}
}
}
if (sz < psz)
{
for (size_t ii = minSize; ii < psz; ++ii)
{
if (!math::linear::equals(p[ii], defaultValue))
{
return false;
}
}
}

return true;
}

} // poly
} // math

Loading

0 comments on commit caafcc0

Please sign in to comment.