Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Nov 13, 2023
1 parent b7d48f3 commit b6db1c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
16 changes: 1 addition & 15 deletions crates/voicevox_core/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ pub(crate) mod runtimes;
pub(crate) mod signatures;
pub(crate) mod status;

use std::{
borrow::Cow,
fmt::{self, Debug, Display},
};
use std::{borrow::Cow, fmt::Debug};

use derive_new::new;
use enum_map::{Enum, EnumMap};
Expand Down Expand Up @@ -132,17 +129,6 @@ impl<D: PartialEq> ParamInfo<D> {
}
}

impl<D: Display> Display for ParamInfo<D> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.name, self.dt)?;
if let Some(ndim) = self.ndim {
f.write_str(&"[]".repeat(ndim))
} else {
f.write_str("[]...")
}
}
}

pub(crate) trait ArrayExt {
type Scalar;
type Dimension: Dimension;
Expand Down
21 changes: 16 additions & 5 deletions crates/voicevox_core/src/infer/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,25 @@ impl<R: InferenceRuntime, G: InferenceGroup> SessionSet<R, G> {
&& itertools::zip_eq(expected, actual)
.all(|(expected, actual)| expected.accepts(actual)))
{
bail!(
"expected {{{}}}, got {{{}}}",
expected.iter().join(", "),
actual.iter().join(", "),
)
let expected = display_param_infos(expected);
let actual = display_param_infos(actual);
bail!("expected {{{expected}}}, got {{{actual}}}")
}
Ok(())
}

fn display_param_infos(infos: &[ParamInfo<impl Display>]) -> impl Display {
infos
.iter()
.map(|ParamInfo { name, dt, ndim }| {
let brackets = match *ndim {
Some(ndim) => "[]".repeat(ndim),
None => "[]...".to_owned(),
};
format!("{name}: {dt}{brackets}")
})
.join(", ")
}
}
}

Expand Down

0 comments on commit b6db1c0

Please sign in to comment.