Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DP3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mattia Mancini
DP3
Commits
9aa048ad
Commit
9aa048ad
authored
1 year ago
by
Bas van der Tol
Browse files
Options
Downloads
Patches
Plain Diff
Extend python interface to ParameterSet
parent
5f95d980
No related branches found
No related tags found
Loading
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pythondp3/parameterset.cc
+16
-1
16 additions, 1 deletion
pythondp3/parameterset.cc
pythondp3/test/unit/CMakeLists.txt
+8
-2
8 additions, 2 deletions
pythondp3/test/unit/CMakeLists.txt
pythondp3/test/unit/tPyParameterSet.py
+63
-0
63 additions, 0 deletions
pythondp3/test/unit/tPyParameterSet.py
with
87 additions
and
3 deletions
pythondp3/parameterset.cc
+
16
−
1
View file @
9aa048ad
...
...
@@ -3,10 +3,12 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include
<pybind11/pybind11.h>
#include
<pybind11/stl.h>
#include
"../common/ParameterSet.h"
using
dp3
::
common
::
ParameterSet
;
using
dp3
::
common
::
ParameterValue
;
namespace
py
=
pybind11
;
...
...
@@ -57,7 +59,20 @@ PYBIND11_MODULE(parameterset, m) {
ParameterSet
::
getString
)
.
def
(
"get_string"
,
(
std
::
string
(
ParameterSet
::*
)(
const
std
::
string
&
,
const
std
::
string
&
)
const
)
&
ParameterSet
::
getString
);
ParameterSet
::
getString
)
.
def
(
"__contains__"
,
&
ParameterSet
::
isDefined
)
.
def
(
"__getitem__"
,
&
ParameterSet
::
get
);
py
::
class_
<
ParameterValue
,
std
::
shared_ptr
<
ParameterValue
>
// holder type
>
(
m
,
"ParameterValue"
)
.
def
(
"__str__"
,
&
ParameterValue
::
getString
)
.
def
(
"__int__"
,
&
ParameterValue
::
getInt
)
.
def
(
"__float__"
,
&
ParameterValue
::
getDouble
)
.
def
(
"__bool__"
,
&
ParameterValue
::
getBool
)
.
def
(
"__iter__"
,
[](
const
ParameterValue
&
v
)
{
return
py
::
cast
(
v
.
getVector
()).
attr
(
"__iter__"
)();
});
}
}
// namespace pythondp3
...
...
This diff is collapsed.
Click to expand it.
pythondp3/test/unit/CMakeLists.txt
+
8
−
2
View file @
9aa048ad
...
...
@@ -6,6 +6,12 @@
if
(
"
${
CMAKE_CXX_FLAGS
}
"
MATCHES
"-fsanitize=address"
)
message
(
STATUS
"The Python tests do not work with address sanitizer enabled."
)
else
()
add_python_tests
(
tPyDpBuffer tPyDpInfo tPyFields tPyFitters tPyStep
tQueueOutput
)
add_python_tests
(
tPyDpBuffer
tPyDpInfo
tPyFields
tPyFitters
tPyParameterSet
tPyStep
tQueueOutput
)
endif
()
This diff is collapsed.
Click to expand it.
pythondp3/test/unit/tPyParameterSet.py
0 → 100644
+
63
−
0
View file @
9aa048ad
# Copyright (C) 2024 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: GPL-3.0-or-later
"""
These tests are checking that the python bindings for the ParameterSet class
behave correctly.
Script can be invoked in two ways:
- as standalone from the build/pythondp3/test/unit directory,
using `pytest source/tPyParameterSet.py` (extended with pytest options of your choice)
- using ctest, see pythondp3/test/unit/CMakeLists.txt
"""
import
sys
# Append current directory to system path in order to import testconfig
sys
.
path
.
append
(
"
.
"
)
import
testconfig
as
tcf
sys
.
path
.
insert
(
0
,
tcf
.
PYTHONDIR
)
try
:
"
The import may fail while running pytest --collect-only
"
import
dp3.parameterset
except
ImportError
:
pass
def
test_parameter_set_magic
():
"""
Test the magic (double underscore) member functions of ParamterSet and ParameterValue
Tests the member functions __contains__ and __getitem__ of ParameterSet, and
__bool__, __float__, __int__, __iter__ and __str__ of ParameterValue
"""
ps
=
dp3
.
parameterset
.
ParameterSet
()
ps
.
add
(
"
prefix.somekey
"
,
"
42
"
)
ps
.
add
(
"
prefix.vecint
"
,
"
[1,2,3]
"
)
ps
.
add
(
"
prefix.vecfloat
"
,
"
[2.71828, 3.14159]
"
)
ps
.
add
(
"
prefix.vecbool
"
,
"
[T, F, True, False, 1, 0]
"
)
ps
.
add
(
"
prefix.vecstr
"
,
"
[CS001,CS002,CS003]
"
)
ps
.
add
(
"
prefix.vecvecstr
"
,
"
[[CS001,CS002],[CS003]]
"
)
assert
"
prefix.not_existent_key
"
not
in
ps
assert
"
prefix.somekey
"
in
ps
assert
[
int
(
v
)
for
v
in
ps
[
"
prefix.vecint
"
]]
==
[
1
,
2
,
3
]
assert
[
str
(
v
)
for
v
in
ps
[
"
prefix.vecstr
"
]]
==
[
"
CS001
"
,
"
CS002
"
,
"
CS003
"
]
assert
[
float
(
v
)
for
v
in
ps
[
"
prefix.vecfloat
"
]]
==
[
2.71828
,
3.14159
]
assert
[
bool
(
v
)
for
v
in
ps
[
"
prefix.vecbool
"
]]
==
[
True
,
False
,
True
,
False
,
True
,
False
,
]
assert
[[
str
(
vv
)
for
vv
in
v
]
for
v
in
ps
[
"
prefix.vecvecstr
"
]]
==
[
[
"
CS001
"
,
"
CS002
"
],
[
"
CS003
"
],
]
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