Skip to content

Commit 5170250

Browse files
committed
Delegate scalar arithmetic ops to function versions
Earlier to this change, the arithmetic trait implementations used to call the C-API directly.
1 parent 607c96a commit 5170250

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

src/arith/mod.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ macro_rules! convertable_type_def {
217217
)
218218
}
219219

220+
convertable_type_def!(Complex<f64>);
221+
convertable_type_def!(Complex<f32>);
220222
convertable_type_def!(u64);
221223
convertable_type_def!(i64);
222224
convertable_type_def!(f64);
@@ -355,29 +357,17 @@ macro_rules! arith_scalar_func {
355357
type Output = Array;
356358

357359
fn $fn_name(self, rhs: $rust_type) -> Array {
358-
let cnst_arr = constant(rhs, self.dims());
359-
unsafe {
360-
let mut temp: i64 = 0;
361-
let err_val = $ffi_fn(&mut temp as MutAfArray, self.get() as AfArray,
362-
cnst_arr.get() as AfArray, 0);
363-
HANDLE_ERROR(AfError::from(err_val));
364-
Array::from(temp)
365-
}
360+
let temp = rhs.clone();
361+
add(self, &temp, false)
366362
}
367363
}
368364

369365
impl $op_name<$rust_type> for Array {
370366
type Output = Array;
371367

372368
fn $fn_name(self, rhs: $rust_type) -> Array {
373-
let cnst_arr = constant(rhs, self.dims());
374-
unsafe {
375-
let mut temp: i64 = 0;
376-
let err_val = $ffi_fn(&mut temp as MutAfArray, self.get() as AfArray,
377-
cnst_arr.get() as AfArray, 0);
378-
HANDLE_ERROR(AfError::from(err_val));
379-
Array::from(temp)
380-
}
369+
let temp = rhs.clone();
370+
add(&self, &temp, false)
381371
}
382372
}
383373
)

0 commit comments

Comments
 (0)