### Install xtensor-blas from Sources Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/README.md Installs xtensor-blas from its source code using CMake. This method requires manual configuration of the installation prefix. ```bash cmake -D CMAKE_INSTALL_PREFIX=your_install_prefix make install ``` -------------------------------- ### CMake Installation and Configuration Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt This snippet details the CMake commands used for installing xtensor-blas headers, directories, and package configuration files. It includes setting up the installation paths for headers, directories, and pkgconfig files, as well as generating and installing CMake configuration files for package management. ```cmake export(EXPORT ${PROJECT_NAME}-targets FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") install(FILES ${XTENSOR_BLAS_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xtensor-blas) install(DIRECTORY ${INCLUDE_DIR}/xflens DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PATTERN *.tgz EXCLUDE PATTERN Makefile EXCLUDE PATTERN dummy.in.cc EXCLUDE PATTERN filter.pm EXCLUDE PATTERN CMakeLists.txt EXCLUDE) configure_file(${PROJECT_NAME}.pc.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig/") set(XTENSOR_BLAS_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xtensor-blasConfig.cmake") configure_package_config_file(${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION ${XTENSOR_BLAS_CMAKECONFIG_INSTALL_DIR}) # xtensor is header-only and does not depend on the architecture. # Remove CMAKE_SIZEOF_VOID_P from xblasConfigVersion.cmake so that an xblasConfig.cmake # generated for a 64 bit target can be used for 32 bit targets and vice versa. set(_XTENSOR_BLAS_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) unset(CMAKE_SIZEOF_VOID_P) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION ${${PROJECT_NAME}_VERSION} COMPATIBILITY AnyNewerVersion) set(CMAKE_SIZEOF_VOID_P ${_XTENSOR_CMAKE_SIZEOF_VOID_P}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake DESTINATION ${XTENSOR_BLAS_CMAKECONFIG_INSTALL_DIR}) install(EXPORT ${PROJECT_NAME}-targets FILE ${PROJECT_NAME}Targets.cmake DESTINATION ${XTENSOR_BLAS_CMAKECONFIG_INSTALL_DIR}) ``` -------------------------------- ### Build xtensor-blas from Source with CMake (Unix) Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/installation.rst Builds and installs xtensor-blas from source using CMake on Unix-like systems. Requires a BLAS installation (e.g., OpenBLAS, MKL). ```bash mkdir build cd buildcmake -DCMAKE_INSTALL_PREFIX=/path/to/prefix .. make install ``` -------------------------------- ### Build xtensor-blas from Source with CMake (Windows) Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/installation.rst Builds and installs xtensor-blas from source using CMake on Windows systems with NMake Makefiles. Requires a BLAS installation (e.g., OpenBLAS, MKL). ```bash mkdir build cd buildcmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=/path/to/prefix .. nmake nmake install ``` -------------------------------- ### xtensor-blas Library Definition and Include Directories Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt Defines the xtensor-blas library as an INTERFACE library and configures include directories for both build and installation contexts. ```cmake set(XTENSOR_BLAS_HEADERS ${INCLUDE_DIR}/xtensor-blas/xblas.hpp ${INCLUDE_DIR}/xtensor-blas/xblas_utils.hpp ${INCLUDE_DIR}/xtensor-blas/xblas_config.hpp ${INCLUDE_DIR}/xtensor-blas/xblas_config_cling.hpp ${INCLUDE_DIR}/xtensor-blas/xlapack.hpp ${INCLUDE_DIR}/xtensor-blas/xlinalg.hpp ) add_library(xtensor-blas INTERFACE) target_include_directories(xtensor-blas INTERFACE $ $) target_compile_features(xtensor-blas INTERFACE cxx_std_20) ``` -------------------------------- ### Installation Configuration Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt Includes CMake modules for installation and exports targets for package configuration files. ```cmake include(GNUInstallDirs) include(CMakePackageConfigHelpers) install(TARGETS xtensor-blas EXPORT ${PROJECT_NAME}-targets) ``` -------------------------------- ### Install C++ Headers for flens Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/include/xflens/cxxlapack/CMakeLists.txt This CMake command installs header files (.h, .tcc, .cxx) from the current source directory into the specified include directory for the flens library. It uses pattern matching to select the appropriate files for installation. ```cmake install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/flens FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc" PATTERN "*.cxx" ) ``` -------------------------------- ### CMake Minimum Requirements and Project Setup Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/test/CMakeLists.txt Sets the minimum required CMake version and defines the project name. It also enables testing and finds necessary packages like xtensor and xtensor-blas. ```cmake cmake_minimum_required(VERSION 3.29) if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) project(xtensor-blas-test) enable_testing() find_package(xtensor REQUIRED CONFIG) set(XTENSOR_INCLUDE_DIR ${xtensor_INCLUDE_DIRS}) find_package(xtensor-blas REQUIRED CONFIG) set(XTENSOR_BLAS_INCLUDE_DIR ${xblas_INCLUDE_DIRS}) endif () ``` -------------------------------- ### Install xtensor-blas with Conda Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/installation.rst Installs the xtensor-blas package using the conda-forge channel for the mamba package manager. ```bash mamba install -c conda-forge xtensor-blas ``` -------------------------------- ### Install xtensor-blas with Mamba Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/README.md Installs xtensor-blas and its core xtensor package using the mamba package manager from the conda-forge channel. ```bash mamba install -c conda-forge xtensor-blas ``` -------------------------------- ### Install C++ Headers for xtensor-blas Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/include/xflens/cxxblas/CMakeLists.txt This CMake command installs header files (.h), template header files (.tcc), and C++ source files (.cxx) from the current directory to the include directory of the flens package. It specifically excludes files matching the 'netlib' pattern. ```cmake install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/flens FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc" PATTERN "*.cxx" PATTERN "netlib" EXCLUDE ) ``` -------------------------------- ### CMake Minimum Requirements and Project Setup Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt Sets the minimum CMake version required and defines the project name. It also configures the C++ standard, defaulting to C++20 if not already set. ```cmake cmake_minimum_required(VERSION 3.29) # Otherwise adds std=gnu++17 on OSX ... set(CMAKE_CXX_EXTENSIONS OFF) project(xtensor-blas) # Otherwise adds flags for C++11 standard on OSX ... if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) endif() message(STATUS "🔧 C++ standard: ${CMAKE_CXX_STANDARD}") ``` -------------------------------- ### BLAS Vendor Selection Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/build-options.rst The BLA_VENDOR option allows users to specify which BLAS (Basic Linear Algebra Subprograms) installation to use during the build process. This is crucial for linking against the correct BLAS library for optimal performance. ```bash BLA_VENDOR= ``` -------------------------------- ### Google Benchmark Integration Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/benchmark/CMakeLists.txt This section handles the integration of the Google Benchmark library. It supports either downloading the benchmark source at configure time or using a local source directory. It then configures and builds the benchmark library, making its include directories and libraries available for the project. ```cmake if(DOWNLOAD_GBENCHMARK OR GBENCHMARK_SRC_DIR) if(DOWNLOAD_GBENCHMARK) # Download and unpack googlebenchmark at configure time configure_file(downloadGBenchmark.cmake.in googlebenchmark-download/CMakeLists.txt) else() # Copy local source of googlebenchmark at configure time configure_file(copyGBenchmark.cmake.in googlebenchmark-download/CMakeLists.txt) endif() execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-download ) if(result) message(FATAL_ERROR "CMake step for googlebenchmark failed: ${result}") endif() execute_process(COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-download ) if(result) message(FATAL_ERROR "Build step for googlebenchmark failed: ${result}") endif() # Add googlebenchmark directly to our build. This defines # the gtest and gtest_main targets. add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build) set(GBENCHMARK_INCLUDE_DIRS "${googlebenchmark_SOURCE_DIR}/include") set(GBENCHMARK_LIBRARIES benchmark) else() find_package(benchmark REQUIRED) endif() ``` -------------------------------- ### Include Directories and BLAS/LAPACK Configuration Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/test/CMakeLists.txt Sets include directories for xtensor and xtensor-blas. It then finds either OpenBLAS or a generic BLAS/LAPACK implementation based on the USE_OPENBLAS flag and sets the appropriate libraries. ```cmake include_directories(${XTENSOR_INCLUDE_DIR}) include_directories(${XBLAS_INCLUDE_DIR}) if(USE_OPENBLAS) find_package(OpenBLAS REQUIRED) set(BLAS_LIBRARIES ${CMAKE_INSTALL_PREFIX}${OpenBLAS_LIBRARIES}) else() find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) endif() message(STATUS "BLAS VENDOR: " ${BLA_VENDOR}) message(STATUS "BLAS LIBRARIES: " ${BLAS_LIBRARIES}) ``` -------------------------------- ### Executable and Target Definitions Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/benchmark/CMakeLists.txt Defines the main executable for xtensor benchmarks and custom targets for running benchmarks. The `benchmark_xtensor` executable is built and linked against xtensor, BLAS, LAPACK, and Google Benchmark libraries. `xbenchmark` is a custom target to simply run the benchmark executable, while `xpowerbench` includes steps to set CPU governor to performance before running the benchmark and reset it afterward. ```cmake include_directories(${XTENSOR_INCLUDE_DIR} ${GBENCHMARK_INCLUDE_DIRS}) set(XTENSOR_BENCHMARK main.cpp benchmark_blas.hpp ) set(XTENSOR_BENCHMARK_TARGET benchmark_xtensor) add_executable(${XTENSOR_BENCHMARK_TARGET} EXCLUDE_FROM_ALL ${XTENSOR_BENCHMARK} ${XTENSOR_HEADERS}) target_link_libraries(${XTENSOR_BENCHMARK_TARGET} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GBENCHMARK_LIBRARIES}) add_custom_target(xbenchmark COMMAND benchmark_xtensor DEPENDS ${XTENSOR_BENCHMARK_TARGET}) add_custom_target(xpowerbench COMMAND benchmark_xtensor DEPENDS ${XTENSOR_BENCHMARK_TARGET}) # Note: The original xpowerbench had commands to set CPU governor. # These are commented out here as they require elevated privileges and might not be portable. # add_custom_target(xpowerbench # COMMAND echo "sudo needed to set cpu power governor to performance" # COMMAND sudo cpupower frequency-set --governor performance # COMMAND benchmark_xtensor # COMMAND sudo cpupower frequency-set --governor powersave # DEPENDS ${XTENSOR_BENCHMARK_TARGET}) ``` -------------------------------- ### Solving Equations and Inverting Matrices Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/reference.rst Provides functions for solving systems of linear equations, least squares solutions, and matrix inversion. ```APIDOC xt::linalg::solve(const xexpression&, const xexpression&) Solves a linear matrix equation, or system of linear scalar equations. xt::linalg::lstsq(const xexpression&, const xexpression&) Returns the least-squares solution to a linear matrix equation. xt::linalg::inv(const xexpression&) Computes the inverse of a square expression. xt::linalg::pinv(const xexpression&) Computes the Moore-Penrose pseudo-inverse of an expression. ``` -------------------------------- ### Manual Linking with g++ Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/performance.rst This snippet demonstrates how to manually link your C++ program against BLAS and LAPACK libraries using the g++ compiler. ```bash g++ test.cpp -o test -lblas -llapack -DHAVE_CBLAS=1 ``` -------------------------------- ### Cling Configuration Header Generation Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt Generates a configuration header file (`xblas_config_cling.hpp`) for Cling, a C/C++ interpreter, by processing a template file. It sets library directory variables for Cling. ```cmake set(XTENSOR_BLAS_CLING_LIBRARY_DIR_64 "\"${CMAKE_INSTALL_PREFIX}/lib64\"") set(XTENSOR_BLAS_CLING_LIBRARY_DIR_32 "\"${CMAKE_INSTALL_PREFIX}/lib32\"") set(XTENSOR_BLAS_CLING_LIBRARY_DIR "\"${CMAKE_INSTALL_PREFIX}/lib\"") configure_file ( "${INCLUDE_DIR}/xtensor-blas/xblas_config_cling.hpp.in" "${INCLUDE_DIR}/xtensor-blas/xblas_config_cling.hpp" ) ``` -------------------------------- ### Update Version and Tag xtensor-blas Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/releasing.rst Steps to update the version macros in the configuration header, commit changes, and tag the release using Git. ```bash echo "XTENSOR_BLAS_VERSION_MAJOR = " echo "XTENSOR_BLAS_VERSION_MINOR = " echo "XTENSOR_BLAS_VERSION_PATCH = " ``` ```git git add xblas_config.hpp.in git commit -m "Bump version to Major.minor.patch" git tag Major.minor.patch git push git push --tags ``` -------------------------------- ### BLAS and LAPACK Configuration Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/benchmark/CMakeLists.txt Configures the BLAS (Basic Linear Algebra Subprograms) and LAPACK (Linear Algebra PACKage) libraries. It checks for the presence of CBLAS and, depending on the platform (Windows vs. others), uses either OpenBLAS or system-provided BLAS/LAPACK. It defines preprocessor macros based on the BLAS implementation found. ```cmake message(STATUS "BLAS VENDOR: " ${BLA_VENDOR}) message(STATUS "BLAS LIBRARIES: " ${BLAS_LIBRARIES}) if (HAVE_CBLAS) if (WIN32) find_package(OpenBLAS REQUIRED) set(BLAS_LIBRARIES ${CMAKE_INSTALL_PREFIX}${OpenBLAS_LIBRARIES}) else() find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) endif() add_definitions(-DHAVE_CBLAS=1 -DWITH_OPENBLAS=1) endif() ``` -------------------------------- ### xtensor-blas Dependency Table Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/README.md Illustrates the compatibility between different versions of xtensor-blas and the xtensor core library. This table is crucial for ensuring correct dependency management. ```markdown | `xtensor-blas` | `xtensor` | |-----------------|-----------| | master | ^0.27.0 | | 0.23.0 | ^0.27.0 | | 0.22.0 | ^0.26.0 | | 0.21.0 | ^0.25.0 | | 0.20.0 | ^0.24.0 | | 0.19.2 | ^0.23.3 | | 0.19.1 | ^0.23.3 | | 0.19.0 | ^0.23.0 | | 0.18.0 | ^0.22.0 | | 0.17.2 | ^0.21.4 | | 0.17.1 | ^0.21.2 | | 0.17.0 | ^0.21.1 | | 0.16.1 | ^0.20.4 | | 0.16.0 | ^0.20.0 | ``` -------------------------------- ### Linking with CMake Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/performance.rst This snippet shows how to configure CMake to link your target program against BLAS and LAPACK implementations, specifically OpenBLAS on Windows. ```cmake add_definitions(-DHAVE_CBLAS=1) if (WIN32) find_package(OpenBLAS REQUIRED) set(BLAS_LIBRARIES ${CMAKE_INSTALL_PREFIX}${OpenBLAS_LIBRARIES}) else() find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) endif() message(STATUS "BLAS VENDOR: " ${BLA_VENDOR}) message(STATUS "BLAS LIBRARIES: " ${BLAS_LIBRARIES}) target_link_libraries(your_target_name ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}) ``` -------------------------------- ### Test Executable Definition and Linking Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/test/CMakeLists.txt Defines the list of source files for the test executable 'test_xtensor_blas' and links it against the necessary libraries, including xtensor-blas, BLAS, LAPACK, doctest, and threads. ```cmake set(XTENSOR_BLAS_TESTS main.cpp test_blas.cpp test_lapack.cpp test_linalg.cpp test_lstsq.cpp test_qr.cpp test_dot.cpp test_tensordot.cpp test_lstsq.cpp test_dot.cpp test_dot_extended.cpp test_qr.cpp test_float_norm.cpp ) add_executable(test_xtensor_blas ${XTENSOR_BLAS_TESTS} ${XTENSOR_BLAS_HEADERS} ${XTENSOR_HEADERS}) target_link_libraries(test_xtensor_blas ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} doctest::doctest ${CMAKE_THREAD_LIBS_INIT}) ``` -------------------------------- ### xtensor-blas Build Options Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt Defines CMake options for configuring the build, including debug information, FLENS or OpenBLAS usage, test and benchmark suite enablement, and experimental C++23 support. ```cmake OPTION(CXXBLAS_DEBUG "print cxxblas debug information" OFF) OPTION(XTENSOR_USE_FLENS_BLAS "use FLENS generic implementation instead of cblas" OFF) # Decide whether to use OpenBLAS or not. # The user might have the folder containing OpenBLASConfig.cmake file # in the paths inspected by CMake already and just setting this to ON # would be enough to detect OpenBLAS. # If that is not the case, one can pass OpenBLAS_DIR without the boolean # toggle. OPTION(USE_OPENBLAS "use OpenBLAS (requires suitable OpenBLASConfig.cmake)" OFF) if(OpenBLAS_DIR) set(USE_OPENBLAS ON) endif() if(XTENSOR_USE_FLENS_BLAS) add_definitions(-DXTENSOR_USE_FLENS_BLAS=1) endif() if (CXXBLAS_DEBUG) add_definitions(-DCXXBLAS_DEBUG=1) endif() OPTION(BUILD_TESTS "xtensor-blas test suite" OFF) OPTION(BUILD_BENCHMARK "xtensor-blas test suite" OFF) OPTION(CPP23 "enables C++23 (experimental)" OFF) ``` -------------------------------- ### Decompositions Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/reference.rst Offers functions for Cholesky decomposition, QR decomposition, and Singular Value Decomposition (SVD) of expressions. ```APIDOC xt::linalg::cholesky(const xexpression&) Computes the Cholesky decomposition of a positive-definite expression. xt::linalg::qrmode Enum for specifying the mode of QR decomposition. xt::linalg::qr(const xexpression&, xt::linalg::qrmode) Computes the QR decomposition of an expression. xt::linalg::svd(const xexpression&) Computes the Singular Value Decomposition (SVD) of an expression. ``` -------------------------------- ### Matrix, Vector, and Tensor Products Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/reference.rst Provides functions for calculating dot products, outer products, matrix powers, Kronecker products, and tensor contractions for xtensor expressions. ```APIDOC xt::linalg::dot(const xexpression&, const xexpression&) Computes the dot product of two expressions. xt::linalg::vdot(const xexpression&, const xexpression&) Computes the vector dot product of two expressions. xt::linalg::outer(const xexpression&, const xexpression&) Computes the outer product of two expressions. xt::linalg::matrix_power(const xexpression&, int) Computes the matrix power of an expression. xt::linalg::kron(const xexpression&, const xexpression&) Computes the Kronecker product of two expressions. xt::linalg::tensordot(const xexpression&, const xexpression&, std::size_t) Computes the tensor contraction of two expressions along a single axis. xt::linalg::tensordot(const xexpression&, const xexpression&, const std::vector&, const std::vector&) Computes the tensor contraction of two expressions along specified axes. ``` -------------------------------- ### Conditional Subdirectory Inclusion for Tests and Benchmarks Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt Includes the 'test' subdirectory if `BUILD_TESTS` is enabled, and the 'benchmark' subdirectory if `BUILD_BENCHMARKS` is enabled. It also sets up necessary include directories for these subdirectories. ```cmake if(BUILD_TESTS) enable_testing() include_directories(${XTENSOR_BLAS_INCLUDE_DIR}) include_directories(${xtensor_INCLUDE_DIRS}) add_subdirectory(test) endif() if(BUILD_BENCHMARKS) include_directories(${XTENSOR_BLAS_INCLUDE_DIR}) include_directories(${xtensor_INCLUDE_DIRS}) add_subdirectory(benchmark) endif() ``` -------------------------------- ### Norms and Other Numbers Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/reference.rst Includes functions for calculating various matrix and vector norms, determinants, and matrix rank. ```APIDOC xt::linalg::normorder Enum for specifying the order of the norm. xt::linalg::norm(const xexpression&, int) Computes the norm of an expression with a specified order. xt::linalg::norm(const xexpression&, xt::linalg::normorder) Computes the norm of an expression with a specified norm order. xt::linalg::norm(const xexpression&) Computes the Frobenius norm of an expression. xt::linalg::det(const xexpression&) Computes the determinant of a square expression. xt::linalg::slogdet(const xexpression&) Computes the sign and logarithm of the determinant of a square expression. xt::linalg::matrix_rank(const xexpression&) Computes the rank of an expression. xt::linalg::trace(const xexpression&) Computes the trace of a square expression. ``` -------------------------------- ### Matrix Eigenvalues Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/reference.rst Provides functions to compute eigenvalues and eigenvectors for general and symmetric/Hermitian matrices. ```APIDOC xt::linalg::eig(const xexpression&) Computes the eigenvalues and eigenvectors of a general square expression. xt::linalg::eigvals(const xexpression&) Computes the eigenvalues of a general square expression. xt::linalg::eigh(const xexpression&, char) Computes the eigenvalues and eigenvectors of a symmetric or Hermitian expression. xt::linalg::eigh(const xexpression&, const xexpression&, const char) Computes the eigenvalues and eigenvectors of a symmetric or Hermitian expression with a specified job. xt::linalg::eigvalsh(const xexpression&) Computes the eigenvalues of a symmetric or Hermitian expression. ``` -------------------------------- ### xtensor Dependency Handling Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt Checks for the xtensor library, ensuring it meets the required version (0.27.0). If xtensor is not already found, it attempts to find it using `find_package`. ```cmake set(xtensor_REQUIRED_VERSION 0.27.0) if(TARGET xtensor) set(xtensor_VERSION ${XTENSOR_VERSION_MAJOR}.${XTENSOR_VERSION_MINOR}.${XTENSOR_VERSION_PATCH}) # Note: This is not SEMVER compatible comparison if( NOT ${xtensor_VERSION} VERSION_GREATER_EQUAL ${xtensor_REQUIRED_VERSION}) message(ERROR "Mismatch xtensor versions. Found '${xtensor_VERSION}' but requires: '${xtensor_REQUIRED_VERSION}'") else() message(STATUS "Found xtensor v${xtensor_VERSION}") endif() else() find_package(xtensor ${xtensor_REQUIRED_VERSION} REQUIRED) message(STATUS "Found xtensor: ${xtensor_INCLUDE_DIRS}/xtensor") endif() ``` -------------------------------- ### xtensor-blas Versioning Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt Extracts the major, minor, and patch versions of xtensor-blas from its configuration header file and sets the project version accordingly. ```cmake set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) set(XTENSOR_BLAS_INCLUDE_DIR ${INCLUDE_DIR}) file(STRINGS "${INCLUDE_DIR}/xtensor-blas/xblas_config.hpp" xtensor_blas_version_defines REGEX "#define XTENSOR_BLAS_VERSION_(MAJOR|MINOR|PATCH)") foreach(ver ${xtensor_blas_version_defines}) if(ver MATCHES "#define XTENSOR_BLAS_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") set(XTENSOR_BLAS_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") endif() endforeach() set(${PROJECT_NAME}_VERSION ${XTENSOR_BLAS_VERSION_MAJOR}.${XTENSOR_BLAS_VERSION_MINOR}.${XTENSOR_BLAS_VERSION_PATCH}) message(STATUS "xtensor-blas v${${PROJECT_NAME}_VERSION}") ``` -------------------------------- ### xtensor-blas Linear Algebra Functions Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/index.rst xtensor-blas provides a set of linear algebra functions within the xt::linalg namespace, mirroring NumPy's functionality. These include dot products, vector norms, matrix inversion, solving linear systems, eigenvalue decomposition, cross products, determinants, and more. The library requires C++14 and interfaces with BLAS/LAPACK via FLENS. ```cpp xt::linalg::dot(a, b) xT::linalg::norm(v, 1) xT::linalg::norm(v, 2) xT::linalg::inverse(m) xT::linalg::solve(a, b) xT::linalg::eig(m) xT::linalg::cross(a, b) xT::linalg::det(m) xT::linalg::slogdet(m) xT::linalg::matrix_rank(m) xT::linalg::inv(m) xT::linalg::cholesky(m) xT::linalg::qr(m) xT::linalg::svd(m) ``` -------------------------------- ### xtensor-blas Linear Algebra Functions Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/README.md Provides a summary of the linear algebra functions available in the xt::linalg namespace of xtensor-blas, which are designed to be equivalent to NumPy functions. These include dot, norm, inverse, solve, eig, cross, det, slogdet, matrix_rank, inv, cholesky, qr, and svd. ```cpp // Example usage (conceptual, actual signatures in xlinalg.hpp): // xt::linalg::dot(a, b); // xt::linalg::norm(v, 2); // xt::linalg::inverse(m); // xt::linalg::solve(a, b); // xt::linalg::eig(m); // xt::linalg::cross(a, b); // xt::linalg::det(m); // xt::linalg::slogdet(m); // xt::linalg::matrix_rank(m); // xt::linalg::inv(m); // xt::linalg::cholesky(m); // xt::linalg::qr(m); // xt::linalg::svd(m); ``` -------------------------------- ### Custom Test Target Creation Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/test/CMakeLists.txt Creates a custom target named 'xtest' that depends on the 'test_xtensor_blas' executable. It also registers 'xtest' as a CTest test, allowing it to be run using the 'ctest' command. ```cmake add_custom_target(xtest COMMAND test_xtensor_blas DEPENDS test_xtensor_blas) add_test(NAME xtest COMMAND test_xtensor_blas) ``` -------------------------------- ### Dependency and Build Type Configuration Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/test/CMakeLists.txt Finds the 'doctest' and 'Threads' packages. It also checks if CMAKE_BUILD_TYPE is set and defaults it to 'Release' if not, ensuring a consistent build type for tests. ```cmake find_package(doctest REQUIRED) find_package(Threads) if(NOT CMAKE_BUILD_TYPE) message(STATUS "Setting tests build type to Release") set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) else() message(STATUS "Tests build type is ${CMAKE_BUILD_TYPE}") endif() ``` -------------------------------- ### CMake Compiler Flags and Settings Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/benchmark/CMakeLists.txt Configures C++ compiler flags for GCC, Clang, and Intel compilers, including architecture-specific optimizations (-march=native), warning levels, C++ standard, and visibility settings. For MSVC, it sets specific flags for exception handling, multi-processing, and object file size, along with modifying runtime library settings. ```cmake cmake_minimum_required(VERSION 3.29) if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) project(xtensor-benchmark) find_package(xtensor REQUIRED CONFIG) set(XTENSOR_INCLUDE_DIR ${xtensor_INCLUDE_DIRS}) endif () message(STATUS "Forcing tests build type to Release") set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) include(CheckCXXCompilerFlag) string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported) if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") # Enable link time optimization and set the default symbol # visibility to hidden (very important to obtain small binaries) if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG) # Default symbol visibility set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") # Check for Link Time Optimization support # (GCC/Clang) # LTO had to be removed as google benchmark doesn't build with it # CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG) # if (HAS_LTO_FLAG) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") # endif() # Intel equivalent to LTO is called IPO if (CMAKE_CXX_COMPILER_ID MATCHES "Intel") CHECK_CXX_COMPILER_FLAG("-ipo" HAS_IPO_FLAG) if (HAS_IPO_FLAG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") endif() endif() endif() endif() if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj") set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO) foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}") endforeach() endif() ``` -------------------------------- ### C++ Standard and Compiler Flag Settings Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/test/CMakeLists.txt Configures C++ compiler flags based on the C++ standard (C++20 or C++23) and compiler type (GNU, Intel, MSVC, Clang). It includes standard flags, warnings, and optimization flags like '-march=native'. ```cmake include(CheckCXXCompilerFlag) string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE) include(set_compiler_flag.cmake) if(CPP23) # User requested C++20, but compiler might not oblige. set_compiler_flag( _cxx_std_flag CXX "-std=c++23" # this should work with GNU, Intel, PGI "/std:c++23" # this should work with MSVC ) if(_cxx_std_flag) message(STATUS "Building with C++23") endif() else() set_compiler_flag( _cxx_std_flag CXX REQUIRED "-std=c++20" # this should work with GNU, Intel, PGI "/std:c++20" # this should work with MSVC ) message(STATUS "Building with C++20") endif() if(NOT _cxx_std_flag) message(FATAL_ERROR "xtensor-blas needs a C++20-compliant compiler.") endif() if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32)) CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported) if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Wunused-variable") elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} /EHsc /MP /bigobj /wd4800") set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO) add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(NOT WIN32) CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported) if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Wunused-variable") else() # We are using clang-cl set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} /EHsc /MP /bigobj -Wno-unused-command-line-argument") set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO) add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) endif() else() message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}") endif() ``` -------------------------------- ### Update Conda-Forge Recipe for xtensor-blas Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/releasing.rst Instructions for updating the conda-forge recipe after a new xtensor-blas tag is released, including version, build number, and dependency checks. ```conda conda recipe update --version Major.minor.patch --build-number 0 --source-hash ``` -------------------------------- ### Calculate Log Determinant using xt::linalg::slogdet Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/usage.rst Shows how to use the `xt::linalg::slogdet` function, which is more robust against under/overflows by summing the logarithm of the determinant. It returns a `std::tuple` containing the sign and the logarithm of the determinant's absolute value, emulating NumPy's `np.linalg.slogdet` behavior. ```cpp xt::xarray a = {{3, 2, 1}, {0, 4, 2}, {1, 3, 5}}; auto d = xt::linalg::slogdet(a); std::cout << std::get<0>(d) << ", " << std::get<1>(d) << std::endl; // +1, 3.7376696 ``` -------------------------------- ### Other Linear Algebra Operations Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/reference.rst Includes the cross product function for 3D vectors. ```APIDOC xt::linalg::cross(const xexpression&, const xexpression&) Computes the cross product of two 3D vectors. ``` -------------------------------- ### Calculate Determinant using xt::linalg::det Source: https://github.com/xtensor-stack/xtensor-blas/blob/master/docs/source/usage.rst Demonstrates how to include the xlinalg header and use the `xt::linalg::det` function to calculate the determinant of a given xarray. This function is part of the xtensor-blas library and aims to provide an interface similar to NumPy's `np.linalg.det`. ```cpp #include "xtensor-blas/xlinalg.hpp" int main() { xt::xarray a = {{3, 2, 1}, {0, 4, 2}, {1, 3, 5}}; auto d = xt::linalg::det(a); std::cout << d << std::endl; // 42.0 } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.