Skip to content

Commit

Permalink
Clippy fixes (lancedb#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyxu committed Feb 14, 2023
1 parent d1a21b9 commit 51afc00
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 39 deletions.
40 changes: 20 additions & 20 deletions rust/src/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,25 @@ impl DataTypeExt for DataType {

fn byte_width(&self) -> usize {
match self {
DataType::Int8 => 1,
DataType::Int16 => 2,
DataType::Int32 => 4,
DataType::Int64 => 8,
DataType::UInt8 => 1,
DataType::UInt16 => 2,
DataType::UInt32 => 4,
DataType::UInt64 => 8,
DataType::Float16 => 2,
DataType::Float32 => 4,
DataType::Float64 => 8,
DataType::Date32 => 4,
DataType::Date64 => 8,
DataType::Time32(_) => 4,
DataType::Time64(_) => 8,
DataType::Decimal128(_, _) => 16,
DataType::Decimal256(_, _) => 32,
DataType::FixedSizeBinary(s) => *s as usize,
DataType::FixedSizeList(dt, s) => *s as usize * dt.data_type().byte_width(),
Self::Int8 => 1,
Self::Int16 => 2,
Self::Int32 => 4,
Self::Int64 => 8,
Self::UInt8 => 1,
Self::UInt16 => 2,
Self::UInt32 => 4,
Self::UInt64 => 8,
Self::Float16 => 2,
Self::Float32 => 4,
Self::Float64 => 8,
Self::Date32 => 4,
Self::Date64 => 8,
Self::Time32(_) => 4,
Self::Time64(_) => 8,
Self::Decimal128(_, _) => 16,
Self::Decimal256(_, _) => 32,
Self::FixedSizeBinary(s) => *s as usize,
Self::FixedSizeList(dt, s) => *s as usize * dt.data_type().byte_width(),
_ => panic!("Does not support get byte width on type {self}"),
}
}
Expand Down Expand Up @@ -388,7 +388,7 @@ impl RecordBatchExt for RecordBatch {
columns.push(self.column(i).clone());
}
}
Ok(RecordBatch::try_new(
Ok(Self::try_new(
Arc::new(Schema::new_with_metadata(
fields,
self.schema().metadata().clone(),
Expand Down
10 changes: 8 additions & 2 deletions rust/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ pub use metadata::Metadata;
pub use page_table::{PageInfo, PageTable};

/// Protobuf definitions
#[allow(clippy::all)]
pub mod pb {
#![allow(clippy::all)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(unused)]
#![allow(improper_ctypes)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::use_self)]
include!(concat!(env!("OUT_DIR"), "/lance.format.pb.rs"));
}

Expand All @@ -42,7 +48,7 @@ impl TryFrom<&pb::Uuid> for Uuid {
}
let mut buf: [u8; 16] = [0; 16];
buf.copy_from_slice(p.uuid.to_byte_slice());
Ok(Uuid::from_bytes(buf))
Ok(Self::from_bytes(buf))
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/src/format/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl From<pb::Metadata> for Metadata {
}

#[derive(Debug, PartialEq)]
pub(crate) struct BatchOffsets {
pub struct BatchOffsets {
pub batch_id: i32,
pub offsets: Vec<u32>,
}
Expand Down
3 changes: 1 addition & 2 deletions rust/src/format/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ impl PageTable {
let num_batches = self
.pages
.values()
.map(|c_map| c_map.keys().max())
.flatten()
.flat_map(|c_map| c_map.keys().max())
.max()
.unwrap()
+ 1;
Expand Down
2 changes: 1 addition & 1 deletion rust/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use std::any::Any;
use async_trait::async_trait;

/// Protobuf definitions for the index on-disk format.
#[allow(clippy::all)]
pub mod pb {
#![allow(clippy::use_self)]
include!(concat!(env!("OUT_DIR"), "/lance.index.pb.rs"));
}

Expand Down
4 changes: 2 additions & 2 deletions rust/src/index/vector/ivf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ impl IndexBuilder for IvfPqIndexBuilder<'_> {
// Write each partition to disk.
let part_col = pq_code_batch
.column_by_name(PARTITION_ID_COLUMN)
.expect(format!("{} does not exist", PARTITION_ID_COLUMN).as_str());
.expect(format!("{PARTITION_ID_COLUMN} does not exist").as_str());
let partition_ids: &UInt32Array = as_primitive_array(part_col);
let min_id = min(partition_ids).unwrap_or(0);
let max_id = max(partition_ids).unwrap_or(1024 * 1024);
Expand Down Expand Up @@ -640,7 +640,7 @@ async fn train_kmean_model(
.await?;
let mut arr_list = vec![];
for batch in batches {
let arr = batch.column_by_name(&column_name).unwrap();
let arr = batch.column_by_name(column_name).unwrap();
let list_arr = as_fixed_size_list_array(&arr);
arr_list.push(list_arr.values().clone());
}
Expand Down
18 changes: 9 additions & 9 deletions rust/src/index/vector/pq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> PQIndex<'a> {
let scores = Arc::new(Float32Array::from_iter(
self.code
.values()
.chunks_exact(self.num_sub_vectors as usize)
.chunks_exact(self.num_sub_vectors)
.map(|c| {
c.iter()
.enumerate()
Expand Down Expand Up @@ -180,20 +180,20 @@ impl ProductQuantizer {

/// Calculate codebook length.
pub fn codebook_length(num_bits: u32, num_sub_vectors: usize) -> usize {
ProductQuantizer::num_centroids(num_bits) * num_sub_vectors
Self::num_centroids(num_bits) * num_sub_vectors
}

/// Get the centroids for one sub-vector.
pub fn centroids(&self, sub_vector_idx: usize) -> Arc<FixedSizeListArray> {
assert!(sub_vector_idx < self.num_sub_vectors as usize);
assert!(sub_vector_idx < self.num_sub_vectors);
assert!(self.codebook.is_some());

let num_centroids = ProductQuantizer::num_centroids(self.num_bits);
let num_centroids = Self::num_centroids(self.num_bits);
let sub_vector_width = self.dimension / self.num_sub_vectors;
let codebook = self.codebook.as_ref().unwrap();
let arr = codebook.slice(
sub_vector_idx * num_centroids * sub_vector_width as usize,
num_centroids * sub_vector_width as usize,
sub_vector_idx * num_centroids * sub_vector_width,
num_centroids * sub_vector_width,
);
let f32_arr: &Float32Array = as_primitive_array(&arr);
Arc::new(FixedSizeListArray::try_new(f32_arr, sub_vector_width as i32).unwrap())
Expand All @@ -204,9 +204,9 @@ impl ProductQuantizer {
&self,
sub_vectors: &[Arc<FixedSizeListArray>],
) -> Result<FixedSizeListArray> {
assert_eq!(sub_vectors.len(), self.num_sub_vectors as usize);
assert_eq!(sub_vectors.len(), self.num_sub_vectors);

let vectors = sub_vectors.iter().map(|v| v.clone()).collect::<Vec<_>>();
let vectors = sub_vectors.to_vec();
let all_centroids = (0..sub_vectors.len())
.map(|idx| self.centroids(idx))
.collect::<Vec<_>>();
Expand Down Expand Up @@ -238,7 +238,7 @@ impl ProductQuantizer {
for i in 0..pq_code.len() {
let vec = pq_code[i].as_slice();
for j in 0..vec.len() {
pq_codebook_builder[j * self.num_sub_vectors as usize + i] = vec[j];
pq_codebook_builder[j * self.num_sub_vectors + i] = vec[j];
}
}

Expand Down
4 changes: 2 additions & 2 deletions rust/src/io/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<'a> FileWriter<'a> {
assert!(!offsets.is_empty());
let offsets = Arc::new(subtract_scalar(&offsets, offsets.value(0))?) as ArrayRef;
self.write_fixed_stride_array(field, &offsets).await?;
self.write_array(&field.children[0], &list_arr.values())
self.write_array(&field.children[0], list_arr.values())
.await
}

Expand All @@ -246,7 +246,7 @@ impl<'a> FileWriter<'a> {
assert!(!offsets.is_empty());
let offsets = Arc::new(subtract_scalar(&offsets, offsets.value(0))?) as ArrayRef;
self.write_fixed_stride_array(field, &offsets).await?;
self.write_array(&field.children[0], &list_arr.values())
self.write_array(&field.children[0], list_arr.values())
.await
}

Expand Down

0 comments on commit 51afc00

Please sign in to comment.