Skip to content

Commit

Permalink
Adding a check for the vector size and formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Pisal <spisal@nvidia.com>
  • Loading branch information
sacpis committed Jan 3, 2025
1 parent dcb0aba commit e0b02e2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/utils/OpaqueArguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ inline py::args simplifiedValidateInputArguments(py::args &args) {
if (shape.size() != 1)
throw std::runtime_error("Cannot pass ndarray with shape != (N,).");

// Vector size validation
size_t size = shape[0].cast<size_t>();
if (size == 0 || (size & (size - 1)) != 0) {
throw std::invalid_argument(fmt::format(
"Invalid vector size: {}. Vector size must be a power of 2.",
size));
}

arg = args[i].attr("tolist")();
} else if (py::isinstance<py::str>(arg)) {
arg = py::cast<std::string>(arg);
Expand Down

0 comments on commit e0b02e2

Please sign in to comment.