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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "lenskit"
version = "2026.3.0-beta1"
edition = "2024"
license = "MIT"
rust-version = "1.87"
rust-version = "1.89"

[lib]
name = "lenskit_accel"
Expand Down
1 change: 1 addition & 0 deletions hk.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local linters = new Mapping<String, Step> {
["trailing-whitespace"] = Builtins.trailing_whitespace
// ["check-merge-conflict"] = Builtins.check_merge_conflict
["check-toml"] = Builtins.taplo
["clippy"] = Builtins.cargo_clippy
["ruff"] = Builtins.ruff
}

Expand Down
38 changes: 19 additions & 19 deletions mise/mise.lock

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

2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "cargo", "rustc", "llvm-tools"]
components = ["rustfmt", "cargo", "rustc", "llvm-tools", "clippy"]
5 changes: 2 additions & 3 deletions src/accel/als/explicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use ndarray::{Array1, ArrayBase, ArrayView2, Axis, ViewRepr};
use numpy::{Ix1, PyArray2, PyArrayMethods};
use pyo3::{IntoPyObjectExt, exceptions::PyRuntimeError, prelude::*};
use rayon::prelude::*;
use thiserror::Error;

use rayon_cancel::CancelAdapter;

Expand Down Expand Up @@ -89,13 +88,13 @@ fn train_row_solve(
let cols = matrix.row_cols(row_num);
let vals = matrix.row_vals(row_num);

if cols.len() == 0 {
if cols.is_empty() {
row_data.fill(0.0);
return Ok(0.0);
}

let cols: Vec<_> = cols.iter().map(|c| *c as usize).collect();
let vals: Array1<_> = vals.iter().map(|f| *f).collect();
let vals: Array1<_> = vals.iter().copied().collect();

let nd = row_data.len();

Expand Down
4 changes: 2 additions & 2 deletions src/accel/als/implicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ fn train_row_solve(
let cols = matrix.row_cols(row_num);
let vals = matrix.row_vals(row_num);

if cols.len() == 0 {
if cols.is_empty() {
row_data.fill(0.0);
return Ok(0.0);
}

let cols: Vec<_> = cols.iter().map(|c| *c as usize).collect();
let mut vals: Array1<_> = vals.iter().map(|f| *f).collect();
let mut vals: Array1<_> = vals.iter().copied().collect();

let nd = row_data.len();

Expand Down
7 changes: 4 additions & 3 deletions src/accel/als/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub enum SolveError {

/// Wrapper for LAPACK solver functions.
#[derive(Clone, Copy)]
#[allow(clippy::upper_case_acronyms)]
pub struct POSV {
lapack_fn: LapackSPOSV,
}
Expand Down Expand Up @@ -105,8 +106,8 @@ impl POSV {
}
}

impl Into<PyErr> for SolveError {
fn into(self) -> PyErr {
PyRuntimeError::new_err(format!("LAPACK error: {}", self))
impl From<SolveError> for PyErr {
fn from(val: SolveError) -> Self {
PyRuntimeError::new_err(format!("LAPACK error: {}", val))
}
}
2 changes: 1 addition & 1 deletion src/accel/arrow/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ impl ExtractListArray for LargeListArray {

impl ExtractListArray for ListArray {
fn extract_list_array(array: &dyn Array) -> Option<Self> {
array.as_any().downcast_ref::<Self>().map(Clone::clone)
array.as_any().downcast_ref::<Self>().cloned()
}
}
4 changes: 2 additions & 2 deletions src/accel/arrow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub fn checked_array_ref<'array, T: Array + 'static>(
)
}

pub fn checked_array<'array, E: ArrowPrimitiveType + 'static>(
pub fn checked_array<E: ArrowPrimitiveType + 'static>(
name: &str,
array: &'array dyn Array,
array: &dyn Array,
) -> PyResult<PrimitiveArray<E>> {
if array.data_type().equals_datatype(&E::DATA_TYPE) {
Ok(downcast_array(array))
Expand Down
2 changes: 1 addition & 1 deletion src/accel/arrow/types/index_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl TryFrom<&DataType> for SparseIndexListType {
type Error = ArrowError;

fn try_from(value: &DataType) -> Result<Self, Self::Error> {
Self::try_new(&value, ())
Self::try_new(value, ())
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/accel/arrow/types/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl TryFrom<&DataType> for SparseRowType {
type Error = ArrowError;

fn try_from(value: &DataType) -> Result<Self, Self::Error> {
Self::try_new(&value, ())
Self::try_new(value, ())
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ impl ExtensionType for SparseRowType {
)));
}

let idx_f = fields.get(0).unwrap();
let idx_f = fields.first().unwrap();
let idx_name = idx_f.name();
let idx_t: SparseIndexType = idx_f.try_extension_type()?;

Expand Down
16 changes: 6 additions & 10 deletions src/accel/data/cooc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,9 @@ fn count_cooc_parallel<PC: ConcurrentPairCounter>(
let n = items.len();

for i in 0..n {
let ri = items[i as usize];
for j in i..n {
let ci = items[j as usize];
counts.crecord(ri, ci);
let ri = items[i];
for ci in &items[i..n] {
counts.crecord(ri, *ci);
}
}
cancel.advance(items.len());
Expand Down Expand Up @@ -239,12 +238,9 @@ fn compute_group_pointers(n_groups: usize, gvals: &[i32]) -> PyResult<Vec<usize>
fn count_items<PC: PairCounter>(counts: &mut PC, items: &[i32]) {
let n = items.len();
for i in 0..n {
let ri = items[i as usize];
for j in (i + 1)..n {
if i != j {
let ci = items[j as usize];
counts.record(ri, ci);
}
let ri = items[i];
for ci in &items[(i + 1)..n] {
counts.record(ri, *ci);
}
}
}
2 changes: 1 addition & 1 deletion src/accel/data/coordinates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl ChunkIndex {

fn hash_entry(chunks: &[Vec<Int32Array>], ix: &ChunkIndex) -> u64 {
let chunk = &chunks[ix.chunk_index()];
hash_chunk_entry(&chunk, ix.item)
hash_chunk_entry(chunk, ix.item)
}

fn hash_chunk_entry(chunk: &[Int32Array], ri: u32) -> u64 {
Expand Down
2 changes: 1 addition & 1 deletion src/accel/data/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl IDIndex {
fn from_data(data: PyArrowType<ArrayData>) -> PyResult<Self> {
let ids = make_array(data.0);
let index: Box<dyn PositionLookup + Sync + Send> = match ids.data_type() {
DataType::Null if ids.len() == 0 => return Ok(Self::empty()),
DataType::Null if ids.is_empty() => return Ok(Self::empty()),
DataType::Int16 => prim_tbl::<Int16Type>(&ids)?,
DataType::UInt16 => prim_tbl::<UInt16Type>(&ids)?,
DataType::Int32 => prim_tbl::<Int32Type>(&ids)?,
Expand Down
2 changes: 1 addition & 1 deletion src/accel/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ fn hash_array(arr: PyArrowType<ArrayData>) -> PyResult<String> {
start += bsize;
}

Ok(hex::encode(&hash.finalize()))
Ok(hex::encode(hash.finalize()))
}
8 changes: 4 additions & 4 deletions src/accel/data/pairs/dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct DensePairCounter {
}

impl DensePairCounter {
#[allow(clippy::missing_transmute_annotations)]
pub fn with_diagonal(n: usize, diagonal: bool) -> Self {
DensePairCounter {
n_items: n,
Expand Down Expand Up @@ -67,10 +68,9 @@ impl PairCounter for DensePairCounter {
let data: Vec<f32> = unsafe { transmute(data) };

let arr = Array1::from_vec(data);
let mat = arr
.into_shape_with_order((self.n_items, self.n_items))
.expect("array reshape failed");
mat

arr.into_shape_with_order((self.n_items, self.n_items))
.expect("array reshape failed")
}
}

Expand Down
1 change: 1 addition & 0 deletions src/accel/data/pairs/symmetric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct SymmetricPairCounter {
}

impl SymmetricPairCounter {
#[allow(clippy::missing_transmute_annotations)]
pub fn with_diagonal(n: usize, diagonal: bool) -> Self {
let cap = arith_tot(n);
SymmetricPairCounter {
Expand Down
1 change: 1 addition & 0 deletions src/accel/data/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::data::CoordinateTable;
/// Sample negative columns for given rows from a coordinate table.
#[pyfunction]
#[pyo3(signature=(coords, rows, n_cols, *, n=1, max_attempts=10, pop_weighted=false, seed))]
#[allow(clippy::too_many_arguments)]
pub fn sample_negatives<'py>(
py: Python<'py>,
coords: &CoordinateTable,
Expand Down
4 changes: 2 additions & 2 deletions src/accel/data/scatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ fn scatter_empty_stype<T: ArrowPrimitiveType>(
}

fn scatter_impl<Ix, T>(
dst: &mut Vec<T::Native>,
dst_valid: &mut Vec<bool>,
dst: &mut [T::Native],
dst_valid: &mut [bool],
idx: &PrimitiveArray<Ix>,
src: &PrimitiveArray<T>,
) where
Expand Down
18 changes: 9 additions & 9 deletions src/accel/data/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ pub(super) fn is_sorted_coo<'py>(
let v1 = col1.value(i);
let v2 = col2.value(i);
let k = (v1, v2);
if let Some(lk) = last {
if k <= lk {
// found a key out-of-order, we're done
return Ok(false);
}
if let Some(lk) = last
&& k <= lk
{
// found a key out-of-order, we're done
return Ok(false);
}
last = Some(k);
}
Expand Down Expand Up @@ -90,10 +90,10 @@ where

let mut indices = Vec::with_capacity(scores.len());
for (i, v) in scores.iter().enumerate() {
if let Some(v) = v {
if !v.is_nan() {
indices.push(i as i32);
}
if let Some(v) = v
&& !v.is_nan()
{
indices.push(i as i32);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/accel/data/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::sparse::{CSR, CSRStructure, IxVar, csr_structure};

/// Transpose the structure of a CSR matrix.
#[pyfunction]
#[allow(clippy::type_complexity)]
pub fn transpose_csr(
arr: PyArrowType<ArrayData>,
permute: bool,
Expand Down Expand Up @@ -55,8 +56,7 @@ where
let nnz = csr.nnz();
let mut row_ptrs = Vec::with_capacity(csr.n_cols + 1);
row_ptrs.resize(csr.n_cols + 1, It::Native::from(0));
let mut col_inds = Vec::with_capacity(nnz);
col_inds.resize(nnz, 0);
let mut col_inds = vec![0; nnz];
let mut permutation = if permute {
let mut p = Vec::with_capacity(nnz);
p.resize(nnz, It::Native::from(0));
Expand Down
2 changes: 1 addition & 1 deletion src/accel/indirect/hashing/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<C: IndirectHashContent> PositionLookup for IndirectHashTable<C> {
let res = self
.table
.find(hash, |jr| search.compare_with_entry(0, *jr));
Ok(res.map(|ir| *ir))
Ok(res.copied())
}

fn lookup_array<'py>(&self, py: Python<'py>, val: Bound<'py, PyAny>) -> PyResult<Int32Array> {
Expand Down
Loading
Loading