All Projects → KeitaNakamura → Tensorial.jl

KeitaNakamura / Tensorial.jl

Licence: MIT license
Statically sized tensors and related operations for Julia

Programming Languages

julia
2034 projects

Projects that are alternatives of or similar to Tensorial.jl

Tensors.jl
Efficient computations with symmetric and non-symmetric tensors with support for automatic differentiation.
Stars: ✭ 142 (+688.89%)
Mutual labels:  automatic-differentiation, tensor, symmetric-tensors
TensorAlgDiff
Automatic Differentiation for Tensor Algebras
Stars: ✭ 26 (+44.44%)
Mutual labels:  automatic-differentiation, tensor
Grassmann.jl
⟨Leibniz-Grassmann-Clifford⟩ differential geometric algebra / multivector simplicial complex
Stars: ✭ 289 (+1505.56%)
Mutual labels:  automatic-differentiation, tensor
Arraymancer
A fast, ergonomic and portable tensor library in Nim with a deep learning focus for CPU, GPU and embedded devices via OpenMP, Cuda and OpenCL backends
Stars: ✭ 793 (+4305.56%)
Mutual labels:  automatic-differentiation, tensor
Rust Autograd
Tensors and differentiable operations (like TensorFlow) in Rust
Stars: ✭ 278 (+1444.44%)
Mutual labels:  automatic-differentiation, tensor
Tullio.jl
Stars: ✭ 231 (+1183.33%)
Mutual labels:  automatic-differentiation, tensor
MissionImpossible
A concise C++17 implementation of automatic differentiation (operator overloading)
Stars: ✭ 18 (+0%)
Mutual labels:  automatic-differentiation
ostd
Online Stochastic Tensor Decomposition for Background Subtraction in Multispectral Video Sequences
Stars: ✭ 21 (+16.67%)
Mutual labels:  tensor
cgdms
Differentiable molecular simulation of proteins with a coarse-grained potential
Stars: ✭ 44 (+144.44%)
Mutual labels:  automatic-differentiation
numeric
numeric facilities for C++ 14; dual numbers, dual quaternions, constrained numbers, intervals
Stars: ✭ 21 (+16.67%)
Mutual labels:  quaternion
Quadcopter SimCon
Quadcopter Simulation and Control. Dynamics generated with PyDy.
Stars: ✭ 84 (+366.67%)
Mutual labels:  quaternion
zalgebra
Linear algebra library for games and real-time graphics.
Stars: ✭ 129 (+616.67%)
Mutual labels:  quaternion
DI-treetensor
Let DI-treetensor help you simplify the structure processing!(树形运算一不小心就逻辑混乱?DI-treetensor快速帮你搞定)
Stars: ✭ 134 (+644.44%)
Mutual labels:  tensor
pytorch-examples-cn
用例子学习PyTorch1.0(Learning PyTorch with Examples 中文翻译与学习)
Stars: ✭ 54 (+200%)
Mutual labels:  tensor
Scientific-Programming-in-Julia
Repository for B0M36SPJ
Stars: ✭ 32 (+77.78%)
Mutual labels:  automatic-differentiation
Fortran-Tools
Fortran compilers, preprocessors, static analyzers, transpilers, IDEs, build systems, etc.
Stars: ✭ 31 (+72.22%)
Mutual labels:  automatic-differentiation
scikit tt
Tensor Train Toolbox
Stars: ✭ 52 (+188.89%)
Mutual labels:  tensor
Xtensor.jl
Julia package for xtensor-julia
Stars: ✭ 38 (+111.11%)
Mutual labels:  tensor
tensority
Strongly typed multidimensional array library for OCaml
Stars: ✭ 44 (+144.44%)
Mutual labels:  tensor
GenericTensor
The only library allowing to create Tensors (matrices extension) with custom types
Stars: ✭ 42 (+133.33%)
Mutual labels:  tensor

Tensorial

Statically sized tensors and related operations for Julia

Stable Build Status codecov

Tensorial provides useful tensor operations (e.g., contraction; tensor product, ; inv; etc.) written in the Julia programming language. The library supports arbitrary size of non-symmetric and symmetric tensors, where symmetries should be specified to avoid wasteful duplicate computations. The way to give a size of the tensor is similar to StaticArrays.jl, and symmetries of tensors can be specified by using @Symmetry. For example, symmetric fourth-order tensor (symmetrizing tensor) is represented in this library as Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}. Einstein summation macro and automatic differentiation functions are also provided.

Speed

a = rand(Vec{3})                         # vector of length 3
A = rand(SecondOrderTensor{3})           # 3x3 second order tensor
S = rand(SymmetricSecondOrderTensor{3})  # 3x3 symmetric second order tensor
B = rand(Tensor{Tuple{3,3,3}})           # 3x3x3 third order tensor
AA = rand(FourthOrderTensor{3})          # 3x3x3x3 fourth order tensor
SS = rand(SymmetricFourthOrderTensor{3}) # 3x3x3x3 symmetric fourth order tensor (symmetrizing tensor)

See here for above aliases.

Operation Tensor Array speed-up
Single contraction
a ⋅ a 1.537 ns 16.943 ns ×11.0
A ⋅ a 1.538 ns 80.647 ns ×52.4
S ⋅ a 1.545 ns 79.630 ns ×51.5
Double contraction
A ⊡ A 2.730 ns 17.909 ns ×6.6
S ⊡ S 1.704 ns 19.099 ns ×11.2
B ⊡ A 4.886 ns 183.789 ns ×37.6
AA ⊡ A 7.035 ns 193.607 ns ×27.5
SS ⊡ S 3.589 ns 192.727 ns ×53.7
Tensor product
a ⊗ a 2.035 ns 53.872 ns ×26.5
Cross product
a × a 2.035 ns 53.872 ns ×26.5
Determinant
det(A) 1.541 ns 223.537 ns ×145.1
det(S) 1.542 ns 227.196 ns ×147.3
Inverse
inv(A) 5.432 ns 544.122 ns ×100.2
inv(S) 3.872 ns 552.627 ns ×142.7
inv(AA) 854.691 ns 1.727 μs ×2.0
inv(SS) 310.218 ns 1.728 μs ×5.6

The benchmarks are generated by runbenchmarks.jl on the following system:

julia> versioninfo()
Julia Version 1.6.3
Commit ae8452a9e0 (2021-09-23 17:34 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.5.0)
  CPU: Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

Installation

pkg> add Tensorial

Cheat Sheet

# identity tensors
one(Tensor{Tuple{3,3}})            == Matrix(1I,3,3) # second-order identity tensor
one(Tensor{Tuple{@Symmetry{3,3}}}) == Matrix(1I,3,3) # symmetric second-order identity tensor
I  = one(Tensor{NTuple{4,3}})               # fourth-order identity tensor
Is = one(Tensor{NTuple{2, @Symmetry{3,3}}}) # symmetric fourth-order identity tensor

# zero tensors
zero(Tensor{Tuple{2,3}}) == zeros(2, 3)
zero(Tensor{Tuple{@Symmetry{3,3}}}) == zeros(3, 3)

# random tensors
rand(Tensor{Tuple{2,3}})
randn(Tensor{Tuple{2,3}})

# macros (same interface as StaticArrays.jl)
@Vec [1,2,3]
@Vec rand(4)
@Mat [1 2
      3 4]
@Mat rand(4,4)
@Tensor rand(2,2,2)

# statically sized getindex by `@Tensor`
x = @Mat [1 2
          3 4
          5 6]
@Tensor(x[2:3, :])   == @Mat [3 4
                              5 6]
@Tensor(x[[1,3], :]) == @Mat [1 2
                              5 6]

# contraction and tensor product
x = rand(Mat{2,2})
y = rand(Tensor{Tuple{@Symmetry{2,2}}})
x ⊗ y isa Tensor{Tuple{2,2,@Symmetry{2,2}}} # tensor product
x  y isa Tensor{Tuple{2,2}}                # single contraction (x_ij * y_jk)
x ⊡ y isa Real                              # double contraction (x_ij * y_ij)

# det/inv for 2nd-order tensor
A = rand(SecondOrderTensor{3})          # equal to one(Tensor{Tuple{3,3}})
S = rand(SymmetricSecondOrderTensor{3}) # equal to one(Tensor{Tuple{@Symmetry{3,3}}})
det(A); det(S)
inv(A)  A  one(A)
inv(S)  S  one(S)

# inv for 4th-order tensor
AA = rand(FourthOrderTensor{3})          # equal to one(Tensor{Tuple{3,3,3,3}})
SS = rand(SymmetricFourthOrderTensor{3}) # equal to one(Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}})
inv(AA) ⊡ AA  one(AA)
inv(SS) ⊡ SS  one(SS)

# Einstein summation convention
A = rand(Mat{3,3})
B = rand(Mat{3,3})
@einsum (i,j) -> A[i,k] * B[k,j]
@einsum A[i,j] * B[i,j]

# Automatic differentiation
gradient(tr, rand(Mat{3,3})) == one(Mat{3,3}) # Tensor -> Real
gradient(identity, rand(SymmetricSecondOrderTensor{3})) == one(SymmetricFourthOrderTensor{3}) # Tensor -> Tensor

Other tensor packages

Inspiration

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].