Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special case for 2x3 matrix solve #1292

Open
weymouth opened this issue Dec 24, 2024 · 0 comments
Open

Special case for 2x3 matrix solve #1292

weymouth opened this issue Dec 24, 2024 · 0 comments

Comments

@weymouth
Copy link

weymouth commented Dec 24, 2024

I'm doing some coordinate transformation stuff that requires the solution of a 2 by 3 system. Right now, all rectangular SMatrix systems are done by LinearAlgebra and the allocations mean I can't run this on the GPU. I coded this version which seems to be working and non-allocating.

@inline function (\)(a::SMatrix{2,3}, b::SVector{2})
    # columns of a'
    a1,a2 = a[1,:],a[2,:]
    
    # Q,R decomposition
    r11 = norm(a1)
    q1 = a1/r11
    r12 = q1'*a2
    p = a2-r12*q1
    r22 = norm(p) < eps(r11) ? one(r11) : norm(p)
    q2 = p/r22

    # forward substitution to solve R'v = b
    v1 = b[1]/r11
    v2 = (b[2]-r12*v1)/r22

    # return solution x = Qv 
    return q1*v1+q2*v2
end

I'm happy to add this to solve.jl and do a PR if it would be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant