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
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
Cyril Moineau
aidge_core
Commits
450f6c80
Commit
450f6c80
authored
1 year ago
by
Maxence Naud
Browse files
Options
Downloads
Patches
Plain Diff
Update Testing.hpp and Testing.cpp according to Aidge coding rules
parent
9d66287d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/aidge/graph/Testing.hpp
+9
-8
9 additions, 8 deletions
include/aidge/graph/Testing.hpp
src/graph/Testing.cpp
+22
-12
22 additions, 12 deletions
src/graph/Testing.cpp
with
31 additions
and
20 deletions
include/aidge/graph/Testing.hpp
+
9
−
8
View file @
450f6c80
...
@@ -12,11 +12,11 @@
...
@@ -12,11 +12,11 @@
#ifndef AIDGE_CORE_GRAPH_TESTING_H_
#ifndef AIDGE_CORE_GRAPH_TESTING_H_
#define AIDGE_CORE_GRAPH_TESTING_H_
#define AIDGE_CORE_GRAPH_TESTING_H_
#include
<cstddef>
#include
<vector>
#include
<vector>
#include
<set>
#include
<set>
#include
<random>
#include
<random>
// std::mt19937::result_type
#include
<algorithm>
#include
<utility>
// std::pair
#include
<utility>
#include
"aidge/graph/Node.hpp"
#include
"aidge/graph/Node.hpp"
#include
"aidge/utils/Types.h"
#include
"aidge/utils/Types.h"
...
@@ -31,11 +31,11 @@ struct RandomGraph {
...
@@ -31,11 +31,11 @@ struct RandomGraph {
/// @brief Connection density (between 0 and 1)
/// @brief Connection density (between 0 and 1)
float
density
=
0.5
;
float
density
=
0.5
;
/// @brief Max number of inputs per node (regardless if they are connected or not)
/// @brief Max number of inputs per node (regardless if they are connected or not)
size_t
maxIn
=
5
;
std
::
size_t
maxIn
=
5
;
/// @brief Average number of inputs per node (regardless if they are connected or not)
/// @brief Average number of inputs per node (regardless if they are connected or not)
float
avgIn
=
1.5
;
float
avgIn
=
1.5
;
/// @brief Max number of outputs per node (regardless if they are connected or not)
/// @brief Max number of outputs per node (regardless if they are connected or not)
size_t
maxOut
=
2
;
std
::
size_t
maxOut
=
2
;
/// @brief Average number of outputs per node (regardless if they are connected or not)
/// @brief Average number of outputs per node (regardless if they are connected or not)
float
avgOut
=
1.1
;
float
avgOut
=
1.1
;
/// @brief List of node types that should be generated in the graph (as GenericOperator)
/// @brief List of node types that should be generated in the graph (as GenericOperator)
...
@@ -47,11 +47,11 @@ struct RandomGraph {
...
@@ -47,11 +47,11 @@ struct RandomGraph {
/**
/**
* Generate a DAG according to the parameters of the class.
* Generate a DAG according to the parameters of the class.
* @param seed Random seed. For an identical seed, an identical topology is
* @param seed Random seed. For an identical seed, an identical topology is
* generated, but with a random node ordering in the return set of nodes.
* generated, but with a random node ordering in the return set of nodes.
* @param nbNodes Number of nodes to generate.
* @param nbNodes Number of nodes to generate.
*/
*/
std
::
pair
<
NodePtr
,
std
::
set
<
NodePtr
>>
gen
(
std
::
mt19937
::
result_type
seed
,
size_t
nbNodes
)
const
;
std
::
pair
<
NodePtr
,
std
::
set
<
NodePtr
>>
gen
(
std
::
mt19937
::
result_type
seed
,
std
::
size_t
nbNodes
)
const
;
};
};
std
::
string
nodePtrToType
(
NodePtr
node
);
std
::
string
nodePtrToType
(
NodePtr
node
);
...
@@ -61,6 +61,7 @@ std::set<std::string> nodePtrTo(const std::set<NodePtr>& nodes,
...
@@ -61,6 +61,7 @@ std::set<std::string> nodePtrTo(const std::set<NodePtr>& nodes,
std
::
vector
<
std
::
pair
<
std
::
string
,
IOIndex_t
>>
nodePtrTo
(
std
::
vector
<
std
::
pair
<
std
::
string
,
IOIndex_t
>>
nodePtrTo
(
const
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>&
nodes
,
const
std
::
vector
<
std
::
pair
<
NodePtr
,
IOIndex_t
>>&
nodes
,
std
::
string
(
*
nodeTo
)(
NodePtr
)
=
nodePtrToType
);
std
::
string
(
*
nodeTo
)(
NodePtr
)
=
nodePtrToType
);
}
}
// namespace Aidge
#endif
/* AIDGE_CORE_GRAPH_TESTING_H_ */
#endif
/* AIDGE_CORE_GRAPH_TESTING_H_ */
This diff is collapsed.
Click to expand it.
src/graph/Testing.cpp
+
22
−
12
View file @
450f6c80
...
@@ -9,46 +9,56 @@
...
@@ -9,46 +9,56 @@
*
*
********************************************************************************/
********************************************************************************/
#include
<algorithm>
// std::shuffle, std::transform
#include
<cstddef>
#include
<memory>
#include
<numeric>
// std::iota
#include
<random>
// std::binomial_distribution, std::mt19937, std::discrete_distribution
#include
<string>
#include
<utility>
// std::pair
#include
<vector>
#include
"aidge/graph/Testing.hpp"
#include
"aidge/graph/Testing.hpp"
#include
"aidge/operator/GenericOperator.hpp"
#include
"aidge/operator/GenericOperator.hpp"
#include
"aidge/utils/Types.h"
std
::
pair
<
Aidge
::
NodePtr
,
std
::
set
<
Aidge
::
NodePtr
>>
Aidge
::
RandomGraph
::
gen
(
std
::
mt19937
::
result_type
seed
,
size_t
nbNodes
)
const
{
std
::
pair
<
Aidge
::
NodePtr
,
std
::
set
<
Aidge
::
NodePtr
>>
Aidge
::
RandomGraph
::
gen
(
std
::
mt19937
::
result_type
seed
,
std
::
size_t
nbNodes
)
const
{
std
::
mt19937
gen
(
seed
);
std
::
mt19937
gen
(
seed
);
std
::
binomial_distribution
<>
dIn
(
maxIn
-
1
,
avgIn
/
maxIn
);
std
::
binomial_distribution
<>
dIn
(
maxIn
-
1
,
avgIn
/
maxIn
);
std
::
binomial_distribution
<>
dOut
(
maxOut
-
1
,
avgOut
/
maxOut
);
std
::
binomial_distribution
<>
dOut
(
maxOut
-
1
,
avgOut
/
maxOut
);
std
::
binomial_distribution
<>
dLink
(
1
,
density
);
std
::
binomial_distribution
<>
dLink
(
1
,
density
);
std
::
discrete_distribution
<>
dType
(
typesWeights
.
begin
(),
typesWeights
.
end
());
std
::
discrete_distribution
<>
dType
(
typesWeights
.
begin
(),
typesWeights
.
end
());
std
::
vector
<
std
::
pair
<
int
,
in
t
>>
nbIOs
;
std
::
vector
<
std
::
pair
<
IOIndex_t
,
IOIndex_
t
>>
nbIOs
;
std
::
vector
<
std
::
string
>
nodesType
;
std
::
vector
<
std
::
string
>
nodesType
;
for
(
size_t
i
=
0
;
i
<
nbNodes
;
++
i
)
{
for
(
std
::
size_t
i
=
0
;
i
<
nbNodes
;
++
i
)
{
const
auto
nbIn
=
1
+
dIn
(
gen
);
const
auto
nbIn
=
1
+
dIn
(
gen
);
nbIOs
.
push_back
(
std
::
make_pair
(
nbIn
,
1
+
dOut
(
gen
)));
nbIOs
.
push_back
(
std
::
make_pair
(
nbIn
,
1
+
dOut
(
gen
)));
nodesType
.
push_back
(
types
[
dType
(
gen
)]);
nodesType
.
push_back
(
types
[
dType
(
gen
)]);
}
}
std
::
vector
<
in
t
>
nodesSeq
(
nbNodes
);
std
::
vector
<
std
::
size_
t
>
nodesSeq
(
nbNodes
);
std
::
iota
(
nodesSeq
.
begin
(),
nodesSeq
.
end
(),
0
);
std
::
iota
(
nodesSeq
.
begin
(),
nodesSeq
.
end
(),
static_cast
<
std
::
size_t
>
(
0
)
);
// Don't use gen or seed here, must be different each time!
// Don't use gen or seed here, must be different each time!
std
::
shuffle
(
nodesSeq
.
begin
(),
nodesSeq
.
end
(),
std
::
default_random_engine
(
std
::
random_device
{}()));
std
::
shuffle
(
nodesSeq
.
begin
(),
nodesSeq
.
end
(),
std
::
default_random_engine
(
std
::
random_device
{}()));
std
::
vector
<
NodePtr
>
nodes
(
nbNodes
,
nullptr
);
std
::
vector
<
NodePtr
>
nodes
(
nbNodes
,
nullptr
);
for
(
auto
idx
:
nodesSeq
)
{
for
(
auto
idx
:
nodesSeq
)
{
const
std
::
string
name
=
nodesType
[
idx
]
+
std
::
to_string
(
idx
);
const
std
::
string
name
=
nodesType
[
idx
]
+
std
::
to_string
(
idx
);
nodes
[
idx
]
=
GenericOperator
(
nodesType
[
idx
]
.
c_str
()
,
nbIOs
[
idx
].
first
,
0
,
nbIOs
[
idx
].
second
,
name
.
c_str
()
);
nodes
[
idx
]
=
GenericOperator
(
nodesType
[
idx
],
nbIOs
[
idx
].
first
,
0
,
nbIOs
[
idx
].
second
,
name
);
}
}
for
(
size_t
i
=
0
;
i
<
nbNodes
;
++
i
)
{
for
(
std
::
size_t
i
=
0
;
i
<
nbNodes
;
++
i
)
{
for
(
size_t
j
=
(
acyclic
)
?
i
+
1
:
0
;
j
<
nbNodes
;
++
j
)
{
for
(
std
::
size_t
j
=
(
acyclic
)
?
i
+
1
:
0
;
j
<
nbNodes
;
++
j
)
{
if
(
i
==
j
)
{
if
(
i
==
j
)
{
// Do not connected node to itself in case of cyclic graph!
// Do not connected node to itself in case of cyclic graph!
continue
;
continue
;
}
}
for
(
size_t
outId
=
0
;
outId
<
nodes
[
i
]
->
nbOutputs
();
++
outId
)
{
for
(
std
::
size_t
outId
=
0
;
outId
<
nodes
[
i
]
->
nbOutputs
();
++
outId
)
{
for
(
size_t
inId
=
0
;
inId
<
nodes
[
j
]
->
nbInputs
();
++
inId
)
{
for
(
std
::
size_t
inId
=
0
;
inId
<
nodes
[
j
]
->
nbInputs
();
++
inId
)
{
if
(
dLink
(
gen
))
{
if
(
dLink
(
gen
))
{
// Warning: connections can be set multiple time for the
// Warning: connections can be set multiple time for the
// same node input! In this case, the previous connection
// same node input! In this case, the previous connection
// is overwritten. This is the expected behavior.
// is overwritten. This is the expected behavior.
nodes
[
i
]
->
addChild
(
nodes
[
j
],
outId
,
inId
);
nodes
[
i
]
->
addChild
(
nodes
[
j
],
outId
,
inId
);
...
@@ -82,7 +92,7 @@ std::pair<Aidge::NodePtr, std::set<Aidge::NodePtr>> Aidge::RandomGraph::gen(std:
...
@@ -82,7 +92,7 @@ std::pair<Aidge::NodePtr, std::set<Aidge::NodePtr>> Aidge::RandomGraph::gen(std:
NodePtr
rootNode
=
nullptr
;
NodePtr
rootNode
=
nullptr
;
std
::
set
<
NodePtr
>
nodesSet
;
std
::
set
<
NodePtr
>
nodesSet
;
for
(
size_t
i
=
0
;
i
<
nbNodes
;
++
i
)
{
for
(
std
::
size_t
i
=
0
;
i
<
nbNodes
;
++
i
)
{
if
(
nodes
[
i
]
->
type
()
!=
omitType
)
{
if
(
nodes
[
i
]
->
type
()
!=
omitType
)
{
if
(
rootNode
==
nullptr
)
{
if
(
rootNode
==
nullptr
)
{
rootNode
=
nodes
[
i
];
rootNode
=
nodes
[
i
];
...
...
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