integer vector types

This commit is contained in:
2026-04-13 12:16:10 -04:00
parent e3be5a8a2c
commit 4530ed3603
23 changed files with 757 additions and 126 deletions

View File

@ -0,0 +1,167 @@
#include <amsculib3/amsculib3.hpp>
namespace amscuda
{
//////////////////
// Vector Class //
//////////////////
__host__ __device__ cuvec2i::cuvec2i()
{
x = 0; y = 0;
return;
}
__host__ __device__ cuvec2i::~cuvec2i()
{
x = 0; y = 0;
return;
}
__host__ __device__ cuvec2i::cuvec2i(const int32_t &_x, const int32_t &_y)
{
x = _x; y = _y;
return;
}
__host__ __device__ int32_t& cuvec2i::operator[](const int &I)
{
switch(I)
{
case 0:
return x;
case 1:
return y;
}
return x;
}
__host__ __device__ const int32_t& cuvec2i::operator[](const int &I) const
{
switch(I)
{
case 0:
return x;
case 1:
return y;
}
return x;
}
__host__ __device__ cuvec2i cuvec2i::operator+(const cuvec2i& rhs) const
{
cuvec2i ret;
ret.x = x + rhs.x;
ret.y = y + rhs.y;
return ret;
}
__host__ __device__ cuvec2i cuvec2i::operator-(const cuvec2i& rhs) const
{
cuvec2i ret;
ret.x = x - rhs.x;
ret.y = y - rhs.y;
return ret;
}
__host__ __device__ cuvec2i cuvec2i::operator*(const cuvec2i& rhs) const
{
//Elementwise product
cuvec2i ret;
ret.x = x * rhs.x;
ret.y = y * rhs.y;
return ret;
}
__host__ __device__ cuvec2i cuvec2i::operator/(const cuvec2i& rhs) const
{
//Elementwise division
cuvec2i ret;
ret.x = x / rhs.x;
ret.y = y / rhs.y;
return ret;
}
__host__ __device__ cuvec2i operator*(const cuvec2i& lhs, const int32_t& rhs)
{
cuvec2i ret;
ret.x = lhs.x*rhs;
ret.y = lhs.y*rhs;
return ret;
}
__host__ __device__ cuvec2i operator*(const int32_t& lhs, const cuvec2i& rhs)
{
cuvec2i ret;
ret.x = lhs*rhs.x;
ret.y = lhs*rhs.y;
return ret;
}
__host__ __device__ cuvec2i operator/(const cuvec2i& lhs, const int32_t& rhs)
{
cuvec2i ret;
ret.x = lhs.x/rhs;
ret.y = lhs.y/rhs;
return ret;
}
__host__ __device__ cuvec2i operator/(const int32_t& lhs, const cuvec2i& rhs)
{
cuvec2i ret;
ret.x = lhs/rhs.x;
ret.y = lhs/rhs.y;
return ret;
}
__host__ __device__ cuvec2i operator-(const cuvec2i& other)
{
cuvec2i ret;
ret.x = -other.x;
ret.y = -other.y;
return ret;
}
__host__ __device__ cuvec2i& cuvec2i::operator+=(const cuvec2i& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
__host__ __device__ cuvec2i& cuvec2i::operator-=(const cuvec2i& rhs)
{
x -= rhs.x;
y -= rhs.y;
return *this;
}
__host__ __device__ cuvec2i& cuvec2i::operator*=(const int32_t& rhs)
{
x *= rhs;
y *= rhs;
return *this;
}
__host__ __device__ cuvec2i& cuvec2i::operator/=(const int32_t& rhs)
{
x /= rhs;
y /= rhs;
return *this;
}
//////////////////////
// Standalone Funcs //
//////////////////////
///////////
// Tests //
///////////
};

View File

@ -0,0 +1,183 @@
#include <amsculib3/amsculib3.hpp>
namespace amscuda
{
//////////////////
// Vector Class //
//////////////////
__host__ __device__ cuvec3i::cuvec3i()
{
x = 0; y = 0; z = 0;
return;
}
__host__ __device__ cuvec3i::~cuvec3i()
{
x = 0; y = 0; z = 0;
return;
}
__host__ __device__ cuvec3i::cuvec3i(const int &_x, const int &_y, const int &_z)
{
x = _x; y = _y; z = _z;
return;
}
__host__ __device__ int& cuvec3i::operator[](const int &I)
{
switch(I)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
}
return x;
}
__host__ __device__ const int& cuvec3i::operator[](const int &I) const
{
switch(I)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
}
return x;
}
__host__ __device__ cuvec3i cuvec3i::operator+(const cuvec3i& rhs) const
{
cuvec3i ret;
ret.x = x + rhs.x;
ret.y = y + rhs.y;
ret.z = z + rhs.z;
return ret;
}
__host__ __device__ cuvec3i cuvec3i::operator-(const cuvec3i& rhs) const
{
cuvec3i ret;
ret.x = x - rhs.x;
ret.y = y - rhs.y;
ret.z = z - rhs.z;
return ret;
}
__host__ __device__ cuvec3i cuvec3i::operator*(const cuvec3i& rhs) const
{
//Elementwise product
cuvec3i ret;
ret.x = x * rhs.x;
ret.y = y * rhs.y;
ret.z = z * rhs.z;
return ret;
}
__host__ __device__ cuvec3i cuvec3i::operator/(const cuvec3i& rhs) const
{
//Elementwise division
cuvec3i ret;
ret.x = x / rhs.x;
ret.y = y / rhs.y;
ret.z = z / rhs.z;
return ret;
}
__host__ __device__ cuvec3i operator*(const cuvec3i& lhs, const int& rhs)
{
cuvec3i ret;
ret.x = lhs.x*rhs;
ret.y = lhs.y*rhs;
ret.z = lhs.z*rhs;
return ret;
}
__host__ __device__ cuvec3i operator*(const int& lhs, const cuvec3i& rhs)
{
cuvec3i ret;
ret.x = lhs*rhs.x;
ret.y = lhs*rhs.y;
ret.z = lhs*rhs.z;
return ret;
}
__host__ __device__ cuvec3i operator/(const cuvec3i& lhs, const int& rhs)
{
cuvec3i ret;
ret.x = lhs.x/rhs;
ret.y = lhs.y/rhs;
ret.z = lhs.z/rhs;
return ret;
}
__host__ __device__ cuvec3i operator/(const int& lhs, const cuvec3i& rhs)
{
cuvec3i ret;
ret.x = lhs/rhs.x;
ret.y = lhs/rhs.y;
ret.z = lhs/rhs.z;
return ret;
}
__host__ __device__ cuvec3i operator-(const cuvec3i& other)
{
cuvec3i ret;
ret.x = -other.x;
ret.y = -other.y;
ret.z = -other.z;
return ret;
}
__host__ __device__ cuvec3i& cuvec3i::operator+=(const cuvec3i& rhs)
{
x += rhs.x;
y += rhs.y;
z += rhs.z;
return *this;
}
__host__ __device__ cuvec3i& cuvec3i::operator-=(const cuvec3i& rhs)
{
x -= rhs.x;
y -= rhs.y;
z -= rhs.z;
return *this;
}
__host__ __device__ cuvec3i& cuvec3i::operator*=(const int& rhs)
{
x *= rhs;
y *= rhs;
z *= rhs;
return *this;
}
__host__ __device__ cuvec3i& cuvec3i::operator/=(const int& rhs)
{
x /= rhs;
y /= rhs;
z /= rhs;
return *this;
}
//////////////////////
// Standalone Funcs //
//////////////////////
///////////
// Tests //
///////////
};

View File

@ -0,0 +1,200 @@
#include <amsculib3/amsculib3.hpp>
namespace amscuda
{
//////////////////
// Vector Class //
//////////////////
__host__ __device__ cuvec4i::cuvec4i()
{
x = 0; y = 0; z = 0; w = 0;
return;
}
__host__ __device__ cuvec4i::~cuvec4i()
{
x = 0; y = 0; z = 0; w = 0;
return;
}
__host__ __device__ cuvec4i::cuvec4i(const int &_x, const int &_y, const int &_z, const int &_w)
{
x = _x; y = _y; z = _z; w = _w;
return;
}
__host__ __device__ int& cuvec4i::operator[](const int &I)
{
switch(I)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
case 3:
return w;
}
return x;
}
__host__ __device__ const int& cuvec4i::operator[](const int &I) const
{
switch(I)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
case 3:
return w;
}
return x;
}
__host__ __device__ cuvec4i cuvec4i::operator+(const cuvec4i& rhs) const
{
cuvec4i ret;
ret.x = x + rhs.x;
ret.y = y + rhs.y;
ret.z = z + rhs.z;
ret.w = w + rhs.w;
return ret;
}
__host__ __device__ cuvec4i cuvec4i::operator-(const cuvec4i& rhs) const
{
cuvec4i ret;
ret.x = x - rhs.x;
ret.y = y - rhs.y;
ret.z = z - rhs.z;
ret.w = w - rhs.w;
return ret;
}
__host__ __device__ cuvec4i cuvec4i::operator*(const cuvec4i& rhs) const
{
//Elementwise product
cuvec4i ret;
ret.x = x * rhs.x;
ret.y = y * rhs.y;
ret.z = z * rhs.z;
ret.w = w * rhs.w;
return ret;
}
__host__ __device__ cuvec4i cuvec4i::operator/(const cuvec4i& rhs) const
{
//Elementwise division
cuvec4i ret;
ret.x = x / rhs.x;
ret.y = y / rhs.y;
ret.z = z / rhs.z;
ret.w = w / rhs.w;
return ret;
}
__host__ __device__ cuvec4i operator*(const cuvec4i& lhs, const int& rhs)
{
cuvec4i ret;
ret.x = lhs.x*rhs;
ret.y = lhs.y*rhs;
ret.z = lhs.z*rhs;
ret.w = lhs.w*rhs;
return ret;
}
__host__ __device__ cuvec4i operator*(const int& lhs, const cuvec4i& rhs)
{
cuvec4i ret;
ret.x = lhs*rhs.x;
ret.y = lhs*rhs.y;
ret.z = lhs*rhs.z;
ret.w = lhs*rhs.w;
return ret;
}
__host__ __device__ cuvec4i operator/(const cuvec4i& lhs, const int& rhs)
{
cuvec4i ret;
ret.x = lhs.x/rhs;
ret.y = lhs.y/rhs;
ret.z = lhs.z/rhs;
ret.w = lhs.w/rhs;
return ret;
}
__host__ __device__ cuvec4i operator/(const int& lhs, const cuvec4i& rhs)
{
cuvec4i ret;
ret.x = lhs/rhs.x;
ret.y = lhs/rhs.y;
ret.z = lhs/rhs.z;
ret.w = lhs/rhs.w;
return ret;
}
__host__ __device__ cuvec4i operator-(const cuvec4i& other)
{
cuvec4i ret;
ret.x = -other.x;
ret.y = -other.y;
ret.z = -other.z;
ret.w = -other.w;
return ret;
}
__host__ __device__ cuvec4i& cuvec4i::operator+=(const cuvec4i& rhs)
{
x += rhs.x;
y += rhs.y;
z += rhs.z;
w += rhs.w;
return *this;
}
__host__ __device__ cuvec4i& cuvec4i::operator-=(const cuvec4i& rhs)
{
x -= rhs.x;
y -= rhs.y;
z -= rhs.z;
w -= rhs.w;
return *this;
}
__host__ __device__ cuvec4i& cuvec4i::operator*=(const int& rhs)
{
x *= rhs;
y *= rhs;
z *= rhs;
w *= rhs;
return *this;
}
__host__ __device__ cuvec4i& cuvec4i::operator/=(const int& rhs)
{
x /= rhs;
y /= rhs;
z /= rhs;
w /= rhs;
return *this;
}
//////////////////////
// Standalone Funcs //
//////////////////////
///////////
// Tests //
///////////
};