burn
burn copied to clipboard
Creating a boolean tensor set to true
It looks like boolean tensors don't currently support zeroes or ones or fill.
empty works to initialize a boolean to false, as in
/// Create a boolean tensor that is all false.
#[test]
fn etude_15() {
let t = Tensor::<B, 2, Bool>::empty([2, 2]);
assert_eq!(vec![false, false, false, false], t.to_data().value);
assert_eq!(vec![2, 2], t.to_data().shape.dims);
}
What is the best way to initialize a boolean to true?
I woun't count on empty to always be false, it will depend on the backend in use and the memory layout during training or inference!
For bool tensors you can probably use from_data with arrays.
let t = Tensor::from_data([[true; 2]; 2]);
We probably should provide more ways to instantiate bool tensors.
We can support via full op for bool tensors in #1535. Closing it to track it there.