Skip to content
Merged
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
40 changes: 40 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,46 @@ env:
package_name: omikuji

jobs:
rust-test:
runs-on: ${{ matrix.target.os }}
strategy:
fail-fast: false
matrix:
target:
- { os: ubuntu-latest, toolchain: stable, triple: x86_64-unknown-linux-gnu }
- { os: ubuntu-latest, toolchain: stable, triple: x86_64-unknown-linux-musl }
- { os: ubuntu-latest, toolchain: "1.88.0", triple: x86_64-unknown-linux-gnu }
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- name: Install Rust
uses: dtolnay/rust-toolchain@7e38f4b43b4db5c8dd498af069a4f6196df1d067 # master
with:
toolchain: ${{ matrix.target.toolchain }}
targets: ${{ matrix.target.triple }}

- name: Query Rust and Cargo versions
run: |
rustup -V
cargo -V

- name: Run tests
run: |
cargo test --target ${{ matrix.target.triple }} --no-fail-fast -F cli
cargo test --target ${{ matrix.target.triple }} --no-fail-fast --manifest-path c-api/Cargo.toml
cargo test --target ${{ matrix.target.triple }} --no-fail-fast -F cli --doc

- name: Run example
run: |
set -e -x
cargo install --path . --features cli --locked
omikuji --help
cd examples
bash run_cli.sh

rust-build:
runs-on: ubuntu-latest
steps:
Expand Down
10 changes: 3 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
name = "omikuji"
description = "an efficient implementation of Partitioned Label Treesand its variations for extreme multi-label classification"
version = "0.5.2"
edition = "2021"
edition = "2024"
authors = ["Tom Dong <tom.tung.dyb@gmail.com>"]
license = "MIT"
repository = "https://github.com/tomtung/omikuji"
documentation = "https://docs.rs/omikuji"
keywords = [
"machine-learning",
"multi-label",
"classification",
"xmc",
]
keywords = ["machine-learning", "multi-label", "classification", "xmc"]
readme = "README.md"
exclude = ["examples/"]
rust-version = "1.88.0"

[dependencies]
const-default = "1.0.*"
Expand Down
1 change: 1 addition & 0 deletions c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "omikuji_c-api"
version = "0.5.2"
edition = "2021"
authors = ["Tom Dong <tom.tung.dyb@gmail.com>"]
rust-version = "1.88.0"

[lib]
name = "omikuji"
Expand Down
2 changes: 1 addition & 1 deletion src/bin/omikuji.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::{Args, Parser, Subcommand, ValueEnum};
use const_default::ConstDefault;
use omikuji::model::liblinear::LossType;
use omikuji::model::TrainHyperParam;
use omikuji::model::liblinear::LossType;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::PathBuf;
Expand Down
2 changes: 1 addition & 1 deletion src/mat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ where
{
if let Some((i, &v)) = arr
.indexed_iter()
.max_by_key(|(_, &l)| NotNan::new(l).unwrap())
.max_by_key(|&(_, &l)| NotNan::new(l).unwrap())
{
Some((v, i))
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/model/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::mat_util::*;
use const_default::ConstDefault;
use itertools::{izip, Itertools};
use itertools::{Itertools, izip};
use ndarray::{Array2, ArrayView2, ArrayViewMut2, Axis, ScalarOperand, ShapeBuilder};
use num_traits::Float;
use order_stat::kth;
Expand Down
11 changes: 5 additions & 6 deletions src/model/liblinear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use itertools::Itertools;
use rand::prelude::*;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use std::f32::{INFINITY, NEG_INFINITY};
use std::ops::Deref;

/// The loss function used by liblinear model.
Expand Down Expand Up @@ -191,7 +190,7 @@ fn solve_l2r_l2_svc(

// PG: projected gradient, for shrinking and stopping
let mut pg: f32;
let mut pgmax_old = INFINITY;
let mut pgmax_old = f32::INFINITY;
let mut pgmax_new: f32;
let mut pgmin_new: f32;

Expand All @@ -211,8 +210,8 @@ fn solve_l2r_l2_svc(
let mut iter = 0;
let mut rng = thread_rng();
while iter < max_iter {
pgmax_new = NEG_INFINITY;
pgmin_new = INFINITY;
pgmax_new = f32::NEG_INFINITY;
pgmin_new = f32::INFINITY;

index.shuffle(&mut rng);

Expand Down Expand Up @@ -265,13 +264,13 @@ fn solve_l2r_l2_svc(
break;
} else {
active_size = l;
pgmax_old = INFINITY;
pgmax_old = f32::INFINITY;
continue;
}
}
pgmax_old = pgmax_new;
if pgmax_old <= 0. {
pgmax_old = INFINITY;
pgmax_old = f32::INFINITY;
}
}

Expand Down
21 changes: 6 additions & 15 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,13 @@ enum TreeNode {
impl TreeNode {
fn is_valid(&self, settings: Settings) -> bool {
match self {
TreeNode::Branch {
ref weights,
ref children,
} => {
TreeNode::Branch { weights, children } => {
weights.shape() == (settings.n_features + 1, children.len())
&& children.iter().all(|c| c.is_valid(settings))
}
TreeNode::Leaf {
ref weights,
ref labels,
} => weights.shape() == (settings.n_features + 1, labels.len()),
TreeNode::Leaf { weights, labels } => {
weights.shape() == (settings.n_features + 1, labels.len())
}
}
}

Expand All @@ -290,18 +286,13 @@ impl TreeNode {
}

match self {
TreeNode::Branch {
ref mut weights,
ref mut children,
} => {
TreeNode::Branch { weights, children } => {
densify(weights, max_sparse_density);
children
.par_iter_mut()
.for_each(|child| child.densify_weights(max_sparse_density));
}
TreeNode::Leaf {
ref mut weights, ..
} => {
TreeNode::Leaf { weights, .. } => {
densify(weights, max_sparse_density);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/model/train.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{cluster, liblinear, Model, Settings, TreeNode};
use super::{Model, Settings, TreeNode, cluster, liblinear};
use crate::data::DataSet;
use crate::mat_util::*;
use crate::util::{create_progress_bar, ProgressBar};
use crate::util::{ProgressBar, create_progress_bar};
use crate::{Index, IndexSet, IndexValueVec};
use const_default::ConstDefault;
use hashbrown::HashMap;
use itertools::{izip, Itertools};
use itertools::{Itertools, izip};
use log::info;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io::{stderr, Stderr};
use std::io::{Stderr, stderr};

pub(crate) type ProgressBar = pbr::ProgressBar<Stderr>;

Expand Down
Loading