@@ -6,7 +6,10 @@ import Base: setindex
66abstract type StaticVector{N, T} end
77function similar_type end
88
9- macro fixed_vector (VecT, SuperT)
9+ macro fixed_vector (name_parent)
10+ @assert name_parent. head == :(= )
11+ name, parent = name_parent. args
12+
1013 expr = quote
1114 struct $ (VecT){N, T} <: $ (SuperT){N, T}
1215 data:: NTuple{N,T}
@@ -186,8 +189,9 @@ Base.reverse(x::P) where P <: StaticVector = P(reverse(x.data))
186189# Since we don't inherit from AbstractArray, some extra functions need to be overloaded
187190LinearAlgebra. promote_leaf_eltypes (x:: StaticVector{N, T} ) where {N,T} = T
188191
189- @fixed_vector Point StaticVector
190- @fixed_vector Vec StaticVector
192+ @fixed_vector Point = StaticVector
193+ @fixed_vector Vec = StaticVector
194+
191195
192196Base. lastindex (:: StaticVector{N} ) where N = N
193197
@@ -199,31 +203,36 @@ const VecTypes{N,T} = Union{StaticVector{N,T}, NTuple{N,T}}
199203const Vecf{N} = Vec{N, Float32}
200204const PointT{T} = Point{N,T} where N
201205const Pointf{N} = Point{N,Float32}
202- Base. isnan (p:: Union{Point,Vec} ) = any (x -> isnan (x), p)
203-
204- include (" mat.jl" )
205-
206- for i in 1 : 4
207- for T in [:Point , :Vec ]
208- name = Symbol (" $T$i " )
209- namef = Symbol (" $T$(i) f" )
210- @eval begin
211- const $ name = $ T{$ i}
212- const $ namef = $ T{$ i,Float32}
213- export $ name
214- export $ namef
206+
207+ Base. isnan (p:: Union{AbstractPoint,Vec} ) = any (isnan, p)
208+ Base. isinf (p:: Union{AbstractPoint,Vec} ) = any (isinf, p)
209+ Base. isfinite (p:: Union{AbstractPoint,Vec} ) = all (isfinite, p)
210+
211+ # # Generate aliases
212+ # # As a text file instead of eval/macro, to not confuse code linter
213+
214+ #=
215+ open(joinpath(@__DIR__, "generated-aliases.jl"), "w") do io
216+ for i in 1:4
217+ for T in [:Point, :Vec, :Mat]
218+ namei = "$T$i"
219+ res = T == :Mat ? "Mat{$i,$i,T,$(i * i)}" : "$T{$i,T}"
220+ println(io, "const $(namei){T} = $res")
221+ println(io, "export $namei")
222+ for (postfix, t) in ["d" => Float64, "f" => Float32, "i" => Int, "ui" => UInt]
223+ namep = "$T$i$postfix"
224+ println(io, "const $(namep) = $(namei){$t}")
225+ println(io, "export $namep")
226+ # mnamep = "$(mname)$postfix"
227+ # println(io, "const $mnamep = $mname{$t}")
228+ # println(io, "export $mnamep")
229+ end
215230 end
216231 end
217- name = Symbol (" Mat$i " )
218- namef = Symbol (" Mat$(i) f" )
219- namef = Symbol (" Mat$(i) f" )
220- @eval begin
221- const $ name{T} = $ Mat{$ i,$ i,T, $ (i* i)}
222- const $ namef = $ name{Float32}
223- export $ name
224- export $ namef
225- end
226232end
233+ =#
234+
235+ include (" generated-aliases.jl" )
227236
228237export Mat, Vec, Point, unit
229238export Vecf, Pointf
0 commit comments