Skip to main content

Math on (Hyper-Dual) Tensors with Trailing Axes

Project description

tensortrax

 _                            
| |                          ████████╗██████╗  █████╗ ██╗  ██╗
| |_ ___ _ __  ___  ___  _ __╚══██╔══╝██╔══██╗██╔══██╗╚██╗██╔╝
| __/ _ \ '_ \/ __|/ _ \| '__|  ██║   ██████╔╝███████║ ╚███╔╝ 
| ||  __/ | | \__ \ (_) | |     ██║   ██╔══██╗██╔══██║ ██╔██╗ 
 \__\___|_| |_|___/\___/|_|     ██║   ██║  ██║██║  ██║██╔╝ ██╗
                                ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝  

Math on (Hyper-Dual) Tensors with Trailing Axes.

PyPI version shields.io License: GPL v3 Made with love in Graz (Austria) codecov

Features

  • Designed to operate on input arrays with trailing axes
  • Essential vector/tensor Hyper-Dual number math, including limited support for einsum (restricted to max. two operands)
  • Forward Mode Automatic Differentiation (AD) using Hyper-Dual Tensors, up to second order derivatives
  • Create functions in terms of Hyper-Dual Tensors
  • Evaluate the function, the gradient (jacobian) and the hessian on given input arrays
  • Straight-forward definition of custom functions in variational-calculus notation

Not Features

  • Not imitating NumPy (like Autograd)
  • No arbitrary-order gradients

Usage

Let's define a scalar-valued function which operates on a tensor.

import tensortrax as tr
import tensortrax.math as tm

def fun(F):
    C = F.T() @ F
    I1 = tm.trace(C)
    J = tm.det(F)
    return J ** (-2 / 3) * I1 - 3

The hessian of the scalar-valued function w.r.t. the function argument is evaluated by variational calculus (Forward Mode AD implemented as Hyper-Dual Tensors). The function is called once for each component of the hessian (symmetry is taken care of). The function and the gradient are evaluated with no additional computational cost.

import numpy as np

# some random input data
np.random.seed(125161)
F = np.random.rand(3, 3, 8, 50) / 10
for a in range(3):
    F[a, a] += 1

# W = tr.function(fun, ntrax=2)(F)
# dWdF, W = tr.gradient(fun, ntrax=2)(F)
d2WdF2, dWdF, W = tr.hessian(fun, ntrax=2)(F)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tensortrax-0.0.1.tar.gz (44.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tensortrax-0.0.1-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file tensortrax-0.0.1.tar.gz.

File metadata

  • Download URL: tensortrax-0.0.1.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for tensortrax-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a792d32e4c87ef41d280925c77bf5f0f6541c7d810ac2afd08a89fe33dd2acb1
MD5 821ad72155eb5b0e28e6825a61591c35
BLAKE2b-256 1220405520da55cf384c11d5af2bfc860d747f7a4c4559286c9480512ddc031a

See more details on using hashes here.

File details

Details for the file tensortrax-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: tensortrax-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for tensortrax-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c786d340915dc2b8737b56105420dcd1dcb739c5a43a136b6ae1865f050015a
MD5 a8b0bc4bed7f94510aead26b70088d1f
BLAKE2b-256 59622443dc1e89d8f915957ee96f67f64756ffb55fa9950a2f13a25639052687

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page