-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03b498d
commit 3c4969a
Showing
3 changed files
with
54 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
|
||
|
||
function torch.find(tensor, val) | ||
if not torch.isTensor(tensor) then | ||
asTable = val | ||
val = tensor | ||
tensor = res | ||
if not asTable then | ||
res = torch.LongTensor() | ||
end | ||
end | ||
function torch.find(tensor, val, dim) | ||
local i = 1 | ||
local indice = {} | ||
tensor:apply(function(x) | ||
if dim then | ||
assert(tensor:dim() == 2, "torch.find dim arg only supports matrices for now") | ||
assert(dim == 2, "torch.find only supports dim=2 for now") | ||
|
||
local colSize, rowSize = tensor:size(1), tensor:size(2) | ||
local rowIndice = {} | ||
tensor:apply(function(x) | ||
if x == val then | ||
table.insert(rowIndice, i) | ||
end | ||
if i == rowSize then | ||
i = 1 | ||
table.insert(indice, rowIndice) | ||
rowIndice = {} | ||
else | ||
i = i + 1 | ||
end | ||
end) | ||
else | ||
tensor:apply(function(x) | ||
if x == val then | ||
table.insert(indice, i) | ||
end | ||
i = i + 1 | ||
end) | ||
end | ||
return indice | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters