Skip to content

Commit 798ec35

Browse files
committed
fix getFastUnitaryMatrix
1 parent e9ee921 commit 798ec35

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

mlir/include/mlir/Dialect/QCO/IR/QCOInterfaces.td

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,27 @@ def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> {
121121
}
122122
}]
123123
>,
124+
InterfaceMethod<
125+
"Returns the unitary matrix definition of the operation.",
126+
"std::variant<Eigen::Matrix<std::complex<double>, 1, 1>, Eigen::Matrix2cd, Eigen::Matrix4cd, Eigen::MatrixXcd>",
127+
"getFastUnitaryMatrixVariant", (ins),
128+
[{
129+
if constexpr (requires { $_op.getUnitaryMatrixDefinition(); }) {
130+
return $_op.getUnitaryMatrixDefinition();
131+
} else {
132+
llvm::reportFatalUsageError("Operation '" + $_op.getBaseSymbol() + "' has no unitary matrix definition!");
133+
}
134+
}]
135+
>,
124136
];
125137

126-
let extraTraitClassDeclaration = [{
138+
let extraClassDeclaration = [{
127139
template<typename MatrixType>
128140
MatrixType getFastUnitaryMatrix() const {
129-
return $_op.getUnitaryMatrixDefinition();
141+
// removing const since it's safe to say UnitaryOpInterface::getFastUnitaryMatrixVariant()
142+
// and OpType::getUnitaryMatrixDefinition() will not modify the state of this
143+
auto&& matrix = const_cast<UnitaryOpInterface*>(this)->getFastUnitaryMatrixVariant();
144+
return std::get<MatrixType>(matrix);
130145
}
131146
}];
132147
}

0 commit comments

Comments
 (0)