jainris commented on a change in pull request #6303: URL: https://github.com/apache/incubator-tvm/pull/6303#discussion_r475451513
########## File path: src/relay/op/tensor/transform.cc ########## @@ -3093,5 +3093,55 @@ RELAY_REGISTER_OP("sparse_to_dense") .set_attr<FInferCorrectLayout>("FInferCorrectLayout", ElemwiseArbitraryLayout) .set_attr<FTVMCompute>("FTVMCompute", SparseToDenseCompute); +// relay.matrix_set_diag +bool MatrixSetDiagRel(const Array<Type>& types, int num_inputs, const Attrs& attrs, + const TypeReporter& reporter) { + // `types` contains: [input, diagonal, result] + CHECK_EQ(types.size(), 3); + + const auto* input = types[0].as<TensorTypeNode>(); + CHECK(input); + + const auto* diagonal = types[1].as<TensorTypeNode>(); + CHECK(diagonal); + + int d_ndims = diagonal->shape.size(); + for (int i = 0; i < d_ndims - 1; i++) { + reporter->AssertEQ(input->shape[i], diagonal->shape[i]); + } + auto min_dim = if_then_else(input->shape[d_ndims - 1] >= input->shape[d_ndims], + input->shape[d_ndims], input->shape[d_ndims - 1]); Review comment: Thanks for reviewing. `if_then_else` is needed here because `input->shape[i]` is a `PrimExpr`, and so `a ? x : y` can't be used. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org