diff options
author | Soumith Chintala <soumith@gmail.com> | 2016-11-17 02:20:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-17 02:20:57 +0300 |
commit | 857f6d218470fb0329a7398a55b39af0a10d6b63 (patch) | |
tree | 5324d94ddbf00e3acdd40d066fbaab1535f2743f /test | |
parent | 6d6fe2061c79ada02ffd15e5314472d65640f498 (diff) | |
parent | d708c93857ca25fb4f96bd51e95079b0b4ce09ea (diff) |
Merge pull request #603 from killeent/remainder
Implement fmod, remainder, equal in Cutorch
Diffstat (limited to 'test')
-rw-r--r-- | test/test.lua | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/test/test.lua b/test/test.lua index c508d5d..ba6c44a 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1001,6 +1001,81 @@ function test.addcdiv() checkMultiDevice(r, 'addcdiv', x, torch.uniform(), y, z) end +function test.fmod() + local sz1 = chooseInt(minsize, maxsize) + local sz2 = chooseInt(minsize, maxsize) + local x = torch.FloatTensor():randn(sz1, sz2) + x:apply(function(x) + x = x * torch.random(1, 100) + return x + end) + local r = torch.normal(0, 25) + print(x, r) + + for _, typename in ipairs(typenames) do + local x = x:type(t2cpu[typename]) + compareCPUAndCUDATypeTensorArgs(typename, nil, x, 'fmod', r) + end +end + +function test.remainder() + local sz1 = chooseInt(minsize, maxsize) + local sz2 = chooseInt(minsize, maxsize) + local x = torch.FloatTensor():randn(sz1, sz2) + x:apply(function(x) + x = x * torch.random(1, 100) + return x + end) + local r = torch.normal(0, 25) + print(x, r) + + for _, typename in ipairs(typenames) do + local x = x:type(t2cpu[typename]) + compareCPUAndCUDATypeTensorArgs(typename, nil, x, 'remainder', r) + end +end + +function test.equal() + -- empty tensors are equal + local x = torch.FloatTensor() + local y = torch.FloatTensor() + + for _, typename in ipairs(typenames) do + local a = x:type(typename) + local b = y:type(typename) + tester:assert(a:equal(b), 'Empty Tensors should be considered equal') + end + + -- mismatched size tensors are not equal + local x = torch.FloatTensor(5):fill(1) + local y = torch.FloatTensor(3):fill(1) + + for _, typename in ipairs(typenames) do + local a = x:type(typename) + local b = y:type(typename) + tester:assert(not a:equal(b), 'Tensors of different sizes not equal') + end + + -- tensors of same size but different value are not equal + local sz1 = chooseInt(minsize, maxsize) + local sz2 = chooseInt(minsize, maxsize) + local x = torch.FloatTensor(sz1, sz2):apply(function() return torch.random(0, 255) end) + local y = torch.add(x, 1) + + for _, typename in ipairs(typenames) do + local a = x:type(typename) + local b = y:type(typename) + tester:assert(not a:equal(b), 'Tensors should not be equal') + end + + -- actual equality + for _, typename in ipairs(typenames) do + local a = x:type(typename) + local b = x:type(typename) + tester:assert(a:equal(b), 'Tensors should be equal') + end +end + function test.logicalValue() local sz1 = chooseInt(minsize, maxsize) local sz2 = chooseInt(minsize, maxsize) |