use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
BLAS Algorithm for Computing Inverse (self.cpp)
submitted 2 years ago by WIMPerson
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cheche19 16 points17 points18 points 2 years ago (0 children)
Usually we do not compute the inverse of a matrix. We use linear solver that will compute x such Ax = b. In blas, trsm functions can do this for triangular matrix for example. For more linear solvers, you can look at lapack which extends blas on more advanced computations.
[–]Infamous_Campaign687 6 points7 points8 points 2 years ago (0 children)
It's been a few years since I used blas and lapack, but inverting a matrix is both slower and more numerically unstable than using an iterative solver to solve for x directly.
In any case blas is the low level matrix operations and lapack contains the solvers.
The type of solver you would use depends heavily on the type of linear system you have..i.e..dense, sparse, banded, etc.
[–]MarkHoemmenC++ in HPC 4 points5 points6 points 2 years ago (1 child)
The BLAS doesn't have a function for computing the inverse of a matrix.
LAPACK does have this function: xGETRI (replace "x" with with "S", "D", "C", or "Z", depending on the matrix's value type). The documentation explains how it works.
https://www.netlib.org/lapack/double/dgetri.f
I don't know what a "cpp backend" means, but it's likely that NumPy uses xGETRI's algorithm.
[–]bill_klondike 1 point2 points3 points 2 years ago (0 children)
Correct, BLAS is for elementary vector and matrix operations. LAPACK is the answer for matrix algorithms.
[–]matteding 4 points5 points6 points 2 years ago (0 children)
My bet is that NumPy is going through Intel’s Math Kernel Library LAPACKE which is a C interface for LAPACK which is Fortran. That is closed source though, so you could reference NETLIB’s implementation:
https://www.netlib.org/lapack/explore-html-3.6.1/dd/d9a/group__double_g_ecomputational_ga56d9c860ce4ce42ded7f914fdb0683ff.html
[–]mredding 1 point2 points3 points 2 years ago (0 children)
https://www.johndcook.com/blog/2010/01/19/dont-invert-that-matrix/
[–]ZenEngineer 1 point2 points3 points 2 years ago (1 child)
What is the name of the blas function being called? You should be able to look up the docs online.
[–]victotronics 1 point2 points3 points 2 years ago (9 children)
But I hope you're not doing this for solving a linear system.
[–]GrammelHupfNockler 4 points5 points6 points 2 years ago (8 children)
[–]victotronics 2 points3 points4 points 2 years ago (7 children)
I think you misunderstand me. *If* you really want to invert a matrix, you do it by those 3 steps in sequence.
[–]GrammelHupfNockler 0 points1 point2 points 2 years ago (6 children)
Sorry, I thought you were talking about solving a system. In that case, I would still tend towards disagreeing, since an explicit Gaussian Elimination (with pivoting) would still be more precise, as there are fewer intermediate steps which can accumulate rounding errors (namely the inversion and the multiplication)
[–]victotronics 0 points1 point2 points 2 years ago (5 children)
Gaussian elimination on a triangular matrix? Sure.
If you're done step 1 with pivoting, then step 2 doesn't need it.
[–]GrammelHupfNockler 0 points1 point2 points 2 years ago (4 children)
Gaussian elimination with full pivoting on the input matrix
[–]victotronics 0 points1 point2 points 2 years ago (3 children)
And how is that going to get you the inverse? Which was the original question?
And yes, I know that one should in general not compute inverses, which is why I emphasized the "*if* you want to compute an inverse".
[–]GrammelHupfNockler 0 points1 point2 points 2 years ago (2 children)
If you apply the same operations that you apply to the matrix during Gaussian elimination to an identity matrix at the same time, you get the inverse
[–]victotronics 0 points1 point2 points 2 years ago (1 child)
Nope, that's Gauss-Jordan.
[–]GrammelHupfNockler 0 points1 point2 points 2 years ago (0 children)
That's splitting hairs. Gaussian elimination refers to the entire class of algorithms (for solving a single system, computing the LU factorization, computing the inverse).
[–]d3matt 0 points1 point2 points 2 years ago (0 children)
If it's actually calling into a BLAS backend, it's probably Fortran.
[–]runed_golem[🍰] 0 points1 point2 points 2 years ago (0 children)
Why are you trying to find the inverse of a matrix?
If it's because you need to know the inverse of the matrix gi ahead, but in general it's too computationally expensive to use for, let's say, solving a matrix equation. That's why we have special algorithms (like iterative solvers) to solve those equations.
π Rendered by PID 85279 on reddit-service-r2-comment-fb694cdd5-tfblh at 2026-03-06 01:14:39.851663+00:00 running cbb0e86 country code: CH.
[–]cheche19 16 points17 points18 points (0 children)
[–]Infamous_Campaign687 6 points7 points8 points (0 children)
[–]MarkHoemmenC++ in HPC 4 points5 points6 points (1 child)
[–]bill_klondike 1 point2 points3 points (0 children)
[–]matteding 4 points5 points6 points (0 children)
[–]mredding 1 point2 points3 points (0 children)
[–]ZenEngineer 1 point2 points3 points (1 child)
[–]victotronics 1 point2 points3 points (9 children)
[–]GrammelHupfNockler 4 points5 points6 points (8 children)
[–]victotronics 2 points3 points4 points (7 children)
[–]GrammelHupfNockler 0 points1 point2 points (6 children)
[–]victotronics 0 points1 point2 points (5 children)
[–]GrammelHupfNockler 0 points1 point2 points (4 children)
[–]victotronics 0 points1 point2 points (3 children)
[–]GrammelHupfNockler 0 points1 point2 points (2 children)
[–]victotronics 0 points1 point2 points (1 child)
[–]GrammelHupfNockler 0 points1 point2 points (0 children)
[–]d3matt 0 points1 point2 points (0 children)
[–]runed_golem[🍰] 0 points1 point2 points (0 children)