mirror of
https://github.com/wassname/ray.git
synced 2026-07-05 21:23:55 +08:00
change filenames and directory structure to use halo (#81)
This commit is contained in:
committed by
Philipp Moritz
parent
b58eaf84ee
commit
67086f663e
@@ -0,0 +1,2 @@
|
||||
import random, linalg
|
||||
from core import *
|
||||
@@ -0,0 +1,80 @@
|
||||
from typing import List
|
||||
import numpy as np
|
||||
import halo
|
||||
|
||||
__all__ = ["zeros", "zeros_like", "ones", "eye", "dot", "vstack", "hstack", "subarray", "copy", "tril", "triu", "diag", "transpose", "add", "subtract", "sum", "shape"]
|
||||
|
||||
@halo.distributed([List[int], str, str], [np.ndarray])
|
||||
def zeros(shape, dtype_name="float", order="C"):
|
||||
return np.zeros(shape, dtype=np.dtype(dtype_name), order=order)
|
||||
|
||||
@halo.distributed([np.ndarray, str, str, bool], [np.ndarray])
|
||||
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)
|
||||
|
||||
@halo.distributed([List[int], str, str], [np.ndarray])
|
||||
def ones(shape, dtype_name="float", order="C"):
|
||||
return np.ones(shape, dtype=np.dtype(dtype_name), order=order)
|
||||
|
||||
@halo.distributed([int, int, int, str], [np.ndarray])
|
||||
def eye(N, M=-1, k=0, dtype_name="float"):
|
||||
M = N if M == -1 else M
|
||||
return np.eye(N, M=M, k=k, dtype=np.dtype(dtype_name))
|
||||
|
||||
@halo.distributed([np.ndarray, np.ndarray], [np.ndarray])
|
||||
def dot(a, b):
|
||||
return np.dot(a, b)
|
||||
|
||||
# TODO(rkn): My preferred signature would have been
|
||||
# @halo.distributed([List[np.ndarray]], [np.ndarray]) but that currently doesn't
|
||||
# work because that would expect a list of ndarrays not a list of ObjRefs
|
||||
@halo.distributed([np.ndarray, None], [np.ndarray])
|
||||
def vstack(*xs):
|
||||
return np.vstack(xs)
|
||||
|
||||
@halo.distributed([np.ndarray, None], [np.ndarray])
|
||||
def hstack(*xs):
|
||||
return np.hstack(xs)
|
||||
|
||||
# TODO(rkn): this doesn't parallel the numpy API, but we can't really slice an ObjRef, think about this
|
||||
@halo.distributed([np.ndarray, List[int], List[int]], [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)]]
|
||||
|
||||
@halo.distributed([np.ndarray, str], [np.ndarray])
|
||||
def copy(a, order="K"):
|
||||
return np.copy(a, order=order)
|
||||
|
||||
@halo.distributed([np.ndarray, int], [np.ndarray])
|
||||
def tril(m, k=0):
|
||||
return np.tril(m, k=k)
|
||||
|
||||
@halo.distributed([np.ndarray, int], [np.ndarray])
|
||||
def triu(m, k=0):
|
||||
return np.triu(m, k=k)
|
||||
|
||||
@halo.distributed([np.ndarray, int], [np.ndarray])
|
||||
def diag(v, k=0):
|
||||
return np.diag(v, k=k)
|
||||
|
||||
@halo.distributed([np.ndarray, List[int]], [np.ndarray])
|
||||
def transpose(a, axes=[]):
|
||||
axes = None if axes == [] else axes
|
||||
return np.transpose(a, axes=axes)
|
||||
|
||||
@halo.distributed([np.ndarray, np.ndarray], [np.ndarray])
|
||||
def add(x1, x2):
|
||||
return np.add(x1, x2)
|
||||
|
||||
@halo.distributed([np.ndarray, np.ndarray], [np.ndarray])
|
||||
def subtract(x1, x2):
|
||||
return np.subtract(x1, x2)
|
||||
|
||||
@halo.distributed([int, np.ndarray, None], [np.ndarray])
|
||||
def sum(axis, *xs):
|
||||
return np.sum(xs, axis=axis)
|
||||
|
||||
@halo.distributed([np.ndarray], [tuple])
|
||||
def shape(a):
|
||||
return np.shape(a)
|
||||
@@ -0,0 +1,88 @@
|
||||
from typing import List
|
||||
import numpy as np
|
||||
import halo
|
||||
|
||||
__all__ = ["matrix_power", "solve", "tensorsolve", "tensorinv", "inv",
|
||||
"cholesky", "eigvals", "eigvalsh", "pinv", "slogdet", "det",
|
||||
"svd", "eig", "eigh", "lstsq", "norm", "qr", "cond", "matrix_rank",
|
||||
"LinAlgError", "multi_dot"]
|
||||
|
||||
@halo.distributed([np.ndarray, int], [np.ndarray])
|
||||
def matrix_power(M, n):
|
||||
return np.linalg.matrix_power(M, n)
|
||||
|
||||
@halo.distributed([np.ndarray, np.ndarray], [np.ndarray])
|
||||
def solve(a, b):
|
||||
return np.linalg.solve(a, b)
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray, np.ndarray])
|
||||
def tensorsolve(a):
|
||||
raise NotImplementedError
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray, np.ndarray])
|
||||
def tensorinv(a):
|
||||
raise NotImplementedError
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray])
|
||||
def inv(a):
|
||||
return np.linalg.inv(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray])
|
||||
def cholesky(a):
|
||||
return np.linalg.cholesky(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray])
|
||||
def eigvals(a):
|
||||
return np.linalg.eigvals(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray])
|
||||
def eigvalsh(a):
|
||||
raise NotImplementedError
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray])
|
||||
def pinv(a):
|
||||
return np.linalg.pinv(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [int])
|
||||
def slogdet(a):
|
||||
raise NotImplementedError
|
||||
|
||||
@halo.distributed([np.ndarray], [float])
|
||||
def det(a):
|
||||
return np.linalg.det(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray, np.ndarray, np.ndarray])
|
||||
def svd(a):
|
||||
return np.linalg.svd(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray, np.ndarray])
|
||||
def eig(a):
|
||||
return np.linalg.eig(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray, np.ndarray])
|
||||
def eigh(a):
|
||||
return np.linalg.eigh(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray, np.ndarray, int, np.ndarray])
|
||||
def lstsq(a, b):
|
||||
return np.linalg.lstsq(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [float])
|
||||
def norm(x):
|
||||
return np.linalg.norm(x)
|
||||
|
||||
@halo.distributed([np.ndarray], [np.ndarray, np.ndarray])
|
||||
def qr(a):
|
||||
return np.linalg.qr(a)
|
||||
|
||||
@halo.distributed([np.ndarray], [float])
|
||||
def cond(x):
|
||||
return np.linalg.cond(x)
|
||||
|
||||
@halo.distributed([np.ndarray], [int])
|
||||
def matrix_rank(M):
|
||||
return np.linalg.matrix_rank(M)
|
||||
|
||||
@halo.distributed([np.ndarray, None], [np.ndarray])
|
||||
def multi_dot(a):
|
||||
raise NotImplementedError
|
||||
@@ -0,0 +1,7 @@
|
||||
from typing import List
|
||||
import numpy as np
|
||||
import halo
|
||||
|
||||
@halo.distributed([List[int]], [np.ndarray])
|
||||
def normal(shape):
|
||||
return np.random.normal(size=shape)
|
||||
Reference in New Issue
Block a user