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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions onnxruntime/contrib_ops/cpu/inverse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Status Inverse::Compute(OpKernelContext* ctx) const {
const auto num_dim = input_shape.NumDimensions();
auto* output = ctx->Output(0, input_shape);

ORT_RETURN_IF_NOT(num_dim >= 2, "Input tensor rank must be >= 2, got: ", num_dim);

int64_t num_batches = 1;
const int64_t rows = input_shape.GetDims()[num_dim - 2];
const int64_t cols = input_shape.GetDims()[num_dim - 1];
Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/contrib_ops/cuda/inverse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Status Inverse::ComputeInternal(OpKernelContext* ctx) const {
const auto num_dim = input_shape.NumDimensions();
auto* output = ctx->Output(0, input_shape);

ORT_RETURN_IF_NOT(num_dim >= 2, "Input tensor rank must be >= 2, got: ", num_dim);

size_t num_batches = 1;
const size_t rows = static_cast<size_t>(input_shape.GetDims()[num_dim - 2]);
const size_t cols = static_cast<size_t>(input_shape.GetDims()[num_dim - 1]);
Expand Down
15 changes: 15 additions & 0 deletions onnxruntime/test/contrib_ops/inverse_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,20 @@ TEST(InverseContribOpTest, four_by_four_batches_float) {
test.AddOutput<float>("Output", {3, 4, 4, 4}, output);
test.Run();
}

TEST(InverseContribOpTest, scalar_input_fails) {
OpTester test("Inverse", 1, kMSDomain);
test.AddInput<float>("X", {}, {4.f});
test.AddOutput<float>("Y", {}, {0.25f});
test.Run(OpTester::ExpectResult::kExpectFailure, "rank must be >= 2");
}

TEST(InverseContribOpTest, one_dim_input_fails) {
OpTester test("Inverse", 1, kMSDomain);
test.AddInput<float>("X", {4}, {4.f, 7.f, 2.f, 6.f});
test.AddOutput<float>("Y", {4}, {0.f, 0.f, 0.f, 0.f});
test.Run(OpTester::ExpectResult::kExpectFailure, "rank must be >= 2");
}

} // namespace test
} // namespace onnxruntime
Loading