Skip to content

[mlir] Fix parsing of empty complex tensors #134322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
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
6 changes: 4 additions & 2 deletions mlir/lib/AsmParser/AttributeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,10 @@ DenseElementsAttr TensorLiteralParser::getAttr(SMLoc loc, ShapedType type) {
if (ComplexType complexTy = dyn_cast<ComplexType>(eltType)) {
eltType = complexTy.getElementType();
isComplex = true;
// Complex types have 2 elements.
if (shape.empty() && storage.size() != 2) {
// Complex types have N*2 elements or complex splat.
// Empty shape may mean a splat or empty literal, only validate splats.
bool isSplat = shape.empty() && type.getNumElements() != 0;
if (isSplat && storage.size() != 2) {
p.emitError(loc) << "parsed " << storage.size() << " elements, but type ("
<< complexTy << ") expected 2 elements";
return nullptr;
Expand Down
4 changes: 4 additions & 0 deletions mlir/test/IR/parser.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ func.func @densetensorattr() -> () {
"complex_attr"(){bar = dense<(1.000000e+00,0.000000e+00)> : tensor<complex<f32>>} : () -> ()
// CHECK: dense<[(1.000000e+00,0.000000e+00), (2.000000e+00,2.000000e+00)]> : tensor<2xcomplex<f32>>
"complex_attr"(){bar = dense<[(1.000000e+00,0.000000e+00), (2.000000e+00,2.000000e+00)]> : tensor<2xcomplex<f32>>} : () -> ()
// CHECK: dense<> : tensor<0xcomplex<i64>>
"complex_attr"(){bar = dense<> : tensor<0xcomplex<i64>>} : () -> ()
// CHECK: dense<> : tensor<2x0xcomplex<i64>>
"complex_attr"(){bar = dense<> : tensor<2x0xcomplex<i64>>} : () -> ()
return
}

Expand Down