Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpreter: add type property to ShapedArray #3709

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/interpreters/test_shaped_array.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from xdsl.dialects.builtin import i32
from xdsl.interpreters.shaped_array import ShapedArray
from xdsl.interpreters.utils.ptr import TypedPtr


def test_shaped_array_type():
array = ShapedArray(TypedPtr.new_int32([1, 2, 3]), [3])
assert array.element_type == i32


def test_shaped_array_offset():
array = ShapedArray(TypedPtr.new_int32([0, 1, 2, 3, 4, 5]), [2, 3])

Expand Down
6 changes: 5 additions & 1 deletion xdsl/interpreters/shaped_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from typing_extensions import Self

from xdsl.dialects.builtin import ShapedType
from xdsl.dialects.builtin import PackableType, ShapedType
from xdsl.interpreters.utils.ptr import TypedPtr

_T = TypeVar("_T")
Expand All @@ -25,6 +25,10 @@ class ShapedArray(Generic[_T]):
_data: TypedPtr[_T]
shape: list[int]

@property
def element_type(self) -> PackableType[_T]:
return self._data.xtype

@property
def size(self) -> int:
return prod(self.shape)
Expand Down
Loading