	__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;
	}


//
//Matrix Header Stuff
//

	__host__ __device__ cumat3i::cumat3i() 
	{
		m00 = 0;
		m01 = 0;
		m02 = 0;

		m10 = 0;
		m11 = 0;
		m12 = 0;

		m20 = 0;
		m21 = 0;
		m22 = 0;

		return;
	}

	__host__ __device__ cumat3i::~cumat3i() 
	{
		//m00 = 0;
		//m01 = 0;
		//m02 = 0;

		//m10 = 0;
		//m11 = 0;
		//m12 = 0;

		//m20 = 0;
		//m21 = 0;
		//m22 = 0;

		return;
	}

	__host__ __device__ cumat3i::cumat3i(
		const int& _m00, const int& _m01, const int& _m02, 
		const int& _m10, const int& _m11, const int& _m12, 
		const int& _m20, const int& _m21, const int& _m22
	)
	{
		m00 = _m00; 
		m10 = _m10; 
		m20 = _m20; 

		m01 = _m01; 
		m11 = _m11; 
		m21 = _m21; 

		m02 = _m02; 
		m12 = _m12; 
		m22 = _m22; 


		return;
	}

	__host__ __device__ cumat3i::cumat3i(const int* data9)
	{
		m00 = data9[0]; 
		m10 = data9[1]; 
		m20 = data9[2]; 

		m01 = data9[3]; 
		m11 = data9[4]; 
		m21 = data9[5]; 

		m02 = data9[6]; 
		m12 = data9[7]; 
		m22 = data9[8]; 


		return;
	}

	__host__ __device__ int& cumat3i::operator[](const int &I)
	{
		switch(I)
		{
			case 0:
				return m00;
			case 1:
				return m10;
			case 2:
				return m20;
			case 3:
				return m01;
			case 4:
				return m11;
			case 5:
				return m21;
			case 6:
				return m02;
			case 7:
				return m12;
			case 8:
				return m22;
		}

		return m00;
	}

	__host__ __device__ const int& cumat3i::operator[](const int &I) const
	{
		switch(I)
		{
			case 0:
				return m00;
			case 1:
				return m10;
			case 2:
				return m20;
			case 3:
				return m01;
			case 4:
				return m11;
			case 5:
				return m21;
			case 6:
				return m02;
			case 7:
				return m12;
			case 8:
				return m22;
		}

		return m00;
	}

	__host__ __device__ int& cumat3i::operator()(const int &I, const int &J)
	{
		return (*this)[I+3*J];
	}

	__host__ __device__ const int& cumat3i::operator()(const int &I, const int &J) const
	{
		return (*this)[I+3*J];
	}

	__host__ __device__ int& cumat3i::at(const int &I, const int &J)
	{
		return (*this)[I+3*J];
	}

	__host__ __device__ const int& cumat3i::at(const int &I, const int &J) const
	{
		return (*this)[I+3*J];
	}

__host__ __device__ int* cumat3i::data()
{
	return (int*)this;
}

__host__ __device__ const int* cumat3i::data() const
{
	return (int*)this;
}

__host__ __device__ cumat3i cumat3i::operator+(const cumat3i& rhs) const
{
	cumat3i ret;
	ret.m00 = m00 + rhs.m00;
	ret.m10 = m10 + rhs.m10;
	ret.m20 = m20 + rhs.m20;

	ret.m01 = m01 + rhs.m01;
	ret.m11 = m11 + rhs.m11;
	ret.m21 = m21 + rhs.m21;

	ret.m02 = m02 + rhs.m02;
	ret.m12 = m12 + rhs.m12;
	ret.m22 = m22 + rhs.m22;

	return ret;
}

__host__ __device__ cumat3i cumat3i::operator-(const cumat3i& rhs) const
{
	cumat3i ret;
	ret.m00 = m00 - rhs.m00;
	ret.m10 = m10 - rhs.m10;
	ret.m20 = m20 - rhs.m20;

	ret.m01 = m01 - rhs.m01;
	ret.m11 = m11 - rhs.m11;
	ret.m21 = m21 - rhs.m21;

	ret.m02 = m02 - rhs.m02;
	ret.m12 = m12 - rhs.m12;
	ret.m22 = m22 - rhs.m22;

	return ret;
}

__host__ __device__ cumat3i cumat3i::operator*(const cumat3i& rhs) const
{
	cumat3i ret; //should be zeroed in constructor
	ret.m00 = m00*rhs.m00 + m01*rhs.m10 + m02*rhs.m20;
	ret.m01 = m00*rhs.m01 + m01*rhs.m11 + m02*rhs.m21;
	ret.m02 = m00*rhs.m02 + m01*rhs.m12 + m02*rhs.m22;

	ret.m10 = m10*rhs.m00 + m11*rhs.m10 + m12*rhs.m20;
	ret.m11 = m10*rhs.m01 + m11*rhs.m11 + m12*rhs.m21;
	ret.m12 = m10*rhs.m02 + m11*rhs.m12 + m12*rhs.m22;

	ret.m20 = m20*rhs.m00 + m21*rhs.m10 + m22*rhs.m20;
	ret.m21 = m20*rhs.m01 + m21*rhs.m11 + m22*rhs.m21;
	ret.m22 = m20*rhs.m02 + m21*rhs.m12 + m22*rhs.m22;

	return ret;
}

__host__ __device__ cumat3i operator*(const cumat3i& lhs, const int& rhs)
{
	cumat3i ret;
	ret.m00=lhs.m00*rhs;
	ret.m10=lhs.m10*rhs;
	ret.m20=lhs.m20*rhs;
	ret.m01=lhs.m01*rhs;
	ret.m11=lhs.m11*rhs;
	ret.m21=lhs.m21*rhs;
	ret.m02=lhs.m02*rhs;
	ret.m12=lhs.m12*rhs;
	ret.m22=lhs.m22*rhs;
	return ret;
}

__host__ __device__ cumat3i operator/(const cumat3i& lhs, const int& rhs)
{
	cumat3i ret;
	ret.m00=lhs.m00/rhs;
	ret.m10=lhs.m10/rhs;
	ret.m20=lhs.m20/rhs;
	ret.m01=lhs.m01/rhs;
	ret.m11=lhs.m11/rhs;
	ret.m21=lhs.m21/rhs;
	ret.m02=lhs.m02/rhs;
	ret.m12=lhs.m12/rhs;
	ret.m22=lhs.m22/rhs;
	return ret;
}

__host__ __device__ cumat3i operator*(const int& lhs, const cumat3i& rhs)
{
	cumat3i ret;
	ret.m00=lhs*rhs.m00;
	ret.m10=lhs*rhs.m10;
	ret.m20=lhs*rhs.m20;
	ret.m01=lhs*rhs.m01;
	ret.m11=lhs*rhs.m11;
	ret.m21=lhs*rhs.m21;
	ret.m02=lhs*rhs.m02;
	ret.m12=lhs*rhs.m12;
	ret.m22=lhs*rhs.m22;
	return ret;
}

__host__ __device__ cuvec3i operator*(const cumat3i& lhs, const cuvec3i& rhs)
{
	cuvec3i ret;
	ret.x = lhs.m00*rhs.x + lhs.m01*rhs.y + lhs.m02*rhs.z;
	ret.y = lhs.m10*rhs.x + lhs.m11*rhs.y + lhs.m12*rhs.z;
	ret.z = lhs.m20*rhs.x + lhs.m21*rhs.y + lhs.m22*rhs.z;
	return ret;
}

__host__ __device__ cuvec3i operator*(const cuvec3i& lhs, const cumat3i& rhs)
{
	cuvec3i ret;
	ret.x = lhs.x*rhs.m00 + lhs.y*rhs.m10 + lhs.z*rhs.m20;
	ret.y = lhs.x*rhs.m01 + lhs.y*rhs.m11 + lhs.z*rhs.m21;
	ret.z = lhs.x*rhs.m02 + lhs.y*rhs.m12 + lhs.z*rhs.m22;
	return ret;
}

__host__ __device__ cumat3i operator-(const cumat3i& rhs)
{
	cumat3i ret;
	ret.m00 = -rhs.m00;
	ret.m10 = -rhs.m10;
	ret.m20 = -rhs.m20;
	ret.m01 = -rhs.m01;
	ret.m11 = -rhs.m11;
	ret.m21 = -rhs.m21;
	ret.m02 = -rhs.m02;
	ret.m12 = -rhs.m12;
	ret.m22 = -rhs.m22;
	return ret;
}

__host__ __device__ cumat3i& cumat3i::operator+=(const cumat3i& rhs)
{
	m00 += rhs.m00;
	m10 += rhs.m10;
	m20 += rhs.m20;
	m01 += rhs.m01;
	m11 += rhs.m11;
	m21 += rhs.m21;
	m02 += rhs.m02;
	m12 += rhs.m12;
	m22 += rhs.m22;
	return *this;
}

__host__ __device__ cumat3i& cumat3i::operator-=(const cumat3i& rhs)
{
	m00 -= rhs.m00;
	m10 -= rhs.m10;
	m20 -= rhs.m20;
	m01 -= rhs.m01;
	m11 -= rhs.m11;
	m21 -= rhs.m21;
	m02 -= rhs.m02;
	m12 -= rhs.m12;
	m22 -= rhs.m22;
	return *this;
}

__host__ __device__ cumat3i& cumat3i::operator*=(const int& rhs)
{
	m00 *= rhs;
	m10 *= rhs;
	m20 *= rhs;
	m01 *= rhs;
	m11 *= rhs;
	m21 *= rhs;
	m02 *= rhs;
	m12 *= rhs;
	m22 *= rhs;
	return *this;
}

__host__ __device__ cumat3i& cumat3i::operator/=(const int& rhs)
{
	m00 /= rhs;
	m10 /= rhs;
	m20 /= rhs;
	m01 /= rhs;
	m11 /= rhs;
	m21 /= rhs;
	m02 /= rhs;
	m12 /= rhs;
	m22 /= rhs;
	return *this;
}

__host__ __device__ cumat3i& cumat3i::operator*=(const cumat3i& rhs)
{
	cumat3i tmp = *this;
	m00 = tmp.m00*rhs.m00 + tmp.m01*rhs.m10 + tmp.m02*rhs.m20;
	m01 = tmp.m00*rhs.m01 + tmp.m01*rhs.m11 + tmp.m02*rhs.m21;
	m02 = tmp.m00*rhs.m02 + tmp.m01*rhs.m12 + tmp.m02*rhs.m22;
	m10 = tmp.m10*rhs.m00 + tmp.m11*rhs.m10 + tmp.m12*rhs.m20;
	m11 = tmp.m10*rhs.m01 + tmp.m11*rhs.m11 + tmp.m12*rhs.m21;
	m12 = tmp.m10*rhs.m02 + tmp.m11*rhs.m12 + tmp.m12*rhs.m22;
	m20 = tmp.m20*rhs.m00 + tmp.m21*rhs.m10 + tmp.m22*rhs.m20;
	m21 = tmp.m20*rhs.m01 + tmp.m21*rhs.m11 + tmp.m22*rhs.m21;
	m22 = tmp.m20*rhs.m02 + tmp.m21*rhs.m12 + tmp.m22*rhs.m22;
	return *this;
}

__host__ __device__ cumat3i cumat3i::transpose() const
{
	cumat3i ret;
	ret.m00 = m00;
	ret.m10 = m01;
	ret.m20 = m02;
	ret.m01 = m10;
	ret.m11 = m11;
	ret.m21 = m12;
	ret.m02 = m20;
	ret.m12 = m21;
	ret.m22 = m22;
	return ret;
}

