26 #ifndef MLN_METAL_ARRAY1D_HH
27 # define MLN_METAL_ARRAY1D_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 Size>
struct array1d;
47 template <
typename T,
unsigned Size>
48 struct value_< mln::metal::array1d<T,Size> >
50 typedef trait::value::nature::vectorial
nature;
51 typedef trait::value::kind::data
kind;
54 nbits = Size * mln_nbits(
T),
55 card = Size * mln_card(
T)
57 typedef mln_value_quant_from_(card) quant;
59 typedef metal::array1d<mln_sum(
T),Size>
sum;
68 template <
typename T,
unsigned Size>
69 struct array1d :
public Object< array1d<T,Size> >
81 array1d(
const array1d<T, Size>&
rhs);
82 array1d<T, Size>& operator=(
const array1d<T, Size>&
rhs);
90 array1d<mln_trait_op_div(T,U), Size>
94 array1d<mln_trait_op_plus(T,U), Size>
99 array1d<mln_trait_op_minus(T,U), Size>
107 T operator[](
unsigned i)
const {
108 mln_precondition(i < Size);
111 T& operator[](
unsigned i) {
112 mln_precondition(i < Size);
127 enum { length = Size };
140 template <
template <
class>
class Name,
141 unsigned n,
typename T >
142 struct set_precise_unary_< Name, metal::array1d<T, n> >
144 typedef mln_trait_unary(Name,
T) V;
145 typedef metal::array1d<V, n>
ret;
150 template < template <class, class> class Name,
151 unsigned n, typename
T,
153 struct set_precise_binary_< Name,
154 metal::array1d<T, n>, metal::array1d<U, n> >
156 typedef mln_trait_binary(Name, T, U) V;
157 typedef metal::array1d<V, n> ret;
160 template <
unsigned n, typename T,
162 struct set_precise_binary_< op::times,
163 metal::array1d<T, n>, metal::array1d<U, n> >
165 typedef mln_sum_product(T,U) ret;
168 template < template <class, class> class Name,
169 unsigned n, typename T,
171 struct set_precise_binary_< Name,
172 metal::array1d<T, n>, mln::
value::scalar_<S> >
174 typedef mln_trait_binary(Name, T, S) V;
175 typedef metal::array1d<V, n> ret;
178 template < template<class, class> class Name,
179 unsigned n, typename T,
181 struct set_binary_< Name,
182 mln::Object, metal::array1d<T, n>,
183 mln::
value::Scalar, S >
185 typedef mln_trait_binary(Name, T, S) V;
186 typedef metal::array1d<T, n> ret;
199 template <
typename T,
unsigned Size>
200 array1d<T,Size>::array1d()
204 template <
typename T,
unsigned Size>
205 array1d<T,Size>::array1d(T* ptr)
207 for (
unsigned i = 0; i < Size; ++i)
213 template <
typename T,
unsigned Size>
214 array1d<T,Size>::array1d(
const array1d<T, Size>&
rhs)
216 for (
unsigned i = 0; i < Size; ++i)
219 template <
typename T,
unsigned Size>
221 array1d<T,Size>::operator=(
const array1d<T, Size>& rhs)
223 for (
unsigned i = 0; i < Size; ++i)
230 template <
typename T,
unsigned Size>
236 array1d<T, Size> tmp;
237 for (
unsigned i = 0; i < Size; ++i)
238 tmp[i] = this->buffer_[i] * w;
242 template <
typename T,
unsigned Size>
244 array1d<mln_trait_op_div(T,U), Size>
247 array1d<T, Size> tmp;
248 for (
unsigned i = 0; i < Size; ++i)
249 tmp[i] = this->buffer_[i] / w;
253 template <
typename T,
unsigned Size>
254 template <
typename U>
255 array1d<mln_trait_op_plus(T,U), Size>
258 array1d<T, Size> tmp;
259 for (
unsigned i = 0; i < Size; ++i)
260 tmp[i] = this->buffer_[i] + rhs.buffer_[i];
263 template <
typename T,
unsigned Size>
267 for (
unsigned i = 0; i < Size; ++i)
268 this->buffer_[i] += rhs.buffer_[i];
272 template <
typename T,
unsigned Size>
273 template <
typename U>
274 array1d<mln_trait_op_minus(T,U), Size>
277 array1d<T, Size> tmp;
278 for (
unsigned i = 0; i < Size; ++i)
279 tmp[i] = this->buffer_[i] - rhs.buffer_[i];
282 template <
typename T,
unsigned Size>
286 for (
unsigned i = 0; i < Size; ++i)
287 this->buffer_[i] -= rhs.buffer_[i];
295 #endif // ! MLN_METAL_ARRAY1D_HH