Struct Schedule

Source
pub struct Schedule<Dim: Dimension>(/* private fields */);
Expand description

Represents a sampling schedule. Schedules are represented as a list of booleans, where true means to take the sample at the position of the index and false means to not take the sample.

Implementations§

Source§

impl<Dim: Dimension> Schedule<Dim>

Source

pub const fn new(sched: Array<bool, Dim>) -> Schedule<Dim>

Create a new schedule from a list of booleans

Source

pub fn into_inner(self) -> Array<bool, Dim>

Unwrap the inner list of bools

Source

pub fn count(&self) -> usize

Count the number of samples in the schedule. Note that this is operation linear in the length of the schedule.

Source

pub fn decode( encoded: &str, encoding_type: EncodingType, dims_rule: impl FnOnce(Dim) -> Result<Dim, String>, ) -> Result<Schedule<Dim>, ScheduleDecodingError>

Decodes a schedule from a string. The format is expected to be a list of line-break separated sample positions, where each sample position is a comma separated list of numbers for each index in each dimension.

len_rule is a function that takes the minimum possible length to contain all of the values and returns either a length for the schedule or an error message that will be propagated. This is necessary because it is not known how many false values there there should be after the last true value, and it allows rejecting input that could cause resource exhaustion of the software. It would make sense to configure this function to return an error above a maximum value because it is possible to make a “schedule bomb” that would consume the entire RAM when decoded:

0
100000000000000000000
§Example
let sched = Schedule::new(Array::from_vec(vec![true, false, true, true, false, true, false, false]));

assert_eq!(
    Schedule::<Ix1>::decode(
        "0\n2\n3\n5",
        EncodingType::ZeroBased,
        |max| Ok(Ix1(max[0].next_power_of_two()))
    ).unwrap(),
    sched
);

assert!(
    Schedule::<Ix1>::decode(
        "1\n3\n4\n6",
        EncodingType::OneBased,
        |max| if max[0] > 4 { Err("Too big!".to_owned()) } else { Ok(max) },
    ).is_err(),
);

let sched = Schedule::new(Array::from_shape_vec(IxDyn(&[8, 2]).strides(IxDyn(&[1, 8])), vec![
    false, false, true,  false, false, false, false, false,
    true,  false, false, true,  false, true,  false, false,
]).unwrap());

assert_eq!(
    Schedule::<IxDyn>::decode(
        "1, 2\n3, 1\n4, 2\n6, 2",
        EncodingType::OneBased,
        |max| Ok(IxDyn(&max.as_array_view().iter().map(|v| v.next_power_of_two()).collect::<Vec<_>>())),
    ).unwrap(),
    sched,
);

let sched = Schedule::new(Array::from_vec(vec![true, false, true, true, false, true, false]));
assert_eq!(
    Schedule::<Ix1>::decode(
        "0\n2\n3\n5",
        EncodingType::ZeroBased,
        |_| Ok(Ix1(7)),
    ).unwrap(),
    sched,
);
Source

pub fn encode(&self, encoding_type: EncodingType) -> String

Writes the schedule to a string using the same format as is understood by Schedule::decode.

§Example
let sched = Schedule::new(Array::from_vec(vec![true, false, false, true, true]));
assert_eq!(sched.encode(EncodingType::ZeroBased), "0\n3\n4");
assert_eq!(sched.encode(EncodingType::OneBased), "1\n4\n5");
assert_eq!(
    Schedule::decode(
        "1, 2\n3, 4",
        EncodingType::OneBased,
        |v: Ix2| Ok(v),
    )
    .unwrap()
    .encode(EncodingType::OneBased),
    "1, 2\n3, 4",
);
Source§

impl Schedule<Ix1>

Source

pub fn point_spread(&self) -> PointSpread

Calculates the Point Spread Function of the schedule.

The PSF is calculated as the discrete fourier transform of the schedule where true is replaced with 1. and false is replaced with 0..

If you take uniformly sampled data and set every sample not taken to zero, the Convolution Theorem states that your true signal will be convolved with the schedule’s PSF. Therefore, it is preferable to generate schedules where the PSF has minimal spikes because that minimizes sampling noise.

The PSF can also be thought of as a plot of global bias towards sampling a particular frequency. For example, a PSF spike at wavenumber 1/3 indicates a bias towards sampling at positions that are at multiples of three, or some offset of a multiple of three, thereby undersampling frequencies that are out of phase with this bias. Therefore, the PSF can be thought of as a plot of how much a schedule undersamples different phases of a particular frequency.

Source

pub fn rlc(&self, seq: impl AsRef<[bool]>) -> Vec<u64>

Calculate the Repeat Length Curve of the schedule for a given pattern.

This metric can be used to determine the number of repeating patterns in the sampling schedule. Schedules with fewer patterns are more condusive to signal reconstruction because patterns represent a local bias against sampling particular frequencies.

The first argument is the pattern to be searched for. The function returns a list where the element at index i is number of places in the schedule where seq is repeated i + 1 times followed by the first element of seq.

§Example
let sched = Schedule::new(Array::from_vec(vec![true, false, true, false, true, false, false, true, false, true]));

// The schedule has 3 instances of `T F T` and 1 instance of `T F T F T`
assert_eq!(sched.rlc([true, false]), vec![3, 1]);

L. E. Cullen, A. Marchiori, D. Rovnyak, Magn Reson Chem 2023, 61(6), 337. https://doi.org/10.1002/mrc.5340

Trait Implementations§

Source§

impl<Dim: Clone + Dimension> Clone for Schedule<Dim>

Source§

fn clone(&self) -> Schedule<Dim>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Dim: Dimension> Debug for Schedule<Dim>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Dim: Dimension> Deref for Schedule<Dim>

Source§

type Target = ArrayBase<OwnedRepr<bool>, Dim>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Dim: Dimension> DerefMut for Schedule<Dim>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<Dim: Dimension> Display for Schedule<Dim>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Dim: PartialEq + Dimension> PartialEq for Schedule<Dim>

Source§

fn eq(&self, other: &Schedule<Dim>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Dim: Eq + Dimension> Eq for Schedule<Dim>

Source§

impl<Dim: Dimension> StructuralPartialEq for Schedule<Dim>

Auto Trait Implementations§

§

impl<Dim> Freeze for Schedule<Dim>
where Dim: Freeze,

§

impl<Dim> RefUnwindSafe for Schedule<Dim>
where Dim: RefUnwindSafe,

§

impl<Dim> Send for Schedule<Dim>

§

impl<Dim> Sync for Schedule<Dim>

§

impl<Dim> Unpin for Schedule<Dim>
where Dim: Unpin,

§

impl<Dim> UnwindSafe for Schedule<Dim>
where Dim: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> TraceOutput for T
where T: Any + Debug + Display,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Upcast the value to &dyn Any. This will be removed when trait upcasting is stabilized.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V