tensorflow/lite/toco/graph_transformations/convert_matrix_set_diag_v2_or_v3_to_v1.cc
// V3 is only different from V2 because it has an extra attribute (align).
// This attribute doesn't affect V1 so we don't have to keep track of it here.
V3 is only different from V2 because it has an extra attribute (align).
This attribute doesn't affect V1 so we don't have to keep track of it here.
V3 is only different from V2 because it has an extra attribute ( align ) . This attribute doesn ' t affect V1 so we don ' t have to keep track of it here .
::tensorflow::Status ConvertMatrixSetDiagV2OrV3ToV1::Run(Model* model,
                                                         std::size_t op_index,
                                                         bool* modified) {
  *modified = false;
  auto it = model->operators.begin() + op_index;
  const auto* op = it->get();
  if (op->type != OperatorType::kMatrixSetDiagV2 &&
      op->type != OperatorType::kMatrixSetDiagV3) {
    return ::tensorflow::Status::OK();
  }
  if (op->inputs.size() != 3) {
    return tensorflow::errors::InvalidArgument(
        "The input size of op %s should be 3", LogName(*op));
  }
  const auto& input_k = model->GetArray(op->inputs[2]);
  if (!input_k.buffer) {
    return ::tensorflow::Status::OK();
  }
  if (input_k.GetBuffer<ArrayDataType::kInt32>().data.size() != 1) {
    return tensorflow::errors::InvalidArgument(
        "Array for argument k of op %s should contains exact one element",
        LogName(*op));
  }
  int k = input_k.GetBuffer<ArrayDataType::kInt32>().data[0];
  if (k != 0) {
    return tensorflow::errors::InvalidArgument(
        "parameter k of op ", LogName(*op),
        " is expected to be 0, other values are not supported currently");
  }
  auto* matrix_set_diag_op = new MatrixSetDiagOperator;
  matrix_set_diag_op->inputs.push_back(op->inputs[0]);
  matrix_set_diag_op->inputs.push_back(op->inputs[1]);
  matrix_set_diag_op->outputs.push_back(op->outputs[0]);
  AddMessageF("Replacing %s with %s", LogName(*op),
              LogName(*matrix_set_diag_op));
  model->operators.emplace(it, matrix_set_diag_op);
  DeleteOpAndArrays(model, op);
  *modified = true;
  return ::tensorflow::Status::OK();
}
:: tensorflow :: Status ConvertMatrixSetDiagV2OrV3ToV1 :: Run ( Model * model , std :: size_t op_index , bool * modified ) { * modified = false ; auto it = model -> operators . begin ( ) + op_index ; const auto * op = it -> get ( ) ; if ( op -> type != OperatorType :: kMatrixSetDiagV2 && op -> type != OperatorType :: kMatrixSetDiagV3 ) { return :: tensorflow :: Status :: OK ( ) ; } if ( op -> inputs . size ( ) != 3 ) { return tensorflow :: errors :: InvalidArgument ( " " , LogName ( * op ) ) ; } const auto & input_k = model -> GetArray ( op -> inputs [ 2 ] ) ; if ( ! input_k . buffer ) { return :: tensorflow :: Status :: OK ( ) ; } if ( input_k . GetBuffer < ArrayDataType :: kInt32 > ( ) . data . size ( ) != 1 ) { return tensorflow :: errors :: InvalidArgument ( " " , LogName ( * op ) ) ; } int k = input_k . GetBuffer < ArrayDataType :: kInt32 > ( ) . data [ 0 ] ; if ( k != 0 ) { return tensorflow :: errors :: InvalidArgument ( " " , LogName ( * op ) , " " ) ; } auto * matrix_set_diag_op = new MatrixSetDiagOperator ; matrix_set_diag_op -> inputs . push_back ( op -> inputs [ 0 ] ) ; matrix_set_diag_op -> inputs . push_back ( op -> inputs [ 1 ] ) ; matrix_set_diag_op -> outputs . push_back ( op -> outputs [ 0 ] ) ; AddMessageF ( " " , LogName ( * op ) , LogName ( * matrix_set_diag_op ) ) ; model -> operators . emplace ( it , matrix_set_diag_op ) ; DeleteOpAndArrays ( model , op ) ; * modified = true ; return :: tensorflow :: Status :: OK ( ) ; }
V3 is only different from V2 because it has an extra attribute (align).
V3 is only different from V2 because it has an extra attribute ( align ) .
// Replace the operator in the graph.