Skip to content

Instantly share code, notes, and snippets.

@George9000
Created September 24, 2023 22:16
Show Gist options
  • Save George9000/1f2ea7734c3198c263fda861d9e27af0 to your computer and use it in GitHub Desktop.
Save George9000/1f2ea7734c3198c263fda861d9e27af0 to your computer and use it in GitHub Desktop.
Julia file used as an example for unicode glyphs
1 โˆˆ [1, 2, 3]
f โˆ˜ g(x)
function hom(v::SVector)
push(v,1)
end
function T(๐›‰::AbstractArray, ๐’ž::Tuple{AbstractArray, Vararg{AbstractArray}}, ๐’Ÿ::Tuple{AbstractArray, Vararg{AbstractArray}})
โŠ— = kron
l = length(๐›‰)
๐ˆโ‚— = SMatrix{l,l}(1.0I)
๐ˆโ‚˜ = SMatrix{1,1}(1.0I)
๐“ = @SMatrix zeros(l,l)
N = length(๐’Ÿ[1])
โ„ณ, โ„ณสน = ๐’Ÿ
ฮ›โ‚, ฮ›โ‚‚ = ๐’ž
๐šฒโ‚™ = @MMatrix zeros(4,4)
๐žโ‚ = @SMatrix [1.0; 0.0; 0.0]
๐žโ‚‚ = @SMatrix [0.0; 1.0; 0.0]
for n = 1: N
index = SVector(1,2)
๐šฒโ‚™[1:2,1:2] .= ฮ›โ‚[n][index,index]
๐šฒโ‚™[3:4,3:4] .= ฮ›โ‚‚[n][index,index]
๐ฆ = hom(โ„ณ[n])
๐ฆสน= hom(โ„ณสน[n])
๐”โ‚™ = (๐ฆ โŠ— ๐ฆสน)
โˆ‚โ‚“๐ฎโ‚™ = [(๐žโ‚ โŠ— ๐ฆสน) (๐žโ‚‚ โŠ— ๐ฆสน) (๐ฆ โŠ— ๐žโ‚) (๐ฆ โŠ— ๐žโ‚‚)]
๐โ‚™ = โˆ‚โ‚“๐ฎโ‚™ * ๐šฒโ‚™ * โˆ‚โ‚“๐ฎโ‚™'
๐šบโ‚™ = ๐›‰' * ๐โ‚™ * ๐›‰
๐šบโ‚™โปยน = inv(๐šบโ‚™)
๐“โ‚ = @SMatrix zeros(Float64,l,l)
for k = 1:l
๐žโ‚– = ๐ˆโ‚—[:,k]
โˆ‚๐žโ‚–๐šบโ‚™ = (๐ˆโ‚˜ โŠ— ๐žโ‚–') * ๐โ‚™ * (๐ˆโ‚˜ โŠ— ๐›‰) + (๐ˆโ‚˜ โŠ— ๐›‰') * ๐โ‚™ * (๐ˆโ‚˜ โŠ— ๐žโ‚–)
# Accumulating the result in ๐“โ‚ allocates memory, even though
# the two terms in the summation are both SArrays.
๐“โ‚ = ๐“โ‚ + ๐”โ‚™ * ๐šบโ‚™โปยน * (โˆ‚๐žโ‚–๐šบโ‚™) * ๐šบโ‚™โปยน * ๐”โ‚™' * ๐›‰ * ๐žโ‚–'
end
๐“ = ๐“ + ๐“โ‚
end
๐“
end
# Some sample data
N = 300
โ„ณ = [@SVector rand(2) for i = 1:N]
โ„ณสน = [@SVector rand(2) for i = 1:N]
ฮ›โ‚ = [SMatrix{3,3}(Matrix(Diagonal([1.0,1.0,0.0]))) for i = 1:length(โ„ณ)]
ฮ›โ‚‚ = [SMatrix{3,3}(Matrix(Diagonal([1.0,1.0,0.0]))) for i = 1:length(โ„ณ)]
F = @SMatrix rand(3,3)
๐’ž = (ฮ›โ‚,ฮ›โ‚‚)
๐’Ÿ = (โ„ณ, โ„ณสน)
T(vec(F),๐’ž,๐’Ÿ)
@btime T(vec($F),$๐’ž,$๐’Ÿ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment