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
impl BoolTensor
Sourcepub fn from_vec(
data: Vec<bool>,
shape: Vec<usize>,
) -> Result<BoolTensor, FerrotorchError>
pub fn from_vec( data: Vec<bool>, shape: Vec<usize>, ) -> Result<BoolTensor, FerrotorchError>
Build from a Vec + shape. Errors on numel mismatch.
Sourcepub fn from_slice(
data: &[bool],
shape: &[usize],
) -> Result<BoolTensor, FerrotorchError>
pub fn from_slice( data: &[bool], shape: &[usize], ) -> Result<BoolTensor, FerrotorchError>
Build from a slice + shape (clones into a fresh Vec).
Sourcepub fn zeros(shape: &[usize]) -> BoolTensor
pub fn zeros(shape: &[usize]) -> BoolTensor
All-false tensor of the given shape.
Sourcepub fn ones(shape: &[usize]) -> BoolTensor
pub fn ones(shape: &[usize]) -> BoolTensor
All-true tensor of the given shape.
Sourcepub fn from_predicate<T>(
t: &Tensor<T>,
pred: impl Fn(T) -> bool,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
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.
Sourcepub fn data(&self) -> Result<&[bool], FerrotorchError>
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.
Sourcepub fn gpu_handle(&self) -> Result<&GpuBufferHandle, FerrotorchError>
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.
Sourcepub fn from_gpu_handle(handle: GpuBufferHandle, shape: Vec<usize>) -> BoolTensor
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.
Sourcepub fn to(&self, device: Device) -> Result<BoolTensor, FerrotorchError>
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
FerrotorchError::DeviceUnavailableif no GPU backend is registered.FerrotorchError::InvalidArgumentfor unsupported device pairs (XPU / MPS are not wired forBoolTensor).
Sourcepub fn not(&self) -> BoolTensor
pub fn not(&self) -> BoolTensor
Pointwise NOT. GPU path (resident) when CUDA-resident, else CPU.
Sourcepub fn and(&self, other: &BoolTensor) -> Result<BoolTensor, FerrotorchError>
pub fn and(&self, other: &BoolTensor) -> Result<BoolTensor, FerrotorchError>
Pointwise AND. Errors on shape/device mismatch.
Sourcepub fn or(&self, other: &BoolTensor) -> Result<BoolTensor, FerrotorchError>
pub fn or(&self, other: &BoolTensor) -> Result<BoolTensor, FerrotorchError>
Pointwise OR.
Sourcepub fn xor(&self, other: &BoolTensor) -> Result<BoolTensor, FerrotorchError>
pub fn xor(&self, other: &BoolTensor) -> Result<BoolTensor, FerrotorchError>
Pointwise XOR.
Sourcepub fn reshape(&self, shape: &[usize]) -> Result<BoolTensor, FerrotorchError>
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).
Sourcepub fn count_true(&self) -> Result<usize, FerrotorchError>
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.
Sourcepub fn any(&self) -> Result<bool, FerrotorchError>
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.
Sourcepub fn all(&self) -> Result<bool, FerrotorchError>
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).
Sourcepub fn gt<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
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)
Sourcepub fn lt<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
pub fn lt<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
Pointwise <. (#615)
Sourcepub fn ge<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
pub fn ge<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
Pointwise >=. (#615)
Sourcepub fn le<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
pub fn le<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
Pointwise <=. (#615)
Sourcepub fn eq_t<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
pub fn eq_t<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
Pointwise ==. (#615)
Sourcepub fn ne<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
pub fn ne<T>(
a: &Tensor<T>,
b: &Tensor<T>,
) -> Result<BoolTensor, FerrotorchError>where
T: Float,
Pointwise !=. (#615)
Sourcepub fn gt_int<I>(
a: &IntTensor<I>,
b: &IntTensor<I>,
) -> Result<BoolTensor, FerrotorchError>where
I: IntElement,
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)
Sourcepub fn lt_int<I>(
a: &IntTensor<I>,
b: &IntTensor<I>,
) -> Result<BoolTensor, FerrotorchError>where
I: IntElement,
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)
Sourcepub fn ge_int<I>(
a: &IntTensor<I>,
b: &IntTensor<I>,
) -> Result<BoolTensor, FerrotorchError>where
I: IntElement,
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)
Sourcepub fn le_int<I>(
a: &IntTensor<I>,
b: &IntTensor<I>,
) -> Result<BoolTensor, FerrotorchError>where
I: IntElement,
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)
Sourcepub fn eq_int<I>(
a: &IntTensor<I>,
b: &IntTensor<I>,
) -> Result<BoolTensor, FerrotorchError>where
I: IntElement,
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)
Sourcepub fn ne_int<I>(
a: &IntTensor<I>,
b: &IntTensor<I>,
) -> Result<BoolTensor, FerrotorchError>where
I: IntElement,
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)
Trait Implementations§
Source§impl Clone for BoolTensor
impl Clone for BoolTensor
Source§fn clone(&self) -> BoolTensor
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)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BoolTensor
impl Debug for BoolTensor
Auto Trait Implementations§
impl !RefUnwindSafe for BoolTensor
impl !UnwindSafe for BoolTensor
impl Freeze for BoolTensor
impl Send for BoolTensor
impl Sync for BoolTensor
impl Unpin for BoolTensor
impl UnsafeUnpin for BoolTensor
Blanket Implementations§
Source§impl<U> AsDistAny for Uwhere
U: 'static,
impl<U> AsDistAny for Uwhere
U: 'static,
Source§fn as_dist_any(&self) -> &(dyn Any + 'static)
fn as_dist_any(&self) -> &(dyn Any + 'static)
&dyn Any for concrete-type downcasting.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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more