MonumoLtd / SimpleGA.jl

Geometric algebra in Julia.
MIT License
23 stars 2 forks source link

Ensure `Base.one` and `Base.zero` are implemented where possible #24

Closed tpgillam closed 10 months ago

tpgillam commented 11 months ago

zero should be definable for all multivector types. one can be defined for even multivector types, where it should correspond to the scalar 1 -- but it should remain undefined for odd multivectors.

Currently it seems to be defined for instances, but often not for types.

tpgillam commented 10 months ago

This is needed to be able to construct an array of zeros or ones, e.g.

using SimpleGA
zeros(GA30.Odd{Float64}, 4)

Currently we get the error:

  MethodError: no method matching SimpleGA.GA30.Odd{Float64}(::Int64)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Closest candidates are:
    (::Type{SimpleGA.GA30.Odd{T}} where T<:Real)(::Any, ::Any, ::Any, ::Any)
     @ SimpleGA ~/.julia/packages/SimpleGA/8UwZx/src/core30.jl:15
    (::Type{T})(::T) where T<:Number                                                                                                                                                                                                                                                             @ Core boot.jl:792
    (::Type{T})(::Base.TwicePrecision) where T<:Number
     @ Base twiceprecision.jl:265
    ...
                                                                                                                                                                                                                                                                                              Stacktrace:                                                                                                                                                                                                                                                                                   [1] convert(::Type{SimpleGA.GA30.Odd{Float64}}, x::Int64)
      @ Base ./number.jl:7
    [2] zero(::Type{SimpleGA.GA30.Odd{Float64}})
      @ Base ./number.jl:309                                                                                                                                                                                                                                                                    [3] zeros(::Type{SimpleGA.GA30.Odd{Float64}}, dims::Tuple{Int64})
      @ Base ./array.jl:637
    [4] zeros(::Type{SimpleGA.GA30.Odd{Float64}}, dims::Int64)
      @ Base ./array.jl:632