.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/ex03_custom_extension.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_ex03_custom_extension.py: Custom Extensions ----------------- Custom functions (extensions) are easy to implement in `tensortrax`. Beside the function expression, three additional (dual) variation expressions have to be defined. .. GENERATED FROM PYTHON SOURCE LINES 7-25 .. code-block:: Python import numpy as np from tensortrax import Tensor, Δ, Δδ, f, δ def sin(A): return Tensor( x=np.sin(f(A)), δx=np.cos(f(A)) * δ(A), Δx=np.cos(f(A)) * Δ(A), Δδx=-np.sin(f(A)) * δ(A) * Δ(A) + np.cos(f(A)) * Δδ(A), ntrax=A.ntrax, ) x = np.eye(3) y = sin(Tensor(x)) .. GENERATED FROM PYTHON SOURCE LINES 26-34 .. note:: Contrary to NumPy's ``w, v = np.linalg.eigh(C)``, which returns eigenvalues and -vectors, the differentiable ``w, M = tm.linalg.eigh(C)`` function returns eigenvalues and eigenbases of symmetric real-valued tensors. .. tip:: Feel free to `contribute `_ missing math-functions to `src/tensortrax/math/_math_tensor.py `_ 📃 ✏️. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.001 seconds) .. _sphx_glr_download_examples_ex03_custom_extension.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ex03_custom_extension.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex03_custom_extension.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex03_custom_extension.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_