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
b0ddd9c6
Commit
b0ddd9c6
authored
Feb 11, 2019
by
Robert Kimball
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix python Executable wrapper
parent
936bcc70
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
32 deletions
+63
-32
executable.cpp
python/pyngraph/runtime/executable.cpp
+1
-1
test_ops.py
python/test/test_ops.py
+62
-31
No files found.
python/pyngraph/runtime/executable.cpp
View file @
b0ddd9c6
...
@@ -25,7 +25,7 @@ namespace py = pybind11;
...
@@ -25,7 +25,7 @@ namespace py = pybind11;
void
regclass_pyngraph_runtime_Executable
(
py
::
module
m
)
void
regclass_pyngraph_runtime_Executable
(
py
::
module
m
)
{
{
py
::
class_
<
ngraph
::
runtime
::
Executable
,
std
::
unique
_ptr
<
ngraph
::
runtime
::
Executable
>>
py
::
class_
<
ngraph
::
runtime
::
Executable
,
std
::
shared
_ptr
<
ngraph
::
runtime
::
Executable
>>
executable
(
m
,
"Executable"
);
executable
(
m
,
"Executable"
);
executable
.
doc
()
=
"ngraph.impl.runtime.Executable wraps ngraph::runtime::Executable"
;
executable
.
doc
()
=
"ngraph.impl.runtime.Executable wraps ngraph::runtime::Executable"
;
executable
.
def
(
"call"
,
executable
.
def
(
"call"
,
...
...
python/test/test_ops.py
View file @
b0ddd9c6
...
@@ -22,7 +22,7 @@ import numpy as np
...
@@ -22,7 +22,7 @@ import numpy as np
from
ngraph.impl
import
util
from
ngraph.impl
import
util
from
ngraph.impl
import
Shape
,
Strides
,
CoordinateDiff
,
AxisSet
,
AxisVector
,
Coordinate
from
ngraph.impl
import
Shape
,
Strides
,
CoordinateDiff
,
AxisSet
,
AxisVector
,
Coordinate
from
ngraph.impl
import
Type
,
Function
,
NodeVector
from
ngraph.impl
import
Type
,
Function
,
NodeVector
from
ngraph.impl.runtime
import
Backend
from
ngraph.impl.runtime
import
Backend
,
Executable
from
ngraph.impl.op
import
Acos
,
Asin
,
Atan
,
Cos
,
Sin
,
Tan
from
ngraph.impl.op
import
Acos
,
Asin
,
Atan
,
Cos
,
Sin
,
Tan
from
ngraph.impl.op
import
Cosh
,
Sinh
,
Tanh
,
Sqrt
,
Sign
from
ngraph.impl.op
import
Cosh
,
Sinh
,
Tanh
,
Sqrt
,
Sign
from
ngraph.impl.op
import
Power
,
Negative
,
Ceiling
,
Floor
from
ngraph.impl.op
import
Power
,
Negative
,
Ceiling
,
Floor
...
@@ -127,7 +127,8 @@ def binary_op_exec(op_str):
...
@@ -127,7 +127,8 @@ def binary_op_exec(op_str):
result_arr
=
np
.
array
([[
0
,
0
],
[
0
,
0
]],
dtype
=
np
.
float32
)
result_arr
=
np
.
array
([[
0
,
0
],
[
0
,
0
]],
dtype
=
np
.
float32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
a_arr
=
np
.
array
([[
1
,
6
],
[
7
,
4
]],
dtype
=
np
.
float32
)
a_arr
=
np
.
array
([[
1
,
6
],
[
7
,
4
]],
dtype
=
np
.
float32
)
...
@@ -156,7 +157,8 @@ def binary_op_comparison(op_str):
...
@@ -156,7 +157,8 @@ def binary_op_comparison(op_str):
result_arr
=
np
.
array
([[
False
,
False
],
[
False
,
False
]],
dtype
=
np
.
bool
)
result_arr
=
np
.
array
([[
False
,
False
],
[
False
,
False
]],
dtype
=
np
.
bool
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
)
a_arr
=
np
.
array
([[
1
,
5
],
[
3
,
2
]],
dtype
=
np
.
float32
)
a_arr
=
np
.
array
([[
1
,
5
],
[
3
,
2
]],
dtype
=
np
.
float32
)
...
@@ -256,7 +258,8 @@ def test_add_with_mul():
...
@@ -256,7 +258,8 @@ def test_add_with_mul():
result_arr
=
np
.
array
([
0
,
0
,
0
,
0
],
dtype
=
np
.
float32
)
result_arr
=
np
.
array
([
0
,
0
,
0
,
0
],
dtype
=
np
.
float32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
,
c
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
,
c
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
a_arr
=
np
.
array
([
1
,
2
,
3
,
4
],
dtype
=
np
.
float32
)
a_arr
=
np
.
array
([
1
,
2
,
3
,
4
],
dtype
=
np
.
float32
)
...
@@ -364,7 +367,8 @@ def unary_op_exec(op_str, input_list):
...
@@ -364,7 +367,8 @@ def unary_op_exec(op_str, input_list):
result_arr
=
np
.
zeros
(
shape_np
,
dtype
=
np
.
float32
)
result_arr
=
np
.
zeros
(
shape_np
,
dtype
=
np
.
float32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
)
a_arr
=
np
.
array
(
input_list
,
dtype
=
np
.
float32
)
a_arr
=
np
.
array
(
input_list
,
dtype
=
np
.
float32
)
...
@@ -497,7 +501,8 @@ def test_not():
...
@@ -497,7 +501,8 @@ def test_not():
result_arr
=
np
.
array
([
False
,
False
],
dtype
=
np
.
bool
)
result_arr
=
np
.
array
([
False
,
False
],
dtype
=
np
.
bool
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
2
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
2
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
2
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
2
)
a_arr
=
np
.
array
([
True
,
False
],
dtype
=
np
.
bool
)
a_arr
=
np
.
array
([
True
,
False
],
dtype
=
np
.
bool
)
...
@@ -522,7 +527,9 @@ def test_sum():
...
@@ -522,7 +527,9 @@ def test_sum():
result_arr
=
np
.
array
([
0
],
dtype
=
np
.
float32
)
result_arr
=
np
.
array
([
0
],
dtype
=
np
.
float32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
get_performance_data
()
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
)
a_arr
=
np
.
array
([
1
,
2
,
3
,
4
],
dtype
=
np
.
float32
)
a_arr
=
np
.
array
([
1
,
2
,
3
,
4
],
dtype
=
np
.
float32
)
...
@@ -547,7 +554,8 @@ def test_reshape():
...
@@ -547,7 +554,8 @@ def test_reshape():
result_arr
=
np
.
array
([[
0
,
0
],
[
0
,
0
],
[
0
,
0
]],
dtype
=
np
.
float32
)
result_arr
=
np
.
array
([[
0
,
0
],
[
0
,
0
],
[
0
,
0
]],
dtype
=
np
.
float32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
)
a_arr
=
np
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
]],
dtype
=
np
.
float32
)
a_arr
=
np
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
]],
dtype
=
np
.
float32
)
...
@@ -573,7 +581,8 @@ def test_convert():
...
@@ -573,7 +581,8 @@ def test_convert():
result_arr
=
np
.
array
([
False
,
False
,
False
],
dtype
=
np
.
bool
)
result_arr
=
np
.
array
([
False
,
False
,
False
],
dtype
=
np
.
bool
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
3
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
3
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
3
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
3
)
a_arr
=
np
.
array
([
1
,
5
,
3
],
dtype
=
np
.
float32
)
a_arr
=
np
.
array
([
1
,
5
,
3
],
dtype
=
np
.
float32
)
...
@@ -590,7 +599,8 @@ def test_convert():
...
@@ -590,7 +599,8 @@ def test_convert():
result_arr
=
np
.
array
([
0
,
0
,
0
],
dtype
=
np
.
int32
)
result_arr
=
np
.
array
([
0
,
0
,
0
],
dtype
=
np
.
int32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
12
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
12
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
12
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
12
)
a_arr
=
np
.
array
([
1.4
,
5.4
,
3.9
],
dtype
=
np
.
float32
)
a_arr
=
np
.
array
([
1.4
,
5.4
,
3.9
],
dtype
=
np
.
float32
)
...
@@ -614,7 +624,8 @@ def test_broadcast():
...
@@ -614,7 +624,8 @@ def test_broadcast():
result_arr
=
np
.
zeros
((
3
,
3
),
dtype
=
np
.
float32
)
result_arr
=
np
.
zeros
((
3
,
3
),
dtype
=
np
.
float32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
a_arr
=
np
.
array
([[
0
],
[
0
],
[
0
]],
dtype
=
np
.
float32
)
a_arr
=
np
.
array
([[
0
],
[
0
],
[
0
]],
dtype
=
np
.
float32
)
...
@@ -636,7 +647,8 @@ def test_constant():
...
@@ -636,7 +647,8 @@ def test_constant():
result_arr
=
np
.
zeros
((
3
,
3
),
dtype
=
np
.
float32
)
result_arr
=
np
.
zeros
((
3
,
3
),
dtype
=
np
.
float32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
result_arr_ref
=
np
.
arange
(
9
)
.
reshape
(
3
,
3
)
result_arr_ref
=
np
.
arange
(
9
)
.
reshape
(
3
,
3
)
...
@@ -659,7 +671,8 @@ def test_onehot():
...
@@ -659,7 +671,8 @@ def test_onehot():
result_arr
=
np
.
zeros
((
3
,
3
),
dtype
=
np
.
float32
)
result_arr
=
np
.
zeros
((
3
,
3
),
dtype
=
np
.
float32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
36
)
a_arr
=
np
.
array
([
1
,
0
,
2
])
a_arr
=
np
.
array
([
1
,
0
,
2
])
...
@@ -691,7 +704,8 @@ def test_concat():
...
@@ -691,7 +704,8 @@ def test_concat():
result_arr
=
np
.
zeros
(
6
,
dtype
=
np
.
float32
)
.
reshape
(
3
,
2
)
result_arr
=
np
.
zeros
(
6
,
dtype
=
np
.
float32
)
.
reshape
(
3
,
2
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
,
c
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
,
c
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
)
a_arr
=
np
.
array
([[
1
,
2
]],
dtype
=
np
.
float32
)
a_arr
=
np
.
array
([[
1
,
2
]],
dtype
=
np
.
float32
)
...
@@ -742,7 +756,8 @@ def test_select():
...
@@ -742,7 +756,8 @@ def test_select():
result_arr
=
np
.
array
([[
0
,
0
]],
dtype
=
np
.
float32
)
result_arr
=
np
.
array
([[
0
,
0
]],
dtype
=
np
.
float32
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
,
c
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
,
c
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
)
result_arr_ref
=
np
.
array
([[
5
,
8
]])
result_arr_ref
=
np
.
array
([[
5
,
8
]])
...
@@ -773,7 +788,8 @@ def test_slice():
...
@@ -773,7 +788,8 @@ def test_slice():
result_arr
=
np
.
zeros
(
16
,
dtype
=
np
.
float32
)
.
reshape
(
4
,
4
)
result_arr
=
np
.
zeros
(
16
,
dtype
=
np
.
float32
)
.
reshape
(
4
,
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
16
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
64
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
64
)
result_arr_ref
=
input_arr
[
lower_bounds
[
0
]:
upper_bounds
[
0
],
lower_bounds
[
1
]:
upper_bounds
[
1
]]
result_arr_ref
=
input_arr
[
lower_bounds
[
0
]:
upper_bounds
[
0
],
lower_bounds
[
1
]:
upper_bounds
[
1
]]
...
@@ -792,7 +808,8 @@ def test_slice():
...
@@ -792,7 +808,8 @@ def test_slice():
result_arr
=
np
.
zeros
(
8
,
dtype
=
np
.
float32
)
.
reshape
(
4
,
2
)
result_arr
=
np
.
zeros
(
8
,
dtype
=
np
.
float32
)
.
reshape
(
4
,
2
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
32
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
32
)
result_arr_ref
=
result_arr_ref
[::
strides
[
0
],
::
strides
[
1
]]
result_arr_ref
=
result_arr_ref
[::
strides
[
0
],
::
strides
[
1
]]
...
@@ -826,7 +843,8 @@ def test_replace_slice():
...
@@ -826,7 +843,8 @@ def test_replace_slice():
result_arr
=
np
.
zeros
(
24
,
dtype
=
np
.
float32
)
.
reshape
(
6
,
4
)
result_arr
=
np
.
zeros
(
24
,
dtype
=
np
.
float32
)
.
reshape
(
6
,
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
*
4
)
result_arr_ref
=
np
.
copy
(
input_arr_a
)
result_arr_ref
=
np
.
copy
(
input_arr_a
)
...
@@ -844,7 +862,8 @@ def test_replace_slice():
...
@@ -844,7 +862,8 @@ def test_replace_slice():
parameter_list
,
'test'
)
parameter_list
,
'test'
)
backend
=
Backend
.
create
(
pytest
.
config
.
getoption
(
'backend'
))
backend
=
Backend
.
create
(
pytest
.
config
.
getoption
(
'backend'
))
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
24
*
4
)
result_arr_ref
=
np
.
copy
(
input_arr_a
)
result_arr_ref
=
np
.
copy
(
input_arr_a
)
...
@@ -875,7 +894,8 @@ def test_max_pool():
...
@@ -875,7 +894,8 @@ def test_max_pool():
result_arr
=
np
.
zeros
(
8
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
8
)
result_arr
=
np
.
zeros
(
8
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
8
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
32
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
32
)
result_arr_ref
=
(
np
.
arange
(
8
)
+
2
)
.
reshape
(
1
,
1
,
8
)
result_arr_ref
=
(
np
.
arange
(
8
)
+
2
)
.
reshape
(
1
,
1
,
8
)
...
@@ -892,7 +912,8 @@ def test_max_pool():
...
@@ -892,7 +912,8 @@ def test_max_pool():
result_arr
=
np
.
zeros
(
size
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
size
)
result_arr
=
np
.
zeros
(
size
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
size
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
size
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
size
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
size
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
size
*
4
)
result_arr_ref
=
((
np
.
arange
(
size
)
+
1
)
*
2
)
.
reshape
(
1
,
1
,
size
)
result_arr_ref
=
((
np
.
arange
(
size
)
+
1
)
*
2
)
.
reshape
(
1
,
1
,
size
)
...
@@ -917,7 +938,8 @@ def test_max_pool():
...
@@ -917,7 +938,8 @@ def test_max_pool():
result_arr
=
np
.
zeros
(
64
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
8
,
8
)
result_arr
=
np
.
zeros
(
64
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
8
,
8
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
*
8
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
*
8
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
*
8
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
8
*
8
*
4
)
result_arr_ref
=
((
np
.
arange
(
100
)
.
reshape
(
10
,
10
))[
2
:,
2
:])
.
reshape
(
1
,
1
,
8
,
8
)
result_arr_ref
=
((
np
.
arange
(
100
)
.
reshape
(
10
,
10
))[
2
:,
2
:])
.
reshape
(
1
,
1
,
8
,
8
)
...
@@ -934,7 +956,8 @@ def test_max_pool():
...
@@ -934,7 +956,8 @@ def test_max_pool():
result_arr
=
np
.
zeros
(
size
*
size
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
size
,
size
)
result_arr
=
np
.
zeros
(
size
*
size
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
size
,
size
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
size
*
size
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
size
*
size
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
size
*
size
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
size
*
size
*
4
)
result_arr_ref
=
((
np
.
arange
(
100
)
.
reshape
(
10
,
10
))[
2
::
2
,
2
::
2
])
.
reshape
(
1
,
1
,
size
,
size
)
result_arr_ref
=
((
np
.
arange
(
100
)
.
reshape
(
10
,
10
))[
2
::
2
,
2
::
2
])
.
reshape
(
1
,
1
,
size
,
size
)
...
@@ -1014,7 +1037,8 @@ def test_convolution():
...
@@ -1014,7 +1037,8 @@ def test_convolution():
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
14
,
14
]))
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
14
,
14
]))
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
14
*
14
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
14
*
14
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
14
*
14
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
14
*
14
*
4
)
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
])
.
reshape
(
1
,
1
,
14
,
14
)
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
])
.
reshape
(
1
,
1
,
14
,
14
)
...
@@ -1048,7 +1072,8 @@ def test_convolution_with_strides():
...
@@ -1048,7 +1072,8 @@ def test_convolution_with_strides():
result_arr
=
np
.
zeros
(
16
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
4
,
4
)
result_arr
=
np
.
zeros
(
16
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
4
,
4
)
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
4
,
4
]))
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
4
,
4
]))
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
*
4
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
*
4
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
*
4
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
4
*
4
*
4
)
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
)
.
reshape
(
1
,
1
,
4
,
4
)
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
)
.
reshape
(
1
,
1
,
4
,
4
)
...
@@ -1082,7 +1107,8 @@ def test_convolution_with_filter_dilation():
...
@@ -1082,7 +1107,8 @@ def test_convolution_with_filter_dilation():
result_arr
=
np
.
zeros
(
36
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
6
,
6
)
result_arr
=
np
.
zeros
(
36
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
6
,
6
)
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
6
,
6
]))
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
6
,
6
]))
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
6
*
6
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
6
*
6
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
6
*
6
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
6
*
6
*
4
)
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
,
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
,
...
@@ -1122,7 +1148,8 @@ def test_convolution_with_padding():
...
@@ -1122,7 +1148,8 @@ def test_convolution_with_padding():
result_arr
=
np
.
zeros
(
36
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
6
,
6
)
result_arr
=
np
.
zeros
(
36
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
6
,
6
)
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
6
,
6
]))
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
6
,
6
]))
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
6
*
6
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
6
*
6
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
6
*
6
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
6
*
6
*
4
)
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
,
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
,
...
@@ -1160,7 +1187,8 @@ def test_convolution_with_padding():
...
@@ -1160,7 +1187,8 @@ def test_convolution_with_padding():
result_arr
=
np
.
zeros
(
81
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
9
,
9
)
result_arr
=
np
.
zeros
(
81
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
9
,
9
)
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
9
,
9
]))
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
9
,
9
]))
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
9
*
9
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
9
*
9
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
9
*
9
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
9
*
9
*
4
)
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
,
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
,
...
@@ -1201,7 +1229,8 @@ def test_convolution_with_data_dilation():
...
@@ -1201,7 +1229,8 @@ def test_convolution_with_data_dilation():
result_arr
=
np
.
zeros
(
17
*
17
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
17
,
17
)
result_arr
=
np
.
zeros
(
17
*
17
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
17
,
17
)
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
17
,
17
]))
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
17
,
17
]))
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
17
*
17
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
17
*
17
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
17
*
17
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
17
*
17
*
4
)
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
,
result_arr_ref
=
convolution2d
(
image_arr
[
0
][
0
],
filter_arr
[
0
][
0
],
strides
,
...
@@ -1248,7 +1277,8 @@ def test_convolutionBackpropData():
...
@@ -1248,7 +1277,8 @@ def test_convolutionBackpropData():
result_arr
=
np
.
zeros
(
10
*
10
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
10
,
10
)
result_arr
=
np
.
zeros
(
10
*
10
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
10
,
10
)
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
10
,
10
]))
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
10
,
10
]))
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
10
*
10
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
10
*
10
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
10
*
10
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
10
*
10
*
4
)
result_arr_ref
=
np
.
array
(
result_arr_ref
=
np
.
array
(
...
@@ -1303,7 +1333,8 @@ def test_convolutionBackpropFilters():
...
@@ -1303,7 +1333,8 @@ def test_convolutionBackpropFilters():
result_arr
=
np
.
zeros
(
3
*
3
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
3
,
3
)
result_arr
=
np
.
zeros
(
3
*
3
,
dtype
=
np
.
float32
)
.
reshape
(
1
,
1
,
3
,
3
)
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
3
,
3
]))
result
=
backend
.
create_tensor
(
element_type
,
Shape
([
1
,
1
,
3
,
3
]))
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
3
*
3
*
4
)
result
.
write
(
util
.
numpy_to_c
(
result_arr
),
0
,
3
*
3
*
4
)
backend
.
call
(
backend
.
compile
(
function
),
[
result
],
[
a
,
b
])
handle
=
backend
.
compile
(
function
)
handle
.
call
([
result
],
[
a
,
b
])
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
3
*
3
*
4
)
result
.
read
(
util
.
numpy_to_c
(
result_arr
),
0
,
3
*
3
*
4
)
result_arr_ref
=
np
.
array
(
result_arr_ref
=
np
.
array
(
...
...
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