Use Self in implementations whenever possible
All checks were successful
/ test (pull_request) Successful in 3m34s

This commit is contained in:
Aaron Fenyes 2025-08-05 14:12:31 -07:00
parent e0230a6fde
commit 1d03d1e8c2
6 changed files with 43 additions and 43 deletions

View file

@ -59,12 +59,12 @@ pub struct MatrixEntry {
pub struct PartialMatrix(Vec<MatrixEntry>);
impl PartialMatrix {
pub fn new() -> PartialMatrix {
PartialMatrix(Vec::<MatrixEntry>::new())
pub fn new() -> Self {
Self(Vec::<MatrixEntry>::new())
}
pub fn push(&mut self, row: usize, col: usize, value: f64) {
let PartialMatrix(entries) = self;
let Self(entries) = self;
entries.push(MatrixEntry { index: (row, col), value });
}
@ -114,7 +114,7 @@ impl IntoIterator for PartialMatrix {
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
let PartialMatrix(entries) = self;
let Self(entries) = self;
entries.into_iter()
}
}
@ -139,8 +139,8 @@ pub struct ConfigSubspace {
}
impl ConfigSubspace {
pub fn zero(assembly_dim: usize) -> ConfigSubspace {
ConfigSubspace {
pub fn zero(assembly_dim: usize) -> Self {
Self {
assembly_dim,
basis_proj: Vec::new(),
basis_std: Vec::new(),
@ -154,7 +154,7 @@ impl ConfigSubspace {
a: DMatrix<f64>,
proj_to_std: DMatrix<f64>,
assembly_dim: usize,
) -> ConfigSubspace {
) -> Self {
// find a basis for the kernel. the basis is expressed in the projection
// coordinates, and it's orthonormal with respect to the projection
// inner product
@ -173,7 +173,7 @@ impl ConfigSubspace {
const ELEMENT_DIM: usize = 5;
const UNIFORM_DIM: usize = 4;
ConfigSubspace {
Self {
assembly_dim,
basis_std: basis_std.column_iter().map(
|v| Into::<DMatrix<f64>>::into(
@ -224,8 +224,8 @@ pub struct DescentHistory {
}
impl DescentHistory {
pub fn new() -> DescentHistory {
DescentHistory {
pub fn new() -> Self {
Self {
config: Vec::<DMatrix<f64>>::new(),
scaled_loss: Vec::<f64>::new(),
neg_grad: Vec::<DMatrix<f64>>::new(),
@ -245,9 +245,9 @@ pub struct ConstraintProblem {
}
impl ConstraintProblem {
pub fn new(element_count: usize) -> ConstraintProblem {
pub fn new(element_count: usize) -> Self {
const ELEMENT_DIM: usize = 5;
ConstraintProblem {
Self {
gram: PartialMatrix::new(),
frozen: PartialMatrix::new(),
guess: DMatrix::<f64>::zeros(ELEMENT_DIM, element_count),
@ -255,8 +255,8 @@ impl ConstraintProblem {
}
#[cfg(feature = "dev")]
pub fn from_guess(guess_columns: &[DVector<f64>]) -> ConstraintProblem {
ConstraintProblem {
pub fn from_guess(guess_columns: &[DVector<f64>]) -> Self {
Self {
gram: PartialMatrix::new(),
frozen: PartialMatrix::new(),
guess: DMatrix::from_columns(guess_columns),
@ -284,10 +284,10 @@ struct SearchState {
}
impl SearchState {
fn from_config(gram: &PartialMatrix, config: DMatrix<f64>) -> SearchState {
fn from_config(gram: &PartialMatrix, config: DMatrix<f64>) -> Self {
let err_proj = gram.sub_proj(&(config.tr_mul(&*Q) * &config));
let loss = err_proj.norm_squared();
SearchState { config, err_proj, loss }
Self { config, err_proj, loss }
}
}