Skip to content

Commit

Permalink
Merge pull request #107 from JuliaGNI/move_relevant_functions_to_utils
Browse files Browse the repository at this point in the history
Moved write_ones kernel to utils.jl
  • Loading branch information
michakraus authored Jan 8, 2024
2 parents 512850f + 96f1a80 commit 917fc67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
19 changes: 5 additions & 14 deletions src/arrays/skew_symmetric.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
"""
A `SkewSymMatrix` is a matrix
| 0 -S |
| S 0 |
@doc raw"""
A `SkewSymMatrix` is a matrix ``A`` s.t. ``A^T = -A``.
If the constructor is called with a matrix as input it returns a symmetric matrix via the projection
A ↦ .5*(A - Aᵀ).
This is a projection defined via the canonical metric (A,B) ↦ tr(AᵀB).
If the constructor is called with a matrix as input it returns a symmetric matrix via the projection ``A \mapsto \frac{1}{2}(A - A^T)``.
This is a projection defined via the canonical metric ``\mathbb{R}^{n\times{}n}\times\mathbb{R}^{n\times{}n}\to\mathbb{R}, (A,B) \mapsto \mathrm{Tr}(A^TB)``.
The first index is the row index, the second one the column index.
TODO: Check how LinearAlgebra implements matrix multiplication!
The struct two fields: `S` and `n`. The first stores all the entries of the matrix in a sparse fashion (in a vector) and the second is the dimension ``n`` for ``A\in\mathbb{R}^{n\times{}n}``.
"""

mutable struct SkewSymMatrix{T, AT <: AbstractVector{T}} <: AbstractMatrix{T}
Expand Down Expand Up @@ -171,11 +167,6 @@ function Base.:*(A::SkewSymMatrix, b::AbstractVector{T}) where T
A*reshape(b, size(b), 1)
end

@kernel function write_ones_kernel!(unit_matrix::AbstractMatrix{T}) where T
i = @index(Global)
unit_matrix[i, i] = one(T)
end

function Base.one(A::SkewSymMatrix{T}) where T
backend = KernelAbstractions.get_backend(A.S)
unit_matrix = KernelAbstractions.zeros(backend, T, A.n, A.n)
Expand Down
8 changes: 2 additions & 6 deletions src/arrays/symmetric.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
@doc raw"""
A `SymmetricMatrix` is a matrix
| a S |
| S b |
The first index is the row index, the second one the column index.
A `SymmetricMatrix` ``A`` is a matrix ``A^T = A``.
If the constructor is called with a matrix as input it returns a symmetric matrix via the projection:
```math
Expand All @@ -17,7 +13,7 @@ Internally the `struct` saves a vector $S$ of size $n(n+1)\div2$. The conversion
S[( (j-1) j ) \div 2 + i] & \text{else}. \end{cases}
```
So $S$ stores a string of vectors taken from $A$: $S = [\tilde{a}_1, \tilde{a}_2, \ldots, \tilde{a}_n]$ with $\tilde{a}_i = [[A]_{i1},[A]_{i2},\ldots,[A]_{ii}]$.
So ``S`` stores a string of vectors taken from $A$: $S = [\tilde{a}_1, \tilde{a}_2, \ldots, \tilde{a}_n]$ with $\tilde{a}_i = [[A]_{i1},[A]_{i2},\ldots,[A]_{ii}]$.
TODO:
- [x] Overload Adjoint operation for SymmetricMatrix!! (Aᵀ = A)
Expand Down
11 changes: 8 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ function Base.:+(a::Vector{Float64}, b::Tuple{Float64})
return y+x
end

"""
Kernel that is needed for functions relating to `SymmetricMatrix` and `SkewSymMatrix`
"""
@kernel function write_ones_kernel!(unit_matrix::AbstractMatrix{T}) where T
i = @index(Global)
unit_matrix[i, i] = one(T)
end

# overloaded similar operation to work with NamedTuples
_similar(x) = similar(x)
Expand All @@ -76,7 +83,6 @@ function _similar(x::NamedTuple)
end

# utils functions on string

function type_without_brace(var)
type_str = string(typeof(var))
replace(type_str, r"\{.*\}"=>"")
Expand All @@ -91,8 +97,7 @@ function center_align_text(text,width)
end


#The following are fallback functions - maybe you want to put them into a separate file

# The following are fallback functions - maybe you want to put them into a separate file
function global_section(::AbstractVecOrMat)
nothing
end

0 comments on commit 917fc67

Please sign in to comment.