26 #ifndef MLN_METAL_ARRAY3D_HH
27 # define MLN_METAL_ARRAY3D_HH
29 # include <mln/core/concept/object.hh>
31 # include <mln/trait/all.hh>
32 # include <mln/trait/value_.hh>
34 # include <mln/value/ops.hh>
41 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
struct array3d;
47 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
48 struct value_< mln::metal::array3d<T,s, r, c> >
50 typedef trait::value::nature::vectorial
nature;
51 typedef trait::value::kind::data
kind;
54 nbits = s * r * c * mln_nbits(
T),
55 card = s * r * c * mln_card(
T)
57 typedef mln_value_quant_from_(card) quant;
59 typedef metal::array3d<mln_sum(
T), s, r, c>
sum;
68 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
69 struct array3d :
public Object< array3d<T, s, r, c> >
81 array3d(
const array3d<T, s, r, c>&
rhs);
82 array3d<T, s, r, c>& operator=(
const array3d<T, s, r, c>&
rhs);
90 array3d<mln_trait_op_div(T,U), s, r, c>
94 array3d<mln_trait_op_plus(T,U), s, r, c>
96 array3d<T, s, r, c>&
operator+=(
const array3d<T, s, r, c>&
rhs);
99 array3d<mln_trait_op_minus(T,U), s, r, c>
107 T operator[](
unsigned i)
const {
108 mln_precondition(i < s * r * c);
111 T& operator[](
unsigned i) {
112 mln_precondition(i < s * r * c);
118 template <
unsigned sli,
unsigned row,
unsigned col>
120 return buffer_[sli * (row * col) + col * r + row];
122 template <
unsigned sli,
unsigned row,
unsigned col>
124 return buffer_[sli * (row * col) + col * r + row];
128 template <
unsigned sli,
unsigned row,
unsigned col>
130 mln_precondition(sli * (row * col) + col * r + row < s * r * c );
131 return buffer_[sli * (row * col) + col * r + row];
133 template <
unsigned sli,
unsigned row,
unsigned col>
135 mln_precondition(sli * (row * col) + col * r + row < s * r * c );
136 return buffer_[sli * (row * col) + col * r + row];
139 enum { length = s * r * c };
142 T buffer_[s * r * c];
152 template <
template <
class>
class Name,
153 unsigned s,
unsigned r,
unsigned c,
typename T >
154 struct set_precise_unary_< Name, metal::array3d<T, s, r, c> >
156 typedef mln_trait_unary(Name, T) V;
157 typedef metal::array3d<V, s, r, c>
ret;
162 template < template <class, class> class Name,
163 unsigned s,
unsigned r,
unsigned c, typename T,
165 struct set_precise_binary_< Name,
166 metal::array3d<T, s, r, c>, metal::array3d<U, s, r, c> >
168 typedef mln_trait_binary(Name, T, U) V;
169 typedef metal::array3d<V, s, r, c> ret;
172 template <
unsigned s,
unsigned r,
unsigned c, typename T,
174 struct set_precise_binary_< op::times,
175 metal::array3d<T, s, r, c>, metal::array3d<U, s, r, c> >
177 typedef mln_sum_product(T,U) ret;
180 template < template <class, class> class Name,
181 unsigned s,
unsigned r,
unsigned c, typename T,
183 struct set_precise_binary_< Name,
184 metal::array3d<T, s, r, c>, mln::
value::scalar_<S> >
186 typedef mln_trait_binary(Name, T, S) V;
187 typedef metal::array3d<V, s, r, c> ret;
190 template < template<class, class> class Name,
191 unsigned s,
unsigned r,
unsigned c, typename T,
193 struct set_binary_< Name,
194 mln::Object, metal::array3d<T, s, r, c>,
195 mln::
value::Scalar, S >
197 typedef mln_trait_binary(Name, T, S) V;
198 typedef metal::array3d<T, s, r, c> ret;
211 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
212 array3d<T,s, r, c>::array3d()
216 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
217 array3d<T,s, r, c>::array3d(T* ptr)
219 for (
unsigned i = 0; i < s * r * c; ++i)
225 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
226 array3d<T,s, r, c>::array3d(
const array3d<T, s, r, c>&
rhs)
228 for (
unsigned i = 0; i < s * r * c; ++i)
231 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
233 array3d<T,s, r, c>::operator=(
const array3d<T, s, r, c>& rhs)
235 for (
unsigned i = 0; i < s * r * c; ++i)
242 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
248 array3d<T, s, r, c> tmp;
249 for (
unsigned i = 0; i < s * r * c; ++i)
250 tmp[i] = this->buffer_[i] * w;
254 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
256 array3d<mln_trait_op_div(T,U), s, r, c>
259 array3d<T, s, r, c> tmp;
260 for (
unsigned i = 0; i < s * r * c; ++i)
261 tmp[i] = this->buffer_[i] / w;
265 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
266 template <
typename U>
267 array3d<mln_trait_op_plus(T,U), s, r, c>
270 array3d<T, s, r, c> tmp;
271 for (
unsigned i = 0; i < s * r * c; ++i)
272 tmp[i] = this->buffer_[i] + rhs.buffer_[i];
275 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
279 for (
unsigned i = 0; i < s * r * c; ++i)
280 this->buffer_[i] += rhs.buffer_[i];
284 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
285 template <
typename U>
286 array3d<mln_trait_op_minus(T,U), s, r, c>
289 array3d<T, s, r, c> tmp;
290 for (
unsigned i = 0; i < s * r * c; ++i)
291 tmp[i] = this->buffer_[i] - rhs.buffer_[i];
294 template <
typename T,
unsigned s,
unsigned r,
unsigned c>
298 for (
unsigned i = 0; i < s * r * c; ++i)
299 this->buffer_[i] -= rhs.buffer_[i];
307 #endif // ! MLN_METAL_ARRAY3D_HH