This package contains various torch extensions:
- concat : concatenates a table of tensors.
- find : finds all indices of a given value.
- group : sorts and groups similar tensor variables together.
- remap : recursively applies a function to tables of Tensors.
- md5 : used for hashing strings.
And some paths extensions :
- indexdir : index a directory of millions of files for faster listing.
Example:
> res = torch.concat({torch.rand(2,3),torch.randn(2,1),torch.randn(2,2)},2) > print(res) 0.8621 0.7776 0.3284 -1.2884 -0.4939 0.6049 0.8404 0.8996 0.5704 0.3911 -0.0428 -1.4627 [torch.DoubleTensor of dimension 2x6]1D example:
> res = torch.find(torch.Tensor{1,2,3,1,1,2}, 1) > unpack(res) 1 4 52D example:
> tensor = torch.Tensor{{1,2,3,4,5},{5,6,0.6,0,2}} > unpack(torch.find(tensor, 2)) 2 10 > unpack(torch.find(tensor:t(), 2)) 3 10 > unpack(torch.find(tensor, 2, 2)) {2} {5} > unpack(torch.find(tensor:t(), 2, 2)) { } {1} { } { } {2} Example:
> tensor = torch.Tensor{5,3,4,5,3,5} > res, val, idx = torch.group(tensor) > res { 3 : { idx : LongTensor - size: 2 val : DoubleTensor - size: 2 } 4 : { idx : LongTensor - size: 1 val : DoubleTensor - size: 1 } 5 : { idx : LongTensor - size: 3 val : DoubleTensor - size: 3 } }Example:
> t1 = {torch.randn(3,4), {torch.randn(3,4), torch.randn(2,4), {torch.randn(1)}}} > t2 = {torch.randn(3,4), {torch.randn(3,4), torch.randn(2,4), {torch.randn(1)}}} > torch.remap(t1, t2, function(x, y) x:add(y) end) { 1 : DoubleTensor - size: 3x4 2 : { 1 : DoubleTensor - size: 3x4 2 : DoubleTensor - size: 2x4 3 : { 1 : DoubleTensor - size: 1 } } } { 1 : DoubleTensor - size: 3x4 2 : { 1 : DoubleTensor - size: 3x4 2 : DoubleTensor - size: 2x4 3 : { 1 : DoubleTensor - size: 1 } } }It also creates missing tensors:
> t2, t3 = torch.remap(t2, nil, function(x, y) y:resizeAs(x):copy(x) end) > print(t3) { 1 : DoubleTensor - size: 3x4 2 : { 1 : DoubleTensor - size: 3x4 2 : DoubleTensor - size: 2x4 3 : { 1 : DoubleTensor - size: 1 } } }When in doubt, first tensor has priority:
> t4, t2 = torch.remap({torch.DoubleTensor()}, t2, function(x, y) x:resize(y:size()):copy(y) end, torch.LongTensor()) > print(t4) { 1 : DoubleTensor - size: 3x4 } > t2, t5 = torch.remap(t2, {torch.DoubleTensor()}, function(x, y) y:resize(x:size()):copy(x) end, torch.LongTensor()) > print(t5) { 1 : DoubleTensor - size: 3x4 2 : { 1 : LongTensor - size: 3x4 2 : LongTensor - size: 2x4 3 : { 1 : LongTensor - size: 1 } } }Pure Lua module copy-pasted from this repo (for some reasons I can't get git submodule to work with luarocks). The module includes two functions:
local md5_as_hex = torch.md5.sumhexa(message) -- returns a hex string local md5_as_data = torch.md5.sum(message) -- returns raw bytesThe torch.md5.sumhexa function takes a string and returns another string:
torch.md5.sumhexa('helloworld!') 420e57b017066b44e05ea1577f6e2e12This function can be used to create an object indexing all files having extensions ext (a string or a list thereof) in directory path (string or list thereof). Useful for directories containing many thousands of files. The function caches the resulting list to disk in /tmp such that it can be used for later calls when use_cache=true (default is false). Argument ignore species a pattern to ignore (e.g. "frame" will ignore all files containing "frame").