Skip to content

Commit

Permalink
fix precompilation error by rearranging definitions
Browse files Browse the repository at this point in the history
- (struct definitions must precede function definitions with the struct's name)
  • Loading branch information
thchr committed Sep 17, 2024
1 parent d5d8da9 commit 833058d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/Crystalline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
105 changes: 54 additions & 51 deletions src/types_symmetry_vectors.jl → src/types_symmetryvectors.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down

2 comments on commit 833058d

@thchr
Copy link
Owner Author

@thchr thchr commented on 833058d Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/115292

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.1 -m "<description of version>" 833058def44ae2d9fa0ed722be87380c4b9b046c
git push origin v0.6.1

Please sign in to comment.