| 1641 | } |
| 1642 | |
| 1643 | void DotInferMeta(const MetaTensor& x, const MetaTensor& y, MetaTensor* out) { |
| 1644 | auto x_dims = x.dims(); |
| 1645 | int x_rank = static_cast<int>(x_dims.size()); |
| 1646 | PADDLE_ENFORCE_EQ(true, |
| 1647 | 1 == x_rank || 2 == x_rank, |
| 1648 | common::errors::PreconditionNotMet( |
| 1649 | "ShapeError: The dimensions of input tensor X (%s) " |
| 1650 | "should be 1 or 2", |
| 1651 | x_dims.to_str())); |
| 1652 | |
| 1653 | auto y_dims = y.dims(); |
| 1654 | PADDLE_ENFORCE_EQ( |
| 1655 | true, |
| 1656 | x_rank == static_cast<int>(y_dims.size()), |
| 1657 | common::errors::PreconditionNotMet( |
| 1658 | "ShapeError: The shape of input tensor Y: %s should match with " |
| 1659 | "input tensor X: %s", |
| 1660 | y_dims.to_str(), |
| 1661 | x_dims.to_str())); |
| 1662 | bool shape_match = true; |
| 1663 | for (int i = 0; i < x_rank; ++i) { |
| 1664 | if (x_dims[i] == 0 || y_dims[i] == 0) { |
| 1665 | continue; |
| 1666 | } |
| 1667 | if (x_dims[i] != y_dims[i]) { |
| 1668 | shape_match = false; |
| 1669 | break; |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | PADDLE_ENFORCE_EQ(true, |
| 1674 | shape_match, |
| 1675 | common::errors::PreconditionNotMet( |
| 1676 | "ShapeError: The shape of input tensor X: %s should " |
| 1677 | "be exactly the same " |
| 1678 | "with input tensor Y: %s", |
| 1679 | x_dims.to_str(), |
| 1680 | y_dims.to_str())); |
| 1681 | |
| 1682 | auto out_dims = x_dims; |
| 1683 | // The output dims need to be modified. |
| 1684 | if (x_rank == 2 && x_dims[0] != 0 && y_dims[0] == 0) { |
| 1685 | out_dims[0] = 0; |
| 1686 | } |
| 1687 | std::vector<int64_t> out_dims_vec = vectorize(out_dims); |
| 1688 | std::vector<int64_t> out_dims_vec_cut(out_dims_vec.begin(), |
| 1689 | out_dims_vec.end() - 1); |
| 1690 | out->set_dims(make_ddim(out_dims_vec_cut)); |
| 1691 | out->set_dtype(x.dtype()); |
| 1692 | out->set_layout(x.layout()); |
| 1693 | } |
| 1694 | |
| 1695 | void ElementwiseInferMeta(const MetaTensor& x, |
| 1696 | const MetaTensor& y, |