diff --git a/Project.toml b/Project.toml index f148592..f35095c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SymmetricTensors" uuid = "1ab33d94-6c6c-50cc-93f0-e3f623a46aa0" authors = ["Krzysztof Domino ", "Ɓukasz Pawela ", "Piotr Gawron "] -version = "1.0.6" +version = "1.0.7" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" @@ -9,13 +9,13 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" CompilerSupportLibraries_jll = "e66e0078-7015-5450-92f7-15fbd957f2ae" -Memoization = "6fafb56a-5788-4b4e-91ca-c0cea6611c73" + [compat] julia = "1" Combinatorics = "1" StatsBase = "0.33" -Memoization = "0.2" + [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/SymmetricTensors.jl b/src/SymmetricTensors.jl index 02fdaa6..5949297 100644 --- a/src/SymmetricTensors.jl +++ b/src/SymmetricTensors.jl @@ -4,7 +4,6 @@ module SymmetricTensors using StatsBase using Random using LinearAlgebra - using Memoization import Base: +, -, *, /, size, getindex, rand, setindex! if VERSION >= v"1.3" using CompilerSupportLibraries_jll diff --git a/src/randgendat.jl b/src/randgendat.jl index c7c0ef3..aa15f23 100644 --- a/src/randgendat.jl +++ b/src/randgendat.jl @@ -10,7 +10,7 @@ function randsymarray(::Type{T}, dim::Int, N::Int = 4) where T<:Real t = zeros(fill(dim, N)...,) for i in pyramidindices(N,dim) n = rand(T) - for j in collect(permutations(i)) + for j in permutations(i) @inbounds t[j...] = n end end diff --git a/src/symmetrictensor.jl b/src/symmetrictensor.jl index f8690c0..ccb54e6 100644 --- a/src/symmetrictensor.jl +++ b/src/symmetrictensor.jl @@ -29,6 +29,22 @@ mutable struct SymmetricTensor{T <: AbstractFloat, N} end end +struct PyramidIndices{N} + size::Int +end + +@generated function _all_indices(p::PyramidIndices{N}) where {N} + quote + multinds = Tuple{fill(Int, $N)...,}[] + tensize = p.size + @nloops $N i x -> (x==$N) ? (1:tensize) : (i_{x+1}:tensize) begin + @inbounds multind = @ntuple $N x -> i_{$N-x+1} + push!(multinds, multind) + end + multinds + end +end + """ unfold(ar::Array{T,N}, mode::Int) @@ -122,24 +138,11 @@ julia> pyramidindices(2,3) (3,3) ``` """ -@memoize function pyramidindices(dims::Int, tensize::Int) - multinds = Tuple{fill(Int,dims)...,}[] - @eval begin - @nloops $dims i x -> (x==$dims) ? (1:$tensize) : (i_{x+1}:$tensize) begin - @inbounds multind = @ntuple $dims x -> i_{$dims-x+1} - push!($multinds, multind) - end - end - multinds +function pyramidindices(dims::Int, tensize::Int) + p = PyramidIndices{dims}(tensize) + return _all_indices(p) end -""" - pyramidindices(st::SymmetricTensor) - -Return the indices of the unique elements of the given symmetric tensor. -""" -pyramidindices(st::SymmetricTensor{<:Any, N}) where N = pyramidindices(N, st.dats) - """ sizetest(dats::Int, bls::Int) diff --git a/test/runtests.jl b/test/runtests.jl index 5bdc6f5..0e0a769 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -57,7 +57,6 @@ t1 = randsymarray(7, 3) end end @test found == length(pinds) - @test pyramidindices(st) == pinds end end