{"id":20101573,"url":"https://github.com/xtensor-stack/xtensor-julia","last_synced_at":"2025-03-02T17:15:57.055Z","repository":{"id":41435463,"uuid":"136346976","full_name":"xtensor-stack/xtensor-julia","owner":"xtensor-stack","description":"Julia bindings for xtensor","archived":false,"fork":false,"pushed_at":"2022-07-01T18:50:29.000Z","size":221,"stargazers_count":19,"open_issues_count":5,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-19T12:53:06.528Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://quantstack.net/xtensor","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xtensor-stack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-06T15:15:28.000Z","updated_at":"2023-09-12T15:04:20.000Z","dependencies_parsed_at":"2022-08-27T05:00:47.819Z","dependency_job_id":null,"html_url":"https://github.com/xtensor-stack/xtensor-julia","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtensor-stack%2Fxtensor-julia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtensor-stack%2Fxtensor-julia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtensor-stack%2Fxtensor-julia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtensor-stack%2Fxtensor-julia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xtensor-stack","download_url":"https://codeload.github.com/xtensor-stack/xtensor-julia/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241541452,"owners_count":19979121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T17:25:48.341Z","updated_at":"2025-03-02T17:15:56.887Z","avatar_url":"https://github.com/xtensor-stack.png","language":"C++","readme":"# ![xtensor-julia](docs/source/xtensor-julia.svg)\n\n[![Documentation Status](http://readthedocs.org/projects/xtensor-julia/badge/?version=latest)](https://xtensor-julia.readthedocs.io/en/latest/?badge=latest)\n[![Join the Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/QuantStack/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nJulia bindings for the [xtensor](https://github.com/xtensor-stack/xtensor) C++ multi-dimensional array library.\n\n - `xtensor` is a C++ library for multi-dimensional arrays enabling numpy-style broadcasting and lazy computing.\n - `xtensor-julia` enables inplace use of julia arrays in C++ with all the benefits from `xtensor`\n\n     - C++ universal function and broadcasting\n     - STL - compliant APIs.\n     - A broad coverage of numpy APIs (see [the numpy to xtensor cheat sheet](http://xtensor.readthedocs.io/en/latest/numpy.html)).\n\nThe Julia bindings for `xtensor` are based on the [libcxxwrap](https://github.com/JuliaInterop/libcxxwrap-julia/) C++ library.\n\n## Documentation\n\nTo get started with using `xtensor-julia`, check out the full documentation\n\nhttp://xtensor-julia.readthedocs.io/\n\n## Usage\n\nxtensor-julia offers two container types wrapping julia arrays inplace to provide an xtensor semantics\n\n - `jltensor`\n - `jlarray`.\n\nBoth containers enable the numpy-style APIs of xtensor (see [the numpy to xtensor cheat sheet](http://xtensor.readthedocs.io/en/latest/numpy.html)).\n\n - On the one hand, `jlarray` has a dynamic number of dimensions. It can be reshaped dynamically and the new shape is reflected on the Julia side.\n\n - On the other hand `jltensor` has a compile time number of dimensions, specified with a template parameter. Shapes of `jltensor` instances are stack allocated, making `jltensor` a significantly faster expression than `jlarray`.\n\n### Example 1: Use an algorithm of the C++ standard library with Julia array.\n\n**C++ code**\n\n```cpp\n#include \u003cnumeric\u003e                        // Standard library import for std::accumulate\n#include \u003ccxx_wrap.hpp\u003e                   // libcxxwrap import to define Julia bindings\n#include \"xtensor-julia/jltensor.hpp\"     // Import the jltensor container definition\n#include \"xtensor/xmath.hpp\"              // xtensor import for the C++ universal functions\n\ndouble sum_of_sines(xt::jltensor\u003cdouble, 2\u003e m)\n{\n    auto sines = xt::sin(m);  // sines does not actually hold values.\n    return std::accumulate(sines.cbegin(), sines.cend(), 0.0);\n}\n\nJLCXX_MODULE define_julia_module(jlcxx::Module\u0026 mod)\n{\n    mod.method(\"sum_of_sines\", sum_of_sines);\n}\n```\n\n**Julia Code**\n\n```julia\nusing xtensor_julia_test\n\narr = [[1.0 2.0]\n       [3.0 4.0]]\n\ns = sum_of_sines(arr)\ns\n```\n\n**Outputs**\n\n```\n1.1350859243855171\n```\n\n### Example 2: Create a numpy-style universal function from a C++ scalar function\n\n**C++ code**\n\n```cpp\n#include \u003ccxx_wrap.hpp\u003e\n#include \"xtensor-julia/jlvectorize.hpp\"\n\ndouble scalar_func(double i, double j)\n{\n    return std::sin(i) - std::cos(j);\n}\n\nJLCXX_MODULE define_julia_module(jlcxx::Module\u0026 mod)\n{\n    mod.method(\"vectorized_func\", xt::jlvectorize(scalar_func));\n}\n```\n\n**Julia Code**\n\n```julia\nusing xtensor_julia_test\n\nx = [[ 0.0  1.0  2.0  3.0  4.0]\n     [ 5.0  6.0  7.0  8.0  9.0]\n     [10.0 11.0 12.0 13.0 14.0]]\ny = [1.0, 2.0, 3.0, 4.0, 5.0]\nz = vectorized_func(x, y)\nz\n```\n\n**Outputs**\n\n```\n[[-0.540302  1.257618  1.89929   0.794764 -1.040465],\n [-1.499227  0.136731  1.646979  1.643002  0.128456],\n [-1.084323 -0.583843  0.45342   1.073811  0.706945]]\n```\n\n## Installation\n\n### Installation of the standalone C++ library\n\n`xtensor-julia` a header-only C++ library. It has been packaged for the mamba (or conda) package manager.\n\n```bash\nmamba install xtensor-julia -c conda-forge\n```\n\n`xtensor-r` can be installed from source with cmake in any installation prefix. For example, on unix systems\n\n```bash\ncmake -D CMAKE_INSTALL_PREFIX=/prefix/path/\nmake\nmake install\n```\n\n### Installation of the Julia package\n \nWe also provide a Julia package for xtensor, which has been packaged for both conda and Pkg (Julia's package manager). The repository for the Julia package is https://github.com/xtensor-stack/Xtensor.jl.\n \nTo install the Julia package:\n\n```julia\nusing Pkg; Pkg.add(\"Xtensor\");\n```\n\nThe Julia available from the Julia package manager vendors the headers for `xtensor-julia`, xtensor`, `xtl` and `xsimd`.\n\n## Building the HTML Documentation\n\n`xtensor-julia`'s documentation is built with three tools\n\n - [doxygen](http://www.doxygen.org)\n - [sphinx](http://www.sphinx-doc.org)\n - [breathe](https://breathe.readthedocs.io)\n\nWhile doxygen must be installed separately, you can install breathe by typing\n\n```bash\npip install breathe\n```\n\nBreathe can also be installed with `conda`\n\n```bash\nconda install -c conda-forge breathe\n```\n\nFinally, build the documentation with\n\n```bash\nmake html\n```\n\nfrom the `docs` subdirectory.\n\n## Running the tests\n\n```\ncmake -D BUILD_TESTS=ON ..\n```\n\n## Dependencies on `xtensor` and `libcxxwrap-julia`\n\n`xtensor-julia` depends on the `xtensor` and `libcxxwrap-julia` libraries\n\n| `xtensor-julia` | `xtensor` | `libcxxwrap`  | `julia`        |\n|-----------------|-----------|---------------|----------------|\n| master          |  ^0.24.0  | \u003e=0.9,\u003c0.10   | \u003e=1.6.4,\u003c2.0   |\n| 0.10.2          |  ^0.24.0  | \u003e=0.0,\u003c0.10   | \u003e=1.6.4,\u003c2.0   |\n| 0.10.1          |  ^0.24.0  | \u003e=0.8.3,\u003c0.9  | \u003e=1.6.4,\u003c2.0   |\n| 0.10.0          |  ^0.24.0  | \u003e=0.8.3,\u003c0.9  | \u003e=1.6.4,\u003c2.0   |\n| 0.9.0           |  ^0.21.2  | \u003e=0.5.3,\u003c0.6  | \u003e=1.0.0,\u003c1.1   |\n\nThese dependencies are automatically resolved when using the Julia package manager.\n\n## License\n\nWe use a shared copyright model that enables all contributors to maintain the copyright on their contributions.\n\nThis software is licensed under the BSD-3-Clause license. See the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtensor-stack%2Fxtensor-julia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtensor-stack%2Fxtensor-julia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtensor-stack%2Fxtensor-julia/lists"}