Skip to content

Commit f66736d

Browse files
committed
Associated method for empty Array creation
1 parent 95c9ec5 commit f66736d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/array.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extern {
1818
fn af_create_array(out: MutAfArray, data: *const c_void,
1919
ndims: c_uint, dims: *const DimT, aftype: uint8_t) -> c_int;
2020

21+
fn af_create_handle(out: MutAfArray, ndims: c_uint, dims: *const DimT, aftype: uint8_t) -> c_int;
22+
2123
fn af_get_elements(out: MutAfArray, arr: AfArray) -> c_int;
2224

2325
fn af_get_type(out: *mut c_int, arr: AfArray) -> c_int;
@@ -175,6 +177,27 @@ impl Array {
175177
}
176178
}
177179

180+
/// Constructs a new Array object of specified dimensions and type
181+
///
182+
/// # Examples
183+
///
184+
/// ```rust
185+
/// use arrayfire::{Array, Dim4, DType};
186+
/// let garbageVals = Array::new_empty(Dim4::new(&[3, 1, 1, 1]), DType::F32);
187+
/// ```
188+
#[allow(unused_mut)]
189+
pub fn new_empty(dims: Dim4, aftype: DType) -> Array {
190+
unsafe {
191+
let mut temp: i64 = 0;
192+
let err_val = af_create_handle(&mut temp as MutAfArray,
193+
dims.ndims() as c_uint,
194+
dims.get().as_ptr() as * const c_longlong,
195+
aftype as uint8_t);
196+
HANDLE_ERROR(AfError::from(err_val));
197+
Array::from(temp)
198+
}
199+
}
200+
178201
/// Returns the backend of the Array
179202
///
180203
/// # Return Values

0 commit comments

Comments
 (0)