Skip to content

Matrix::centroids method#759

Merged
eddyxu merged 8 commits intomainfrom
lei/centroids
Apr 7, 2023
Merged

Matrix::centroids method#759
eddyxu merged 8 commits intomainfrom
lei/centroids

Conversation

@eddyxu
Copy link
Copy Markdown
Member

@eddyxu eddyxu commented Apr 7, 2023

  • Consolidate centorids computation to MatirxView, for later optimization
  • Change MatrixView::row() to return &[f32] slice for better code and performance (by avoiding more memory allocation to create Float32Array)

Comment thread rust/src/arrow/linalg.rs

let u_values = Arc::new(Float32Array::from_iter_values(u));
let u = MatrixView::new(u_values, m as usize).transpose();
let u = Self::new(u_values, m as usize).transpose();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo clippy

Comment thread rust/src/arrow/linalg.rs
pub fn row(&self, i: usize) -> Option<Float32Array> {
/// Returns a row at index `i`. Returns `None` if the index is out of bound.
///
/// # Panics if the matrix is transposed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Panic instead of Result?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is assert. which should not happen , and there is no code path to recover from such error?

residual_builder.append_slice(resi_arr.values());
unsafe {
residual_builder
.append_trusted_len_iter(vector.iter().zip(cent.iter()).map(|(v, c)| v - c))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If somehow vector and centroid are incompatible does this segfault or just panic or does it fail silently?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can check the length of the two slices. Their types should be the same to be compiled tho.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that this should be assert or debug_assert tho. no recoverable bug.

@eddyxu eddyxu merged commit 017873e into main Apr 7, 2023
@eddyxu eddyxu deleted the lei/centroids branch April 7, 2023 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants