Skip to content

Commit

Permalink
Allow for equal bounds in range
Browse files Browse the repository at this point in the history
  • Loading branch information
jucor committed Dec 12, 2012
1 parent 522f550 commit bbdab55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/TH/generic/THTensorMath.c
Expand Up @@ -659,7 +659,7 @@ void THTensor_(range)(THTensor *r_, real xmin, real xmax, real step)
real i = 0;

THArgCheck(step > 0 || step < 0, 3, "step must be a non-null number");
THArgCheck((step > 0) && (xmax > xmin) || (step < 0) && (xmax < xmin), 2, "upper bound and larger bound incoherent with step sign");
THArgCheck((step > 0) && (xmax >= xmin) || (step < 0) && (xmax <= xmin), 2, "upper bound and larger bound incoherent with step sign");

size = (long)((xmax-xmin)/step+1);

Expand Down
8 changes: 8 additions & 0 deletions pkg/torch/test/test.lua
Expand Up @@ -105,6 +105,14 @@ function torchtest.rangenegative()
torch.range(mxx,1,0,-1)
mytester:asserteq(maxdiff(mx,mxx),0,'torch.range value for negative step')
end
function torchtest.rangeequalbounds()
local mx = torch.Tensor({1})
local mxx = torch.Tensor()
torch.range(mxx,1,1,-1)
mytester:asserteq(maxdiff(mx,mxx),0,'torch.range value for equal bounds step')
torch.range(mxx,1,1,1)
mytester:asserteq(maxdiff(mx,mxx),0,'torch.range value for equal bounds step')
end
function torchtest.randperm()
local t=os.time()
torch.manualSeed(t)
Expand Down

0 comments on commit bbdab55

Please sign in to comment.