andresy/torch — pull request #100 by jucor (2013-01-08 17:56:27+00:00)
Title: Fix boundary cases in logspace() and linspace()

For any a < b:
torch.linspace(a, a, 1) returns a 1-dim tensor of a, instead of nan
torch.linspace(a, b, 1) throws an error, instead of returning nan
torch.logspace(a, a, 1) returns a 1-dim tensor of 10^a, instead of nan
torch.logspace(a, b, 1) throws an error, instead of returning nan
torch.test() checks the 4 asserts above.

```
Try the IDE: torch -ide
Type help() for more info
Torch 7.0 Copyright (C) 2001-2011 Idiap, NEC Labs, NYU
Lua 5.1 Copyright (C) 1994-2008 Lua.org, PUC-Rio
t7> =linspace(1,1,1)
[string "return linspace(1,1,1)"]:1: attempt to call global 'linspace' (a nil value)
stack traceback:
[string "return linspace(1,1,1)"]:1: in main chunk
[C]: ?
t7> ^D
Really quit [y/N]? y
[julien@stmartin torch (LinspaceFix)]$ torch
Try the IDE: torch -ide
Type help() for more info
Torch 7.0 Copyright (C) 2001-2011 Idiap, NEC Labs, NYU
Lua 5.1 Copyright (C) 1994-2008 Lua.org, PUC-Rio
t7> =torch.linspace(0,1,1) -- used to be accepted and return nan due to divide-by-0
bad argument #3 to '?' (invalid number of points)
stack traceback:
[C]: ?
[C]: in function 'linspace'
[string "return torch.linspace(0,1,1) -- used to be ..."]:1: in main chunk
[C]: ?
t7> =torch.linspace(0,0,1) -- used to return nan due to divide-by-0
0
[torch.DoubleTensor of dimension 1]

t7> =torch.logspace(0,1,1) -- used to be accepted and return nan due to divide-by-0
bad argument #3 to '?' (invalid number of points)
stack traceback:
[C]: ?
[C]: in function 'logspace'
[string "return torch.logspace(0,1,1) -- used to be ..."]:1: in main chunk
[C]: ?
t7> =torch.logspace(0,0,1) -- used to be accepted and return nan due to divide-by-0
1
[torch.DoubleTensor of dimension 1]

t7> torch.test()
Running 34 tests
__________________________________ ==> Done

Completed 79 asserts in 34 tests with 0 errors

--------------------------------------------------------------------------------
t7>
```