open_cl_low_level/
dims.rs1#[derive(Debug, Clone, Eq, PartialEq)]
2pub enum Dims {
3 One(usize),
4 Two(usize, usize),
5 Three(usize, usize, usize),
6}
7
8use Dims::*;
9
10impl Dims {
11 pub fn as_offset_volume(&self) -> [usize; 3] {
12 match *self {
13 One(x) => [x, 0, 0],
14 Two(x, y) => [x, y, 0],
15 Three(x, y, z) => [x, y, z],
16 }
17 }
18
19 pub fn n_items(&self) -> usize {
20 match *self {
21 One(x) => x,
22 Two(x, y) => x * y,
23 Three(x, y, z) => x * y * z,
24 }
25 }
26
27 pub fn n_dimensions(&self) -> u8 {
28 match *self {
29 One(..) => 1,
30 Two(..) => 2,
31 Three(..) => 3,
32 }
33 }
34
35 pub fn transpose(&self) -> Dims {
36 match *self {
37 One(x) => Two(1, x),
38 Two(x, y) => Two(y, x),
39 Three(x, y, z) => Three(x, z, y),
40 }
41 }
42}
43
44impl From<usize> for Dims {
45 fn from(x: usize) -> Dims {
46 Dims::One(x)
47 }
48}
49
50impl From<(usize,)> for Dims {
51 fn from((x,): (usize,)) -> Dims {
52 Dims::One(x)
53 }
54}
55
56impl From<(usize, usize)> for Dims {
57 fn from((x, y): (usize, usize)) -> Dims {
58 Dims::Two(x, y)
59 }
60}
61
62impl From<(usize, usize, usize)> for Dims {
63 fn from((x, y, z): (usize, usize, usize)) -> Dims {
64 Dims::Three(x, y, z)
65 }
66}