broadcast.h
¶
Functions
-
static inline bool is_broadcastable(const std::vector<std::size_t> &src_shape, const std::vector<std::size_t> &dst_shape)¶
Test if
src_shape
can be broadcast todst_shape
-
static inline std::vector<std::size_t> smallest_broadcastable_shape(const std::vector<std::size_t> &shape1, const std::vector<std::size_t> &shape2)¶
Get the smallest broadcastable shape from
shape1
andshape2
. Return an empty vector_.size() == 0
if the shapes can not be broadcast together.
-
template<typename FUNC>
static inline std::size_t src_to_dst_idx(std::size_t i, FUNC &&broadcast_rule, const std::vector<std::size_t> &strides)¶ Compute the destination index of source index
i
based on abroadcasting_rule
. The destination index is weighted usingstrides
. This function assumes thatstrides.size() == broadcast_rule.size()
-
template<typename RANDOM_ACCESS_CONST_ITERATOR, typename RANDOM_ACCESS_ITERATOR>
static inline void broadcast_data_copy(RANDOM_ACCESS_CONST_ITERATOR src, RANDOM_ACCESS_ITERATOR dst, const std::vector<std::size_t> &src_shape, const std::vector<std::size_t> &dst_shape, std::size_t itemsize = 1)¶ Perform a broadcast by copying data. This function assumes that
src_shape
can be broadcast todst_shape
, i.e.,is_broadcastable(src_shape, dst_shape) == true
. It further assumes that the data insrc
is stored in C-style order and thatdst
has enough space to store the broadcast result.