26template <
typename T,
typename U = T,
typename Op>
27void unary_op(
const T* a, U* out, Op op,
size_t shape,
size_t stride) {
28 for (
size_t i = 0; i < shape; i += 1) {
34template <
typename T,
typename U = T,
typename Op>
36 const T* a_ptr = a.
data<T>();
39 U* dst = out.
data<U>();
56 U* dst = out.
data<U>();
57 size_t shape = a.
ndim() > 0 ? a.
shape(-1) : 1;
60 unary_op(a_ptr, dst, op, shape, stride);
64 for (
size_t elem = 0; elem < a.
size(); elem += shape) {
65 unary_op(a_ptr + it.
loc, dst + elem, op, shape, stride);
73 switch (out.
dtype()) {
119template <
typename Op>
121 switch (out.
dtype()) {
138 std::ostringstream err;
139 err <<
"[unary_fp] Does not support " << out.
dtype();
140 throw std::runtime_error(err.str());
144template <
typename Op>
146 switch (out.
dtype()) {
172 std::ostringstream err;
173 err <<
"[unary_int] Does not support " << out.
dtype();
174 throw std::runtime_error(err.str());
const Flags & flags() const
Get the Flags bit-field.
Definition array.h:318
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:354
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:332
Buffer malloc_or_wait(size_t size)
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_int(const array &a, array &out, Op op)
Definition unary.h:145
constexpr Dtype bool_
Definition dtype.h:68
constexpr Dtype uint64
Definition dtype.h:73
void unary_op(const T *a, U *out, Op op, size_t shape, size_t stride)
Definition unary.h:27
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:13
constexpr Dtype bfloat16
Definition dtype.h:83
constexpr Dtype int32
Definition dtype.h:77
constexpr Dtype float32
Definition dtype.h:81
void unary(const array &a, array &out, Op op)
Definition unary.h:72
constexpr Dtype int16
Definition dtype.h:76
void unary_fp(const array &a, array &out, Op op)
Definition unary.h:120
constexpr Dtype int8
Definition dtype.h:75
constexpr Dtype int64
Definition dtype.h:78
constexpr Dtype uint8
Definition dtype.h:70
constexpr Dtype float16
Definition dtype.h:80
constexpr Dtype uint32
Definition dtype.h:72
bool is_donatable(const array &in, const array &out)
Definition utils.h:155
constexpr Dtype complex64
Definition dtype.h:84
int64_t loc
Definition utils.h:126
void step()
Definition utils.h:74
bool contiguous
Definition array.h:231