A Python package for forward-mode automatic differentiation using dual numbers.
Project description
dual_autodiff
dual_autodiff is a Python package that provides automatic differentiation using dual numbers. It is designed to handle derivatives and mathematical operations efficiently. The package also includes dual_autodiff_x, a Cython-optimized version for enhanced performance.
Features
- Automatic differentiation using dual numbers.
- Support for a wide range of mathematical funtions:
- Cython-optimized version (
dual_autodiff_x) for improved speed.
Installation
Prerequisites
- Python 3.9 or higher.
pipfor package installation.conda(optional) for managing virtual environments.
Installing dual_autodiff
Using pip
Clone the repository and install the package:
git clone 'https://gitlab.developers.cam.ac.uk/phy/data-intensive-science-mphil/assessments/c1_coursework1/rsr45.git'
cd dual_autodiff
pip install e .
Using conda
- Create a virtual environment using the provided
environment.yamlfile:
conda env create -n dual_env -f environment.yaml
- Activate the environment:
conda activate dual_env
- Install the package within this environment:
pip install -e .
Usage
Using dual_autodiff
from dual_autodiff import Dual, sin, cos
# Create a Dual object
x = Dual(1.0, 1.0)
# Perform operations
y = sin(x)
print(f"Value: {y.real}, Derivative: {y.dual}")
Available Functions
Dual Class Methods
The following methods are available in the Dual class:
Arithmetic Operations
__add__,__radd__- Addition__sub__,__rsub__- Subtraction__mul__,__rmul__- Multiplication__truediv__,__rtruediv__- Division__pow__- Power
Trigonometric Functions
sin()- Sinecos()- Cosinetan()- Tangentasin()- Arcsineacos()- Arccosineatan()- Arctangent
Exponential and Logarithmic Functions
exp()- Exponentiallog()- Natural Logarithmsqrt()- Square Root
Hyperbolic Functions
sinh()- Hyperbolic Sinecosh()- Hyperbolic Cosinetanh()- Hyperbolic Tangent
Global Functions in functions.py
These functions are global aliases for the corresponding Dual class methods, allowing them to be called directly with either float or Dual inputs:
Trigonometric Functions
sincostanasinacosatan
Exponential and Logarithmic Functions
explogsqrt
Hyperbolic Functions
sinhcoshtanh
How It Works
Dual Numbers
Dual numbers are numbers of the form:
[ a + b $\epsilon$ ]
Where:
- a is the real part, representing the function value.
- b is the dual part, representing the derivative.
- $\epsilon$^2 = 0, making (\epsilon) infinitesimally small.
This structure allows for efficient computation of derivatives during operations.
Cython Optimization
The dual_autodiff_x package uses Cython to compile critical operations into C, providing a significant speed boost for computationally intensive tasks.
Installing dual_autodiff_x
For the Cython-optimized version:
cd dual_autodiff_x
pip install e .
See the README.md file in dual_autodiff_x.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rsr45_dual_autodiff-0.0.post33.tar.gz.
File metadata
- Download URL: rsr45_dual_autodiff-0.0.post33.tar.gz
- Upload date:
- Size: 2.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
755a29c1b0ef7eba546ff29eed608a607af167e73d468d2e9c843cbaa814c4a9
|
|
| MD5 |
2d38197867e8e5e8eb256bb34e7117ea
|
|
| BLAKE2b-256 |
f80703788d6d23817c5e991fa69ab0e3e19c55a45989e9a04fa4f1cf10657c79
|
File details
Details for the file rsr45_dual_autodiff-0.0.post33-py3-none-any.whl.
File metadata
- Download URL: rsr45_dual_autodiff-0.0.post33-py3-none-any.whl
- Upload date:
- Size: 2.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af38c122758605fc5c981606fe50c2a8535c795af0d9401f318d8e120d75ca9e
|
|
| MD5 |
51bb9909d0783c189e6894beb4da7557
|
|
| BLAKE2b-256 |
a8000249a194ca9934c65383d1628de4a9cc3f5d494376078b047c9f75608a23
|