pub struct FeatureHistogram<'a> {
pub data: &'a [UnsafeCell<Bin>],
}Expand description
Feature Histogram using UnsafeCell for concurrent mutation.
Fields§
§data: &'a [UnsafeCell<Bin>]Reference to the histogram data.
Implementations§
Source§impl<'a> FeatureHistogram<'a>
impl<'a> FeatureHistogram<'a>
Sourcepub fn new(hist: &'a mut [Bin]) -> Self
pub fn new(hist: &'a mut [Bin]) -> Self
Create a new FeatureHistogram from a mutable slice of bins.
Sourcepub unsafe fn update(
&self,
feature: &[u16],
sorted_grad: &[f32],
sorted_hess: Option<&[f32]>,
index: &[usize],
)
pub unsafe fn update( &self, feature: &[u16], sorted_grad: &[f32], sorted_hess: Option<&[f32]>, index: &[usize], )
Updates the histogram data based on the provided gradients and Hessian values.
§Arguments
feature: A slice of bin indices for each data element.sorted_grad: The full gradient array (absolute indexing viaindex).sorted_hess: An optional full Hessian array (absolute indexing viaindex).index: A slice of original indices for the data elements in this node.
§Safety
This function is unsafe because it uses get_unchecked and as_mut().unwrap_unchecked(),
which bypass Rust’s standard safety checks. The caller must ensure the following:
- The
featureslice must be a valid bin index for every element. - All indices in the
indexslice must be within the bounds of thefeatureslice. - The
sorted_gradslice must cover all indices referenced byindex. - If
sorted_hessisSome, it must also cover all indices referenced byindex. - The internal
self.datastructure must not be modified externally while this function is running. - Each element in
self.datamust contain a validSomevalue that can be mutated.
Sourcepub unsafe fn update_cuts(&self, cuts: &[f64])
pub unsafe fn update_cuts(&self, cuts: &[f64])
Updates the cut-off values for the histogram bins.
This function is unsafe because…
§Safety
The cuts slice must be sorted in ascending order.
The length of cuts must be exactly one less than the number of bins.
Calling this function with an unsorted slice or an incorrect length
could lead to incorrect binning logic and potential data corruption.
Trait Implementations§
Source§impl<'a> Clone for FeatureHistogram<'a>
impl<'a> Clone for FeatureHistogram<'a>
Source§fn clone(&self) -> FeatureHistogram<'a>
fn clone(&self) -> FeatureHistogram<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for FeatureHistogram<'a>
impl<'a> Debug for FeatureHistogram<'a>
impl<'a> Copy for FeatureHistogram<'a>
impl<'a> Send for FeatureHistogram<'a>
impl<'a> Sync for FeatureHistogram<'a>
Auto Trait Implementations§
impl<'a> Freeze for FeatureHistogram<'a>
impl<'a> !RefUnwindSafe for FeatureHistogram<'a>
impl<'a> Unpin for FeatureHistogram<'a>
impl<'a> UnsafeUnpin for FeatureHistogram<'a>
impl<'a> !UnwindSafe for FeatureHistogram<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more