Skip to content

Commit d152c36

Browse files
upgrade to current hdf5-sys and rust
1 parent 14917d0 commit d152c36

File tree

3 files changed

+85
-78
lines changed

3 files changed

+85
-78
lines changed

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "numeric"
3-
version = "0.1.4"
3+
version = "0.2.0"
44
authors = ["Gustav Larsson <[email protected]>"]
55
description = "N-dimensional matrix class for Rust"
66
repository = "https://github.com/numeric-rust/numeric"
@@ -11,12 +11,12 @@ keywords = ["numeric", "tensor", "matrix", "vector", "hdf5"]
1111
license = "MIT"
1212

1313
[dependencies]
14-
blas = "0.9.1"
15-
lapack = "0.8.1"
16-
num = "0.1.29"
17-
rand = "0.3.12"
18-
libc = "0.2.4"
19-
hdf5-sys = "0.3.2"
14+
blas = "0.22.0"
15+
lapack = "0.19.0"
16+
num = "0.4.0"
17+
rand = "0.8.3"
18+
libc = "0.2.94"
19+
hdf5-sys = "0.7.1"
2020

2121
[[test]]
2222
name = "numeric"

src/io/mod.rs

Lines changed: 76 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ extern crate std;
4444
use libc::{c_char, c_void};
4545
use std::path::Path;
4646
use hdf5_sys as ffi;
47+
use hdf5_sys::h5d;
48+
use hdf5_sys::h5t;
49+
use hdf5_sys::h5p;
50+
use hdf5_sys::h5f;
51+
use hdf5_sys::h5e;
52+
use hdf5_sys::h5s;
4753

4854
use tensor::Tensor;
4955

@@ -71,30 +77,30 @@ macro_rules! add_save {
7177
let group = "data";
7278

7379
unsafe {
74-
let filename_cstr = try!(::std::ffi::CString::new(filename));
75-
let group_cstr = try!(::std::ffi::CString::new(group));
80+
let filename_cstr = ::std::ffi::CString::new(filename)?;
81+
let group_cstr = ::std::ffi::CString::new(group)?;
7682

77-
//ffi::H5Eset_auto2(0, error_handler, 0 as *const c_void);
83+
//h5e::H5Eset_auto2(0, error_handler, 0 as *const c_void);
7884

79-
let file = ffi::H5Fcreate(filename_cstr.as_ptr() as *const c_char,
80-
ffi::H5F_ACC_TRUNC, ffi::H5P_DEFAULT, ffi::H5P_DEFAULT);
85+
let file = h5f::H5Fcreate(filename_cstr.as_ptr() as *const c_char,
86+
h5f::H5F_ACC_TRUNC, h5p::H5P_DEFAULT, h5p::H5P_DEFAULT);
8187

8288
let mut shape: Vec<u64> = Vec::new();
8389
for s in self.shape().iter() {
8490
shape.push(*s as u64);
8591
}
8692

87-
let space = ffi::H5Screate_simple(shape.len() as i32, shape.as_ptr(),
93+
let space = h5s::H5Screate_simple(shape.len() as i32, shape.as_ptr(),
8894
std::ptr::null());
8995

90-
let dset = ffi::H5Dcreate2(file, group_cstr.as_ptr() as *const c_char,
96+
let dset = h5d::H5Dcreate2(file, group_cstr.as_ptr() as *const c_char,
9197
$h5type, space,
92-
ffi::H5P_DEFAULT,
93-
ffi::H5P_DEFAULT,
94-
ffi::H5P_DEFAULT);
98+
h5p::H5P_DEFAULT,
99+
h5p::H5P_DEFAULT,
100+
h5p::H5P_DEFAULT);
95101

96-
let status = ffi::H5Dwrite(dset, $h5type, ffi::H5S_ALL, ffi::H5S_ALL,
97-
ffi::H5P_DEFAULT, self.as_ptr() as * const c_void);
102+
let status = h5d::H5Dwrite(dset, $h5type, h5s::H5S_ALL, h5s::H5S_ALL,
103+
h5p::H5P_DEFAULT, self.as_ptr() as * const c_void);
98104

99105
if status < 0 {
100106
let msg = format!("Failed to write '{}': {:?}", group, path);
@@ -103,25 +109,25 @@ macro_rules! add_save {
103109
}
104110

105111

106-
ffi::H5Dclose(dset);
107-
ffi::H5Fclose(file);
112+
h5d::H5Dclose(dset);
113+
h5f::H5Fclose(file);
108114
}
109115
Ok(())
110116
}
111117
}
112118
)
113119
}
114120

115-
add_save!(u8, ffi::H5T_NATIVE_UINT8);
116-
add_save!(u16, ffi::H5T_NATIVE_UINT16);
117-
add_save!(u32, ffi::H5T_NATIVE_UINT32);
118-
add_save!(u64, ffi::H5T_NATIVE_UINT64);
119-
add_save!(i8, ffi::H5T_NATIVE_INT8);
120-
add_save!(i16, ffi::H5T_NATIVE_INT16);
121-
add_save!(i32, ffi::H5T_NATIVE_INT32);
122-
add_save!(i64, ffi::H5T_NATIVE_INT64);
123-
add_save!(f32, ffi::H5T_NATIVE_FLOAT);
124-
add_save!(f64, ffi::H5T_NATIVE_DOUBLE);
121+
add_save!(u8, h5t::H5T_NATIVE_UINT8);
122+
add_save!(u16, h5t::H5T_NATIVE_UINT16);
123+
add_save!(u32, h5t::H5T_NATIVE_UINT32);
124+
add_save!(u64, h5t::H5T_NATIVE_UINT64);
125+
add_save!(i8, h5t::H5T_NATIVE_INT8);
126+
add_save!(i16, h5t::H5T_NATIVE_INT16);
127+
add_save!(i32, h5t::H5T_NATIVE_INT32);
128+
add_save!(i64, h5t::H5T_NATIVE_INT64);
129+
add_save!(f32, h5t::H5T_NATIVE_FLOAT);
130+
add_save!(f64, h5t::H5T_NATIVE_DOUBLE);
125131

126132

127133
macro_rules! add_load {
@@ -137,38 +143,38 @@ macro_rules! add_load {
137143
},
138144
};
139145
unsafe {
140-
let filename_cstr = try!(::std::ffi::CString::new(filename));
141-
let group_cstr = try!(::std::ffi::CString::new(group));
146+
let filename_cstr = ::std::ffi::CString::new(filename)?;
147+
let group_cstr = ::std::ffi::CString::new(group)?;
142148

143-
ffi::H5Eset_auto2(0, error_handler, 0 as *const c_void);
149+
h5e::H5Eset_auto2(0, error_handler, 0 as *const c_void);
144150

145-
let file = ffi::H5Fopen(filename_cstr.as_ptr() as *const c_char,
146-
ffi::H5F_ACC_RDONLY, ffi::H5P_DEFAULT);
151+
let file = h5f::H5Fopen(filename_cstr.as_ptr() as *const c_char,
152+
h5f::H5F_ACC_RDONLY, h5p::H5P_DEFAULT);
147153

148154
if file < 0 {
149155
let msg = format!("File not found: {:?}", path);
150156
let err = std::io::Error::new(std::io::ErrorKind::NotFound, msg);
151157
return Err(err);
152158
}
153159

154-
let dset = ffi::H5Dopen2(file, group_cstr.as_ptr() as *const c_char,
155-
ffi::H5P_DEFAULT);
160+
let dset = h5d::H5Dopen2(file, group_cstr.as_ptr() as *const c_char,
161+
h5p::H5P_DEFAULT);
156162

157163
if dset < 0 {
158164
let msg = format!("Group '{}' not found: {}", group, filename);
159165
let err = std::io::Error::new(std::io::ErrorKind::NotFound, msg);
160166
return Err(err);
161167
}
162168

163-
let datatype = ffi::H5Dget_type(dset);
169+
let datatype = h5d::H5Dget_type(dset);
164170

165-
let space = ffi::H5Dget_space(dset);
166-
let ndims = ffi::H5Sget_simple_extent_ndims(space);
171+
let space = h5d::H5Dget_space(dset);
172+
let ndims = h5s::H5Sget_simple_extent_ndims(space);
167173

168-
let mut shape: Tensor<ffi::hsize_t> = Tensor::zeros(&[ndims as usize]);
174+
let mut shape: Tensor<h5d::hsize_t> = Tensor::zeros(&[ndims as usize]);
169175

170-
if ffi::H5Sget_simple_extent_dims(space, shape.as_mut_ptr(),
171-
0 as *mut ffi::hsize_t) != ndims {
176+
if h5s::H5Sget_simple_extent_dims(space, shape.as_mut_ptr(),
177+
0 as *mut h5d::hsize_t) != ndims {
172178
let msg = format!("Could not read shape of tesor: {}", filename);
173179
let err = std::io::Error::new(std::io::ErrorKind::InvalidData, msg);
174180
return Err(err);
@@ -179,65 +185,65 @@ macro_rules! add_load {
179185
let unsigned_shape = &unsigned_tensor.data();
180186

181187
let data: Tensor<$t> = {
182-
if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_UINT8) == 1 {
188+
if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_UINT8) == 1 {
183189
let mut native_data: Tensor<u8> = Tensor::empty(&unsigned_shape[..]);
184190
// Finally load the actual data
185-
ffi::H5Dread(dset, ffi::H5T_NATIVE_UINT8, ffi::H5S_ALL, ffi::H5S_ALL,
186-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
191+
h5d::H5Dread(dset, h5t::H5T_NATIVE_UINT8, h5s::H5S_ALL, h5s::H5S_ALL,
192+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
187193
native_data.convert::<$t>()
188-
} else if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_INT8) == 1 {
194+
} else if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_INT8) == 1 {
189195
let mut native_data: Tensor<i8> = Tensor::empty(&unsigned_shape[..]);
190196
// Finally load the actual data
191-
ffi::H5Dread(dset, ffi::H5T_NATIVE_INT8, ffi::H5S_ALL, ffi::H5S_ALL,
192-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
197+
h5d::H5Dread(dset, h5t::H5T_NATIVE_INT8, h5s::H5S_ALL, h5s::H5S_ALL,
198+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
193199
native_data.convert::<$t>()
194-
} else if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_UINT16) == 1 {
200+
} else if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_UINT16) == 1 {
195201
let mut native_data: Tensor<u16> = Tensor::empty(&unsigned_shape[..]);
196202
// Finally load the actual data
197-
ffi::H5Dread(dset, ffi::H5T_NATIVE_UINT16, ffi::H5S_ALL, ffi::H5S_ALL,
198-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
203+
h5d::H5Dread(dset, h5t::H5T_NATIVE_UINT16, h5s::H5S_ALL, h5s::H5S_ALL,
204+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
199205
native_data.convert::<$t>()
200-
} else if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_INT16) == 1 {
206+
} else if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_INT16) == 1 {
201207
let mut native_data: Tensor<i16> = Tensor::empty(&unsigned_shape[..]);
202208
// Finally load the actual data
203-
ffi::H5Dread(dset, ffi::H5T_NATIVE_INT16, ffi::H5S_ALL, ffi::H5S_ALL,
204-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
209+
h5d::H5Dread(dset, h5t::H5T_NATIVE_INT16, h5s::H5S_ALL, h5s::H5S_ALL,
210+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
205211
native_data.convert::<$t>()
206-
} else if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_UINT32) == 1 {
212+
} else if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_UINT32) == 1 {
207213
let mut native_data: Tensor<u32> = Tensor::empty(&unsigned_shape[..]);
208214
// Finally load the actual data
209-
ffi::H5Dread(dset, ffi::H5T_NATIVE_UINT32, ffi::H5S_ALL, ffi::H5S_ALL,
210-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
215+
h5d::H5Dread(dset, h5t::H5T_NATIVE_UINT32, h5s::H5S_ALL, h5s::H5S_ALL,
216+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
211217
native_data.convert::<$t>()
212-
} else if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_INT32) == 1 {
218+
} else if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_INT32) == 1 {
213219
let mut native_data: Tensor<i32> = Tensor::empty(&unsigned_shape[..]);
214220
// Finally load the actual data
215-
ffi::H5Dread(dset, ffi::H5T_NATIVE_INT32, ffi::H5S_ALL, ffi::H5S_ALL,
216-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
221+
h5d::H5Dread(dset, h5t::H5T_NATIVE_INT32, h5s::H5S_ALL, h5s::H5S_ALL,
222+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
217223
native_data.convert::<$t>()
218-
} else if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_UINT64) == 1 {
224+
} else if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_UINT64) == 1 {
219225
let mut native_data: Tensor<u64> = Tensor::empty(&unsigned_shape[..]);
220226
// Finally load the actual data
221-
ffi::H5Dread(dset, ffi::H5T_NATIVE_UINT64, ffi::H5S_ALL, ffi::H5S_ALL,
222-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
227+
h5d::H5Dread(dset, h5t::H5T_NATIVE_UINT64, h5s::H5S_ALL, h5s::H5S_ALL,
228+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
223229
native_data.convert::<$t>()
224-
} else if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_INT64) == 1 {
230+
} else if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_INT64) == 1 {
225231
let mut native_data: Tensor<i64> = Tensor::empty(&unsigned_shape[..]);
226232
// Finally load the actual data
227-
ffi::H5Dread(dset, ffi::H5T_NATIVE_INT64, ffi::H5S_ALL, ffi::H5S_ALL,
228-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
233+
h5d::H5Dread(dset, h5t::H5T_NATIVE_INT64, h5s::H5S_ALL, h5s::H5S_ALL,
234+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
229235
native_data.convert::<$t>()
230-
} else if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_FLOAT) == 1 {
236+
} else if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_FLOAT) == 1 {
231237
let mut native_data: Tensor<f32> = Tensor::empty(&unsigned_shape[..]);
232238
// Finally load the actual data
233-
ffi::H5Dread(dset, ffi::H5T_NATIVE_FLOAT, ffi::H5S_ALL, ffi::H5S_ALL,
234-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
239+
h5d::H5Dread(dset, h5t::H5T_NATIVE_FLOAT, h5s::H5S_ALL, h5s::H5S_ALL,
240+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
235241
native_data.convert::<$t>()
236-
} else if ffi::H5Tequal(datatype, ffi::H5T_NATIVE_DOUBLE) == 1 {
242+
} else if h5t::H5Tequal(datatype, h5t::H5T_NATIVE_DOUBLE) == 1 {
237243
let mut native_data: Tensor<f64> = Tensor::empty(&unsigned_shape[..]);
238244
// Finally load the actual data
239-
ffi::H5Dread(dset, ffi::H5T_NATIVE_DOUBLE, ffi::H5S_ALL, ffi::H5S_ALL,
240-
ffi::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
245+
h5d::H5Dread(dset, h5t::H5T_NATIVE_DOUBLE, h5s::H5S_ALL, h5s::H5S_ALL,
246+
h5p::H5P_DEFAULT, native_data.as_mut_ptr() as *mut c_void);
241247
native_data.convert::<$t>()
242248
} else {
243249
let msg = format!("Unable to convert '{}' to {}: {}",
@@ -247,9 +253,9 @@ macro_rules! add_load {
247253
}
248254
};
249255

250-
ffi::H5Tclose(datatype);
251-
ffi::H5Dclose(dset);
252-
ffi::H5Fclose(file);
256+
h5t::H5Tclose(datatype);
257+
h5d::H5Dclose(dset);
258+
h5f::H5Fclose(file);
253259

254260
Ok(data)
255261
}

src/random/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
//! // 0.702227 0.346673 0.737954
1717
//! // [Tensor<f64> of shape 3x3]
1818
//! ```
19-
use rand::{Rng, SeedableRng, StdRng};
19+
use rand::{Rng, SeedableRng};
20+
use rand::rngs::StdRng;
2021
use rand::distributions::range::SampleRange;
2122
use num::traits::Float;
2223
use std::f64;

0 commit comments

Comments
 (0)