From 36ab6c6fe8ab6010e376d168e376ad998e39b0b9 Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Thu, 30 Jan 2025 21:21:07 +0100 Subject: [PATCH] Add method for multiplication of a `Matrix` by an `Array{Grad}` --- KomaMRIBase/src/datatypes/sequence/Grad.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/KomaMRIBase/src/datatypes/sequence/Grad.jl b/KomaMRIBase/src/datatypes/sequence/Grad.jl index 7c1eb5c0f..c9a09600f 100644 --- a/KomaMRIBase/src/datatypes/sequence/Grad.jl +++ b/KomaMRIBase/src/datatypes/sequence/Grad.jl @@ -226,6 +226,13 @@ Base.zero(::Type{Grad}) = Grad(0.0, 0.0) # Rotation Base.zero(::Grad) = Grad(0.0, 0.0) *(α::Real, x::Grad) = Grad(α * x.A, x.T, x.rise, x.fall, x.delay) +*(α::Matrix, x::Array{Grad}) = begin + y = deepcopy(x) + for (i, g) in enumerate(y) + g.A = (α*x.A)[i] + end + return y +end +(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 # Others *(x::Grad, α::Real) = Grad(α * x.A, x.T, x.rise, x.fall, x.delay)