c++openblasxtensor

xtensor-blas incorrect computation


I'm trying to use xtensor-blas for the first time. I've had lots of difficulties linking to it, but finally, I've done that and tried to run the sample programs. However, as the output, I get 0 for the first and 0, -inf for the second.

I'm using Windows 10 x64, Clion 2021.1
Installed cmake 3.19.7, xtensor 0.23.4, xtensor-blas 0.19.0, openblas 0.3.13, lapack 3.6.1 using anaconda
Compiled using Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe

cmake_minimum_required(VERSION 3.19)
project(tstxtensor6)

set(CMAKE_CXX_STANDARD 20)

find_package(xtensor)
find_package(xtensor-blas)
add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} xtensor xtensor-blas)
#include <xtensor-blas/xlinalg.hpp>

int main()
{
    {
        xt::xarray<double> a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        auto d = xt::linalg::det(a);
        std::cout << d << std::endl;  // 6.661338e-16
    }
    {
        xt::xarray<double> a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        auto d = xt::linalg::slogdet(a);
        std::cout << std::get<0>(d) << ", " << std::get<1>(d) << std::endl;  // 1, -34.9450...
    }
}

Solution

  • The problem is with the example, that uses a singular matrix. Its determinant should be 0 as your code outputs correctly.

    This case was discussed in a pull request for xtensor-blas, and the solution was to change the example.