mirror of
https://github.com/wassname/ray.git
synced 2026-08-19 12:30:27 +08:00
implement serialization using numbuf
This commit is contained in:
+11
-10
@@ -1,6 +1,7 @@
|
||||
from types import ModuleType
|
||||
import typing
|
||||
import numpy as np
|
||||
import pynumbuf
|
||||
|
||||
import orchpy
|
||||
import serialization
|
||||
@@ -14,11 +15,11 @@ class Worker(object):
|
||||
|
||||
def put_object(self, objref, value):
|
||||
"""Put `value` in the local object store with objref `objref`. This assumes that the value for `objref` has not yet been placed in the local object store."""
|
||||
# if type(value) == np.ndarray:
|
||||
# orchpy.lib.put_arrow(self.handle, objref, value)
|
||||
# else:
|
||||
object_capsule, contained_objrefs = serialization.serialize(self.handle, value) # contained_objrefs is a list of the objrefs contained in object_capsule
|
||||
orchpy.lib.put_object(self.handle, objref, object_capsule, contained_objrefs)
|
||||
if pynumbuf.serializable(value):
|
||||
orchpy.lib.put_arrow(self.handle, objref, value)
|
||||
else:
|
||||
object_capsule, contained_objrefs = serialization.serialize(self.handle, value) # contained_objrefs is a list of the objrefs contained in object_capsule
|
||||
orchpy.lib.put_object(self.handle, objref, object_capsule, contained_objrefs)
|
||||
|
||||
def get_object(self, objref):
|
||||
"""
|
||||
@@ -27,11 +28,11 @@ class Worker(object):
|
||||
|
||||
WARNING: get_object can only be called on a canonical objref.
|
||||
"""
|
||||
# if orchpy.lib.is_arrow(self.handle, objref):
|
||||
# return orchpy.lib.get_arrow(self.handle, objref)
|
||||
# else:
|
||||
object_capsule = orchpy.lib.get_object(self.handle, objref)
|
||||
return serialization.deserialize(self.handle, object_capsule)
|
||||
if orchpy.lib.is_arrow(self.handle, objref):
|
||||
return orchpy.lib.get_arrow(self.handle, objref)
|
||||
else:
|
||||
object_capsule = orchpy.lib.get_object(self.handle, objref)
|
||||
return serialization.deserialize(self.handle, object_capsule)
|
||||
|
||||
def alias_objrefs(self, alias_objref, target_objref):
|
||||
"""Make `alias_objref` refer to the same object that `target_objref` refers to."""
|
||||
|
||||
Reference in New Issue
Block a user