# Hadamard.jl and fwht()

**URL:** <https://discourse.julialang.org/t/hadamard-jl-and-fwht/57185>\
**Category:** Performance\
**Tags:** question, package\
**Created:** [March 15, 2021, 9:30am UTC](https://discourse.julialang.org/t/hadamard-jl-and-fwht/57185 "2021-03-15T09:30:46Z")\
**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, 9:30am UTC](https://discourse.julialang.org/t/hadamard-jl-and-fwht/57185/1 "2021-03-15T09:30:46Z")

</div>

Hi, in order to use fwht() function from Hadamard.jl package, I have to resize the input vector A into a vector tempA of a length that can be write as a power of two. I am doing this in the srht() function below at row 2. Also ispow2() checks if size(A)[1] is a power of 2 and n2p(size(A)[1]) returns the next upper power of 2 interger from the input interger.

```julia
function srht(to::TimerOutput, A::Array{<:AbstractFloat,1}, D::Array{Int}, R::Array{Int}, l::Int)::Array{<:AbstractFloat,1}
    @timeit to "vcat" tempA = (ispow2(size(A)[1])) ? A : vcat(A,zeros(eltype(A), n2p(size(A)[1])-size(A)[1], 1))
    #@assert l <= size(tempA)[1]
    scale::AbstractFloat = (size(tempA)[1]/sqrt(l))
    @timeit to "D.*tempA" view(tempA,:,1).*=D
    copyto!(tempA,@timeit to "fwht" fwht(tempA))
    return @timeit to "lmul!" lmul!(scale, tempA[R])
end

```

Without this resize/recast step, the fwht() function exits with an error (like input size isn’t a power of two). Is it possible to avoid this time and memory comsuming step, tagged with “vcat” in plot below ?  
(see only RGS or GAUSS process, “vcat” is in blue shade, time is ~60-120 sec, Matrix size is 5E6x300)

 ![dodgeTPSbench](https://global.discourse-cdn.com/julialang/original/3X/0/5/0571c29721954ab8efea57c742ba948dc781f9f9.png)
