Skip to content

Commit

Permalink
Merge pull request #32 from StevenWhitaker/stw/add_methods
Browse files Browse the repository at this point in the history
Add some methods.
  • Loading branch information
StevenWhitaker authored Aug 28, 2023
2 parents 4fdc3e6 + 4f15971 commit 22154f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BlochSim"
uuid = "5c0f8cbe-99a4-11e9-108b-216da9629524"
authors = ["Steven Whitaker <[email protected]>"]
version = "0.7.0"
version = "0.7.1"

[deps]
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand Down
18 changes: 18 additions & 0 deletions src/blochmatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,24 @@ function Base.:*(A::BlochMatrix, ::IdealSpoilingMatrix)

end

function Base.:*(A::FreePrecessionMatrix, B::BlochMatrix)

(sinθ, cosθ) = sincos(A.θ)
return BlochMatrix(
A.E2 * cosθ * B.a11 + A.E2 * sinθ * B.a21,
-A.E2 * sinθ * B.a11 + A.E2 * cosθ * B.a21,
A.E1 * B.a31,
A.E2 * cosθ * B.a12 + A.E2 * sinθ * B.a22,
-A.E2 * sinθ * B.a12 + A.E2 * cosθ * B.a22,
A.E1 * B.a32,
A.E2 * cosθ * B.a13 + A.E2 * sinθ * B.a23,
-A.E2 * sinθ * B.a13 + A.E2 * cosθ * B.a23,
A.E1 * B.a33
)

end

Base.:*(A::ExcitationMatrix, B::FreePrecessionMatrix) = A.A * B
Base.:*(A::ExcitationMatrix, ::IdealSpoilingMatrix) = A.A * idealspoiling

function Base.:*(A::BlochMcConnellMatrix{T1,N}, B::BlochMcConnellMatrix{T2,N}) where {T1,T2,N}
Expand Down
22 changes: 17 additions & 5 deletions test/blochmatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,28 @@ end

function times6()

A = BlochMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9)
A = ExcitationMatrix(BlochMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9))
B = FreePrecessionMatrix(1, 1, 1)
C = A * B
correct = Matrix(A) * Matrix(B)
correct = Matrix(A.A) * Matrix(B)

return Matrix(C) correct

end

function times7()

A = FreePrecessionMatrix(1, 1, 1)
B = BlochMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9)
C = A * B
correct = Matrix(A) * Matrix(B)

return Matrix(C) correct

end

function times8()

A = ExcitationMatrix(BlochMatrix(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9))
C = A * idealspoiling
correct = BlochMatrix(0, 0, 0, 0, 0, 0, 0.7, 0.8, 0.9)
Expand All @@ -183,7 +194,7 @@ function times7()

end

function times8()
function times9()

A = ExcitationMatrix(BlochMatrix(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9))
B = BlochMcConnellMatrix(3)
Expand All @@ -205,7 +216,7 @@ function times8()

end

function times9()
function times10()

A = idealspoiling
B = BlochMcConnellMatrix(3)
Expand Down Expand Up @@ -631,7 +642,7 @@ function mul16()
mul!(C, A, A)
correct = Matrix(A) * Matrix(A)

return Matrix(C) == correct
return Matrix(C) correct

end

Expand Down Expand Up @@ -1216,6 +1227,7 @@ end
@test times7()
@test times8()
@test times9()
@test times10()

end

Expand Down

0 comments on commit 22154f4

Please sign in to comment.