• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

facet-rs / facet / 19992174439

06 Dec 2025 05:56PM UTC coverage: 58.742% (-0.005%) from 58.747%
19992174439

Pull #1118

github

web-flow
Merge d1d251ac8 into 45a8cb1c3
Pull Request #1118: Reduce/cordon bloat in facet, introduce bloatbench

1138 of 3103 new or added lines in 61 files covered. (36.67%)

540 existing lines in 30 files now uncovered.

24225 of 41240 relevant lines covered (58.74%)

502.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/facet-core/src/types/def/ndarray.rs
1
use crate::ptr::{PtrConst, PtrMut};
2

3
use super::Shape;
4

5
/// Fields for n-dimensional array types
6
#[derive(Clone, Copy, Debug)]
7
#[repr(C)]
8
pub struct NdArrayDef {
9
    /// vtable for interacting with the array
10
    pub vtable: &'static NdArrayVTable,
11
    /// shape of the items in the array
12
    pub t: &'static Shape,
13
}
14

15
impl NdArrayDef {
16
    /// Construct a `NdArrayDef` from its vtable and element shape.
NEW
17
    pub const fn new(vtable: &'static NdArrayVTable, t: &'static Shape) -> Self {
×
NEW
18
        Self { vtable, t }
×
UNCOV
19
    }
×
20

21
    /// Returns the shape of the items in the array
22
    pub const fn t(&self) -> &'static Shape {
12✔
23
        self.t
12✔
24
    }
12✔
25
}
26

27
/// Get the total count of elements in the array.
28
///
29
/// # Safety
30
///
31
/// The `array` parameter must point to aligned, initialized memory of the correct type.
32
pub type NdArrayCountFn = unsafe fn(array: PtrConst) -> usize;
33

34
/// Get the number of dimensions in the array.
35
///
36
/// # Safety
37
///
38
/// The `array` parameter must point to aligned, initialized memory of the correct type.
39
pub type NdArrayNDimFn = unsafe fn(array: PtrConst) -> usize;
40

41
/// Get the i-th dimension in the array, or `None` if the dimension index is out of bounds.
42
///
43
/// # Safety
44
///
45
/// The `array` parameter must point to aligned, initialized memory of the correct type.
46
pub type NdArrayDimFn = unsafe fn(array: PtrConst, i: usize) -> Option<usize>;
47

48
/// Get the i-th stride in the array in bytes, or `None` if the dimension index is out of bounds.
49
///
50
/// # Safety
51
///
52
/// The `array` parameter must point to aligned, initialized memory of the correct type.
53
pub type NdArrayByteStrideFn = unsafe fn(array: PtrConst, i: usize) -> Option<isize>;
54

55
/// Get pointer to the element at `index` in the array, or `None` if the
56
/// index is out of bounds.
57
///
58
/// The flat index is transformed into separate array indices like this:
59
/// ```text
60
///  - i0 = index % d0;
61
///  - i1 = index / d0 % d1;
62
///  - …
63
///  - i{n-1} = index / d0 / d1 / ... / d{n-1} % dn;
64
///  - remainder = index / d0 / d1 / ... / dn;
65
/// ```
66
///
67
/// if `remainder` is non-zero, the index is out of bounds and `None` is returned.
68
///
69
/// # Safety
70
///
71
/// The `array` parameter must point to aligned, initialized memory of the correct type.
72
pub type NdArrayGetFn = unsafe fn(array: PtrConst, index: usize) -> Option<PtrConst>;
73

74
/// Get mutable pointer to the element at `index` in the array, or `None` if the
75
/// index is out of bounds.
76
///
77
/// # Safety
78
///
79
/// The `array` parameter must point to aligned, initialized memory of the correct type.
80
pub type NdArrayGetMutFn = unsafe fn(array: PtrMut, index: usize) -> Option<PtrMut>;
81

82
/// Get pointer to the data buffer of the array.
83
///
84
/// # Safety
85
///
86
/// The `array` parameter must point to aligned, initialized memory of the correct type.
87
pub type NdArrayAsPtrFn = unsafe fn(array: PtrConst) -> PtrConst;
88

89
/// Get mutable pointer to the data buffer of the array.
90
///
91
/// # Safety
92
///
93
/// The `array` parameter must point to aligned, initialized memory of the correct type.
94
pub type NdArrayAsMutPtrFn = unsafe fn(array: PtrMut) -> PtrMut;
95

96
/// Virtual table for a n-dimensional array type (like `Matrix<T>`, `Tensor<T>`, etc.)
97
#[derive(Clone, Copy, Debug)]
98
#[repr(C)]
99
pub struct NdArrayVTable {
100
    /// cf. [`NdArrayCountFn`]
101
    pub count: NdArrayCountFn,
102

103
    /// cf. [`NdArrayNDimFn`]
104
    pub n_dim: NdArrayNDimFn,
105

106
    /// cf. [`NdArrayDimFn`]
107
    pub dim: NdArrayDimFn,
108

109
    /// cf. [`NdArrayGetFn`]
110
    pub get: NdArrayGetFn,
111

112
    /// cf. [`NdArrayGetMutFn`]
113
    /// Only available for mutable arrays
114
    pub get_mut: Option<NdArrayGetMutFn>,
115

116
    /// cf. [`NdArrayByteStrideFn`]
117
    /// Only available for types that can be accessed as a strided array
118
    pub byte_stride: Option<NdArrayByteStrideFn>,
119

120
    /// cf. [`NdArrayAsPtrFn`]
121
    /// Only available for types that can be accessed as a strided array
122
    pub as_ptr: Option<NdArrayAsPtrFn>,
123

124
    /// cf. [`NdArrayAsMutPtrFn`]
125
    /// Only available for types that can be accessed as a strided array
126
    pub as_mut_ptr: Option<NdArrayAsMutPtrFn>,
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc