use arrow_array::FixedSizeListArray;
use arrow_array::types::{Float32Type, Float64Type};
use super::{
ArrowInteropError, complex64_matrix_from_owned, complex64_matrix_view,
fixed_size_list_from_owned, fixed_size_list_view,
};
pub fn decompose_f32(
matrix: &FixedSizeListArray,
) -> Result<crate::linalg::svd::NdarraySVD<f32>, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float32Type>(matrix)?;
Ok(crate::linalg::svd::decompose_view(&matrix_view)?)
}
pub fn decompose_f64(
matrix: &FixedSizeListArray,
) -> Result<crate::linalg::svd::NdarraySVD<f64>, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float64Type>(matrix)?;
Ok(crate::linalg::svd::decompose_view(&matrix_view)?)
}
pub fn decompose_truncated_f32(
matrix: &FixedSizeListArray,
k: usize,
) -> Result<crate::linalg::svd::NdarraySVD<f32>, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float32Type>(matrix)?;
Ok(crate::linalg::svd::decompose_truncated_view(&matrix_view, k)?)
}
pub fn decompose_truncated_f64(
matrix: &FixedSizeListArray,
k: usize,
) -> Result<crate::linalg::svd::NdarraySVD<f64>, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float64Type>(matrix)?;
Ok(crate::linalg::svd::decompose_truncated_view(&matrix_view, k)?)
}
pub fn decompose_with_tolerance_f32(
matrix: &FixedSizeListArray,
tolerance: f32,
) -> Result<crate::linalg::svd::NdarraySVD<f32>, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float32Type>(matrix)?;
Ok(crate::linalg::svd::decompose_with_tolerance_view(&matrix_view, tolerance)?)
}
pub fn decompose_with_tolerance_f64(
matrix: &FixedSizeListArray,
tolerance: f64,
) -> Result<crate::linalg::svd::NdarraySVD<f64>, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float64Type>(matrix)?;
Ok(crate::linalg::svd::decompose_with_tolerance_view(&matrix_view, tolerance)?)
}
pub fn pseudo_inverse_f32(
matrix: &FixedSizeListArray,
config: crate::linalg::svd::PseudoInverseConfig<f32>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float32Type>(matrix)?;
let output = crate::linalg::svd::pseudo_inverse_view(&matrix_view, &config)?;
fixed_size_list_from_owned::<Float32Type>(output)
}
pub fn pseudo_inverse_f64(
matrix: &FixedSizeListArray,
config: crate::linalg::svd::PseudoInverseConfig<f64>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float64Type>(matrix)?;
let output = crate::linalg::svd::pseudo_inverse_view(&matrix_view, &config)?;
fixed_size_list_from_owned::<Float64Type>(output)
}
pub fn null_space_f32(
matrix: &FixedSizeListArray,
tolerance: Option<f32>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float32Type>(matrix)?;
let output = crate::linalg::svd::null_space_view(&matrix_view, tolerance)?;
fixed_size_list_from_owned::<Float32Type>(output)
}
pub fn null_space_f64(
matrix: &FixedSizeListArray,
tolerance: Option<f64>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float64Type>(matrix)?;
let output = crate::linalg::svd::null_space_view(&matrix_view, tolerance)?;
fixed_size_list_from_owned::<Float64Type>(output)
}
pub fn decompose_complex(
matrix: &FixedSizeListArray,
) -> Result<crate::linalg::svd::NdarrayComplexSVD, ArrowInteropError> {
let matrix_view = complex64_matrix_view(matrix)?;
Ok(crate::linalg::svd::decompose_complex_view(&matrix_view)?)
}
pub fn reconstruct_f32(
svd: &crate::linalg::svd::NdarraySVD<f32>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
fixed_size_list_from_owned::<Float32Type>(crate::linalg::svd::reconstruct_matrix(svd))
}
pub fn reconstruct_f64(
svd: &crate::linalg::svd::NdarraySVD<f64>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
fixed_size_list_from_owned::<Float64Type>(crate::linalg::svd::reconstruct_matrix(svd))
}
pub fn reconstruct_complex(
svd: &crate::linalg::svd::NdarrayComplexSVD,
) -> Result<FixedSizeListArray, ArrowInteropError> {
complex64_matrix_from_owned(crate::linalg::svd::reconstruct_matrix_complex(svd))
}
pub fn condition_number<T: nabled_core::scalar::NabledReal>(
svd: &crate::linalg::svd::NdarraySVD<T>,
) -> T {
crate::linalg::svd::condition_number(svd)
}
pub fn rank<T: nabled_core::scalar::NabledReal>(
svd: &crate::linalg::svd::NdarraySVD<T>,
tolerance: Option<T>,
) -> usize {
crate::linalg::svd::rank(svd, tolerance)
}