mirror of
https://github.com/wassname/ray.git
synced 2026-07-01 12:37:14 +08:00
change directory structure, rename array libraries (#87)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from typing import List
|
||||
import numpy as np
|
||||
import arrays.single as single
|
||||
import halo.arrays.remote as ra
|
||||
import halo
|
||||
|
||||
__all__ = ["BLOCK_SIZE", "DistArray", "assemble", "zeros", "ones", "copy",
|
||||
@@ -87,14 +87,14 @@ def numpy_to_dist(a):
|
||||
def zeros(shape, dtype_name="float"):
|
||||
result = DistArray(shape)
|
||||
for index in np.ndindex(*result.num_blocks):
|
||||
result.objrefs[index] = single.zeros(DistArray.compute_block_shape(index, shape), dtype_name=dtype_name)
|
||||
result.objrefs[index] = ra.zeros(DistArray.compute_block_shape(index, shape), dtype_name=dtype_name)
|
||||
return result
|
||||
|
||||
@halo.remote([List[int], str], [DistArray])
|
||||
def ones(shape, dtype_name="float"):
|
||||
result = DistArray(shape)
|
||||
for index in np.ndindex(*result.num_blocks):
|
||||
result.objrefs[index] = single.ones(DistArray.compute_block_shape(index, shape), dtype_name=dtype_name)
|
||||
result.objrefs[index] = ra.ones(DistArray.compute_block_shape(index, shape), dtype_name=dtype_name)
|
||||
return result
|
||||
|
||||
@halo.remote([DistArray], [DistArray])
|
||||
@@ -112,9 +112,9 @@ def eye(dim1, dim2=-1, dtype_name="float"):
|
||||
for (i, j) in np.ndindex(*result.num_blocks):
|
||||
block_shape = DistArray.compute_block_shape([i, j], shape)
|
||||
if i == j:
|
||||
result.objrefs[i, j] = single.eye(block_shape[0], block_shape[1], dtype_name=dtype_name)
|
||||
result.objrefs[i, j] = ra.eye(block_shape[0], block_shape[1], dtype_name=dtype_name)
|
||||
else:
|
||||
result.objrefs[i, j] = single.zeros(block_shape, dtype_name=dtype_name)
|
||||
result.objrefs[i, j] = ra.zeros(block_shape, dtype_name=dtype_name)
|
||||
return result
|
||||
|
||||
@halo.remote([DistArray], [DistArray])
|
||||
@@ -124,11 +124,11 @@ def triu(a):
|
||||
result = DistArray(a.shape)
|
||||
for (i, j) in np.ndindex(*result.num_blocks):
|
||||
if i < j:
|
||||
result.objrefs[i, j] = single.copy(a.objrefs[i, j])
|
||||
result.objrefs[i, j] = ra.copy(a.objrefs[i, j])
|
||||
elif i == j:
|
||||
result.objrefs[i, j] = single.triu(a.objrefs[i, j])
|
||||
result.objrefs[i, j] = ra.triu(a.objrefs[i, j])
|
||||
else:
|
||||
result.objrefs[i, j] = single.zeros_like(a.objrefs[i, j])
|
||||
result.objrefs[i, j] = ra.zeros_like(a.objrefs[i, j])
|
||||
return result
|
||||
|
||||
@halo.remote([DistArray], [DistArray])
|
||||
@@ -138,11 +138,11 @@ def tril(a):
|
||||
result = DistArray(a.shape)
|
||||
for (i, j) in np.ndindex(*result.num_blocks):
|
||||
if i > j:
|
||||
result.objrefs[i, j] = single.copy(a.objrefs[i, j])
|
||||
result.objrefs[i, j] = ra.copy(a.objrefs[i, j])
|
||||
elif i == j:
|
||||
result.objrefs[i, j] = single.tril(a.objrefs[i, j])
|
||||
result.objrefs[i, j] = ra.tril(a.objrefs[i, j])
|
||||
else:
|
||||
result.objrefs[i, j] = single.zeros_like(a.objrefs[i, j])
|
||||
result.objrefs[i, j] = ra.zeros_like(a.objrefs[i, j])
|
||||
return result
|
||||
|
||||
@halo.remote([np.ndarray], [np.ndarray])
|
||||
@@ -209,7 +209,7 @@ def transpose(a):
|
||||
result = DistArray([a.shape[1], a.shape[0]])
|
||||
for i in range(result.num_blocks[0]):
|
||||
for j in range(result.num_blocks[1]):
|
||||
result.objrefs[i, j] = single.transpose(a.objrefs[j, i])
|
||||
result.objrefs[i, j] = ra.transpose(a.objrefs[j, i])
|
||||
return result
|
||||
|
||||
# TODO(rkn): support broadcasting?
|
||||
@@ -219,7 +219,7 @@ def add(x1, x2):
|
||||
raise Exception("add expects arguments `x1` and `x2` to have the same shape, but x1.shape = {}, and x2.shape = {}.".format(x1.shape, x2.shape))
|
||||
result = DistArray(x1.shape)
|
||||
for index in np.ndindex(*result.num_blocks):
|
||||
result.objrefs[index] = single.add(x1.objrefs[index], x2.objrefs[index])
|
||||
result.objrefs[index] = ra.add(x1.objrefs[index], x2.objrefs[index])
|
||||
return result
|
||||
|
||||
# TODO(rkn): support broadcasting?
|
||||
@@ -229,5 +229,5 @@ def subtract(x1, x2):
|
||||
raise Exception("subtract expects arguments `x1` and `x2` to have the same shape, but x1.shape = {}, and x2.shape = {}.".format(x1.shape, x2.shape))
|
||||
result = DistArray(x1.shape)
|
||||
for index in np.ndindex(*result.num_blocks):
|
||||
result.objrefs[index] = single.subtract(x1.objrefs[index], x2.objrefs[index])
|
||||
result.objrefs[index] = ra.subtract(x1.objrefs[index], x2.objrefs[index])
|
||||
return result
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import List
|
||||
|
||||
import numpy as np
|
||||
import arrays.single as single
|
||||
import halo.arrays.remote as ra
|
||||
import halo
|
||||
|
||||
from core import *
|
||||
@@ -35,14 +35,14 @@ def tsqr(a):
|
||||
current_rs = []
|
||||
for i in range(num_blocks):
|
||||
block = a.objrefs[i, 0]
|
||||
q, r = single.linalg.qr(block)
|
||||
q, r = ra.linalg.qr(block)
|
||||
q_tree[i, 0] = q
|
||||
current_rs.append(r)
|
||||
for j in range(1, K):
|
||||
new_rs = []
|
||||
for i in range(int(np.ceil(1.0 * len(current_rs) / 2))):
|
||||
stacked_rs = single.vstack(*current_rs[(2 * i):(2 * i + 2)])
|
||||
q, r = single.linalg.qr(stacked_rs)
|
||||
stacked_rs = ra.vstack(*current_rs[(2 * i):(2 * i + 2)])
|
||||
q, r = ra.linalg.qr(stacked_rs)
|
||||
q_tree[i, j] = q
|
||||
new_rs.append(r)
|
||||
current_rs = new_rs
|
||||
@@ -74,7 +74,7 @@ def tsqr(a):
|
||||
lower = [a.shape[1], 0]
|
||||
upper = [2 * a.shape[1], BLOCK_SIZE]
|
||||
ith_index /= 2
|
||||
q_block_current = single.dot(q_block_current, single.subarray(q_tree[ith_index, j], lower, upper))
|
||||
q_block_current = ra.dot(q_block_current, ra.subarray(q_tree[ith_index, j], lower, upper))
|
||||
q_result.objrefs[i] = q_block_current
|
||||
r = current_rs[0]
|
||||
return q_result, r
|
||||
@@ -164,9 +164,9 @@ def qr(a):
|
||||
y_res.objrefs[j, i] = y_val.objrefs[j - i, 0]
|
||||
if a.shape[0] > a.shape[1]:
|
||||
# in this case, R needs to be square
|
||||
R_shape = halo.pull(single.shape(R))
|
||||
eye_temp = single.eye(R_shape[1], R_shape[0], dtype_name=result_dtype)
|
||||
r_res.objrefs[i, i] = single.dot(eye_temp, R)
|
||||
R_shape = halo.pull(ra.shape(R))
|
||||
eye_temp = ra.eye(R_shape[1], R_shape[0], dtype_name=result_dtype)
|
||||
r_res.objrefs[i, i] = ra.dot(eye_temp, R)
|
||||
else:
|
||||
r_res.objrefs[i, i] = R
|
||||
Ts.append(numpy_to_dist(t))
|
||||
@@ -176,7 +176,7 @@ def qr(a):
|
||||
for r in range(i, a.num_blocks[0]):
|
||||
y_ri = y_val.objrefs[r - i, 0]
|
||||
W_rcs.append(qr_helper2(y_ri, a_work.objrefs[r, c]))
|
||||
W_c = single.sum(0, *W_rcs)
|
||||
W_c = ra.sum(0, *W_rcs)
|
||||
for r in range(i, a.num_blocks[0]):
|
||||
y_ri = y_val.objrefs[r - i, 0]
|
||||
A_rc = qr_helper1(a_work.objrefs[r, c], y_ri, t, W_c)
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import List
|
||||
|
||||
import numpy as np
|
||||
import arrays.single as single
|
||||
import halo.arrays.remote as ra
|
||||
import halo
|
||||
|
||||
from core import *
|
||||
@@ -11,7 +11,7 @@ def normal(shape):
|
||||
num_blocks = DistArray.compute_num_blocks(shape)
|
||||
objrefs = np.empty(num_blocks, dtype=object)
|
||||
for index in np.ndindex(*num_blocks):
|
||||
objrefs[index] = single.random.normal(DistArray.compute_block_shape(index, shape))
|
||||
objrefs[index] = ra.random.normal(DistArray.compute_block_shape(index, shape))
|
||||
result = DistArray()
|
||||
result.construct(shape, objrefs)
|
||||
return result
|
||||
Reference in New Issue
Block a user