-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '66f5d391a6ef01834658ec9d5a9a8ba3d4b0f827' into kmp5/fea…
…ture/FieldTypes
- Loading branch information
Showing
103 changed files
with
2,104 additions
and
938 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
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,7 +1,7 @@ | ||
name = "NDTensors" | ||
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" | ||
authors = ["Matthew Fishman <[email protected]>"] | ||
version = "0.2.14" | ||
version = "0.2.15" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
|
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,8 +1,24 @@ | ||
function Base.getindex(::Type{<:CuArray}, T::DenseTensor{<:Number}) | ||
return CUDA.@allowscalar data(T)[] | ||
function Base.getindex(E::Exposed{<:CuArray}) | ||
return CUDA.@allowscalar unexpose(E)[] | ||
end | ||
|
||
function Base.setindex!(::Type{<:CuArray}, T::DenseTensor{<:Number}, x::Number) | ||
CUDA.@allowscalar data(T)[] = x | ||
return T | ||
function setindex!(E::Exposed{<:CuArray}, x::Number) | ||
CUDA.@allowscalar unexpose(E)[] = x | ||
return unexpose(E) | ||
end | ||
|
||
function Base.getindex(E::Exposed{<:CuArray,<:Adjoint}, I...) | ||
Ap = parent(E) | ||
return expose(Ap)[I...] | ||
end | ||
|
||
function Base.copy(E::Exposed{<:CuArray,<:Base.ReshapedArray}) | ||
Ap = parent(E) | ||
return copy(expose(Ap)) | ||
end | ||
|
||
Base.any(f, E::Exposed{<:CuArray,<:NDTensors.Tensor}) = any(f, data(unexpose(E))) | ||
|
||
function Base.print_array(io::IO, E::Exposed{<:CuArray}) | ||
return Base.print_array(io, expose(NDTensors.cpu(E))) | ||
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This circumvents an issues that `MtlArray` can't call `resize!`. | ||
# TODO: Raise an issue with Metal.jl. | ||
function NDTensors.append!!(::Type{<:MtlArray}, collection, collections...) | ||
return vcat(collection, collections...) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import NDTensors: mtl, set_ndims, set_eltype, set_eltype_if_unspecified | ||
import NDTensors.SetParameters: nparameters, get_parameter, set_parameter, default_parameter | ||
|
||
using NDTensors.Unwrap: Exposed, unwrap_type, unexpose, expose | ||
using Metal: DefaultStorageMode | ||
using NDTensors: adapt |
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,8 +1,8 @@ | ||
function Base.getindex(::Type{<:MtlArray}, T::DenseTensor{<:Number}) | ||
return Metal.@allowscalar data(T)[] | ||
function Base.getindex(E::Exposed{<:MtlArray}) | ||
return Metal.@allowscalar unexpose(E)[] | ||
end | ||
|
||
function Base.setindex!(::Type{<:MtlArray}, T::DenseTensor{<:Number}, x::Number) | ||
Metal.@allowscalar data(T)[] = x | ||
return T | ||
function Base.setindex!(E::Exposed{<:MtlArray}, x::Number) | ||
Metal.@allowscalar unexpose(E)[] = x | ||
return unexpose(E) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
function NDTensors.qr(leaf_parenttype::Type{<:MtlArray}, A::AbstractMatrix) | ||
Q, R = NDTensors.qr(NDTensors.cpu(A)) | ||
return adapt(leaf_parenttype, Matrix(Q)), adapt(leaf_parenttype, R) | ||
function LinearAlgebra.qr(A::Exposed{<:MtlMatrix}) | ||
Q, R = qr(expose(NDTensors.cpu(A))) | ||
return adapt(unwrap_type(A), Matrix(Q)), adapt(unwrap_type(A), R) | ||
end | ||
|
||
function NDTensors.eigen(leaf_parenttype::Type{<:MtlArray}, A::AbstractMatrix) | ||
D, U = NDTensors.eigen(NDTensors.cpu(A)) | ||
return adapt(set_ndims(leaf_parenttype, ndims(D)), D), adapt(leaf_parenttype, U) | ||
function NDTensors.Unwrap.qr_positive(A::Exposed{<:MtlMatrix}) | ||
Q, R = qr_positive(expose(NDTensors.cpu(A))) | ||
return adapt(unwrap_type(A), Matrix(Q)), adapt(unwrap_type(A), R) | ||
end | ||
|
||
function NDTensors.svd(leaf_parenttype::Type{<:MtlArray}, A::AbstractMatrix) | ||
U, S, V = NDTensors.svd(NDTensors.cpu(A)) | ||
return adapt(leaf_parenttype, U), | ||
adapt(set_ndims(leaf_parenttype, ndims(S)), S), | ||
adapt(leaf_parenttype, V) | ||
function NDTensors.Unwrap.ql(A::Exposed{<:MtlMatrix}) | ||
Q, L = ql(expose(NDTensors.cpu(A))) | ||
return adapt(unwrap_type(A), Matrix(Q)), adapt(unwrap_type(A), L) | ||
end | ||
function NDTensors.Unwrap.ql_positive(A::Exposed{<:MtlMatrix}) | ||
Q, L = ql_positive(expose(NDTensors.cpu(A))) | ||
return adapt(unwrap_type(A), Matrix(Q)), adapt(unwrap_type(A), L) | ||
end | ||
|
||
function LinearAlgebra.eigen(A::Exposed{<:MtlMatrix}) | ||
D, U = eigen(expose(NDTensors.cpu(A))) | ||
return adapt(set_ndims(unwrap_type(A), ndims(D)), D), adapt(unwrap_type(A), U) | ||
end | ||
|
||
function LinearAlgebra.svd(A::Exposed{<:MtlMatrix}; kwargs...) | ||
U, S, V = svd(expose(NDTensors.cpu(A)); kwargs...) | ||
return adapt(unwrap_type(A), U), | ||
adapt(set_ndims(unwrap_type(A), ndims(S)), S), | ||
adapt(unwrap_type(A), V) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This was calling generic matrix multiplication. | ||
# TODO: Raise an issue with `Metal.jl`. | ||
function LinearAlgebra.mul!( | ||
CM::Exposed{<:MtlArray,<:Transpose}, | ||
AM::Exposed{<:MtlArray}, | ||
BM::Exposed{<:MtlArray}, | ||
α, | ||
β, | ||
) | ||
mul!(transpose(CM), transpose(BM), transpose(AM), α, β) | ||
return unexpose(CM) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
function NDTensors.permutedims!( | ||
::Type{<:MtlArray}, | ||
Adest::Base.ReshapedArray{<:Any,<:Any,<:SubArray}, | ||
::Type{<:MtlArray}, | ||
A, | ||
perm, | ||
function permutedims!( | ||
Edest::Exposed{<:MtlArray,<:Base.ReshapedArray}, Esrc::Exposed{<:MtlArray}, perm | ||
) | ||
Aperm = permutedims(A, perm) | ||
Adest_parent = parent(Adest) | ||
copyto!(Adest_parent, Aperm) | ||
return Adest | ||
Aperm = permutedims(Esrc, perm) | ||
copyto!(expose(parent(Edest)), expose(Aperm)) | ||
return unexpose(Edest) | ||
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# DiagonalArrays.jl | ||
|
||
A Julia `DiagonalArray` type. | ||
|
||
````julia | ||
using NDTensors.DiagonalArrays: | ||
DiagonalArray, | ||
DiagIndex, | ||
DiagIndices, | ||
densearray | ||
|
||
d = DiagonalArray([1.0, 2, 3], 3, 4, 5) | ||
@show d[1, 1, 1] == 1 | ||
@show d[2, 2, 2] == 2 | ||
@show d[1, 2, 1] == 0 | ||
|
||
d[2, 2, 2] = 22 | ||
@show d[2, 2, 2] == 22 | ||
|
||
@show length(d[DiagIndices()]) == 3 | ||
@show densearray(d) == d | ||
@show d[DiagIndex(2)] == d[2, 2, 2] | ||
|
||
d[DiagIndex(2)] = 222 | ||
@show d[2, 2, 2] == 222 | ||
|
||
a = randn(3, 4, 5) | ||
new_diag = randn(3) | ||
a[DiagIndices()] = new_diag | ||
d[DiagIndices()] = a[DiagIndices()] | ||
|
||
@show a[DiagIndices()] == new_diag | ||
@show d[DiagIndices()] == new_diag | ||
```` | ||
|
||
You can generate this README with: | ||
```julia | ||
using Literate | ||
Literate.markdown("examples/README.jl", "."; flavor=Literate.CommonMarkFlavor()) | ||
``` | ||
|
||
--- | ||
|
||
*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* | ||
|
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# # DiagonalArrays.jl | ||
# | ||
# A Julia `DiagonalArray` type. | ||
|
||
using NDTensors.DiagonalArrays: DiagonalArray, DiagIndex, DiagIndices, densearray | ||
|
||
d = DiagonalArray([1.0, 2, 3], 3, 4, 5) | ||
@show d[1, 1, 1] == 1 | ||
@show d[2, 2, 2] == 2 | ||
@show d[1, 2, 1] == 0 | ||
|
||
d[2, 2, 2] = 22 | ||
@show d[2, 2, 2] == 22 | ||
|
||
@show length(d[DiagIndices()]) == 3 | ||
@show densearray(d) == d | ||
@show d[DiagIndex(2)] == d[2, 2, 2] | ||
|
||
d[DiagIndex(2)] = 222 | ||
@show d[2, 2, 2] == 222 | ||
|
||
a = randn(3, 4, 5) | ||
new_diag = randn(3) | ||
a[DiagIndices()] = new_diag | ||
d[DiagIndices()] = a[DiagIndices()] | ||
|
||
@show a[DiagIndices()] == new_diag | ||
@show d[DiagIndices()] == new_diag | ||
|
||
# You can generate this README with: | ||
# ```julia | ||
# using Literate | ||
# Literate.markdown("examples/README.jl", "."; flavor=Literate.CommonMarkFlavor()) | ||
# ``` |
Oops, something went wrong.