You can also express this as a two-dimensional index:
@view x[[1:3 4:6]]
# or
@view x[reshape(1:6, 2,3)]
In this case, though, the reshaped view should a bit more performant.
On Monday, October 3, 2016 at 10:33:34 AM UTC-5, Alexey Cherkaev wrote:
>
> Ah, of course! reshape the view! Sometimes
Ah, of course! reshape the view! Sometimes once things are put open in
front of you, one cannot help to wonder: "Why I ddin't think of that!".
Thanks a lot!
On Monday, October 3, 2016 at 4:21:32 AM UTC+2, Chris Rackauckas wrote:
>
> Fengyang's reshape((@view x[1:6]), (3, 2)) will work well and
Fengyang's reshape((@view x[1:6]), (3, 2)) will work well and will be
essentially cost-free since reshape creates a view, and a view of a view is
still just a view (no copy). Another way to write it is
reshape(view(x,1:6), (3, 2)). For example:
function f(t,u,du)
x = reshape(view(x,1:6), (3,
There should be no copy if you reshape a view.
julia> reshape((@view x[1:6]), (3, 2))
3×2
Base.ReshapedArray{Float64,2,SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{}}:
1.0 1.0
1.0 1.0
1.0 1.0
On Sunday, October 2, 2016 at 8:43:01 AM UTC-4, Alexey Cherkaev