Skip to content

Commit

Permalink
Merge pull request #741 from d-dorazio/add-arc-array-aliases
Browse files Browse the repository at this point in the history
add ArcArray1 and ArcArray2 aliases
  • Loading branch information
bluss authored Oct 7, 2019
2 parents ad7efff + fe41ca3 commit a7d4988
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions serialization-tests/tests/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate rmp_serde;
#[cfg(feature = "ron")]
extern crate ron;

use ndarray::{arr0, arr1, arr2, s, ArcArray, ArrayD, Ix2, IxDyn};
use ndarray::{arr0, arr1, arr2, s, ArcArray, ArcArray2, ArrayD, IxDyn};

#[test]
fn serial_many_dim_serde() {
Expand Down Expand Up @@ -98,13 +98,13 @@ fn serial_ixdyn_serde() {
fn serial_wrong_count_serde() {
// one element too few
let text = r##"{"v":1,"dim":[2,3],"data":[3,1,2.2,3.1,4]}"##;
let arr = serde_json::from_str::<ArcArray<f32, Ix2>>(text);
let arr = serde_json::from_str::<ArcArray2<f32>>(text);
println!("{:?}", arr);
assert!(arr.is_err());

// future version
let text = r##"{"v":200,"dim":[2,3],"data":[3,1,2.2,3.1,4,7]}"##;
let arr = serde_json::from_str::<ArcArray<f32, Ix2>>(text);
let arr = serde_json::from_str::<ArcArray2<f32>>(text);
println!("{:?}", arr);
assert!(arr.is_err());
}
Expand Down
7 changes: 6 additions & 1 deletion src/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::dimension::Dim;
#[allow(deprecated)]
use crate::{Array, ArrayView, ArrayViewMut, Ix, IxDynImpl, RcArray};
use crate::{ArcArray, Array, ArrayView, ArrayViewMut, Ix, IxDynImpl, RcArray};

/// Create a zero-dimensional index
#[allow(non_snake_case)]
Expand Down Expand Up @@ -158,3 +158,8 @@ pub type RcArray1<A> = RcArray<A, Ix1>;
#[allow(deprecated)]
#[deprecated(note = "`RcArray` has been renamed to `ArcArray`")]
pub type RcArray2<A> = RcArray<A, Ix2>;

/// one-dimensional shared ownership array
pub type ArcArray1<A> = ArcArray<A, Ix1>;
/// two-dimensional shared ownership array
pub type ArcArray2<A> = ArcArray<A, Ix2>;
6 changes: 3 additions & 3 deletions src/free_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use std::mem::{forget, size_of};
use std::slice;

use crate::dimension;
use crate::imp_prelude::*;
use crate::{dimension, ArcArray1, ArcArray2};

/// Create an [**`Array`**](type.Array.html) with one, two or
/// three dimensions.
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn arr1<A: Clone>(xs: &[A]) -> Array1<A> {
}

/// Create a one-dimensional array with elements from `xs`.
pub fn rcarr1<A: Clone>(xs: &[A]) -> ArcArray<A, Ix1> {
pub fn rcarr1<A: Clone>(xs: &[A]) -> ArcArray1<A> {
arr1(xs).into_shared()
}

Expand Down Expand Up @@ -289,7 +289,7 @@ where

/// Create a two-dimensional array with elements from `xs`.
///
pub fn rcarr2<A: Clone, V: Clone + FixedInitializer<Elem = A>>(xs: &[V]) -> ArcArray<A, Ix2> {
pub fn rcarr2<A: Clone, V: Clone + FixedInitializer<Elem = A>>(xs: &[V]) -> ArcArray2<A> {
arr2(xs).into_shared()
}

Expand Down

0 comments on commit a7d4988

Please sign in to comment.