chakravala / Grassmann.jl

⟨Grassmann-Clifford-Hodge⟩ multilinear differential geometric algebra
https://grassmann.crucialflow.com
GNU Affero General Public License v3.0
470 stars 38 forks source link

abs2 is not type-stable #64

Closed eschnett closed 4 years ago

eschnett commented 4 years ago

The result type of abs2 seems to depend on argument values:

julia> @basis 2
(⟨++⟩, v, v₁, v₂, v₁₂)

julia> abs2(MultiVector(v+v1)) |> typeof
MultiVector{⟨++⟩,Int64,4}

julia> abs2(MultiVector(v)) |> typeof
Simplex{⟨++⟩,0,v,Int64}

The return type of a function should usually only depend on the argument types.

I am currently not running benchmarks, so this does currently not affect me.

chakravala commented 4 years ago

That's not a bug, it's a feature. It performs better this way. To keep it type stable, it would be necessary to output a full MultiVector when only a Simplex would do. Having a scalar Simplex instead of a full valued MultiVector is faster for computing exp and other essential methods.

This is intentional and will not be changed.