{"action":"created","issue":{"url":"https://api.github.com/repos/torch/torch7/issues/620","repository_url":"https://api.github.com/repos/torch/torch7","labels_url":"https://api.github.com/repos/torch/torch7/issues/620/labels{/name}","comments_url":"https://api.github.com/repos/torch/torch7/issues/620/comments","events_url":"https://api.github.com/repos/torch/torch7/issues/620/events","html_url":"https://github.com/torch/torch7/pull/620","id":144215614,"number":620,"title":"Add fmod(), remainder(), remove mod() and fix tensor operator % behavior","user":{"login":"liboyue","id":5857249,"avatar_url":"https://avatars.githubusercontent.com/u/5857249?v=3","gravatar_id":"","url":"https://api.github.com/users/liboyue","html_url":"https://github.com/liboyue","followers_url":"https://api.github.com/users/liboyue/followers","following_url":"https://api.github.com/users/liboyue/following{/other_user}","gists_url":"https://api.github.com/users/liboyue/gists{/gist_id}","starred_url":"https://api.github.com/users/liboyue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liboyue/subscriptions","organizations_url":"https://api.github.com/users/liboyue/orgs","repos_url":"https://api.github.com/users/liboyue/repos","events_url":"https://api.github.com/users/liboyue/events{/privacy}","received_events_url":"https://api.github.com/users/liboyue/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-03-29T09:56:41Z","updated_at":"2016-03-30T06:32:40Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/torch/torch7/pulls/620","html_url":"https://github.com/torch/torch7/pull/620","diff_url":"https://github.com/torch/torch7/pull/620.diff","patch_url":"https://github.com/torch/torch7/pull/620.patch"},"body":"To resolve https://github.com/torch/torch7/issues/607, I added `torch.fmod()`, `torch.cfmod()` for computing remainder of division (rounded towards zero) and `torch.remainder()`, `torch.cremainder()` for computing `a % b = a - b * floor(a/b)`.\r\n\r\n1. `torch.fmod()` and `torch.cfmod()` are the same as `torch.mod()` and `torch.fmod()`.\r\n2. `torch.remainder()` and `torch.cremainder()` compute remainders by `a - b * floor(a/b)` and it will return `nan` if `b == 0`. The function `remainder()` in the math library computes by `a - b * round(a/b)`. In my laptop, `torch.remainder()` is faster than `torch.fmod()`.\r\n```lua\r\nth> a = torch.Tensor(10000, 10000):uniform(-10, 10);\r\n                                                                      [0.9528s]\r\nth> b = torch.fmod(a, 2);\r\n                                                                      [1.0508s]\r\nth> c = torch.remainder(a, 2);\r\n                                                                      [0.5180s]\r\n```\r\n\r\n3. The tensor operator uses `THTensor_(mod)` as its backend. To make sure it's the same as Lua `%` operator I changed it with `THTensor_(remainder)`."},"comment":{"url":"https://api.github.com/repos/torch/torch7/issues/comments/203274008","html_url":"https://github.com/torch/torch7/pull/620#issuecomment-203274008","issue_url":"https://api.github.com/repos/torch/torch7/issues/620","id":203274008,"user":{"login":"andreaskoepf","id":9976399,"avatar_url":"https://avatars.githubusercontent.com/u/9976399?v=3","gravatar_id":"","url":"https://api.github.com/users/andreaskoepf","html_url":"https://github.com/andreaskoepf","followers_url":"https://api.github.com/users/andreaskoepf/followers","following_url":"https://api.github.com/users/andreaskoepf/following{/other_user}","gists_url":"https://api.github.com/users/andreaskoepf/gists{/gist_id}","starred_url":"https://api.github.com/users/andreaskoepf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreaskoepf/subscriptions","organizations_url":"https://api.github.com/users/andreaskoepf/orgs","repos_url":"https://api.github.com/users/andreaskoepf/repos","events_url":"https://api.github.com/users/andreaskoepf/events{/privacy}","received_events_url":"https://api.github.com/users/andreaskoepf/received_events","type":"User","site_admin":false},"created_at":"2016-03-30T06:32:40Z","updated_at":"2016-03-30T06:32:40Z","body":"Since C does not have a % operator for floating point values I would be fine with defining it as floored-mod for tensors.\r\n"}}