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 compute_f32(
matrix: &FixedSizeListArray,
n_components: Option<usize>,
) -> Result<crate::ml::pca::NdarrayPCAResult<f32>, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float32Type>(matrix)?;
Ok(crate::ml::pca::compute_pca_view(&matrix_view, n_components)?)
}
pub fn compute_f64(
matrix: &FixedSizeListArray,
n_components: Option<usize>,
) -> Result<crate::ml::pca::NdarrayPCAResult<f64>, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float64Type>(matrix)?;
Ok(crate::ml::pca::compute_pca_view(&matrix_view, n_components)?)
}
pub fn transform_f32(
matrix: &FixedSizeListArray,
pca: &crate::ml::pca::NdarrayPCAResult<f32>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float32Type>(matrix)?;
let output = crate::ml::pca::transform_view(&matrix_view, pca);
fixed_size_list_from_owned::<Float32Type>(output)
}
pub fn transform_f64(
matrix: &FixedSizeListArray,
pca: &crate::ml::pca::NdarrayPCAResult<f64>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let matrix_view = fixed_size_list_view::<Float64Type>(matrix)?;
let output = crate::ml::pca::transform_view(&matrix_view, pca);
fixed_size_list_from_owned::<Float64Type>(output)
}
pub fn inverse_transform_f32(
scores: &FixedSizeListArray,
pca: &crate::ml::pca::NdarrayPCAResult<f32>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let score_view = fixed_size_list_view::<Float32Type>(scores)?;
let output = crate::ml::pca::inverse_transform_view(&score_view, pca);
fixed_size_list_from_owned::<Float32Type>(output)
}
pub fn inverse_transform_f64(
scores: &FixedSizeListArray,
pca: &crate::ml::pca::NdarrayPCAResult<f64>,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let score_view = fixed_size_list_view::<Float64Type>(scores)?;
let output = crate::ml::pca::inverse_transform_view(&score_view, pca);
fixed_size_list_from_owned::<Float64Type>(output)
}
pub fn compute_complex(
matrix: &FixedSizeListArray,
n_components: Option<usize>,
) -> Result<crate::ml::pca::NdarrayComplexPCAResult, ArrowInteropError> {
let matrix_view = complex64_matrix_view(matrix)?;
Ok(crate::ml::pca::compute_pca_complex_view(&matrix_view, n_components)?)
}
pub fn transform_complex(
matrix: &FixedSizeListArray,
pca: &crate::ml::pca::NdarrayComplexPCAResult,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let matrix_view = complex64_matrix_view(matrix)?;
complex64_matrix_from_owned(crate::ml::pca::transform_complex_view(&matrix_view, pca))
}
pub fn inverse_transform_complex(
scores: &FixedSizeListArray,
pca: &crate::ml::pca::NdarrayComplexPCAResult,
) -> Result<FixedSizeListArray, ArrowInteropError> {
let score_view = complex64_matrix_view(scores)?;
complex64_matrix_from_owned(crate::ml::pca::inverse_transform_complex_view(&score_view, pca))
}