Skip to content

Commit

Permalink
rework Basis more after tightening of supertype; avoid StaticArrays…
Browse files Browse the repository at this point in the history
… ambiguities etc.
  • Loading branch information
thchr committed May 24, 2021
1 parent 581b746 commit 497a9a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Crystalline"
uuid = "ae5e2be0-a263-11e9-351e-f94dad1eb351"
authors = ["Thomas Christensen <[email protected]>"]
version = "0.3.8"
version = "0.3.9"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
3 changes: 2 additions & 1 deletion src/Crystalline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import Base: getindex, setindex!, # → iteration/AbstractArray interface
string, isapprox, zero,
readuntil, vec, show, summary,
+, -, , ==, ImmutableDict,
isone, one
isone, one,
convert
import LinearAlgebra: inv
import Random # → `_Uniform` in src/utils.jl
import Random: rand #
Expand Down
28 changes: 20 additions & 8 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@ for T in (:DirectBasis, :ReciprocalBasis)
@doc """
$($T){D} <: Basis{D}
- `vecs::NTuple{D, SVector{D, Float64}}`
- `vecs::SVector{D, SVector{D,Float64}}`
"""
struct $T{D} <: Basis{D}
vecs::SVector{D,SVector{D,Float64}}
vecs::SVector{D, SVector{D,Float64}}
$T{D}(vecs::SVector{D, SVector{D,Float64}}) where D = new{D}(vecs)
$T(vecs::SVector{D, SVector{D,Float64}}) where D = new{D}(vecs)
end
end
@eval $T(Rs::NTuple{D,AbstractVector{<:Real}}) where D = $T{D}(SVector{D,Float64}.(Rs))
@eval $T(Rs::NTuple{D,NTuple{D,<:Real}}) where D = $T{D}(SVector{D,Float64}.(Rs))
@eval $T(Rs::AbstractVector{<:Real}...) = $T(Rs)
@eval $T(Rs::NTuple{D,<:Real}...) where D = $T{D}(SVector{D,Float64}.(Rs))
@eval $T(Rs::AbstractVector{<:Real}) = (D=length(Rs); $T{D}(SVector{D,Float64}.(Rs)))
end
@eval function convert(::Type{$T{D}}, Vs::StaticVector{D, <:StaticVector{D, <:Real}}) where D
$T{D}(convert(SVector{D, SVector{D, Float64}}, Vs))
end
@eval $T{D}(Vs::NTuple{D, SVector{D, Float64}}) where D = $T{D}(SVector{D}(Vs))
@eval $T(Vs::NTuple{D, SVector{D, Float64}}) where D = $T{D}(Vs)
@eval $T{D}(Vs::NTuple{D, NTuple{D,<:Real}}) where D = $T{D}(SVector{D,Float64}.(Vs))
@eval $T(Vs::NTuple{D, NTuple{D,<:Real}}) where D = $T{D}(Vs)
@eval $T{D}(Vs::AbstractVector{<:Real}...) where D = $T{D}(convert(SVector{D, SVector{D, Float64}}, Vs))
@eval $T(Vs::AbstractVector{<:Real}...) = $T{length(Vs)}(Vs...)
@eval $T{D}(Vs::StaticVector{D,<:Real}...) where D = $T{D}(Vs) # resolve ambiguities w/
@eval $T(Vs::StaticVector{D,<:Real}...) where D = $T{D}(Vs) # `::StaticArray` methods
end

# Fix a bug in StaticArrays: https://github.com/JuliaArrays/StaticArrays.jl/issues/915
# TODO: Remove when fixed upstream
Base.abs2(a::StaticArray) = LinearAlgebra.norm_sqr(a)

vecs(Vs::Basis) = Vs.vecs
# define the AbstractArray interface for DirectBasis{D}
Expand Down

2 comments on commit 497a9a1

@thchr
Copy link
Owner Author

@thchr thchr commented on 497a9a1 May 24, 2021

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 created: JuliaRegistries/General/37400

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.3.9 -m "<description of version>" 497a9a1717e83b2783b28bafc982bad1f6ae8e81
git push origin v0.3.9

Please sign in to comment.