JuliaLang/julia — pull request #9150 by andreasnoack (2014-11-25 17:23:54+00:00)
Title: RFC: Return views from UnitRange indexing of Arrays

This PR changes the behavior of array indexing to return a `SubArray` of the original array instead of an `Array`. This should reduce the number of intermediate arrays allocated in computations and hopefully that change will not be notified much in casual command prompt use of Julia.

I have decided to use `slice` instead of `sub` which is a change in indexing convention. However, this can easily be changed in the pull request if we decide to stick with the present convention. Because of this, I haven't adjusted the `arrayops.jl` tests yet. I'll only do that when we have decided to use either `sub` or `slice`. The rest of the tests should have been through the necessary adjustments.

Examples:
```julia
julia> A = randn(4,4)
4x4 Array{Float64,2}:
0.735034 2.32154 1.40147 -1.6871
-0.683693 0.72711 0.105667 1.30328
1.03254 0.038653 -0.0259387 -1.46718
0.600892 -0.0290964 -1.52698 -0.194185

julia> A[1:3,1:3]
3x3 SubArray{Float64,2,Array{Float64,2},(UnitRange{Int64},UnitRange{Int64}),1}:
0.735034 2.32154 1.40147
-0.683693 0.72711 0.105667
1.03254 0.038653 -0.0259387

julia> A[1,:]
4-element SubArray{Float64,1,Array{Float64,2},(Int64,Colon),2}:
0.735034
2.32154
1.40147
-1.6871
```

@carlobaldassi I have made some adjustments to the `BitArray` tests because indexing `Array{Bool}` now behaves differently. I haven't changed the behavior of `BitArray` indexing.

I have also not made any changes to indexing of `SparseMatrixCSC`.

@JeffBezanson I had to change quite a few places in `inference.jl` to avoid the creation of `SubArray`s there. You might want to take a look and see if the changes there are okay.