Python numpy.bitwise_xor() Examples
The following are 30
code examples of numpy.bitwise_xor().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.

Example #1
Source File: test_ufunc.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #2
Source File: test_umath.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #3
Source File: test_umath.py From pySINDy with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #4
Source File: test_ufunc.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod, np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal] a = np.array('1') b = 1 c = np.array([1., 2.]) for f in binary_funcs: assert_raises(TypeError, f, a, b) assert_raises(TypeError, f, c, a)
Example #5
Source File: seqc_tests.py From qupulse with MIT License | 6 votes |
def get_unique_wfs(n=10000, duration=32, defined_channels=frozenset(['A'])): if not hasattr(get_unique_wfs, 'cache'): get_unique_wfs.cache = {} key = (n, duration) if key not in get_unique_wfs.cache: h = hash(key) base = np.bitwise_xor(np.linspace(-h, h, num=duration + n, dtype=np.int64), h) base = base / np.max(np.abs(base)) get_unique_wfs.cache[key] = [ DummyWaveform(duration=duration, sample_output=base[idx:idx+duration], defined_channels=defined_channels) for idx in range(n) ] return get_unique_wfs.cache[key]
Example #6
Source File: test_umath.py From recruit with Apache License 2.0 | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #7
Source File: test_ufunc.py From coffeegrindsize with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod, np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal] a = np.array('1') b = 1 c = np.array([1., 2.]) for f in binary_funcs: assert_raises(TypeError, f, a, b) assert_raises(TypeError, f, c, a)
Example #8
Source File: test_umath.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #9
Source File: matrixmod2.py From pyGSTi with Apache License 2.0 | 6 votes |
def gaussian_elimination_mod2(A): """ Gaussian elimination mod2 of A. """ A = _np.array(A, dtype='int') m, n = A.shape i, j = 0, 0 while (i < m) and (j < n): k = A[i:m, j].argmax() + i A[_np.array([i, k]), :] = A[_np.array([k, i]), :] aijn = _np.array([A[i, j:]]) col = _np.array([A[:, j]]).T col[i] = 0 flip = _np.dot(col, aijn) A[:, j:] = _np.bitwise_xor(A[:, j:], flip) i += 1 j += 1 return A
Example #10
Source File: test_umath.py From coffeegrindsize with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #11
Source File: elemwise.py From attention-lvcsr with MIT License | 6 votes |
def set_ufunc(self, scalar_op): # This is probably a speed up of the implementation if isinstance(scalar_op, theano.scalar.basic.Add): self.ufunc = numpy.add elif isinstance(scalar_op, theano.scalar.basic.Mul): self.ufunc = numpy.multiply elif isinstance(scalar_op, theano.scalar.basic.Maximum): self.ufunc = numpy.maximum elif isinstance(scalar_op, theano.scalar.basic.Minimum): self.ufunc = numpy.minimum elif isinstance(scalar_op, theano.scalar.basic.AND): self.ufunc = numpy.bitwise_and elif isinstance(scalar_op, theano.scalar.basic.OR): self.ufunc = numpy.bitwise_or elif isinstance(scalar_op, theano.scalar.basic.XOR): self.ufunc = numpy.bitwise_xor else: self.ufunc = numpy.frompyfunc(scalar_op.impl, 2, 1)
Example #12
Source File: elemwise.py From D-VAE with MIT License | 6 votes |
def set_ufunc(self, scalar_op): # This is probably a speed up of the implementation if isinstance(scalar_op, theano.scalar.basic.Add): self.ufunc = numpy.add elif isinstance(scalar_op, theano.scalar.basic.Mul): self.ufunc = numpy.multiply elif isinstance(scalar_op, theano.scalar.basic.Maximum): self.ufunc = numpy.maximum elif isinstance(scalar_op, theano.scalar.basic.Minimum): self.ufunc = numpy.minimum elif isinstance(scalar_op, theano.scalar.basic.AND): self.ufunc = numpy.bitwise_and elif isinstance(scalar_op, theano.scalar.basic.OR): self.ufunc = numpy.bitwise_or elif isinstance(scalar_op, theano.scalar.basic.XOR): self.ufunc = numpy.bitwise_xor else: self.ufunc = numpy.frompyfunc(scalar_op.impl, 2, 1)
Example #13
Source File: test_ufunc.py From vnpy_crypto with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #14
Source File: test_ufunc.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #15
Source File: test_umath.py From vnpy_crypto with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #16
Source File: test_ufunc.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #17
Source File: test_ufunc.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod, np.greater, np.greater_equal, np.less, np.less_equal, np.equal, np.not_equal] a = np.array('1') b = 1 c = np.array([1., 2.]) for f in binary_funcs: assert_raises(TypeError, f, a, b) assert_raises(TypeError, f, c, a)
Example #18
Source File: test_ufunc.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #19
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #20
Source File: test_umath.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #21
Source File: test_umath.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_values(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_equal(np.bitwise_not(zeros), ones, err_msg=msg) assert_equal(np.bitwise_not(ones), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg) assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg) assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
Example #22
Source File: test_ufunc.py From pySINDy with MIT License | 6 votes |
def test_NotImplemented_not_returned(self): # See gh-5964 and gh-2091. Some of these functions are not operator # related and were fixed for other reasons in the past. binary_funcs = [ np.power, np.add, np.subtract, np.multiply, np.divide, np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or, np.bitwise_xor, np.left_shift, np.right_shift, np.fmax, np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2, np.logical_and, np.logical_or, np.logical_xor, np.maximum, np.minimum, np.mod ] # These functions still return NotImplemented. Will be fixed in # future. # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal] a = np.array('1') b = 1 for f in binary_funcs: assert_raises(TypeError, f, a, b)
Example #23
Source File: test_umath.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_truth_table_bitwise(self): arg1 = [False, False, True, True] arg2 = [False, True, False, True] out = [False, True, True, True] assert_equal(np.bitwise_or(arg1, arg2), out) out = [False, False, False, True] assert_equal(np.bitwise_and(arg1, arg2), out) out = [False, True, True, False] assert_equal(np.bitwise_xor(arg1, arg2), out)
Example #24
Source File: test_umath.py From pySINDy with MIT License | 5 votes |
def test_truth_table_bitwise(self): arg1 = [False, False, True, True] arg2 = [False, True, False, True] out = [False, True, True, True] assert_equal(np.bitwise_or(arg1, arg2), out) out = [False, False, False, True] assert_equal(np.bitwise_and(arg1, arg2), out) out = [False, True, True, False] assert_equal(np.bitwise_xor(arg1, arg2), out)
Example #25
Source File: test_umath.py From pySINDy with MIT License | 5 votes |
def test_identity(self): assert_(np.bitwise_or.identity == 0, 'bitwise_or') assert_(np.bitwise_xor.identity == 0, 'bitwise_xor') assert_(np.bitwise_and.identity == -1, 'bitwise_and')
Example #26
Source File: securenn_test.py From tf-encrypted with Apache License 2.0 | 5 votes |
def _core_test(self, tensor_factory): prot = tfe.protocol.SecureNN(tensor_factory=tensor_factory) bit_dtype = prot.prime_factory val_dtype = prot.tensor_factory x = np.array([21, 21, 21, 21, 21, 21, 21, 21], dtype=np.int32,).reshape( (2, 2, 2) ) r = np.array([36, 20, 21, 22, 36, 20, 21, 22], dtype=np.int32,).reshape( (2, 2, 2) ) beta = np.array([0, 0, 0, 0, 1, 1, 1, 1], dtype=np.int32,).reshape((2, 2, 2)) expected = np.bitwise_xor(x > r, beta.astype(bool)).astype(np.int32) x_native = tf.convert_to_tensor(x, dtype=val_dtype.native_type) x_bits_preshare = val_dtype.tensor(x_native).bits(bit_dtype) x_bits = prot._share(x_bits_preshare) # pylint: disable=protected-access r_native = tf.convert_to_tensor(r, dtype=val_dtype.native_type) r0 = r1 = val_dtype.tensor(r_native) beta_native = tf.convert_to_tensor(beta, dtype=bit_dtype.native_type) beta0 = beta1 = bit_dtype.tensor(beta_native) res = _private_compare( prot, x_bits=PondPrivateTensor(prot, *x_bits, False), r=PondPublicTensor(prot, r0, r1, False), beta=PondPublicTensor(prot, beta0, beta1, False), ) with tfe.Session() as sess: actual = sess.run(res.reveal().value_on_0.to_native()) np.testing.assert_array_equal(actual, expected)
Example #27
Source File: test_umath.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_types(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_(np.bitwise_not(zeros).dtype == dt, msg) assert_(np.bitwise_or(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_xor(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_and(zeros, zeros).dtype == dt, msg)
Example #28
Source File: utils_geom.py From pyslam with GNU General Public License v3.0 | 5 votes |
def hamming_distance(a, b): #r = (1 << np.arange(8))[:,None] #return np.count_nonzero((np.bitwise_xor(a,b) & r) != 0) return np.count_nonzero(a!=b)
Example #29
Source File: test_umath.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_identity(self): assert_(np.bitwise_or.identity == 0, 'bitwise_or') assert_(np.bitwise_xor.identity == 0, 'bitwise_xor') assert_(np.bitwise_and.identity == -1, 'bitwise_and')
Example #30
Source File: test_umath.py From pySINDy with MIT License | 5 votes |
def test_types(self): for dt in self.bitwise_types: zeros = np.array([0], dtype=dt) ones = np.array([-1], dtype=dt) msg = "dt = '%s'" % dt.char assert_(np.bitwise_not(zeros).dtype == dt, msg) assert_(np.bitwise_or(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_xor(zeros, zeros).dtype == dt, msg) assert_(np.bitwise_and(zeros, zeros).dtype == dt, msg)