Skip to content

355 convert long num arrays #358

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

Merged
merged 39 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1690f2a
first try on lockfile logic
songmeo Jun 6, 2025
980601b
Merge branch 'dev' of github.com:OpenCyphal/pycyphal into 335-create-…
songmeo Jun 6, 2025
aa158ea
fix couple path problems
songmeo Jun 6, 2025
3bd33cb
create lockfile class
songmeo Jun 9, 2025
5be4ba5
remove compiled_dir from nox
songmeo Jun 9, 2025
c22ac68
address comments
songmeo Jun 10, 2025
f4c07c4
add tests
songmeo Jun 11, 2025
adacb45
fix tests
songmeo Jun 11, 2025
3ddafbc
Merge branch '335-create-lockfile' of github.com:OpenCyphal/pycyphal …
songmeo Jun 12, 2025
657d727
address comments
songmeo Jun 12, 2025
ed79fd3
Merge branch '335-create-lockfile' of github.com:OpenCyphal/pycyphal …
songmeo Jun 12, 2025
3fcb454
add context manager
songmeo Jun 14, 2025
3892925
Add a function for removing import hooks (#356)
songmeo Jun 5, 2025
e0423d9
fix couple path problems
songmeo Jun 6, 2025
541e1b1
create lockfile class
songmeo Jun 9, 2025
6ef87ae
remove compiled_dir from nox
songmeo Jun 9, 2025
37fb27f
address comments
songmeo Jun 10, 2025
ee9f06a
add tests
songmeo Jun 11, 2025
2540db3
fix tests
songmeo Jun 11, 2025
106b4ba
address comments
songmeo Jun 12, 2025
5d79b75
add context manager
songmeo Jun 14, 2025
7df9e8c
choose value type based on the list length
songmeo Jun 14, 2025
b55b456
address comments
songmeo Jun 16, 2025
f331a60
remove the improve UX code
songmeo Jun 16, 2025
171bb12
create separate lockfile for support
songmeo Jun 16, 2025
50a414b
remove test related to old UX code
songmeo Jun 16, 2025
64dd205
change to elif
songmeo Jun 16, 2025
22a4dca
Trigger CI rebuild
songmeo Jun 17, 2025
7d978d7
choose value type based on the list length
songmeo Jun 14, 2025
c587a23
change to elif
songmeo Jun 16, 2025
d4a7a45
Trigger CI rebuild
songmeo Jun 17, 2025
d3ef982
Merge branch '355-convert-long-num-arrays' of github.com:OpenCyphal/p…
songmeo Jun 27, 2025
b7a23e0
merge changes from dev
songmeo Jun 30, 2025
e83708b
first tests
songmeo Jul 7, 2025
ad67509
attempt to fix uavcan import error
songmeo Jul 8, 2025
b0109c9
Merge branch 'master' of github.com:OpenCyphal/pycyphal into 355-conv…
songmeo Jul 8, 2025
f0992a3
fix mypy
songmeo Jul 8, 2025
53ce134
Merge branch 'dev' of github.com:OpenCyphal/pycyphal into 355-convert…
songmeo Jul 9, 2025
52c43e9
remove redundant condition
songmeo Jul 9, 2025
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
18 changes: 15 additions & 3 deletions pycyphal/application/register/_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,21 @@ def _strictify(s: RelaxedValue) -> Value:
if all(isinstance(x, bool) for x in s):
return _strictify(Bit(s))
if all(isinstance(x, (int, bool)) for x in s):
return _strictify(Natural64(s)) if all(x >= 0 for x in s) else _strictify(Integer64(s))
if all(isinstance(x, (float, int, bool)) for x in s):
return _strictify(Real64(s))
if len(s) <= 32:
return _strictify(Natural64(s)) if all(x >= 0 for x in s) else _strictify(Integer64(s))
if len(s) <= 64:
return _strictify(Natural32(s)) if all(x >= 0 for x in s) else _strictify(Integer32(s))
if len(s) <= 128:
return _strictify(Natural16(s)) if all(x >= 0 for x in s) else _strictify(Integer16(s))
if len(s) <= 256:
return _strictify(Natural8(s)) if all(x >= 0 for x in s) else _strictify(Integer8(s))
elif all(isinstance(x, (float, int, bool)) for x in s):
if len(s) <= 32:
return _strictify(Real64(s))
if len(s) <= 64:
return _strictify(Real32(s))
if len(s) <= 128:
return _strictify(Real16(s))

raise ValueConversionError(f"Don't know how to convert {s!r} into {Value}") # pragma: no cover

Expand Down
81 changes: 81 additions & 0 deletions tests/application/long_numerical_arrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (c) 2025 OpenCyphal
# This software is distributed under the terms of the MIT License.
# Author: Huong Pham <[email protected]>
from typing import List


def _unittest_strictify_bool() -> None:
# noinspection PyProtectedMember
from pycyphal.application.register._value import _strictify

s = [True, False]
n = _strictify(s).bit
assert n is not None
v = n.value
assert (s == v).all() # type: ignore[attr-defined]


def _unittest_strictify_u64() -> None:
# noinspection PyProtectedMember
from pycyphal.application.register._value import _strictify

s = [x * 1000000 for x in range(30)]
n = _strictify(s).natural64
assert n is not None
v = n.value
assert (s == v).all() # type: ignore[attr-defined]


def _unittest_strictify_u32() -> None:
# noinspection PyProtectedMember
from pycyphal.application.register._value import _strictify

s = [x * 1000000 for x in range(60)]
n = _strictify(s).natural32
assert n is not None
v = n.value
assert (s == v).all() # type: ignore[attr-defined]


def _unittest_strictify_u16() -> None:
# noinspection PyProtectedMember
from pycyphal.application.register._value import _strictify

s = [x * 100 for x in range(80)]
n = _strictify(s).natural16
assert n is not None
v = n.value
assert (s == v).all() # type: ignore[attr-defined]


def _unittest_strictify_i64() -> None:
# noinspection PyProtectedMember
from pycyphal.application.register._value import _strictify

s = [-x * 1000000 for x in range(30)]
n = _strictify(s).integer64
assert n is not None
v = n.value
assert (s == v).all() # type: ignore[attr-defined]


def _unittest_strictify_i32() -> None:
# noinspection PyProtectedMember
from pycyphal.application.register._value import _strictify

s = [-x * 1000000 for x in range(60)]
n = _strictify(s).integer32
assert n is not None
v = n.value
assert (s == v).all() # type: ignore[attr-defined]


def _unittest_strictify_i16() -> None:
# noinspection PyProtectedMember
from pycyphal.application.register._value import _strictify

s = [-x * 100 for x in range(80)]
n = _strictify(s).integer16
assert n is not None
v = n.value
assert (s == v).all() # type: ignore[attr-defined]