def test_tree_reduce_futures(n_parts, client): a = [client.submit(s, i) for i in range(n_parts)] b = tree_reduce(a) c = client.compute(b, sync=True) assert (sum(range(n_parts)) == c)
def test_tree_reduce_delayed(n_parts, client): func = delayed(sum) a = [delayed(i) for i in range(n_parts)] b = tree_reduce(a, func=func) c = client.compute(b, sync=True) assert (sum(range(n_parts)) == c)
def test_tree_reduce_futures(n_parts, cluster): client = Client(cluster) try: a = [client.submit(s, i) for i in range(n_parts)] b = tree_reduce(a) c = client.compute(b, sync=True) assert (sum(range(n_parts)) == c) finally: client.close()
def score(self, X, y): """ Compute accuracy score Parameters ---------- X : Dask.Array Features to predict. Note- it is assumed that chunk sizes and shape of X are known. This can be done for a fully delayed Array by calling X.compute_chunks_sizes() y : Dask.Array Labels to use for computing accuracy. Note- it is assumed that chunk sizes and shape of X are known. This can be done for a fully delayed Array by calling X.compute_chunks_sizes() Returns ------- score : float the resulting accuracy score """ y_hat = self.predict(X) @dask.delayed def _count_accurate_predictions(y_hat, y): y_hat = rmm_cupy_ary(cp.asarray, y_hat, dtype=y_hat.dtype) y = rmm_cupy_ary(cp.asarray, y, dtype=y.dtype) return y.shape[0] - cp.count_nonzero(y - y_hat) delayed_parts = zip(y_hat.to_delayed(), y.to_delayed()) accuracy_parts = [ _count_accurate_predictions(*p) for p in delayed_parts ] reduced = first(dask.compute(tree_reduce(accuracy_parts))) return reduced / X.shape[0]