Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add rust Dual and Spline as extension modules. #136

Merged
merged 239 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
239 commits
Select commit Hold shift + click to select a range
4d9590a
ENH: begin to transfer some methods to Rust
attack68 Jun 17, 2023
32172f3
ENH: begin to transfer some methods to Rust
attack68 Jun 18, 2023
f3ffdae
ENH: begin to transfer some methods to Rust
attack68 Jun 18, 2023
c66a474
ENH: begin to transfer some methods to Rust
attack68 Jun 19, 2023
8d3a38d
ENH: begin to transfer some methods to Rust
attack68 Jun 21, 2023
d85f087
ENH: begin to transfer some methods to Rust
attack68 Jun 22, 2023
371e7cd
PERF: add RC to `vars` so that references can be maintained
attack68 Jun 23, 2023
c7d82da
PERF: add benchmarks for dual shared vars
attack68 Jun 23, 2023
efa7cf7
ENH: consider first draft dual tensordot
attack68 Jun 25, 2023
af9df8b
Merge branch 'main' into rust
attack68 Jul 27, 2023
8b00d91
Merge branch 'main' into rust
attack68 Aug 1, 2023
28d181e
REF: structure project accroding to recommended specs
attack68 Aug 1, 2023
841a1c3
REF: create Enum for Duals
attack68 Aug 2, 2023
4e30f09
REF: create Enum for Duals
attack68 Aug 2, 2023
e986596
REF: create Enum for Duals
attack68 Aug 2, 2023
48d27e2
Merge branch 'main' into rust
attack68 Aug 27, 2023
d24014a
Merge branch 'main' into rust
attack68 Sep 9, 2023
4ba3233
ENH: begin to transfer some methods to Rust
attack68 Jun 17, 2023
1e7698b
ENH: begin to transfer some methods to Rust
attack68 Jun 18, 2023
de8a302
ENH: begin to transfer some methods to Rust
attack68 Jun 18, 2023
6dc280f
ENH: begin to transfer some methods to Rust
attack68 Jun 19, 2023
2dcd20d
ENH: begin to transfer some methods to Rust
attack68 Jun 21, 2023
e82677f
ENH: begin to transfer some methods to Rust
attack68 Jun 22, 2023
b374562
PERF: add RC to `vars` so that references can be maintained
attack68 Jun 23, 2023
2bde5dd
PERF: add benchmarks for dual shared vars
attack68 Jun 23, 2023
a8ba8db
ENH: consider first draft dual tensordot
attack68 Jun 25, 2023
4966ed9
REF: structure project accroding to recommended specs
attack68 Aug 1, 2023
17a7152
REF: create Enum for Duals
attack68 Aug 2, 2023
f02c30e
REF: create Enum for Duals
attack68 Aug 2, 2023
3177af2
REF: create Enum for Duals
attack68 Aug 2, 2023
7267850
Merge remote-tracking branch 'origin/rust' into rust
attack68 Nov 5, 2023
136e5c3
Merge branch 'main' into rust
attack68 Nov 11, 2023
f91bea3
RUST: begin exploring Dual connections
attack68 Nov 22, 2023
8605b5c
Merge branch 'main' into rust
attack68 Nov 24, 2023
43e55f8
REF: change Rc to Arc
attack68 Nov 24, 2023
ff8bde3
RUST: explore
attack68 Nov 26, 2023
344a45a
RUST: explore
attack68 Nov 26, 2023
fc95580
Merge branch 'main' into rust
attack68 Feb 4, 2024
99122e6
RUST: try and fix
attack68 Feb 7, 2024
9c61b80
Remove pyproto
attack68 Feb 8, 2024
720c512
extract gradient as numpy array
attack68 Feb 8, 2024
3c37390
Fix up ARC sync
attack68 Feb 8, 2024
dc03fff
reorgainse
attack68 Feb 9, 2024
a9f88fe
reorgainse
attack68 Feb 9, 2024
0e4c875
reorgainse
attack68 Feb 9, 2024
2561fe3
test Python import of DualRS
attack68 Feb 9, 2024
a1b9f33
add tests
attack68 Feb 10, 2024
d43c196
add tests
attack68 Feb 10, 2024
87dada0
add tests
attack68 Feb 10, 2024
740f46f
add tests
attack68 Feb 10, 2024
f60b2c1
add tests
attack68 Feb 10, 2024
45bf7c7
add tests
attack68 Feb 10, 2024
95001d0
Possible optimisation
attack68 Feb 10, 2024
85a2f79
BACKPORT: make dual folder capable of switching between Py and Rust
attack68 Feb 11, 2024
573c876
BACKPORT: properly specify Dual
attack68 Feb 11, 2024
3d7ad5b
BACKPORT: specification of Dual in Py
attack68 Feb 11, 2024
b42ecca
BACKPORT: Dual specificiation
attack68 Feb 11, 2024
0d18097
BACKPORT: Dual specification
attack68 Feb 11, 2024
7ca9f64
DualRS development
attack68 Feb 11, 2024
2de061f
Merge remote-tracking branch 'origin/main' into rust
attack68 Feb 11, 2024
88565cb
TEST: numpy compat for Rust Dual
attack68 Feb 11, 2024
1794fdb
TEST: numpy compat for Rust Dual
attack68 Feb 11, 2024
d085e75
TEST: numpy compat for Rust Dual
attack68 Feb 12, 2024
431005d
pivot matrix
attack68 Feb 12, 2024
a06a3b4
pivot matrix
attack68 Feb 13, 2024
c51fd66
implement traits Num and Signed
attack68 Feb 16, 2024
a6a5c89
edits
attack68 Feb 16, 2024
d83ded2
Linalg: add pivot matrix
attack68 Feb 17, 2024
e8b2a14
Linalg solver and tests
attack68 Feb 17, 2024
8d06a0f
Linalg solver and tests
attack68 Feb 18, 2024
adad7a9
Linalg solver and tests
attack68 Feb 18, 2024
f2fe17d
cargo fmt
attack68 Feb 19, 2024
8895ea8
fiddling around with types
attack68 Feb 19, 2024
60d4eb8
reorganise code to avoid SegFault
attack68 Feb 19, 2024
d9f14df
Reorganise NumPy<T> to Rust
attack68 Feb 20, 2024
e3f26f3
Fix upper triangular solve
attack68 Feb 20, 2024
31fb07e
Clippy up
attack68 Feb 20, 2024
51f721d
Linalg solver and tests
attack68 Feb 20, 2024
f1e7bbb
Remove comments
attack68 Feb 20, 2024
1c77eac
Merge branch 'main' into rust
attack68 Feb 20, 2024
bc09ce1
begin spline
attack68 Feb 21, 2024
c56817e
Add splines
attack68 Feb 21, 2024
c4593f0
tests
attack68 Feb 22, 2024
5a68339
tests and generics linalg
attack68 Feb 23, 2024
32cd4ef
tests and generics linalg
attack68 Feb 23, 2024
3eb3d61
Add splines
attack68 Feb 23, 2024
09f2e10
Add splines
attack68 Feb 23, 2024
8174091
ENH: add csolve
attack68 Feb 24, 2024
06e8527
ENH: add ppev
attack68 Feb 24, 2024
88c09c5
ENH: add ppev test
attack68 Feb 24, 2024
a150017
ENH: add ppev test
attack68 Feb 25, 2024
e5e5698
ENH: add ppev test
attack68 Feb 25, 2024
c60ebc6
Split Tensor Ops by type into files
attack68 Feb 25, 2024
b0a6020
Reorganise dualrs tests
attack68 Feb 26, 2024
52aaea7
Add simple f64 outer product
attack68 Feb 27, 2024
26a6c80
Dual2 development
attack68 Feb 27, 2024
73e36a3
Dual2 development + fmt
attack68 Feb 28, 2024
a3ff2d5
REF: reconfigure Dual2 to accept vector dual2 input
attack68 Feb 28, 2024
416789d
REF: reconfigure Dual2 to accept vector dual2 input in tests
attack68 Feb 28, 2024
471bbf5
Add Dual2 class to PyO3
attack68 Feb 28, 2024
8a10a8d
Enum DualsOrF64
attack68 Feb 29, 2024
ace7680
REF: edit tests for Rust Dual implementation
attack68 Mar 1, 2024
ac56d95
REF: dual tests for rust implementation
attack68 Mar 1, 2024
6a6f7c9
Add dual2 getter for Dual in rust
attack68 Mar 1, 2024
f783b83
Merge branch 'main' into rust
attack68 Mar 1, 2024
5cc5faa
REF: edit tests for rust Dual implemenntation
attack68 Mar 2, 2024
2a45ca4
Add rust dual and dual2 gradient functions
attack68 Mar 2, 2024
32a5338
REF: edit tests for rust Dual implemenntation
attack68 Mar 2, 2024
f07ddc2
REF: remove `dual.gradient(..)` in favour of `gradient(dual, ..)`
attack68 Mar 2, 2024
fdb5206
REF: remove `dual.gradient(..)` in favour of `gradient(dual, ..)`
attack68 Mar 2, 2024
87958fd
Merge branch 'rust_duals_preconfig' into rust
attack68 Mar 2, 2024
a79552d
add grad1 and grad2 in rust and Py
attack68 Mar 2, 2024
a710656
REF: tests for Dual2 rust
attack68 Mar 2, 2024
66c4b10
add gradient method in init
attack68 Mar 2, 2024
251e03f
REF: tests for Dual2 rust
attack68 Mar 2, 2024
7db5d30
Merge branch 'rust_duals_preconfig' into rust
attack68 Mar 2, 2024
9a1dd9b
REF: tests for rust implementation
attack68 Mar 2, 2024
263e03b
REF: init for rust Dual
attack68 Mar 2, 2024
c73e71a
REF: prepare for rust Dual
attack68 Mar 2, 2024
af2a68d
REF: skip creating new object when setting order
attack68 Mar 2, 2024
f5529eb
REF: adjust tests to allow rust Duals
attack68 Mar 2, 2024
a704a42
REF: Dual2 init arguments
attack68 Mar 2, 2024
9aa7a4d
REF: init method for Dual
attack68 Mar 2, 2024
cd1f9bb
REF: adjust tests
attack68 Mar 2, 2024
9c93a9e
add gradient methods
attack68 Mar 2, 2024
bf6aa39
REF: amend Dual repr to align with rust
attack68 Mar 3, 2024
d27a8b0
REF: tests for rust Dual
attack68 Mar 3, 2024
391bf81
REF: tests for rust Dual
attack68 Mar 3, 2024
bb37114
REF: tests for rust Dual
attack68 Mar 3, 2024
a5a05ab
dual tests import gradient
attack68 Mar 3, 2024
2a58485
begin benchmarking
attack68 Mar 4, 2024
1f41265
Add vars_from method
attack68 Mar 4, 2024
5a7e2a1
REF: numpy deprecation changes
attack68 Mar 4, 2024
dd64914
REF: Extend set_order_convert to allow `vars_from`
attack68 Mar 4, 2024
3700884
Merge branch 'main' into rust
attack68 Mar 5, 2024
467a867
Merge branch 'main' into rust
attack68 Mar 5, 2024
f5fbacc
CONFIG: build toolchain info
attack68 Mar 6, 2024
6eec69e
REF: refactor docs for Rust Dual enable
attack68 Mar 7, 2024
1826927
DOC: attempt to roll over Sphinx docs for rust overloads
attack68 Mar 8, 2024
605a638
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 8, 2024
cde2b06
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 8, 2024
a06bcb0
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 8, 2024
578a8d3
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 8, 2024
87dceb4
DELETE unusued
attack68 Mar 8, 2024
0e2310a
Finalise Dual Rust tests
attack68 Mar 8, 2024
3a460b3
modify dsolve
attack68 Mar 9, 2024
a1a897b
Refactor linalg rust
attack68 Mar 9, 2024
1d7444a
fdsolve to py
attack68 Mar 9, 2024
f414ed7
fdsolve to py
attack68 Mar 9, 2024
92847e4
TST: all tests passing!
attack68 Mar 9, 2024
650dcc3
Set Complete pivoting
attack68 Mar 9, 2024
043e3e1
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 12, 2024
0f92e7a
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 12, 2024
b729754
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 12, 2024
f0773b8
Profile for closed vars
attack68 Mar 12, 2024
898a63c
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 13, 2024
838c7f8
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 13, 2024
4604aa9
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 13, 2024
996612f
DOC: manually port Dual sphinx docs to Python code
attack68 Mar 13, 2024
6467103
Profile for closed vars
attack68 Mar 14, 2024
8156522
Profile for closed vars
attack68 Mar 15, 2024
2bd21e0
Profile for closed vars
attack68 Mar 15, 2024
cc59d4e
Profile for closed vars
attack68 Mar 15, 2024
c62b3d1
fdsolve to py
attack68 Mar 15, 2024
59e256c
fdsolve to py
attack68 Mar 15, 2024
6520a6b
REMOVE old file
attack68 Mar 15, 2024
bb9a924
REMOVE old file
attack68 Mar 15, 2024
1458a57
Profile for closed vars
attack68 Mar 16, 2024
c1c1052
REMOVE old file
attack68 Mar 16, 2024
db71fb2
correct dual2 gradients
attack68 Mar 16, 2024
18aae29
chg outer11
attack68 Mar 16, 2024
0115845
delete files
attack68 Mar 16, 2024
e81f7a9
gitignore
attack68 Mar 16, 2024
1eae0e5
Merge branch 'main' into rust
attack68 Mar 16, 2024
da4d940
Begin to add in Chrono support
attack68 Mar 16, 2024
2b42291
develop splines
attack68 Mar 17, 2024
5e7f9a8
Merge remote-tracking branch 'origin/main' into rust
attack68 Mar 17, 2024
d1c60dd
develop splines
attack68 Mar 17, 2024
ec4725c
develop splines
attack68 Mar 17, 2024
b834b94
BUG: solver iteration numbers reported
attack68 Mar 18, 2024
912099f
REF: consider changes here to move to main.
attack68 Mar 18, 2024
dd968d0
RUST: add pyo3 bindings
attack68 Mar 18, 2024
3fd7781
Merge branch 'main' into rust
attack68 Mar 18, 2024
462c1be
develop splines
attack68 Mar 17, 2024
cc6700f
develop splines
attack68 Mar 17, 2024
2f437be
BUG: solver iteration numbers reported
attack68 Mar 18, 2024
001a3b8
REF: consider changes here to move to main.
attack68 Mar 18, 2024
ca42f5c
RUST: add pyo3 bindings
attack68 Mar 18, 2024
a7092e3
Merge branch 'main' into rust
attack68 Mar 18, 2024
d07cddd
Merge branch 'rust' into spline_posix
attack68 Mar 18, 2024
10dc107
Merge remote-tracking branch 'origin/spline_posix' into spline_posix
attack68 Mar 19, 2024
9438d0e
Merge branch 'main' into rust
attack68 Mar 19, 2024
d5d3173
Merge branch 'rust' into spline_posix
attack68 Mar 19, 2024
3aa4c89
REF: convert timedelta ops to f64 ops
attack68 Mar 19, 2024
61506f3
DEV: continue splines development
attack68 Mar 19, 2024
1e42e0c
Merge branch 'main' into rust
attack68 Mar 20, 2024
7b8c6ac
Merge branch 'rust' into spline_posix
attack68 Mar 20, 2024
82069ef
PartialEq annd Copy/Clone
attack68 Mar 20, 2024
98b2c51
RUST: index_left
attack68 Mar 21, 2024
4d4fd57
REF: curves to use Rust index_left
attack68 Mar 21, 2024
0fc5faf
REF: linear zero rate posix interp
attack68 Mar 22, 2024
929f4dd
extend dual constuctors
attack68 Mar 24, 2024
126bacb
Rust: add try new and try new from
attack68 Mar 25, 2024
039b5ea
Clippy
attack68 Mar 25, 2024
35903b0
Clippy
attack68 Mar 25, 2024
3048092
Clippy
attack68 Mar 25, 2024
90c043a
extend dual constuctors
attack68 Mar 25, 2024
3931065
Dual2 Ref
attack68 Mar 26, 2024
fa396d0
Dual2 Ref
attack68 Mar 26, 2024
57a52d0
Docs
attack68 Mar 26, 2024
8387b31
Docs
attack68 Mar 26, 2024
8116ac5
Docs
attack68 Mar 26, 2024
581c3da
Merge branch 'rust' into spline_posix
attack68 Mar 26, 2024
fb69c67
Docs
attack68 Mar 26, 2024
eb265ad
Docs
attack68 Mar 26, 2024
2f13b79
Docs
attack68 Mar 26, 2024
2e6a034
Docs
attack68 Mar 26, 2024
e9ba7e8
DOC: add rst files
attack68 Mar 26, 2024
06b314f
DOC: add rst files
attack68 Mar 26, 2024
59e441c
DOC: add rst files
attack68 Mar 27, 2024
961dd0f
Docs
attack68 Mar 27, 2024
9e3cd3c
Docs
attack68 Mar 27, 2024
a9d4011
Docs
attack68 Mar 27, 2024
79dc19f
Docs
attack68 Mar 27, 2024
7a1436c
Docs
attack68 Mar 27, 2024
3a3739c
Docs
attack68 Mar 27, 2024
9cabd3a
Docs
attack68 Mar 27, 2024
1474c01
extend dual constuctors
attack68 Mar 27, 2024
2cf14b3
add workflow
attack68 Mar 27, 2024
119af50
add workflow
attack68 Mar 27, 2024
93f4581
add workflow
attack68 Mar 27, 2024
c2e8202
Merge branch 'main' into spline_posix
attack68 Mar 27, 2024
9d3d959
GH: workflow trial and error
attack68 Mar 27, 2024
046e5c2
Github workflow
attack68 Mar 28, 2024
3f77dad
Github workflow
attack68 Mar 28, 2024
508825a
Fix clippy warnings
attack68 Mar 28, 2024
c456398
workflows fix
attack68 Mar 28, 2024
2a07955
add workflow
attack68 Mar 28, 2024
74bb0d5
add Result to csolve output
attack68 Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/ubuntu-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,17 @@ jobs:
python-version: ["3.11"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-latest.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
pip install .[dev] -v
- name: Test with pytest
run: |
coverage run -m pytest
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ubuntu-minimum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
python-version: ["3.9"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
Expand All @@ -28,6 +30,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements-minimum.txt
pip install . -v
- name: Test with pytest
run: |
pytest
12 changes: 4 additions & 8 deletions .github/workflows/windows-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,17 @@ jobs:
python-version: ["3.11"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-latest.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
pip install .[dev] -v
- name: Test with pytest
run: |
pytest
5 changes: 4 additions & 1 deletion .github/workflows/windows-minimum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
python-version: ["3.9"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
Expand All @@ -28,6 +30,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements-minimum.txt
pip install . -v
- name: Test with pytest
run: |
pytest
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ __pycache__/
# C extensions
*.so

# Rust extensions
src/bin

# Distribution / packaging
.Python
local_resources/
Expand Down Expand Up @@ -138,4 +141,5 @@ dmypy.json
scratch.py

.idea/
/*.ipynb
/*.ipynb
Carlo.lock
6 changes: 5 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build:
os: ubuntu-22.04
tools:
python: "3.11"
rust: "1.75"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
Expand All @@ -28,4 +29,7 @@ sphinx:
# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: requirements.txt
- method: pip
path: .
extra_requirements:
- dev
39 changes: 39 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "rateslibrs"
version = "1.2.0"
edition = "2021"

[lib]
name = "rateslibrs"
path = "src/lib.rs"
#crate-type = ["rlib"]
#crate-type = ["cdylib"] # for pyO3
crate-type = ["lib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
#pyo3 = { version = "0.20.3", features = ["abi3-py39", "extension-module"] }
#chrono = "0.4.0"
ndarray = "0.15.6"
indexmap = "1.9.3"
num-traits = "0.2.15"
auto_ops = "0.3.0"
numpy = "0.20.0"
itertools = "0.12.1"

# --- This section should be live in development to use `cargo test --lib --no-default-features`
[dependencies.pyo3]
version = "0.20.3"

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]
# ------------- When building commment this out and use the abi3-py39 feature in the above block.

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }

[[bench]]
name = "my_benchmark"
harness = false
4 changes: 3 additions & 1 deletion PACKAGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ On "main":
1) Update the whatsnew with the target release date.
2) Add a new entry to the switcher.json in main:docs/source/static, pushing stable to next version.
3) Change the badges.json file is there is anything to add, e.g. versions.
4) Bump the "version" in pyproject.toml and check the dependencies.
4) Bump the "version" in pyproject.toml, and __init__ __version__ and check the dependencies.
5) Checks should be OK in github actions but perform a local double check.

Checks:
Expand All @@ -26,6 +26,8 @@ On "release branch":
DEVELOPMENT to False.

4) Commit and Push the branch.
5) Run `cargo test --lib --no-default-features`
6) Change the Cargo.toml file for abi3-py39 features.

Build:
$ pip install build twine
Expand Down
2 changes: 2 additions & 0 deletions benches/_README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Contains benchmark files for rust implementation.
Directed by Cargo.toml.
95 changes: 95 additions & 0 deletions benches/my_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};

use rateslibrs::dual::dual1::Dual;
use rateslibrs::dual::Duals;

use indexmap::set::IndexSet;
use ndarray::Array;
use std::rc::Rc;

fn dual_add_bm(a: &Dual, b: &Dual) -> Dual {
a + b
}

fn duals_add_bm(a: &Duals, b: &Duals) -> Duals {
a + b
}

fn dual_sub_bm(a: &Dual, b: &Dual) -> Dual {
a - b
}

fn dual_mul_bm(a: &Dual, b: &Dual) -> Dual {
a * b
}

fn dual_div_bm(a: &Dual, b: &Dual) -> Dual {
a / b
}

fn float_add_bm(a: &f64, b: &f64) -> f64 {
a + b
}

fn criterion_benchmark(c: &mut Criterion) {
let dual_ = Array::ones(1000);
let vars = IndexSet::from_iter((0..1000).map(|x| format!("v{}", x).to_string()));
let dual_2 = Array::ones(1000);
let vars2 = IndexSet::from_iter((0..1000).map(|x| format!("u{}", x).to_string()));

let a = Dual {
real: 2.0,
vars: Rc::new(vars),
dual: dual_,
};
let b = Dual {
real: 3.0,
vars: Rc::new(vars2),
dual: dual_2,
};
let x = 20.1;
let y = 22.1;

let duals_ = Array::ones(1000);
let duals_2 = Array::ones(1000);
let vars = IndexSet::from_iter((0..1000).map(|x| format!("v{}", x).to_string()));
let vars2 = IndexSet::from_iter((0..1000).map(|x| format!("u{}", x).to_string()));
let a2 = Duals::Dual(Dual {
real: 2.0,
vars: Rc::new(vars),
dual: duals_,
});
let b2 = Duals::Dual(Dual {
real: 3.0,
vars: Rc::new(vars2),
dual: duals_2,
});
let x2 = Duals::Float(20.1);
let y2 = Duals::Float(22.1);

c.bench_function("float add", |z| z.iter(|| float_add_bm(&x, &y)));
c.bench_function("float add duals", |z| z.iter(|| duals_add_bm(&x2, &y2)));
c.bench_function("dual add diff vars", |z| z.iter(|| dual_add_bm(&a, &b)));
c.bench_function("duals add diff vars", |z| z.iter(|| duals_add_bm(&a2, &b2)));
c.bench_function("dual sub diff vars", |z| z.iter(|| dual_sub_bm(&a, &b)));
c.bench_function("dual mul diff vars", |z| z.iter(|| dual_mul_bm(&a, &b)));
c.bench_function("dual div diff vars", |z| z.iter(|| dual_div_bm(&a, &b)));
c.bench_function("dual add same ptr vars", |z| {
z.iter(|| dual_add_bm(&a, &a.clone()))
});
c.bench_function("duals add same ptr vars", |z| {
z.iter(|| duals_add_bm(&a2, &a2.clone()))
});
c.bench_function("dual sub same ptr vars", |z| {
z.iter(|| dual_sub_bm(&a, &a.clone()))
});
c.bench_function("dual mul same ptr vars", |z| {
z.iter(|| dual_mul_bm(&a, &a.clone()))
});
c.bench_function("dual div same ptr vars", |z| {
z.iter(|| dual_div_bm(&a, &a.clone()))
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
44 changes: 44 additions & 0 deletions docs/source/api/rateslib.dual.Dual.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Dual
==========

.. currentmodule:: rateslib.dual

.. py:class:: Dual(real, vars, dual)
Dual number data type to perform first derivative automatic differentiation.

:param real: The real coefficient of the dual number
:type real: float, int

:param vars: The labels of the variables for which to record derivatives. If empty,
the dual number represents a constant, equivalent to a float.
:type vars: tuple of str

:param dual: First derivative information contained as coefficient of linear manifold.
Defaults to an array of ones the length of ``vars`` if empty.
:type dual: list of float

.. rubric:: Attributes

:ivar real: float
:ivar vars: sequence of str
:ivar dual: 1d ndarray

.. seealso::
:class:`~rateslib.dual.Dual2`: Dual number data type to perform second derivative automatic differentiation.

.. rubric:: Examples

.. ipython:: python
from rateslib.dual import Dual, gradient
def func(x, y):
return 5 * x**2 + 10 * y**3
x = Dual(1.0, ["x"], [])
y = Dual(1.0, ["y"], [])
gradient(func(x,y), ["x", "y"])
.. rubric:: Methods Summary

.. include:: rateslib.dual.Dual.vars_from.rst
44 changes: 44 additions & 0 deletions docs/source/api/rateslib.dual.Dual.vars_from.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.. vars_from
==========
.. .. currentmodule:: rateslib.dual
.. py:method:: Dual.vars_from(other, real, vars, dual)
Create a :class:`~rateslib.dual.Dual` object with ``vars`` linked with another.

:param other: The other Dual from which to link vars.
:type other: Dual

:param real: The real coefficient of the dual number
:type real: float, int

:param vars: The labels of the variables for which to record derivatives. If empty,
the dual number represents a constant, equivalent to a float.
:type vars: tuple of str

:param dual: First derivative information contained as coefficient of linear manifold.
Defaults to an array of ones the length of ``vars`` if empty.
:type dual: list of float

:rtype: Dual

.. rubric:: Notes

Variables are constantly checked when operations are performed between dual numbers. In Rust the variables
are stored within an ARC pointer. It is much faster to check the equivalence of two ARC pointers than if the elements
within a variables Set, say, are the same *and* in the same order. This method exists to create dual data types
with shared ARC pointers directly.

.. ipython:: python
from rateslib import Dual
x1 = Dual(1.0, ["x"], [])
x2 = Dual(2.0, ["x"], [])
# x1 and x2 have the same variables (["x"]) but it is a different object
x1.ptr_eq(x2)
x3 = Dual.vars_from(x1, 3.0, ["x"], [])
# x3 contains shared object variables with x1
x1.ptr_eq(x3)
Loading
Loading