Skip to main content

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.
  • pip for 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

  1. Create a virtual environment using the provided environment.yaml file:
conda env create -n dual_env -f environment.yaml
  1. Activate the environment:
conda activate dual_env
  1. 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() - Sine
  • cos() - Cosine
  • tan() - Tangent
  • asin() - Arcsine
  • acos() - Arccosine
  • atan() - Arctangent

Exponential and Logarithmic Functions

  • exp() - Exponential
  • log() - Natural Logarithm
  • sqrt() - Square Root

Hyperbolic Functions

  • sinh() - Hyperbolic Sine
  • cosh() - Hyperbolic Cosine
  • tanh() - 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

  • sin
  • cos
  • tan
  • asin
  • acos
  • atan

Exponential and Logarithmic Functions

  • exp
  • log
  • sqrt

Hyperbolic Functions

  • sinh
  • cosh
  • tanh

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.

Metadata

Release files for rsr45-dual-autodiff 0.0.post33

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rsr45-dual-autodiff 0.0.post33
File Size Uploaded Provenance Actions
rsr45_dual_autodiff-0.0.post33.tar.gz 2.4 MB Without provenance Details for rsr45_dual_autodiff-0.0.post33.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rsr45-dual-autodiff 0.0.post33
File Interpreter ABI Platform Actions
rsr45_dual_autodiff-0.0.post33-py3-none-any.whl Python 3 none any Details for rsr45_dual_autodiff-0.0.post33-py3-none-any.whl

Total release size: 4.6 MB

Release files / rsr45_dual_autodiff-0.0.post33.tar.gz

Download URL rsr45_dual_autodiff-0.0.post33.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
755a29c1b0ef7eba546ff29eed608a607af167e73d468d2e9c843cbaa814c4a9
BLAKE2b-256 checksum
How to use checksums
f80703788d6d23817c5e991fa69ab0e3e19c55a45989e9a04fa4f1cf10657c79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release files / rsr45_dual_autodiff-0.0.post33-py3-none-any.whl

Download URL rsr45_dual_autodiff-0.0.post33-py3-none-any.whl
Size 2.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
af38c122758605fc5c981606fe50c2a8535c795af0d9401f318d8e120d75ca9e
BLAKE2b-256 checksum
How to use checksums
a8000249a194ca9934c65383d1628de4a9cc3f5d494376078b047c9f75608a23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Security for rsr45-dual-autodiff 0.0.post33

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page