Skip to content

Commit 6cd7d36

Browse files
committed
fix unittest warning for python3 and add submodule numpy-groupies
1 parent f1621d4 commit 6cd7d36

21 files changed

+26
-1938
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "thirdparty/numpy-groupies"]
2+
path = thirdparty/numpy-groupies
3+
url = https://github.com/ml31415/numpy-groupies

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ It's **an efficent Python-DNN Implementation used numpy mainly**, and it's aimed
2323
Mobula is implemented by only Python. You can modify the code easily to implement what you want.
2424

2525
## How to install it?
26+
- Git:
27+
```bash
28+
git clone https://github.com/wkcn/mobula --recursive
2629
```
30+
31+
- pip:
32+
```bash
2733
pip install mobula
2834
```
2935

mobula/layers/Concat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def reshape(self):
1111
ss = x.shape[self.axis]
1212
self.slices[i][self.axis] = slice(last, last + ss)
1313
last += ss
14+
self.slices = [tuple(s) for s in self.slices]
1415

1516
shp = list(self.X[0].shape)
1617
shp[self.axis] = last

mobula/layers/Crop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def reshape(self):
1616
assert len(self.offset) == n, "len(Crop.offset) must be the number of dims which will be cropped"
1717
self.axes = [slice(None)] * self.axis + [slice(o, o + self.R.Y.shape[i + self.axis]) for i, o in enumerate(self.offset)]
1818
def forward(self):
19-
self.Y = self.X[self.axes]
19+
self.Y = self.X[tuple(self.axes)]
2020
def backward(self):
2121
self.dX = np.zeros(self.X.shape)
22-
self.dX[self.axes] = self.dY
22+
self.dX[tuple(self.axes)] = self.dY

mobula/layers/Slice.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def reshape(self):
1919
self.Y[i] = self.X[s]
2020
s = slice(last, None)
2121
self.slices[-1][self.axis] = s
22+
self.slices = [tuple(s) for s in self.slices]
2223
self.Y[-1] = self.X[s]
2324
def forward(self):
2425
self.Y = [self.X[s] for s in self.slices]

mobula/layers/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
PATH = os.path.dirname(__file__)
55
sys.path.append(PATH)
6-
sys.path.append(PATH + "/../../thirdparty")
6+
thirdparties = ['numpy-groupies']
7+
for name in thirdparties:
8+
sys.path.append(os.path.join(PATH, '../../thirdparty/', name))
79

810
# Data Layer
911
from .Data import *

tests/test_layers/test_concat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def go_concat(axis):
2020
def G(s):
2121
w = [slice(None) for _ in range(4)]
2222
w[axis] = s
23-
return w
23+
return tuple(w)
2424
ssa = G(sa)
2525
ssb = G(sb)
2626
ssc = G(sc)

tests/test_layers/test_crop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ def test_crop():
1616
l = L.Crop([x1, x2], offset = offset, axis = axis)
1717
l.reshape()
1818
l.forward()
19-
assert np.allclose(l.Y, X1[w])
19+
assert np.allclose(l.Y, X1[tuple(w)])
2020
l.dY = np.random.random(l.Y.shape)
2121
l.backward()
2222
tmp = np.zeros(X1.shape)
23-
tmp[w] = l.dY
23+
tmp[tuple(w)] = l.dY
2424
assert np.allclose(l.dX, tmp)
2525

2626
def test_crop2():

tests/test_layers/test_slice.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def go_slice1(axis):
4545
axes2 = [slice(None)] * 4
4646
axes1[axis] = slice(None, slice_point)
4747
axes2[axis] = slice(slice_point, None)
48-
assert np.allclose(y1.Y, X[axes1])
49-
assert np.allclose(y2.Y, X[axes2])
48+
assert np.allclose(y1.Y, X[tuple(axes1)])
49+
assert np.allclose(y2.Y, X[tuple(axes2)])
5050

5151
y1.dY = np.random.random(y1.Y.shape)
5252
y2.dY = np.random.random(y2.Y.shape)
@@ -64,9 +64,9 @@ def go_slice2(axis):
6464
axes1[axis] = slice(None, 3)
6565
axes2[axis] = slice(3, 5)
6666
axes3[axis] = slice(5, None)
67-
assert np.allclose(y1.Y, X[axes1])
68-
assert np.allclose(y2.Y, X[axes2])
69-
assert np.allclose(y3.Y, X[axes3])
67+
assert np.allclose(y1.Y, X[tuple(axes1)])
68+
assert np.allclose(y2.Y, X[tuple(axes2)])
69+
assert np.allclose(y3.Y, X[tuple(axes3)])
7070

7171

7272
y1.dY = np.random.random(y1.Y.shape)

tests/test_layers/test_softmax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_softmax():
2222
axes[axis] = np.newaxis
2323
pu = [1] * 4
2424
pu[axis] = a.shape[axis]
25-
s = np.tile(su[axes], pu)
25+
s = np.tile(su[tuple(axes)], pu)
2626

2727
# softmax forward
2828
assert np.allclose(y, exp / s)

0 commit comments

Comments
 (0)