18
18
19
19
20
20
def numpy2blob (tensor : np .ndarray ) -> tuple :
21
- """ Convert the numpy input from user to `Tensor` """
21
+ """Convert the numpy input from user to `Tensor`. """
22
22
try :
23
23
dtype = dtype_dict [str (tensor .dtype )]
24
24
except KeyError :
@@ -29,7 +29,7 @@ def numpy2blob(tensor: np.ndarray) -> tuple:
29
29
30
30
31
31
def blob2numpy (value : ByteString , shape : Union [list , tuple ], dtype : str ) -> np .ndarray :
32
- """ Convert `BLOB` result from RedisAI to `np.ndarray` """
32
+ """Convert `BLOB` result from RedisAI to `np.ndarray`. """
33
33
mm = {
34
34
'FLOAT' : 'float32' ,
35
35
'DOUBLE' : 'float64'
@@ -40,6 +40,7 @@ def blob2numpy(value: ByteString, shape: Union[list, tuple], dtype: str) -> np.n
40
40
41
41
42
42
def list2dict (lst ):
43
+ """Convert the list from RedisAI to a dict."""
43
44
if len (lst ) % 2 != 0 :
44
45
raise RuntimeError ("Can't unpack the list: {}" .format (lst ))
45
46
out = {}
@@ -55,10 +56,8 @@ def list2dict(lst):
55
56
def recursive_bytetransform (arr : List [AnyStr ], target : Callable ) -> list :
56
57
"""
57
58
Recurse value, replacing each element of b'' with the appropriate element.
58
- Function returns the same array after inplace operation which updates `arr`
59
59
60
- :param target: Type of tensor | array
61
- :param arr: The array with b'' numbers or recursive array of b''
60
+ Function returns the same array after inplace operation which updates `arr`
62
61
"""
63
62
for ix in range (len (arr )):
64
63
obj = arr [ix ]
@@ -70,10 +69,16 @@ def recursive_bytetransform(arr: List[AnyStr], target: Callable) -> list:
70
69
71
70
72
71
def listify (inp : Union [str , Sequence [str ]]) -> Sequence [str ]:
72
+ """Wrap the ``inp`` with a list if it's not a list already."""
73
73
return (inp ,) if not isinstance (inp , (list , tuple )) else inp
74
74
75
75
76
- def tensorget_postprocessor (as_numpy , meta_only , rai_result ):
76
+ def tensorget_postprocessor (rai_result , as_numpy , meta_only ):
77
+ """Process the tensorget output.
78
+
79
+ If ``as_numpy`` is True, it'll be converted to a numpy array. The required
80
+ information such as datatype and shape must be in ``rai_result`` itself.
81
+ """
77
82
rai_result = list2dict (rai_result )
78
83
if meta_only :
79
84
return rai_result
0 commit comments