Fortran-like arrays x = FArray(Float64, -1:1,-7:7,-128:512)

60 views
Skip to first unread message

Alexander Samoilov

unread,
Dec 6, 2013, 10:38:45 AM12/6/13
to juli...@googlegroups.com
Dear developers,

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 ℤ:

    julia> x = FArray(Float64, -1:1,-7:7,-128:512)

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:
  1. more efficient REPL loop for program development. Repeated include ("FortranArray.jl") is not possible. I mean how to clean from previously evaluated FArray definitions.
  2. would like to have more efficient (?) ranges::Vector{Range1{Int}} specialization but don't know how convert from tuple r::Range1{Int}... to vector (is it possible?).
  3. any recommendations for getting more efficient code, especially for array specializations and not yet written getindex, setindex.
Any comments would be greatly appreciated.
Thanks!
Alexander
Reply all
Reply to author
Forward
0 new messages