mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 09:50:00 +00:00
Fix typos in documentation comments and improve clarity in cumsum_horizontal implementation
This commit is contained in:
parent
c30646d5d0
commit
284471f4aa
@ -1,6 +1,6 @@
|
|||||||
use crate::matrix::{Axis, BoolMatrix, FloatMatrix};
|
use crate::matrix::{Axis, BoolMatrix, FloatMatrix};
|
||||||
|
|
||||||
/// “Series–like” helpers that work along a single axis.
|
/// "Series-like" helpers that work along a single axis.
|
||||||
///
|
///
|
||||||
/// *All* the old methods (`sum_*`, `prod_*`, `is_nan`, …) are exposed
|
/// *All* the old methods (`sum_*`, `prod_*`, `is_nan`, …) are exposed
|
||||||
/// through this trait, so nothing needs to stay on an `impl Matrix<f64>`;
|
/// through this trait, so nothing needs to stay on an `impl Matrix<f64>`;
|
||||||
@ -100,7 +100,7 @@ impl SeriesOps for FloatMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn cumsum_horizontal(&self) -> FloatMatrix {
|
fn cumsum_horizontal(&self) -> FloatMatrix {
|
||||||
// 1. Store row-wise cumulative sums temporarily
|
// Compute cumulative sums for each row and store in a temporary buffer
|
||||||
let mut row_results: Vec<Vec<f64>> = Vec::with_capacity(self.rows());
|
let mut row_results: Vec<Vec<f64>> = Vec::with_capacity(self.rows());
|
||||||
for r in 0..self.rows() {
|
for r in 0..self.rows() {
|
||||||
let mut row_data = Vec::with_capacity(self.cols());
|
let mut row_data = Vec::with_capacity(self.cols());
|
||||||
@ -115,16 +115,15 @@ impl SeriesOps for FloatMatrix {
|
|||||||
row_results.push(row_data);
|
row_results.push(row_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Build the final data vector in column-major order
|
// Assemble the final data vector in column-major format
|
||||||
let mut final_data = Vec::with_capacity(self.rows() * self.cols());
|
let mut final_data = Vec::with_capacity(self.rows() * self.cols());
|
||||||
for c in 0..self.cols() {
|
for c in 0..self.cols() {
|
||||||
for r in 0..self.rows() {
|
for r in 0..self.rows() {
|
||||||
// Get the element from row 'r', column 'c' of the row_results
|
// Extract the element at (r, c) from the temporary row-wise results
|
||||||
final_data.push(row_results[r][c]);
|
final_data.push(row_results[r][c]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Construct the matrix using the correctly ordered data
|
|
||||||
FloatMatrix::from_vec(final_data, self.rows(), self.cols())
|
FloatMatrix::from_vec(final_data, self.rows(), self.cols())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +145,7 @@ impl SeriesOps for FloatMatrix {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
// Helper function to create a FloatMatrix for SeriesOps testing
|
// Helper function to create a FloatMatrix for SeriesOps testing
|
||||||
fn create_float_test_matrix() -> FloatMatrix {
|
fn create_float_test_matrix() -> FloatMatrix {
|
||||||
// 3x3 matrix (column-major) with some NaNs
|
// 3x3 matrix (column-major) with some NaNs
|
||||||
@ -361,4 +360,4 @@ mod tests {
|
|||||||
assert_eq!(matrix.count_nan_horizontal(), vec![2, 2]);
|
assert_eq!(matrix.count_nan_horizontal(), vec![2, 2]);
|
||||||
assert_eq!(matrix.is_nan().data(), &[true, true, true, true]);
|
assert_eq!(matrix.is_nan().data(), &[true, true, true, true]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user