@@ -33,8 +33,8 @@ julia> motionlist = MotionList(
3333 )
3434```
3535"""
36- struct MotionList{T <: Real }
37- motions:: Vector{<:Motion{T} }
36+ struct MotionList
37+ motions:: Vector{<:Motion}
3838end
3939
4040# NOTE: this constructor must be simplified once the Vector{<:Motion} approach is accomplished:
5252
5353# NOTE: these vcat methods must be simplified once the Vector{<:Motion} approach is accomplished:
5454# https://github.com/JuliaHealth/KomaMRI.jl/issues/480
55- """ Addition of MotionLists """
55+ """ Addition of MotionLists """
5656# MotionList + MotionList
57- function Base. vcat (m1:: MotionList{T} , m2:: MotionList{T} , Ns1, Ns2) where {T <: Real }
58- mv_aux = Motion{T} []
57+ function Base. vcat (m1:: MotionList , m2:: MotionList , Ns1, Ns2)
58+ mv_aux = Motion[]
5959 for m in m1. motions
6060 m_aux = deepcopy (m)
6161 m_aux. spins = expand (m_aux. spins, Ns1)
@@ -70,8 +70,8 @@ function Base.vcat(m1::MotionList{T}, m2::MotionList{T}, Ns1, Ns2) where {T<:Rea
7070 return MotionList (mv_aux... )
7171end
7272# Motion + Motion
73- function Base. vcat (m1:: Motion{T} , m2:: Motion{T} , Ns1, Ns2) where {T <: Real }
74- mv_aux = Motion{T} []
73+ function Base. vcat (m1:: Motion , m2:: Motion , Ns1, Ns2)
74+ mv_aux = Motion[]
7575 m_aux = deepcopy (m1)
7676 m_aux. spins = expand (m_aux. spins, Ns1)
7777 push! (mv_aux, m_aux)
@@ -82,9 +82,9 @@ function Base.vcat(m1::Motion{T}, m2::Motion{T}, Ns1, Ns2) where {T<:Real}
8282 return MotionList (mv_aux... )
8383end
8484# Motion + MotionList
85- Base. vcat (m1:: MotionList{T} , m2:: Motion{T} , Ns1, Ns2) where {T <: Real } = vcat (m2, m1, Ns2, Ns1)
86- function Base. vcat (m1:: Motion{T} , m2:: MotionList{T} , Ns1, Ns2) where {T <: Real }
87- mv_aux = Motion{T} []
85+ Base. vcat (m1:: MotionList , m2:: Motion , Ns1, Ns2) = vcat (m2, m1, Ns2, Ns1)
86+ function Base. vcat (m1:: Motion , m2:: MotionList , Ns1, Ns2)
87+ mv_aux = Motion[]
8888 m_aux = deepcopy (m1)
8989 m_aux. spins = expand (m_aux. spins, Ns1)
9090 push! (mv_aux, m_aux)
@@ -98,29 +98,29 @@ function Base.vcat(m1::Motion{T}, m2::MotionList{T}, Ns1, Ns2) where {T<:Real}
9898end
9999
100100""" MotionList sub-group """
101- function Base. getindex (mv:: MotionList{T} , p) where {T <: Real }
102- motion_array_aux = Motion{T} []
101+ function Base. getindex (mv:: MotionList , p)
102+ motion_array_aux = Motion[]
103103 for m in mv. motions
104104 m[p] isa NoMotion ? nothing : push! (motion_array_aux, m[p])
105105 end
106106 return MotionList (motion_array_aux... )
107107end
108- function Base. view (mv:: MotionList{T} , p) where {T <: Real }
109- motion_array_aux = Motion{T} []
108+ function Base. view (mv:: MotionList , p)
109+ motion_array_aux = Motion[]
110110 for m in mv. motions
111111 @view (m[p]) isa NoMotion ? nothing : push! (motion_array_aux, @view (m[p]))
112112 end
113113 return MotionList (motion_array_aux... )
114114end
115115
116116""" Compare two MotionLists """
117- function Base.:(== )(mv1:: MotionList{T} , mv2:: MotionList{T} ) where {T <: Real }
117+ function Base.:(== )(mv1:: MotionList , mv2:: MotionList )
118118 if length (mv1) != length (mv2) return false end
119119 sort_motions! (mv1)
120120 sort_motions! (mv2)
121121 return reduce (& , mv1. motions .== mv2. motions)
122122end
123- function Base.:(≈ )(mv1:: MotionList{T} , mv2:: MotionList{T} ) where {T <: Real }
123+ function Base.:(≈ )(mv1:: MotionList , mv2:: MotionList )
124124 if length (mv1) != length (mv2) return false end
125125 sort_motions! (mv1)
126126 sort_motions! (mv2)
@@ -131,14 +131,14 @@ end
131131Base. length (m:: MotionList ) = length (m. motions)
132132
133133function get_spin_coords (
134- ml:: MotionList{T} , x:: AbstractVector{T} , y:: AbstractVector{T} , z:: AbstractVector{T} , t
135- ) where {T <: Real }
134+ ml:: MotionList , x:: AbstractVector , y:: AbstractVector , z:: AbstractVector , t
135+ )
136136 # Sort motions
137137 sort_motions! (ml)
138138 # Buffers for positions:
139139 xt, yt, zt = x .+ 0 * t, y .+ 0 * t, z .+ 0 * t
140140 # Buffers for displacements:
141- ux, uy, uz = xt .* zero (T ), yt .* zero (T ), zt .* zero (T )
141+ ux, uy, uz = zero .(xt ), zero .(yt ), zero .(zt )
142142 # Composable motions: they need to be run sequentially. Note that they depend on xt, yt, and zt
143143 for m in Iterators. filter (is_composable, ml. motions)
144144 t_unit = unit_time (t, m. time)
@@ -147,7 +147,7 @@ function get_spin_coords(
147147 displacement_y! (@view (uy[idx, :]), m. action, @view (xt[idx, :]), @view (yt[idx, :]), @view (zt[idx, :]), t_unit)
148148 displacement_z! (@view (uz[idx, :]), m. action, @view (xt[idx, :]), @view (yt[idx, :]), @view (zt[idx, :]), t_unit)
149149 xt .+ = ux; yt .+ = uy; zt .+ = uz
150- ux .*= zero (T ); uy .*= zero (T ); uz .*= zero (T )
150+ fill! (ux, 0 ); fill! (uy, 0 ); fill! (uz, 0 )
151151 end
152152 # Additive motions: these motions can be run in parallel
153153 for m in Iterators. filter (! is_composable, ml. motions)
@@ -157,7 +157,7 @@ function get_spin_coords(
157157 displacement_y! (@view (uy[idx, :]), m. action, @view (x[idx]), @view (y[idx]), @view (z[idx]), t_unit)
158158 displacement_z! (@view (uz[idx, :]), m. action, @view (x[idx]), @view (y[idx]), @view (z[idx]), t_unit)
159159 xt .+ = ux; yt .+ = uy; zt .+ = uz
160- ux .*= zero (T ); uy .*= zero (T ); uz .*= zero (T )
160+ fill! (ux, 0 ); fill! (uy, 0 ); fill! (uz, 0 )
161161 end
162162 return xt, yt, zt
163163end
0 commit comments