forked from M-Labs/nalgebra
Update slice->view in nalgebra-sparse
This commit is contained in:
parent
660ee9c6f2
commit
02caca0ece
@ -3,7 +3,7 @@ use crate::ops::serial::spsolve_csc_lower_triangular;
|
|||||||
use crate::ops::Op;
|
use crate::ops::Op;
|
||||||
use crate::pattern::SparsityPattern;
|
use crate::pattern::SparsityPattern;
|
||||||
use core::{iter, mem};
|
use core::{iter, mem};
|
||||||
use nalgebra::{DMatrix, DMatrixSlice, DMatrixSliceMut, RealField};
|
use nalgebra::{DMatrix, DMatrixView, DMatrixViewMut, RealField};
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
/// A symbolic sparse Cholesky factorization of a CSC matrix.
|
/// A symbolic sparse Cholesky factorization of a CSC matrix.
|
||||||
@ -264,7 +264,7 @@ impl<T: RealField> CscCholesky<T> {
|
|||||||
///
|
///
|
||||||
/// Panics if `B` is not square.
|
/// Panics if `B` is not square.
|
||||||
#[must_use = "Did you mean to use solve_mut()?"]
|
#[must_use = "Did you mean to use solve_mut()?"]
|
||||||
pub fn solve<'a>(&'a self, b: impl Into<DMatrixSlice<'a, T>>) -> DMatrix<T> {
|
pub fn solve<'a>(&'a self, b: impl Into<DMatrixView<'a, T>>) -> DMatrix<T> {
|
||||||
let b = b.into();
|
let b = b.into();
|
||||||
let mut output = b.clone_owned();
|
let mut output = b.clone_owned();
|
||||||
self.solve_mut(&mut output);
|
self.solve_mut(&mut output);
|
||||||
@ -278,7 +278,7 @@ impl<T: RealField> CscCholesky<T> {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if `b` is not square.
|
/// Panics if `b` is not square.
|
||||||
pub fn solve_mut<'a>(&'a self, b: impl Into<DMatrixSliceMut<'a, T>>) {
|
pub fn solve_mut<'a>(&'a self, b: impl Into<DMatrixViewMut<'a, T>>) {
|
||||||
let expect_msg = "If the Cholesky factorization succeeded,\
|
let expect_msg = "If the Cholesky factorization succeeded,\
|
||||||
then the triangular solve should never fail";
|
then the triangular solve should never fail";
|
||||||
// Solve LY = B
|
// Solve LY = B
|
||||||
|
@ -2,7 +2,7 @@ use crate::cs::CsMatrix;
|
|||||||
use crate::ops::serial::{OperationError, OperationErrorKind};
|
use crate::ops::serial::{OperationError, OperationErrorKind};
|
||||||
use crate::ops::Op;
|
use crate::ops::Op;
|
||||||
use crate::SparseEntryMut;
|
use crate::SparseEntryMut;
|
||||||
use nalgebra::{ClosedAdd, ClosedMul, DMatrixSlice, DMatrixSliceMut, Scalar};
|
use nalgebra::{ClosedAdd, ClosedMul, DMatrixView, DMatrixViewMut, Scalar};
|
||||||
use num_traits::{One, Zero};
|
use num_traits::{One, Zero};
|
||||||
|
|
||||||
fn spmm_cs_unexpected_entry() -> OperationError {
|
fn spmm_cs_unexpected_entry() -> OperationError {
|
||||||
@ -176,10 +176,10 @@ where
|
|||||||
/// the transposed operation must be specified for the CSC matrix.
|
/// the transposed operation must be specified for the CSC matrix.
|
||||||
pub fn spmm_cs_dense<T>(
|
pub fn spmm_cs_dense<T>(
|
||||||
beta: T,
|
beta: T,
|
||||||
mut c: DMatrixSliceMut<'_, T>,
|
mut c: DMatrixViewMut<'_, T>,
|
||||||
alpha: T,
|
alpha: T,
|
||||||
a: Op<&CsMatrix<T>>,
|
a: Op<&CsMatrix<T>>,
|
||||||
b: Op<DMatrixSlice<'_, T>>,
|
b: Op<DMatrixView<'_, T>>,
|
||||||
) where
|
) where
|
||||||
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ use crate::ops::serial::cs::{
|
|||||||
};
|
};
|
||||||
use crate::ops::serial::{OperationError, OperationErrorKind};
|
use crate::ops::serial::{OperationError, OperationErrorKind};
|
||||||
use crate::ops::Op;
|
use crate::ops::Op;
|
||||||
use nalgebra::{ClosedAdd, ClosedMul, DMatrixSlice, DMatrixSliceMut, RealField, Scalar};
|
use nalgebra::{ClosedAdd, ClosedMul, DMatrixView, DMatrixViewMut, RealField, Scalar};
|
||||||
use num_traits::{One, Zero};
|
use num_traits::{One, Zero};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
@ -16,10 +16,10 @@ use std::borrow::Cow;
|
|||||||
/// Panics if the dimensions of the matrices involved are not compatible with the expression.
|
/// Panics if the dimensions of the matrices involved are not compatible with the expression.
|
||||||
pub fn spmm_csc_dense<'a, T>(
|
pub fn spmm_csc_dense<'a, T>(
|
||||||
beta: T,
|
beta: T,
|
||||||
c: impl Into<DMatrixSliceMut<'a, T>>,
|
c: impl Into<DMatrixViewMut<'a, T>>,
|
||||||
alpha: T,
|
alpha: T,
|
||||||
a: Op<&CscMatrix<T>>,
|
a: Op<&CscMatrix<T>>,
|
||||||
b: Op<impl Into<DMatrixSlice<'a, T>>>,
|
b: Op<impl Into<DMatrixView<'a, T>>>,
|
||||||
) where
|
) where
|
||||||
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
||||||
{
|
{
|
||||||
@ -29,10 +29,10 @@ pub fn spmm_csc_dense<'a, T>(
|
|||||||
|
|
||||||
fn spmm_csc_dense_<T>(
|
fn spmm_csc_dense_<T>(
|
||||||
beta: T,
|
beta: T,
|
||||||
c: DMatrixSliceMut<'_, T>,
|
c: DMatrixViewMut<'_, T>,
|
||||||
alpha: T,
|
alpha: T,
|
||||||
a: Op<&CscMatrix<T>>,
|
a: Op<&CscMatrix<T>>,
|
||||||
b: Op<DMatrixSlice<'_, T>>,
|
b: Op<DMatrixView<'_, T>>,
|
||||||
) where
|
) where
|
||||||
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
||||||
{
|
{
|
||||||
@ -173,7 +173,7 @@ where
|
|||||||
/// Panics if `L` is not square, or if `L` and `B` are not dimensionally compatible.
|
/// Panics if `L` is not square, or if `L` and `B` are not dimensionally compatible.
|
||||||
pub fn spsolve_csc_lower_triangular<'a, T: RealField>(
|
pub fn spsolve_csc_lower_triangular<'a, T: RealField>(
|
||||||
l: Op<&CscMatrix<T>>,
|
l: Op<&CscMatrix<T>>,
|
||||||
b: impl Into<DMatrixSliceMut<'a, T>>,
|
b: impl Into<DMatrixViewMut<'a, T>>,
|
||||||
) -> Result<(), OperationError> {
|
) -> Result<(), OperationError> {
|
||||||
let b = b.into();
|
let b = b.into();
|
||||||
let l_matrix = l.into_inner();
|
let l_matrix = l.into_inner();
|
||||||
@ -195,7 +195,7 @@ pub fn spsolve_csc_lower_triangular<'a, T: RealField>(
|
|||||||
|
|
||||||
fn spsolve_csc_lower_triangular_no_transpose<T: RealField>(
|
fn spsolve_csc_lower_triangular_no_transpose<T: RealField>(
|
||||||
l: &CscMatrix<T>,
|
l: &CscMatrix<T>,
|
||||||
b: DMatrixSliceMut<'_, T>,
|
b: DMatrixViewMut<'_, T>,
|
||||||
) -> Result<(), OperationError> {
|
) -> Result<(), OperationError> {
|
||||||
let mut x = b;
|
let mut x = b;
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ fn spsolve_encountered_zero_diagonal() -> Result<(), OperationError> {
|
|||||||
|
|
||||||
fn spsolve_csc_lower_triangular_transpose<T: RealField>(
|
fn spsolve_csc_lower_triangular_transpose<T: RealField>(
|
||||||
l: &CscMatrix<T>,
|
l: &CscMatrix<T>,
|
||||||
b: DMatrixSliceMut<'_, T>,
|
b: DMatrixViewMut<'_, T>,
|
||||||
) -> Result<(), OperationError> {
|
) -> Result<(), OperationError> {
|
||||||
let mut x = b;
|
let mut x = b;
|
||||||
|
|
||||||
|
@ -4,17 +4,17 @@ use crate::ops::serial::cs::{
|
|||||||
};
|
};
|
||||||
use crate::ops::serial::OperationError;
|
use crate::ops::serial::OperationError;
|
||||||
use crate::ops::Op;
|
use crate::ops::Op;
|
||||||
use nalgebra::{ClosedAdd, ClosedMul, DMatrixSlice, DMatrixSliceMut, Scalar};
|
use nalgebra::{ClosedAdd, ClosedMul, DMatrixView, DMatrixViewMut, Scalar};
|
||||||
use num_traits::{One, Zero};
|
use num_traits::{One, Zero};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
/// Sparse-dense matrix-matrix multiplication `C <- beta * C + alpha * op(A) * op(B)`.
|
/// Sparse-dense matrix-matrix multiplication `C <- beta * C + alpha * op(A) * op(B)`.
|
||||||
pub fn spmm_csr_dense<'a, T>(
|
pub fn spmm_csr_dense<'a, T>(
|
||||||
beta: T,
|
beta: T,
|
||||||
c: impl Into<DMatrixSliceMut<'a, T>>,
|
c: impl Into<DMatrixViewMut<'a, T>>,
|
||||||
alpha: T,
|
alpha: T,
|
||||||
a: Op<&CsrMatrix<T>>,
|
a: Op<&CsrMatrix<T>>,
|
||||||
b: Op<impl Into<DMatrixSlice<'a, T>>>,
|
b: Op<impl Into<DMatrixView<'a, T>>>,
|
||||||
) where
|
) where
|
||||||
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
||||||
{
|
{
|
||||||
@ -24,10 +24,10 @@ pub fn spmm_csr_dense<'a, T>(
|
|||||||
|
|
||||||
fn spmm_csr_dense_<T>(
|
fn spmm_csr_dense_<T>(
|
||||||
beta: T,
|
beta: T,
|
||||||
c: DMatrixSliceMut<'_, T>,
|
c: DMatrixViewMut<'_, T>,
|
||||||
alpha: T,
|
alpha: T,
|
||||||
a: Op<&CsrMatrix<T>>,
|
a: Op<&CsrMatrix<T>>,
|
||||||
b: Op<DMatrixSlice<'_, T>>,
|
b: Op<DMatrixView<'_, T>>,
|
||||||
) where
|
) where
|
||||||
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
T: Scalar + ClosedAdd + ClosedMul + Zero + One,
|
||||||
{
|
{
|
||||||
|
@ -348,8 +348,8 @@ fn coo_push_matrix_valid_entries() {
|
|||||||
// Works with sliced
|
// Works with sliced
|
||||||
{
|
{
|
||||||
let source = nalgebra::SMatrix::<i32, 2, 2>::new(6, 7, 8, 9);
|
let source = nalgebra::SMatrix::<i32, 2, 2>::new(6, 7, 8, 9);
|
||||||
let sliced = source.fixed_slice::<2, 1>(0, 0);
|
let view = source.fixed_view::<2, 1>(0, 0);
|
||||||
coo.push_matrix(1, 0, &sliced);
|
coo.push_matrix(1, 0, &view);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
coo.triplet_iter().collect::<Vec<_>>(),
|
coo.triplet_iter().collect::<Vec<_>>(),
|
||||||
|
@ -14,7 +14,7 @@ use nalgebra_sparse::pattern::SparsityPattern;
|
|||||||
use nalgebra_sparse::proptest::{csc, csr, sparsity_pattern};
|
use nalgebra_sparse::proptest::{csc, csr, sparsity_pattern};
|
||||||
|
|
||||||
use nalgebra::proptest::{matrix, vector};
|
use nalgebra::proptest::{matrix, vector};
|
||||||
use nalgebra::{DMatrix, DMatrixSlice, DMatrixSliceMut, Scalar};
|
use nalgebra::{DMatrix, DMatrixView, DMatrixViewMut, Scalar};
|
||||||
|
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
@ -333,10 +333,10 @@ fn csc_square_with_non_zero_diagonals() -> impl Strategy<Value = CscMatrix<f64>>
|
|||||||
/// Helper function to help us call dense GEMM with our `Op` type
|
/// Helper function to help us call dense GEMM with our `Op` type
|
||||||
fn dense_gemm<'a>(
|
fn dense_gemm<'a>(
|
||||||
beta: i32,
|
beta: i32,
|
||||||
c: impl Into<DMatrixSliceMut<'a, i32>>,
|
c: impl Into<DMatrixViewMut<'a, i32>>,
|
||||||
alpha: i32,
|
alpha: i32,
|
||||||
a: Op<impl Into<DMatrixSlice<'a, i32>>>,
|
a: Op<impl Into<DMatrixView<'a, i32>>>,
|
||||||
b: Op<impl Into<DMatrixSlice<'a, i32>>>,
|
b: Op<impl Into<DMatrixView<'a, i32>>>,
|
||||||
) {
|
) {
|
||||||
let mut c = c.into();
|
let mut c = c.into();
|
||||||
let a = a.convert();
|
let a = a.convert();
|
||||||
|
Loading…
Reference in New Issue
Block a user