Skip to main content

CscMatrix

Struct CscMatrix 

Source
pub struct CscMatrix { /* private fields */ }
Expand description

列圧縮形式(CSC: Compressed Sparse Column)の疎行列

非ゼロ要素を列単位で格納する疎行列フォーマット。 列ポインタ・行インデックス・値の3配列で表現される。

§フォーマット詳細

j の非ゼロ要素は values[col_ptr[j]..col_ptr[j+1]] に格納され、 対応する行インデックスは row_ind[col_ptr[j]..col_ptr[j+1]] に入る。 各列の行インデックスは昇順にソートされている。

Implementations§

Source§

impl CscMatrix

Source

pub fn new(nrows: usize, ncols: usize) -> Self

空の CSC 行列を生成する

すべての要素がゼロの (nrows × ncols) 行列として初期化される。

§引数
  • nrows: 行数
  • ncols: 列数
Source

pub fn nnz(&self) -> usize

非ゼロ要素の総数を返す

Source

pub fn col_ptr(&self) -> &[usize]

Returns the column pointer array (length ncols + 1).

Source

pub fn row_ind(&self) -> &[usize]

Returns the row index array for non-zero entries.

Source

pub fn values(&self) -> &[f64]

Returns the value array for non-zero entries.

Source

pub fn scale_values(&self, factor: f64) -> Self

Returns a new matrix with all non-zero values multiplied by factor.

Source

pub fn nrows(&self) -> usize

Returns the number of rows.

Source

pub fn ncols(&self) -> usize

Returns the number of columns.

Source

pub fn row_infinity_norms(&self) -> Vec<f64>

各行の∞ノルム(行ごとの最大絶対値)を一括計算する: O(nnz)

CSC格式では行方向アクセスが非効率だが、全非ゼロ要素を1回走査して 各行の最大絶対値を収集することで O(nnz) で完了する。

Source

pub fn from_triplets( rows: &[usize], cols: &[usize], vals: &[f64], nrows: usize, ncols: usize, ) -> Result<Self, SolverError>

COO(座標形式)のトリプレットから CSC 行列を構築する

同一 (row, col) への重複エントリは自動的に加算される。 ゼロ近傍の結果値(絶対値 DROP_TOL 以下)は格納しない。

§引数
  • rows: 各エントリの行インデックス
  • cols: 各エントリの列インデックス
  • vals: 各エントリの値
  • nrows: 行列の行数
  • ncols: 行列の列数
§エラー
  • rowscolsvals の長さが異なる場合
  • 行/列インデックスが範囲外の場合
Source

pub fn transpose(&self) -> Self

転置行列を生成する(新しい CSC 行列として返す)

元の行列の行と列を入れ替えた行列を返す。 counting sort を使用するため O(nnz) の計算量となる。

Source

pub fn mat_vec_mul(&self, x: &[f64]) -> Result<Vec<f64>, SolverError>

行列ベクトル積を計算する: y = A * x

CSC 形式の列走査を利用して O(nnz) で計算する。

§引数
  • x: 入力ベクトル(長さ: ncols)
§戻り値
  • Ok(y): 結果ベクトル(長さ: nrows)
  • Err: x の長さが ncols と一致しない場合
Source

pub fn get_column(&self, j: usize) -> Result<(&[usize], &[f64]), SolverError>

列 j の非ゼロ要素を取得する

行インデックス配列と値配列のスライスを返す。両スライスの長さは等しく、 行インデックスは昇順にソートされている。

§引数
  • j: 取得する列インデックス(0-based)
§戻り値
  • Ok((row_indices, values)): 列 j の行インデックスと値のスライスペア
  • Err: j が範囲外の場合
Source

pub fn identity(n: usize) -> Self

n×n 単位行列を CSC 形式で生成する

対角要素が 1.0 で、非対角要素がゼロの正方行列を返す。

§引数
  • n: 行列のサイズ(n×n)

Trait Implementations§

Source§

impl Clone for CscMatrix

Source§

fn clone(&self) -> CscMatrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CscMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,