Skip to content

Commit

Permalink
rustfmt groups imports
Browse files Browse the repository at this point in the history
  • Loading branch information
acrrd committed Oct 25, 2022
1 parent 1282b5a commit aa782ed
Show file tree
Hide file tree
Showing 62 changed files with 84 additions and 130 deletions.
3 changes: 1 addition & 2 deletions discovery_engine_core/ai/ai/src/coi/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,12 @@ mod tests {
use ndarray::arr1;
use xayn_discovery_engine_test_utils::assert_approx_eq;

use super::*;
use crate::{
coi::point::tests::{create_neg_cois, create_pos_cois},
utils::SECONDS_PER_DAY_F32,
};

use super::*;

#[test]
fn test_has_enough_cois() {
let user_interests = UserInterests::default();
Expand Down
1 change: 0 additions & 1 deletion discovery_engine_core/ai/ai/src/coi/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ where
#[cfg(test)]
pub(crate) mod tests {
use ndarray::{arr1, FixedInitializer};

use xayn_discovery_engine_test_utils::assert_approx_eq;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion discovery_engine_core/ai/ai/src/coi/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ pub(super) fn compute_coi_decay_factor(

#[cfg(test)]
mod tests {
use crate::coi::{config::Config, point::tests::create_pos_cois};
use xayn_discovery_engine_test_utils::assert_approx_eq;

use super::*;
use crate::coi::{config::Config, point::tests::create_pos_cois};

#[test]
fn test_compute_relevances_empty_cois() {
Expand Down
3 changes: 1 addition & 2 deletions discovery_engine_core/ai/ai/src/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::ops::RangeInclusive;
use itertools::Itertools;
use ndarray::{Array2, ArrayBase, ArrayView1, Data, Ix1};
use xayn_discovery_engine_bert::Embedding1;

// Re-export `Embedding` specific errors.
pub use xayn_discovery_engine_bert::MalformedBytesEmbedding;

Expand Down Expand Up @@ -109,9 +108,9 @@ pub fn cosine_similarity(a: ArrayView1<'_, f32>, b: ArrayView1<'_, f32>) -> f32
#[cfg(test)]
mod tests {
use ndarray::{arr1, arr2};
use xayn_discovery_engine_test_utils::assert_approx_eq;

use super::*;
use xayn_discovery_engine_test_utils::assert_approx_eq;

#[test]
fn test_l2_norm() {
Expand Down
3 changes: 1 addition & 2 deletions discovery_engine_core/ai/ai/src/kps/key_phrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,12 @@ mod tests {
use ndarray::arr2;
use xayn_discovery_engine_test_utils::assert_approx_eq;

use super::*;
use crate::{
coi::{config::Config as CoiConfig, point::tests::create_pos_cois},
kps::config::Config as KpsConfig,
};

use super::*;

impl KeyPhrases {
pub(crate) fn new<'a, const N: usize>(
iter: impl IntoIterator<Item = (CoiId, (&'a str, &'a str), &'a str, [f32; N])>,
Expand Down
5 changes: 2 additions & 3 deletions discovery_engine_core/ai/ai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ mod error;
mod kps;
pub mod utils;

#[cfg(doc)]
pub use crate::embedding::COSINE_SIMILARITY_RANGE;
pub use crate::{
coi::{
config::{Config as CoiConfig, Error as CoiConfigError},
Expand All @@ -62,6 +64,3 @@ pub use crate::{
},
utils::{nan_safe_f32_cmp, nan_safe_f32_cmp_desc, system_time_now},
};

#[cfg(doc)]
pub use crate::embedding::COSINE_SIMILARITY_RANGE;
2 changes: 1 addition & 1 deletion discovery_engine_core/ai/ai/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ mod tests {

use serde::{Deserialize, Serialize};
use serde_json::{from_str, to_string};
use xayn_discovery_engine_test_utils::assert_approx_eq;

use super::*;
use xayn_discovery_engine_test_utils::assert_approx_eq;

#[test]
fn test_nan_safe_f32_cmp_sorts_in_the_right_order() {
Expand Down
1 change: 0 additions & 1 deletion discovery_engine_core/ai/bert/benches/mbert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::{
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use ndarray::s;
use onnxruntime::{environment::Environment, GraphOptimizationLevel};

use xayn_discovery_engine_bert::{
kinds::SMBert,
tokenizer::Tokenizer,
Expand Down
1 change: 0 additions & 1 deletion discovery_engine_core/ai/bert/examples/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use csv::Reader;
use indicatif::ProgressBar;
use ndarray::{s, Array1, Array2, ArrayView1, Axis};
use onnxruntime::{environment::Environment, session::Session, GraphOptimizationLevel};

use xayn_discovery_engine_bert::{
kinds::{QAMBert, SMBert},
tokenizer::Tokenizer,
Expand Down
2 changes: 1 addition & 1 deletion discovery_engine_core/ai/bert/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ where

#[cfg(test)]
mod tests {
use ndarray::Array2;
use std::{fs::File, io::BufReader};

use ndarray::Array2;
use xayn_discovery_engine_test_utils::smbert::model;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion discovery_engine_core/ai/bert/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ impl Tokenizer {

#[cfg(test)]
mod tests {
use ndarray::ArrayView;
use std::{fs::File, io::BufReader};

use ndarray::ArrayView;
use xayn_discovery_engine_test_utils::smbert::vocab;

use super::*;
Expand Down
3 changes: 2 additions & 1 deletion discovery_engine_core/ai/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod example;
pub mod smbert;
pub mod uuid;

pub use crate::approx_eq::ApproxEqIter;
#[doc(hidden)] // required for standalone export of assert_approx_eq!
pub use float_cmp::approx_eq;

pub use crate::approx_eq::ApproxEqIter;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use proc_macro2::TokenStream;
use quote::quote;

use self::dart_glue::generate_dart_api_init;
use crate::{
parse::{
api::Api,
Expand All @@ -24,8 +25,6 @@ use crate::{
Language,
};

use self::dart_glue::generate_dart_api_init;

mod dart_glue;

pub(crate) fn generate_type(api: &Api) -> TokenStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ struct ClassContext<'a> {

#[cfg(test)]
mod tests {
use crate::{parse_genesis::DartFunctionInputs, test_utils::assert_trimmed_line_eq};

use super::*;
use crate::{parse_genesis::DartFunctionInputs, test_utils::assert_trimmed_line_eq};

#[test]
fn test_rendering_template_works() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

//! Provides ways to handle the async runtime used by async-bindgen.
use std::future::Future;
use tokio::runtime::{Handle, Runtime};

use once_cell::sync::OnceCell;
use tokio::runtime::{Handle, Runtime};

static RUNTIME: OnceCell<Runtime> = OnceCell::new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
use std::{future::Future, intrinsics::transmute, pin::Pin};

use thiserror::Error;
use xayn_dart_api_dl::{
cobject::{CObject, TypedData},
ports::SendPort,
DartRuntime,
};

use thiserror::Error;

pub use xayn_dart_api_dl::{initialize_dart_api_dl, ports::DartPortId};

use crate::async_runtime::spawn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::ptr::addr_of_mut;

use uuid::Uuid;

use xayn_discovery_engine_core::document::{Document, Embedding, NewsResource, UserReaction};

/// Returns a pointer to the `id` field of a document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::{ptr::addr_of_mut, time::Duration};

use uuid::Uuid;

use xayn_discovery_engine_core::document::{Embedding, TimeSpent, UserReaction, ViewMode};

/// Returns a pointer to the `id` field of a [`TimeSpent`] memory object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::ptr::addr_of_mut;

use uuid::Uuid;

use xayn_discovery_engine_core::document::{Embedding, UserReacted, UserReaction};
use xayn_discovery_engine_providers::Market;

Expand Down Expand Up @@ -123,7 +122,6 @@ mod tests {
use std::alloc::Layout;

use uuid::Uuid;

use xayn_discovery_engine_core::{document, stack};

#[test]
Expand Down
6 changes: 2 additions & 4 deletions discovery_engine_core/bindings/src/types/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
use std::process::abort;

use ndarray::Array;

use crate::types::slice::boxed_slice_from_raw_parts;
use xayn_discovery_engine_core::document::Embedding;

use super::primitives::FfiUsize;
use crate::types::slice::boxed_slice_from_raw_parts;

/// Creates a rust `Embedding` with given capacity at given memory address.
///
Expand Down Expand Up @@ -129,9 +128,8 @@ mod tests {

use ndarray::arr1;

use crate::types::primitives::alloc_uninitialized_f32_slice;

use super::*;
use crate::types::primitives::alloc_uninitialized_f32_slice;

#[test]
fn test_reading_embedding_works() {
Expand Down
3 changes: 1 addition & 2 deletions discovery_engine_core/bindings/src/types/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@

//! FFI functions for handling engine instances.
use cfg_if::cfg_if;
use std::ptr::addr_of_mut;

use cfg_if::cfg_if;
use derive_more::{AsRef, From};
use tokio::sync::Mutex;

use xayn_discovery_engine_core::{Engine, InitDbHint};

/// A shared discovery engine with a lock.
Expand Down
3 changes: 1 addition & 2 deletions discovery_engine_core/bindings/src/types/history_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
use xayn_discovery_engine_core::document::HistoricDocument;

use super::{boxed::alloc_uninitialized, primitives::FfiUsize};
use crate::types::{
slice::{alloc_uninitialized_slice, boxed_slice_from_raw_parts, next_element},
vec::{get_vec_buffer, get_vec_len},
};

use super::{boxed::alloc_uninitialized, primitives::FfiUsize};

/// Initializes a `Vec<HistoricDocument>` at given place.
///
/// This moves the passed in slice into the vector,
Expand Down
9 changes: 4 additions & 5 deletions discovery_engine_core/bindings/src/types/market_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
use xayn_discovery_engine_providers::Market;

use crate::types::{
slice::{alloc_uninitialized_slice, boxed_slice_from_raw_parts, next_element},
vec::{get_vec_buffer, get_vec_len},
};

use super::{
boxed::{self, alloc_uninitialized},
primitives::FfiUsize,
};
use crate::types::{
slice::{alloc_uninitialized_slice, boxed_slice_from_raw_parts, next_element},
vec::{get_vec_buffer, get_vec_len},
};

/// Initializes a `Vec<Market>` at given place.
///
Expand Down
9 changes: 4 additions & 5 deletions discovery_engine_core/bindings/src/types/string_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@

//! FFI functions for handling slices and vectors of [`String`] instance.
use crate::types::{
slice::{alloc_uninitialized_slice, boxed_slice_from_raw_parts, next_element},
vec::{get_vec_buffer, get_vec_len},
};

use super::{
boxed::{self, alloc_uninitialized},
primitives::FfiUsize,
};
use crate::types::{
slice::{alloc_uninitialized_slice, boxed_slice_from_raw_parts, next_element},
vec::{get_vec_buffer, get_vec_len},
};

/// Initializes a `Vec<String>` at given place.
///
Expand Down
1 change: 0 additions & 1 deletion discovery_engine_core/bindings/src/types/trending_topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::ptr::addr_of_mut;

use url::Url;
use uuid::Uuid;

use xayn_discovery_engine_core::document::{Embedding, TrendingTopic};

/// Returns a pointer to the `id` field of a trending topic.
Expand Down
9 changes: 4 additions & 5 deletions discovery_engine_core/bindings/src/types/uuid_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
use uuid::Uuid;

use crate::types::{
slice::{alloc_uninitialized_slice, boxed_slice_from_raw_parts, next_element},
vec::{get_vec_buffer, get_vec_len},
};

use super::{
boxed::{self, alloc_uninitialized},
primitives::FfiUsize,
};
use crate::types::{
slice::{alloc_uninitialized_slice, boxed_slice_from_raw_parts, next_element},
vec::{get_vec_buffer, get_vec_len},
};

/// Initializes a `Vec<Uuid>` at given place.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
use xayn_discovery_engine_core::document::WeightedSource;

use super::{boxed::alloc_uninitialized, primitives::FfiUsize};
use crate::types::{
slice::{alloc_uninitialized_slice, boxed_slice_from_raw_parts, next_element},
vec::{get_vec_buffer, get_vec_len},
};

use super::{boxed::alloc_uninitialized, primitives::FfiUsize};

/// Initializes a `Vec<WeightedSource>` at given place.
///
/// This moves the passed in slice into the vector,
Expand Down
1 change: 0 additions & 1 deletion discovery_engine_core/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use figment::{
};
use serde::{Deserialize, Serialize};
use tokio::sync::RwLock;

use xayn_discovery_engine_ai::{CoiConfig, KpsConfig};
use xayn_discovery_engine_providers::{Market, ProviderConfig};

Expand Down
5 changes: 1 addition & 4 deletions discovery_engine_core/core/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
use thiserror::Error;
use url::Url;
use uuid::Uuid;

pub use xayn_discovery_engine_ai::Embedding;
use xayn_discovery_engine_ai::{Document as AiDocument, DocumentId};
use xayn_discovery_engine_providers::{GenericArticle, Market, TrendingTopic as BingTopic};

use crate::stack::Id as StackId;

pub use xayn_discovery_engine_ai::Embedding;

/// Errors that could happen when constructing a [`Document`].
#[derive(Error, Debug, DisplayDoc)]
pub enum Error {
Expand Down Expand Up @@ -365,7 +363,6 @@ impl AiDocument for TrendingTopic {
#[cfg(test)]
pub(crate) mod tests {
use chrono::TimeZone;

use xayn_discovery_engine_providers::{Rank, UrlWithDomain};

use super::*;
Expand Down
Loading

0 comments on commit aa782ed

Please sign in to comment.