forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_uniform.cpp
59 lines (48 loc) · 1.93 KB
/
random_uniform.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/random_uniform.hpp"
#include "common_op_table.hpp"
#include "openvino/op/constant.hpp"
using namespace std;
using namespace ov::op;
namespace ov {
namespace frontend {
namespace tensorflow {
namespace op {
ov::OutputVector translate_random_uniform_op(const NodeContext& node) {
default_op_checks(node, 1, {"RandomUniform"});
auto shape = node.get_input(0);
// retrieve attributes
auto seed = node.get_attribute<int64_t>("seed", 0);
auto seed2 = node.get_attribute<int64_t>("seed2", 0);
auto output_type = node.get_attribute<ov::element::Type>("dtype");
auto minval = make_shared<v0::Constant>(output_type, Shape{}, 0);
auto maxval = make_shared<v0::Constant>(output_type, Shape{}, 1);
auto random = std::make_shared<v8::RandomUniform>(shape, minval, maxval, output_type, seed, seed2);
set_node_name(node.get_name(), random);
return random->outputs();
}
ov::OutputVector translate_random_uniform_int_op(const NodeContext& node) {
default_op_checks(node, 3, {"RandomUniformInt"});
auto shape = node.get_input(0);
auto minval = node.get_input(1);
auto maxval = node.get_input(2);
// retrieve attributes
auto seed = node.get_attribute<int64_t>("seed", 0);
auto seed2 = node.get_attribute<int64_t>("seed2", 0);
auto output_type = minval.get_element_type();
Output<Node> random;
if (output_type.is_static()) {
random = std::make_shared<v8::RandomUniform>(shape, minval, maxval, output_type, seed, seed2);
} else {
random = std::make_shared<v8::RandomUniform>(shape, minval, maxval, element::i64, seed, seed2);
random = make_shared<v1::ConvertLike>(random, minval);
}
set_node_name(node.get_name(), random.get_node_shared_ptr());
return {random};
}
} // namespace op
} // namespace tensorflow
} // namespace frontend
} // namespace ov