# LowRankApprox.jl and sketch.jl

**URL:** <https://discourse.julialang.org/t/lowrankapprox-jl-and-sketch-jl/57200>\
**Category:** Performance\
**Tags:** question, package\
**Created:** [March 15, 2021, 3:06pm UTC](https://discourse.julialang.org/t/lowrankapprox-jl-and-sketch-jl/57200 "2021-03-15T15:06:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vlederer](https://avatars.discourse-cdn.com/v4/letter/v/e8c25b/32.png) [@vlederer](https://discourse.julialang.org/u/vlederer)\
**Post date:** [March 15, 2021, 3:06pm UTC](https://discourse.julialang.org/t/lowrankapprox-jl-and-sketch-jl/57200/1 "2021-03-15T15:06:18Z")

</div>

In LowRankApprox package we have access to sketching methods via sketch.jl.  
I only need to compute the sketching step below in pseudo-code:

```julia
function f(Q::StridedMatrix{Float32}, Qv::StridedVector{Float32},
           Sv::StridedVector{Float32}, order::Int)
  opts = LRAOptions()
  opts.sketch = :randn
  Sv[:,:] = sketch(:left, :n, Qv[:,:], order, opts)
  mul!(Qv, Q, ...)
  Sv[:,:] = sketch(:left, :n, Qv[:,:], order, opts)
end

```

As you can see, Sv and Qv have to be update in-place. And this function is called in the loop below

```julia
A = randn(Float32, n, m)
order = 5*m
Q = deepcopy(A)
S = zeros(Formats[2], order, m)
for k in 1:m
  f(view(Q, :, 1:k-1), view(Q, :, k),
    view(S, :, k), order)
end

```

1. Avoid regeneration of the random Gaussian Matrix  
So I am calling 2_m times the sketch() function how has to generate 2_m times a random Gaussian matrix. There is a way to reuse the same Gaussian matrix without re-generate her? (Random.seed!() will not do the trick).
2. In case of a mixed precision process  
when (typeof(Q)=typeof(Qv)) != typeof(Sv) for example:

```julia
f(Q::StridedMatrix{Float32}, Qv::StridedVector{Float32},
           Sv::StridedVector{Float64}, order::Int)

```

I will have to convert Qv into a Float64 Vector object-like, but there is no such method in julia when input type is a Strided object-like, right?
