Skip to content

Commit 97c9678

Browse files
committed
transitioned clifford conj and rand samplers
1 parent f76020f commit 97c9678

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AbstractTensors = "a8e43f4a-99b7-5565-8bf1-0165161caaea"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
1111
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
12+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1213

1314
[compat]
1415
julia = "1"

src/generic.jl

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,33 +204,34 @@ end
204204

205205
@pure parityreverse(G) = isodd(Int((G-1)*G/2))
206206
@pure parityinvolute(G) = isodd(G)
207-
@pure parityconj(G) = parityreverse(G)parityinvolute(G)
207+
@pure parityclifford(G) = parityreverse(G)parityinvolute(G)
208+
const parityconj = parityreverse
208209

209210
## reverse
210211

211212
import Base: reverse, ~
212-
export involute
213+
export involute, clifford
213214

214215
@pure grade_basis(V,B) = B&(one(UInt)<<grade(V)-1)
215216
@pure grade_basis(v,::SubManifold{V,G,B} where G) where {V,B} = grade_basis(V,B)
216217
@pure grade(V,B) = count_ones(grade_basis(V,B))
217218
@pure grade(v,::SubManifold{V,G,B} where G) where {V,B} = grade(V,B)
218219

219-
for r (:reverse,:involute,:(Base.conj))
220+
for r (:reverse,:involute,:(Base.conj),:clifford)
220221
p = Symbol(:parity,r==:(Base.conj) ? :conj : r)
221222
@eval begin
222223
@pure function $r(b::SubManifold{V,G,B}) where {V,G,B}
223224
$p(grade(V,B)) ? Simplex{V}(-value(b),b) : b
224225
end
225-
$r(b::Simplex) = value(b) 0 ? value(b) * $r(basis(b)) : g_zero(Manifold(b))
226+
$r(b::Simplex) = value(b) 0 ? Simplex(value(b),$r(basis(b))) : g_zero(Manifold(b))
226227
end
227228
end
228229

229230
@doc """
230231
~(ω::TensorAlgebra)
231232
232233
Reverse of a `MultiVector` element: ~ω = (-1)^(grade(ω)*(grade(ω)-1)/2)*ω
233-
""" reverse
234+
""" Base.conj
234235
#reverse(a::UniformScaling{Bool}) = UniformScaling(!a.λ)
235236
#reverse(a::UniformScaling{T}) where T<:Field = UniformScaling(-a.λ)
236237

@@ -239,7 +240,7 @@ Reverse of a `MultiVector` element: ~ω = (-1)^(grade(ω)*(grade(ω)-1)/2)*ω
239240
240241
Reverse of a `MultiVector` element: ~ω = (-1)^(grade(ω)*(grade(ω)-1)/2)*ω
241242
"""
242-
@inline Base.:~(b::TensorAlgebra) = reverse(b)
243+
@inline Base.:~(b::TensorAlgebra) = conj(b)
243244
#@inline ~(b::UniformScaling) = reverse(b)
244245

245246
@doc """
@@ -249,10 +250,10 @@ Involute of a `MultiVector` element: ~ω = (-1)^grade(ω)*ω
249250
""" involute
250251

251252
@doc """
252-
conj(ω::TensorAlgebra)
253+
clifford(ω::TensorAlgebra)
253254
254-
Clifford conjugate of a `MultiVector` element: conj(ω) = involute()
255-
""" conj
255+
Clifford conjugate of a `MultiVector` element: clifford(ω) = involute(conj(ω))
256+
""" clifford
256257

257258
odd(t::T) where T<:TensorGraded{V,G} where {V,G} = parityinvolute(G) ? t : zero(V)
258259
even(t::T) where T<:TensorGraded{V,G} where {V,G} = parityinvolute(G) ? zero(V) : t
@@ -295,3 +296,19 @@ Base.isless(a,b::T) where T<:TensorTerm{V,0} where V = isless(a,value(b))
295296
Base.:<=(x::T,y::S) where {T<:TensorTerm{V,0},S<:TensorTerm{W,0}} where {V,W} = isless(x,y) | (x == y)
296297
Base.:<=(x::T,y) where T<:TensorTerm{V,0} where V = isless(x,y) | (x == y)
297298
Base.:<=(x,y::T) where T<:TensorTerm{V,0} where V = isless(x,y) | (x == y)
299+
300+
# random samplers
301+
302+
orand(T=Float64) = 2(rand(T).-0.5)
303+
import Random: SamplerType, AbstractRNG
304+
Base.rand(::AbstractRNG,::SamplerType{Manifold}) where V = SubManifold(Manifold(rand(1:5)))
305+
Base.rand(::AbstractRNG,::SamplerType{SubManifold}) = rand(SubManifold{rand(Manifold)})
306+
Base.rand(::AbstractRNG,::SamplerType{SubManifold{V}}) where V = SubManifold{V}(UInt(rand(0:1<<ndims(V)-1)))
307+
Base.rand(::AbstractRNG,::SamplerType{SubManifold{V,G}}) where {V,G} = Λ(V).b[rand(binomsum(ndims(V),G)+1:binomsum(ndims(V),G+1))]
308+
Base.rand(::AbstractRNG,::SamplerType{Simplex}) = rand(Simplex{rand(Manifold)})
309+
Base.rand(::AbstractRNG,::SamplerType{Simplex{V}}) where V = orand()*rand(SubManifold{V})
310+
Base.rand(::AbstractRNG,::SamplerType{Simplex{V,G}}) where {V,G} = orand()*rand(SubManifold{V,G})
311+
Base.rand(::AbstractRNG,::SamplerType{Simplex{V,G,B}}) where {V,G,B} = orand()*B
312+
Base.rand(::AbstractRNG,::SamplerType{Simplex{V,G,B,T}}) where {V,G,B,T} = rand(T)*B
313+
Base.rand(::AbstractRNG,::SamplerType{Simplex{V,G,B,T} where B}) where {V,G,T} = rand(T)*rand(SubManifold{V,G})
314+
Base.rand(::AbstractRNG,::SamplerType{Simplex{V,G,B,T} where {G,B}}) where {V,T} = rand(T)*rand(SubManifold{V})

0 commit comments

Comments
 (0)