!43335 Unify graph and pynative error message for sparse
Merge pull request !43335 from 杨林枫/sparse_error_msg
This commit is contained in:
commit
d6d4235fa8
|
@ -70,9 +70,9 @@ AbstractBasePtr MakeCSRTensorInfer(const abstract::AnalysisEnginePtr &, const Pr
|
|||
return elem;
|
||||
});
|
||||
if (values_shp.size() + 1 != shape_vec.size()) {
|
||||
MS_EXCEPTION(ValueError) << "Values' dimension should equal to csr_tensor's dimension - 1, but got"
|
||||
MS_EXCEPTION(ValueError) << "Values' dimension should equal to CSRTensor's dimension - 1, but got"
|
||||
<< "Values' dimension: " << values_shp.size()
|
||||
<< ", csr_tensor's dimension: " << shape_vec.size() << ".";
|
||||
<< ", CSRTensor's dimension: " << shape_vec.size() << ".";
|
||||
}
|
||||
if (shape_vec[kIndexZero] + 1 != indptr_shp[kIndexZero]) {
|
||||
MS_EXCEPTION(ValueError) << "Indptr must have length (1 + shape[0]), but got: " << indptr_shp[kIndexZero];
|
||||
|
@ -84,7 +84,10 @@ AbstractBasePtr MakeCSRTensorInfer(const abstract::AnalysisEnginePtr &, const Pr
|
|||
MS_EXCEPTION(ValueError) << "The element of shape must be positive, but got " << shape_value->ToString();
|
||||
}
|
||||
if ((i > 1) && (shape_vec[i] != values_shp[i - 1])) {
|
||||
MS_EXCEPTION(ValueError) << "csr_tensor's shape should match with values' shape.";
|
||||
MS_EXCEPTION(ValueError)
|
||||
<< "CSRTensor's shape[2: ] must be equal to value's shape[1: ], but CSRTensor's shape got: "
|
||||
<< shape_value->ToString() << ", "
|
||||
<< "values's shape got: " << values->shape()->ToString() << ".";
|
||||
}
|
||||
if (!shape_types[i]->isa<Int>()) {
|
||||
MS_EXCEPTION(TypeError) << "The element type of shape must be Int, but got " << shape_types[i]->ToString();
|
||||
|
|
|
@ -971,9 +971,13 @@ class Validator:
|
|||
err_msg1 = "For CSRTensor, indices and values must equal in their shape, "
|
||||
err_msg2 = f"but got indices shape: {indices_shp[0]}, values shape: {values_shp[0]}."
|
||||
raise ValueError(err_msg1 + err_msg2)
|
||||
if len(values_shp) + 1 != len(csr_shp):
|
||||
raise ValueError(f"Values' dimension should equal to CSRTensor's dimension - 1, but got"\
|
||||
f"Values' dimension: {len(values_shp)} , CSRTensor's dimension: "\
|
||||
f"{len(csr_shp)}")
|
||||
if values_shp[1: ] != csr_shp[2: ]:
|
||||
raise ValueError(f"csr_tensor's shape[2: ] must be equal to value's shape[1: ],"\
|
||||
f"but csr_tensor's shape[2: ] got: {csr_shp[2: ]} and value's shape[1: ]"\
|
||||
raise ValueError(f"CSRTensor's shape[2: ] must be equal to value's shape[1: ],"\
|
||||
f"but CSRTensor's shape[2: ] got: {csr_shp[2: ]} and value's shape[1: ]"\
|
||||
f"got: {values_shp[1: ]}")
|
||||
|
||||
@staticmethod
|
||||
|
@ -996,11 +1000,15 @@ class Validator:
|
|||
"""Checks input tensors' shapes for COOTensor."""
|
||||
if len(coo_shp) != 2:
|
||||
raise ValueError(f"For COOTensor, the length of 'shape' must be 2, but got {coo_shp}.")
|
||||
shp_mul = 1
|
||||
for sh in coo_shp:
|
||||
if sh <= 0:
|
||||
raise ValueError(f"For COOTensor, the element of 'shape' must be positive, but got {sh} in {coo_shp}.")
|
||||
if not isinstance(sh, int):
|
||||
raise TypeError(f"For COOTensor, the element type of 'shape' must be int, but got {type(sh)}")
|
||||
shp_mul *= sh
|
||||
if shp_mul < values_shp[0]:
|
||||
raise ValueError(f"For COOTensor, shape is too small: ({shp_mul}) to hold all values({values_shp[0]}).")
|
||||
if len(indices_shp) != 2:
|
||||
raise ValueError(f"For COOTensor, 'indices' must be a 2-dimensional tensor, but got a {len(indices_shp)}"
|
||||
f"-dimensional tensor.")
|
||||
|
|
Loading…
Reference in New Issue