Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
84d236ad
Commit
84d236ad
authored
Feb 22, 2018
by
Matthew Brookhart
Committed by
Scott Cyphers
Feb 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite variance to use 2 pass (#520)
parent
59bdd6ee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
reduce_ops.cpp
src/ngraph/builder/reduce_ops.cpp
+18
-9
No files found.
src/ngraph/builder/reduce_ops.cpp
View file @
84d236ad
...
...
@@ -15,10 +15,12 @@
*******************************************************************************/
#include "ngraph/builder/reduce_ops.hpp"
#include "ngraph/builder/autobroadcast.hpp"
#include "ngraph/ops/add.hpp"
#include "ngraph/ops/divide.hpp"
#include "ngraph/ops/multiply.hpp"
#include "ngraph/ops/power.hpp"
#include "ngraph/ops/reshape.hpp"
#include "ngraph/ops/subtract.hpp"
#include "ngraph/ops/sum.hpp"
...
...
@@ -80,27 +82,34 @@ namespace ngraph
const
AxisSet
&
reduction_axes
,
const
bool
bessel_correction
)
{
auto
xsum
=
std
::
make_shared
<
op
::
Sum
>
(
node
,
reduction_axes
);
std
::
shared_ptr
<
Node
>
mu
=
mean
(
node
,
reduction_axes
);
auto
x2
=
node
*
node
;
auto
reshape
=
node
->
get_shape
();
for
(
auto
i
:
reduction_axes
)
{
reshape
[
i
]
=
1
;
}
auto
x2sum
=
std
::
make_shared
<
op
::
Sum
>
(
x2
,
reduction_axes
);
ngraph
::
AxisVector
order
(
mu
->
get_shape
().
size
());
std
::
iota
(
order
.
begin
(),
order
.
end
(),
0
);
const
auto
&
et
=
node
->
get_element_type
();
auto
N
=
get_num_elements
(
node
->
get_shape
(),
reduction_axes
);
mu
=
std
::
make_shared
<
op
::
Reshape
>
(
mu
,
order
,
reshape
);
std
::
shared_ptr
<
Node
>
diff
=
make_with_numpy_broadcast
<
op
::
Subtract
>
(
node
,
mu
);
auto
Nconst
=
op
::
Constant
::
create
(
et
,
xsum
->
get_shape
(),
{
N
});
auto
xbar2
=
(
xsum
*
xsum
)
/
Nconst
;
diff
=
std
::
make_shared
<
op
::
Sum
>
(
diff
*
diff
,
reduction_axes
);
auto
diff
=
x2sum
-
xbar2
;
const
auto
&
et
=
node
->
get_element_type
();
auto
N
=
get_num_elements
(
node
->
get_shape
(),
reduction_axes
);
if
(
bessel_correction
)
{
auto
N1const
=
op
::
Constant
::
create
(
et
,
xsum
->
get_shape
(),
{
N
-
1
});
auto
N1const
=
op
::
Constant
::
create
(
et
,
diff
->
get_shape
(),
{
N
-
1
});
return
diff
/
N1const
;
}
else
{
auto
Nconst
=
op
::
Constant
::
create
(
et
,
diff
->
get_shape
(),
{
N
});
return
diff
/
Nconst
;
}
}
...
...
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