22# This file is part of DirectSum.jl. It is licensed under the GPL license
33# Grassmann Copyright (C) 2019 Michael Reed
44
5+ struct Dim{N}
6+ @pure Dim {N} () where N = new {N} ()
7+ end
8+
9+ @pure Dim (N:: Int ) = Dim {N} ()
10+ @pure Base. ndims (:: Dim{N} ) where N = N
11+
512# vector and co-vector prefix
613const pre = (" v" ," w" ," ϵ" ," ∂" )
714
@@ -82,8 +89,9 @@ const ndigits_extra = Dict{Bits,SVector}[]
8289 end
8390end
8491
92+ const indices_cache = Dict {Bits,Vector} ()
8593@pure indices (b:: Bits ) = findall (digits (b,base= 2 ).== 1 )
86- @pure function indices (b:: Bits ,N:: Int )
94+ @pure function indices_calc (b:: Bits ,N:: Int )
8795 d = ndigits (b,N)
8896 l = length (d)
8997 a = Int[]
92100 end
93101 return a
94102end
103+ @pure function indices (b:: Bits ,N:: Int )
104+ ! haskey (indices_cache,b) && push! (indices_cache,b=> indices_calc (b,N))
105+ return @inbounds indices_cache[b]
106+ end
95107
96- @pure shift_indices (V:: T ,b:: Bits ) where T<: VectorSpace = shift_indices (V,indices (b,ndims (V)))
97- function shift_indices (s:: T ,set:: Vector{Int} ) where T<: VectorSpace{N,M} where N where M
108+ @pure shift_indices (V:: T ,b:: Bits ) where T<: VectorSpace = shift_indices! (V,copy ( indices (b,ndims (V) )))
109+ function shift_indices! (s:: T ,set:: Vector{Int} ) where T<: VectorSpace{N,M} where N where M
98110 if ! isempty (set)
99111 k = 1
100112 hasinf (s) && set[1 ] == 1 && (set[1 ] = - 1 ; k += 1 )
@@ -104,6 +116,7 @@ function shift_indices(s::T,set::Vector{Int}) where T<:VectorSpace{N,M} where N
104116 end
105117 return set
106118end
119+ @deprecate (shift_indices (s:: VectorSpace ,set:: Vector{Int} ),shift_indices! (s:: VectorSpace ,set:: Vector{Int} ))
107120
108121# printing of indices
109122@inline function printindex (i,l:: Bool = false ,e:: String = pre[1 ],t= i> 36 ,j= t ? i- 26 : i)
0 commit comments