-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing Cell #91
Comments
|
import spglib
lattice = [[1,0,0],[0,1,0],[0,0,1]]
positions = [[-0.1, -0.1, -0.1], [0.1, 0.1, 0.1]]
atoms = [1, 1]
magmoms = [[0., 0., 1.], [0., 0., -1.]]
>>> spglib.get_symmetry((lattice, positions, atoms))["rotations"].shape
(12, 3, 3)
>>> spglib.get_symmetry((lattice, positions, atoms, magmoms))["rotations"].shape
(2, 3, 3) The python function is
using StaticArrays
struct MyCell1{N,P}
positions::MMatrix{3,N,P}
end
function MyCell1(positions_::AbstractVector)
positions = reduce(hcat, positions_)
N, P = size(positions, 2), eltype(positions)
return MyCell1{N,P}(positions)
end
struct MyCell2{P}
positions::Vector{MVector{3, P}}
end
function MyCell2(positions_::AbstractVector)
positions = MVector{3}.(positions_)
P = eltype(eltype(positions))
return MyCell2{P}(positions)
end
pos = [[0., 0., 0.], [0.5, 0.5, 0.5]]
@code_warntype MyCell1(pos)
@code_warntype MyCell2(pos) Example output: julia> @code_warntype MyCell1(pos)
MethodInstance for MyCell1(::Vector{Vector{Float64}})
from MyCell1(positions_::AbstractVector) in Main at REPL[3]:1
Arguments
#self#::Type{MyCell1}
positions_::Vector{Vector{Float64}}
Locals
P::Type{Float64}
N::Int64
positions::Matrix{Float64}
Body::MyCell1{_A, Float64} where _A
1 ─ (positions = Main.reduce(Main.hcat, positions_))
│ %2 = Main.size(positions, 2)::Int64
│ %3 = Main.eltype(positions)::Core.Const(Float64)
│ (N = %2)
│ (P = %3)
│ %6 = Core.apply_type(Main.MyCell1, N, P::Core.Const(Float64))::Type{MyCell1{_A, Float64}} where _A
│ %7 = (%6)(positions)::MyCell1{_A, Float64} where _A
└── return %7
julia> @code_warntype MyCell2(pos)
MethodInstance for MyCell2(::Vector{Vector{Float64}})
from MyCell2(positions_::AbstractVector) in Main at REPL[5]:1
Arguments
#self#::Type{MyCell2}
positions_::Vector{Vector{Float64}}
Locals
P::Type{Float64}
positions::Vector{MVector{3, Float64}}
Body::MyCell2{Float64}
1 ─ %1 = Core.apply_type(Main.MVector, 3)::Core.Const(MVector{3})
│ %2 = Base.broadcasted(%1, positions_)::Core.PartialStruct(Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, Type{MVector{3}}, Tuple{Vector{Vector{Float64}}}}, Any[Core.Const(MVector{3}), Tuple{Vector{Vector{Float64}}}, Core.Const(nothing)])
│ (positions = Base.materialize(%2))
│ %4 = Main.eltype(positions)::Core.Const(MVector{3, Float64})
│ (P = Main.eltype(%4))
│ %6 = Core.apply_type(Main.MyCell2, P::Core.Const(Float64))::Core.Const(MyCell2{Float64})
│ %7 = (%6)(positions)::MyCell2{Float64}
└── return %7 |
…}}`, Drop type `N` as in #91 (comment)
Hi @jaemolihm, I removed the constraint on |
|
Hi @jaemolihm, the magnetic code is now available on the main branch's head. Please try. |
Hi, thanks for this nice package!
I would like to ask what do you think about making following changes to the
Cell
struct.magmom
to benothing
(nonmagnetic),Vector{T}
(collinear), andVector{MVector{3,M}}
(noncollinear).Vector{MVector{3,P}}
instead ofMMatrix{3,N,P}
forposition
. The latter causes type instability when constructingCell
. (This was also suggested in Fix type-instability inlattice
-field ofCell
#84)The text was updated successfully, but these errors were encountered: