Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a view which is a vector created from different columns?

Tags:

arrays

julia

For matrices A, B, and C, and some integer i, is there an easy way to make view whose result is

vec([A[:,i];B[:,i];C[:,i]])

without creating any temporaries? My current try is:

A = rand(4,4); B = rand(4,4); C = rand(4,4)
[@view(A[:,1]);@view(B[:,1]);@view(C[:,1])]

that obviously creates the vector at the end instead of a view to the four columns stacked as a vector.

like image 664
Chris Rackauckas Avatar asked Dec 05 '25 06:12

Chris Rackauckas


1 Answers

It looks like you're looking for a lazy version of cat. Here's one implementation:

lazy cat http://www.mrwallpaper.com/wallpapers/Lazy-Cat.jpg

But in all seriousness, consider the (still experimental) solution ahwillia has here: CatViews.jl. In your situation, CatView(@view(A[:,1]), @view(B[:,1]), @view(C[:,1])) would work.

like image 73
Fengyang Wang Avatar answered Dec 07 '25 20:12

Fengyang Wang