1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use wolfram_library_link::{self as wll, DataStore, NumericArray};


#[wll::export]
fn test_na_automatic_count(array: &NumericArray) -> i64 {
    array.share_count() as i64
}

#[wll::export]
fn test_na_constant_count(array: &NumericArray) -> i64 {
    array.share_count() as i64
}

#[wll::export]
fn test_na_manual_count(array: NumericArray) -> i64 {
    array.share_count() as i64
}

#[wll::export]
fn test_na_shared_count(array: NumericArray) -> i64 {
    array.share_count() as i64
}

//

#[wll::export]
fn test_na_constant_are_ptr_eq(
    array1: &NumericArray<i64>,
    array2: &NumericArray<i64>,
) -> DataStore {
    let mut data = DataStore::new();
    data.add_bool(array1.ptr_eq(&array2));
    data.add_i64(array1.share_count() as i64);
    data
}

#[wll::export]
fn test_na_manual_are_not_ptr_eq(
    mut array1: NumericArray<i64>,
    array2: NumericArray<i64>,
) -> DataStore {
    let mut data = DataStore::new();
    data.add_bool(array1.ptr_eq(&array2));
    data.add_i64(array1.share_count() as i64);
    data.add_bool(array1.as_slice_mut().is_some());
    data
}

#[wll::export]
fn test_na_shared_are_ptr_eq(
    mut array1: NumericArray<i64>,
    array2: NumericArray<i64>,
) -> DataStore {
    let mut data = DataStore::new();
    data.add_bool(array1.ptr_eq(&array2));
    data.add_i64(array1.share_count() as i64);
    data.add_bool(array1.as_slice_mut().is_some());
    data
}

//----------------------------
// Test cloning NumericArray's
//----------------------------

#[wll::export]
fn test_na_clone() -> bool {
    let array = NumericArray::<i64>::from_slice(&[1, 2, 3]);

    assert!(array.share_count() == 0);

    let clone = array.clone();

    assert!(!array.ptr_eq(&clone));

    assert!(array.share_count() == 0);
    assert!(clone.share_count() == 0);

    true
}

#[wll::export]
fn test_na_shared_clone(array: NumericArray<i64>) -> bool {
    assert!(array.share_count() == 1);

    let clone = array.clone();

    assert!(!array.ptr_eq(&clone));

    assert!(array.share_count() == 1);
    assert!(clone.share_count() == 0);

    true
}