JuliaSIMD / JuliaSIMD/StrideArraysCore.jl

--check-bounds=yes should also check bounds for `view`s

Open
#27 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
19
Forks
10
PR merge metrics
No merged PRs in 30d

Description

With `julia --check-bounds=yes`, bounds are checked when directly accessing arrays:

```
julia> using StrideArraysCore

julia> zeros_stridearray(size...) = StrideArray(zeros(Float32, size...), static.(size))
zeros_stridearray (generic function with 1 method)

julia> x = zeros_stridearray(8, 8, 12, 64);

julia> x[1, 1, 1, 65]
ERROR: BoundsError: attempt to access 8×8×12×64 PtrArray [output truncated by me]
```
No such check happens when creating a view:

```
julia> view(x, 1, 1, 1, 65)
0-dimensional StrideArray{Float32, 0, (), Tuple{}, Tuple{}, Tuple{}, Array{Float32, 4}}:
0.0

julia> view(x, :, 1, 1, 65)
8-element StrideArray{Float32, 1, (1,), Tuple{StaticInt{8}}, Tuple{Nothing}, Tuple{StaticInt{1}}, Array{Float32, 4}} with indices static(1):static(8):
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
```

By chance, I also noticed this incorrect behavior:
```
julia> view(x, 1)
ERROR: StackOverflowError:

julia> x = zeros(8, 8, 12, 64);

julia> view(x, 1)
0-dimensional view(::Vector{Float64}, 1) with eltype Float64:
0.0
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.