1 /** 2 * Copyright 2024 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CORE_OPS_OPS_FUNC_IMPL_RAND_H_ 18 #define MINDSPORE_CORE_OPS_OPS_FUNC_IMPL_RAND_H_ 19 20 #include <set> 21 #include <vector> 22 #include "ops/ops_func_impl/ones.h" 23 #include "ops/ops_func_impl/op_func_impl.h" 24 #include "ops/base_operator.h" 25 #include "ops/op_name.h" 26 #include "utils/check_convert_utils.h" 27 28 namespace mindspore { 29 namespace ops { 30 class MIND_API RandExtFuncImpl : public OnesFuncImpl { 31 public: InferType(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)32 TypePtr InferType(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) const override { 33 auto prim_name = primitive->name(); 34 // check 35 auto dtype_type = input_args[kIndex3]->GetType(); 36 if (dtype_type->isa<TypeNone>()) { 37 return kFloat32; 38 } 39 auto dtype_ptr = input_args[kIndex3]->GetValue(); 40 if (!dtype_ptr->isa<Int64Imm>()) { 41 MS_EXCEPTION(TypeError) << "For '" << prim_name 42 << "', 'dtype' must be a TypeId, but got an invalid type: " << dtype_ptr->ToString() 43 << "."; 44 } 45 auto val = GetValue<int64_t>(dtype_ptr); 46 auto infer_type = TypeIdToType(static_cast<TypeId>(val)); 47 CheckAndConvertUtils::CheckTypeValid("dtype", infer_type, {kFloat16, kFloat32, kFloat64, kBFloat16}, 48 primitive->name()); 49 return infer_type; 50 } 51 }; 52 } // namespace ops 53 } // namespace mindspore 54 55 #endif // MINDSPORE_CORE_OPS_OPS_FUNC_IMPL_RAND_H_ 56