| 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_; |
nothing calls this directly
no test coverage detected