Merge pull request #43 from alha02/add-more-tf-ops
Add tf ops: diag, diagm, size, chol
This commit is contained in:
commit
e3b432165c
@ -28,10 +28,13 @@ graph(::typeof(all), x, dim=nothing) = TensorFlow.reduce_all(x;axis=dim)
|
|||||||
graph(::typeof(any), x, dim=nothing) = TensorFlow.reduce_any(x;axis=dim)
|
graph(::typeof(any), x, dim=nothing) = TensorFlow.reduce_any(x;axis=dim)
|
||||||
graph(::typeof(mean), x, dim=nothing) = TensorFlow.reduce_mean(x;axis=dim)
|
graph(::typeof(mean), x, dim=nothing) = TensorFlow.reduce_mean(x;axis=dim)
|
||||||
graph(::typeof(svd), x) = svd(x)
|
graph(::typeof(svd), x) = svd(x)
|
||||||
|
graph(::typeof(size), x, dim) = TensorFlow.size(x,convert(Tensor{Int32}, dim))
|
||||||
|
graph(::typeof(size), x) = TensorFlow.size(x)
|
||||||
|
graph(::typeof(chol), args...) = TensorFlow.transpose(TensorFlow.cholesky(args...))
|
||||||
|
|
||||||
for op in (*, .*, .+, .^, log, exp, ceil, floor, sqrt, abs, cos,
|
for op in (*, .*, .+, .^, log, exp, ceil, floor, sqrt, abs, cos,
|
||||||
sin, tan, atan, asin, acos, tanh, lgamma, erf, erfc, real, imag, conj,
|
sin, tan, atan, asin, acos, tanh, lgamma, erf, erfc, real, imag, conj,
|
||||||
inv, det)
|
inv, det, transpose, permutedims, cat, length, diag, diagm)
|
||||||
@eval graph(::typeof($op), args...) = $op(args...)
|
@eval graph(::typeof($op), args...) = $op(args...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,6 +29,24 @@ end
|
|||||||
@test A ≈ u*diagm(s)*transpose(v)
|
@test A ≈ u*diagm(s)*transpose(v)
|
||||||
@test tf(@net x -> inv(x))(A) ≈ inv(A)
|
@test tf(@net x -> inv(x))(A) ≈ inv(A)
|
||||||
@test tf(@net x -> det(x))(A) ≈ det(A)
|
@test tf(@net x -> det(x))(A) ≈ det(A)
|
||||||
|
A = randn(Float32,(6,3))
|
||||||
|
@test tf(@net x -> transpose(x))(A) ≈ transpose(A)
|
||||||
|
A = randn(Float32,(6,3,2))
|
||||||
|
@test tf(@net (x,y) -> permutedims(x,y))(A,[3,2,1]) ≈ permutedims(A,[3,2,1])
|
||||||
|
A1 = randn(Float32,(4,1))
|
||||||
|
A2 = randn(Float32,(4,1))
|
||||||
|
@test tf(@net (x,y) -> cat(2,x,y))(A1,A2) ≈ cat(2,A1,A2)
|
||||||
|
@test tf(@net x -> length(x))(A1) == length(A1)
|
||||||
|
A = randn(Float32,(5,5))
|
||||||
|
@test tf(@net x -> diag(x))(A) ≈ diag(A)
|
||||||
|
A = randn(Float32,(5,))
|
||||||
|
@test tf(@net x -> diagm(x))(A) ≈ diagm(A)
|
||||||
|
A = randn(4,5)
|
||||||
|
@test tf(@net x -> size(x))(A) == [4,5]
|
||||||
|
@test tf(@net (x,y) -> size(x,y))(A,1) == 4
|
||||||
|
A = randn(6,5)
|
||||||
|
A = A'*A
|
||||||
|
@test tf(@net x -> chol(x))(A) ≈ chol(A)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user