visionipc: replace numpy with memoryview (#688)

This commit is contained in:
Adeeb Shihadeh
2026-05-15 10:01:54 -07:00
committed by GitHub
parent 3eb9a5a806
commit ecbaf9f887
4 changed files with 12 additions and 13 deletions

View File

@@ -2,7 +2,6 @@ import os
import platform
import subprocess
import sysconfig
import numpy as np
import catch2
arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
@@ -71,7 +70,6 @@ env = Environment(
Export('env', 'arch', 'common')
envCython = env.Clone(LIBS=[])
envCython["CPPPATH"] += [np.get_include()]
envCython["CCFLAGS"] += ["-Wno-#warnings", "-Wno-cpp", "-Wno-shadow", "-Wno-deprecated-declarations"]
envCython["CCFLAGS"].remove('-Werror')
if arch == "Darwin":

View File

@@ -1,6 +1,6 @@
import struct
import unittest
from typing import Optional
import numpy as np
from msgq.visionipc import VisionIpcServer, VisionIpcClient, VisionStreamType
@@ -55,13 +55,17 @@ class TestVisionIpc(unittest.TestCase):
assert self.server is not None
assert self.client is not None
assert self.client.buffer_len is not None
buf = np.zeros(self.client.buffer_len, dtype=np.uint8)
buf.view('<u8')[0] = 1234
buf = bytearray(self.client.buffer_len)
struct.pack_into("<Q", buf, 0, 1234)
self.server.send(VisionStreamType.VISION_STREAM_ROAD, buf, frame_id=1337)
recv_buf = self.client.recv()
assert recv_buf is not None
assert recv_buf.data.view('<u8')[0] == 1234
data = recv_buf.data
assert isinstance(data, memoryview)
assert struct.unpack_from("<Q", data, 0)[0] == 1234
assert len(data) == self.client.buffer_len
assert data[8:].nbytes == self.client.buffer_len - 8
assert self.client.frame_id == 1337
assert recv_buf.frame_id == 1337
@@ -70,7 +74,7 @@ class TestVisionIpc(unittest.TestCase):
assert self.server is not None
assert self.client is not None
assert self.client.buffer_len is not None
buf = np.zeros(self.client.buffer_len, dtype=np.uint8)
buf = bytearray(self.client.buffer_len)
self.server.send(VisionStreamType.VISION_STREAM_ROAD, buf, frame_id=1)
self.server.send(VisionStreamType.VISION_STREAM_ROAD, buf, frame_id=2)
@@ -87,7 +91,7 @@ class TestVisionIpc(unittest.TestCase):
assert self.server is not None
assert self.client is not None
assert self.client.buffer_len is not None
buf = np.zeros(self.client.buffer_len, dtype=np.uint8)
buf = bytearray(self.client.buffer_len)
self.server.send(VisionStreamType.VISION_STREAM_ROAD, buf, frame_id=1)
self.server.send(VisionStreamType.VISION_STREAM_ROAD, buf, frame_id=2)

View File

@@ -2,9 +2,6 @@
# cython: c_string_encoding=ascii, language_level=3
import sys
import numpy as np
cimport numpy as cnp
from cython.view cimport array
from libc.string cimport memcpy
from libc.stdint cimport uint32_t, uint64_t
from libcpp cimport bool
@@ -37,7 +34,8 @@ cdef class VisionBuf:
@property
def data(self):
return np.asarray(<cnp.uint8_t[:self.buf.len]> self.buf.addr)
cdef unsigned char[:] data = <unsigned char[:self.buf.len]> self.buf.addr
return memoryview(data)
@property
def width(self):

View File

@@ -19,7 +19,6 @@ dependencies = [
"ruff",
"parameterized",
"coverage",
"numpy",
"cppcheck",
"cpplint",
"codespell",