1313// limitations under the License.
1414
1515#include " paddle/cinn/frontend/paddle/cpp/block_desc.h"
16+ #include " paddle/common/enforce.h"
1617
1718namespace cinn ::frontend::paddle::cpp {
1819
1920template <>
2021VarDesc* BlockDesc::GetVar<VarDesc>(int32_t idx) {
21- CHECK_LT (idx, VarsSize ()) << " idx >= vars.size()" ;
22+ PADDLE_ENFORCE_LT (
23+ idx,
24+ VarsSize (),
25+ phi::errors::InvalidArgument (
26+ " The value of idx and vars.size() is incorrect."
27+ " Expected idx < vars.size(), but receive idx >= vars.size()." ));
2228 return &vars_[idx];
2329}
2430
2531template <>
2632const VarDesc& BlockDesc::GetConstVar<VarDesc>(int32_t idx) const {
27- CHECK_LT (idx, static_cast <int32_t >(VarsSize ())) << " idx >= vars.size()" ;
33+ PADDLE_ENFORCE_LT (
34+ idx,
35+ static_cast <int32_t >(VarsSize ()),
36+ phi::errors::InvalidArgument (
37+ " The value of idx and vars.size() is incorrect."
38+ " Expected idx < vars.size(), but receive idx >= vars.size()." ));
2839 return vars_[idx];
2940}
3041
@@ -36,13 +47,23 @@ VarDesc* BlockDesc::AddVar<VarDesc>() {
3647
3748template <>
3849OpDesc* BlockDesc::GetOp<OpDesc>(int32_t idx) {
39- CHECK_LT (idx, OpsSize ()) << " idx >= ops.size()" ;
50+ PADDLE_ENFORCE_LT (
51+ idx,
52+ OpsSize (),
53+ phi::errors::InvalidArgument (
54+ " The value of idx and ops.size() is incorrect."
55+ " Expected idx < ops.size(), but receive idx >= ops.size()." ));
4056 return &ops_[idx];
4157}
4258
4359template <>
4460const OpDesc& BlockDesc::GetConstOp<OpDesc>(int32_t idx) const {
45- CHECK_LT (idx, static_cast <int32_t >(OpsSize ())) << " idx >= ops.size()" ;
61+ PADDLE_ENFORCE_LT (
62+ idx,
63+ static_cast <int32_t >(OpsSize ()),
64+ phi::errors::InvalidArgument (
65+ " The value of idx and ops.size() is incorrect."
66+ " Expected idx < ops.size(), but receive idx >= ops.size()." ));
4667 return ops_[idx];
4768}
4869
0 commit comments