Skip to content

Fortran-like arrays with arbitrary, zero or negative starting indices.

License

Notifications You must be signed in to change notification settings

jishnub/OffsetArrays.jl

 
 

Repository files navigation

OffsetArrays.jl

Build Status codecov.io PkgEval

OffsetArrays provides Julia users with arrays that have arbitrary indices, similar to those found in some other programming languages like Fortran.

Usage

You can construct such arrays as follows:

OA = OffsetArray(A, axis1, axis2, ...)

where you want OA to have axes (axis1, axis2, ...) and be indexed by values that fall within these axis ranges. Example:

using OffsetArrays
A = reshape(1:15, 3, 5)
println("here is A:")
display(A)
OA = OffsetArray(A, -1:1, 0:4)    # OA will have axes (-1:1, 0:4)
println("here is OA:")
display(OA)
@show OA[-1,0] OA[1,4]

which prints out

here is A:
3×5 reshape(::UnitRange{Int64}, 3, 5) with eltype Int64:
 1  4  7  10  13
 2  5  8  11  14
 3  6  9  12  15
here is OA:
OffsetArray(reshape(::UnitRange{Int64}, 3, 5), -1:1, 0:4) with eltype Int64 with indices -1:1×0:4:
 1  4  7  10  13
 2  5  8  11  14
 3  6  9  12  15
OA[-1, 0] = 1
OA[1, 4] = 15

About

Fortran-like arrays with arbitrary, zero or negative starting indices.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Julia 100.0%