Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9e8fbfa
add .DS_Store to .gitignore
nahuakang Oct 1, 2017
43f31a6
add index method and unittest
nahuakang Oct 2, 2017
9872dac
adjust .gitignore to upstream/master
nahuakang Oct 2, 2017
a35d8b6
add fmod and fmod_ methods to tensor.py
nahuakang Oct 2, 2017
26a0849
add unittests to fmod and fmod_ methods
nahuakang Oct 2, 2017
d8ac5fb
alter .gitignore to fit pull request
nahuakang Oct 2, 2017
1b7d853
modify .gitignore before pull upstream master
nahuakang Oct 2, 2017
7f8eefe
remove index method before pull upstream master
nahuakang Oct 2, 2017
181ea05
remove unit test for index method before pull upstream master
nahuakang Oct 2, 2017
a972dcc
align with upstream/master/.gitignore
nahuakang Oct 2, 2017
20f856b
Merge branch 'master' into func-fmod
nahuakang Oct 3, 2017
bac100e
add PEP8 style pytest in Makefile
aiorla Oct 3, 2017
7cbb256
add .DS_Store to .gitignore
nahuakang Oct 1, 2017
8469bb5
adjust .gitignore to upstream/master
nahuakang Oct 2, 2017
8075a04
add fmod and fmod_ methods to tensor.py
nahuakang Oct 2, 2017
0549c3f
add unittests to fmod and fmod_ methods
nahuakang Oct 2, 2017
a5ab808
alter .gitignore to fit pull request
nahuakang Oct 2, 2017
e8c0214
commit .gitignore again
nahuakang Oct 3, 2017
a27550a
add test_tensor.py with changes
nahuakang Oct 3, 2017
4a51146
add new line to .gitignore
nahuakang Oct 3, 2017
d7cb73e
fix some flake8 style issues
nahuakang Oct 3, 2017
cf32eff
fix flake8 style issues
nahuakang Oct 3, 2017
6ad663b
fix flake8 style issue
nahuakang Oct 3, 2017
d2d6375
fixing another flake8 style issue
nahuakang Oct 3, 2017
ec42d43
fix another flake8 issue
nahuakang Oct 3, 2017
533dc53
Merge branch 'master' into func-fmod
iamtrask Oct 3, 2017
71a644b
fix and move fmod method to math.py
nahuakang Oct 3, 2017
ea86d9a
fix fmod_ method to call syft.math.fmod method for inline operation
nahuakang Oct 3, 2017
16bcfd3
fix and move fmodTest to test_math.py
nahuakang Oct 3, 2017
c06f8cb
remove fmodTest from test_tensor.py
nahuakang Oct 3, 2017
6cdcd34
fix FLAKE8 issue with no newline at the end of test_math.py
nahuakang Oct 3, 2017
936431c
Merge branch 'master' into func-fmod
bharathgs Oct 4, 2017
4bd4c31
add fmod to syft/__init__.py
nahuakang Oct 4, 2017
453ab48
edit doc convention of syft/math.py
nahuakang Oct 4, 2017
fcaac45
edit doc convention of syft/tensor.py
nahuakang Oct 4, 2017
1d80b3a
resolve conflict from git pull upstream master with func-fmod
nahuakang Oct 4, 2017
bb195d5
resolve conflict with git pull origin func-fmod
nahuakang Oct 4, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion syft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from syft.tensor import equal, TensorBase
from syft.math import cumprod, cumsum, ceil, dot, matmul, addmm, addcmul
from syft.math import addcdiv, addmv, bmm, addbmm, baddbmm, transpose
from syft.math import unsqueeze, zeros, ones, rand, randn, mm
from syft.math import unsqueeze, zeros, ones, rand, randn, mm, fmod

s = str(he)
s += str(nn)
Expand All @@ -19,3 +19,4 @@
s += str(transpose) + str(rand) + str(randn) + str(ones) + str(zeros)
s += str(unsqueeze)
s += str(mm)
s += str(fmod)
26 changes: 26 additions & 0 deletions syft/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,29 @@ def mm(tensor1, tensor2):
return NotImplemented
else:
return TensorBase(np.array(np.matmul(tensor1.data, tensor2.data)))


def fmod(tensor, divisor):
"""
Performs the element-wise division of tensor by divisor.

Parameters
----------
tensor: TensorBase

divisor: number or TensorBase

Returns
-------
TensorBase:
Output Tensor
"""
if tensor.encrypted:
return NotImplemented

if isinstance(divisor, TensorBase):
if divisor.encrypted:
return NotImplemented
divisor = divisor.data

return TensorBase(np.fmod(tensor.data, divisor))
24 changes: 24 additions & 0 deletions syft/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2981,6 +2981,30 @@ def mm(self, tensor):

return syft.mm(self, tensor)

def fmod_(self, divisor):
"""
Performs the element-wise division of tensor by divisor.

Parameters
----------
divisor: number or TensorBase

Returns
-------
TensorBase:
Output Tensor
"""
if self.encrypted:
return NotImplemented

if isinstance(divisor, TensorBase):
if divisor.encrypted:
return NotImplemented

self.data = syft.math.fmod(self, divisor)

return self


def mv(tensormat, tensorvector):
"""
Expand Down
16 changes: 16 additions & 0 deletions tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,19 @@ def test_mm_3d(self):
out = syft.mm(t1, t2)
self.assertTrue(np.alltrue(
out.data == [[5, 8, 11], [8, 13, 18], [11, 18, 25]]))


class fmodTest(unittest.TestCase):
def test_fmod_number(self):
t1 = TensorBase(np.array([-3, -2, -1, 1, 2, 3]))
self.assertTrue(np.array_equal(syft.math.fmod(t1, 2).data, np.array([-1, 0, -1, 1, 0, 1])))
t2 = TensorBase(np.array([-3.5, -2.5, -1.5, 1.5, 2.5, 3.5]))
self.assertTrue(np.array_equal(syft.math.fmod(t2, 2.).data, np.array([-1.5, -0.5, -1.5, 1.5, 0.5, 1.5])))

def test_fmod_tensor(self):
t1 = TensorBase(np.array([-3, -2, -1, 1, 2, 3]))
divisor = np.array([2] * 6)
self.assertTrue(np.array_equal(syft.math.fmod(t1, divisor).data, np.array([-1, 0, -1, 1, 0, 1])))
t2 = TensorBase(np.array([-3.5, -2.5, -1.5, 1.5, 2.5, 3.5]))
divisor = np.array([2.] * 6)
self.assertTrue(np.array_equal(syft.math.fmod(t2, divisor).data, np.array([-1.5, -0.5, -1.5, 1.5, 0.5, 1.5])))
20 changes: 20 additions & 0 deletions tests/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,5 +1119,25 @@ def test_mm_3d(self):
self.assertTrue(np.alltrue(out.data == [[5, 8, 11], [8, 13, 18], [11, 18, 25]]))


class fmod_Test(unittest.TestCase):
def test_fmod_number(self):
t1 = TensorBase(np.array([-3, -2, -1, 1, 2, 3]))
t1.fmod_(2)
self.assertTrue(np.array_equal(t1.data, np.array([-1, 0, -1, 1, 0, 1])))
t2 = TensorBase(np.array([-3.5, -2.5, -1.5, 1.5, 2.5, 3.5]))
t2.fmod_(2.)
self.assertTrue(np.array_equal(t2.data, np.array([-1.5, -0.5, -1.5, 1.5, 0.5, 1.5])))

def test_fmod_tensor(self):
t1 = TensorBase(np.array([-3, -2, -1, 1, 2, 3]))
divisor = np.array([2] * 6)
t1.fmod_(divisor)
self.assertTrue(np.array_equal(t1.data, np.array([-1, 0, -1, 1, 0, 1])))
t2 = TensorBase(np.array([-3.5, -2.5, -1.5, 1.5, 2.5, 3.5]))
divisor = np.array([2.] * 6)
t2.fmod_(divisor)
self.assertTrue(np.array_equal(t2.data, np.array([-1.5, -0.5, -1.5, 1.5, 0.5, 1.5])))


if __name__ == "__main__":
unittest.main()