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
pycodegen
pystencils
Commits
95a195ea
Commit
95a195ea
authored
8 months ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
Add scalar shapes to array type; generalize to SupportsIndex
parent
c3ed7ca5
No related branches found
No related tags found
1 merge request
!420
Revised Array Modelling & Memory Model
Pipeline
#69604
passed
8 months ago
Stage: Code Quality
Stage: Unit Tests
Stage: legacy_test
Stage: docs
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencils/types/types.py
+9
-3
9 additions, 3 deletions
src/pystencils/types/types.py
tests/nbackend/types/test_types.py
+3
-1
3 additions, 1 deletion
tests/nbackend/types/test_types.py
with
12 additions
and
4 deletions
src/pystencils/types/types.py
+
9
−
3
View file @
95a195ea
from
__future__
import
annotations
from
__future__
import
annotations
from
abc
import
ABC
,
abstractmethod
from
abc
import
ABC
,
abstractmethod
from
typing
import
final
,
Any
,
Sequence
from
typing
import
final
,
Any
,
Sequence
,
SupportsIndex
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
import
numpy
as
np
import
numpy
as
np
...
@@ -105,8 +105,14 @@ class PsArrayType(PsDereferencableType):
...
@@ -105,8 +105,14 @@ class PsArrayType(PsDereferencableType):
"""
"""
def
__init__
(
def
__init__
(
self
,
element_type
:
PsType
,
shape
:
S
equence
[
int
],
const
:
bool
=
False
self
,
element_type
:
PsType
,
shape
:
S
upportsIndex
|
Sequence
[
SupportsIndex
],
const
:
bool
=
False
):
):
from
operator
import
index
if
isinstance
(
shape
,
SupportsIndex
):
shape
=
(
index
(
shape
),)
else
:
shape
=
tuple
(
index
(
s
)
for
s
in
shape
)
if
not
shape
or
any
(
s
<=
0
for
s
in
shape
):
if
not
shape
or
any
(
s
<=
0
for
s
in
shape
):
raise
ValueError
(
f
"
Invalid array shape:
{
shape
}
"
)
raise
ValueError
(
f
"
Invalid array shape:
{
shape
}
"
)
...
@@ -115,7 +121,7 @@ class PsArrayType(PsDereferencableType):
...
@@ -115,7 +121,7 @@ class PsArrayType(PsDereferencableType):
element_type
=
deconstify
(
element_type
)
element_type
=
deconstify
(
element_type
)
self
.
_shape
=
tuple
(
shape
)
self
.
_shape
=
shape
super
().
__init__
(
element_type
,
const
)
super
().
__init__
(
element_type
,
const
)
def
__args__
(
self
)
->
tuple
[
Any
,
...]:
def
__args__
(
self
)
->
tuple
[
Any
,
...]:
...
...
This diff is collapsed.
Click to expand it.
tests/nbackend/types/test_types.py
+
3
−
1
View file @
95a195ea
...
@@ -152,12 +152,14 @@ def test_struct_types():
...
@@ -152,12 +152,14 @@ def test_struct_types():
def
test_array_types
():
def
test_array_types
():
t
=
PsArrayType
(
UInt
(
64
),
[
42
]
)
t
=
PsArrayType
(
UInt
(
64
),
42
)
assert
t
.
dim
==
1
assert
t
.
dim
==
1
assert
t
.
shape
==
(
42
,)
assert
t
.
shape
==
(
42
,)
assert
not
t
.
const
assert
not
t
.
const
assert
t
.
c_string
()
==
"
uint64_t[42]
"
assert
t
.
c_string
()
==
"
uint64_t[42]
"
assert
t
==
PsArrayType
(
UInt
(
64
),
(
42
,))
t
=
PsArrayType
(
UInt
(
64
),
[
3
,
4
,
5
])
t
=
PsArrayType
(
UInt
(
64
),
[
3
,
4
,
5
])
assert
t
.
dim
==
3
assert
t
.
dim
==
3
assert
t
.
shape
==
(
3
,
4
,
5
)
assert
t
.
shape
==
(
3
,
4
,
5
)
...
...
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