xtensor-stack / xtensor-blas

BLAS extension to xtensor
BSD 3-Clause "New" or "Revised" License
158 stars 55 forks source link

Incorrect result from sample programs #191

Open michael-pruglo opened 3 years ago

michael-pruglo commented 3 years ago

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 from https://xtensor-blas.readthedocs.io/en/latest/usage.html . However, as the output, I get 0 for the first and 0, -inf for the second.

I'm using Windows 10 x64, Clion Installed cmake 3.19.7, xtensor 0.23.4, xtensor-blas 0.19.0, openblas 0.3.13, lapack 3.6.1 using anaconda Compile 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...
    }
}
tdegeus commented 3 years ago

Looking better at this, it seems that the examples are terrible!! So it's not you! The determinant of the first example is zero, which make the second example completely undefined. So they should be replaced with something descent. In the mean-time you could try something other the is defined.