Skip to content

Update ndarray to Rust 2018 edition #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sudo: required
dist: trusty
matrix:
include:
- rust: 1.30.0
- rust: 1.31.0
env:
- FEATURES='test docs'
- rust: stable
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

name = "ndarray"
version = "0.12.1"
edition = "2018"
authors = [
"bluss",
"Jim Turner"
Expand Down
4 changes: 2 additions & 2 deletions src/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
//!

#[allow(deprecated)]
use ::{
use crate::{
Ix,
Array,
ArrayView,
ArrayViewMut,
RcArray,
IxDynImpl,
};
use ::dimension::Dim;
use crate::dimension::Dim;

/// Create a zero-dimensional index
#[allow(non_snake_case)]
Expand Down
46 changes: 23 additions & 23 deletions src/array_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use serde::ser::{SerializeSeq, SerializeStruct};
use std::fmt;
use std::marker::PhantomData;

use imp_prelude::*;
use crate::imp_prelude::*;

use super::arraytraits::ARRAY_FORMAT_VERSION;
use super::Iter;
use IntoDimension;
use crate::IntoDimension;

/// Verifies that the version of the deserialized array matches the current
/// `ARRAY_FORMAT_VERSION`.
Expand All @@ -25,10 +25,10 @@ pub fn verify_version<E>(v: u8) -> Result<(), E>
{
if v != ARRAY_FORMAT_VERSION {
let err_msg = format!("unknown array version: {}", v);
try!(Err(de::Error::custom(err_msg)));
Err(de::Error::custom(err_msg))
} else {
Ok(())
}

Ok(())
}

/// **Requires crate feature `"serde-1"`**
Expand Down Expand Up @@ -84,10 +84,10 @@ impl<A, D, S> Serialize for ArrayBase<S, D>
fn serialize<Se>(&self, serializer: Se) -> Result<Se::Ok, Se::Error>
where Se: Serializer
{
let mut state = try!(serializer.serialize_struct("Array", 3));
try!(state.serialize_field("v", &ARRAY_FORMAT_VERSION));
try!(state.serialize_field("dim", &self.raw_dim()));
try!(state.serialize_field("data", &Sequence(self.iter())));
let mut state = serializer.serialize_struct("Array", 3)?;
state.serialize_field("v", &ARRAY_FORMAT_VERSION)?;
state.serialize_field("dim", &self.raw_dim())?;
state.serialize_field("data", &Sequence(self.iter()))?;
state.end()
}
}
Expand All @@ -103,9 +103,9 @@ impl<'a, A, D> Serialize for Sequence<'a, A, D>
where S: Serializer
{
let iter = &self.0;
let mut seq = try!(serializer.serialize_seq(Some(iter.len())));
let mut seq = serializer.serialize_seq(Some(iter.len()))?;
for elt in iter.clone() {
try!(seq.serialize_element(elt));
seq.serialize_element(elt)?;
}
seq.end()
}
Expand Down Expand Up @@ -197,23 +197,23 @@ impl<'de, A, Di, S> Visitor<'de> for ArrayVisitor<S,Di>
fn visit_seq<V>(self, mut visitor: V) -> Result<ArrayBase<S, Di>, V::Error>
where V: SeqAccess<'de>,
{
let v: u8 = match try!(visitor.next_element()) {
let v: u8 = match visitor.next_element()? {
Some(value) => value,
None => {
return Err(de::Error::invalid_length(0, &self));
}
};

try!(verify_version(v));
verify_version(v)?;

let dim: Di = match try!(visitor.next_element()) {
let dim: Di = match visitor.next_element()? {
Some(value) => value,
None => {
return Err(de::Error::invalid_length(1, &self));
}
};

let data: Vec<A> = match try!(visitor.next_element()) {
let data: Vec<A> = match visitor.next_element()? {
Some(value) => value,
None => {
return Err(de::Error::invalid_length(2, &self));
Expand All @@ -234,35 +234,35 @@ impl<'de, A, Di, S> Visitor<'de> for ArrayVisitor<S,Di>
let mut data: Option<Vec<A>> = None;
let mut dim: Option<Di> = None;

while let Some(key) = try!(visitor.next_key()) {
while let Some(key) = visitor.next_key()? {
match key {
ArrayField::Version => {
let val = try!(visitor.next_value());
try!(verify_version(val));
let val = visitor.next_value()?;
verify_version(val)?;
v = Some(val);
},
ArrayField::Data => {
data = Some(try!(visitor.next_value()));
data = Some(visitor.next_value()?);
},
ArrayField::Dim => {
dim = Some(try!(visitor.next_value()));
dim = Some(visitor.next_value()?);
},
}
}

let _v = match v {
Some(v) => v,
None => try!(Err(de::Error::missing_field("v"))),
None => Err(de::Error::missing_field("v"))?,
};

let data = match data {
Some(data) => data,
None => try!(Err(de::Error::missing_field("data"))),
None => Err(de::Error::missing_field("data"))?,
};

let dim = match dim {
Some(dim) => dim,
None => try!(Err(de::Error::missing_field("dim"))),
None => Err(de::Error::missing_field("dim"))?,
};

if let Ok(array) = ArrayBase::from_shape_vec(dim, data) {
Expand Down
20 changes: 10 additions & 10 deletions src/arrayformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{
Dimension,
NdProducer,
};
use dimension::IntoDimension;
use crate::dimension::IntoDimension;

fn format_array<A, S, D, F>(view: &ArrayBase<S, D>, f: &mut fmt::Formatter,
mut format: F)
Expand All @@ -33,7 +33,7 @@ fn format_array<A, S, D, F>(view: &ArrayBase<S, D>, f: &mut fmt::Formatter,
Some(ix) => ix,
};
for _ in 0..ndim {
try!(write!(f, "["));
write!(f, "[")?;
}
let mut first = true;
// Simply use the indexed iterator, and take the index wraparounds
Expand All @@ -52,33 +52,33 @@ fn format_array<A, S, D, F>(view: &ArrayBase<S, D>, f: &mut fmt::Formatter,
// # of ['s needed
let n = ndim - i - 1;
for _ in 0..n {
try!(write!(f, "]"));
write!(f, "]")?;
}
try!(write!(f, ","));
try!(write!(f, "\n"));
write!(f, ",")?;
write!(f, "\n")?;
for _ in 0..ndim - n {
try!(write!(f, " "));
write!(f, " ")?;
}
for _ in 0..n {
try!(write!(f, "["));
write!(f, "[")?;
}
first = true;
update_index = true;
break;
}
}
if !first {
try!(write!(f, ", "));
write!(f, ", ")?;
}
first = false;
try!(format(elt, f));
format(elt, f)?;

if update_index {
last_index = index;
}
}
for _ in 0..ndim {
try!(write!(f, "]"));
write!(f, "]")?;
}
Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions src/arraytraits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ use std::ops::{
IndexMut,
};

use imp_prelude::*;
use iter::{
use crate::imp_prelude::*;
use crate::iter::{
Iter,
IterMut,
};
use {
use crate::{
NdIndex,
};

use numeric_util;
use {Zip, FoldWhile};
use crate::numeric_util;
use crate::{Zip, FoldWhile};

#[cold]
#[inline(never)]
Expand Down
4 changes: 2 additions & 2 deletions src/data_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::mem::{self, size_of};
use std::sync::Arc;

use {
use crate::{
ArrayBase,
Dimension,
RawViewRepr,
Expand Down Expand Up @@ -52,7 +52,7 @@ pub unsafe trait RawDataMut : RawData {
/// If `Self` provides safe mutable access to array elements, then it
/// **must** panic or ensure that the data is unique.
#[doc(hidden)]
fn try_ensure_unique<D>(&mut ArrayBase<Self, D>)
fn try_ensure_unique<D>(_: &mut ArrayBase<Self, D>)
where Self: Sized,
D: Dimension;

Expand Down
2 changes: 1 addition & 1 deletion src/dimension/axes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

use {Dimension, Axis, Ix, Ixs};
use crate::{Dimension, Axis, Ix, Ixs};

/// Create a new Axes iterator
pub fn axes_of<'a, D>(d: &'a D, strides: &'a D) -> Axes<'a, D>
Expand Down
4 changes: 2 additions & 2 deletions src/dimension/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
//! Tuple to array conversion, IntoDimension, and related things

use std::ops::{Index, IndexMut};
use libnum::Zero;
use num_traits::Zero;

use {Ix, Ix1, IxDyn, Dimension, Dim, IxDynImpl};
use crate::{Ix, Ix1, IxDyn, Dimension, Dim, IxDynImpl};

/// $m: macro callback
/// $m is called with $arg and then the indices corresponding to the size argument
Expand Down
2 changes: 1 addition & 1 deletion src/dimension/dim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use itertools::zip;

use super::IntoDimension;
use super::Dimension;
use Ix;
use crate::Ix;

/// Dimension description.
///
Expand Down
10 changes: 5 additions & 5 deletions src/dimension/dimension_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use std::ops::{Add, Sub, Mul, AddAssign, SubAssign, MulAssign};

use itertools::{enumerate, izip, zip};

use {Ix, Ixs, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, Dim, SliceOrIndex, IxDynImpl};
use IntoDimension;
use RemoveAxis;
use {ArrayView1, ArrayViewMut1};
use Axis;
use crate::{Ix, Ixs, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, Dim, SliceOrIndex, IxDynImpl};
use crate::IntoDimension;
use crate::RemoveAxis;
use crate::{ArrayView1, ArrayViewMut1};
use crate::Axis;
use super::{
stride_offset,
stride_offset_checked,
Expand Down
4 changes: 2 additions & 2 deletions src/dimension/dynindeximpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ops::{
Deref,
DerefMut,
};
use imp_prelude::*;
use crate::imp_prelude::*;

const CAP: usize = 4;

Expand Down Expand Up @@ -53,7 +53,7 @@ impl Default for IxDynRepr<Ix> {
}


use ::libnum::Zero;
use num_traits::Zero;

impl<T: Copy + Zero> IxDynRepr<T> {
pub fn copy_from(x: &[T]) -> Self {
Expand Down
10 changes: 5 additions & 5 deletions src/dimension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use {Ix, Ixs, Slice, SliceOrIndex};
use error::{from_kind, ErrorKind, ShapeError};
use crate::{Ix, Ixs, Slice, SliceOrIndex};
use crate::error::{from_kind, ErrorKind, ShapeError};
use itertools::izip;
use num_integer::div_floor;

Expand Down Expand Up @@ -621,11 +621,11 @@ mod test {
max_abs_offset_check_overflow, slice_min_max, slices_intersect,
solve_linear_diophantine_eq, IntoDimension
};
use error::{from_kind, ErrorKind};
use crate::{Dim, Dimension, Ix0, Ix1, Ix2, Ix3, IxDyn};
use crate::error::{from_kind, ErrorKind};
use crate::slice::Slice;
use num_integer::gcd;
use quickcheck::{quickcheck, TestResult};
use slice::{Slice, SliceOrIndex};
use {Dim, Dimension, Ix0, Ix1, Ix2, Ix3, IxDyn};

#[test]
fn slice_indexing_uncommon_strides() {
Expand Down
5 changes: 1 addition & 4 deletions src/dimension/ndindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::fmt::Debug;

use itertools::zip;

use {Ix, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, Dim, Dimension, IntoDimension};
use {
IxDynImpl,
};
use crate::{Ix, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, IxDynImpl, Dim, Dimension, IntoDimension};
use super::{stride_offset, stride_offset_checked};

/// Tuple or fixed size arrays that can be used to index an array.
Expand Down
2 changes: 1 addition & 1 deletion src/dimension/remove_axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// except according to those terms.


use {Ix, Ix0, Ix1, Dimension, Dim, Axis};
use crate::{Ix, Ix0, Ix1, Dimension, Dim, Axis};

/// Array shape with a next smaller dimension.
///
Expand Down
4 changes: 2 additions & 2 deletions src/free_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use std::slice;
use std::mem::{size_of, forget};

use dimension;
use imp_prelude::*;
use crate::dimension;
use crate::imp_prelude::*;

/// Create an [**`Array`**](type.Array.html) with one, two or
/// three dimensions.
Expand Down
Loading