MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / operator()

Method operator()

oneflow/core/functional/impl/array_functor.cpp:1572–1586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1570 public:
1571 ViewFunctor() { op_ = CHECK_JUST(one::OpBuilder("reshape").Input("in").Output("out").Build()); }
1572 Maybe<Tensor> operator()(const std::shared_ptr<one::Tensor>& x, const Shape& shape) const {
1573 Shape infered_shape = *JUST(InferShapeUnspecifiedDim(x->shape()->Count(0), shape));
1574 if (view::IsViewApplicable(x)) {
1575 Optional<Stride> infered_stride =
1576 ComputeStride(*(x->shape()), *JUST(x->stride()), infered_shape);
1577 CHECK_OR_RETURN_ERROR(infered_stride.has_value())
1578 << Error::RuntimeError()
1579 << "view size is not compatible with input tensor's size and stride (at least one "
1580 "dimension spans across two contiguous subspaces). Use .reshape(...) instead.";
1581 return view::Reshape(x, infered_shape, *JUST(infered_stride));
1582 }
1583 auto& attrs = THREAD_CACHED_MUTABLE_ATTR_MAP("shape");
1584 attrs.SetAllAttrs(infered_shape);
1585 return OpInterpUtil::Dispatch<Tensor>(*op_, {x}, attrs);
1586 }
1587
1588 private:
1589 std::shared_ptr<OpExpr> op_;

Callers

nothing calls this directly

Calls 9

InferShapeUnspecifiedDimFunction · 0.85
IsViewApplicableFunction · 0.85
ComputeStrideFunction · 0.85
ReshapeFunction · 0.85
SetAllAttrsMethod · 0.80
CountMethod · 0.45
shapeMethod · 0.45
strideMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected