@@ -335,7 +335,7 @@ def tensorset(self,
335335 return res if not self .enable_postprocess else processor .tensorset (res )
336336
337337 def tensorget (self ,
338- key : AnyStr , as_numpy : bool = True ,
338+ key : AnyStr , as_numpy : bool = True , as_numpy_mutable : bool = False ,
339339 meta_only : bool = False ) -> Union [dict , np .ndarray ]:
340340 """
341341 Retrieve the value of a tensor from the server. By default it returns the numpy
@@ -349,6 +349,9 @@ def tensorget(self,
349349 If True, returns a numpy.ndarray. Returns the value as a list and the
350350 metadata in a dictionary if False. This flag also decides how to fetch
351351 the value from the RedisAI server, which also has performance implications
352+ as_numpy_mutable : bool
353+ If True, returns a a mutable numpy.ndarray object by copy the tensor data. Otherwise (as long as_numpy=True)
354+ the returned numpy.ndarray will use the original tensor buffer and will be for read-only
352355 meta_only : bool
353356 If True, the value is not retrieved, only the shape and the type
354357
@@ -368,8 +371,7 @@ def tensorget(self,
368371 """
369372 args = builder .tensorget (key , as_numpy , meta_only )
370373 res = self .execute_command (* args )
371- return res if not self .enable_postprocess else processor .tensorget (res ,
372- as_numpy , meta_only )
374+ return res if not self .enable_postprocess else processor .tensorget (res , as_numpy , as_numpy_mutable , meta_only )
373375
374376 def scriptset (self , key : AnyStr , device : str , script : str , tag : AnyStr = None ) -> str :
375377 """
@@ -587,11 +589,12 @@ def __init__(self, enable_postprocess, *args, **kwargs):
587589 def dag (self , * args , ** kwargs ):
588590 raise RuntimeError ("Pipeline object doesn't allow DAG creation currently" )
589591
590- def tensorget (self , key , as_numpy = True , meta_only = False ):
592+ def tensorget (self , key , as_numpy = True , as_numpy_mutable = False , meta_only = False ):
591593 self .tensorget_processors .append (partial (processor .tensorget ,
592594 as_numpy = as_numpy ,
595+ as_numpy_mutable = as_numpy_mutable ,
593596 meta_only = meta_only ))
594- return super ().tensorget (key , as_numpy , meta_only )
597+ return super ().tensorget (key , as_numpy , as_numpy_mutable , meta_only )
595598
596599 def _execute_transaction (self , * args , ** kwargs ):
597600 # TODO: Blocking commands like MODELRUN, SCRIPTRUN and DAGRUN won't work
@@ -648,13 +651,14 @@ def tensorset(self,
648651 return self
649652
650653 def tensorget (self ,
651- key : AnyStr , as_numpy : bool = True ,
654+ key : AnyStr , as_numpy : bool = True , as_numpy_mutable : bool = False ,
652655 meta_only : bool = False ) -> Any :
653- args = builder .tensorget (key , as_numpy , meta_only )
656+ args = builder .tensorget (key , as_numpy , as_numpy_mutable )
654657 self .commands .extend (args )
655658 self .commands .append ("|>" )
656659 self .result_processors .append (partial (processor .tensorget ,
657660 as_numpy = as_numpy ,
661+ as_numpy_mutable = as_numpy_mutable ,
658662 meta_only = meta_only ))
659663 return self
660664
0 commit comments