Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
258 changes: 222 additions & 36 deletions pixi.lock

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build-backend = "maturin"
[project]
name = "scippneutron_algorithms"
description = "Optimized and compile algorithms for ScippNeutron"
version = "26.7.0"
authors = [{ name = "Scipp contributors" }]
license = "BSD-3-Clause"
license-files = ["LICENSE"]
Expand All @@ -21,12 +22,12 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Typing :: Typed",
]
dynamic = ["version"]
requires-python = ">=3.11"

dependencies = [
"numpy>=2",
"scipp>=25.11.0",
"scipy>=1.7.0",
]

[dependency-groups]
Expand All @@ -46,6 +47,9 @@ python = "3.11.*"
"Source" = "https://github.com/scipp/scippneutron_algorithms"

[tool.maturin]
profile = "release"
editable-profile = "dev"
manifest-path = "rust/crates/algo_bindings/Cargo.toml"
module-name = "scippneutron_algorithms._scippneutron_algorithms_lib"

[tool.pytest.ini_options]
Expand All @@ -72,7 +76,7 @@ extend-exclude = [

[tool.ruff.lint]
# See https://docs.astral.sh/ruff/rules/
select = ["B", "C4", "DTZ", "E", "F", "G", "I", "PERF", "PGH", "PT", "PYI", "RUF", "S", "T20", "UP", "W"]
select = ["B", "C4", "D", "DTZ", "E", "F", "G", "I", "FBT", "FURB", "PERF", "PGH", "PT", "PYI", "RUF", "S", "T20", "UP", "W"]
ignore = [
# Conflict with ruff format, see
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
Expand All @@ -85,8 +89,12 @@ pydocstyle.convention = "numpy"
[tool.ruff.lint.per-file-ignores]
# those files have an increased risk of relying on import order
"tests/*" = [
"S101", # asserts are fine in tests
"B018", # 'useless expressions' are ok because some tests just check for exceptions
"D", # no need for docstrings in the tests
"S101", # asserts are fine in tests
]
"tools/*" = [
"D",
]

[tool.mypy]
Expand Down
10 changes: 9 additions & 1 deletion rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "_scippneutron_algorithms_lib"
version = "26.7.0"
edition = "2024"
[workspace]
members = ["crates/*"]
resolver = "2"

[lib]
name = "_scippneutron_algorithms_lib"
crate-type = ["cdylib"]
[workspace.package]
edition = "2024"
rust-version = "1.91"

[dependencies]
[workspace.dependencies]
ndarray = "0.17.2"
numpy = "0.29"
pyo3 = { version = "0.29", features = ["abi3", "abi3-py311"] }
Expand Down
16 changes: 16 additions & 0 deletions rust/crates/algo_bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "_scippneutron_algorithms_lib"
version = "0.0.0" # The version is set in pyproject.toml
edition.workspace = true
rust-version.workspace = true

[lib]
name = "_scippneutron_algorithms_lib"
crate-type = ["cdylib"]

[dependencies]
algo_impl = { path = "../algo_impl" }

ndarray = { workspace = true }
numpy = { workspace = true }
pyo3 = { workspace = true }
47 changes: 47 additions & 0 deletions rust/crates/algo_bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026 Scipp contributors (https://github.com/scipp)

use pyo3::prelude::*;

#[pymodule]
mod _scippneutron_algorithms_lib {
use numpy::{IntoPyArray, PyArray4, PyReadonlyArray1, PyReadonlyArray2};
use pyo3::prelude::*;

#[pyfunction]
#[pyo3(signature = (*, start, stop, solid_angle, grid, n_threads=None, block_size=None))]
fn compute_single_crystal_norm<'py>(
py: Python<'py>,
start: PyReadonlyArray2<'py, f64>,
stop: PyReadonlyArray2<'py, f64>,
solid_angle: PyReadonlyArray1<'py, f64>,
grid: (
PyReadonlyArray1<'py, f64>,
PyReadonlyArray1<'py, f64>,
PyReadonlyArray1<'py, f64>,
PyReadonlyArray1<'py, f64>,
),
n_threads: Option<usize>,
block_size: Option<usize>,
) -> Bound<'py, PyArray4<f64>> {
use algo_impl::normalization::single_crystal_norm::{
Grid, ThreadConfig, compute_single_crystal_norm,
};

let grid = Grid::new(
grid.0.as_array(),
grid.1.as_array(),
grid.2.as_array(),
grid.3.as_array(),
);

compute_single_crystal_norm(
start.as_array(),
stop.as_array(),
solid_angle.as_array(),
grid,
ThreadConfig::new(n_threads, block_size),
)
.into_pyarray(py)
}
}
8 changes: 8 additions & 0 deletions rust/crates/algo_impl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "algo_impl"
version = "0.0.0" # The version is set in pyproject.toml
edition.workspace = true
rust-version.workspace = true

[dependencies]
ndarray = { workspace = true }
4 changes: 4 additions & 0 deletions rust/crates/algo_impl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026 Scipp contributors (https://github.com/scipp)

pub mod normalization;
4 changes: 4 additions & 0 deletions rust/crates/algo_impl/src/normalization/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026 Scipp contributors (https://github.com/scipp)

pub mod single_crystal_norm;
Loading
Loading