Add PInv Moore-Penrose pseudoinverse
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Rust
- スター
- 452
- フォーク
- 95
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-ndarray/ndarray-linalg のほかの issue
-
Thin SVD オープン
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
rust-ndarray/ndarray-linalg#414 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
rust-ndarray/ndarray-linalg#413 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
rust-ndarray/ndarray-linalg#404 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
rust-ndarray/ndarray-linalg#402 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
rust-ndarray/ndarray-linalg#401 · リアクション 2 件 ·
rust-ndarray/ndarray-linalg の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
bug good first issue package: quic
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
-
`dora trace view` sends a non-canonical full UUID as-is, so a valid trace ID shows "No spans found" オープンcli coordinator rust
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
area: tasks enhancement good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
Jason-jo17/Polybench#15 · コメント 1 件 ·