Skip to content

Commit

Permalink
Added test support
Browse files Browse the repository at this point in the history
  • Loading branch information
vnmabus committed Sep 20, 2017
1 parent 4fb5a08 commit 0d9c966
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python
python:
- "2.6"
- "2.7"
- "3.5"
- "3.6"
install:
- "pip install -r requirements.txt --use-mirrors"
script:
- "python setup.py test"
17 changes: 8 additions & 9 deletions dcor/dcor.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,13 @@ def _can_use_u_fast_algorithm(x, y):


@numba.jit
def _dyad_update(Y, C):
def _dyad_update(y, c):

Y = np.asarray(Y)
C = np.asarray(C)

n = Y.shape[0]
n = y.shape[0]
gamma = np.zeros(n)

# Step 1: get the smallest L such that n <= 2^L
L = int(math.ceil(math.log(n, 2)))
L = int(math.ceil(np.log2(n)))

# Step 2: assign s(l, k) = 0
S_len = 2 ** (L + 1)
Expand All @@ -480,17 +477,17 @@ def _dyad_update(Y, C):

# Step 3.a: update s(l, k)
for l in range(L):
k = int(math.ceil(Y[i - 1] / 2 ** l))
k = int(math.ceil(y[i - 1] / 2 ** l))
pos = k - 1

if l > 0:
pos += pos_sums[l - 1]

S[pos] += C[i - 1]
S[pos] += c[i - 1]

# Steps 3.b and 3.c
for l in range(L):
k = int(math.floor((Y[i] - 1) / 2 ** l))
k = int(math.floor((y[i] - 1) / 2 ** l))
if k / 2 > math.floor(k / 2):
pos = k - 1
if l > 0:
Expand Down Expand Up @@ -536,6 +533,8 @@ def _partial_sum_2d(x, y, c):
c_dot = np.sum(c)

# Step 6
y = np.asarray(y)
c = np.asarray(c)
gamma1 = _dyad_update(y, c)

# Step 7
Expand Down
4 changes: 2 additions & 2 deletions dcor/tests/test_dcor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def test_average_product(self):
self.assertAlmostEqual(result, 0)

def test_dyad_update(self):
Y = [1, 2, 3]
C = [4, 5, 6]
Y = np.array([1, 2, 3])
C = np.array([4, 5, 6])

gamma = dc._dyad_update(Y, C)
expected_gamma = [0., 4., 9.]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy==1.12.1
numba==0.32.0
scipy==0.19.0
numpy==1.12.1
setuptools==36.4.0
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[aliases]
test=pytest
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
author_email='vnmabus@gmail.com',
license='MIT',
packages=['dcor'],
setup_requires=['pytest-runner'],
tests_require=['pytest'],
test_suite='dcor.tests',
zip_safe=False)

0 comments on commit 0d9c966

Please sign in to comment.