Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Projects
aidge
aidge_core
Merge requests
!102
feat/operator_squeeze_unsqueeze
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
feat/operator_squeeze_unsqueeze
hrouis/aidge_core:feat/operator_squeeze_unsqueeze
into
dev
Overview
36
Commits
53
Pipelines
40
Changes
23
Closed
Grégoire Kubler
requested to merge
hrouis/aidge_core:feat/operator_squeeze_unsqueeze
into
dev
1 year ago
Overview
36
Commits
53
Pipelines
40
Changes
23
Expand
Context
see issue
#65 (closed)
1
0
Merge request reports
Compare
dev
version 37
c1ecff21
7 months ago
version 36
9ba16cb8
7 months ago
version 35
74a3fe62
7 months ago
version 34
e63220fb
7 months ago
version 33
ba3137e9
8 months ago
version 32
57846296
8 months ago
version 31
6daf1a29
8 months ago
version 30
4331d1f9
8 months ago
version 29
fbb14d80
8 months ago
version 28
6d1aff9f
8 months ago
version 27
9919ce39
8 months ago
version 26
2d2abc7e
8 months ago
version 25
fc57d529
8 months ago
version 24
98c7a1eb
8 months ago
version 23
cb70cc73
8 months ago
version 22
e929af87
8 months ago
version 21
fd9a7658
8 months ago
version 20
eb665264
8 months ago
version 19
6ed686af
8 months ago
version 18
38ca346f
9 months ago
version 17
62ae6870
9 months ago
version 16
354ea7c7
9 months ago
version 15
e25b3a8c
9 months ago
version 14
783e9bc4
9 months ago
version 13
c7ba5424
9 months ago
version 12
4620ef62
9 months ago
version 11
4f28ba6c
9 months ago
version 10
be69cabf
9 months ago
version 9
8db373ee
1 year ago
version 8
8db373ee
1 year ago
version 7
7de61513
1 year ago
version 6
a5222834
1 year ago
version 5
844cf634
1 year ago
version 4
dde63dd4
1 year ago
version 3
dde63dd4
1 year ago
version 2
00406350
1 year ago
version 1
50806bdc
1 year ago
dev (base)
and
latest version
latest version
c1ecff21
53 commits,
7 months ago
version 37
c1ecff21
53 commits,
7 months ago
version 36
9ba16cb8
52 commits,
7 months ago
version 35
74a3fe62
51 commits,
7 months ago
version 34
e63220fb
53 commits,
7 months ago
version 33
ba3137e9
51 commits,
8 months ago
version 32
57846296
50 commits,
8 months ago
version 31
6daf1a29
50 commits,
8 months ago
version 30
4331d1f9
49 commits,
8 months ago
version 29
fbb14d80
48 commits,
8 months ago
version 28
6d1aff9f
47 commits,
8 months ago
version 27
9919ce39
43 commits,
8 months ago
version 26
2d2abc7e
42 commits,
8 months ago
version 25
fc57d529
41 commits,
8 months ago
version 24
98c7a1eb
40 commits,
8 months ago
version 23
cb70cc73
38 commits,
8 months ago
version 22
e929af87
35 commits,
8 months ago
version 21
fd9a7658
34 commits,
8 months ago
version 20
eb665264
33 commits,
8 months ago
version 19
6ed686af
32 commits,
8 months ago
version 18
38ca346f
31 commits,
9 months ago
version 17
62ae6870
30 commits,
9 months ago
version 16
354ea7c7
32 commits,
9 months ago
version 15
e25b3a8c
32 commits,
9 months ago
version 14
783e9bc4
30 commits,
9 months ago
version 13
c7ba5424
26 commits,
9 months ago
version 12
4620ef62
25 commits,
9 months ago
version 11
4f28ba6c
16 commits,
9 months ago
version 10
be69cabf
14 commits,
9 months ago
version 9
8db373ee
12 commits,
1 year ago
version 8
8db373ee
12 commits,
1 year ago
version 7
7de61513
11 commits,
1 year ago
version 6
a5222834
10 commits,
1 year ago
version 5
844cf634
9 commits,
1 year ago
version 4
dde63dd4
8 commits,
1 year ago
version 3
dde63dd4
499 commits,
1 year ago
version 2
00406350
497 commits,
1 year ago
version 1
50806bdc
496 commits,
1 year ago
23 files
+
2021
−
28
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
23
Search (e.g. *.vue) (Ctrl+P)
aidge_core/unit_tests/test_operator_squeeze.py
0 → 100644
+
194
−
0
Options
"""
Copyright (c) 2023 CEA-List
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.
SPDX-License-Identifier: EPL-2.0
"""
import
unittest
import
aidge_core
from
aidge_core
import
Log
import
numpy
as
np
from
numpy
import
testing
as
npt
class
TestSqueeze
(
unittest
.
TestCase
):
"""
Test squeeze operator
"""
def
setUp
(
self
):
############DEFINING INPUT AND OUTPUTS FOR TESTS
axes_to_squeeze_0
=
[
0
]
axes_to_squeeze_many
=
[
0
,
1
,
4
]
axes_to_squeeze_all
=
[]
axes_to_squeeze_error
=
[
1
,
2
,
4
,
5
,
10
,
3
,
42
,
127
,
12
,
3
,
4
,
1
,
4
,
50
]
squeeze_dim_0
=
aidge_core
.
Squeeze
(
axes_to_squeeze_0
,
name
=
"
squeeze_dim_0
"
)
squeeze_many
=
aidge_core
.
Squeeze
(
axes_to_squeeze_many
,
name
=
"
squeeze_many
"
)
squeeze_all
=
aidge_core
.
Squeeze
(
axes_to_squeeze_all
,
name
=
"
squeeze_all
"
)
squeeze_error
=
aidge_core
.
Squeeze
(
axes_to_squeeze_error
,
name
=
"
squeeze_error
"
)
input_1_data_shape
=
np
.
array
([
1
,
2
,
3
])
input_2_data_hape
=
np
.
array
([
1
,
1
,
3
,
3
,
1
,
9
])
input_3_data_shape
=
np
.
array
([
1
])
input_4_data_shape
=
np
.
array
([
1
,
1
,
4
])
input_axes_0
=
axes_to_squeeze_0
input_axes_many
=
axes_to_squeeze_many
input_axes_all
=
axes_to_squeeze_all
# input_axes_error = aidge_core.Tensor(axes_to_squeeze_error)
####################### DEFINING TEST RUNS
self
.
tests_axes_defined_by_attribute
=
[
(
input_1_data_shape
,
squeeze_dim_0
,
np
.
array
([
2
,
3
])),
(
input_1_data_shape
,
squeeze_all
,
np
.
array
([
2
,
3
])),
(
input_2_data_hape
,
squeeze_dim_0
,
np
.
array
([
1
,
3
,
3
,
1
,
9
])),
(
input_2_data_hape
,
squeeze_many
,
np
.
array
([
3
,
3
,
9
])),
(
input_2_data_hape
,
squeeze_all
,
np
.
array
([
3
,
3
,
9
])),
(
input_3_data_shape
,
squeeze_dim_0
,
np
.
array
([])),
(
input_3_data_shape
,
squeeze_all
,
np
.
array
([])),
(
input_4_data_shape
,
squeeze_dim_0
,
np
.
array
([
1
,
4
])),
(
input_4_data_shape
,
squeeze_all
,
np
.
array
([
4
])),
]
# operators are puprposefully chosen with different predefined attribute than the input_axes tensor
self
.
tests_axes_defined_by_input
=
[
(
input_1_data_shape
,
input_axes_0
,
squeeze_error
,
np
.
array
([
2
,
3
])),
(
input_1_data_shape
,
input_axes_all
,
squeeze_error
,
np
.
array
([
2
,
3
])),
(
input_2_data_hape
,
input_axes_0
,
squeeze_error
,
np
.
array
([
1
,
3
,
3
,
1
,
9
])),
(
input_2_data_hape
,
input_axes_many
,
squeeze_error
,
np
.
array
([
3
,
3
,
9
])),
(
input_2_data_hape
,
input_axes_all
,
squeeze_error
,
np
.
array
([
3
,
3
,
9
])),
(
input_3_data_shape
,
input_axes_0
,
squeeze_error
,
np
.
array
([])),
(
input_3_data_shape
,
input_axes_all
,
squeeze_error
,
np
.
array
([])),
(
input_4_data_shape
,
input_axes_0
,
squeeze_error
,
np
.
array
([
1
,
4
])),
(
input_4_data_shape
,
input_axes_all
,
squeeze_error
,
np
.
array
([
4
])),
]
self
.
test_error
=
[
(
input_1_data_shape
,
squeeze_error
),
(
input_1_data_shape
,
squeeze_many
),
(
input_3_data_shape
,
squeeze_many
),
(
input_4_data_shape
,
squeeze_many
),
]
return
def
tearDown
(
self
):
pass
def
test_axes_defined_via_tensor_input
(
self
):
Log
.
notice
(
"
\n
test_axes_defined_via_tensor_input
"
)
for
index
,
(
input_shape
,
input_axes_to_squeeze
,
squeeze_node_template
,
output_shape
,
)
in
enumerate
(
self
.
tests_axes_defined_by_input
):
test_squeeze_node
=
squeeze_node_template
test_squeeze_op
=
test_squeeze_node
.
get_operator
()
print
(
f
"
\n
Test
{
index
}
"
)
print
(
f
"
input shape :
{
input_shape
}
"
)
print
(
f
"
input axes:
{
np
.
array
(
input_axes_to_squeeze
)
}
"
)
print
(
f
"
operator :
{
test_squeeze_node
}
"
)
print
(
f
"
expected output_shape :
{
output_shape
}
"
)
test_squeeze_op
.
set_backend
(
"
cpu
"
)
test_squeeze_op
.
set_datatype
(
aidge_core
.
dtype
.
float32
)
input_values
=
np
.
ones
(
shape
=
input_shape
,
dtype
=
np
.
float32
)
output_values
=
np
.
ones
(
shape
=
output_shape
,
dtype
=
np
.
float32
)
input_data
=
aidge_core
.
Tensor
(
input_values
)
input_data
.
set_datatype
(
aidge_core
.
dtype
.
float32
)
input_data
.
set_backend
(
"
cpu
"
)
input_axes
=
aidge_core
.
Tensor
(
np
.
array
(
input_axes_to_squeeze
,
dtype
=
np
.
float32
)
)
input_axes
.
set_datatype
(
aidge_core
.
dtype
.
int8
)
input_axes
.
set_backend
(
"
cpu
"
)
test_squeeze_op
.
set_input
(
0
,
input_data
)
test_squeeze_op
.
set_input
(
1
,
input_axes
)
self
.
assertEqual
(
test_squeeze_op
.
forward_dims
(
True
),
True
)
test_squeeze_op
.
forward
()
squeeze_output
=
test_squeeze_op
.
get_output
(
0
)
npt
.
assert_array_equal
(
squeeze_output
.
dims
(),
output_shape
,
err_msg
=
f
"
SQUEEZE FAILURE : expected result differs from output size
\n\t
operator :
{
test_squeeze_node
}
\n\t
input.shape :
{
input_shape
.
shape
}
"
,
)
npt
.
assert_array_almost_equal
(
np
.
array
(
squeeze_output
,
dtype
=
np
.
float32
),
output_values
,
7
,
err_msg
=
f
"
SQUEEZE FAILURE : output tensor values differs from expected values
\n\t
operator :
{
test_squeeze_node
}
\n\t
input.shape :
{
input_shape
.
shape
}
"
,
)
# self.assertEqual(test_squeeze_op.dims_forwarded(), True, "SQUEEZE_FAILURE : dims_forwarded failed.")
return
def
test_axes_defined_via_attribute
(
self
):
Log
.
notice
(
"
\n
test_axes_defined_via_attribute
"
)
for
index
,
(
input_shape
,
squeeze_node_template
,
output_shape
)
in
enumerate
(
self
.
tests_axes_defined_by_attribute
):
test_squeeze_node
=
squeeze_node_template
test_squeeze_op
=
test_squeeze_node
.
get_operator
()
print
(
f
"
\n
Test
{
index
}
"
)
print
(
f
"
input size :
{
input_shape
.
shape
}
"
)
print
(
f
"
operator :
{
test_squeeze_node
}
"
)
print
(
f
"
expected output_shape :
{
output_shape
}
"
)
test_squeeze_node
.
get_operator
().
set_backend
(
"
cpu
"
)
input_values
=
np
.
ones
(
shape
=
input_shape
,
dtype
=
np
.
float32
)
output_values
=
np
.
ones
(
shape
=
output_shape
,
dtype
=
np
.
float32
)
input_data
=
aidge_core
.
Tensor
(
input_values
)
input_data
.
set_datatype
(
aidge_core
.
dtype
.
float32
)
input_data
.
set_backend
(
"
cpu
"
)
test_squeeze_op
.
set_input
(
0
,
input_data
)
test_squeeze_op
.
forward_dims
()
test_squeeze_op
.
forward
()
squeeze_output
=
test_squeeze_op
.
get_output
(
0
)
npt
.
assert_array_equal
(
squeeze_output
.
dims
(),
output_shape
,
err_msg
=
f
"
SQUEEZE FAILURE : expected result differs from output size
\n\t
operator :
{
test_squeeze_node
}
\n\t
input.shape :
{
input_shape
.
shape
}
"
,
)
npt
.
assert_array_almost_equal
(
np
.
array
(
squeeze_output
,
dtype
=
np
.
float32
),
output_values
,
7
,
err_msg
=
f
"
SQUEEZE FAILURE : output tensor values differs from expected values
\n\t
operator :
{
test_squeeze_node
}
\n\t
input.shape :
{
input_shape
.
shape
}
"
,
)
return
def
test_error
(
self
):
for
input_shape
,
squeeze_node_template
in
self
.
test_error
:
test_squeeze_node
=
squeeze_node_template
test_squeeze_op
=
test_squeeze_node
.
get_operator
()
input_values
=
np
.
ones
(
shape
=
input_shape
)
input_data
=
aidge_core
.
Tensor
(
input_values
)
input_data
.
set_datatype
(
aidge_core
.
dtype
.
float32
)
input_data
.
set_backend
(
"
cpu
"
)
test_squeeze_op
.
set_input
(
0
,
input_data
)
with
self
.
assertRaises
((
RuntimeError
,
AssertionError
)):
test_squeeze_op
.
forward_dims
()
test_squeeze_op
.
forward
()
return
if
__name__
==
"
__main__
"
:
unittest
.
main
()
Loading