I'm aware about several discussions in this group and julia-users for zero-based Julia arrays, proposals to have negative indices for Julia arrays, like Fortran has, and so on.
Generally having 1-based array for Julia is a good decision, but sometimes it is desirable to have Fortran-like array with indices that span some subranges of ℤ:
where it would be useful:
in the codes accompanying the book Numerical Solution of Hyperbolic Partial Differential Equations by prof. John A. Trangenstein these negative indices are used intensively for ghost cells for boundary conditions.
The same is true for Clawpack (stands for “Conservation Laws Package”) by prof. Randall J. LeVeque
and there are many other codes where such indices would be natural.
So such auxiliary class would be useful for speedy translation of such codes.
I just started to implement such an auxiliary type but as I'm quite new to Julia your help would be greatly appreciated.
I started with:
type FArray
ranges
array::Array
function FArray(T, r::Range1{Int}...)
dims = map((x) -> length(x), r)
array = Array(T, dims)
new(r, array)
end
end
Output:
# julia> include ("FortranArray.jl")
#
# julia> x = FArray(Float64, -1:1,-7:7,-128:512)
# FArray((-1:1,-7:7,-128:512),3x15x641 Array{Float64,3}:
# [:, :, 1] =
# 6.90321e-310 2.6821e-316 1.96042e-316 0.0 0.0 0.0 9.84474e-317 … 1.83233e-316 2.63285e-316 0.0 9.61618e-317 0.0
# 6.90321e-310 6.32404e-322 2.63285e-316 0.0 0.0 0.0 2.63292e-316 2.67975e-316 0.0 0.0 0.0 0.0
# 2.6821e-316 6.32404e-322 0.0 0.0 0.0 0.0 2.3428e-316 1.87441e-316 0.0 2.12342e-316 0.0 2.1135e-316
#
# [:, :, 2] =
I'm completely new to Julia
Questions: