basic operations | 50% done | d = torch.ClTensor{{3,5,-2},{2.1,2.2,3.9}}
c = torch.ClTensor{{4,2,-1},{3.1,1.2,4.9}}
c:add(d)
c:csub(d) -- subtracts d from c, element-wise
-- similar to 'c - d'
-- but stores results into c
c:cmul(d)
c:cdiv(d)
c:add(3)
c:mul(3)
c:div(2)
c = torch.add(c,3)
c = torch.mul(c, 4)
c = torch.div(c, 3)
torch.pow(2,c)
c:pow(2)
torch.cpow(c,d)
torch.cdiv(c,d)
torch.pow(c,2)
torch.clamp(c, 50, 100)
c:clamp(50, 100)
-c
A = torch.ClTensor{{1,2,-1},
{3,4,0}}
B = torch.ClTensor{{0,1},
{1,2},
{4,5}}
print(torch.mm(A,B))
C:mm(A,B)
C = torch.ClTensor{{3,2},{9,7}}
D = torch.ClTensor{{3,1,7},{3,2,4}}
E = torch.ClTensor{{3,1},{2,9},{3,2}}
print(torch.addmm(C,D,E))
c = torch.ClTensor{3,2}
D = torch.ClTensor{{3,1,7},{3,2,4}}
e = torch.ClTensor{3,1,2}
print(torch.addmv(c,D,e))
v1 = torch.ClTensor{3,5,1}
v2 = torch.ClTensor{2,4,8}
print(torch.dot(v1, v2))
print(torch.mv(A,v1))
C = torch.ClTensor{{3,1,7},{3,2,4},{8,5,3}}
d = torch.ClTensor{3,2,5}
e = torch.ClTensor{3,1,2}
print(torch.addr(C,d,e))
a:cmin(b)
a:cmax(b)
a:cmin(0.6)
a:cmax(0.6)
|
Logical operations | Done | d = torch.ClTensor{{3,5,-2},{2.1,2.2,3.9}}
c = torch.ClTensor{{4,2,-1},{3.1,1.2,4.9}}
for _,name in ipairs({'lt','le','gt','ge','ne','eq'}) do
print(loadstring('return c:' .. name .. '(5)')())
end
for _,name in ipairs({'lt','le','gt','ge','ne','eq'}) do
print(loadstring('return torch.' .. name .. '(c,d)')())
end
torch.any(torch.Tensor({0,1,0}):cl())
torch.all(torch.Tensor({0,1,0}):cl())
|
Overloaded operators | 80% done | d = torch.ClTensor{{3,5,-2},{2.1,2.2,3.9}}
c = torch.ClTensor{{4,2,-1},{3.1,1.2,4.9}}
c = c + d
c = c - d
c = c / 2
c = c * 1.5
c = c + 4
c = c - 5
A = torch.ClTensor{{1,2,-1},
{3,4,0}}
B = torch.ClTensor{{0,1},
{1,2},
{4,5}}
print( A * B)
v1 = torch.ClTensor{3,5,1}
v2 = torch.ClTensor{2,4,8}
print(v1 * v2)
|
Column or row-wise operations | 30% done | A = torch.ClTensor{{3,5,2},{4,5,6}}
B = torch.ClTensor{{3,5,2},{4,5,6}}
A:sum()
A:sum(2)
A:sum(1)
A:mean()
A:mean(1)
A:mean(2)
A:sign()
A:norm()
A:norm(1)
A:norm(1,2)
A:norm(1,1)
torch.sign(A)
torch.atan2(A, B)
print(torch.prod(A))
print(A:prod())
print(A:prod(1))
print(A:prod(2))
A:max()
result, idx = A:max(1)
result, idx = A:max(2)
A:min()
result, idx = A:min(1)
result, idx = A:min(2)
torch.cumsum(x, 1)
torch.cumsum(x, 2)
torch.cumprod(x, 1)
torch.cumprod(x, 2)
|
Original, not in torch or cutorch | N/A | -- arbitrary apply/map
c:apply("x = sqrt(x + 3.5)")
-- note: a string, not a lua function
-- this will be passed to OpenCL kernel :-)
-- Update: in fact, this is available for cutorch :-)
-- It is here: https://github.com/szagoruyko/cutorch-rtc
c:map(d, "x = 1000 * x + y * 10")
-- note: a string, not a lua function
-- this will be passed to OpenCL kernel :-)
c:map2(d, e, "x = sqrt(1000 * x + y * 10 + z * z)")
-- note: a string, not a lua function
-- this will be passed to OpenCL kernel
-- Point tensors
c = torch.ClTensor({3,4,7})
a = torch.ClTensor()
a:sum(c) -- a is still a ClTensor, stays on GPU
a:prod(c) -- a is still a ClTensor, on GPU
a:min(c) -- a is ClTensor, on GPU
a:max(c) -- a is ClTensor, on GPU
a:all(c) -- a is ClTensor, on GPU
a:any(c) -- a is ClTensor, on GPU
c:add(a) -- can pass a into :add
c:csub(a) -- ... or csub
c:mul(a) -- ... or mul
c:div(a) -- ... or div
c:fill(a) -- ... or fill
c:lt(a) -- or any of the logical operators:
c:gt(a)
c:eq(a)
c:ne(a)
c:le(a)
c:ge(a)
-- optimization tools:
cltorch.setProfiling(1) -- turn on opencl kernel profiling
cltorch.dumpProfiling() -- dump opencl kernel profiling
-- timings since last call
cltorch.dumpTimings() -- dump cumulative wall-clock timings
-- for cltorch code
cltorch.setTrace(1) -- print all gpu buffer allocations
-- and copies between host/gpu
-- misc
cltorch.about() -- dump version/build information
|