### Basic usage replaced with getting started Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst Replaces the 'basic usage' section with a more comprehensive 'getting started' guide. This aims to provide a smoother onboarding experience for new users. ```cpp /* * basic usage replaced with getting started * #1004 */ ``` -------------------------------- ### Improve getting started CMakeLists.txt Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst The 'getting started' guide, specifically the CMakeLists.txt file, has been improved. This likely makes it easier for new users to build and integrate xtensor into their projects. ```cmake # Improved getting started CMakeLists.txt # See PR #1440 for details. ``` -------------------------------- ### First xtensor Example: Array Addition Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/getting_started.rst Demonstrates basic array creation and element-wise addition using xtensor. It includes creating two xarray objects and performing an operation between them. Requires xtensor headers. ```cpp #include #include #include #include int main(int argc, char* argv[]) { xt::xarray arr1 {{1.0, 2.0, 3.0}, {2.0, 5.0, 7.0}, {2.0, 5.0, 7.0}}; xt::xarray arr2 {5.0, 6.0, 7.0}; xt::xarray res = xt::view(arr1, 1) + arr2; std::cout << res << std::endl; return 0; } ``` -------------------------------- ### Second xtensor Example: Reshaping an Array Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/getting_started.rst Shows how to initialize a 1-dimensional xarray and then reshape it in-place to a 2-dimensional array. Demonstrates the `reshape` method of xarray. ```cpp #include #include #include int main(int argc, char* argv[]) { xt::xarray arr {1, 2, 3, 4, 5, 6, 7, 8, 9}; arr.reshape({3, 3}); std::cout << arr; return 0; } ``` -------------------------------- ### Compiling xtensor Example with g++ Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/getting_started.rst Shows how to compile a C++ program that uses xtensor with g++. It highlights the use of the -I flag to specify include paths for xtensor and xtl headers. Assumes the code is in example.cpp. ```bash g++ -I /path/to/xtensor/ -I /path/to/xtl/ example.cpp -o example ``` -------------------------------- ### Building xtensor Project with CMake Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/getting_started.rst Provides a minimal CMakeLists.txt file for building a project that uses xtensor. It includes finding xtl and xtensor packages, adding an executable, and linking against xtensor libraries. Also mentions optional flags for optimization and SIMD acceleration. ```cmake cmake_minimum_required(VERSION 3.1) project(first_example) find_package(xtl REQUIRED) find_package(xtensor REQUIRED) add_executable(first_example src/example.cpp) if(MSVC) set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO) endif() target_link_libraries(first_example xtensor xtensor::optimize xtensor::use_xsimd) ``` -------------------------------- ### CMake SIMD Acceleration with xsimd Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/getting_started.rst Demonstrates linking xtensor::use_xsimd in CMake to enable SIMD (Single Instruction, Multiple Data) acceleration provided by the xsimd library, which can significantly improve performance on tensor operations. ```cmake target_link_libraries(... xtensor::use_xsimd) ``` -------------------------------- ### CMake Optimization Flags for xtensor Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/getting_started.rst Illustrates how to link xtensor::optimize in CMake to enable hardware-specific compiler flags like -march=native (Unix) or /EHsc /MP /bigobj (Windows) for potential performance improvements. ```cmake target_link_libraries(... xtensor::optimize) ``` -------------------------------- ### Broadcasting with xt::pow Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/getting_started.rst Illustrates the broadcasting mechanism in xtensor by applying the `xt::pow` function to arrays of different shapes. Broadcasting allows element-wise operations between arrays with compatible shapes, automatically expanding dimensions as needed. ```cpp #include #include #include #include int main(int argc, char* argv[]) { xt::xarray arr1 {1.0, 2.0, 3.0}; xt::xarray arr2 {4, 5, 6, 7}; arr2.reshape({4, 1}); xt::xarray res = xt::pow(arr1, arr2); std::cout << res; return 0; } ``` -------------------------------- ### Build and Install xtensor from Source with CMake (Unix) Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/installation.rst Builds and installs xtensor from source on Unix-like systems using CMake. Requires xtl to be installed. Assumes a 'build' directory is created and cmake is configured with an installation prefix. ```bash mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=path_to_prefix .. make install ``` -------------------------------- ### Install xtensor using mamba Source: https://github.com/xtensor-stack/xtensor/blob/master/README.md Installs the xtensor library using the mamba package manager from the conda-forge channel. This is a convenient way to get started with xtensor. ```bash mamba install -c conda-forge xtensor ``` -------------------------------- ### Install xtensor with Spack Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/installation.rst Installs xtensor using the Spack package manager and loads it with its dependencies. ```bash spack install xtensor spack load --dependencies xtensor ``` -------------------------------- ### Build and Install xtensor from Source with CMake (Windows NMake) Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/installation.rst Builds and installs xtensor from source on Windows using CMake with the NMake generator. Requires xtl to be installed. Assumes a 'build' directory is created and cmake is configured with an installation prefix. ```bash mkdir build cd build cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=path_to_prefix .. nmake nmake install ``` -------------------------------- ### Build and Install xtensor from Source with CMake (Windows MinGW) Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/installation.rst Builds and installs xtensor from source on Windows using CMake with the MinGW generator. Requires xtl to be installed. Assumes a 'build' directory is created and cmake is configured with an installation prefix. ```bash mkdir build cd build cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=path_to_prefix .. mingw32-make mingw32-make install ``` -------------------------------- ### Printing xtensor Shape to Standard Output Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/getting_started.rst Provides two methods to print the shape of an xtensor array to standard output. The first uses iterators and `std::copy`, while the second uses `xt::adapt` for a more concise approach. ```cpp const auto& s = arr.shape(); std::copy(s.cbegin(), s.cend(), std::ostream_iterator(std::cout, " ")); ``` ```cpp std::cout << xt::adapt(arr.shape()); // with: #include ``` -------------------------------- ### Install xtensor with Debian Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/installation.rst Installs the xtensor development package on Debian-based systems using apt-get. ```bash sudo apt-get install xtensor-dev ``` -------------------------------- ### Install xtensor using vcpkg Source: https://github.com/xtensor-stack/xtensor/blob/master/README.md Installs xtensor using the vcpkg dependency manager. This command clones the vcpkg repository, integrates it with the system, and then installs xtensor. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install xtensor ``` -------------------------------- ### Tensor Initialization Example Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/view.rst Demonstrates the initialization of a 2D tensor with specific values using xtensor. ```c++ // => a = {{1.2, 1.2, 1.2}, {3., 4., 5.}} ``` -------------------------------- ### Multidimensional Array Initialization Example Source: https://github.com/xtensor-stack/xtensor/blob/master/test/files/xio_expected_results/print_options_result.txt Demonstrates the initialization of a multidimensional array with numerical data. This example shows how data can be structured and represented within the xtensor library. ```python import xtensor as xt data = [ [-3.2993450647, 0.1656660217, -5.741487258 , 7.6658710517, 7.4421535525, -8.7237405417, -1.6565722798, -9.5092800257, -2.9103572582, -9.0512625226, '...', 0.956576245 , -2.1176214529, 1.224063253 , 9.4574798674, 1.5253960498, 9.0468728933, 1.4632485328, 5.388738737 , -5.0804525812, 9.9405982276], [-3.8595565152, 3.9711250838, -0.7466613442, -7.8472288594, -9.7060944334, 5.8814551806, 1.5839099422, -3.2811630355, -2.5670295888, -2.2946266962, '...', -8.3226376255, -6.1266055234, -8.53220412 , 0.0712064945, -8.6836749392, 1.1484328631, -9.9792581277, -7.8110753489, 9.4993486219, 6.8471466225}, { 4.0164446191, 2.6124123025, 3.009438323 , -5.5299690191, -4.4891102742, 5.137638025 , 5.7287509146, -2.275257769 , 5.6551393668, -5.2959856257, '...', -0.671183266 , 6.450851233 , 1.0147749194, -4.3992512334, -5.7095954354, 7.7680651531, 2.5030521106, 6.6729805346, 5.0310323451, -7.5703964152}, { 0.5886834152, 4.6679436689, -8.592678009 , -7.6868968194, 7.1161214125, -1.4239915896, 6.2509497685, 8.4953751982, 9.7493446122, 7.2939809954, '...', 5.6044133488, -4.1291454101, -8.28053945 , 3.5683828275, -1.2860306048, -9.0687648703, 3.8310462403, -9.0213947232, 2.1923222357, -6.3506701839}] x = xt.array(data) print(x) ``` -------------------------------- ### xtensor C++ API Example Source: https://github.com/xtensor-stack/xtensor/blob/master/test/files/xio_expected_results/print_options_result.txt Provides a basic example of using xtensor's C++ API for creating and manipulating tensors. This showcases the performance benefits of using C++ directly. ```c++ #include #include #include #include int main() { // Create a 3x3 xarray of floats xt::xarray arr = xt::random::rand({3, 3}); // Print the array std::cout << "Random 3x3 array:\n" << arr << std::endl; // Perform an operation: add 1 to each element xt::xarray result = arr + 1.0f; std::cout << "Array after adding 1.0:\n" << result << std::endl; return 0; } ``` -------------------------------- ### xtensor Installation Instructions Update Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst Updates the installation instructions to include mentions of `mamba`, a package manager that can simplify the installation process. ```markdown /* Update installation instructions to mention mamba #2357 https://github.com/xtensor-stack/xtensor/pull/2357 */ ``` -------------------------------- ### xtensor index_view Examples Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst Improves the examples for index_view to better illustrate its usage and capabilities. ```markdown ## index_view Examples ```cpp // Example usage of index_view ... ``` -------------------------------- ### Added islice example to view doc Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst Includes an example demonstrating the usage of `islice` within the documentation for views. This helps users understand how to apply `islice` for specific slicing needs. ```cpp /* * added islice example to view doc * #940 */ ``` -------------------------------- ### Added Installation Instruction with MinGW Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst Includes instructions for installing and building `xtensor` using the MinGW compiler on Windows. This expands the platform support for the library. ```cpp # Documentation for installation with MinGW ``` -------------------------------- ### Install Documentation Build Tools Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/dev-build-options.rst This command installs the necessary tools for building the xtensor project's documentation using Conda. It installs Breathe, Doxygen, and Sphinx Read the Docs theme, which are essential for generating HTML documentation from source. ```bash conda install breathe doxygen sphinx_rtd_theme -c conda-forge ``` -------------------------------- ### Index Access in xtensor Arrays Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/getting_started.rst Demonstrates how to access individual elements of xtensor arrays using multidimensional indexing for xarray and single-dimensional indexing for a flat array. This is a fundamental operation for manipulating data within xtensor. ```cpp #include #include #include int main(int argc, char* argv[]) { xt::xarray arr1 {{1.0, 2.0, 3.0}, {2.0, 5.0, 7.0}, {2.0, 5.0, 7.0}}; std::cout << arr1(0, 0) << std::endl; xt::xarray arr2 {1, 2, 3, 4, 5, 6, 7, 8, 9}; std::cout << arr2(0); return 0; } ``` -------------------------------- ### Multidimensional Array Initialization Example (C++) Source: https://github.com/xtensor-stack/xtensor/blob/master/test/files/xio_expected_results/print_options_result.txt Demonstrates the initialization of a multidimensional array with numerical data in C++. This example shows how data can be structured and represented within the xtensor library using C++. ```c++ #include #include int main() { xt::xarray arr = { {-3.2993450647, 0.1656660217, -5.741487258 , 7.6658710517, 7.4421535525, -8.7237405417, -1.6565722798, -9.5092800257, -2.9103572582, -9.0512625226}, {-3.8595565152, 3.9711250838, -0.7466613442, -7.8472288594, -9.7060944334, 5.8814551806, 1.5839099422, -3.2811630355, -2.5670295888, -2.2946266962}, { 4.0164446191, 2.6124123025, 3.009438323 , -5.5299690191, -4.4891102742, 5.137638025 , 5.7287509146, -2.275257769 , 5.6551393668, -5.2959856257}, { 0.5886834152, 4.6679436689, -8.592678009 , -7.6868968194, 7.1161214125, -1.4239915896, 6.2509497685, 8.4953751982, 9.7493446122, 7.2939809954} }; std::cout << arr << std::endl; return 0; } ``` -------------------------------- ### Install Documentation Tools with Pip Source: https://github.com/xtensor-stack/xtensor/blob/master/README.md Installs the Breathe and sphinx_rtd_theme Python packages, which are required for building the HTML documentation for xtensor using Sphinx. ```python pip install breathe sphinx_rtd_theme ``` -------------------------------- ### xtensor Array Reshape and Print Example Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/indices.rst Demonstrates reshaping an xtensor array and printing its contents to the console. This example sets up a 3x4 array and shows its row-major representation. ```cpp #include #include #include int main() { xt::xarray a = xt::arange(3 * 4); a.reshape({3,4}); std::cout << a << std::endl; } ``` -------------------------------- ### Install xtensor from sources Source: https://github.com/xtensor-stack/xtensor/blob/master/README.md Installs xtensor as a header-only library using CMake. This method requires a C++ compiler and allows specifying a custom installation prefix. ```cmake cmake -DCMAKE_INSTALL_PREFIX=your_install_prefix make install ``` -------------------------------- ### xtensor CMake Installation and Package Configuration Source: https://github.com/xtensor-stack/xtensor/blob/master/CMakeLists.txt Handles the installation of the xtensor library, including targets, headers, and package configuration files (xtensorConfig.cmake, xtensorConfigVersion.cmake, xtensor.pc) for use with other CMake projects. ```cmake include(GNUInstallDirs) include(CMakePackageConfigHelpers) install(TARGETS xtensor EXPORT ${PROJECT_NAME}-targets) # Makes the project importable from the build directory export(EXPORT ${PROJECT_NAME}-targets FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") install(DIRECTORY ${XTENSOR_INCLUDE_DIR}/xtensor DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) set(XTENSOR_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xtensorConfig.cmake") configure_package_config_file(${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION ${XTENSOR_CMAKECONFIG_INSTALL_DIR}) # xtensor is header-only and does not depend on the architecture. # Remove CMAKE_SIZEOF_VOID_P from xtensorConfigVersion.cmake so that an xtensorConfig.cmake # generated for a 64 bit target can be used for 32 bit targets and vice versa. set(_XTENSOR_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_CMAKECONFIG_INSTALL_DIR}) install(EXPORT ${PROJECT_NAME}-targets FILE ${PROJECT_NAME}Targets.cmake DESTINATION ${XTENSOR_CMAKECONFIG_INSTALL_DIR}) 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/") ``` -------------------------------- ### Build xtensor Documentation Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/dev-build-options.rst This sequence of commands builds the HTML documentation for the xtensor project. It involves changing the directory to 'docs' and then executing the 'make html' command, which utilizes the installed documentation tools to generate the output. ```bash cd docs make html ``` -------------------------------- ### NumPy Array Initialization Example Source: https://github.com/xtensor-stack/xtensor/blob/master/test/files/xio_expected_results/random_nan_inf.txt Demonstrates the initialization of a NumPy array with specific values, including handling of special float values like infinity and NaN. ```python import numpy as np data = np.array([ [ 4.259106, -1.430581, 3.817697, 4.383006, -0.177621, 5.600555, -1.781513, 1.593886, -7.200985, -1.979649, 2.54634 , -3.516982, -5.104814, 3.895104, 1.878048, 2.63584 , -1.194856, -8.32547 , 4.246604, -1.44273 ], [-4.04439 , -1. , 1. , -2.845422, -1.655801, 3.094426, -2.523971, -5.309743, 9.759906, 5.319919, 5.540089, -9.440361, -6.52187 , -6.918355, -8.45827 , 7.797314, 5.007574, 3.868065, 0.235268, -0.714639], [ 1.368614, -3.949011, np.inf, -np.inf, 8.333974, -7.821421, -0.090164, -5.343281, -1.262787, 5.03086 , -0.382158, 5.954568, -4.345941, -1.331635, -9.804853, -3.18408 , 3.78544 , 7.387386, -4.643924, -0.865042], [-4.634374, 6.741056, -4.589707, 0.60124 , -6.492547, -3.700671, 7.822182, -6.393274, -0.113676, -5.754038, 0.417537, -6.798001, 8.381136, 9.885798, -0.459049, -3.80233 , 0.144086, -4.384136, 5.276734, -7.829154], [ 0.233094, 8.195388, -5.63248 , -2.737919, np.nan, 4.227836, -2.141112, -5.37397 , -2.396506, 0.983242, 1.134381, -9.917307, 2.76045 , -8.84704 , -9.139462, 7.501023, -4.148248, 5.255353, -2.642695, 7.470045], [-9.411525, 1.040874, -5.19505 , 7.6961 , -0.795232, -6.136593, -4.12615 , 6.35855 , 1.189747, 3.558509, 6.182534, 7.371443, -1.640151, -8.821237, -0.43082 , 0.423189, 1.61264 , -3.81602 , 8.397652, 3.10695 ], [-3.015172, 0.821881, -1.018932, -4.353581, -4.08247 , 1.26962 , 4.303826, 0.352374, -2.959163, 2.655577, 7.462381, -6.642231, 9.749566, -3.011701, 6.524103, -8.690769, -9.892934, 7.738893, 8.226363, -6.011844], [-9.448972, 6.346698, -5.163448, -8.87834 , -8.648783, -0.522563, 0.188585, -1.664097, -4.883141, -2.369758, 6.147689, 6.220783, 3.723737, 9.852273, -1.896296, -6.196526, -0.23651 , 0.047393, -1.932904, -6.378091], [-9.039404, 2.093827, -4.681776, 7.62694 , 1.680922, -0.45079 , -6.5697 , -8.8676 , -6.859295, -3.22765 , -1.187141, 3.676862, -5.882566, 2.328674, 8.489432, -8.407435, -0.292063, 3.971273, -8.36863 , 7.382047], [-1.337886, -0.113399, -0.085191, -2.585558, 8.442573, 6.825565, 3.110518, -0.746299, 1.300226, -1.52169 , -4.235761, -4.720386, 3.814765, 6.656731, 1.847831, -0.669548, 3.4732 , -2.170413, 4.042087, 9.313953], [-8.189802, -8.837497, 1.760348, 5.023475, 0.226348, 8.410024, -3.920718, -0.139945, 9.587207, -3.529835, -6.208657, -3.895418, -3.117761, 3.590606, -8.9237 , 6.132075, 2.059004, 3.104264, 4.953196, 0.712524], [-7.81687 , -0.076074, -6.553148, 3.679784, 0.596504, 2.504485, -3.69714 , -0.169787, 6.402841, -7.347591, -7.57381 , -1.075701, -9.181317, -3.989666, -1.812192, -2.549612, -3.200597, 6.251402, 0.564111, 1.076542], [-7.655863, 5.692096, -1.308276, -8.455545, -6.363769, 0.420217, -0.413317, -3.72915 , -8.006616, 1.931053, -5.036602, 2.086803, -3.897727, 7.946099, 1.640307, 4.249848, 3.672309, 8.932418, 8.264625, -8.974902], [-2.39369 , 1.277131, -7.348525, 1.502706, -3.548645, 9.678551, 1.513316, 2.594553, -1.979754, 4.892601, -1.976282, 5.309503, 9.648625, -6.637665, -0.508106, 0.97881 , -1.277853, -4.065374, -2.128725, 6.761622], [ 3.032851, 9.077939, -0.459995, 7.577871, 5.844156, -4.69285 , 5.248765, 6.454728, -2.940153, 9.48464 , 3.504667, 3.987593, -0.808062, -8.605302, 9.959603, 2.755019, -8.636948, -7.077259, 6.778265, -4.456102], [ 0.789019, -8.391345, 1.326935, -2.750302, -3.635727, 3.070465, -2.90194 , 4.305136, 2.56563 , 9.350227, -4.37165 , -5.072099, -8.449633, 7.84151 , -9.3091 , -0.170497, -9.981909, 7.783972, -3.212051, 2.616364], [-3.385869, 7.779795, 4.586448, -8.113584, 4.134024, 7.608333, 0.810756, 9.514617, -0.599935, -9.215927, 0.269787, 0.436816, 1.589945, 6.745015, -2.984754, 8.22778 , -1.991758, -2.205407, -1.954704, -7.920165], [-0.681457, 2.961423, -4.046124, 7.84679 , -0.428581, -4.352744, -1.629202, -1.682069, 5.426159, 4.759028, -0.535463, 0.037947, 6.713306, 4.397586, 0.211848, 4.890704, -3.313785, 0.839388, 1.601047, -8.551511], [ 3.58872 , 4.407113, 1.049608, 0.099257, -8.345609, 1.612125, 2.578687, 1.733626, 4.454039, -8.312231, 9.610947, -7.572344, -7.769007, 0.116085, -1.100301, -6.350003, -1.589225, 7.378157, 5.114439, -7.273815], [-6.417325, 1.029412, 1.246413, -1.370279, -2.788699, 0.373218, -1.76683 , -9.41086 , -8.920649, -7.659411, 2.569412, -1.410808, -7.417977, -2.567283, 5.480396, 4.847727, -8.649269, 4.136584, -3.603764, 9.610047] ]) print(data) ``` -------------------------------- ### Install xtensor with Conda Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/installation.rst Installs the xtensor package from the conda-forge channel using the mamba package manager. ```bash mamba install -c conda-forge xtensor ``` -------------------------------- ### Try xtensor online with Jupyter Source: https://github.com/xtensor-stack/xtensor/blob/master/README.md Launches a Jupyter notebook environment using Binder to interactively use xtensor. This requires no local installation and is powered by the xeus-cling C++ kernel. ```python https://mybinder.org/v2/gh/xtensor-stack/xtensor/stable?filepath=notebooks%2Fxtensor.ipynb ``` -------------------------------- ### Include xtensor in a CMake Project Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/installation.rst Demonstrates how to find and link the xtensor library in a CMake project. It uses find_package to locate xtensor and then sets include directories and links the library to a target. ```cmake find_package(xtensor REQUIRED) target_include_directories(your_target PUBLIC ${xtensor_INCLUDE_DIRS}) target_link_libraries(your_target PUBLIC xtensor) ``` -------------------------------- ### Fix Example Code in container.rst Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst Corrects an error in the example code provided in the `container.rst` documentation file. This documentation fix was part of the 0.20.5 release. ```cpp // Conceptual documentation correction // In file container.rst: // "Corrected the example usage of xcontainer." ``` -------------------------------- ### CMake Project Setup and Versioning Source: https://github.com/xtensor-stack/xtensor/blob/master/CMakeLists.txt Configures the CMake build for the xtensor project, sets the minimum required CMake version, defines the project name, and extracts the xtensor version from its header files. ```cmake cmake_minimum_required(VERSION 3.15..3.29) project(xtensor CXX) set(XTENSOR_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) # Versionning # =========== file(STRINGS "${XTENSOR_INCLUDE_DIR}/xtensor/core/xtensor_config.hpp" xtensor_version_defines REGEX "#define XTENSOR_VERSION_(MAJOR|MINOR|PATCH)") foreach(ver ${xtensor_version_defines}) if(ver MATCHES "#define XTENSOR_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") set(XTENSOR_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") endif() endforeach() set(${PROJECT_NAME}_VERSION ${XTENSOR_VERSION_MAJOR}.${XTENSOR_VERSION_MINOR}.${XTENSOR_VERSION_PATCH}) message(STATUS "Building xtensor v${${PROJECT_NAME}_VERSION}") ``` -------------------------------- ### xtensor Argwhere Example Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/indices.rst Illustrates the usage of `xt::argwhere` which returns a vector of array indices for elements satisfying a condition. ```cpp int main() { xt::xarray a = xt::arange(3 * 4); a.reshape({3,4}); // Example usage of xt::argwhere // xt::argwhere(a < 5) returns a std::vector of array indices. } ``` -------------------------------- ### Build xtensor Tests with CMake (Download GTest) Source: https://github.com/xtensor-stack/xtensor/blob/master/README.md Builds the xtensor project with tests enabled, automatically downloading and building GTest if not found. This simplifies the setup process by managing the GTest dependency. ```bash mkdir build cd build cmake -DBUILD_TESTS=ON -DDOWNLOAD_GTEST=ON ../ make xtest ``` -------------------------------- ### xtensor Argmin and Argmax Documentation Update Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst Updates the documentation for the `argmin` and `argmax` functions, providing clearer explanations and usage examples. ```cpp /* Updated docs of argmin and argmax #2425 https://github.com/xtensor-stack/xtensor/pull/2425 */ ``` -------------------------------- ### Reverse Iterators and STL Algorithms Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/quickref/basic.rst Demonstrates the use of reverse iterators provided by xtensor containers, compatible with STL algorithms like 'std::copy'. This example copies elements in reverse order. ```cpp xt::xarray a = {{1., 2., 3.}, {4., 5., 6.}; xt::xarray b(a.shape()); std::copy(a.crbegin(), a.crend(), b.begin()); std::cout << b << std::endl; // Outputs {{6., 5., 4.}, {3., 2., 1.}} ``` -------------------------------- ### Trigonometric Functions Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/quickref/math.rst Shows examples of trigonometric functions including cosine, sine, tangent, and their inverse counterparts, as well as atan2. ```cpp xt::xarray res0 = xt::cos(e1); xt::xarray res1 = xt::sin(e1); xt::xarray res2 = xt::tan(e1); xt::xarray res3 = xt::acos(e2); xt::xarray res4 = xt::asin(e2); xt::xarray res5 = xt::atan(e2); xt::xarray res6 = xt::atan2(e2, e3); ``` -------------------------------- ### xtensor README.md Update for Conan Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst Updates the README.md file to include instructions for installing xtensor using the Conan package manager. This improves accessibility for users who prefer Conan. ```markdown ## Conan Installation To install xtensor using Conan, run: ```bash conan install . --build=missing ``` ... ``` -------------------------------- ### Quantile and Median Operations (xtensor vs NumPy) Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/numpy.rst Shows how to compute quantiles and medians for multi-dimensional arrays. The C++ xtensor examples demonstrate specific usage patterns. ```cpp xt::quantile(a, {.1, .3}, 1, 1.0, 1.0) xt::median(a, 1) ``` ```python np.median(a, axis=1) ``` -------------------------------- ### Slicing and Indexing Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/numpy.rst Provides examples of slicing and indexing multi-dimensional arrays in both Python NumPy and C++ xtensor, showcasing equivalent operations. ```python a[3, 2] a.flat[4] a[3] a[:, 2] a[:5, 1:] a[5:1:-1, :] a[..., 3] a[:, np.newaxis] ``` ```cpp a(3, 2) a.flat(4) xt::view(a, 3, xt::all()) xt::row(a, 3) xt::view(a, xt::all(), 2) xt::col(a, 2) xt::view(a, xt::range(_, 5), xt::range(1, _)) xt::view(a, xt::range(5, 1, -1), xt::all()) xt::strided_view(a, {xt::ellipsis(), 3}) xt::view(a, xt::all(), xt::newaxis()) ``` -------------------------------- ### Basic Mathematical Functions Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/quickref/math.rst Provides examples for basic mathematical operations like absolute value, modulo, remainder, fused multiply-add, maximum, minimum, and dimension functions. ```cpp xt::xarray res0 = xt::abs(e1); xt::xarray res1 = xt::fabs(e1); xt::xarray res2 = xt::fmod(e1, e2); xt::xarray res3 = xt::remainder(e1, e2); xt::xarray res4 = xt::fma(e1, e2, e3); xt::xarray res5 = xt::maximum(e1, e2); xt::xarray res6 = xt::minimum(e2, e2); xt::xarray res7 = xt::fmax(e1, e2); xt::xarray res8 = xt::fmin(e1, e2); xt::xarray res9 = xt::fdim(e1, e2); xt::xarray res10 = xt::clip(e1, e2, e3); xt::xarray res11 = xt::sign(e1); ``` -------------------------------- ### CMake Minimum Version and Project Setup Source: https://github.com/xtensor-stack/xtensor/blob/master/test/CMakeLists.txt Sets the minimum required CMake version and defines the project name and language. It also enables testing and finds the xtensor package if it's the main source directory. ```cmake cmake_minimum_required(VERSION 3.15..3.29) if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) project(xtensor-test CXX) enable_testing() find_package(xtensor REQUIRED CONFIG) set(XTENSOR_INCLUDE_DIR ${xtensor_INCLUDE_DIRS}) endif () ``` -------------------------------- ### xtensor Functions and Generators Overview Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/api/function_index.rst This section provides an overview of the various functional components within the xtensor library, including functions, reducers, accumulators, generators, and builders. It serves as a starting point for understanding how to perform computations and data manipulations. ```text xfunction xreducer xaccumulator xgenerator xbuilder ``` -------------------------------- ### xtensor BLAS Installation Requirement Removal Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/changelog.rst Removes the explicit requirement to install BLAS with the latest `xtensor-blas`, simplifying setup when using the library. ```cpp /* No need to explicitly install blas anymore with latest xtensor-blas #2343 https://github.com/xtensor-stack/xtensor/pull/2343 */ ``` -------------------------------- ### Transform Elements using STL Algorithms Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/quickref/basic.rst Illustrates how xtensor containers provide STL-compatible iterators, enabling the use of standard algorithms like 'std::transform'. This example shows adding 1 to each element of an array. ```cpp xt::xarray a = {{1., 2., 3.}, {4., 5., 6.}; xt::xarray b(a.shape()); std::transform(a.cbegin(), a.cend(), b.begin(), [](auto&& v) { return v + 1; }); std::cout << b << std::endl; // Outputs {{2., 3., 4.}, {5., 6., 7.}} ``` -------------------------------- ### Load and Dump JSON Data with xtensor Source: https://github.com/xtensor-stack/xtensor/blob/master/docs/source/file_loading.rst Illustrates loading and dumping data to JSON format using the nlohmann/json library. The library needs to be installed separately. Requires xtensor headers for xarray and xjson. ```cpp #include #include int main() { xt::xarray t = {{{1, 2}, {3, 4}}, {{1, 2}, {3, 4}}}; nlohmann::json jl = t; // To obtain the json serialized string std::string s = jl.dump(); xt::xarray res; auto j = "[[10.0,10.0],[10.0,10.0]]"_json; xt::from_json(j, res); } ``` -------------------------------- ### Build xtensor Tests with CMake (Existing GTest) Source: https://github.com/xtensor-stack/xtensor/blob/master/README.md Builds the xtensor project with tests enabled, assuming GTest and CMake are already installed. It creates a build directory, configures the build with CMake, and then compiles the xtest executable. ```bash mkdir build cd build cmake -DBUILD_TESTS=ON ../ make xtest ```