36 Matrix3D(T *data,
int dim_x,
int dim_y,
int dim_z) : m_data(data), m_dim_x(dim_x), m_dim_y(dim_y), m_dim_z(dim_z) {}
38#if defined(__CUDACC__)
39 __host__ __device__ T &operator()(
int x,
int y,
int z) {
return m_data[x * m_dim_y * m_dim_z + y * m_dim_z + z]; }
41 __host__ __device__
const T &operator()(
int x,
int y,
int z)
const {
42 return m_data[x * m_dim_y * m_dim_z + y * m_dim_z + z];
45 T &operator()(
int x,
int y,
int z) {
46 if (x < 0 || x >= m_dim_x || y < 0 || y >= m_dim_y || z < 0 || z >= m_dim_z) {
47 printf(
"%d, %d, %d\n", x, y, z);
48 printf(
"%d, %d, %d\n", m_dim_x, m_dim_y, m_dim_z);
49 throw std::out_of_range(
"Matrix3D: Indices out of range.");
51 return m_data[x * m_dim_y * m_dim_z + y * m_dim_z + z];
54 const T &operator()(
int x,
int y,
int z)
const {
55 if (x < 0 || x >= m_dim_x || y < 0 || y >= m_dim_y || z < 0 || z >= m_dim_z) {
56 printf(
"%d, %d, %d\n", x, y, z);
57 printf(
"%d, %d, %d\n", m_dim_x, m_dim_y, m_dim_z);
58 throw std::out_of_range(
"Matrix3D: Indices out of range.");
60 return m_data[x * m_dim_y * m_dim_z + y * m_dim_z + z];
65 if (m_dim_x != other.m_dim_x || m_dim_y != other.m_dim_y || m_dim_z != other.m_dim_z) {
69 for (
int x = 0; x < m_dim_x; ++x) {
70 for (
int y = 0; y < m_dim_y; ++y) {
71 for (
int z = 0; z < m_dim_z; ++z) {
72 if ((*
this)(x, y, z) != other(x, y, z)) {
82#if defined(__CUDACC__)
83 __host__ __device__
int length()
const {
return m_dim_x * m_dim_y * m_dim_z; }
85 int length()
const {
return m_dim_x * m_dim_y * m_dim_z; }
90 for (
int i = 0; i < this->length(); i++) {
91 sum += this->m_data[i];
95 T sum(
int size)
const {
97 for (
int i = 0; i < size; i++) {
98 sum += this->m_data[i];
103 T sum(
int size,
int start_idx)
const {
105 for (
int i = 0; i < size; i++) {
106 sum += this->m_data[start_idx + i];
111 void load(
const char *path) {
112 std::ifstream infile(path, std::ios::binary | std::ios::in);
114 std::cout << strerror(errno) <<
": " << path << std::endl;
115 throw(
"Expected error...");
117 infile.read(
reinterpret_cast<char *
>(this->m_data), this->length() *
sizeof(T));
122 int m_dim_x, m_dim_y, m_dim_z;
131 Matrix4D(T *data,
int dim_w,
int dim_x,
int dim_y,
int dim_z) :
132 m_data(data), m_dim_w(dim_w), m_dim_x(dim_x), m_dim_y(dim_y), m_dim_z(dim_z) {}
134#if defined(__CUDACC__)
135 __host__ __device__ T &operator()(
int w,
int x,
int y,
int z) {
136 return m_data[w * m_dim_x * m_dim_y * m_dim_z + x * m_dim_y * m_dim_z + y * m_dim_z + z];
139 __host__ __device__
const T &operator()(
int w,
int x,
int y,
int z)
const {
140 return m_data[w * m_dim_x * m_dim_y * m_dim_z + x * m_dim_y * m_dim_z + y * m_dim_z + z];
143 T &operator()(
int w,
int x,
int y,
int z) {
144 if (w < 0 || w >= m_dim_w || x < 0 || x >= m_dim_x || y < 0 || y >= m_dim_y || z < 0 || z >= m_dim_z) {
145 printf(
"%d, %d, %d, %d\n", w, x, y, z);
146 printf(
"%d, %d, %d, %d\n", m_dim_w, m_dim_x, m_dim_y, m_dim_z);
147 throw std::out_of_range(
"Matrix4D: Indices out of range.");
149 return m_data[w * m_dim_x * m_dim_y * m_dim_z + x * m_dim_y * m_dim_z + y * m_dim_z + z];
152 const T &operator()(
int w,
int x,
int y,
int z)
const {
153 if (w < 0 || w >= m_dim_w || x < 0 || x >= m_dim_x || y < 0 || y >= m_dim_y || z < 0 || z >= m_dim_z) {
154 printf(
"%d, %d, %d, %d\n", w, x, y, z);
155 printf(
"%d, %d, %d, %d\n", m_dim_w, m_dim_x, m_dim_y, m_dim_z);
156 throw std::out_of_range(
"Matrix4D: Indices out of range.");
158 return m_data[w * m_dim_x * m_dim_y * m_dim_z + x * m_dim_y * m_dim_z + y * m_dim_z + z];
163 if (m_dim_w != other.m_dim_w || m_dim_x != other.m_dim_x || m_dim_y != other.m_dim_y || m_dim_z != other.m_dim_z) {
167 for (
int w = 0; w < m_dim_w; ++w) {
168 for (
int x = 0; x < m_dim_x; ++x) {
169 for (
int y = 0; y < m_dim_y; ++y) {
170 for (
int z = 0; z < m_dim_z; ++z) {
171 if ((*
this)(w, x, y, z) != other(w, x, y, z)) {
182#if defined(__CUDACC__)
183 __host__ __device__
int length()
const {
return m_dim_w * m_dim_x * m_dim_y * m_dim_z; }
185 int length()
const {
return m_dim_w * m_dim_x * m_dim_y * m_dim_z; }
190 for (
int i = 0; i < this->length(); i++) {
191 sum += this->m_data[i];
195 T sum(
int size)
const {
197 for (
int i = 0; i < size; i++) {
198 sum += this->m_data[i];
203 T sum(
int size,
int start_idx)
const {
205 for (
int i = 0; i < size; i++) {
206 sum += this->m_data[start_idx + i];
211 void load(
const char *path) {
212 std::ifstream infile(path, std::ios::binary | std::ios::in);
214 std::cout << strerror(errno) <<
": " << path << std::endl;
215 throw(
"Expected error...");
217 infile.read(
reinterpret_cast<char *
>(this->m_data), this->length() *
sizeof(T));
222 int m_dim_w, m_dim_x, m_dim_y, m_dim_z;