burn icon indicating copy to clipboard operation
burn copied to clipboard

Creating a boolean tensor set to true

Open dhbradshaw opened this issue 2 years ago • 1 comments

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?

dhbradshaw avatar Sep 25 '23 12:09 dhbradshaw

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.

nathanielsimard avatar Sep 25 '23 13:09 nathanielsimard

We can support via full op for bool tensors in #1535. Closing it to track it there.

antimora avatar Mar 29 '24 01:03 antimora