Skip to main content

BoolTensor

Struct BoolTensor 

Source
pub struct BoolTensor { /* private fields */ }
Expand description

Contiguous tensor of booleans, device-aware.

Data lives in a TensorStorage<bool> (CPU Vec<bool> or a CUDA GpuBufferHandle); the storage carries its own Device. CPU-resident behaviour is byte-identical to the pre-Phase-3a Arc<Vec<bool>> design.

Implementations§

Source§

impl BoolTensor

Source

pub fn from_vec( data: Vec<bool>, shape: Vec<usize>, ) -> Result<BoolTensor, FerrotorchError>

Build from a Vec + shape. Errors on numel mismatch.

Source

pub fn from_slice( data: &[bool], shape: &[usize], ) -> Result<BoolTensor, FerrotorchError>

Build from a slice + shape (clones into a fresh Vec).

Source

pub fn zeros(shape: &[usize]) -> BoolTensor

All-false tensor of the given shape.

Source

pub fn ones(shape: &[usize]) -> BoolTensor

All-true tensor of the given shape.

Source

pub fn from_predicate<T>( t: &Tensor<T>, pred: impl Fn(T) -> bool, ) -> Result<BoolTensor, FerrotorchError>
where T: Float,

Build a mask by applying pred to every element of t. Useful for Tensor < 0, Tensor.is_finite(), etc.

Source

pub fn shape(&self) -> &[usize]

Logical shape.

Source

pub fn numel(&self) -> usize

Total number of elements.

Source

pub fn ndim(&self) -> usize

Number of dimensions.

Source

pub fn device(&self) -> Device

The device this tensor’s storage resides on.

Source

pub fn is_cuda(&self) -> bool

Returns true if this tensor is on a CUDA GPU.

Source

pub fn data(&self) -> Result<&[bool], FerrotorchError>

Borrow the contiguous buffer as a host slice.

§Errors

Returns FerrotorchError::GpuTensorNotAccessible if the tensor is on a GPU (CUDA / XPU) device, or is a meta tensor. This mirrors IntTensor::data and prevents callers from silently reading device memory as a host slice — call Self::to(Device::Cpu) first to transfer.

Source

pub fn gpu_handle(&self) -> Result<&GpuBufferHandle, FerrotorchError>

Get the CUDA buffer handle. Returns Err for CPU (and other non-CUDA) tensors, mirroring Tensor::gpu_handle.

§Errors

Returns FerrotorchError::InvalidArgument when the tensor is not CUDA-resident.

Source

pub fn from_gpu_handle(handle: GpuBufferHandle, shape: Vec<usize>) -> BoolTensor

Construct a GPU-resident BoolTensor from a CUDA buffer handle + shape.

The handle must carry the DType::Bool tag — this is what every Phase-3b GPU op returns. Mirrors IntTensor::from_gpu_handle.

Source

pub fn to(&self, device: Device) -> Result<BoolTensor, FerrotorchError>

Move this tensor to device, returning a new tensor.

Reuses the same DType-tagged raw-byte transport as Tensor::to / IntTensor::to: CPU→CUDA uploads via GpuBackend::cpu_to_gpu (handle tagged DType::Bool), CUDA→CPU reads back via gpu_to_cpu. Both are bit-exact. On-device→same-device is a cheap storage clone.

This is the explicit transfer entry point (PyTorch parity — like .cuda() / .cpu()). The host-readback inside the CUDA→CPU arm is the user-requested D2H copy, not a silent fallback.

§Errors
Source

pub fn not(&self) -> BoolTensor

Pointwise NOT. GPU path (resident) when CUDA-resident, else CPU.

Source

pub fn and(&self, other: &BoolTensor) -> Result<BoolTensor, FerrotorchError>

Pointwise AND. Errors on shape/device mismatch.

Source

pub fn or(&self, other: &BoolTensor) -> Result<BoolTensor, FerrotorchError>

Pointwise OR.

Source

pub fn xor(&self, other: &BoolTensor) -> Result<BoolTensor, FerrotorchError>

Pointwise XOR.

Source

pub fn reshape(&self, shape: &[usize]) -> Result<BoolTensor, FerrotorchError>

Reshape (must preserve numel). Metadata-only; the storage is cloned (cheap for CPU; a clone_buffer for GPU — no host readback).

Source

pub fn count_true(&self) -> Result<usize, FerrotorchError>

Number of true elements (CPU only).

§Errors

Returns FerrotorchError::GpuTensorNotAccessible for a CUDA-resident tensor: a host count would require a full-buffer D2H copy, which the device-error policy forbids. Use Self::any / Self::all (which run the reduction on-device) or .to(Device::Cpu) explicitly first.

Source

pub fn any(&self) -> Result<bool, FerrotorchError>

True if any element is true.

On CUDA the OR-reduction runs on the GPU (real PTX kernel); only the single reduced byte crosses to the host — that byte IS the scalar result (PyTorch parity: Tensor.any() -> bool), NOT a full-buffer round trip.

Source

pub fn all(&self) -> Result<bool, FerrotorchError>

True if all elements are true.

On CUDA the AND-reduction runs on the GPU; only the single reduced byte crosses to the host (the scalar result, not a buffer round trip).

Source

pub fn gt<T>( a: &Tensor<T>, b: &Tensor<T>, ) -> Result<BoolTensor, FerrotorchError>
where T: Float,

Pointwise > comparing two float tensors of the same shape; produces a BoolTensor of matching shape. Mirrors torch.gt(a, b) returning a bool tensor. (#615)

Source

pub fn lt<T>( a: &Tensor<T>, b: &Tensor<T>, ) -> Result<BoolTensor, FerrotorchError>
where T: Float,

Pointwise <. (#615)

Source

pub fn ge<T>( a: &Tensor<T>, b: &Tensor<T>, ) -> Result<BoolTensor, FerrotorchError>
where T: Float,

Pointwise >=. (#615)

Source

pub fn le<T>( a: &Tensor<T>, b: &Tensor<T>, ) -> Result<BoolTensor, FerrotorchError>
where T: Float,

Pointwise <=. (#615)

Source

pub fn eq_t<T>( a: &Tensor<T>, b: &Tensor<T>, ) -> Result<BoolTensor, FerrotorchError>
where T: Float,

Pointwise ==. (#615)

Source

pub fn ne<T>( a: &Tensor<T>, b: &Tensor<T>, ) -> Result<BoolTensor, FerrotorchError>
where T: Float,

Pointwise !=. (#615)

Source

pub fn gt_int<I>( a: &IntTensor<I>, b: &IntTensor<I>, ) -> Result<BoolTensor, FerrotorchError>
where I: IntElement,

Pointwise a > b over two integer tensors → BoolTensor. (#1185)

Source

pub fn lt_int<I>( a: &IntTensor<I>, b: &IntTensor<I>, ) -> Result<BoolTensor, FerrotorchError>
where I: IntElement,

Pointwise a < b over two integer tensors. (#1185)

Source

pub fn ge_int<I>( a: &IntTensor<I>, b: &IntTensor<I>, ) -> Result<BoolTensor, FerrotorchError>
where I: IntElement,

Pointwise a >= b over two integer tensors. (#1185)

Source

pub fn le_int<I>( a: &IntTensor<I>, b: &IntTensor<I>, ) -> Result<BoolTensor, FerrotorchError>
where I: IntElement,

Pointwise a <= b over two integer tensors. (#1185)

Source

pub fn eq_int<I>( a: &IntTensor<I>, b: &IntTensor<I>, ) -> Result<BoolTensor, FerrotorchError>
where I: IntElement,

Pointwise a == b over two integer tensors. (#1185)

Source

pub fn ne_int<I>( a: &IntTensor<I>, b: &IntTensor<I>, ) -> Result<BoolTensor, FerrotorchError>
where I: IntElement,

Pointwise a != b over two integer tensors. (#1185)

Source

pub fn to_float<T>(&self) -> Result<Tensor<T>, FerrotorchError>
where T: Float,

Convert to a float tensor: true → 1.0, false → 0.0.

On CUDA the cast runs on the GPU and the result stays resident (no host round-trip); on CPU it maps the host slice.

Trait Implementations§

Source§

impl Clone for BoolTensor

Source§

fn clone(&self) -> BoolTensor

Clone the tensor. For CPU storage this clones the Vec; for GPU storage it allocates a new device buffer with the same contents (via the backend’s clone_buffer). Delegates to TensorStorage::clone.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BoolTensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for BoolTensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<U> AsDistAny for U
where U: 'static,

Source§

fn as_dist_any(&self) -> &(dyn Any + 'static)

Recover the value as &dyn Any for concrete-type downcasting.
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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more