use crate::{OpaqueContext, managed_tensor::ManagedTensorBase};
use snafu::Snafu;
use std::{convert::Infallible, ptr::NonNull};
mod allocation;
mod array;
mod borrowed;
mod context;
mod raw;
mod slice;
pub use array::{CopiedArray, GenericArray};
pub use borrowed::{BorrowedArray, BorrowedSlice};
pub use context::FromContext;
pub(crate) use context::try_allocate_generic_from_context;
pub use slice::{CopiedSlice, GenericSlice};
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("Mismatched length of shape ({shape_len}) and strides ({strides_len})"))]
MismatchedLength {
shape_len: usize,
strides_len: usize,
},
#[snafu(display("Dimension count ({ndim}) exceeds i32::MAX"))]
NdimOverflow {
ndim: usize,
source: std::num::TryFromIntError,
},
#[snafu(display("shape value at axis {axis} does not fit in i64"))]
ShapeValueOverflow { axis: usize },
#[snafu(display("stride value at axis {axis} does not fit in i64"))]
StrideValueOverflow { axis: usize },
}
pub unsafe trait Metadata {
type Error;
fn try_allocate<C, M>(self, ctx: C) -> Result<NonNull<M>, Self::Error>
where
C: OpaqueContext,
M: ManagedTensorBase;
unsafe fn allocate_unchecked<C, M>(self, ctx: C) -> NonNull<M>
where
C: OpaqueContext,
M: ManagedTensorBase;
}
pub unsafe trait InfallibleMetadata: Metadata<Error = Infallible> {
fn allocate<C, M>(self, ctx: C) -> NonNull<M>
where
C: OpaqueContext,
M: ManagedTensorBase;
}