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

Different behaviors of solve, solve_triangular, and solve_cholesky (possibly a bug) #242

Open
shiqingw opened this issue Mar 21, 2024 · 0 comments

Comments

@shiqingw
Copy link

I want to solve linear equations like AX = B where A is a n-by-n nonsingular square matrix, and B is a n-by-m matrix. When I tried to make use of the structure of the coefficient matrix A, I found that the behaviors of solve, solve_triangular, and solve_cholesky are different. It seems that solve does what I want, but solve_triangular and solve_cholesky only solve the first column of B.

Here is a simple example:

#include <iostream>
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>
#include <xtensor-blas/xlinalg.hpp>

int main()
{   xt::xarray<double> A {{4,0,0},
                          {0,4,0},
                          {0,0,4}};
    xt::xarray<double> L {{2,0,0},
                          {0,2,0},
                          {0,0,2}};
    xt::xarray<double> B {{1,0,0},
                          {0,2,0},
                          {0,0,3}};

    std::cout << xt::linalg::solve(A, B) << std::endl;
    std::cout << xt::linalg::solve_triangular(A, B) << std::endl;
    std::cout << xt::linalg::solve_cholesky(L, B) << std::endl;
}

The output is:

{{ 0.25,  0.  ,  0.  },
 { 0.  ,  0.5 ,  0.  },
 { 0.  ,  0.  ,  0.75}}
{{ 0.25,  0.  ,  0.  },
 { 0.  ,  2.  ,  0.  },
 { 0.  ,  0.  ,  3.  }}
{{ 0.25,  0.  ,  0.  },
 { 0.  ,  2.  ,  0.  },
 { 0.  ,  0.  ,  3.  }}

Can we align solve_triangular and solve_cholesky with solve?

@shiqingw shiqingw changed the title Different behaviors of solve, solve_triangular, and solve_cholesky (potentially a bug) Different behaviors of solve, solve_triangular, and solve_cholesky (possibly a bug) Mar 21, 2024
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