-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26e2d4e
commit f9f76c5
Showing
2 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
import numpy as np | ||
from elephas.utils import functional_utils | ||
|
||
pytest.mark.usefixtures("spark_context") | ||
|
||
|
||
def test_add_params(): | ||
p1 = [np.ones((5, 5)) for i in range(10)] | ||
p2 = [np.ones((5, 5)) for i in range(10)] | ||
|
||
res = functional_utils.add_params(p1, p2) | ||
assert len(res) == 10 | ||
for i in range(5): | ||
for j in range(5): | ||
assert res[0][i, j] == 2 | ||
|
||
|
||
def test_subtract_params(): | ||
p1 = [np.ones((5, 5)) for i in range(10)] | ||
p2 = [np.ones((5, 5)) for i in range(10)] | ||
|
||
res = functional_utils.subtract_params(p1, p2) | ||
|
||
assert len(res) == 10 | ||
for i in range(5): | ||
for j in range(5): | ||
assert res[0][i, j] == 0 | ||
|
||
|
||
def test_get_neutral(): | ||
x = [np.ones((3, 4))] | ||
res = functional_utils.get_neutral(x) | ||
assert res[0].shape == x[0].shape | ||
assert res[0][0, 0] == 0 | ||
|
||
|
||
def test_divide_by(): | ||
x = [np.ones((3, 4))] | ||
res = functional_utils.divide_by(x, num_workers=10) | ||
assert res[0].shape == x[0].shape | ||
assert res[0][0, 0] == 0.1 |