Skip to content

Commit 4e1bf8a

Browse files
committed
added __array__ method to deal with the casting issues
Signed-off-by: Rahul Steiger <[email protected]>
1 parent 1c1c420 commit 4e1bf8a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

vllm/multimodal/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from pathlib import Path
77
from typing import Generic, TypeVar
88

9+
import numpy as np
10+
911
_T = TypeVar("_T")
1012

1113

@@ -21,6 +23,10 @@ class MediaWithBytes(Generic[_T]):
2123
media: _T
2224
original_bytes: bytes
2325

26+
def __array__(self, dtype=None, copy=None):
27+
"""Allow np.array(obj) to return np.array(obj.media)."""
28+
return np.array(self.media, dtype=dtype, copy=copy)
29+
2430

2531
class MediaIO(ABC, Generic[_T]):
2632
@abstractmethod

0 commit comments

Comments
 (0)