Skip to content

Commit 6937f53

Browse files
authored
Merge pull request #889 from rust-ndarray/nostd-fixups
Setup and tweak rayon, serde, blas features for no-std changes
2 parents 225d967 + 97e33c5 commit 6937f53

File tree

9 files changed

+30
-22
lines changed

9 files changed

+30
-22
lines changed

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@ num-integer = { version = "0.1.39", default-features = false }
3232
num-traits = { version = "0.2", default-features = false }
3333
num-complex = { version = "0.3", default-features = false }
3434

35-
rayon = { version = "1.0.3", optional = true }
35+
# Use via the `rayon` crate feature!
36+
rayon_ = { version = "1.0.3", optional = true, package = "rayon" }
3637

3738
approx = { version = "0.4", optional = true , default-features = false }
3839

3940
# Use via the `blas` crate feature!
4041
cblas-sys = { version = "0.1.4", optional = true, default-features = false }
4142
blas-src = { version = "0.6.1", optional = true, default-features = false }
43+
libc = { version = "0.2.82", optional = true }
4244

4345
matrixmultiply = { version = "0.2.0", default-features = false}
44-
serde = { version = "1.0", optional = true }
46+
serde = { version = "1.0", optional = true, default-features = false, features = ["alloc"] }
4547
rawpointer = { version = "0.2" }
4648

4749
[dev-dependencies]
@@ -55,7 +57,7 @@ default = ["std"]
5557

5658
# Enable blas usage
5759
# See README for more instructions
58-
blas = ["cblas-sys", "blas-src"]
60+
blas = ["cblas-sys", "blas-src", "libc"]
5961

6062
# Old name for the serde feature
6163
serde-1 = ["serde"]
@@ -68,6 +70,7 @@ test = ["test-blas-openblas-sys"]
6870
docs = ["approx", "serde", "rayon"]
6971

7072
std = ["num-traits/std", "matrixmultiply/std"]
73+
rayon = ["rayon_", "std"]
7174

7275
[profile.release]
7376
[profile.bench]

README.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ your `Cargo.toml`.
5050

5151
- ``std``
5252

53-
- Rust Standard Library
53+
- Rust standard library (enabled by default)
5454

5555
- This crate can be used without the standard library by disabling the
5656
default `std` feature. To do so, use this in your `Cargo.toml`:
@@ -63,20 +63,18 @@ your `Cargo.toml`.
6363

6464
- ``serde``
6565

66-
- Optional, compatible with Rust stable
6766
- Enables serialization support for serde 1.x
6867

6968
- ``rayon``
7069

71-
- Optional, compatible with Rust stable
7270
- Enables parallel iterators, parallelized methods and ``par_azip!``.
71+
- Implies std
7372

7473
- ``blas``
7574

76-
- Optional and experimental, compatible with Rust stable
7775
- Enable transparent BLAS support for matrix multiplication.
7876
Uses ``blas-src`` for pluggable backend, which needs to be configured
79-
separately.
77+
separately (see below).
8078

8179
How to use with cargo
8280
---------------------

serialization-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ default = ["ron"]
1515

1616
[dev-dependencies.serde]
1717
version = "1.0.100"
18+
default-features = false
1819

1920
[dev-dependencies.serde_json]
2021
version = "1.0.40"

src/arrayformat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use super::{ArrayBase, ArrayView, Axis, Data, Dimension, NdProducer};
99
use crate::aliases::{Ix1, IxDyn};
1010
use std::fmt;
1111
use alloc::format;
12-
use alloc::string::String;
13-
use alloc::vec::Vec;
1412

1513
/// Default threshold, below this element count, we don't ellipsize
1614
const ARRAY_MANY_ELEMENT_LIMIT: usize = 500;
@@ -290,6 +288,8 @@ where
290288
mod formatting_with_omit {
291289
use itertools::Itertools;
292290
use std::fmt;
291+
use alloc::string::String;
292+
use alloc::vec::Vec;
293293

294294
use super::*;
295295
use crate::prelude::*;

src/impl_constructors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use crate::extension::nonnull::nonnull_from_vec_data;
2424
use crate::imp_prelude::*;
2525
use crate::indexes;
2626
use crate::indices;
27-
use crate::iterators::{to_vec, to_vec_mapped};
27+
#[cfg(feature = "std")]
28+
use crate::iterators::to_vec;
29+
use crate::iterators::to_vec_mapped;
2830
use crate::StrideShape;
2931
#[cfg(feature = "std")]
3032
use crate::{geomspace, linspace, logspace};

src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,23 @@
7070
//! `Cargo.toml`.
7171
//!
7272
//! - `std`
73-
//! - Rust Standard Library
73+
//! - Rust standard library (enabled by default)
7474
//! - This crate can be used without the standard library by disabling the
7575
//! default `std` feature. To do so, use `default-features = false` in
7676
//! your `Cargo.toml`.
7777
//! - The `geomspace` `linspace` `logspace` `range` `std` `var` `var_axis`
78-
//! and `std_axis` methods are only available when `std` is
79-
//! enabled.
78+
//! and `std_axis` methods are only available when `std` is enabled.
8079
//! - `serde`
81-
//! - Optional, compatible with Rust stable
8280
//! - Enables serialization support for serde 1.x
8381
//! - `rayon`
84-
//! - Optional, compatible with Rust stable
8582
//! - Enables parallel iterators, parallelized methods and [`par_azip!`].
83+
//! - Implies std
8684
//! - `approx`
87-
//! - Optional, compatible with Rust stable
8885
//! - Enables implementations of traits from the [`approx`] crate.
8986
//! - `blas`
90-
//! - Optional and experimental, compatible with Rust stable
9187
//! - Enable transparent BLAS support for matrix multiplication.
9288
//! Uses ``blas-src`` for pluggable backend, which needs to be configured
93-
//! separately.
89+
//! separately (see the README).
9490
//!
9591
//! ## Documentation
9692
//!
@@ -1594,6 +1590,8 @@ where
15941590

15951591
// parallel methods
15961592
#[cfg(feature = "rayon")]
1593+
extern crate rayon_ as rayon;
1594+
#[cfg(feature = "rayon")]
15971595
pub mod parallel;
15981596

15991597
mod impl_1d;

src/linalg/impl_linalg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::cmp;
1919
#[cfg(feature = "blas")]
2020
use std::mem::swap;
2121
#[cfg(feature = "blas")]
22-
use std::os::raw::c_int;
22+
use libc::c_int;
2323

2424
#[cfg(feature = "blas")]
2525
use cblas_sys as blas_sys;

src/linalg_traits.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
8-
use crate::ScalarOperand;
8+
99
#[cfg(feature = "std")]
1010
use num_traits::Float;
1111
use num_traits::{One, Zero};
12+
13+
#[cfg(feature = "std")]
1214
use std::fmt;
1315
use std::ops::{Add, Div, Mul, Sub};
16+
#[cfg(feature = "std")]
1417
use std::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign};
1518

19+
#[cfg(feature = "std")]
20+
use crate::ScalarOperand;
21+
1622
/// Elements that support linear algebra operations.
1723
///
1824
/// `'static` for type-based specialization, `Copy` so that they don't need move

src/stacking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
8-
use alloc::vec::Vec;
8+
99
use crate::error::{from_kind, ErrorKind, ShapeError};
1010
use crate::imp_prelude::*;
1111
use crate::traversal_utils::assign_to;

0 commit comments

Comments
 (0)