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
4ea1c64a
Commit
4ea1c64a
authored
1 year ago
by
Olivier BICHLER
Browse files
Options
Downloads
Patches
Plain Diff
Fixed bug with setAttrPy
parent
6872857b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aidge_core/unit_tests/test_operator_binding.py
+2
-0
2 additions, 0 deletions
aidge_core/unit_tests/test_operator_binding.py
include/aidge/utils/DynamicAttributes.hpp
+10
-3
10 additions, 3 deletions
include/aidge/utils/DynamicAttributes.hpp
with
12 additions
and
3 deletions
aidge_core/unit_tests/test_operator_binding.py
+
2
−
0
View file @
4ea1c64a
...
@@ -89,6 +89,8 @@ class test_operator_binding(unittest.TestCase):
...
@@ -89,6 +89,8 @@ class test_operator_binding(unittest.TestCase):
# Check that added Python attribute is accessible in C++
# Check that added Python attribute is accessible in C++
# Return the value of an attribute named "d" of type float64 (double in C++)
# Return the value of an attribute named "d" of type float64 (double in C++)
self
.
assertEqual
(
aidge_core
.
test_DynamicAttributes_binding_check
(
attrs
),
18.56
)
self
.
assertEqual
(
aidge_core
.
test_DynamicAttributes_binding_check
(
attrs
),
18.56
)
attrs
.
set_attr
(
"
d
"
,
23.89
)
self
.
assertEqual
(
aidge_core
.
test_DynamicAttributes_binding_check
(
attrs
),
23.89
)
def
test_compute_output_dims
(
self
):
def
test_compute_output_dims
(
self
):
in_dims
=
[
25
,
25
]
in_dims
=
[
25
,
25
]
...
...
This diff is collapsed.
Click to expand it.
include/aidge/utils/DynamicAttributes.hpp
+
10
−
3
View file @
4ea1c64a
...
@@ -48,7 +48,7 @@ public:
...
@@ -48,7 +48,7 @@ public:
template
<
class
T
>
T
&
getAttr
(
const
std
::
string
&
name
)
template
<
class
T
>
T
&
getAttr
(
const
std
::
string
&
name
)
{
{
#ifdef PYBIND
#ifdef PYBIND
// If attribute does not exist in C++, it might have been created in Python
// If attribute does not exist in C++, it might have been created
or modified
in Python
auto
it
=
mAttrs
.
find
(
name
);
auto
it
=
mAttrs
.
find
(
name
);
if
(
it
==
mAttrs
.
end
())
{
if
(
it
==
mAttrs
.
end
())
{
auto
itPy
=
mAttrsPy
.
find
(
name
);
auto
itPy
=
mAttrsPy
.
find
(
name
);
...
@@ -66,7 +66,7 @@ public:
...
@@ -66,7 +66,7 @@ public:
template
<
class
T
>
const
T
&
getAttr
(
const
std
::
string
&
name
)
const
template
<
class
T
>
const
T
&
getAttr
(
const
std
::
string
&
name
)
const
{
{
#ifdef PYBIND
#ifdef PYBIND
// If attribute does not exist in C++, it might have been created in Python
// If attribute does not exist in C++, it might have been created
or modified
in Python
auto
it
=
mAttrs
.
find
(
name
);
auto
it
=
mAttrs
.
find
(
name
);
if
(
it
==
mAttrs
.
end
())
{
if
(
it
==
mAttrs
.
end
())
{
auto
itPy
=
mAttrsPy
.
find
(
name
);
auto
itPy
=
mAttrsPy
.
find
(
name
);
...
@@ -129,7 +129,11 @@ public:
...
@@ -129,7 +129,11 @@ public:
#ifdef PYBIND
#ifdef PYBIND
void
addAttrPy
(
const
std
::
string
&
name
,
py
::
object
&&
value
)
void
addAttrPy
(
const
std
::
string
&
name
,
py
::
object
&&
value
)
{
{
mAttrsPy
.
emplace
(
std
::
make_pair
(
name
,
value
));
auto
it
=
mAttrs
.
find
(
name
);
assert
(
it
==
mAttrs
.
end
()
&&
"attribute already exists"
);
const
auto
&
res
=
mAttrsPy
.
emplace
(
std
::
make_pair
(
name
,
value
));
assert
(
res
.
second
&&
"attribute already exists"
);
}
}
void
setAttrPy
(
const
std
::
string
&
name
,
py
::
object
&&
value
)
void
setAttrPy
(
const
std
::
string
&
name
,
py
::
object
&&
value
)
...
@@ -137,6 +141,9 @@ public:
...
@@ -137,6 +141,9 @@ public:
auto
resPy
=
mAttrsPy
.
emplace
(
std
::
make_pair
(
name
,
value
));
auto
resPy
=
mAttrsPy
.
emplace
(
std
::
make_pair
(
name
,
value
));
if
(
!
resPy
.
second
)
if
(
!
resPy
.
second
)
resPy
.
first
->
second
=
std
::
move
(
value
);
resPy
.
first
->
second
=
std
::
move
(
value
);
// Force getAttr() to take attribute value from mAttrsPy and update mAttrs
mAttrs
.
erase
(
name
);
}
}
#endif
#endif
...
...
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