From d6510969e177a6ccaa64f250d5b923ff076aaa53 Mon Sep 17 00:00:00 2001 From: Ben Arthur Date: Thu, 16 Apr 2026 10:53:56 -0400 Subject: [PATCH 1/3] make A[begin:stride:end] work --- src/TensorStoreWrapper.jl | 6 ++++++ test/runtests.jl | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/TensorStoreWrapper.jl b/src/TensorStoreWrapper.jl index 160fc34..74fbe53 100644 --- a/src/TensorStoreWrapper.jl +++ b/src/TensorStoreWrapper.jl @@ -187,6 +187,9 @@ function Base.axes(w::TensorStoreWrapper) max_indices = pyconvert(Vector{Int}, domain.exclusive_max) return Tuple((min_indices[i]+1):max_indices[i] for i in 1:rank) end +Base.axes(w::TensorStoreWrapper, d::Integer) = axes(w)[d] +Base.firstindex(w::TensorStoreWrapper, d::Integer) = first(axes(w, d)) +Base.lastindex(w::TensorStoreWrapper, d::Integer) = last(axes(w, d)) function Base.show(io::IO, w::TensorStoreWrapper) print(io, "TensorStore(", eltype(w), ", rank=", ndims(w), ", shape=", size(w), ")") @@ -235,6 +238,9 @@ function Base.axes(w::IndexDomainWrapper) max_indices = pyconvert(Vector{Int}, parent(w).exclusive_max) return Tuple((min_indices[i]+1):max_indices[i] for i in 1:rank) end +Base.axes(w::IndexDomainWrapper, d::Integer) = axes(w)[d] +Base.firstindex(w::TensorStoreWrapper, d::Integer) = first(axes(w, d)) +Base.lastindex(w::TensorStoreWrapper, d::Integer) = last(axes(w, d)) """ labels(w::IndexDomainWrapper) -> Vector{String} diff --git a/test/runtests.jl b/test/runtests.jl index 4068501..5a6d81d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,6 +24,10 @@ using PythonCall @test ndims(w) == 2 @test size(w) == (10, 20) @test axes(w) == (1:10, 1:20) + @test firstindex(w, 1) == 1 + @test lastindex(w, 1) == 10 + @test lastindex(w, 2) == 20 + end @testset "Write & Read Operations" begin @@ -45,6 +49,9 @@ using PythonCall sub_w = w[x=1:5, y=11:15] @test size(sub_w) == (5, 5) @test axes(sub_w) == (1:5, 11:15) + @test firstindex(domain, 1) == 1 + @test lastindex(domain, 1) == 10 + @test lastindex(domain, 2) == 20 # translate_by tw = PyTensorStore.translate_by(w, 10, 20) From a4bcbcb418a5120cd7378e55b1bc06123bb5be9f Mon Sep 17 00:00:00 2001 From: Ben Arthur Date: Thu, 16 Apr 2026 12:53:49 -0400 Subject: [PATCH 2/3] fixup d6510969e177a6 --- src/TensorStoreWrapper.jl | 4 ++-- test/runtests.jl | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/TensorStoreWrapper.jl b/src/TensorStoreWrapper.jl index 74fbe53..4c073d1 100644 --- a/src/TensorStoreWrapper.jl +++ b/src/TensorStoreWrapper.jl @@ -239,8 +239,8 @@ function Base.axes(w::IndexDomainWrapper) return Tuple((min_indices[i]+1):max_indices[i] for i in 1:rank) end Base.axes(w::IndexDomainWrapper, d::Integer) = axes(w)[d] -Base.firstindex(w::TensorStoreWrapper, d::Integer) = first(axes(w, d)) -Base.lastindex(w::TensorStoreWrapper, d::Integer) = last(axes(w, d)) +Base.firstindex(w::IndexDomainWrapper, d::Integer) = first(axes(w, d)) +Base.lastindex(w::IndexDomainWrapper, d::Integer) = last(axes(w, d)) """ labels(w::IndexDomainWrapper) -> Vector{String} diff --git a/test/runtests.jl b/test/runtests.jl index 5a6d81d..a0cb3da 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -49,9 +49,9 @@ using PythonCall sub_w = w[x=1:5, y=11:15] @test size(sub_w) == (5, 5) @test axes(sub_w) == (1:5, 11:15) - @test firstindex(domain, 1) == 1 - @test lastindex(domain, 1) == 10 - @test lastindex(domain, 2) == 20 + @test firstindex(sub_w, 1) == 1 + @test lastindex(sub_w, 1) == 5 + @test lastindex(sub_w, 2) == 15 # translate_by tw = PyTensorStore.translate_by(w, 10, 20) From ebaa378e9f0b88b9e0d08a6f0c21dcb25068ee40 Mon Sep 17 00:00:00 2001 From: Ben Arthur Date: Thu, 16 Apr 2026 12:54:08 -0400 Subject: [PATCH 3/3] test begin and end --- test/runtests.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index a0cb3da..c0b26be 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -27,7 +27,7 @@ using PythonCall @test firstindex(w, 1) == 1 @test lastindex(w, 1) == 10 @test lastindex(w, 2) == 20 - + @test size(w[begin:2:end, begin:2:end]) == (5,10) end @testset "Write & Read Operations" begin @@ -52,6 +52,7 @@ using PythonCall @test firstindex(sub_w, 1) == 1 @test lastindex(sub_w, 1) == 5 @test lastindex(sub_w, 2) == 15 + @test size(sub_w[begin:2:end, begin:2:end]) == (3,3) # translate_by tw = PyTensorStore.translate_by(w, 10, 20)