You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the special cases that you want to compensate the offset back to the ordinary 1-based array, you
47
+
can use [`OffsetArrays.no_offset_view(A)`](@ref). Furthermore, you could use
48
+
`Base.require_one_based_indexing` if you want to ensure the array does not have offsets.
55
49
56
-
julia>summary(y)
57
-
"OffsetArrays.OffsetArray{Float64,8,Array{Float64,8}} with indices -1:1×-7:7×-128:512×-5:5×-1:1×-3:3×-2:2×-1:1"
50
+
```@repl index
51
+
OffsetArrays.no_offset_view(OA)
58
52
59
-
julia> y[-1,-7,-128,-5,-1,-3,-2,-1] =14
60
-
14
53
+
Base.require_one_based_indexing(ans)
61
54
62
-
julia> y[-1,-7,-128,-5,-1,-3,-2,-1] +=5
63
-
19.0
55
+
Base.require_one_based_indexing(OA)
64
56
```
65
57
66
-
You can use `OffsetArrays.no_offset_view(A)` if you want to return a view of the data in `A` but where indexing starts at 1.
67
-
68
58
## Example: Relativistic Notation
69
59
70
60
Suppose we have a position vector `r = [:x, :y, :z]` which is naturally one-based, ie. `r[1] == :x`, `r[2] == :y`, `r[3] == :z` and we also want to construct a relativistic position vector which includes time as the 0th component. This can be done with OffsetArrays like
71
61
72
-
```jldoctest
73
-
julia> using OffsetArrays
74
-
62
+
```jldoctest; setup = :(using OffsetArrays)
75
63
julia> r = [:x, :y, :z];
76
64
77
65
julia> x = OffsetVector([:t, r...], 0:3)
78
-
4-element OffsetArray(::Array{Symbol,1}, 0:3) with eltype Symbol with indices 0:3:
66
+
4-element OffsetArray(::Vector{Symbol}, 0:3) with eltype Symbol with indices 0:3:
79
67
:t
80
68
:x
81
69
:y
@@ -85,7 +73,7 @@ julia> x[0]
85
73
:t
86
74
87
75
julia> x[1:3]
88
-
3-element Array{Symbol,1}:
76
+
3-element Vector{Symbol}:
89
77
:x
90
78
:y
91
79
:z
@@ -94,17 +82,17 @@ julia> x[1:3]
94
82
## Example: Polynomials
95
83
96
84
Suppose one wants to represent the Laurent polynomial
97
-
```
85
+
86
+
```math
98
87
6/x + 5 - 2*x + 3*x^2 + x^3
99
88
```
100
-
in julia. The coefficients of this polynomial are a naturally `-1` based list, since the `n`th element of the list
101
-
(counting from `-1`) `6, 5, -2, 3, 1` is the coefficient corresponding to the `n`th power of `x`. This Laurent polynomial can be evaluated at say `x = 2` as follows.
102
89
103
-
```jldoctest
104
-
julia> using OffsetArrays
90
+
The coefficients of this polynomial are a naturally `-1` based list, since the `n`th element of the list
91
+
(counting from `-1`) `6, 5, -2, 3, 1` is the coefficient corresponding to the `n`th power of `x`. This Laurent polynomial can be evaluated at say `x = 2` as follows.
0 commit comments