mirror of
https://github.com/wassname/ray.git
synced 2026-07-04 04:27:36 +08:00
export remote functions and reusable variables that were defined before connect was called (#292)
This commit is contained in:
committed by
Philipp Moritz
parent
8e9f98c5ff
commit
3bae6f136b
@@ -83,14 +83,14 @@ def numpy_to_dist(a):
|
||||
result.objrefs[index] = ray.put(a[[slice(l, u) for (l, u) in zip(lower, upper)]])
|
||||
return result
|
||||
|
||||
@ray.remote([List[int], str], [DistArray])
|
||||
@ray.remote([List, str], [DistArray])
|
||||
def zeros(shape, dtype_name="float"):
|
||||
result = DistArray(shape)
|
||||
for index in np.ndindex(*result.num_blocks):
|
||||
result.objrefs[index] = ra.zeros(DistArray.compute_block_shape(index, shape), dtype_name=dtype_name)
|
||||
return result
|
||||
|
||||
@ray.remote([List[int], str], [DistArray])
|
||||
@ray.remote([List, str], [DistArray])
|
||||
def ones(shape, dtype_name="float"):
|
||||
result = DistArray(shape)
|
||||
for index in np.ndindex(*result.num_blocks):
|
||||
@@ -171,7 +171,7 @@ def dot(a, b):
|
||||
result.objrefs[i, j] = blockwise_dot(*args)
|
||||
return result
|
||||
|
||||
@ray.remote([DistArray, List[int]], [DistArray])
|
||||
@ray.remote([DistArray, List], [DistArray])
|
||||
def subblocks(a, *ranges):
|
||||
"""
|
||||
This function produces a distributed array from a subset of the blocks in the `a`. The result and `a` will have the same number of dimensions.For example,
|
||||
|
||||
@@ -6,7 +6,7 @@ import ray
|
||||
|
||||
from core import *
|
||||
|
||||
@ray.remote([List[int]], [DistArray])
|
||||
@ray.remote([List], [DistArray])
|
||||
def normal(shape):
|
||||
num_blocks = DistArray.compute_num_blocks(shape)
|
||||
objrefs = np.empty(num_blocks, dtype=object)
|
||||
|
||||
@@ -4,7 +4,7 @@ import ray
|
||||
|
||||
__all__ = ["zeros", "zeros_like", "ones", "eye", "dot", "vstack", "hstack", "subarray", "copy", "tril", "triu", "diag", "transpose", "add", "subtract", "sum", "shape", "sum_list"]
|
||||
|
||||
@ray.remote([List[int], str, str], [np.ndarray])
|
||||
@ray.remote([List, str, str], [np.ndarray])
|
||||
def zeros(shape, dtype_name="float", order="C"):
|
||||
return np.zeros(shape, dtype=np.dtype(dtype_name), order=order)
|
||||
|
||||
@@ -13,7 +13,7 @@ def zeros_like(a, dtype_name="None", order="K", subok=True):
|
||||
dtype_val = None if dtype_name == "None" else np.dtype(dtype_name)
|
||||
return np.zeros_like(a, dtype=dtype_val, order=order, subok=subok)
|
||||
|
||||
@ray.remote([List[int], str, str], [np.ndarray])
|
||||
@ray.remote([List, str, str], [np.ndarray])
|
||||
def ones(shape, dtype_name="float", order="C"):
|
||||
return np.ones(shape, dtype=np.dtype(dtype_name), order=order)
|
||||
|
||||
@@ -35,7 +35,7 @@ def hstack(*xs):
|
||||
return np.hstack(xs)
|
||||
|
||||
# TODO(rkn): instead of this, consider implementing slicing
|
||||
@ray.remote([np.ndarray, List[int], List[int]], [np.ndarray])
|
||||
@ray.remote([np.ndarray, List, List], [np.ndarray])
|
||||
def subarray(a, lower_indices, upper_indices): # TODO(rkn): be consistent about using "index" versus "indices"
|
||||
return a[[slice(l, u) for (l, u) in zip(lower_indices, upper_indices)]]
|
||||
|
||||
@@ -55,7 +55,7 @@ def triu(m, k=0):
|
||||
def diag(v, k=0):
|
||||
return np.diag(v, k=k)
|
||||
|
||||
@ray.remote([np.ndarray, List[int]], [np.ndarray])
|
||||
@ray.remote([np.ndarray, List], [np.ndarray])
|
||||
def transpose(a, axes=[]):
|
||||
axes = None if axes == [] else axes
|
||||
return np.transpose(a, axes=axes)
|
||||
|
||||
@@ -2,6 +2,6 @@ from typing import List
|
||||
import numpy as np
|
||||
import ray
|
||||
|
||||
@ray.remote([List[int]], [np.ndarray])
|
||||
@ray.remote([List], [np.ndarray])
|
||||
def normal(shape):
|
||||
return np.random.normal(size=shape)
|
||||
|
||||
Reference in New Issue
Block a user