Skip to main content

ScratchArena

Struct ScratchArena 

Source
pub struct ScratchArena<'a, B>
where B: Backend,
{ /* private fields */ }
Expand description

Backend-native scratch arena borrowed from a ScratchOwned.

This arena keeps backend ownership explicit and carves typed temporaries using the backend’s native borrowed buffer view (B::BufMut<'a>).

Implementations§

Source§

impl<'a, B> ScratchArena<'a, B>
where B: Backend,

Source

pub fn borrow<'b>(&'b mut self) -> ScratchArena<'b, B>

Reborrows this arena with a shorter lifetime.

Source

pub fn scope<R>( &mut self, f: impl for<'b> FnOnce(ScratchArena<'b, B>) -> R, ) -> R

Runs f with a shorter-lived reborrow of this arena.

This is useful for nested workspace use where the borrowed arena must not leak into the outer function’s scratch lifetime.

Source

pub fn apply_mut( self, f: impl FnOnce(&mut ScratchArena<'a, B>), ) -> ScratchArena<'a, B>

Applies f to this arena through a temporary mutable borrow and returns the advanced arena.

This is useful while migrating callers that still thread scratch by value around newer &mut ScratchArena APIs.

Source

pub fn consume<R>( &mut self, f: impl for<'b> FnOnce(ScratchArena<'b, B>) -> (R, ScratchArena<'b, B>), ) -> R

Runs f on a shorter-lived owned reborrow and commits the returned remainder.

This is useful while migrating APIs from arena-by-value to &mut ScratchArena: existing helpers can keep their (result, remainder) style internally, while the outer mutable arena advances to the returned remainder.

Source

pub fn available(&self) -> usize

Returns the number of aligned bytes that can still be carved out.

Source

pub fn split_at(self, len: usize) -> (ScratchArena<'a, B>, ScratchArena<'a, B>)

Splits off len aligned bytes from the front of this arena.

Source

pub fn split( self, n: usize, len: usize, ) -> (Vec<ScratchArena<'a, B>>, ScratchArena<'a, B>)

Splits this arena into n disjoint aligned chunks of len bytes each.

Source

pub fn take_region( self, len: usize, ) -> (<B as Backend>::BufMut<'a>, ScratchArena<'a, B>)

Takes a backend-native mutable region of len bytes.

Trait Implementations§

Source§

impl<'a, B> ScratchArenaTakeBasic<'a, B> for ScratchArena<'a, B>
where B: Backend,

Source§

fn take_cnv_pvec_left_scratch<M>( self, module: &M, cols: usize, size: usize, ) -> (CnvPVecLViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a, M: ModuleN + CnvPVecBytesOf,

Takes a CnvPVecL from the scratch arena.
Source§

fn take_cnv_pvec_right_scratch<M>( self, module: &M, cols: usize, size: usize, ) -> (CnvPVecRViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a, M: ModuleN + CnvPVecBytesOf,

Takes a CnvPVecR from the scratch arena.
Source§

fn take_scalar_znx_scratch( self, n: usize, cols: usize, ) -> (ScalarZnxViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a,

Takes a ScalarZnx from the scratch arena.
Source§

fn take_svp_ppol_scratch<M>( self, module: &M, cols: usize, ) -> (SvpPPolViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a, M: SvpPPolBytesOf + ModuleN,

Takes a SvpPPol from the scratch arena.
Source§

fn take_vec_znx_scratch( self, n: usize, cols: usize, size: usize, ) -> (VecZnxViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a,

Takes a VecZnx from the scratch arena.
Source§

fn take_vec_znx_big_scratch<M>( self, module: &M, cols: usize, size: usize, ) -> (VecZnxBigViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a, M: VecZnxBigBytesOf + ModuleN,

Takes a VecZnxBig from the scratch arena.
Source§

fn take_vec_znx_big_scratch_n( self, n: usize, cols: usize, size: usize, ) -> (VecZnxBigViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a,

Source§

fn take_vec_znx_dft_scratch<M>( self, module: &M, cols: usize, size: usize, ) -> (VecZnxDftViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a, M: VecZnxDftBytesOf + ModuleN,

Takes a VecZnxDft from the scratch arena.
Source§

fn take_vmp_pmat_scratch<M>( self, module: &M, rows: usize, cols_in: usize, cols_out: usize, size: usize, ) -> (VmpPMatViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a, M: VmpPMatBytesOf + ModuleN,

Takes a VmpPMat from the scratch arena.
Source§

fn take_mat_znx_scratch( self, n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize, ) -> (MatZnxViewMut<'a, B>, ScratchArena<'a, B>)
where B: 'a,

Takes a MatZnx from the scratch arena.
Source§

fn take_vec_znx_dft_slice_scratch<M>( self, module: &M, len: usize, cols: usize, size: usize, ) -> (Vec<VecZnxDftViewMut<'a, B>>, Self)
where B: 'a, M: VecZnxDftBytesOf + ModuleN,

Takes len consecutive VecZnxDft objects from the scratch arena.
Source§

fn take_vec_znx_slice_scratch( self, len: usize, n: usize, cols: usize, size: usize, ) -> (Vec<VecZnxViewMut<'a, B>>, Self)
where B: 'a,

Takes len consecutive VecZnx objects from the scratch arena.
Source§

impl<'a, B> ScratchArenaTakeCore<'a, B> for ScratchArena<'a, B>
where B: Backend,

Source§

fn take_lwe_scratch<A>(self, infos: &A) -> (LWEViewMut<'a, B>, Self)
where B: 'a, A: LWEInfos,

Allocates an LWE ciphertext from scratch space.
Source§

fn take_lwe_plaintext_scratch<A>( self, infos: &A, ) -> (LWEPlaintextViewMut<'a, B>, Self)
where B: 'a, A: LWEInfos,

Allocates an LWEPlaintext from scratch space.
Source§

fn take_glwe_scratch<A>(self, infos: &A) -> (GLWEViewMut<'a, B>, Self)
where B: 'a, A: GLWEInfos,

Allocates a GLWE ciphertext from scratch space.
Source§

fn take_glwe_slice_scratch<A>( self, size: usize, infos: &A, ) -> (Vec<GLWEViewMut<'a, B>>, Self)
where B: 'a, A: GLWEInfos,

Allocates a Vec of size GLWE ciphertexts from scratch space.
Source§

fn take_glwe_tensor_scratch<A>( self, infos: &A, ) -> (GLWETensorViewMut<'a, B>, Self)
where B: 'a, A: GLWEInfos,

Allocates a GLWETensor from scratch space.
Source§

fn take_glwe_plaintext_scratch<A>( self, infos: &A, ) -> (GLWEPlaintextViewMut<'a, B>, Self)
where B: 'a, A: GLWEInfos,

Allocates a GLWEPlaintext from scratch space.
Source§

fn take_glwe_secret_prepared_scratch<M>( self, module: &M, rank: Rank, ) -> (GLWESecretPreparedViewMut<'a, B>, Self)
where B: 'a, M: ModuleN + SvpPPolBytesOf,

Allocates a GLWESecretPrepared (DFT-domain secret key) from scratch space.
Source§

fn take_glwe_secret_scratch( self, n: Degree, rank: Rank, ) -> (GLWESecretViewMut<'a, B>, Self)
where B: 'a,

Allocates a GLWESecret from scratch space.
Source§

fn take_glwe_secret_tensor_scratch( self, n: Degree, rank: Rank, ) -> (GLWESecretTensorViewMut<'a, B>, Self)
where B: 'a,

Allocates a GLWESecretTensor from scratch space.
Source§

fn take_gglwe_scratch<A>(self, infos: &A) -> (GGLWEViewMut<'a, B>, Self)
where B: 'a, A: GGLWEInfos,

Allocates a GGLWE ciphertext from scratch space.
Source§

fn take_gglwe_prepared_scratch<A, M>( self, module: &M, infos: &A, ) -> (GGLWEPreparedViewMut<'a, B>, Self)
where B: 'a, A: GGLWEInfos, M: ModuleN + VmpPMatBytesOf,

Allocates a GGLWEPrepared (DFT-domain GGLWE) from scratch space.
Source§

fn take_ggsw_scratch<A>(self, infos: &A) -> (GGSWViewMut<'a, B>, Self)
where B: 'a, A: GGSWInfos,

Allocates a GGSW ciphertext from scratch space.
Source§

fn take_ggsw_prepared_scratch<A, M>( self, module: &M, infos: &A, ) -> (GGSWPreparedViewMut<'a, B>, Self)
where B: 'a, A: GGSWInfos, M: ModuleN + VmpPMatBytesOf,

Allocates a GGSWPrepared (DFT-domain GGSW) from scratch space.
Source§

impl<B> ScratchAvailable for ScratchArena<'_, B>
where B: Backend,

Auto Trait Implementations§

§

impl<'a, B> Freeze for ScratchArena<'a, B>

§

impl<'a, B> RefUnwindSafe for ScratchArena<'a, B>

§

impl<'a, B> !Send for ScratchArena<'a, B>

§

impl<'a, B> !Sync for ScratchArena<'a, B>

§

impl<'a, B> Unpin for ScratchArena<'a, B>

§

impl<'a, B> UnsafeUnpin for ScratchArena<'a, B>

§

impl<'a, B> !UnwindSafe for ScratchArena<'a, B>

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<'a, BE, T> ScratchArenaTakeCKKS<'a, BE> for T
where BE: Backend + 'a, T: ScratchArenaTakeCore<'a, BE>,

Source§

fn take_ckks_ciphertext_scratch<I>( self, infos: &I, meta: CKKSMeta, ) -> (CKKSCiphertextViewMut<'a, BE>, Self)
where BE: 'a, I: GLWEInfos,

Source§

fn take_ckks_ciphertext_like_scratch<C>( self, ct: &C, ) -> (CKKSCiphertextViewMut<'a, BE>, Self)
where BE: 'a, C: GLWEInfos + CKKSInfos,

Source§

fn take_unnormalized_ckks_ciphertext_scratch<I>( self, infos: &I, meta: CKKSMeta, ) -> (CKKSCiphertext<<BE as Backend>::BufMut<'a>, Unnormalized>, Self)
where BE: 'a, I: GLWEInfos,

Source§

fn take_unnormalized_ckks_ciphertext_like_scratch<C>( self, ct: &C, ) -> (CKKSCiphertext<<BE as Backend>::BufMut<'a>, Unnormalized>, Self)
where BE: 'a, C: GLWEInfos + CKKSInfos,

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