Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/bin/dmapembed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct HnswParams {

impl HnswParams {
pub fn my_default() -> Self {
HnswParams {
Self {
max_conn: 64,
ef_c: 512,
knbn: 10,
Expand All @@ -90,7 +90,7 @@ impl HnswParams {
distance: String,
scale_modification: f64,
) -> Self {
HnswParams {
Self {
max_conn,
ef_c,
knbn,
Expand All @@ -109,7 +109,7 @@ pub struct QualityParams {

impl Default for QualityParams {
fn default() -> Self {
QualityParams {
Self {
sampling_fraction: 1.0,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/bin/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct HnswParams {

impl HnswParams {
pub fn my_default() -> Self {
HnswParams {
Self {
max_conn: 64,
ef_c: 512,
knbn: 10,
Expand All @@ -81,7 +81,7 @@ impl HnswParams {
distance: String,
scale_modification: f64,
) -> Self {
HnswParams {
Self {
max_conn,
ef_c,
knbn,
Expand All @@ -100,7 +100,7 @@ pub struct QualityParams {

impl Default for QualityParams {
fn default() -> Self {
QualityParams {
Self {
sampling_fraction: 1.0,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/diffmaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl DiffusionParams {
/// - optional diffusion time
/// - optional number of neighbours used in laplacian discretisation
pub fn new(asked_dim: usize, t_opt: Option<f32>, g_opt: Option<usize>) -> Self {
DiffusionParams {
Self {
asked_dim,
alfa: 1.,
beta: 0.,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl DiffusionParams {

impl Default for DiffusionParams {
fn default() -> Self {
DiffusionParams {
Self {
asked_dim: 2,
alfa: 1.,
beta: 0.,
Expand Down Expand Up @@ -166,7 +166,7 @@ pub struct DiffusionMaps {
impl DiffusionMaps {
/// iitialization from NodeParams
pub fn new(params: DiffusionParams) -> Self {
DiffusionMaps {
Self {
params,
_node_params: None,
normed_scales: None,
Expand Down
10 changes: 5 additions & 5 deletions src/embedder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ where
Hnsw::<F, DistL2F>::new(max_nb_connection, nb_nodes, nb_layer, ef_c, DistL2F {});
hnsw.set_keeping_pruned(true);
// need to store arrayviews to get a sufficient lifetime to call as_slice later
let vectors: Vec<ArrayView1<F>> = (0..nb_nodes).map(|i| (embedding.row(i))).collect();
let vectors: Vec<ArrayView1<F>> = (0..nb_nodes).map(|i| embedding.row(i)).collect();
let mut data_with_id = Vec::<(&[F], usize)>::with_capacity(nb_nodes);
for (i, v) in vectors.iter().enumerate().take(nb_nodes) {
data_with_id.push((v.as_slice().unwrap(), i));
Expand Down Expand Up @@ -1014,7 +1014,9 @@ where
log::trace!("\n entering EntropyOptim::ce_compute_threaded");
//
let b: f64 = self.params.b;
let ce_entropy = self

//
self
.edges
.par_iter()
.fold(
Expand Down Expand Up @@ -1043,9 +1045,7 @@ where
}
},
)
.sum::<f64>();
//
ce_entropy
.sum::<f64>()
} // end of ce_compute_threaded

// TODO : pass functions corresponding to edge_weight and grad_edge_weight as arguments to test others weight function
Expand Down
2 changes: 1 addition & 1 deletion src/embedparams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl EmbedderParams {
let nb_grad_batch = 20;
let grad_factor: usize = 4;
let hierarchy_layer = 0;
EmbedderParams {
Self {
asked_dim,
dmap_init,
beta,
Expand Down
2 changes: 1 addition & 1 deletion src/fromhnsw/kgproj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ where
}
log::trace!("Projection exiting from new");
//
KGraphProjection {
Self {
layer,
small_graph: upper_graph,
proj_data,
Expand Down
2 changes: 1 addition & 1 deletion src/fromhnsw/kgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
/// allocates a graph with expected size nbnodes and nbng neighbours
pub fn new() -> Self {
let neighbours_init = Vec::<Vec<OutEdge<F>>>::new();
KGraph {
Self {
max_nbng: 0,
nbnodes: 0,
neighbours: neighbours_init,
Expand Down
2 changes: 1 addition & 1 deletion src/graphlaplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) struct GraphLaplacian {

impl GraphLaplacian {
pub fn new(sym_laplacian: MatRepr<f32>, degrees: Array1<f32>) -> Self {
GraphLaplacian {
Self {
sym_laplacian,
degrees,
svd_res: None,
Expand Down
2 changes: 1 addition & 1 deletion src/hdbscan/kruskal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
fn new(parent: Vec<Ix>) -> Self {
let rank = vec![1; parent.len()];
//
UnionFind { parent, rank }
Self { parent, rank }
} // end of new

fn find(&mut self, mut node: Ix) -> Ix {
Expand Down
4 changes: 2 additions & 2 deletions src/hdbscan/sl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct Dendrogram<NodeIdx: PrimInt, F: Float> {

impl<NodeIdx: PrimInt, F: Float> Dendrogram<NodeIdx, F> {
pub fn new(nbstep: usize) -> Self {
Dendrogram {
Self {
steps: Vec::<UnionStep<NodeIdx, F>>::with_capacity(nbstep),
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ where
let kgraph = kgraph_from_hnsw_all(hnsw, nbng).unwrap();
//
let nbstep = kgraph.get_nb_nodes() - nbcluster;
SLclustering {
Self {
kgraph,
dendrogram: Dendrogram::<NodeIdx, F>::new(nbstep),
nbcluster,
Expand Down
16 changes: 8 additions & 8 deletions src/tools/entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
F: Float + AddAssign + SubAssign + MulAssign + DivAssign + std::iter::Sum,
{
pub fn new(q: F, value: F) -> Self {
RenyiEntropy {
Self {
kind: EntropyKind::Renyi,
q,
value,
Expand Down Expand Up @@ -68,7 +68,7 @@ where
}
}
let np = p.iter().map(|&x| x / sum).collect();
DiscreteProba {
Self {
p: np,
entropy: None,
}
Expand Down Expand Up @@ -111,7 +111,7 @@ where
} // end of entropy_renyi

// compute relative entropy at q=1
fn relative_renyi_entropy_1(&self, other: &DiscreteProba<F>) -> F {
fn relative_renyi_entropy_1(&self, other: &Self) -> F {
let zero = F::zero();
self.p
.iter()
Expand All @@ -127,9 +127,10 @@ where
}

//
fn relative_renyi_entropy_q(&self, other: &DiscreteProba<F>, q: F) -> F {
fn relative_renyi_entropy_q(&self, other: &Self, q: F) -> F {
let zero = F::zero();
let entropy = self

self
.p
.iter()
.zip(other.p.iter())
Expand All @@ -140,8 +141,7 @@ where
zero
}
})
.sum();
entropy
.sum()
}

/// computes mean diversity of other with respect to self.
Expand All @@ -150,7 +150,7 @@ where
/// $$ \sum_{self.p_{i} != 0} self.p_{i} * \phi(\frac{other.p_{i}}{self.p_{i}})$$
///
///
pub fn relative_renyi_entropy(&self, other: &DiscreteProba<F>, q: F) -> F {
pub fn relative_renyi_entropy(&self, other: &Self, q: F) -> F {
if near_to_1(q) {
self.relative_renyi_entropy_1(other)
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/tools/nodeparam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ pub struct OutEdge<F> {

impl<F> OutEdge<F> {
pub fn new(node: NodeIdx, weight: F) -> Self {
OutEdge { node, weight }
Self { node, weight }
}
}

impl<F> PartialEq for OutEdge<F>
where
F: Float,
{
fn eq(&self, other: &OutEdge<F>) -> bool {
fn eq(&self, other: &Self) -> bool {
self.weight == other.weight
} // end eq
}

// CAVEAT coud use the PointWithOrder<T> implementation for Ord which panic on Nan.
/// order points by distance to self.
impl<F: Float> PartialOrd for OutEdge<F> {
fn partial_cmp(&self, other: &OutEdge<F>) -> Option<Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.weight.partial_cmp(&other.weight)
} // end cmp
} // end impl PartialOrd
Expand All @@ -53,8 +53,8 @@ where
F: Float + FromPrimitive,
{
//
fn from(neighbour: Neighbour) -> OutEdge<F> {
OutEdge {
fn from(neighbour: Neighbour) -> Self {
Self {
node: neighbour.d_id,
weight: F::from_f32(neighbour.distance).unwrap(),
}
Expand All @@ -76,7 +76,7 @@ pub struct NodeParam {

impl NodeParam {
pub fn new(scale: f32, edges: Vec<OutEdge<f32>>) -> Self {
NodeParam { scale, edges }
Self { scale, edges }
}

/// for a given node index return corresponding edge if it is in neighbours, None else
Expand All @@ -99,7 +99,7 @@ impl NodeParam {

impl Default for NodeParam {
fn default() -> Self {
NodeParam {
Self {
scale: 0f32,
edges: Vec::<OutEdge<f32>>::new(),
}
Expand All @@ -115,7 +115,7 @@ pub struct NodeParams {

impl NodeParams {
pub fn new(params: Vec<NodeParam>, max_nbng: usize) -> Self {
NodeParams { params, max_nbng }
Self { params, max_nbng }
}
//
pub fn get_node_param(&self, node: NodeIdx) -> &NodeParam {
Expand Down
24 changes: 12 additions & 12 deletions src/tools/svdapprox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
let mat: Array2<F> =
ArrayBase::from_shape_fn(dims, |_| F::from_f64(stdnormal.sample(&mut rng)).unwrap());
//
RandomGaussianMatrix { mat }
Self { mat }
}
} // end of impl block for RandomGaussianMatrix

Expand All @@ -82,7 +82,7 @@ struct RandomGaussianGenerator<F> {
impl<F: Float + FromPrimitive> RandomGaussianGenerator<F> {
pub fn new() -> Self {
let rng = Xoshiro256PlusPlus::seed_from_u64(4664397);
RandomGaussianGenerator::<F> {
Self {
rng,
_ty: PhantomData,
}
Expand Down Expand Up @@ -136,23 +136,23 @@ where
{
/// initialize a MatRepr from an Array2
#[inline]
pub fn from_array2(mat: Array2<F>) -> MatRepr<F> {
MatRepr {
pub fn from_array2(mat: Array2<F>) -> Self {
Self {
data: MatMode::FULL(mat),
}
}

pub fn from_trimat(trimat: TriMat<F>) -> MatRepr<F> {
MatRepr {
pub fn from_trimat(trimat: TriMat<F>) -> Self {
Self {
data: MatMode::CSR(trimat.to_csr()),
}
}

/// initialize a MatRepr from a CsMat
#[inline]
pub fn from_csrmat(mat: CsMat<F>) -> MatRepr<F> {
pub fn from_csrmat(mat: CsMat<F>) -> Self {
assert!(mat.is_csr());
MatRepr {
Self {
data: MatMode::CSR(mat),
}
}
Expand Down Expand Up @@ -227,9 +227,9 @@ where
/// return a transposed copy
pub fn transpose_owned(&self) -> Self {
match &self.data {
MatMode::FULL(mat) => MatRepr::<F>::from_array2(mat.t().to_owned()),
MatMode::FULL(mat) => Self::from_array2(mat.t().to_owned()),
// in CSR mode we must reconvert to csr beccause the transposed view is csc
MatMode::CSR(csmat) => MatRepr::<F>::from_csrmat(csmat.transpose_view().to_csr()),
MatMode::CSR(csmat) => Self::from_csrmat(csmat.transpose_view().to_csr()),
}
} // end of transpose_owned

Expand Down Expand Up @@ -307,7 +307,7 @@ impl RangePrecision {
} else {
step_arg
};
RangePrecision {
Self {
epsil,
step,
max_rank,
Expand All @@ -329,7 +329,7 @@ pub struct RangeRank {
impl RangeRank {
/// initializes a RangeRank structure with asked rank and maximum QR decompositions
pub fn new(rank: usize, nbiter: usize) -> Self {
RangeRank { rank, nbiter }
Self { rank, nbiter }
}
} // end of RangeRank

Expand Down
4 changes: 2 additions & 2 deletions src/utils/mnistio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct MnistData {
}

impl MnistData {
pub fn new(image_filename: String, label_filename: String) -> std::io::Result<MnistData> {
pub fn new(image_filename: String, label_filename: String) -> std::io::Result<Self> {
let image_path = PathBuf::from(image_filename.clone());
let image_file = OpenOptions::new().read(true).open(image_path)?;
let mut image_io = BufReader::new(image_file);
Expand All @@ -31,7 +31,7 @@ impl MnistData {
let labels_file = OpenOptions::new().read(true).open(label_path)?;
let mut labels_io = BufReader::new(labels_file);
let labels = read_label_file(&mut labels_io);
Ok(MnistData {
Ok(Self {
_image_filename: image_filename,
_label_filename: label_filename,
images,
Expand Down