Skip to content

Commit f66b367

Browse files
authored
RSDK-9590 - upgrade numpy (#805)
1 parent 36a1530 commit f66b367

File tree

5 files changed

+114
-30
lines changed

5 files changed

+114
-30
lines changed

.github/workflows/update_protos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: arduino/setup-protoc@v3
1919
with:
2020
repo-token: ${{ secrets.GITHUB_TOKEN }}
21-
version: "28.2"
21+
version: "29.1"
2222

2323
- name: Install uv
2424
uses: astral-sh/setup-uv@v3

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ buf: clean
1616
rm -rf src/viam/gen
1717
chmod +x plugin/main.py
1818
uv pip install protoletariat
19-
uv pip install protobuf --upgrade
19+
uv pip install protobuf==5.29.1
2020
$(eval API_VERSION := $(shell grep 'API_VERSION' src/viam/version_metadata.py | awk -F '"' '{print $$2}'))
2121
buf generate buf.build/viamrobotics/api:${API_VERSION}
2222
buf generate buf.build/viamrobotics/goutils

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dynamic = [
1313
dependencies = [
1414
"googleapis-common-protos>=1.65.0",
1515
"grpclib>=0.4.7",
16-
"protobuf==5.28.2",
16+
"protobuf==5.29.1",
1717
"typing-extensions>=4.12.2",
1818
"pymongo>=4.10.1"
1919
]
@@ -47,7 +47,7 @@ dev-dependencies = [
4747
"myst-nb>=1.0.0; python_version>='3.9'",
4848
"nbmake>=1.5.4",
4949
"numpy<1.25.0; python_version<'3.9'",
50-
"numpy>=1.26.2,<2; python_version>='3.9'",
50+
"numpy>=1.26.2; python_version>='3.9'",
5151
"pillow>=10.4.0",
5252
"pyright>=1.1.382.post1",
5353
"pytest-asyncio>=0.24.0",

src/viam/services/mlmodel/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Dict
2+
from packaging.version import Version
23

34
import numpy as np
45
from numpy.typing import NDArray
@@ -37,7 +38,16 @@ def make_ndarray(flat_data, dtype, shape):
3738
"""Takes flat data (protobuf RepeatedScalarFieldContainer | bytes) to output an ndarray
3839
of appropriate dtype and shape"""
3940
make_array = np.frombuffer if dtype == np.int8 or dtype == np.uint8 else np.array
40-
return make_array(flat_data, dtype).reshape(shape)
41+
# As per proto, int16 and uint16 are stored as uint32. As of numpy v2, this creates
42+
# some strange interactions with negative values for int16. Specifically, we end up
43+
# trying to create an np.Int16 value with an out of bounds int due to rollover.
44+
# Creating our array as a uint32 array initially and then casting to int16 solves this.
45+
if Version(np.__version__) >= Version("2") and dtype == np.int16:
46+
arr = np.astype(make_array(flat_data, np.uint32), np.int16) # pyright: ignore [reportAttributeAccessIssue]
47+
48+
else:
49+
arr = make_array(flat_data, dtype)
50+
return arr.reshape(shape)
4151

4252
ndarrays: Dict[str, NDArray] = dict()
4353
for name, flat_tensor in flat_tensors.tensors.items():

0 commit comments

Comments
 (0)