Skip to content

Commit

Permalink
add constant test
Browse files Browse the repository at this point in the history
  • Loading branch information
mo271 committed Nov 22, 2024
1 parent 74f9f4b commit 6c22edf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions jxl/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ impl<T: ImageDataType> Image<T> {
Ok(img)
}

#[cfg(test)]
pub fn new_constant(size: (usize, usize), val: T) -> Result<Image<T>> {
let mut img = Self::new(size)?;
img.data.iter_mut().for_each(|x| *x = val);
Ok(img)
}

pub fn size(&self) -> (usize, usize) {
self.size
}
Expand Down
18 changes: 18 additions & 0 deletions jxl/src/render/stages/upsample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ mod test {
)
}

#[test]
fn upsample2x_constant() -> Result<()> {
let ups_factors = CustomTransformData::default();
let image_size = (238, 412);
let input_size = (image_size.0 / 2, image_size.1 / 2);
let val = 0.777f32;
let input = Image::new_constant(input_size, val)?;
let stage = Upsample2x::new(&ups_factors, 0);
let output: Vec<Image<f32>> =
make_and_run_simple_pipeline(stage, &[input], image_size, 123)?.1;
for x in 0..image_size.0 {
for y in 0..image_size.1 {
assert!((output[0].as_rect().row(y)[x] - val).abs() <= 0.0000001);
}
}
Ok(())
}

#[test]
fn test_upsample2() -> Result<()> {
let mut input = Image::new((7, 7))?;
Expand Down

0 comments on commit 6c22edf

Please sign in to comment.