Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/keitanakamura/tensorial.jl
Statically sized tensors and related operations for Julia
https://github.com/keitanakamura/tensorial.jl
automatic-differentiation continuum-mechanics einstein-summation julia quaternion symmetric-tensors tensor
Last synced: 8 days ago
JSON representation
Statically sized tensors and related operations for Julia
- Host: GitHub
- URL: https://github.com/keitanakamura/tensorial.jl
- Owner: KeitaNakamura
- License: mit
- Created: 2021-01-16T15:38:18.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T03:07:41.000Z (22 days ago)
- Last Synced: 2024-10-24T16:34:30.486Z (22 days ago)
- Topics: automatic-differentiation, continuum-mechanics, einstein-summation, julia, quaternion, symmetric-tensors, tensor
- Language: Julia
- Homepage: https://keitanakamura.github.io/Tensorial.jl/
- Size: 4.06 MB
- Stars: 35
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tensorial.jl
*Statically sized tensors and related operations for Julia*
[![CI](https://github.com/KeitaNakamura/Tensorial.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/KeitaNakamura/Tensorial.jl/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/KeitaNakamura/Tensorial.jl/branch/main/graph/badge.svg?token=V58DXDI1R5)](https://codecov.io/gh/KeitaNakamura/Tensorial.jl)Tensorial.jl provides statically sized `Tensor` type that is compatible with `AbstractArray`, similar to `SArray` from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl).
In addition to supporting basic `AbstractArray` operations, the package offers a *tensorial* interface and several advanced features:* Contraction, tensor product (`⊗`), and a flexible `@einsum` macro for Einstein summation convention
* A `@Symmetry` macro to define the tensor symmetries, eliminating unnecessary calculations
* Automatic differentiation via `gradient` and `hessian` functions, leveraging [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl)
* Performance comparable to `SArray` (see [benchmarks](https://keitanakamura.github.io/Tensorial.jl/stable/Benchmarks/))## Documentation
[![Stable](https://img.shields.io/badge/docs-latest%20release-blue.svg)](https://KeitaNakamura.github.io/Tensorial.jl/stable)
## Breaking changes (v0.18)
Starting from version 0.18, Tensorial.jl is now built on [TensorCore.jl](https://github.com/JuliaMath/TensorCore.jl). The breaking changes are as follows:
* Single contraction: `⋅` has been replaced by `⊡` (`⋅` now behaves as in `LinearAlgebra`).
* Double contraction: `⊡` has been replaced by `⊡₂` (which can be typed by `\boxdot\_2`).
* `@einsum`: The syntax now aligns with other tensor packages.
* Broadcasting: Scalar-like behavior has been removed. Broadcasting now behaves the same as with other `AbstractArray`s.
* `mean`: The specialized `mean` definition in `Statistics` has been removed.## Quick start
```julia
julia> using Tensorialjulia> x = Vec{3}(rand(3)); # constructor similar to SArray.jl
julia> A = @Mat rand(3,3); # @Vec, @Mat and @Tensor, analogous to @SVector, @SMatrix and @SArray
julia> A ⊡ x ≈ A * x # single contraction (⊡)
truejulia> A ⊡₂ A ≈ A ⋅ A # double contraction (⊡₂)
truejulia> x ⊗ x ≈ x * x' # tensor product (⊗)
truejulia> (@einsum y := x[i] * A[j,i] * x[j]) ≈ x ⊡ A' ⊡ x # Einstein summation (@einsum)
truejulia> As = rand(Tensor{Tuple{@Symmetry{3,3}}}); # specify symmetry S₍ᵢⱼ₎
julia> AAs = rand(Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}); # SS₍ᵢⱼ₎₍ₖₗ₎
julia> inv(AAs) ⊡₂ As ≈ @einsum Bs[i,j] := inv(AAs)[i,j,k,l] * As[k,l] # it just works
truejulia> δ = one(Mat{3,3}) # identity tensor
3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0julia> gradient(identity, As) ≈ one(AAs) # ∂Asᵢⱼ/∂Asₖₗ = (δᵢₖδⱼₗ + δᵢₗδⱼₖ) / 2
true
```## Other tensor packages
* [Einsum.jl](https://github.com/ahwillia/Einsum.jl)
* [TensorOprations.jl](https://github.com/Jutho/TensorOperations.jl)
* [Tensors.jl](https://github.com/Ferrite-FEM/Tensors.jl)
* [Tullio.jl](https://github.com/mcabbott/Tullio.jl)## Inspiration
Some functionalities are inspired from the following packages:
* [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl)
* [Tensors.jl](https://github.com/Ferrite-FEM/Tensors.jl)## Citation
If you find Tensorial.jl useful in your work, I kindly request that you cite it as below:
```bibtex
@software{NakamuraTensorial2024,
title = {Tensorial.jl: a {J}ulia package for tensor operations},
author = {Nakamura, Keita},
doi = {10.5281/zenodo.13955151},
year = {2024},
url = {https://github.com/KeitaNakamura/Tensorial.jl}
licence = {MIT},
}
```