Skip to content

Commit 15334f7

Browse files
committed
Move main tests to hdf5/ and add f16/complex tests
1 parent f02d354 commit 15334f7

File tree

11 files changed

+43
-5
lines changed

11 files changed

+43
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ edition = "2021"
1515
[workspace.dependencies]
1616
# external
1717
cfg-if = "1.0"
18+
half = { version = "2.2", default-features = false }
1819
libc = "0.2"
1920
libz-sys = { version = "1.1", default-features = false }
2021
mpi-sys = "0.2"
22+
num-complex = { version = "0.4", default-features = false }
2123
regex = "1.8"
2224
# internal
2325
hdf5-derive = { version = "0.8.1", path = "hdf5-derive" } # !V

hdf5-types/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ edition.workspace = true
1515

1616
[features]
1717
h5-alloc = []
18-
complex = ["num-complex"]
19-
f16 = ["half"]
18+
complex = ["dep:num-complex"]
19+
f16 = ["dep:half"]
2020

2121
[dependencies]
2222
ascii = "1.1"
2323
cfg-if = { workspace = true }
2424
hdf5-sys = { workspace = true }
2525
libc = { workspace = true }
26-
num-complex = { version = "0.4", optional = true, default-features = false }
27-
half = { version = "2.2", optional = true, default-features = false }
26+
num-complex = { workspace = true, optional = true }
27+
half = { workspace = true, optional = true }
2828

2929
[dev-dependencies]
3030
quickcheck = { version = "1.0", default-features = false }

hdf5/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ hdf5-sys = { workspace = true }
5454
hdf5-types = { workspace = true }
5555

5656
[dev-dependencies]
57+
half = { workspace = true }
58+
num-complex = { workspace = true }
5759
paste = "1.0"
5860
pretty_assertions = "1.3"
5961
rand = { version = "0.8", features = ["small_rng"] }
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
use std::convert::TryFrom;
2-
use std::fmt;
2+
use std::fmt::{self, Debug};
33
use std::iter;
44

55
use hdf5::types::{FixedAscii, FixedUnicode, VarLenArray, VarLenAscii, VarLenUnicode};
66
use hdf5::H5Type;
77

8+
use half::f16;
89
use ndarray::{ArrayD, SliceInfo, SliceInfoElem};
10+
use num_complex::Complex;
11+
use rand::distributions::Standard;
912
use rand::distributions::{Alphanumeric, Uniform};
13+
use rand::prelude::Distribution;
1014
use rand::prelude::{Rng, SliceRandom};
1115

1216
pub fn gen_shape<R: Rng + ?Sized>(rng: &mut R, ndim: usize) -> Vec<usize> {
@@ -93,6 +97,21 @@ macro_rules! impl_gen_tuple {
9397

9498
impl_gen_tuple! { A, B, C, D, E, F, G, H, I, J, K, L }
9599

100+
impl Gen for f16 {
101+
fn gen<R: Rng + ?Sized>(rng: &mut R) -> Self {
102+
Self::from_f32(rng.gen())
103+
}
104+
}
105+
106+
impl<T: Debug> Gen for Complex<T>
107+
where
108+
Standard: Distribution<T>,
109+
{
110+
fn gen<R: Rng + ?Sized>(rng: &mut R) -> Self {
111+
Self::new(rng.gen(), rng.gen())
112+
}
113+
}
114+
96115
pub fn gen_vec<R: Rng + ?Sized, T: Gen>(rng: &mut R, size: usize) -> Vec<T> {
97116
iter::repeat(()).map(|_| T::gen(rng)).take(size).collect()
98117
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,21 @@ fn test_read_write_primitive() -> hdf5::Result<()> {
313313
Ok(())
314314
}
315315

316+
#[cfg(feature = "f16")]
317+
#[test]
318+
fn test_read_write_f16() -> hdf5::Result<()> {
319+
test_read_write::<::half::f16>()?;
320+
Ok(())
321+
}
322+
323+
#[cfg(feature = "complex")]
324+
#[test]
325+
fn test_read_write_complex() -> hdf5::Result<()> {
326+
test_read_write::<::num_complex::Complex32>()?;
327+
test_read_write::<::num_complex::Complex64>()?;
328+
Ok(())
329+
}
330+
316331
#[test]
317332
fn test_read_write_enum() -> hdf5::Result<()> {
318333
test_read_write::<Enum>()

0 commit comments

Comments
 (0)