With FSA I get around a factor 50 speedup (when I don't use the iterative 
corrector):

function \{T}(A::FixedMatrix{2, 2, T}, b::FixedVector{2, T})
    x = unroll_LU(A[1,1], A[1,2], b[1], A[2,1], A[2,2], b[2])
    return x
end

@inline function unroll_LU{T <: Number}(a::T ,b::T ,c::T , d::T ,e::T ,f::T)
    if a == 0 && d == 0
        throw(ArgumentError("singular matrix"))
    end
    if abs(a) >= abs(d)
        a⁻¹ = 1/a
        α = d * a⁻¹
        β = e - b * α
        β == 0 && throw(ArgumentError("singular matrix"))
        γ = f - c * α
        y = γ / β
        x = (c - b * y) * a⁻¹
        return Vec{2, T}(x, y)
    else
        unroll_LU(d,e,f, a,b,c)
    end
end


m = Mat{2,2, Float64}(rand(2,2))^C

c = Vec{2, Float64}(rand(2))



julia> @benchmark foo(m,c)
================ Benchmark Results ========================
     Time per evaluation: 13.60 ns [13.42 ns, 13.78 ns]


julia> @benchmark foo(rand(2,2),rand(2))
================ Benchmark Results ========================
     Time per evaluation: 564.77 ns [548.25 ns, 581.28 ns]



On Wednesday, November 18, 2015 at 11:53:59 AM UTC+1, Tim Holy wrote:
>
> If allocating the arrays is a big bottleneck, you might consider making 
> use 
> of/adding this to FixedSizeArrays. 
>
> --Tim 
>
> On Tuesday, November 17, 2015 05:12:13 PM Pavel wrote: 
> > Quite useful, thank you. Essentially choosing the form of exact 
> expression 
> > based on matrix element comparison. Appears to be reasonably stable and 
> > over 10 times speedup! 
> > 
> > On Tuesday, November 17, 2015 at 12:57:33 AM UTC-8, Kristoffer Carlsson 
> > 
> > wrote: 
> > > Maybe this link is of use? http://stackoverflow.com/a/10188318 
>
>

Reply via email to