Add PInv Moore-Penrose pseudoinverse
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start in numrs/src/linalg.rs at the proposed Pinv traits and the existing self.svd(true, true) call. Check how ndarray-linalg represents real and complex Scalar values and how matrix multiplication is supported across those types. Done means a generic Moore-Penrose pseudoinverse with optional rcond that avoids the reported multiplication error and matches the NumPy and MATLAB references.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I was porting some code from NumPy, and needed the pinv[1][2] function (Moore-Penrose pseudoinverse). I have started implementing it but have run into some issues making it generic over real and complex numbers.
pub trait Pinv {
type B;
type E;
type C;
fn pinv(&self, rcond: Option<Self::E>) -> Result<Self::B, Error>;
}
pub trait PInvVInto {
type B;
type E;
fn pinv(self, rcond: Option<Self::E>) -> Result<Self::B, Error>;
}
pub trait PInvInplace {
type B;
type E;
fn pinv(&mut self, rcond: Option<Self::E>) -> Result<Self::B, Error>;
}
impl<A, S> Pinv for ArrayBase<S, Ix2>
where
A: Scalar + Lapack + PartialOrd + Zero,
S: Data<Elem = A>,
{
type E = A::Real;
type B = Array2<A>;
type C = Array1<A::Real>;
fn pinv(&self, rconf: Option<Self::E>) -> Result<Self::B, Error> {
let result: (Option<Self::B>, Self::C, Option<Self::B>) =
self.svd(true, true).map_err(|_| Error::SvdFailed)?;
if let (Some(u), s, Some(vt)) = result {
// discard small singular values
let s: Self::C = if let Some(rconf) = rconf {
s.mapv(|v| if v > rconf { v } else { Zero::zero() })
} else {
s
};
let u = u.reversed_axes();
let s = s.insert_axis(Axis(1));
let x1 = s * u;
Ok(&vt.reversed_axes() * x1)
} else {
Err(Error::SvdFailed)
}
}
}
At the moment I am getting this error
error[E0277]: cannot multiply `ndarray::ArrayBase<OwnedRepr<<A as ndarray_linalg::Scalar>::Real>, Dim<[usize; 2]>>` by `ndarray::ArrayBase<OwnedRepr<A>, Dim<[usize; 2]>>`
--> numrs/src/linalg.rs:58:24
|
58 | let x1 = s * u;
| ^ no implementation for `ndarray::ArrayBase<OwnedRepr<<A as ndarray_linalg::Scalar>::Real>, Dim<[usize; 2]>> * ndarray::ArrayBase<OwnedRepr<A>, Dim<[usize; 2]>>`
|
= help: the trait `Mul<ndarray::ArrayBase<OwnedRepr<A>, Dim<[usize; 2]>>>` is not implemented for `ndarray::ArrayBase<OwnedRepr<<A as ndarray_linalg::Scalar>::Real>, Dim<[usize; 2]>>`
help: consider extending the `where` bound, but there might be an alternative better way to express this requirement
|
38 | S: Data<Elem = A>, ndarray::ArrayBase<OwnedRepr<<A as ndarray_linalg::Scalar>::Real>, Dim<[usize; 2]>>: Mul<ndarray::ArrayBase<OwnedRepr<A>, Dim<[usize; 2]>>>
My understanding this is because I am trying to multiple Scalar::Real with a Scalar, but I am not sure how this should be fixed.
- Lenguaje dominante
- Rust
- Estrellas
- 452
- Forks
- 95
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-ndarray/ndarray-linalg
-
Thin SVDAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
rust-ndarray/ndarray-linalg#414 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
rust-ndarray/ndarray-linalg#413 · 1 comentario ·
-
Cyclically Tridiagonal Matrices?Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
rust-ndarray/ndarray-linalg#404 ·
-
SIGSEGV on qr decompositionAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
rust-ndarray/ndarray-linalg#402 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
rust-ndarray/ndarray-linalg#401 · 2 reacciones ·
Todos los issues de rust-ndarray/ndarray-linalg
Issues similares
-
Fix large enum variantAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
software-challenge/player_rust#22 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
foundry-rs/foundry#17175 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
state:triage-needed
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
github/copilot-sdk#2793 ·
Los mantenedores suelen responder en 1 día