Skip to content

Commit 9633769

Browse files
committed
Fix for OSX platform w.r.t static arrays
For some reason, directly passing a `&[]` to function that is using OpenCL backend is causing a SEGFAULT. This problem is however is not happening with CPU or CUDA backend. Moving the slice to a independent variable and then borrowing a reference is executing as expected on OSX. This may have to do with slices and the memory they are pointing to, but it is quite puzzling why it only happens on one of three backends.
1 parent 4a3ad46 commit 9633769

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

examples/helloworld.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ fn main() {
1010

1111
let num_rows: u64 = 5;
1212
let num_cols: u64 = 3;
13-
let values: &[f32] = &[1.0, 2.0, 3.0];
14-
let indices = Array::new(values, Dim4::new(&[3, 1, 1, 1]));
13+
let values: [f32; 3] = [1.0, 2.0, 3.0];
14+
let indices = Array::new(&values, Dim4::new(&[3, 1, 1, 1]));
1515

1616
let dims = Dim4::new(&[num_rows, num_cols, 1, 1]);
1717

1818
let a = randu::<f32>(dims);
1919
af_print!("Create a 5-by-3 matrix of random floats on the GPU", a);
2020

2121
println!("Element-wise arithmetic");
22-
let b = add(&sin(&a), &1.5, false);
22+
let b = add(&sin(&a), &1.5f32, false);
2323

2424
let b2 = add(&sin(&a), &cos(&a), false);
2525

src/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ impl Array {
119119
///
120120
/// ```
121121
/// use arrayfire::{Array, Dim4, print};
122-
/// let values: &[f32] = &[1.0, 2.0, 3.0];
123-
/// let indices = Array::new(values, Dim4::new(&[3, 1, 1, 1]));
122+
/// let values: [f32; 3] = [1.0, 2.0, 3.0];
123+
/// let indices = Array::new(&values, Dim4::new(&[3, 1, 1, 1]));
124124
/// print(&indices);
125125
/// ```
126126
#[allow(unused_mut)]
@@ -384,4 +384,4 @@ pub fn print(input: &Array) {
384384
let err_val = af_print_array(input.get() as AfArray);
385385
HANDLE_ERROR(AfError::from(err_val));
386386
}
387-
}
387+
}

src/index.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ pub fn assign_seq<T: Copy>(lhs: &Array, seqs: &[Seq<T>], rhs: &Array) -> Array
315315
///
316316
/// ```
317317
/// use arrayfire::{Array, Dim4, Seq, print, randu, index_gen, Indexer};
318-
/// let values: &[f32] = &[1.0, 2.0, 3.0];
319-
/// let indices = Array::new(values, Dim4::new(&[3, 1, 1, 1]));
318+
/// let values: [f32; 3] = [1.0, 2.0, 3.0];
319+
/// let indices = Array::new(&values, Dim4::new(&[3, 1, 1, 1]));
320320
/// let seq4gen = Seq::new(0.0, 2.0, 1.0);
321321
/// let a = randu::<f32>(Dim4::new(&[5, 3, 1, 1]));
322322
/// // [5 3 1 1]
@@ -354,8 +354,8 @@ pub fn index_gen(input: &Array, indices: Indexer) -> Array {
354354
///
355355
/// ```
356356
/// use arrayfire::{Array, Dim4, Seq, print, randu, constant, Indexer, assign_gen};
357-
/// let values: &[f32] = &[1.0, 2.0, 3.0];
358-
/// let indices = Array::new(values, Dim4::new(&[3, 1, 1, 1]));
357+
/// let values: [f32; 3] = [1.0, 2.0, 3.0];
358+
/// let indices = Array::new(&values, Dim4::new(&[3, 1, 1, 1]));
359359
/// let seq4gen = Seq::new(0.0, 2.0, 1.0);
360360
/// let a = randu::<f32>(Dim4::new(&[5, 3, 1, 1]));
361361
/// // [5 3 1 1]

0 commit comments

Comments
 (0)