1#ifndef INFINI_OPS_BASE_MUL_H_
2#define INFINI_OPS_BASE_MUL_H_
23 input.IsContiguous()},
25 other.IsContiguous()},
27 assert(!out.HasBroadcastDim() &&
28 "the output of `Mul` should NOT have broadcasted dim!");
30 "operator `Mul` requires all input and output tensors to have the "
41 assert(input.ndim() <= out.ndim() &&
42 "operator `Mul` input rank must not exceed output rank");
43 Tensor::Strides strides(out.ndim(), 0);
44 auto offset = out.ndim() - input.ndim();
46 for (Tensor::Size i = 0; i < input.ndim(); ++i) {
47 auto out_dim = i + offset;
48 assert((input.size(i) == 1 || input.size(i) == out.size(out_dim)) &&
49 "operator `Mul` input shape is not broadcast-compatible with "
51 strides[out_dim] = input.size(i) == 1 ? 0 : input.stride(i);
59 for (Tensor::Size i = 0; i < out.ndim(); ++i) {
60 auto input_dim = i < out.ndim() - input.ndim()
62 : input.size(i + input.ndim() - out.ndim());
63 auto other_dim = i < out.ndim() - other.ndim()
65 : other.size(i + other.ndim() - out.ndim());
66 [[maybe_unused]]
auto broadcast_dim =
67 input_dim == 1 ? other_dim : input_dim;
68 assert(out.size(i) == broadcast_dim &&
69 "operator `Mul` output shape must equal the broadcasted input "
Tensor::Size ndim_
Definition mul.h:74
Tensor::Strides out_strides_
Definition mul.h:94
Tensor::Strides input_strides_
Definition mul.h:90
bool is_input_contiguous_
Definition mul.h:96
Tensor::Shape input_shape_
Definition mul.h:84
Tensor::Shape other_shape_
Definition mul.h:86
Tensor::Strides other_strides_
Definition mul.h:92
bool is_out_contiguous_
Definition mul.h:100
virtual void operator()(const Tensor input, const Tensor other, Tensor out) const =0
Tensor::Size output_size_
Definition mul.h:76
bool is_other_contiguous_
Definition mul.h:98
const DataType other_type_
Definition mul.h:80
static void ValidateBroadcast(const Tensor input, const Tensor other, const Tensor out)
Definition mul.h:57
const DataType out_type_
Definition mul.h:82
static Tensor::Strides BroadcastStrides(const Tensor input, const Tensor out)
Definition mul.h:39
const DataType input_type_
Definition mul.h:78
Mul(const Tensor input, const Tensor other, Tensor out)
Definition mul.h:10
Tensor::Shape out_shape_
Definition mul.h:88
Definition generated/include/operator.h:282
Definition generated/include/operator.h:28
infini::rt::TensorView Tensor
Definition tensor.h:8