Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions paddle/phi/kernels/cpu/arange_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ void ArangeKernel(const Context& dev_ctx,
T start_value = start.to<T>();
T end_value = end.to<T>();
T step_value = step.to<T>();
if constexpr (std::is_floating_point_v<T>) {
if (std::isnan(end_value)) {
PADDLE_THROW(phi::errors::InvalidArgument(
"The end value of arange cannot be NaN. Please check your input."));
}
}
ArangeFunc<T, Context>(dev_ctx, start_value, end_value, step_value, out);
}

Expand Down
22 changes: 22 additions & 0 deletions paddle/phi/kernels/gpu/arange_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ void ArangeNullaryKernel(const Context& dev_ctx,
MPType start_value_mpt = static_cast<MPType>(start_value);
MPType end_value_mpt = static_cast<MPType>(end_value);
MPType step_value_mpt = static_cast<MPType>(step_value);
if constexpr (std::is_same_v<T, float>) {
if (std::isnan(static_cast<float>(end_value))) {
PADDLE_THROW(phi::errors::InvalidArgument(
"The end value of arange cannot be NaN. Please check your input."));
}
} else if constexpr (std::is_same_v<T, double>) {
if (std::isnan(static_cast<double>(end_value))) {
PADDLE_THROW(phi::errors::InvalidArgument(
"The end value of arange cannot be NaN. Please check your input."));
}
}
int64_t size = 0;
phi::funcs::GetSize(start_value_mpt, end_value_mpt, step_value_mpt, &size);
out->Resize(common::make_ddim({size}));
Expand All @@ -94,6 +105,17 @@ void ArangeKernel(const Context& dev_ctx,
T start_value = start.to<T>();
T end_value = end.to<T>();
T step_value = step.to<T>();
if constexpr (std::is_same_v<T, float>) {
if (std::isnan(end_value)) {
PADDLE_THROW(phi::errors::InvalidArgument(
"The end value of arange cannot be NaN. Please check your input."));
}
} else if constexpr (std::is_same_v<T, double>) {
if (std::isnan(end_value)) {
PADDLE_THROW(phi::errors::InvalidArgument(
"The end value of arange cannot be NaN. Please check your input."));
}
}
ArangeNullaryKernel<T, Context>(
dev_ctx, start_value, end_value, step_value, out);
}
Expand Down
4 changes: 4 additions & 0 deletions paddle/phi/kernels/xpu/arange_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ void ArangeTensorKernel(const Context& dev_ctx,
static_cast<MPType>(GetValue<T, Context>(dev_ctx, start));
MPType end_value = static_cast<MPType>(GetValue<T, Context>(dev_ctx, end));
MPType step_value = static_cast<MPType>(GetValue<T, Context>(dev_ctx, step));
if (std::isnan(static_cast<float>(end_value))) {
PADDLE_THROW(phi::errors::InvalidArgument(
"The end value of arange cannot be NaN. Please check your input."));
}

int64_t size = 0;
phi::funcs::GetSize(start_value, end_value, step_value, &size);
Expand Down