Skip to content
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

Allow macro ndarray::s! in no_std. #1154

Merged
merged 3 commits into from
Mar 2, 2022
Merged
Changes from 1 commit
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
24 changes: 13 additions & 11 deletions src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use crate::dimension::slices_intersect;
use crate::error::{ErrorKind, ShapeError};
use crate::{ArrayViewMut, DimAdd, Dimension, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn};
use alloc::vec::Vec;
use std::convert::TryFrom;
jturner314 marked this conversation as resolved.
Show resolved Hide resolved
use core::convert::TryFrom;
use core::marker::PhantomData;
use core::ops::{Deref, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive};
#[cfg(feature = "std")]
use std::fmt;
use std::marker::PhantomData;
use std::ops::{Deref, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive};

/// A slice (range with step size).
///
Expand Down Expand Up @@ -146,6 +147,7 @@ impl SliceInfoElem {
}
}

#[cfg(feature = "std")]
makotokato marked this conversation as resolved.
Show resolved Hide resolved
impl fmt::Display for SliceInfoElem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Expand Down Expand Up @@ -842,14 +844,14 @@ macro_rules! s(
}
};
// empty call, i.e. `s![]`
(@parse ::std::marker::PhantomData::<$crate::Ix0>, ::std::marker::PhantomData::<$crate::Ix0>, []) => {
(@parse ::core::marker::PhantomData::<$crate::Ix0>, ::core::marker::PhantomData::<$crate::Ix0>, []) => {
{
#[allow(unsafe_code)]
unsafe {
$crate::SliceInfo::new_unchecked(
[],
::std::marker::PhantomData::<$crate::Ix0>,
::std::marker::PhantomData::<$crate::Ix0>,
::core::marker::PhantomData::<$crate::Ix0>,
::core::marker::PhantomData::<$crate::Ix0>,
)
}
}
Expand All @@ -858,18 +860,18 @@ macro_rules! s(
(@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![] call.") };
// convert range/index/new-axis into SliceInfoElem
(@convert $r:expr) => {
<$crate::SliceInfoElem as ::std::convert::From<_>>::from($r)
<$crate::SliceInfoElem as ::core::convert::From<_>>::from($r)
};
// convert range/index/new-axis and step into SliceInfoElem
(@convert $r:expr, $s:expr) => {
<$crate::SliceInfoElem as ::std::convert::From<_>>::from(
<$crate::Slice as ::std::convert::From<_>>::from($r).step_by($s as isize)
<$crate::SliceInfoElem as ::core::convert::From<_>>::from(
<$crate::Slice as ::core::convert::From<_>>::from($r).step_by($s as isize)
)
};
($($t:tt)*) => {
$crate::s![@parse
::std::marker::PhantomData::<$crate::Ix0>,
::std::marker::PhantomData::<$crate::Ix0>,
::core::marker::PhantomData::<$crate::Ix0>,
::core::marker::PhantomData::<$crate::Ix0>,
[]
$($t)*
]
Expand Down