Skip to content

Commit

Permalink
Added support for bitwise not operator [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 16, 2024
1 parent fce403d commit 12fca66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/torch/tensor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Tensor
alias_method :^, :logical_xor
alias_method :<<, :__lshift__
alias_method :>>, :__rshift__
alias_method :~, :bitwise_not

def self.new(*args)
FloatTensor.new(*args)
Expand Down
5 changes: 5 additions & 0 deletions test/tensor_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,9 @@ def test_dup
def test_cumsum_dtype
assert_equal :int64, Torch.tensor([1, 2, 3]).cumsum(dim: 0).dtype
end

def test_bitwise_not
x = Torch.tensor([1, 2, 3])
assert_tensor [-2, -3, -4], ~x
end
end

0 comments on commit 12fca66

Please sign in to comment.