Speed up matrix multiplication with permuted vector

Sorry, I still have trouble constructing this x :sweat_smile:

Does this look correct for a MWE (Please provide a copy-pastable example next time :slight_smile: )?

julia> A = sprand(10,20,0.5)                                  
10×20 SparseMatrixCSC{Float64, Int64} with 93 stored entries: 
⡙⠂⢍⣘⢪⣎⠴⢁⣹⡷                                                    
⠟⣅⢆⢀⣗⣠⡡⠨⡈⢬                                                    
⠈⠚⠘⠛⠂⠉⠉⠈⠊⠚                                                    
                                                              
julia> x = sprand(10, 0.5)                                    
10-element SparseVector{Float64, Int64} with 5 stored entries:
  [1 ]  =  0.766693                                           
  [2 ]  =  0.66149                                            
  [4 ]  =  0.385874                                           
  [8 ]  =  0.90622                                            
  [10]  =  0.931918                                           

The x[QR.prow] allocates a bunch of new memory, which may be what slows you down here as I believe x is somewhat large. Sadly, using a view here doesn’t seem to help too much:

julia> @time y = QR.Q' * x[QR.prow];                
  0.000117 seconds (2.18 k allocations: 126.141 KiB)
                                                    
julia> @time y = QR.Q' * @view x[QR.prow];          
  0.000104 seconds (2.17 k allocations: 125.047 KiB)

I think at this point there’s some expert in terms of sparse matrices etc. needed :sweat_smile:

Nevertheless, doesn’t the suggestion at the end of the post you linked do what you want? This one:

1 Like