-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move the BLAS definitions into the `linalg` directory. * Move some general optimizations into a specific utilities file for linear algebra definitions. * Consolidate structured matrix operations, e.g. diagonal and symmetric, into one file.
- Loading branch information
Showing
7 changed files
with
53 additions
and
36 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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
# Structured matrices | ||
|
||
##### | ||
##### `Diagonal` | ||
##### | ||
|
||
rrule(::Type{<:Diagonal}, d::AbstractVector) = Diagonal(d), Rule(diag) | ||
|
||
rrule(::typeof(diag), A::AbstractMatrix) = diag(A), Rule(Diagonal) | ||
|
||
##### | ||
##### `Symmetric` | ||
##### | ||
|
||
rrule(::Type{<:Symmetric}, A::AbstractMatrix) = Symmetric(A), Rule(_symmetric_back) | ||
|
||
_symmetric_back(ΔΩ) = UpperTriangular(ΔΩ) + LowerTriangular(ΔΩ)' - Diagonal(ΔΩ) | ||
_symmetric_back(ΔΩ::Union{Diagonal,UpperTriangular}) = ΔΩ |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
# Some utility functions for optimizing linear algebra operations that aren't specific | ||
# to any particular rule definition | ||
|
||
# F .* (X - X'), overwrites X | ||
function _mulsubtrans!(X::AbstractMatrix{T}, F::AbstractMatrix{T}) where T<:Real | ||
k = size(X, 1) | ||
@inbounds for j = 1:k, i = 1:j # Iterate the upper triangle | ||
if i == j | ||
X[i,i] = zero(T) | ||
else | ||
X[i,j], X[j,i] = F[i,j] * (X[i,j] - X[j,i]), F[j,i] * (X[j,i] - X[i,j]) | ||
end | ||
end | ||
X | ||
end | ||
|
||
# I - X, overwrites X | ||
function _eyesubx!(X::AbstractMatrix) | ||
n, m = size(X) | ||
@inbounds for j = 1:m, i = 1:n | ||
X[i,j] = (i == j) - X[i,j] | ||
end | ||
X | ||
end | ||
|
||
# X + Y, overwrites X | ||
function _add!(X::AbstractVecOrMat{T}, Y::AbstractVecOrMat{T}) where T<:Real | ||
@inbounds for i = eachindex(X, Y) | ||
X[i] += Y[i] | ||
end | ||
X | ||
end |