Skip to content

Commit

Permalink
Allow CSR and CSC matrices with no non-zero entries (#100)
Browse files Browse the repository at this point in the history
* allow CSR matrices with no non-zero entries

* allow CSC matrices with no non-zero entries

* correct borrowing

* clippy

* fmt and deps

* decrease version of pulp

* Updated to recent pulp

---------

Co-authored-by: Timo Betcke <[email protected]>
  • Loading branch information
mscroggs and tbetcke authored Dec 4, 2024
1 parent 9f36f8c commit 143f6ed
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 147 deletions.
18 changes: 7 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,34 @@ repository = "https://github.com/linalg-rs/rlst"
readme = "README.md"
keywords = ["numerics"]
categories = ["mathematics", "science"]
exclude = [
"suitesparse-src",
"netlib-lapack-src",
"blis-src",
]
exclude = ["suitesparse-src", "netlib-lapack-src", "blis-src"]

[lib]
name = "rlst"

[dependencies]
rlst-proc-macro = { path = "proc-macro", version = "0.2" }
num = { version = "0.4", features = ["serde", "rand"]}
num = { version = "0.4", features = ["serde", "rand"] }
rand = "0.8"
rand_chacha = "0.3"
rand_distr = "0.4"
itertools = "0.13"
blas = "0.22"
lapack = "0.19"
thiserror = "1"
thiserror = "2"
serde = "1"

coe-rs = "0.1.2"
pulp = { version = "0.18.12" }
pulp = { version = "0.20" }
bytemuck = "1.16.0"

mpi = { version="0.8.0", optional=true }
mpi-sys = { version="0.2.1", optional=true }
mpi = { version = "0.8.0", optional = true }
mpi-sys = { version = "0.2.1", optional = true }


[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
approx = { version = "0.5", features=["num-complex"] }
approx = { version = "0.5", features = ["num-complex"] }
paste = "1"
rand = "0.8"

Expand Down
3 changes: 1 addition & 2 deletions benches/exp.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use std::hint::black_box;

use criterion::{criterion_group, criterion_main, Criterion};
use paste;
use rand::prelude::*;
use rlst::prelude::*;

struct Impl<'a, T: RlstScalar<Real = T>> {
values: &'a [T],
}

impl<'a, T: RlstScalar<Real = T> + RlstSimd> pulp::WithSimd for Impl<'a, T> {
impl<T: RlstScalar<Real = T> + RlstSimd> pulp::WithSimd for Impl<'_, T> {
type Output = ();

fn with_simd<S: pulp::Simd>(self, simd: S) -> Self::Output {
Expand Down
1 change: 1 addition & 0 deletions benches/inverse_sqrt_f32.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Benchmark the inverse sqrt function
use std::hint::black_box;

#[cfg(target_arch = "x86_64")]
use bytemuck;
use criterion::{criterion_group, criterion_main, Criterion};

Expand Down
1 change: 1 addition & 0 deletions benches/inverse_sqrt_f64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Benchmark the inverse sqrt function
use std::hint::black_box;

#[cfg(target_arch = "x86_64")]
use bytemuck;
use criterion::{criterion_group, criterion_main, Criterion};

Expand Down
3 changes: 1 addition & 2 deletions benches/sin_cos.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use std::hint::black_box;

use criterion::{criterion_group, criterion_main, Criterion};
use paste;
use rand::prelude::*;
use rlst::prelude::*;

struct Impl<'a, T: RlstScalar<Real = T>> {
values: &'a [T],
}

impl<'a, T: RlstScalar<Real = T> + RlstSimd> pulp::WithSimd for Impl<'a, T> {
impl<T: RlstScalar<Real = T> + RlstSimd> pulp::WithSimd for Impl<'_, T> {
type Output = ();

fn with_simd<S: pulp::Simd>(self, simd: S) -> Self::Output {
Expand Down
13 changes: 9 additions & 4 deletions src/dense/array/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item> + Shape<NDIM>,
const NDIM: usize,
> std::iter::Iterator for ArrayDefaultIterator<'a, Item, ArrayImpl, NDIM>
> std::iter::Iterator for ArrayDefaultIterator<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;
fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -156,7 +155,10 @@ impl<
> crate::dense::traits::DefaultIterator for Array<Item, ArrayImpl, NDIM>
{
type Item = Item;
type Iter<'a> = ArrayDefaultIterator<'a, Item, ArrayImpl, NDIM> where Self: 'a;
type Iter<'a>
= ArrayDefaultIterator<'a, Item, ArrayImpl, NDIM>
where
Self: 'a;

fn iter(&self) -> Self::Iter<'_> {
ArrayDefaultIterator::new(self)
Expand All @@ -172,7 +174,10 @@ impl<
> crate::dense::traits::DefaultIteratorMut for Array<Item, ArrayImpl, NDIM>
{
type Item = Item;
type IterMut<'a> = ArrayDefaultIteratorMut<'a, Item, ArrayImpl, NDIM> where Self: 'a;
type IterMut<'a>
= ArrayDefaultIteratorMut<'a, Item, ArrayImpl, NDIM>
where
Self: 'a;

fn iter_mut(&mut self) -> Self::IterMut<'_> {
ArrayDefaultIteratorMut::new(self)
Expand Down
2 changes: 1 addition & 1 deletion src/dense/array/mult_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<
}
}

/// MultIntoResize
// MultIntoResize

impl<
Item: RlstScalar + Gemm,
Expand Down
36 changes: 12 additions & 24 deletions src/dense/array/views/flattened.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,21 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item> + Shape<NDIM>,
const NDIM: usize,
> Shape<1> for ArrayFlatView<'a, Item, ArrayImpl, NDIM>
> Shape<1> for ArrayFlatView<'_, Item, ArrayImpl, NDIM>
{
fn shape(&self) -> [usize; 1] {
[self.arr.shape().iter().product()]
}
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item> + Shape<NDIM>,
const NDIM: usize,
> UnsafeRandomAccessByValue<1> for ArrayFlatView<'a, Item, ArrayImpl, NDIM>
> UnsafeRandomAccessByValue<1> for ArrayFlatView<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;

Expand All @@ -63,13 +61,12 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item>
+ Shape<NDIM>
+ UnsafeRandomAccessByRef<NDIM, Item = Item>,
const NDIM: usize,
> UnsafeRandomAccessByRef<1> for ArrayFlatView<'a, Item, ArrayImpl, NDIM>
> UnsafeRandomAccessByRef<1> for ArrayFlatView<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;

Expand All @@ -80,11 +77,10 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item> + Shape<NDIM> + RawAccess<Item = Item>,
const NDIM: usize,
> RawAccess for ArrayFlatView<'a, Item, ArrayImpl, NDIM>
> RawAccess for ArrayFlatView<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;

Expand All @@ -102,12 +98,11 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item> + Shape<NDIM> + ChunkedAccess<N, Item = Item>,
const NDIM: usize,
const N: usize,
> ChunkedAccess<N> for ArrayFlatView<'a, Item, ArrayImpl, NDIM>
> ChunkedAccess<N> for ArrayFlatView<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;

Expand Down Expand Up @@ -148,27 +143,25 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item>
+ Shape<NDIM>
+ UnsafeRandomAccessMut<NDIM, Item = Item>,
const NDIM: usize,
> Shape<1> for ArrayFlatViewMut<'a, Item, ArrayImpl, NDIM>
> Shape<1> for ArrayFlatViewMut<'_, Item, ArrayImpl, NDIM>
{
fn shape(&self) -> [usize; 1] {
[self.arr.shape().iter().product()]
}
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item>
+ Shape<NDIM>
+ UnsafeRandomAccessMut<NDIM, Item = Item>,
const NDIM: usize,
> UnsafeRandomAccessByValue<1> for ArrayFlatViewMut<'a, Item, ArrayImpl, NDIM>
> UnsafeRandomAccessByValue<1> for ArrayFlatViewMut<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;

Expand All @@ -179,13 +172,12 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item>
+ Shape<NDIM>
+ UnsafeRandomAccessMut<NDIM, Item = Item>,
const NDIM: usize,
> UnsafeRandomAccessMut<1> for ArrayFlatViewMut<'a, Item, ArrayImpl, NDIM>
> UnsafeRandomAccessMut<1> for ArrayFlatViewMut<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;

Expand All @@ -196,14 +188,13 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item>
+ Shape<NDIM>
+ UnsafeRandomAccessMut<NDIM, Item = Item>
+ UnsafeRandomAccessByRef<NDIM, Item = Item>,
const NDIM: usize,
> UnsafeRandomAccessByRef<1> for ArrayFlatViewMut<'a, Item, ArrayImpl, NDIM>
> UnsafeRandomAccessByRef<1> for ArrayFlatViewMut<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;

Expand All @@ -214,14 +205,13 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item>
+ Shape<NDIM>
+ UnsafeRandomAccessMut<NDIM, Item = Item>
+ RawAccess<Item = Item>,
const NDIM: usize,
> RawAccess for ArrayFlatViewMut<'a, Item, ArrayImpl, NDIM>
> RawAccess for ArrayFlatViewMut<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;

Expand All @@ -239,14 +229,13 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item>
+ Shape<NDIM>
+ UnsafeRandomAccessMut<NDIM, Item = Item>
+ RawAccessMut<Item = Item>,
const NDIM: usize,
> RawAccessMut for ArrayFlatViewMut<'a, Item, ArrayImpl, NDIM>
> RawAccessMut for ArrayFlatViewMut<'_, Item, ArrayImpl, NDIM>
{
fn data_mut(&mut self) -> &mut [Self::Item] {
self.arr.data_mut()
Expand All @@ -258,15 +247,14 @@ impl<
}

impl<
'a,
Item: RlstBase,
ArrayImpl: UnsafeRandomAccessByValue<NDIM, Item = Item>
+ Shape<NDIM>
+ UnsafeRandomAccessMut<NDIM, Item = Item>
+ ChunkedAccess<N, Item = Item>,
const NDIM: usize,
const N: usize,
> ChunkedAccess<N> for ArrayFlatViewMut<'a, Item, ArrayImpl, NDIM>
> ChunkedAccess<N> for ArrayFlatViewMut<'_, Item, ArrayImpl, NDIM>
{
type Item = Item;

Expand Down
Loading

0 comments on commit 143f6ed

Please sign in to comment.