Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
mlz
BornAgain
Commits
a1cfe50c
Commit
a1cfe50c
authored
1 year ago
by
AlQuemist
Browse files
Options
Downloads
Patches
Plain Diff
Add Unit.PyBinding.Embedded.PyInterpreterNumpyTest
parent
a3d2b5d3
No related branches found
No related tags found
1 merge request
!2274
PyCore tests; rm old Python API
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tests/Unit/PyBinding/Embedded.cpp
+24
-12
24 additions, 12 deletions
Tests/Unit/PyBinding/Embedded.cpp
with
24 additions
and
12 deletions
Tests/Unit/PyBinding/Embedded.cpp
+
24
−
12
View file @
a1cfe50c
...
...
@@ -11,15 +11,12 @@
//
// ************************************************************************************************
//#include "BABuild.h"
#include
"PyCore/Embed/PyInterpreter.h"
#include
"PyCore/Embed/PyObjectPtr.h"
#include
"PyCore/Embed/WithNumpy.h"
#include
"PyCore/Sample/ImportMultiLayer.h"
#include
"Tests/GTestWrapper/google_test.h"
#include
<vector>
#include
<string>
#include
<vector>
//! Importing numpy and accessing its version string.
...
...
@@ -29,18 +26,35 @@ TEST(Embedded, PyInterpreterTest)
PyInterpreter
::
initialize
();
EXPECT_TRUE
(
PyInterpreter
::
isInitialized
());
PyInterpreter
::
Numpy
::
initialize
();
EXPECT_TRUE
(
PyInterpreter
::
Numpy
::
isInitialized
());
// add Python path
PyInterpreter
::
addPythonPath
(
"/Some/Extra/Python/Path/"
);
EXPECT_FALSE
(
PyInterpreter
::
checkError
());
// import Numpy
PyObjectPtr
numpy_module
=
PyInterpreter
::
import
(
"numpy"
);
EXPECT_TRUE
(
numpy_module
.
valid
());
// get runtime info
std
::
string
runtime_info
=
PyInterpreter
::
runtimeInfo
();
std
::
cout
<<
"Python runtime info:
\n
"
<<
runtime_info
<<
std
::
endl
;
// set Python path
PyInterpreter
::
setPythonPath
(
"/Some/Extra/Python/Path/"
);
}
TEST
(
Embedded
,
PyInterpreterNumpyTest
)
{
// initialize Python interpreter
PyInterpreter
::
initialize
();
EXPECT_TRUE
(
PyInterpreter
::
isInitialized
());
PyInterpreter
::
Numpy
::
initialize
();
EXPECT_TRUE
(
PyInterpreter
::
Numpy
::
isInitialized
());
// import Numpy
PyObjectPtr
numpy_module
=
PyInterpreter
::
import
(
"numpy"
);
EXPECT_TRUE
(
numpy_module
.
valid
());
// initialize Numpy
PyInterpreter
::
Numpy
::
initialize
();
EXPECT_TRUE
(
PyInterpreter
::
Numpy
::
isInitialized
());
...
...
@@ -51,7 +65,8 @@ TEST(Embedded, PyInterpreterTest)
for
(
int
ii
=
0
;
ii
<
a_size
;
++
ii
)
c_array
[
ii
]
=
ii
+
1
;
PyObjectPtr
np_array1d
=
PyInterpreter
::
Numpy
::
createArray1DfromC
(
c_array
,
static_cast
<
PyInterpreter
::
Numpy
::
np_size_t
>
(
a_size
));
PyObjectPtr
np_array1d
=
PyInterpreter
::
Numpy
::
createArray1DfromC
(
c_array
,
static_cast
<
PyInterpreter
::
Numpy
::
np_size_t
>
(
a_size
));
EXPECT_TRUE
(
np_array1d
.
valid
());
PyInterpreter
::
Numpy
::
np_size_t
dims
[
2
]
=
{
n_rows
,
n_cols
};
...
...
@@ -68,7 +83,4 @@ TEST(Embedded, PyInterpreterTest)
std
::
vector
<
std
::
size_t
>
dimensions
{
1
,
2
,
3
};
PyObjectPtr
np_arrayNd
=
PyInterpreter
::
Numpy
::
arrayND
(
dimensions
);
EXPECT_TRUE
(
np_arrayNd
.
valid
());
// set Python path
PyInterpreter
::
setPythonPath
(
"/Some/Extra/Python/Path/"
);
}
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