Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
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
Model registry
Operate
Environments
Monitor
Incidents
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
Markus Holzer
pystencils
Commits
e90b0d55
Commit
e90b0d55
authored
2 years ago
by
Markus Holzer
Browse files
Options
Downloads
Patches
Plain Diff
Clean up
parent
6f9648ee
No related branches found
No related tags found
No related merge requests found
Pipeline
#47298
passed
2 years ago
Stage: pretest
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pystencils/config.py
+14
-13
14 additions, 13 deletions
pystencils/config.py
pystencils_tests/test_config.py
+12
-0
12 additions, 0 deletions
pystencils_tests/test_config.py
with
26 additions
and
13 deletions
pystencils/config.py
+
14
−
13
View file @
e90b0d55
...
...
@@ -139,6 +139,14 @@ class CreateKernelConfig:
def
__call__
(
self
):
return
BasicType
(
self
.
dt
)
def
_check_type
(
self
,
dtype_to_check
):
if
isinstance
(
dtype_to_check
,
str
)
and
(
dtype_to_check
==
'
float
'
or
dtype_to_check
==
'
int
'
):
self
.
_typing_error
()
if
isinstance
(
dtype_to_check
,
type
)
and
not
hasattr
(
dtype_to_check
,
"
dtype
"
):
# NumPy-types are also of type 'type'. However, they have more properties
self
.
_typing_error
()
@staticmethod
def
_typing_error
():
raise
ValueError
(
"
It is not possible to use python types (float, int) for datatypes because these
"
...
...
@@ -163,30 +171,23 @@ class CreateKernelConfig:
# Normalise data types
for
dtype
in
[
self
.
data_type
,
self
.
default_number_float
,
self
.
default_number_int
]:
if
isinstance
(
dtype
,
str
)
and
(
dtype
==
'
float
'
or
dtype
==
'
int
'
):
self
.
_typing_error
()
if
isinstance
(
dtype
,
type
):
# NumPy-types are also of type 'type'. However, they have more properties
if
not
hasattr
(
dtype
,
"
dtype
"
):
self
.
_typing_error
()
self
.
_check_type
(
dtype
)
if
not
isinstance
(
self
.
data_type
,
dict
):
dt
=
copy
(
self
.
data_type
)
# The copy is necessary because BasicType has sympy shinanigans
self
.
data_type
=
defaultdict
(
self
.
DataTypeFactory
(
dt
))
if
isinstance
(
self
.
data_type
,
dict
)
and
not
isinstance
(
self
.
data_type
,
defaultdict
):
if
any
(
isinstance
(
dtype
,
str
)
and
(
dtype
==
'
float
'
or
dtype
==
'
int
'
)
for
dtype
in
self
.
data_type
.
values
()):
self
.
_typing_error
()
for
dtype
in
self
.
data_type
.
values
():
self
.
_check_type
(
dtype
)
if
any
(
isinstance
(
dtype
,
type
)
and
not
hasattr
(
dtype
,
"
dtype
"
)
for
dtype
in
self
.
data_type
.
values
()):
self
.
_typing_error
()
dt
=
collate_types
([
BasicType
(
dtype
)
for
dtype
in
self
.
data_type
.
values
()])
dtype_dict
=
self
.
data_type
self
.
data_type
=
defaultdict
(
self
.
DataTypeFactory
(
dt
),
dtype_dict
)
assert
isinstance
(
self
.
data_type
,
defaultdict
),
"
At this point data_type must be a defaultdict!
"
self
.
_check_type
(
self
.
data_type
.
default_factory
())
if
self
.
default_number_float
is
None
:
self
.
default_number_float
=
self
.
data_type
.
default_factory
()
...
...
This diff is collapsed.
Click to expand it.
pystencils_tests/test_config.py
+
12
−
0
View file @
e90b0d55
...
...
@@ -88,3 +88,15 @@ def test_config_python_types5():
def
test_config_python_types6
():
with
pytest
.
raises
(
ValueError
):
CreateKernelConfig
(
default_number_float
=
"
float
"
)
def
test_config_python_types7
():
dtype
=
defaultdict
(
lambda
:
'
float
'
,
{
'
a
'
:
np
.
float64
,
'
b
'
:
np
.
int64
})
with
pytest
.
raises
(
ValueError
):
CreateKernelConfig
(
data_type
=
dtype
)
def
test_config_python_types8
():
dtype
=
defaultdict
(
lambda
:
float
,
{
'
a
'
:
np
.
float64
,
'
b
'
:
np
.
int64
})
with
pytest
.
raises
(
ValueError
):
CreateKernelConfig
(
data_type
=
dtype
)
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