From 833058def44ae2d9fa0ed722be87380c4b9b046c Mon Sep 17 00:00:00 2001 From: Thomas Christensen Date: Tue, 17 Sep 2024 08:38:28 +0200 Subject: [PATCH] fix precompilation error by rearranging definitions - (struct definitions must precede function definitions with the struct's name) --- src/Crystalline.jl | 2 +- ...ry_vectors.jl => types_symmetryvectors.jl} | 105 +++++++++--------- 2 files changed, 55 insertions(+), 52 deletions(-) rename src/{types_symmetry_vectors.jl => types_symmetryvectors.jl} (97%) diff --git a/src/Crystalline.jl b/src/Crystalline.jl index 84d34adb..e1ec6dfa 100644 --- a/src/Crystalline.jl +++ b/src/Crystalline.jl @@ -73,7 +73,7 @@ export SymOperation, # types irreplabels, klabels, # ::BandRep & ::BandRepSet isspinful -include("types_symmetry_vectors.jl") +include("types_symmetryvectors.jl") export SymmetryVector, NewBandRep export irreps, multiplicities, occupation diff --git a/src/types_symmetry_vectors.jl b/src/types_symmetryvectors.jl similarity index 97% rename from src/types_symmetry_vectors.jl rename to src/types_symmetryvectors.jl index 06e6e64a..4341c6d6 100644 --- a/src/types_symmetry_vectors.jl +++ b/src/types_symmetryvectors.jl @@ -1,7 +1,60 @@ # ---------------------------------------------------------------------------------------- # -# AbstractSymmetryVector +# AbstractSymmetryVector definition abstract type AbstractSymmetryVector{D} <: AbstractVector{Int} end +# ---------------------------------------------------------------------------------------- # +# SymmetryVector + +mutable struct SymmetryVector{D} <: AbstractSymmetryVector{D} + const lgirsv :: Vector{Collection{LGIrrep{D}}} + const multsv :: Vector{Vector{Int}} + occupation :: Int +end + +# ::: AbstractSymmetryVector interface ::: +irreps(n::SymmetryVector) = n.lgirsv +multiplicities(n::SymmetryVector) = n.multsv +occupation(n::SymmetryVector) = n.occupation +SymmetryVector(n::SymmetryVector) = n + +# ::: AbstractArray interface beyond AbstractSymmetryVector ::: +function Base.similar(n::SymmetryVector{D}) where D + SymmetryVector{D}(n.lgirsv, similar(n.multsv), 0) +end +@propagate_inbounds function Base.setindex!(n::SymmetryVector, v::Int, i::Int) + Nⁱʳ = length(n) + @boundscheck i > Nⁱʳ && throw(BoundsError(n, i)) + i == Nⁱʳ && (n.occupation = v; return v) + i₀ = i₁ = 0 + for mults in multiplicities(n) + i₁ += length(mults) + if i ≤ i₁ + mults[i-i₀] = v + return v + end + i₀ = i₁ + end +end + +# ::: Optimizations and utilities ::: +function Base.Vector(n::SymmetryVector) + nv = Vector{Int}(undef, length(n)) + i = 1 + for mults in multiplicities(n) + N = length(mults) + copyto!(nv, i, mults, 1, N) + i += N + end + nv[end] = occupation(n) + return nv +end +irreplabels(n::SymmetryVector) = [label(ir) for ir in Iterators.flatten(irreps(n))] +klabels(n::SymmetryVector) = [klabel(first(irs)) for irs in irreps(n)] +num(n::SymmetryVector) = num(first(first(irreps(n)))) + +# ---------------------------------------------------------------------------------------- # +# AbstractSymmetryVector interface & shared implementation + # ::: API ::: """ SymmetryVector(n::AbstractSymmetryVector) -> SymmetryVector @@ -103,56 +156,6 @@ end # ::: Utilities & misc ::: dim(::AbstractSymmetryVector{D}) where D = D -# ---------------------------------------------------------------------------------------- # -# SymmetryVector - -mutable struct SymmetryVector{D} <: AbstractSymmetryVector{D} - const lgirsv :: Vector{Collection{LGIrrep{D}}} - const multsv :: Vector{Vector{Int}} - occupation :: Int -end - -# ::: AbstractSymmetryVector interface ::: -irreps(n::SymmetryVector) = n.lgirsv -multiplicities(n::SymmetryVector) = n.multsv -occupation(n::SymmetryVector) = n.occupation -SymmetryVector(n::SymmetryVector) = n - -# ::: AbstractArray interface beyond AbstractSymmetryVector ::: -function Base.similar(n::SymmetryVector{D}) where D - SymmetryVector{D}(n.lgirsv, similar(n.multsv), 0) -end -@propagate_inbounds function Base.setindex!(n::SymmetryVector, v::Int, i::Int) - Nⁱʳ = length(n) - @boundscheck i > Nⁱʳ && throw(BoundsError(n, i)) - i == Nⁱʳ && (n.occupation = v; return v) - i₀ = i₁ = 0 - for mults in multiplicities(n) - i₁ += length(mults) - if i ≤ i₁ - mults[i-i₀] = v - return v - end - i₀ = i₁ - end -end - -# ::: Optimizations and utilities ::: -function Base.Vector(n::SymmetryVector) - nv = Vector{Int}(undef, length(n)) - i = 1 - for mults in multiplicities(n) - N = length(mults) - copyto!(nv, i, mults, 1, N) - i += N - end - nv[end] = occupation(n) - return nv -end -irreplabels(n::SymmetryVector) = [label(ir) for ir in Iterators.flatten(irreps(n))] -klabels(n::SymmetryVector) = [klabel(first(irs)) for irs in irreps(n)] -num(n::SymmetryVector) = num(first(first(irreps(n)))) - # ---------------------------------------------------------------------------------------- # # NewBandRep