forked from mindspore-Ecosystem/mindspore
!38512 [MSLITE] Fix documents of uniform.
Merge pull request !38512 from wangshaocong/uniform_ops
This commit is contained in:
commit
2b5bce1b42
|
@ -62,23 +62,25 @@ abstract::AbstractBasePtr UniformIntInfer(const abstract::AnalysisEnginePtr &, c
|
|||
abstract::ShapePtr minval_shape = minval->shape();
|
||||
MS_EXCEPTION_IF_NULL(minval_shape);
|
||||
if (minval_shape->IsDimUnknown() || minval_shape->shape().size() != 0) {
|
||||
MS_LOG(EXCEPTION) << "The min value should be a scalar tensor, while the shape is: " << minval_shape->ToString();
|
||||
MS_EXCEPTION(ValueError) << "The min value should be a scalar tensor, while the shape is: "
|
||||
<< minval_shape->ToString();
|
||||
}
|
||||
abstract::AbstractTensorPtr maxval = abstract::CheckArg<abstract::AbstractTensor>(op_name, input_args, 2);
|
||||
(void)CheckAndConvertUtils::CheckTensorTypeValid("maxval", maxval->BuildType(), {kInt32}, op_name);
|
||||
abstract::ShapePtr maxval_shape = maxval->shape();
|
||||
MS_EXCEPTION_IF_NULL(maxval_shape);
|
||||
if (maxval_shape->IsDimUnknown() || maxval_shape->shape().size() != 0) {
|
||||
MS_LOG(EXCEPTION) << "The max value should be a scalar tensor, while the shape is: " << minval_shape->ToString();
|
||||
MS_EXCEPTION(ValueError) << "The max value should be a scalar tensor, while the shape is: "
|
||||
<< minval_shape->ToString();
|
||||
}
|
||||
|
||||
ShapeVector shape;
|
||||
abstract::ShapePtr output_shape;
|
||||
auto shape_value = input_args[0]->BuildValue();
|
||||
if (!shape_value->isa<AnyValue>() && !shape_value->isa<None>()) {
|
||||
shape = shape_value->isa<ValueTuple>()
|
||||
? CheckAndConvertUtils::CheckTupleInt("input[shape]", shape_value, op_name)
|
||||
: CheckAndConvertUtils::CheckTensorIntValue("input[shape]", shape_value, op_name);
|
||||
shape = shape_value->isa<tensor::Tensor>()
|
||||
? CheckAndConvertUtils::CheckTensorIntValue("input[shape]", shape_value, op_name)
|
||||
: CheckAndConvertUtils::CheckTupleInt("input[shape]", shape_value, op_name);
|
||||
output_shape = std::make_shared<abstract::Shape>(shape);
|
||||
} else {
|
||||
shape = {-2}; // unknown dimension.
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CORE_OPS_RANDOM_UNIFORM_INT_H_
|
||||
#define MINDSPORE_CORE_OPS_RANDOM_UNIFORM_INT_H_
|
||||
#ifndef MINDSPORE_CORE_OPS_UNIFORM_INT_H_
|
||||
#define MINDSPORE_CORE_OPS_UNIFORM_INT_H_
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
@ -56,4 +56,4 @@ abstract::AbstractBasePtr UniformIntInfer(const abstract::AnalysisEnginePtr &, c
|
|||
} // namespace ops
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CORE_OPS_RANDOM_UNIFORM_INT_H_
|
||||
#endif // MINDSPORE_CORE_OPS_UNIFORM_INT_H_
|
||||
|
|
|
@ -61,9 +61,9 @@ abstract::AbstractBasePtr UniformRealInfer(const abstract::AnalysisEnginePtr &,
|
|||
abstract::ShapePtr output_shape;
|
||||
auto shape_value = input_args[0]->BuildValue();
|
||||
if (!shape_value->isa<AnyValue>() && !shape_value->isa<None>()) {
|
||||
shape = shape_value->isa<ValueTuple>()
|
||||
? CheckAndConvertUtils::CheckTupleInt("input[shape]", shape_value, op_name)
|
||||
: CheckAndConvertUtils::CheckTensorIntValue("input[shape]", shape_value, op_name);
|
||||
shape = shape_value->isa<tensor::Tensor>()
|
||||
? CheckAndConvertUtils::CheckTensorIntValue("input[shape]", shape_value, op_name)
|
||||
: CheckAndConvertUtils::CheckTupleInt("input[shape]", shape_value, op_name);
|
||||
output_shape = std::make_shared<abstract::Shape>(shape);
|
||||
} else {
|
||||
shape = {-2}; // unknown dimension.
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CORE_OPS_RANDOM_UNIFORM_REAL_H_
|
||||
#define MINDSPORE_CORE_OPS_RANDOM_UNIFORM_REAL_H_
|
||||
#ifndef MINDSPORE_CORE_OPS_UNIFORM_REAL_H_
|
||||
#define MINDSPORE_CORE_OPS_UNIFORM_REAL_H_
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
@ -55,4 +55,4 @@ abstract::AbstractBasePtr UniformRealInfer(const abstract::AnalysisEnginePtr &,
|
|||
} // namespace ops
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CORE_OPS_RANDOM_UNIFORM_REAL_H_
|
||||
#endif // MINDSPORE_CORE_OPS_UNIFORM_REAL_H_
|
||||
|
|
|
@ -51,7 +51,7 @@ class Uniform(Distribution):
|
|||
TypeError: When the input `dtype` is not a subclass of float.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``GPU``
|
||||
``Ascend`` ``GPU`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> import mindspore
|
||||
|
|
|
@ -174,7 +174,7 @@ def uniform(shape, minval, maxval, seed=None, dtype=mstype.float32):
|
|||
TypeError: If 'dtype' is neither int32 nor float32.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``GPU``
|
||||
``Ascend`` ``GPU`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> from mindspore import Tensor, ops
|
||||
|
|
|
@ -200,7 +200,7 @@ def uniform(shape, minval, maxval, seed=None, dtype=mstype.float32):
|
|||
TypeError: If 'dtype' is neither int32 nor float32.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``GPU``
|
||||
``Ascend`` ``GPU`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> from mindspore import Tensor, ops
|
||||
|
@ -210,13 +210,13 @@ def uniform(shape, minval, maxval, seed=None, dtype=mstype.float32):
|
|||
>>> shape = (4, 2)
|
||||
>>> minval = Tensor(1, mindspore.int32)
|
||||
>>> maxval = Tensor(2, mindspore.int32)
|
||||
>>> output = F.uniform(shape, minval, maxval, seed=5, dtype=mindspore.int32)
|
||||
>>> output = ops.uniform(shape, minval, maxval, seed=5, dtype=mindspore.int32)
|
||||
>>>
|
||||
>>> # For continuous uniform distribution, minval and maxval can be multi-dimentional:
|
||||
>>> shape = (3, 1, 2)
|
||||
>>> minval = Tensor(np.array([[3, 4], [5, 6]]), mindspore.float32)
|
||||
>>> maxval = Tensor([8.0, 10.0], mindspore.float32)
|
||||
>>> output = F.uniform(shape, minval, maxval, seed=5)
|
||||
>>> output = ops.uniform(shape, minval, maxval, seed=5)
|
||||
>>> result = output.shape
|
||||
>>> print(result)
|
||||
(3, 2, 2)
|
||||
|
|
Loading…
Reference in New Issue