31template <
typename T,
typename U = T,
typename Op>
32void unary_op(
const T* a, U* out,
size_t shape,
size_t stride) {
33 for (
size_t i = 0; i < shape; i += 1) {
39template <
typename T,
typename U = T,
typename Op>
41 const T* src = a.
data<T>();
42 U* dst = out.
data<U>();
60 size_t shape = ndim > 0 ? a.
shape().back() : 1;
61 size_t stride = ndim > 0 ? a.
strides().back() : 1;
67 for (
size_t elem = 0; elem < a.
size(); elem += shape) {
78 encoder.set_input_array(a);
79 encoder.set_output_array(out);
83 switch (out.
dtype()) {
130template <
typename Op>
134 encoder.set_input_array(a);
135 encoder.set_output_array(out);
139 switch (out.
dtype()) {
153 std::ostringstream err;
154 err <<
"[unary_real] Does not support " << out.
dtype();
155 throw std::runtime_error(err.str());
159template <
typename Op>
163 encoder.set_input_array(a);
164 encoder.set_output_array(out);
168 switch (out.
dtype()) {
185 std::ostringstream err;
186 err <<
"[unary_fp] Does not support " << out.
dtype();
187 throw std::runtime_error(err.str());
192template <
typename Op>
196 encoder.set_input_array(a);
197 encoder.set_output_array(out);
201 switch (out.
dtype()) {
230 throw std::runtime_error(
"[Abs] Called on unsigned type");
235template <
typename Op>
239 encoder.set_input_array(a);
240 encoder.set_output_array(out);
246template <
typename Op>
250 encoder.set_input_array(a);
251 encoder.set_output_array(out);
258template <
typename Op>
262 encoder.set_input_array(a);
263 encoder.set_output_array(out);
267 switch (out.
dtype()) {
293 std::ostringstream err;
294 err <<
"[unary_int] Does not support " << out.
dtype();
295 throw std::runtime_error(err.str());
const Flags & flags() const
Get the Flags bit-field.
Definition array.h:313
const Shape & shape() const
The shape of the array as a vector of integers.
Definition array.h:103
const Strides & strides() const
The strides of the array.
Definition array.h:117
size_t nbytes() const
The number of bytes in the array.
Definition array.h:93
size_t ndim() const
The number of dimensions of the array.
Definition array.h:98
size_t size() const
The number of elements in the array.
Definition array.h:88
T * data()
Definition array.h:349
static array unsafe_weak_copy(const array &other)
Get a new array that refers to the same data as the input but with a non-owning pointer to it.
void copy_shared_buffer(const array &other, const Strides &strides, Flags flags, size_t data_size, size_t offset=0)
Dtype dtype() const
Get the arrays data type.
Definition array.h:131
size_t itemsize() const
The size of the array's datatype in bytes.
Definition array.h:83
void set_data(allocator::Buffer buffer, Deleter d=allocator::free)
size_t data_size() const
The size (in elements) of the underlying buffer the array points to.
Definition array.h:327
Buffer malloc_or_wait(size_t size)
CommandEncoder & get_command_encoder(Stream stream)
Simd< T, N > load(const T *x)
Definition base_simd.h:28
static constexpr int max_size
Definition base_simd.h:14
void store(T *dst, Simd< T, N > x)
Definition base_simd.h:33
void unary_complex_to_float(const array &a, array &out, Op op, Stream stream)
Definition unary.h:247
void unary(const array &a, array &out, Op op, Stream stream)
Definition unary.h:75
constexpr Dtype bool_
Definition dtype.h:68
constexpr Dtype uint64
Definition dtype.h:73
constexpr Dtype uint16
Definition dtype.h:71
constexpr Dtype float64
Definition dtype.h:82
void set_unary_output_data(const array &in, array &out)
Definition unary.h:14
void unary_int(const array &a, array &out, Op op, Stream stream)
Definition unary.h:259
constexpr Dtype bfloat16
Definition dtype.h:83
constexpr Dtype int32
Definition dtype.h:77
constexpr Dtype float32
Definition dtype.h:81
void unary_fp(const array &a, array &out, Op op, Stream stream)
Definition unary.h:160
constexpr Dtype int16
Definition dtype.h:76
constexpr Dtype int8
Definition dtype.h:75
constexpr Dtype int64
Definition dtype.h:78
void unary_real_fp(const array &a, array &out, Op op, Stream stream)
Definition unary.h:131
constexpr Dtype uint8
Definition dtype.h:70
void unary_complex(const array &a, array &out, Op op, Stream stream)
Definition unary.h:236
void unary_op(const T *a, U *out, size_t shape, size_t stride)
Definition unary.h:32
constexpr Dtype float16
Definition dtype.h:80
constexpr Dtype uint32
Definition dtype.h:72
void unary_signed(const array &a, array &out, Op op, Stream stream)
Definition unary.h:193
bool is_donatable(const array &in, const array &out)
Definition utils.h:155
constexpr Dtype complex64
Definition dtype.h:84
bool contiguous
Definition array.h:238