Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- In tensor index notation, `r[;]` now denotes a tensor with no indices, just like `r[]` ([#325](https://github.com/QuantumKitHub/TensorOperations.jl/issues/325)).

### Performance

## [5.8.4](https://github.com/QuantumKitHub/TensorOperations.jl/compare/v5.8.3...v5.8.4) - 2026-11-16
Expand Down
2 changes: 2 additions & 0 deletions src/indexnotation/analyzers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function decomposetensor(ex)
else
return ex.args[1], ex.args[2:end], Any[]
end
elseif isemptysplittensor(ex)
return ex.args[1], Any[], Any[]
elseif isexpr(ex, :typed_vcat)
if isexpr(ex.args[2], [:row, :tuple])
leftind = ex.args[2].args
Expand Down
2 changes: 2 additions & 0 deletions src/indexnotation/preprocessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ function replaceindices((@nospecialize f), ex)
return Expr(:block, map(x -> replaceindices(f, x), ex.args)...)
elseif isexpr(ex, :macrocall) && ex.args[1] == Symbol("@notensor")
return ex
elseif isemptysplittensor(ex)
return ex
elseif istensor(ex)
if ex.head == :ref || ex.head == :typed_hcat
if length(ex.args) == 1
Expand Down
7 changes: 6 additions & 1 deletion src/indexnotation/verifiers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ function isindex(ex)
end
end

# Julia parses A[;] as a typed concatenation with dimension 1 and no elements.
isemptysplittensor(ex) = isexpr(ex, :typed_ncat, 2) && ex.args[2] === 1

# test for a simple tensor object indexed by valid indices
"""
istensor(ex)
Expand All @@ -42,6 +45,8 @@ function istensor(ex::Expr)
else
return all(isindex, ex.args[2:end])
end
elseif isemptysplittensor(ex)
return true
elseif ex.head == :typed_vcat && length(ex.args) == 3
if isexpr(ex.args[2], [:row, :tuple])
all(isindex, ex.args[2].args) || return false
Expand Down Expand Up @@ -120,7 +125,7 @@ function isscalarexpr(ex)
return true
elseif isexpr(ex, :call) && ex.args[1] == :tensorscalar
return istensorexpr(ex.args[2])
elseif isexpr(ex, (:ref, :typed_vcat, :typed_hcat))
elseif isexpr(ex, (:ref, :typed_vcat, :typed_hcat)) || isemptysplittensor(ex)
return false
elseif isexpr(ex, :call) # || isdefinition(ex) || isassignment(ex)
return all(isscalarexpr, ex.args[2:end])
Expand Down
5 changes: 5 additions & 0 deletions test/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
@test !isindex(:("x"))
@test !isindex(:(5.1))

@test istensor(:(a[;]))
@test !isscalarexpr(:(a[;]))
@test decomposetensor(:(a[;])) == decomposetensor(:(a[]))
@test !istensor(:(a[;;]))
@test !istensor(:(a[i;; j]))
@test istensor(:(a[1, 2, 3]))
@test decomposetensor(:(a[1, 2, 3])) == (:a, Any[1, 2, 3], Any[])
@test istensor(:(a[5][a b c]))
Expand Down
12 changes: 12 additions & 0 deletions test/tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
#-----------------------------------------
backendlist = (BaseCopy(), BaseView(), StridedNative(), StridedBLAS())

@testset "empty left and right indices on input" begin
r = fill(5.0)
@tensor s[] := 2 * r[;]
@test s == 2 * r
end

@testset "with backend $b" for b in backendlist
@testset "empty left and right indices" begin
A = [1.0 2.0; 3.0 4.0]
@tensor backend = b r[;] := A[1; 1]
@test r == fill(tr(A))
end

@testset "tensorcontract 1" begin
A = randn(Float64, (3, 5, 4, 6))
p = (4, 1, 3, 2)
Expand Down
Loading