Skip to content

Port intensity measure calculations to rust code#199

Merged
lispandfound merged 110 commits intomasterfrom
rust_calculations
Feb 15, 2026
Merged

Port intensity measure calculations to rust code#199
lispandfound merged 110 commits intomasterfrom
rust_calculations

Conversation

@lispandfound
Copy link
Contributor

This PR ports the majority of the intensity measures to rust including:

  • CAV,
  • Arias intensity,
  • pSA (dealt with in a separate PR),
  • RotD calculations for PGA, PGV, and pSA

The primary motivations for this are:

  • To remove the annoying numba and numexpr dependencies which make it difficult to upgrade python versions, and make importing modules painful.
  • To enable faster intensity measure calculation by parallelising more of the IM workflow, which was currently limited in the numba/numexpr implementations. Because rust is a proper compiled language, single threaded performance is also faster due to better a vectorisation and optimisation engine than what is present in Numba.
  • To reduce the memory overhead of IM calc implementations. Unlike numpy and numba, rust will not copy values around by default, so we can better control the allocated memory in hot loops. Out of control memory usage has resulted in mysterious IM calc crashes in the past.
  • Better type checking guarantees and testing.
  • Proper benchmarking to make it easy to assess the impact of future optimisations in the IM workflow.
  • 64-bit floating point calculations for intensity measures. While some calculations don't benefit from this, accumulated results for CAV, AI, Ds, and especially pSA benefit from the higher precision calculations in 64-bit floating point arithmetic. This was, of course, possible using numba and numexpr but the aforementioned memory and speed issues are even more sensitive when you double the memory required for the waveforms.

lispandfound and others added 30 commits November 28, 2025 10:38
- pSA now calculated with either linear or constant newmark according
to stability.
- rotd calculation in parallel
- use `select_nth_unstable` instead of sorting to reduce
post-processing.
- use branchless absmax to speed up rotd fold
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports intensity measure calculations from Python (numba/numexpr) to Rust to improve performance, remove problematic dependencies, enable better parallelization, reduce memory overhead, and provide 64-bit floating point precision. The PR includes new Rust modules for parallel processing utilities, numerical integration (trapezoid rule with zero-crossing correction), significant duration calculations, RotD calculations, and physical constants.

Changes:

  • Implemented core intensity measure calculations in Rust with parallel processing support
  • Migrated from 32-bit to 64-bit floating point for waveform data
  • Updated test suite to work with new Rust implementations and float64 precision
  • Added comprehensive unit tests in Rust code
  • Updated benchmark CSV files to reflect float64 precision changes

Reviewed changes

Copilot reviewed 35 out of 52 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src-rust/utils.rs New parallel processing utilities for row-wise operations on 2D arrays
src-rust/trapz.rs Numerical integration using trapezoid rule with zero-crossing correction
src-rust/significant_duration.rs Significant duration calculations using binary search
src-rust/rotd.rs RotD180 calculations for component rotation
src-rust/constants.rs Physical constants (gravitational acceleration)
tests/test_ims.py Updated test suite for Rust implementations with float64
tests/resources/*/im_benchmark.csv Updated benchmark data for float64 precision
IM/waveform_reading.py Changed dtype from float32 to float64
MANIFEST.in Excluded additional files from distribution

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

joelridden
joelridden previously approved these changes Jan 19, 2026
Copy link
Contributor

@AndrewRidden-Harper AndrewRidden-Harper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 52 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lispandfound lispandfound merged commit 70d463a into master Feb 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants