Skip to content

Commit 6d5ab72

Browse files
committed
Add new function get_size(DType)
1 parent 9997c9a commit 6d5ab72

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub use statistics::{var_all, mean_all, stdev_all, median_all};
9898
pub use statistics::{mean_all_weighted, var_all_weighted};
9999
mod statistics;
100100

101-
pub use util::{HasAfEnum};
101+
pub use util::{HasAfEnum, get_size};
102102
mod util;
103103

104104
pub use vision::Features;

src/util.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
extern crate libc;
12
extern crate num;
23

34
use defines::{AfError, ColorMap, ConvDomain, ConvMode, DType, InterpType, MatProp, MatchType};
5+
use error::HANDLE_ERROR;
46
use std::mem;
57
use self::num::Complex;
8+
use self::libc::{uint8_t, c_int, size_t};
9+
10+
#[allow(dead_code)]
11+
extern {
12+
fn af_get_size_of(size: *mut size_t, aftype: uint8_t) -> c_int;
13+
}
14+
15+
/// Get size, in bytes, of the arrayfire native type
16+
pub fn get_size(value: DType) -> u64 {
17+
unsafe {
18+
let mut ret_val: u64 = 0;
19+
let err_val = af_get_size_of(&mut ret_val as *mut size_t, value as uint8_t);
20+
HANDLE_ERROR(AfError::from(err_val));
21+
ret_val
22+
}
23+
}
624

725
impl From<i32> for AfError {
826
fn from(t: i32) -> AfError {

0 commit comments

Comments
 (0)