Skip to content

Commit

Permalink
Fixed broken implementation of scalar_product
Browse files Browse the repository at this point in the history
  • Loading branch information
brainandforce committed Sep 19, 2024
1 parent a46af89 commit 8492608
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/math/scalar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ ispseudoscalar(x::KVector{K,Q}) where {K,Q} = (iszero(x) || K == dimension(Q))
Calculates the scalar product of two Clifford numbers with quadratic form `Q`. The result is a
`Real` or `Complex` number. This can be converted back to an `AbstractCliffordNumber`.
"""
function scalar_product(x::AbstractCliffordNumber{Q,T}, y::AbstractCliffordNumber{Q,T}) where {Q,T}
# This is so much faster than anything else I can come up with
return @inline scalar(mul(x, y, GradeFilter{:*}()))
@inline function scalar_product(x::T, y::T) where T<:AbstractCliffordNumber
return sum(Tuple(x) .* Tuple(y))
end

@inline function scalar_product(x::AbstractCliffordNumber{Q}, y::AbstractCliffordNumber{Q}) where Q
# TODO: we could actually demote types here.
# Indices not represented by both x and y should be skipped and add zero.
return scalar_product(promote(x, y)...)
end

"""
Expand Down

0 comments on commit 8492608

Please sign in to comment.