-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add LinearAlgebraExt #86
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
71425d9
add LinearAlgebraExt
longemen3000 3b4bf8f
move usage of LinearAlgebra into conditional loading
longemen3000 1c4a492
add `<0.0.1` in compat, typo in ext
longemen3000 01e1739
typo in extension include
longemen3000 ad3df52
another typo in ext include
longemen3000 6988031
add conditional test on getfields([])
longemen3000 2596c4b
Update test/runtests.jl
longemen3000 7d953c6
Update runtests.jl
longemen3000 b7ee255
use LinearAlgebra unconditionally
longemen3000 6947d65
Merge branch 'master' of /~https://github.com/JuliaObjects/Construction…
longemen3000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module ConstructionBaseLinearAlgebraExt | ||
|
||
if isdefined(Base, :get_extension) | ||
import ConstructionBase | ||
import LinearAlgebra | ||
else | ||
import ..ConstructionBase | ||
import ..LinearAlgebra | ||
end | ||
|
||
### Tridiagonal | ||
|
||
function tridiagonal_constructor(dl::V, d::V, du::V) where {V<:AbstractVector{T}} where T | ||
LinearAlgebra.Tridiagonal{T,V}(dl, d, du) | ||
end | ||
function tridiagonal_constructor(dl::V, d::V, du::V, du2::V) where {V<:AbstractVector{T}} where T | ||
LinearAlgebra.Tridiagonal{T,V}(dl, d, du, du2) | ||
end | ||
|
||
# `du2` may be undefined, so we need a custom `getfields` that checks `isdefined` | ||
function ConstructionBase.getfields(o::LinearAlgebra.Tridiagonal) | ||
if isdefined(o, :du2) | ||
(dl=o.dl, d=o.d, du=o.du, du2=o.du2) | ||
else | ||
(dl=o.dl, d=o.d, du=o.du) | ||
end | ||
end | ||
|
||
ConstructionBase.constructorof(::Type{<:LinearAlgebra.Tridiagonal}) = tridiagonal_constructor | ||
|
||
### Cholesky | ||
|
||
ConstructionBase.setproperties(C::LinearAlgebra.Cholesky, patch::NamedTuple{()}) = C | ||
|
||
function ConstructionBase.setproperties(C::LinearAlgebra.Cholesky, patch::NamedTuple{(:L,),<:Tuple{<:LinearAlgebra.LowerTriangular}}) | ||
return LinearAlgebra.Cholesky(C.uplo === 'U' ? copy(patch.L.data') : patch.L.data, C.uplo, C.info) | ||
end | ||
function ConstructionBase.setproperties(C::LinearAlgebra.Cholesky, patch::NamedTuple{(:U,),<:Tuple{<:LinearAlgebra.UpperTriangular}}) | ||
return LinearAlgebra.Cholesky(C.uplo === 'L' ? copy(patch.U.data') : patch.U.data, C.uplo, C.info) | ||
end | ||
function ConstructionBase.setproperties( | ||
C::LinearAlgebra.Cholesky, | ||
patch::NamedTuple{(:UL,),<:Tuple{<:Union{LinearAlgebra.LowerTriangular,LinearAlgebra.UpperTriangular}}} | ||
) | ||
return LinearAlgebra.Cholesky(patch.UL.data, C.uplo, C.info) | ||
end | ||
function ConstructionBase.setproperties(C::LinearAlgebra.Cholesky, patch::NamedTuple) | ||
throw(ArgumentError("Invalid patch for `Cholesky`: $(patch)")) | ||
end | ||
|
||
end #module |
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,4 +1,3 @@ | ||
using LinearAlgebra | ||
|
||
### SubArray | ||
# `offset1` and `stride1` fields are calculated from parent indices. | ||
|
@@ -28,24 +27,7 @@ end | |
constructorof(::Type{<:PermutedDimsArray{<:Any,N,perm,iperm,<:Any}}) where {N,perm,iperm} = | ||
PermutedDimsArrayConstructor{N,perm,iperm}() | ||
|
||
### Tridiagonal | ||
function tridiagonal_constructor(dl::V, d::V, du::V) where {V<:AbstractVector{T}} where T | ||
Tridiagonal{T,V}(dl, d, du) | ||
end | ||
function tridiagonal_constructor(dl::V, d::V, du::V, du2::V) where {V<:AbstractVector{T}} where T | ||
Tridiagonal{T,V}(dl, d, du, du2) | ||
end | ||
|
||
# `du2` may be undefined, so we need a custom `getfields` that checks `isdefined` | ||
function getfields(o::Tridiagonal) | ||
if isdefined(o, :du2) | ||
(dl=o.dl, d=o.d, du=o.du, du2=o.du2) | ||
else | ||
(dl=o.dl, d=o.d, du=o.du) | ||
end | ||
end | ||
|
||
constructorof(::Type{<:LinearAlgebra.Tridiagonal}) = tridiagonal_constructor | ||
|
||
### LinRange | ||
# `lendiv` is a calculated field | ||
|
@@ -57,20 +39,7 @@ constructorof(::Type{<:LinRange}) = linrange_constructor | |
# ::Expr annotation is to make it type-stable on Julia 1.3- | ||
constructorof(::Type{<:Expr}) = (head, args) -> Expr(head, args...)::Expr | ||
|
||
### Cholesky | ||
setproperties(C::LinearAlgebra.Cholesky, patch::NamedTuple{()}) = C | ||
function setproperties(C::LinearAlgebra.Cholesky, patch::NamedTuple{(:L,),<:Tuple{<:LinearAlgebra.LowerTriangular}}) | ||
return LinearAlgebra.Cholesky(C.uplo === 'U' ? copy(patch.L.data') : patch.L.data, C.uplo, C.info) | ||
end | ||
function setproperties(C::LinearAlgebra.Cholesky, patch::NamedTuple{(:U,),<:Tuple{<:LinearAlgebra.UpperTriangular}}) | ||
return LinearAlgebra.Cholesky(C.uplo === 'L' ? copy(patch.U.data') : patch.U.data, C.uplo, C.info) | ||
end | ||
function setproperties( | ||
C::LinearAlgebra.Cholesky, | ||
patch::NamedTuple{(:UL,),<:Tuple{<:Union{LinearAlgebra.LowerTriangular,LinearAlgebra.UpperTriangular}}} | ||
) | ||
return LinearAlgebra.Cholesky(patch.UL.data, C.uplo, C.info) | ||
end | ||
function setproperties(C::LinearAlgebra.Cholesky, patch::NamedTuple) | ||
throw(ArgumentError("Invalid patch for `Cholesky`: $(patch)")) | ||
end | ||
if !isdefined(Base,:get_extension) | ||
using LinearAlgebra | ||
include("../ext/ConstructionBaseLinearAlgebraExt.jl") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to main source file? |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed?