2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2::cuvec2()
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
x = 0; y = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2::~cuvec2()
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
x = 0; y = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2::cuvec2(const double &_x, const double &_y)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
x = _x; y = _y;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 12:16:10 -04:00
|
|
|
__host__ __device__ double& cuvec2::operator[](const int &I)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
switch(I)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
return x;
|
|
|
|
|
case 1:
|
|
|
|
|
return y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 12:16:10 -04:00
|
|
|
__host__ __device__ const double& cuvec2::operator[](const int &I) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
switch(I)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
return x;
|
|
|
|
|
case 1:
|
|
|
|
|
return y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 cuvec2::operator+(const cuvec2& rhs) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = x + rhs.x;
|
|
|
|
|
ret.y = y + rhs.y;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 cuvec2::operator-(const cuvec2& rhs) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = x - rhs.x;
|
|
|
|
|
ret.y = y - rhs.y;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 cuvec2::operator*(const cuvec2& rhs) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
//Elementwise product
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = x * rhs.x;
|
|
|
|
|
ret.y = y * rhs.y;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 cuvec2::operator/(const cuvec2& rhs) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
//Elementwise division
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = x / rhs.x;
|
|
|
|
|
ret.y = y / rhs.y;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 operator*(const cuvec2& lhs, const double& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = lhs.x*rhs;
|
|
|
|
|
ret.y = lhs.y*rhs;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 operator*(const double& lhs, const cuvec2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = lhs*rhs.x;
|
|
|
|
|
ret.y = lhs*rhs.y;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 operator/(const cuvec2& lhs, const double& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = lhs.x/rhs;
|
|
|
|
|
ret.y = lhs.y/rhs;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 operator/(const double& lhs, const cuvec2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = lhs/rhs.x;
|
|
|
|
|
ret.y = lhs/rhs.y;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 operator-(const cuvec2& other)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = -other.x;
|
|
|
|
|
ret.y = -other.y;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2& cuvec2::operator+=(const cuvec2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
x += rhs.x;
|
|
|
|
|
y += rhs.y;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2& cuvec2::operator-=(const cuvec2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
x -= rhs.x;
|
|
|
|
|
y -= rhs.y;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2& cuvec2::operator*=(const double& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
x *= rhs;
|
|
|
|
|
y *= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2& cuvec2::operator/=(const double& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
x /= rhs;
|
|
|
|
|
y /= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//Matrix Header Stuff
|
|
|
|
|
//
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2::cumat2()
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
m00 = 0;
|
|
|
|
|
m01 = 0;
|
|
|
|
|
|
|
|
|
|
m10 = 0;
|
|
|
|
|
m11 = 0;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2::~cumat2()
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
//m00 = 0;
|
|
|
|
|
//m01 = 0;
|
|
|
|
|
|
|
|
|
|
//m10 = 0;
|
|
|
|
|
//m11 = 0;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2::cumat2(
|
|
|
|
|
const double& _m00, const double& _m01,
|
|
|
|
|
const double& _m10, const double& _m11
|
2026-04-13 06:45:12 -04:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
m00 = _m00;
|
|
|
|
|
m10 = _m10;
|
|
|
|
|
|
|
|
|
|
m01 = _m01;
|
|
|
|
|
m11 = _m11;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2::cumat2(const double* data4)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
m00 = data4[0];
|
|
|
|
|
m10 = data4[1];
|
|
|
|
|
|
|
|
|
|
m01 = data4[2];
|
|
|
|
|
m11 = data4[3];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 12:16:10 -04:00
|
|
|
__host__ __device__ double& cumat2::operator[](const int &I)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
switch(I)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
return m00;
|
|
|
|
|
case 1:
|
|
|
|
|
return m10;
|
|
|
|
|
case 2:
|
|
|
|
|
return m01;
|
|
|
|
|
case 3:
|
|
|
|
|
return m11;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return m00;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 12:16:10 -04:00
|
|
|
__host__ __device__ const double& cumat2::operator[](const int &I) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
switch(I)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
return m00;
|
|
|
|
|
case 1:
|
|
|
|
|
return m10;
|
|
|
|
|
case 2:
|
|
|
|
|
return m01;
|
|
|
|
|
case 3:
|
|
|
|
|
return m11;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return m00;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 12:16:10 -04:00
|
|
|
__host__ __device__ double& cumat2::operator()(const int &I, const int &J)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
return (*this)[I+2*J];
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 12:16:10 -04:00
|
|
|
__host__ __device__ const double& cumat2::operator()(const int &I, const int &J) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
return (*this)[I+2*J];
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 12:16:10 -04:00
|
|
|
__host__ __device__ double& cumat2::at(const int &I, const int &J)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
return (*this)[I+2*J];
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 12:16:10 -04:00
|
|
|
__host__ __device__ const double& cumat2::at(const int &I, const int &J) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
return (*this)[I+2*J];
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ double* cumat2::data()
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
return (double*)this;
|
2026-04-13 06:45:12 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ const double* cumat2::data() const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
return (double*)this;
|
2026-04-13 06:45:12 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2 cumat2::operator+(const cumat2& rhs) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cumat2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.m00 = m00 + rhs.m00;
|
|
|
|
|
ret.m10 = m10 + rhs.m10;
|
|
|
|
|
|
|
|
|
|
ret.m01 = m01 + rhs.m01;
|
|
|
|
|
ret.m11 = m11 + rhs.m11;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2 cumat2::operator-(const cumat2& rhs) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cumat2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.m00 = m00 - rhs.m00;
|
|
|
|
|
ret.m10 = m10 - rhs.m10;
|
|
|
|
|
|
|
|
|
|
ret.m01 = m01 - rhs.m01;
|
|
|
|
|
ret.m11 = m11 - rhs.m11;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2 cumat2::operator*(const cumat2& rhs) const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cumat2 ret; //should be zeroed in constructor
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.m00 = m00*rhs.m00 + m01*rhs.m10;
|
|
|
|
|
ret.m01 = m00*rhs.m01 + m01*rhs.m11;
|
|
|
|
|
|
|
|
|
|
ret.m10 = m10*rhs.m00 + m11*rhs.m10;
|
|
|
|
|
ret.m11 = m10*rhs.m01 + m11*rhs.m11;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2 operator*(const cumat2& lhs, const double& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cumat2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.m00=lhs.m00*rhs;
|
|
|
|
|
ret.m10=lhs.m10*rhs;
|
|
|
|
|
ret.m01=lhs.m01*rhs;
|
|
|
|
|
ret.m11=lhs.m11*rhs;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2 operator/(const cumat2& lhs, const double& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cumat2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.m00=lhs.m00/rhs;
|
|
|
|
|
ret.m10=lhs.m10/rhs;
|
|
|
|
|
ret.m01=lhs.m01/rhs;
|
|
|
|
|
ret.m11=lhs.m11/rhs;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2 operator*(const double& lhs, const cumat2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cumat2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.m00=lhs*rhs.m00;
|
|
|
|
|
ret.m10=lhs*rhs.m10;
|
|
|
|
|
ret.m01=lhs*rhs.m01;
|
|
|
|
|
ret.m11=lhs*rhs.m11;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 operator*(const cumat2& lhs, const cuvec2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = lhs.m00*rhs.x + lhs.m01*rhs.y;
|
|
|
|
|
ret.y = lhs.m10*rhs.x + lhs.m11*rhs.y;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cuvec2 operator*(const cuvec2& lhs, const cumat2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cuvec2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.x = lhs.x*rhs.m00 + lhs.y*rhs.m10;
|
|
|
|
|
ret.y = lhs.x*rhs.m01 + lhs.y*rhs.m11;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2 operator-(const cumat2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cumat2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.m00 = -rhs.m00;
|
|
|
|
|
ret.m10 = -rhs.m10;
|
|
|
|
|
ret.m01 = -rhs.m01;
|
|
|
|
|
ret.m11 = -rhs.m11;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2& cumat2::operator+=(const cumat2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
m00 += rhs.m00;
|
|
|
|
|
m10 += rhs.m10;
|
|
|
|
|
m01 += rhs.m01;
|
|
|
|
|
m11 += rhs.m11;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2& cumat2::operator-=(const cumat2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
m00 -= rhs.m00;
|
|
|
|
|
m10 -= rhs.m10;
|
|
|
|
|
m01 -= rhs.m01;
|
|
|
|
|
m11 -= rhs.m11;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2& cumat2::operator*=(const double& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
m00 *= rhs;
|
|
|
|
|
m10 *= rhs;
|
|
|
|
|
m01 *= rhs;
|
|
|
|
|
m11 *= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2& cumat2::operator/=(const double& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
|
|
|
|
m00 /= rhs;
|
|
|
|
|
m10 /= rhs;
|
|
|
|
|
m01 /= rhs;
|
|
|
|
|
m11 /= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2& cumat2::operator*=(const cumat2& rhs)
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cumat2 tmp = *this;
|
2026-04-13 06:45:12 -04:00
|
|
|
m00 = tmp.m00*rhs.m00 + tmp.m01*rhs.m10;
|
|
|
|
|
m01 = tmp.m00*rhs.m01 + tmp.m01*rhs.m11;
|
|
|
|
|
m10 = tmp.m10*rhs.m00 + tmp.m11*rhs.m10;
|
|
|
|
|
m11 = tmp.m10*rhs.m01 + tmp.m11*rhs.m11;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 11:42:40 -04:00
|
|
|
__host__ __device__ cumat2 cumat2::transpose() const
|
2026-04-13 06:45:12 -04:00
|
|
|
{
|
2026-04-13 11:42:40 -04:00
|
|
|
cumat2 ret;
|
2026-04-13 06:45:12 -04:00
|
|
|
ret.m00 = m00;
|
|
|
|
|
ret.m10 = m01;
|
|
|
|
|
ret.m01 = m10;
|
|
|
|
|
ret.m11 = m11;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|