Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_backend_cpu
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_backend_cpu
Commits
e2adb2e4
Commit
e2adb2e4
authored
1 month ago
by
Houssem ROUIS
Committed by
Maxence Naud
3 weeks ago
Browse files
Options
Downloads
Patches
Plain Diff
separate fwdDims tests section from fwd section
parent
54988d11
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unit_tests/operator/Test_EqualImpl.cpp
+72
-73
72 additions, 73 deletions
unit_tests/operator/Test_EqualImpl.cpp
with
72 additions
and
73 deletions
unit_tests/operator/Test_EqualImpl.cpp
+
72
−
73
View file @
e2adb2e4
...
...
@@ -19,86 +19,85 @@
using
namespace
Aidge
;
TEST_CASE
(
"[cpu/operator] Equal(forward)"
,
"[Equal][CPU]"
)
{
SECTION
(
"ForwardDims"
)
{
constexpr
std
::
uint16_t
NBTRIALS
=
10
;
// Create a random number generator
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
uniform_real_distribution
<
float
>
valueDist
(
0.1
f
,
1.1
f
);
// Random float distribution between 0 and 1
std
::
uniform_int_distribution
<
std
::
size_t
>
dimSizeDist
(
std
::
size_t
(
2
),
std
::
size_t
(
10
));
std
::
uniform_int_distribution
<
std
::
size_t
>
nbDimsDist
(
std
::
size_t
(
1
),
std
::
size_t
(
5
));
std
::
uniform_int_distribution
<
int
>
boolDist
(
0
,
1
);
SECTION
(
"Same dimensions"
)
{
for
(
std
::
uint16_t
trial
=
0
;
trial
<
NBTRIALS
;
++
trial
)
{
DimSize_t
nbDims
=
nbDimsDist
(
gen
);
std
::
vector
<
DimSize_t
>
dims
(
nbDims
);
for
(
std
::
size_t
i
=
0
;
i
<
nbDims
;
i
++
)
{
dims
[
i
]
=
dimSizeDist
(
gen
);
}
std
::
shared_ptr
<
Tensor
>
myInput1
=
std
::
make_shared
<
Tensor
>
(
dims
);
myInput1
->
setBackend
(
"cpu"
);
myInput1
->
setDataType
(
DataType
::
Float32
);
myInput1
->
zeros
();
std
::
shared_ptr
<
Tensor
>
myInput2
=
std
::
make_shared
<
Tensor
>
(
dims
);
myInput2
->
setBackend
(
"cpu"
);
myInput2
->
setDataType
(
DataType
::
Float32
);
myInput2
->
zeros
();
std
::
shared_ptr
<
Node
>
myEqual
=
Equal
();
auto
op
=
std
::
static_pointer_cast
<
OperatorTensor
>
(
myEqual
->
getOperator
());
op
->
associateInput
(
0
,
myInput1
);
op
->
associateInput
(
1
,
myInput2
);
op
->
setDataType
(
DataType
::
Float32
);
op
->
setBackend
(
"cpu"
);
op
->
forwardDims
();
const
auto
outputDims
=
op
->
getOutput
(
0
)
->
dims
();
REQUIRE
(
outputDims
==
dims
);
TEST_CASE
(
"[cpu/operator] Equal(forwardDims)"
,
"[Equal][CPU]"
)
{
constexpr
std
::
uint16_t
NBTRIALS
=
10
;
// Create a random number generator
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
uniform_real_distribution
<
float
>
valueDist
(
0.1
f
,
1.1
f
);
// Random float distribution between 0 and 1
std
::
uniform_int_distribution
<
std
::
size_t
>
dimSizeDist
(
std
::
size_t
(
2
),
std
::
size_t
(
10
));
std
::
uniform_int_distribution
<
std
::
size_t
>
nbDimsDist
(
std
::
size_t
(
1
),
std
::
size_t
(
5
));
std
::
uniform_int_distribution
<
int
>
boolDist
(
0
,
1
);
SECTION
(
"Same dimensions"
)
{
for
(
std
::
uint16_t
trial
=
0
;
trial
<
NBTRIALS
;
++
trial
)
{
DimSize_t
nbDims
=
nbDimsDist
(
gen
);
std
::
vector
<
DimSize_t
>
dims
(
nbDims
);
for
(
std
::
size_t
i
=
0
;
i
<
nbDims
;
i
++
)
{
dims
[
i
]
=
dimSizeDist
(
gen
);
}
std
::
shared_ptr
<
Tensor
>
myInput1
=
std
::
make_shared
<
Tensor
>
(
dims
);
myInput1
->
setBackend
(
"cpu"
);
myInput1
->
setDataType
(
DataType
::
Float32
);
myInput1
->
zeros
();
std
::
shared_ptr
<
Tensor
>
myInput2
=
std
::
make_shared
<
Tensor
>
(
dims
);
myInput2
->
setBackend
(
"cpu"
);
myInput2
->
setDataType
(
DataType
::
Float32
);
myInput2
->
zeros
();
std
::
shared_ptr
<
Node
>
myEqual
=
Equal
();
auto
op
=
std
::
static_pointer_cast
<
OperatorTensor
>
(
myEqual
->
getOperator
());
op
->
associateInput
(
0
,
myInput1
);
op
->
associateInput
(
1
,
myInput2
);
op
->
setDataType
(
DataType
::
Float32
);
op
->
setBackend
(
"cpu"
);
op
->
forwardDims
();
const
auto
outputDims
=
op
->
getOutput
(
0
)
->
dims
();
REQUIRE
(
outputDims
==
dims
);
}
SECTION
(
"Broadcasting"
)
{
for
(
std
::
uint16_t
trial
=
0
;
trial
<
NBTRIALS
;
++
trial
)
{
DimSize_t
nbDims
=
nbDimsDist
(
gen
);
std
::
vector
<
DimSize_t
>
dims1
(
nbDims
,
1
);
std
::
vector
<
DimSize_t
>
dims2
(
nbDims
,
1
);
std
::
vector
<
DimSize_t
>
expectedOutDims
;
for
(
std
::
size_t
i
=
0
;
i
<
nbDims
;
i
++
)
{
DimSize_t
dim
=
dimSizeDist
(
gen
);
if
(
boolDist
(
gen
))
{
dims1
[
i
]
=
dim
;
}
if
(
boolDist
(
gen
))
{
dims2
[
i
]
=
dim
;
}
expectedOutDims
.
push_back
(
std
::
max
(
dims1
[
i
],
dims2
[
i
]));
}
SECTION
(
"Broadcasting"
)
{
for
(
std
::
uint16_t
trial
=
0
;
trial
<
NBTRIALS
;
++
trial
)
{
DimSize_t
nbDims
=
nbDimsDist
(
gen
);
std
::
vector
<
DimSize_t
>
dims1
(
nbDims
,
1
);
std
::
vector
<
DimSize_t
>
dims2
(
nbDims
,
1
);
std
::
vector
<
DimSize_t
>
expectedOutDims
;
for
(
std
::
size_t
i
=
0
;
i
<
nbDims
;
i
++
)
{
DimSize_t
dim
=
dimSizeDist
(
gen
);
if
(
boolDist
(
gen
))
{
dims1
[
i
]
=
dim
;
}
if
(
boolDist
(
gen
))
{
dims2
[
i
]
=
dim
;
}
expectedOutDims
.
push_back
(
std
::
max
(
dims1
[
i
],
dims2
[
i
]));
}
std
::
shared_ptr
<
Tensor
>
myInput1
=
std
::
make_shared
<
Tensor
>
(
dims1
);
myInput1
->
setBackend
(
"cpu"
);
myInput1
->
setDataType
(
DataType
::
Float32
);
myInput1
->
zeros
();
std
::
shared_ptr
<
Tensor
>
myInput2
=
std
::
make_shared
<
Tensor
>
(
dims2
);
myInput2
->
setBackend
(
"cpu"
);
myInput2
->
setDataType
(
DataType
::
Float32
);
myInput2
->
zeros
();
std
::
shared_ptr
<
Node
>
myEqual
=
Equal
();
auto
op
=
std
::
static_pointer_cast
<
OperatorTensor
>
(
myEqual
->
getOperator
());
op
->
associateInput
(
0
,
myInput1
);
op
->
associateInput
(
1
,
myInput2
);
op
->
setDataType
(
DataType
::
Float32
);
op
->
setBackend
(
"cpu"
);
op
->
forwardDims
();
const
auto
outputDims
=
op
->
getOutput
(
0
)
->
dims
();
REQUIRE
(
outputDims
==
expectedOutDims
);
}
std
::
shared_ptr
<
Tensor
>
myInput1
=
std
::
make_shared
<
Tensor
>
(
dims1
);
myInput1
->
setBackend
(
"cpu"
);
myInput1
->
setDataType
(
DataType
::
Float32
);
myInput1
->
zeros
();
std
::
shared_ptr
<
Tensor
>
myInput2
=
std
::
make_shared
<
Tensor
>
(
dims2
);
myInput2
->
setBackend
(
"cpu"
);
myInput2
->
setDataType
(
DataType
::
Float32
);
myInput2
->
zeros
();
std
::
shared_ptr
<
Node
>
myEqual
=
Equal
();
auto
op
=
std
::
static_pointer_cast
<
OperatorTensor
>
(
myEqual
->
getOperator
());
op
->
associateInput
(
0
,
myInput1
);
op
->
associateInput
(
1
,
myInput2
);
op
->
setDataType
(
DataType
::
Float32
);
op
->
setBackend
(
"cpu"
);
op
->
forwardDims
();
const
auto
outputDims
=
op
->
getOutput
(
0
)
->
dims
();
REQUIRE
(
outputDims
==
expectedOutDims
);
}
}
}
TEST_CASE
(
"[cpu/operator] Equal(forward)"
,
"[Equal][CPU]"
)
{
SECTION
(
"Same size inputs"
)
{
std
::
shared_ptr
<
Tensor
>
input1
=
std
::
make_shared
<
Tensor
>
(
Array4D
<
int
,
3
,
3
,
3
,
2
>
{
{
//
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment