Kronecker sum implemented
This commit is contained in:
parent
1f834f72e9
commit
222ab12ef7
|
|
@ -1,3 +1,5 @@
|
||||||
|
using LinearAlgebra
|
||||||
|
|
||||||
"Sum over array while minimizing catastrophic cancellation as much as possible"
|
"Sum over array while minimizing catastrophic cancellation as much as possible"
|
||||||
function better_sum(arr::Array{Float64})
|
function better_sum(arr::Array{Float64})
|
||||||
pos_arr = arr[arr .> 0]
|
pos_arr = arr[arr .> 0]
|
||||||
|
|
@ -16,3 +18,9 @@ triangle_ineq(l1, l2, L) = abs(l1 - l2) ≤ L && L ≤ (l1 + l2)
|
||||||
|
|
||||||
"Nearest value in a list to a given reference point"
|
"Nearest value in a list to a given reference point"
|
||||||
nearest(list::Array, ref) = list[argmin(norm.(list .- ref))]
|
nearest(list::Array, ref) = list[argmin(norm.(list .- ref))]
|
||||||
|
|
||||||
|
"Simple implementation of the Kronecker sum"
|
||||||
|
function kron_sum(A::AbstractMatrix, B::AbstractMatrix)
|
||||||
|
@assert size(A, 1) == size(A, 2) && size(B, 1) == size(B, 2) "Matrices should be square"
|
||||||
|
return kron(A, I(size(B, 1))) + kron(B, I(size(A, 1)))
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue