Skip to content

Commit 356c48a

Browse files
authored
Merge pull request #486 from JuliaHealth/fix-rotation
Fix sum of `Grad`s
2 parents 386cf0d + e03607a commit 356c48a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

KomaMRIBase/src/datatypes/sequence/Grad.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ Base.zero(::Type{Grad}) = Grad(0.0, 0.0)
226226
# Rotation
227227
Base.zero(::Grad) = Grad(0.0, 0.0)
228228
*::Real, x::Grad) = Grad* x.A, x.T, x.rise, x.fall, x.delay)
229-
+(x::Grad, y::Grad) = Grad(x.A .+ y.A, x.T, x.rise, x.fall, x.delay)
229+
+(x::Grad, y::Grad) = Grad(x.A .+ y.A, max(x.T, y.T), max(x.rise, y.rise), max(x.fall, y.fall), max(x.delay, y.delay)) #TODO: solve this in a better way (by "stacking" gradients) issue #487
230230
# Others
231231
*(x::Grad, α::Real) = Grad* x.A, x.T, x.rise, x.fall, x.delay)
232232
/(x::Grad, α::Real) = Grad(x.A / α, x.T, x.rise, x.fall, x.delay)
233233
-(x::Grad) = -1 * x
234-
-(x::Grad, y::Grad) = Grad(x.A .- y.A, x.T, x.rise, x.fall, x.delay)
234+
-(x::Grad, y::Grad) = Grad(x.A .- y.A, max(x.T, y.T), max(x.rise, y.rise), max(x.fall, y.fall), max(x.delay, y.delay)) #TODO: solve this in a better way (by "stacking" gradients) issue #487
235235

236236
# Gradient functions
237237
function vcat(x::Array{Grad,1}, y::Array{Grad,1})

KomaMRIBase/test/runtests.jl

+10-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ using TestItems, TestItemRunner
3434
R = rotz(θ)
3535
s2 = R*s #Matrix-Matrix{Grad} multiplication
3636
GR2 = R*s.GR.A #Matrix-vector multiplication
37-
@test s2.GR.A GR2
37+
@test s2.GR.A GR2
38+
@test s.GR.T == s2.GR.T
39+
@test s.GR.delay == s2.GR.delay
40+
@test s.GR.rise == s2.GR.rise
41+
@test s.GR.fall == s2.GR.fall
3842
# Rotation 3D case
3943
T, t1, t2, t3 = rand(4)
4044
N = 100
@@ -47,8 +51,11 @@ using TestItems, TestItemRunner
4751
R = Rx*Ry*Rz
4852
s2 = R*s #Matrix-Matrix{Grad} multiplication
4953
GR2 = R*s.GR.A #Matrix-vector multiplication
50-
@test s2.GR.A GR2
51-
54+
@test s2.GR.A GR2
55+
@test s.GR.T == s2.GR.T
56+
@test s.GR.delay == s2.GR.delay
57+
@test s.GR.rise == s2.GR.rise
58+
@test s.GR.fall == s2.GR.fall
5259
# Concatenation of sequences
5360
A1, A2, A3, T1 = rand(4)
5461
s1 = Sequence([Grad(A1,T1);

0 commit comments

Comments
 (0)