Loading...
Searching...
No Matches
ap.h
Go to the documentation of this file.
/********************************************************************
AP library.
See www.alglib.net or alglib.sources.ru for details.
********************************************************************/
#ifndef AP_H
#define AP_H
#include <stdlib.h>
#include <math.h>
/********************************************************************
Checking of the array boundaries mode.
********************************************************************/
//#define NO_AP_ASSERT
#define AP_ASSERT
#ifndef AP_ASSERT
#define NO_AP_ASSERT
#endif
#ifdef NO_AP_ASSERT
#ifdef AP_ASSERT
#undef NO_AP_ASSERT
#endif
#endif
/********************************************************************
This symbol is used for debugging. Do not define it and do not remove
comments.
********************************************************************/
//#define UNSAFE_MEM_COPY
/********************************************************************
Namespace of a standard library AlgoPascal.
********************************************************************/
namespace ap
{
/********************************************************************
Exception class.
********************************************************************/
class ap_error
{
public:
static void make_assertion(bool bClause)
{ if(!bClause) throw ap_error(); };
private:
};
/********************************************************************
Class defining a complex number with double precision.
********************************************************************/
class complex;
class complex
{
public:
complex():x(0.0),y(0.0){};
complex(const double &_x):x(_x),y(0.0){};
complex(const double &_x, const double &_y):x(_x),y(_y){};
complex(const complex &z):x(z.x),y(z.y){};
complex& operator= (const double& v){ x = v; y = 0.0; return *this; };
complex& operator+=(const double& v){ x += v; return *this; };
complex& operator-=(const double& v){ x -= v; return *this; };
complex& operator*=(const double& v){ x *= v; y *= v; return *this; };
complex& operator/=(const double& v){ x /= v; y /= v; return *this; };
complex& operator= (const complex& z){ x = z.x; y = z.y; return *this; };
complex& operator+=(const complex& z){ x += z.x; y += z.y; return *this; };
complex& operator-=(const complex& z){ x -= z.x; y -= z.y; return *this; };
complex& operator*=(const complex& z){ double t = x*z.x-y*z.y; y = x*z.y+y*z.x; x = t; return *this; };
complex& operator/=(const complex& z)
{
ap::complex result;
double e;
double f;
if( fabs(z.y)<fabs(z.x) )
{
e = z.y/z.x;
f = z.x+z.y*e;
result.x = (z.x+z.y*e)/f;
result.y = (z.y-z.x*e)/f;
}
else
{
e = z.x/z.y;
f = z.y+z.x*e;
result.x = (z.y+z.x*e)/f;
result.y = (-z.x+z.y*e)/f;
}
*this = result;
return *this;
};
double x, y;
};
const complex operator/(const complex& lhs, const complex& rhs);
const bool operator==(const complex& lhs, const complex& rhs);
const bool operator!=(const complex& lhs, const complex& rhs);
const complex operator+(const complex& lhs);
const complex operator-(const complex& lhs);
const complex operator+(const complex& lhs, const complex& rhs);
const complex operator+(const complex& lhs, const double& rhs);
const complex operator+(const double& lhs, const complex& rhs);
const complex operator-(const complex& lhs, const complex& rhs);
const complex operator-(const complex& lhs, const double& rhs);
const complex operator-(const double& lhs, const complex& rhs);
const complex operator*(const complex& lhs, const complex& rhs);
const complex operator*(const complex& lhs, const double& rhs);
const complex operator*(const double& lhs, const complex& rhs);
const complex operator/(const complex& lhs, const complex& rhs);
const complex operator/(const double& lhs, const complex& rhs);
const complex operator/(const complex& lhs, const double& rhs);
const double abscomplex(const complex &z);
const complex conj(const complex &z);
const complex csqr(const complex &z);
/********************************************************************
Template defining vector in memory. It is used by the basic
subroutines of linear algebra.
Vector consists of Length elements of type T, starting from an element,
which Data is pointed to. Interval between adjacent elements equals
the value of Step.
The class provides an access for reading only.
********************************************************************/
template<class T>
class const_raw_vector
{
public:
const_raw_vector(const T *Data, int Length, int Step):
pData(const_cast<T*>(Data)),iLength(Length),iStep(Step){};
const T* GetData() const
{ return pData; };
int GetLength() const
{ return iLength; };
int GetStep() const
{ return iStep; };
protected:
T *pData;
int iLength, iStep;
};
/********************************************************************
Template defining vector in memory, derived from const_raw_vector.
It is used by the basic subroutines of linear algebra.
Vector consists of Length elements of type T, starting from an element,
which Data is pointed to. Interval between adjacent elements equals
the value of Step.
The class provides an access both for reading and writing.
********************************************************************/
template<class T>
class raw_vector : public const_raw_vector<T>
{
public:
raw_vector(T *Data, int Length, int Step):const_raw_vector<T>(Data, Length, Step){};
T* GetData()
{ return const_raw_vector<T>::pData; };
};
/********************************************************************
Scalar product
********************************************************************/
template<class T>
T vdotproduct(const_raw_vector<T> v1, const_raw_vector<T> v2)
{
ap_error::make_assertion(v1.GetLength()==v2.GetLength());
if( v1.GetStep()==1 && v2.GetStep()==1 )
{
//
// fast
//
T r = 0;
const T *p1 = v1.GetData();
const T *p2 = v2.GetData();
int imax = v1.GetLength()/4;
int i;
for(i=imax; i!=0; i--)
{
r += (*p1)*(*p2) + p1[1]*p2[1] + p1[2]*p2[2] + p1[3]*p2[3];
p1+=4;
p2+=4;
}
for(i=0; i<v1.GetLength()%4; i++)
r += (*(p1++))*(*(p2++));
return r;
}
else
{
//
// general
//
int offset11 = v1.GetStep(), offset12 = 2*offset11, offset13 = 3*offset11, offset14 = 4*offset11;
int offset21 = v2.GetStep(), offset22 = 2*offset21, offset23 = 3*offset21, offset24 = 4*offset21;
T r = 0;
const T *p1 = v1.GetData();
const T *p2 = v2.GetData();
int imax = v1.GetLength()/4;
int i;
for(i=0; i<imax; i++)
{
r += (*p1)*(*p2) + p1[offset11]*p2[offset21] + p1[offset12]*p2[offset22] + p1[offset13]*p2[offset23];
p1+=offset14;
p2+=offset24;
}
for(i=0; i<v1.GetLength()%4; i++)
{
r += (*p1)*(*p2);
p1+=offset11;
p2+=offset21;
}
return r;
}
}
/********************************************************************
Copy one vector into another
********************************************************************/
template<class T>
void vmove(raw_vector<T> vdst, const_raw_vector<T> vsrc)
{
ap_error::make_assertion(vdst.GetLength()==vsrc.GetLength());
if( vdst.GetStep()==1 && vsrc.GetStep()==1 )
{
//
// fast
//
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/2;
int i;
for(i=imax; i!=0; i--)
{
*p1 = *p2;
p1[1] = p2[1];
p1 += 2;
p2 += 2;
}
if(vdst.GetLength()%2 != 0)
*p1 = *p2;
return;
}
else
{
//
// general
//
int offset11 = vdst.GetStep(), offset12 = 2*offset11, offset13 = 3*offset11, offset14 = 4*offset11;
int offset21 = vsrc.GetStep(), offset22 = 2*offset21, offset23 = 3*offset21, offset24 = 4*offset21;
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=0; i<imax; i++)
{
*p1 = *p2;
p1[offset11] = p2[offset21];
p1[offset12] = p2[offset22];
p1[offset13] = p2[offset23];
p1 += offset14;
p2 += offset24;
}
for(i=0; i<vdst.GetLength()%4; i++)
{
*p1 = *p2;
p1 += vdst.GetStep();
p2 += vsrc.GetStep();
}
return;
}
}
/********************************************************************
Copy one vector multiplied by -1 into another.
********************************************************************/
template<class T>
void vmoveneg(raw_vector<T> vdst, const_raw_vector<T> vsrc)
{
ap_error::make_assertion(vdst.GetLength()==vsrc.GetLength());
if( vdst.GetStep()==1 && vsrc.GetStep()==1 )
{
//
// fast
//
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/2;
int i;
for(i=0; i<imax; i++)
{
*p1 = -*p2;
p1[1] = -p2[1];
p1 += 2;
p2 += 2;
}
if(vdst.GetLength()%2 != 0)
*p1 = -*p2;
return;
}
else
{
//
// general
//
int offset11 = vdst.GetStep(), offset12 = 2*offset11, offset13 = 3*offset11, offset14 = 4*offset11;
int offset21 = vsrc.GetStep(), offset22 = 2*offset21, offset23 = 3*offset21, offset24 = 4*offset21;
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=imax; i!=0; i--)
{
*p1 = -*p2;
p1[offset11] = -p2[offset21];
p1[offset12] = -p2[offset22];
p1[offset13] = -p2[offset23];
p1 += offset14;
p2 += offset24;
}
for(i=0; i<vdst.GetLength()%4; i++)
{
*p1 = -*p2;
p1 += vdst.GetStep();
p2 += vsrc.GetStep();
}
return;
}
}
/********************************************************************
Copy one vector multiplied by a number into another vector.
********************************************************************/
template<class T, class T2>
void vmove(raw_vector<T> vdst, const_raw_vector<T> vsrc, T2 alpha)
{
ap_error::make_assertion(vdst.GetLength()==vsrc.GetLength());
if( vdst.GetStep()==1 && vsrc.GetStep()==1 )
{
//
// fast
//
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=imax; i!=0; i--)
{
*p1 = alpha*(*p2);
p1[1] = alpha*p2[1];
p1[2] = alpha*p2[2];
p1[3] = alpha*p2[3];
p1 += 4;
p2 += 4;
}
for(i=0; i<vdst.GetLength()%4; i++)
*(p1++) = alpha*(*(p2++));
return;
}
else
{
//
// general
//
int offset11 = vdst.GetStep(), offset12 = 2*offset11, offset13 = 3*offset11, offset14 = 4*offset11;
int offset21 = vsrc.GetStep(), offset22 = 2*offset21, offset23 = 3*offset21, offset24 = 4*offset21;
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=0; i<imax; i++)
{
*p1 = alpha*(*p2);
p1[offset11] = alpha*p2[offset21];
p1[offset12] = alpha*p2[offset22];
p1[offset13] = alpha*p2[offset23];
p1 += offset14;
p2 += offset24;
}
for(i=0; i<vdst.GetLength()%4; i++)
{
*p1 = alpha*(*p2);
p1 += vdst.GetStep();
p2 += vsrc.GetStep();
}
return;
}
}
/********************************************************************
Vector addition
********************************************************************/
template<class T>
void vadd(raw_vector<T> vdst, const_raw_vector<T> vsrc)
{
ap_error::make_assertion(vdst.GetLength()==vsrc.GetLength());
if( vdst.GetStep()==1 && vsrc.GetStep()==1 )
{
//
// fast
//
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=imax; i!=0; i--)
{
*p1 += *p2;
p1[1] += p2[1];
p1[2] += p2[2];
p1[3] += p2[3];
p1 += 4;
p2 += 4;
}
for(i=0; i<vdst.GetLength()%4; i++)
*(p1++) += *(p2++);
return;
}
else
{
//
// general
//
int offset11 = vdst.GetStep(), offset12 = 2*offset11, offset13 = 3*offset11, offset14 = 4*offset11;
int offset21 = vsrc.GetStep(), offset22 = 2*offset21, offset23 = 3*offset21, offset24 = 4*offset21;
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=0; i<imax; i++)
{
*p1 += *p2;
p1[offset11] += p2[offset21];
p1[offset12] += p2[offset22];
p1[offset13] += p2[offset23];
p1 += offset14;
p2 += offset24;
}
for(i=0; i<vdst.GetLength()%4; i++)
{
*p1 += *p2;
p1 += vdst.GetStep();
p2 += vsrc.GetStep();
}
return;
}
}
/********************************************************************
Add one vector multiplied by a number to another vector.
********************************************************************/
template<class T, class T2>
void vadd(raw_vector<T> vdst, const_raw_vector<T> vsrc, T2 alpha)
{
ap_error::make_assertion(vdst.GetLength()==vsrc.GetLength());
if( vdst.GetStep()==1 && vsrc.GetStep()==1 )
{
//
// fast
//
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=imax; i!=0; i--)
{
*p1 += alpha*(*p2);
p1[1] += alpha*p2[1];
p1[2] += alpha*p2[2];
p1[3] += alpha*p2[3];
p1 += 4;
p2 += 4;
}
for(i=0; i<vdst.GetLength()%4; i++)
*(p1++) += alpha*(*(p2++));
return;
}
else
{
//
// general
//
int offset11 = vdst.GetStep(), offset12 = 2*offset11, offset13 = 3*offset11, offset14 = 4*offset11;
int offset21 = vsrc.GetStep(), offset22 = 2*offset21, offset23 = 3*offset21, offset24 = 4*offset21;
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=0; i<imax; i++)
{
*p1 += alpha*(*p2);
p1[offset11] += alpha*p2[offset21];
p1[offset12] += alpha*p2[offset22];
p1[offset13] += alpha*p2[offset23];
p1 += offset14;
p2 += offset24;
}
for(i=0; i<vdst.GetLength()%4; i++)
{
*p1 += alpha*(*p2);
p1 += vdst.GetStep();
p2 += vsrc.GetStep();
}
return;
}
}
/********************************************************************
Vector subtraction
********************************************************************/
template<class T>
void vsub(raw_vector<T> vdst, const_raw_vector<T> vsrc)
{
ap_error::make_assertion(vdst.GetLength()==vsrc.GetLength());
if( vdst.GetStep()==1 && vsrc.GetStep()==1 )
{
//
// fast
//
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=imax; i!=0; i--)
{
*p1 -= *p2;
p1[1] -= p2[1];
p1[2] -= p2[2];
p1[3] -= p2[3];
p1 += 4;
p2 += 4;
}
for(i=0; i<vdst.GetLength()%4; i++)
*(p1++) -= *(p2++);
return;
}
else
{
//
// general
//
int offset11 = vdst.GetStep(), offset12 = 2*offset11, offset13 = 3*offset11, offset14 = 4*offset11;
int offset21 = vsrc.GetStep(), offset22 = 2*offset21, offset23 = 3*offset21, offset24 = 4*offset21;
T *p1 = vdst.GetData();
const T *p2 = vsrc.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=0; i<imax; i++)
{
*p1 -= *p2;
p1[offset11] -= p2[offset21];
p1[offset12] -= p2[offset22];
p1[offset13] -= p2[offset23];
p1 += offset14;
p2 += offset24;
}
for(i=0; i<vdst.GetLength()%4; i++)
{
*p1 -= *p2;
p1 += vdst.GetStep();
p2 += vsrc.GetStep();
}
return;
}
}
/********************************************************************
Subtract one vector multiplied by a number from another vector.
********************************************************************/
template<class T, class T2>
void vsub(raw_vector<T> vdst, const_raw_vector<T> vsrc, T2 alpha)
{
vadd(vdst, vsrc, -alpha);
}
/********************************************************************
In-place vector multiplication
********************************************************************/
template<class T, class T2>
void vmul(raw_vector<T> vdst, T2 alpha)
{
if( vdst.GetStep()==1 )
{
//
// fast
//
T *p1 = vdst.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=imax; i!=0; i--)
{
*p1 *= alpha;
p1[1] *= alpha;
p1[2] *= alpha;
p1[3] *= alpha;
p1 += 4;
}
for(i=0; i<vdst.GetLength()%4; i++)
*(p1++) *= alpha;
return;
}
else
{
//
// general
//
int offset11 = vdst.GetStep(), offset12 = 2*offset11, offset13 = 3*offset11, offset14 = 4*offset11;
T *p1 = vdst.GetData();
int imax = vdst.GetLength()/4;
int i;
for(i=0; i<imax; i++)
{
*p1 *= alpha;
p1[offset11] *= alpha;
p1[offset12] *= alpha;
p1[offset13] *= alpha;
p1 += offset14;
}
for(i=0; i<vdst.GetLength()%4; i++)
{
*p1 *= alpha;
p1 += vdst.GetStep();
}
return;
}
}
/********************************************************************
Template of a dynamical one-dimensional array
********************************************************************/
template<class T>
class template_1d_array
{
public:
template_1d_array()
{
m_Vec=0;
m_iVecSize = 0;
};
~template_1d_array()
{
if(m_Vec)
delete[] m_Vec;
};
template_1d_array(const template_1d_array &rhs)
{
m_iVecSize = rhs.m_iVecSize;
m_iLow = rhs.m_iLow;
m_iHigh = rhs.m_iHigh;
if(rhs.m_Vec)
{
m_Vec = new T[m_iVecSize];
#ifndef UNSAFE_MEM_COPY
for(int i=0; i<m_iVecSize; i++)
m_Vec[i] = rhs.m_Vec[i];
#else
memcpy(m_Vec, rhs.m_Vec, m_iVecSize*sizeof(T));
#endif
}
else
m_Vec=0;
};
const template_1d_array& operator=(const template_1d_array &rhs)
{
if( this==&rhs )
return *this;
m_iLow = rhs.m_iLow;
m_iHigh = rhs.m_iHigh;
m_iVecSize = rhs.m_iVecSize;
if(m_Vec)
delete[] m_Vec;
if(rhs.m_Vec)
{
m_Vec = new T[m_iVecSize];
#ifndef UNSAFE_MEM_COPY
for(int i=0; i<m_iVecSize; i++)
m_Vec[i] = rhs.m_Vec[i];
#else
memcpy(m_Vec, rhs.m_Vec, m_iVecSize*sizeof(T));
#endif
}
else
m_Vec=0;
return *this;
};
const T& operator()(int i) const
{
#ifndef NO_AP_ASSERT
ap_error::make_assertion(i>=m_iLow && i<=m_iHigh);
#endif
return m_Vec[ i-m_iLow ];
};
T& operator()(int i)
{
#ifndef NO_AP_ASSERT
ap_error::make_assertion(i>=m_iLow && i<=m_iHigh);
#endif
return m_Vec[ i-m_iLow ];
};
void setbounds( int iLow, int iHigh )
{
if(m_Vec)
delete[] m_Vec;
m_iLow = iLow;
m_iHigh = iHigh;
m_iVecSize = iHigh-iLow+1;
m_Vec = new T[m_iVecSize];
};
void setcontent( int iLow, int iHigh, const T *pContent )
{
setbounds(iLow, iHigh);
for(int i=iLow; i<=iHigh; i++)
(*this)(i) = pContent[i-iLow];
};
T* getcontent()
{
return m_Vec;
};
const T* getcontent() const
{
return m_Vec;
};
int getlowbound(int iBoundNum = 0) const
{
return m_iLow;
};
int gethighbound(int iBoundNum = 0) const
{
return m_iHigh;
};
raw_vector<T> getvector(int iStart, int iEnd)
{
if( iStart>iEnd || wrongIdx(iStart) || wrongIdx(iEnd) )
return raw_vector<T>(0, 0, 1);
else
return raw_vector<T>(m_Vec+iStart-m_iLow, iEnd-iStart+1, 1);
};
const_raw_vector<T> getvector(int iStart, int iEnd) const
{
if( iStart>iEnd || wrongIdx(iStart) || wrongIdx(iEnd) )
return const_raw_vector<T>(0, 0, 1);
else
return const_raw_vector<T>(m_Vec+iStart-m_iLow, iEnd-iStart+1, 1);
};
private:
bool wrongIdx(int i) const { return i<m_iLow || i>m_iHigh; };
T *m_Vec;
long m_iVecSize;
long m_iLow, m_iHigh;
};
/********************************************************************
Template of a dynamical two-dimensional array
********************************************************************/
template<class T>
class template_2d_array
{
public:
template_2d_array()
{
m_Vec=0;
m_iVecSize=0;
};
~template_2d_array()
{
if(m_Vec)
delete[] m_Vec;
};
template_2d_array(const template_2d_array &rhs)
{
m_iVecSize = rhs.m_iVecSize;
m_iLow1 = rhs.m_iLow1;
m_iLow2 = rhs.m_iLow2;
m_iHigh1 = rhs.m_iHigh1;
m_iHigh2 = rhs.m_iHigh2;
m_iConstOffset = rhs.m_iConstOffset;
m_iLinearMember = rhs.m_iLinearMember;
if(rhs.m_Vec)
{
m_Vec = new T[m_iVecSize];
#ifndef UNSAFE_MEM_COPY
for(int i=0; i<m_iVecSize; i++)
m_Vec[i] = rhs.m_Vec[i];
#else
memcpy(m_Vec, rhs.m_Vec, m_iVecSize*sizeof(T));
#endif
}
else
m_Vec=0;
};
const template_2d_array& operator=(const template_2d_array &rhs)
{
if( this==&rhs )
return *this;
m_iLow1 = rhs.m_iLow1;
m_iLow2 = rhs.m_iLow2;
m_iHigh1 = rhs.m_iHigh1;
m_iHigh2 = rhs.m_iHigh2;
m_iConstOffset = rhs.m_iConstOffset;
m_iLinearMember = rhs.m_iLinearMember;
m_iVecSize = rhs.m_iVecSize;
if(m_Vec)
delete[] m_Vec;
if(rhs.m_Vec)
{
m_Vec = new T[m_iVecSize];
#ifndef UNSAFE_MEM_COPY
for(int i=0; i<m_iVecSize; i++)
m_Vec[i] = rhs.m_Vec[i];
#else
memcpy(m_Vec, rhs.m_Vec, m_iVecSize*sizeof(T));
#endif
}
else
m_Vec=0;
return *this;
};
const T& operator()(int i1, int i2) const
{
#ifndef NO_AP_ASSERT
ap_error::make_assertion(i1>=m_iLow1 && i1<=m_iHigh1);
ap_error::make_assertion(i2>=m_iLow2 && i2<=m_iHigh2);
#endif
return m_Vec[ m_iConstOffset + i2 +i1*m_iLinearMember];
};
T& operator()(int i1, int i2)
{
#ifndef NO_AP_ASSERT
ap_error::make_assertion(i1>=m_iLow1 && i1<=m_iHigh1);
ap_error::make_assertion(i2>=m_iLow2 && i2<=m_iHigh2);
#endif
return m_Vec[ m_iConstOffset + i2 +i1*m_iLinearMember];
};
void setbounds( int iLow1, int iHigh1, int iLow2, int iHigh2 )
{
if(m_Vec)
delete[] m_Vec;
m_iVecSize = (iHigh1-iLow1+1)*(iHigh2-iLow2+1);
m_Vec = new T[m_iVecSize];
m_iLow1 = iLow1;
m_iHigh1 = iHigh1;
m_iLow2 = iLow2;
m_iHigh2 = iHigh2;
m_iConstOffset = -m_iLow2-m_iLow1*(m_iHigh2-m_iLow2+1);
m_iLinearMember = (m_iHigh2-m_iLow2+1);
};
void setcontent( int iLow1, int iHigh1, int iLow2, int iHigh2, const T *pContent )
{
setbounds(iLow1, iHigh1, iLow2, iHigh2);
for(int i=0; i<m_iVecSize; i++)
m_Vec[i]=pContent[i];
};
T* getcontent()
{
return m_Vec;
};
const T* getcontent() const
{
return m_Vec;
};
int getlowbound(int iBoundNum) const
{
return iBoundNum==1 ? m_iLow1 : m_iLow2;
};
int gethighbound(int iBoundNum) const
{
return iBoundNum==1 ? m_iHigh1 : m_iHigh2;
};
raw_vector<T> getcolumn(int iColumn, int iRowStart, int iRowEnd)
{
if( (iRowStart>iRowEnd) || wrongColumn(iColumn) || wrongRow(iRowStart) ||wrongRow(iRowEnd) )
return raw_vector<T>(0, 0, 1);
else
return raw_vector<T>(&((*this)(iRowStart, iColumn)), iRowEnd-iRowStart+1, m_iLinearMember);
};
raw_vector<T> getrow(int iRow, int iColumnStart, int iColumnEnd)
{
if( (iColumnStart>iColumnEnd) || wrongRow(iRow) || wrongColumn(iColumnStart) || wrongColumn(iColumnEnd))
return raw_vector<T>(0, 0, 1);
else
return raw_vector<T>(&((*this)(iRow, iColumnStart)), iColumnEnd-iColumnStart+1, 1);
};
const_raw_vector<T> getcolumn(int iColumn, int iRowStart, int iRowEnd) const
{
if( (iRowStart>iRowEnd) || wrongColumn(iColumn) || wrongRow(iRowStart) ||wrongRow(iRowEnd) )
return const_raw_vector<T>(0, 0, 1);
else
return const_raw_vector<T>(&((*this)(iRowStart, iColumn)), iRowEnd-iRowStart+1, m_iLinearMember);
};
const_raw_vector<T> getrow(int iRow, int iColumnStart, int iColumnEnd) const
{
if( (iColumnStart>iColumnEnd) || wrongRow(iRow) || wrongColumn(iColumnStart) || wrongColumn(iColumnEnd))
return const_raw_vector<T>(0, 0, 1);
else
return const_raw_vector<T>(&((*this)(iRow, iColumnStart)), iColumnEnd-iColumnStart+1, 1);
};
private:
bool wrongRow(int i) const { return i<m_iLow1 || i>m_iHigh1; };
bool wrongColumn(int j) const { return j<m_iLow2 || j>m_iHigh2; };
T *m_Vec;
long m_iVecSize;
long m_iLow1, m_iLow2, m_iHigh1, m_iHigh2;
long m_iConstOffset, m_iLinearMember;
};
typedef template_1d_array<int> integer_1d_array;
typedef template_1d_array<double> real_1d_array;
typedef template_1d_array<complex> complex_1d_array;
typedef template_1d_array<bool> boolean_1d_array;
typedef template_2d_array<int> integer_2d_array;
typedef template_2d_array<double> real_2d_array;
typedef template_2d_array<complex> complex_2d_array;
typedef template_2d_array<bool> boolean_2d_array;
/********************************************************************
Constants and functions introduced for compatibility with AlgoPascal
********************************************************************/
extern const double machineepsilon;
extern const double maxrealnumber;
extern const double minrealnumber;
int sign(double x);
double randomreal();
int randominteger(int maxv);
int round(double x);
int trunc(double x);
int ifloor(double x);
int iceil(double x);
double pi();
double sqr(double x);
int maxint(int m1, int m2);
int minint(int m1, int m2);
double maxreal(double m1, double m2);
double minreal(double m1, double m2);
};//namespace ap
#endif
i
int i
Definition cfEzgcd.cc:132
x
Variable x
Definition cfModGcd.cc:4090
f
FILE * f
Definition checklibs.c:9
ap::ap_error
Definition ap.h:47
ap::ap_error::make_assertion
static void make_assertion(bool bClause)
Definition ap.h:49
ap::complex
Definition ap.h:60
ap::complex::operator+=
complex & operator+=(const double &v)
Definition ap.h:68
ap::complex::operator+=
complex & operator+=(const complex &z)
Definition ap.h:74
ap::complex::complex
complex(const double &_x)
Definition ap.h:63
ap::complex::operator-=
complex & operator-=(const complex &z)
Definition ap.h:75
ap::complex::operator=
complex & operator=(const double &v)
Definition ap.h:67
ap::complex::operator-=
complex & operator-=(const double &v)
Definition ap.h:69
ap::complex::operator*=
complex & operator*=(const complex &z)
Definition ap.h:76
ap::complex::operator*=
complex & operator*=(const double &v)
Definition ap.h:70
ap::complex::operator/=
complex & operator/=(const double &v)
Definition ap.h:71
ap::complex::x
double x
Definition ap.h:100
ap::complex::operator/=
complex & operator/=(const complex &z)
Definition ap.h:77
ap::complex::complex
complex(const double &_x, const double &_y)
Definition ap.h:64
ap::complex::complex
complex()
Definition ap.h:62
ap::complex::complex
complex(const complex &z)
Definition ap.h:65
ap::complex::y
double y
Definition ap.h:100
ap::const_raw_vector
Definition ap.h:137
ap::const_raw_vector::GetStep
int GetStep() const
Definition ap.h:148
ap::const_raw_vector::pData
T * pData
Definition ap.h:151
ap::const_raw_vector::GetData
const T * GetData() const
Definition ap.h:142
ap::const_raw_vector::const_raw_vector
const_raw_vector(const T *Data, int Length, int Step)
Definition ap.h:139
ap::const_raw_vector::iLength
int iLength
Definition ap.h:152
ap::const_raw_vector::iStep
int iStep
Definition ap.h:152
ap::const_raw_vector::GetLength
int GetLength() const
Definition ap.h:145
ap::raw_vector
Definition ap.h:168
ap::raw_vector::GetData
T * GetData()
Definition ap.h:172
ap::raw_vector::raw_vector
raw_vector(T *Data, int Length, int Step)
Definition ap.h:170
ap::template_1d_array
Definition ap.h:657
ap::template_1d_array::getvector
raw_vector< T > getvector(int iStart, int iEnd)
Definition ap.h:776
ap::template_1d_array< int >::m_Vec
int * m_Vec
Definition ap.h:795
ap::template_1d_array::gethighbound
int gethighbound(int iBoundNum=0) const
Definition ap.h:771
ap::template_1d_array::wrongIdx
bool wrongIdx(int i) const
Definition ap.h:793
ap::template_1d_array::getvector
const_raw_vector< T > getvector(int iStart, int iEnd) const
Definition ap.h:785
ap::template_1d_array::operator()
const T & operator()(int i) const
Definition ap.h:717
ap::template_1d_array::getcontent
T * getcontent()
Definition ap.h:754
ap::template_1d_array::getlowbound
int getlowbound(int iBoundNum=0) const
Definition ap.h:765
ap::template_1d_array::template_1d_array
template_1d_array()
Definition ap.h:659
ap::template_1d_array::setcontent
void setcontent(int iLow, int iHigh, const T *pContent)
Definition ap.h:746
ap::template_1d_array::template_1d_array
template_1d_array(const template_1d_array &rhs)
Definition ap.h:671
ap::template_1d_array::operator()
T & operator()(int i)
Definition ap.h:726
ap::template_1d_array::~template_1d_array
~template_1d_array()
Definition ap.h:665
ap::template_1d_array::setbounds
void setbounds(int iLow, int iHigh)
Definition ap.h:735
ap::template_1d_array< int >::m_iLow
long m_iLow
Definition ap.h:797
ap::template_1d_array< int >::m_iHigh
long m_iHigh
Definition ap.h:797
ap::template_1d_array< int >::m_iVecSize
long m_iVecSize
Definition ap.h:796
ap::template_1d_array::operator=
const template_1d_array & operator=(const template_1d_array &rhs)
Definition ap.h:691
ap::template_1d_array::getcontent
const T * getcontent() const
Definition ap.h:759
ap::template_2d_array
Definition ap.h:807
ap::template_2d_array::setcontent
void setcontent(int iLow1, int iHigh1, int iLow2, int iHigh2, const T *pContent)
Definition ap.h:904
ap::template_2d_array< int >::m_iConstOffset
long m_iConstOffset
Definition ap.h:969
ap::template_2d_array< int >::m_iHigh1
long m_iHigh1
Definition ap.h:968
ap::template_2d_array::template_2d_array
template_2d_array(const template_2d_array &rhs)
Definition ap.h:821
ap::template_2d_array::operator()
const T & operator()(int i1, int i2) const
Definition ap.h:872
ap::template_2d_array::setbounds
void setbounds(int iLow1, int iHigh1, int iLow2, int iHigh2)
Definition ap.h:890
ap::template_2d_array< int >::m_iLow2
long m_iLow2
Definition ap.h:968
ap::template_2d_array::wrongRow
bool wrongRow(int i) const
Definition ap.h:963
ap::template_2d_array< int >::m_Vec
int * m_Vec
Definition ap.h:966
ap::template_2d_array::wrongColumn
bool wrongColumn(int j) const
Definition ap.h:964
ap::template_2d_array< int >::m_iLinearMember
long m_iLinearMember
Definition ap.h:969
ap::template_2d_array::getcontent
T * getcontent()
Definition ap.h:911
ap::template_2d_array::getcontent
const T * getcontent() const
Definition ap.h:916
ap::template_2d_array::getlowbound
int getlowbound(int iBoundNum) const
Definition ap.h:921
ap::template_2d_array< int >::m_iVecSize
long m_iVecSize
Definition ap.h:967
ap::template_2d_array::getcolumn
const_raw_vector< T > getcolumn(int iColumn, int iRowStart, int iRowEnd) const
Definition ap.h:947
ap::template_2d_array::template_2d_array
template_2d_array()
Definition ap.h:809
ap::template_2d_array::operator=
const template_2d_array & operator=(const template_2d_array &rhs)
Definition ap.h:843
ap::template_2d_array::~template_2d_array
~template_2d_array()
Definition ap.h:815
ap::template_2d_array::getrow
raw_vector< T > getrow(int iRow, int iColumnStart, int iColumnEnd)
Definition ap.h:939
ap::template_2d_array::getcolumn
raw_vector< T > getcolumn(int iColumn, int iRowStart, int iRowEnd)
Definition ap.h:931
ap::template_2d_array::gethighbound
int gethighbound(int iBoundNum) const
Definition ap.h:926
ap::template_2d_array::getrow
const_raw_vector< T > getrow(int iRow, int iColumnStart, int iColumnEnd) const
Definition ap.h:955
ap::template_2d_array::operator()
T & operator()(int i1, int i2)
Definition ap.h:881
ap::template_2d_array< int >::m_iHigh2
long m_iHigh2
Definition ap.h:968
ap::template_2d_array< int >::m_iLow1
long m_iLow1
Definition ap.h:968
alpha
Variable alpha
Definition facAbsBiFact.cc:52
result
return result
Definition facAbsBiFact.cc:76
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
j
int j
Definition facHensel.cc:110
T
STATIC_VAR jList * T
Definition janet.cc:30
ap
Definition ap.h:40
ap::maxint
int maxint(int m1, int m2)
Definition ap.cpp:162
ap::real_2d_array
template_2d_array< double > real_2d_array
Definition ap.h:978
ap::boolean_1d_array
template_1d_array< bool > boolean_1d_array
Definition ap.h:976
ap::iceil
int iceil(double x)
Definition ap.cpp:153
ap::boolean_2d_array
template_2d_array< bool > boolean_2d_array
Definition ap.h:980
ap::sqr
double sqr(double x)
Definition ap.cpp:159
ap::operator*
const complex operator*(const complex &lhs, const complex &rhs)
Definition ap.cpp:41
ap::csqr
const complex csqr(const complex &z)
Definition ap.cpp:120
ap::vdotproduct
T vdotproduct(const_raw_vector< T > v1, const_raw_vector< T > v2)
Definition ap.h:181
ap::machineepsilon
const double machineepsilon
Definition svd_si.h:995
ap::round
int round(double x)
Definition ap.cpp:144
ap::trunc
int trunc(double x)
Definition ap.cpp:147
ap::vmove
void vmove(raw_vector< T > vdst, const_raw_vector< T > vsrc)
Definition ap.h:237
ap::integer_2d_array
template_2d_array< int > integer_2d_array
Definition ap.h:977
ap::minrealnumber
const double minrealnumber
Definition svd_si.h:997
ap::complex_2d_array
template_2d_array< complex > complex_2d_array
Definition ap.h:979
ap::vmoveneg
void vmoveneg(raw_vector< T > vdst, const_raw_vector< T > vsrc)
Definition ap.h:295
ap::vadd
void vadd(raw_vector< T > vdst, const_raw_vector< T > vsrc)
Definition ap.h:413
ap::randomreal
double randomreal()
Definition ap.cpp:133
ap::randominteger
int randominteger(int maxv)
Definition ap.cpp:141
ap::sign
int sign(double x)
Definition ap.cpp:126
ap::maxreal
double maxreal(double m1, double m2)
Definition ap.cpp:172
ap::abscomplex
const double abscomplex(const complex &z)
Definition ap.cpp:97
ap::complex_1d_array
template_1d_array< complex > complex_1d_array
Definition ap.h:975
ap::operator!=
const bool operator!=(const complex &lhs, const complex &rhs)
Definition ap.cpp:14
ap::minreal
double minreal(double m1, double m2)
Definition ap.cpp:177
ap::minint
int minint(int m1, int m2)
Definition ap.cpp:167
ap::vmul
void vmul(raw_vector< T > vdst, T2 alpha)
Definition ap.h:603
ap::pi
double pi()
Definition ap.cpp:156
ap::vsub
void vsub(raw_vector< T > vdst, const_raw_vector< T > vsrc)
Definition ap.h:533
ap::conj
const complex conj(const complex &z)
Definition ap.cpp:117
ap::operator+
const complex operator+(const complex &lhs)
Definition ap.cpp:17
ap::ifloor
int ifloor(double x)
Definition ap.cpp:150
ap::operator/
const complex operator/(const complex &lhs, const complex &rhs)
Definition ap.cpp:50
ap::integer_1d_array
template_1d_array< int > integer_1d_array
Definition ap.h:973
ap::maxrealnumber
const double maxrealnumber
Definition svd_si.h:996
ap::operator==
const bool operator==(const complex &lhs, const complex &rhs)
Definition ap.cpp:11
ap::operator-
const complex operator-(const complex &lhs)
Definition ap.cpp:20
ap::real_1d_array
template_1d_array< double > real_1d_array
Definition ap.h:974