Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
99a9d56f
Commit
99a9d56f
authored
Aug 22, 2023
by
Brian Pickrell
Browse files
added integer types to random_uniform and removed range_max and range_min attributes
parent
10432892
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
12 deletions
+20
-12
src/include/migraphx/op/random_seed.hpp
src/include/migraphx/op/random_seed.hpp
+1
-3
src/include/migraphx/op/random_uniform.hpp
src/include/migraphx/op/random_uniform.hpp
+19
-9
No files found.
src/include/migraphx/op/random_seed.hpp
View file @
99a9d56f
...
...
@@ -62,9 +62,7 @@ struct random_seed
{
argument
result
(
output_shape
);
result
.
visit
([
&
](
auto
output
)
{
output
.
front
()
=
std
::
random_device
{}();
});
result
.
visit
([
&
](
auto
output
)
{
output
.
front
()
=
std
::
random_device
{}();
});
return
result
;
}
};
...
...
src/include/migraphx/op/random_uniform.hpp
View file @
99a9d56f
...
...
@@ -56,13 +56,10 @@ struct random_uniform
// The random_uniform operation does not contain a random number generator seed
// as a member, and expects it to be passed as a runtime input.
float
range_min
=
0.0
f
;
float
range_max
=
1.0
f
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
range_min
,
"range_min"
),
f
(
self
.
range_max
,
"range_max"
)
);
return
pack
();
}
/**
...
...
@@ -90,14 +87,27 @@ struct random_uniform
argument
compute
(
const
shape
&
,
std
::
vector
<
argument
>
args
)
const
{
// Output goes into the passed buffer, not the shape output.
a
rgument
result
=
args
[
1
];
a
uto
result
=
args
[
1
];
uint64_t
local_seed
=
args
[
0
].
at
<
uint64_t
>
(
0
);
std
::
mt19937
gen
(
local_seed
);
std
::
uniform_real_distribution
<>
dis
(
range_min
,
range_max
);
result
.
visit
([
&
](
auto
output_shape
)
{
std
::
generate
(
output_shape
.
begin
(),
output_shape
.
end
(),
[
&
]()
{
return
dis
(
gen
);
});
result
.
visit
([
&
](
auto
output
)
{
using
type
=
typename
decltype
(
output
)
::
value_type
;
if
constexpr
(
std
::
is_integral
<
type
>
{})
{
// default range for all integer types is (0, INT_MAX) which depends
// on the integral type. To clamp
// to a different range, apply min or max ops. to the output of this.
std
::
uniform_int_distribution
<
type
>
dis
;
std
::
generate
(
output
.
begin
(),
output
.
end
(),
[
&
]
{
return
dis
(
gen
);
});
}
else
{
// default real distribution type is double with range (0, 1);
std
::
uniform_real_distribution
<>
dis
;
std
::
generate
(
output
.
begin
(),
output
.
end
(),
[
&
]
{
return
dis
(
gen
);
});
}
});
return
result
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment