Struct ArraySection

Source
pub struct ArraySection {
    pub lower_bound: Option<Expression>,
    pub length: Option<Expression>,
    pub stride: Option<Expression>,
}
Expand description

Array section specification: [lower:length:stride]

OpenMP allows specifying portions of arrays using array sections:

  • arr[0:N] - elements 0 through N-1
  • arr[i:10:2] - 10 elements starting at i, every 2nd element
  • arr[:] - all elements

§Learning: Optional Fields

All three parts (lower, length, stride) are optional! This is modeled with Option<Expression>:

  • Some(expr) - part is present
  • None - part is omitted

§Syntax Examples

OpenMP Syntaxlowerlengthstride
arr[0:N]Some(0)Some(N)None
arr[:]NoneNoneNone
arr[i:10:2]Some(i)Some(10)Some(2)
arr[i]Some(i)NoneNone

§Example

use roup::ir::{ArraySection, Expression, ParserConfig};

let config = ParserConfig::default();

// arr[0:N]
let section = ArraySection {
    lower_bound: Some(Expression::new("0", &config)),
    length: Some(Expression::new("N", &config)),
    stride: None,
};

Fields§

§lower_bound: Option<Expression>

Lower bound (starting index)

If None, starts at beginning (equivalent to 0)

§length: Option<Expression>

Length (number of elements)

If None, goes to end of dimension

§stride: Option<Expression>

Stride (spacing between elements)

If None, defaults to 1 (consecutive elements)

Implementations§

Source§

impl ArraySection

Source

pub fn new( lower_bound: Option<Expression>, length: Option<Expression>, stride: Option<Expression>, ) -> Self

Create a new array section with all fields

Source

pub fn single_index(index: Expression) -> Self

Create an array section for a single index: arr[i]

§Example
use roup::ir::{ArraySection, Expression, ParserConfig};

let config = ParserConfig::default();
let section = ArraySection::single_index(Expression::new("i", &config));
// Represents arr[i]
Source

pub const fn all() -> Self

Create an array section for all elements: arr[:]

§Example
use roup::ir::ArraySection;

let section = ArraySection::all();
// Represents arr[:]
Source

pub fn is_single_index(&self) -> bool

Check if this represents a single index access

Source

pub fn is_all(&self) -> bool

Check if this represents all elements

Trait Implementations§

Source§

impl Clone for ArraySection

Source§

fn clone(&self) -> ArraySection

Returns a duplicate 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 Debug for ArraySection

Source§

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

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

impl Display for ArraySection

Source§

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

Format as OpenMP array section syntax

§Example
use roup::ir::{ArraySection, Expression, ParserConfig};

let config = ParserConfig::default();
let section = ArraySection::new(
    Some(Expression::new("0", &config)),
    Some(Expression::new("N", &config)),
    None,
);
assert_eq!(format!("{}", section), "0:N");
Source§

impl PartialEq for ArraySection

Source§

fn eq(&self, other: &ArraySection) -> 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 StructuralPartialEq for ArraySection

Auto Trait Implementations§

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<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, 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.