Python operator.inv() Examples
The following are 30
code examples of operator.inv().
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
operator
, or try the search function
.
Example #1
Source File: operators.py From sqlalchemy with MIT License | 6 votes |
def __invert__(self): """Implement the ``~`` operator. When used with SQL expressions, results in a NOT operation, equivalent to :func:`_expression.not_`, that is:: ~a is equivalent to:: from sqlalchemy import not_ not_(a) """ return self.operate(inv)
Example #2
Source File: test_clifford.py From clifford with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_normalInv(self, g3): layout, blades = g3, g3.blades e1 = layout.blades['e1'] e2 = layout.blades['e2'] e3 = layout.blades['e3'] assert (2*e1).normalInv() == (0.5*e1) with pytest.raises(ValueError): (0*e1).normalInv() # divide by 0 with pytest.raises(ValueError): (1 + e1 + e2).normalInv() # mixed even and odd grades # produces garbage, but doesn't crash (1 + e1 + e2).normalInv(check=False) # check that not requiring normalInv works fine assert (1 + e1 + e2).inv() == -1 + e1 + e2
Example #3
Source File: cparser.py From pyglet with BSD 3-Clause "New" or "Revised" License | 6 votes |
def p_unary_operator(p): '''unary_operator : '&' | '*' | '+' | '-' | '~' | '!' ''' # reduces to (op, op_str) p[0] = ({ '+': operator.pos, '-': operator.neg, '~': operator.inv, '!': operator.not_, '&': 'AddressOfUnaryOperator', '*': 'DereferenceUnaryOperator'}[p[1]], p[1])
Example #4
Source File: test_intbv.py From myhdl with GNU Lesser General Public License v2.1 | 5 votes |
def testInvert(self): self.unaryCheck(operator.inv)
Example #5
Source File: test_operator.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_invert(self): self.failUnlessRaises(TypeError, operator.invert) self.failUnlessRaises(TypeError, operator.invert, None) self.failUnless(operator.inv(4) == -5)
Example #6
Source File: orm.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def parse_item_operation(specifier): """ Returns a tuple indicating the specifier string, and its related operation (if one was found). If the first character in the specifier is '|', the operator will be OR. If the first character in the specifier is '&', the operator will be AND. If the first character in the specifier is '!', or the specifier starts with "not_", the operator will be AND(existing_query, ~(new_query)). If unspecified, the default operator is OR. :param specifier: a string containing the specifier. :return: tuple """ specifier = specifier.strip() from operator import and_ as AND, inv as INV, or_ as OR def AND_NOT(current, next_): return AND(current, INV(next_)) if specifier.startswith("|"): op = OR specifier = specifier[1:] elif specifier.startswith("&"): op = AND specifier = specifier[1:] elif specifier.startswith("not_"): op = AND_NOT specifier = specifier[4:] elif specifier.startswith("!"): op = AND_NOT specifier = specifier[1:] else: # Default to OR. op = OR return specifier, op
Example #7
Source File: test_operator.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_invert(self): self.failUnlessRaises(TypeError, operator.invert) self.failUnlessRaises(TypeError, operator.invert, None) self.failUnless(operator.inv(4) == -5)
Example #8
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_negate_operator_label(self): orig_expr = or_( self.table1.c.myid == 1, self.table1.c.myid == 2 ).label("foo") expr = not_(orig_expr) isinstance(expr, Label) eq_(expr.name, "foo") is_not_(expr, orig_expr) is_(expr._element.operator, operator.inv) # e.g. and not false_ self.assert_compile( expr, "NOT (mytable.myid = :myid_1 OR mytable.myid = :myid_2)", dialect=default.DefaultDialect(supports_native_boolean=False), )
Example #9
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_negate_operators_1(self): for (py_op, op) in ((operator.neg, "-"), (operator.inv, "NOT ")): for expr, expected in ( (self.table1.c.myid, "mytable.myid"), (literal("foo"), ":param_1"), ): self.assert_compile(py_op(expr), "%s%s" % (op, expected))
Example #10
Source File: test_clifford.py From clifford with BSD 3-Clause "New" or "Revised" License | 5 votes |
def check_inv(self, A): Ainv = None for k in range(3): try: Ainv = A.inv except ValueError: pass if Ainv is None: return for m, a in enumerate(A): for n, b in enumerate(A.inv): if m == n: assert(a | b == 1) else: assert(a | b == 0)
Example #11
Source File: test_clifford.py From clifford with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_inv_g4(self, g4): ''' a numerical test for the inverse of a MV. truth was generated by results of clifford v0.82 ''' layout, blades = g4, g4.blades valA = np.array([ -0.3184271488037198 , -0.8751064635010213 , # noqa -1.5011710376191947 , 1.7946332649746224 , # noqa -0.8899576254164621 , -0.3297631748225678 , # noqa 0.04310366054166925, 1.3970365638677635 , # noqa -1.545423393858595 , 1.7790215501876614 , # noqa 0.4785341530609175 , -1.32279679741638 , # noqa 0.5874769077573831 , -1.0227287710873676 , # noqa 1.779673249468527 , -1.5415648119743852 # noqa ]) valAinv = np.array([ 0.06673424072253006 , -0.005709960252678998, # noqa -0.10758540037163118 , 0.1805895938775471 , # noqa 0.13919236400967427 , 0.04123255613093294 , # noqa -0.015395162562329407, -0.1388977308136247 , # noqa -0.1462160646855434 , -0.1183453106997158 , # noqa -0.06961956152268277 , 0.1396713851886765 , # noqa -0.02572904638749348 , 0.02079613649197489 , # noqa -0.06933660606043765 , -0.05436077710009021 # noqa ]) A = MultiVector(layout=layout, value=valA) Ainv = MultiVector(layout=layout, value=valAinv) np.testing.assert_almost_equal(A.inv().value, Ainv.value)
Example #12
Source File: test_operator.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_invert(self): self.failUnlessRaises(TypeError, operator.invert) self.failUnlessRaises(TypeError, operator.invert, None) self.failUnless(operator.inv(4) == -5)
Example #13
Source File: transform.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __invert__(self): return type(self)(self, operator.inv)
Example #14
Source File: test_operator.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_invert(self): self.assertRaises(TypeError, operator.invert) self.assertRaises(TypeError, operator.invert, None) self.assertTrue(operator.inv(4) == -5)
Example #15
Source File: core.py From pythonflow with Apache License 2.0 | 5 votes |
def __invert__(self): return inv(self, graph=self.graph)
Example #16
Source File: preprocessor.py From pyglet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def p_unary_operator(self, p): '''unary_operator : '+' | '-' | '~' | '!' ''' # reduces to (op, op_str) p[0] = ({ '+': operator.pos, '-': operator.neg, '~': operator.inv, '!': operator.not_}[p[1]], p[1])
Example #17
Source File: myhdlpeek.py From myhdlpeek with MIT License | 5 votes |
def __inv__(self): return self.apply_op1(operator.inv)
Example #18
Source File: test_operators.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_logical_operators(self): def _check_bin_op(op): result = op(df1, df2) expected = DataFrame(op(df1.values, df2.values), index=df1.index, columns=df1.columns) assert result.values.dtype == np.bool_ assert_frame_equal(result, expected) def _check_unary_op(op): result = op(df1) expected = DataFrame(op(df1.values), index=df1.index, columns=df1.columns) assert result.values.dtype == np.bool_ assert_frame_equal(result, expected) df1 = {'a': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}, 'b': {'a': False, 'b': True, 'c': False, 'd': False, 'e': False}, 'c': {'a': False, 'b': False, 'c': True, 'd': False, 'e': False}, 'd': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}, 'e': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}} df2 = {'a': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False}, 'b': {'a': False, 'b': True, 'c': False, 'd': False, 'e': False}, 'c': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False}, 'd': {'a': False, 'b': False, 'c': False, 'd': True, 'e': False}, 'e': {'a': False, 'b': False, 'c': False, 'd': False, 'e': True}} df1 = DataFrame(df1) df2 = DataFrame(df2) _check_bin_op(operator.and_) _check_bin_op(operator.or_) _check_bin_op(operator.xor) _check_unary_op(operator.inv) # TODO: belongs elsewhere
Example #19
Source File: UserLong.py From pycopia with Apache License 2.0 | 5 votes |
def __invert__(self): return self._uop(operator.inv)
Example #20
Source File: UserInt.py From pycopia with Apache License 2.0 | 5 votes |
def __invert__(self): return self._uop(operator.inv)
Example #21
Source File: UserFloat.py From pycopia with Apache License 2.0 | 5 votes |
def __invert__(self): return self._uop(operator.inv)
Example #22
Source File: test_operator.py From oss-ftp with MIT License | 5 votes |
def test_invert(self): self.assertRaises(TypeError, operator.invert) self.assertRaises(TypeError, operator.invert, None) self.assertTrue(operator.inv(4) == -5)
Example #23
Source File: series.py From Computable with MIT License | 5 votes |
def __invert__(self): arr = operator.inv(self.values) return self._constructor(arr, self.index).__finalize__(self) #---------------------------------------------------------------------- # unbox reductions
Example #24
Source File: generic.py From Computable with MIT License | 5 votes |
def __invert__(self): arr = operator.inv(_values_from_object(self)) return self._wrap_array(arr, self.axes, copy=False)
Example #25
Source File: test_operator.py From BinderFilter with MIT License | 5 votes |
def test_invert(self): self.assertRaises(TypeError, operator.invert) self.assertRaises(TypeError, operator.invert, None) self.assertTrue(operator.inv(4) == -5)
Example #26
Source File: test_operator.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_invert(self): self.assertRaises(TypeError, operator.invert) self.assertRaises(TypeError, operator.invert, None) self.assertTrue(operator.inv(4) == -5)
Example #27
Source File: test_operators.py From recruit with Apache License 2.0 | 5 votes |
def test_logical_operators(self): def _check_bin_op(op): result = op(df1, df2) expected = DataFrame(op(df1.values, df2.values), index=df1.index, columns=df1.columns) assert result.values.dtype == np.bool_ assert_frame_equal(result, expected) def _check_unary_op(op): result = op(df1) expected = DataFrame(op(df1.values), index=df1.index, columns=df1.columns) assert result.values.dtype == np.bool_ assert_frame_equal(result, expected) df1 = {'a': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}, 'b': {'a': False, 'b': True, 'c': False, 'd': False, 'e': False}, 'c': {'a': False, 'b': False, 'c': True, 'd': False, 'e': False}, 'd': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}, 'e': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}} df2 = {'a': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False}, 'b': {'a': False, 'b': True, 'c': False, 'd': False, 'e': False}, 'c': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False}, 'd': {'a': False, 'b': False, 'c': False, 'd': True, 'e': False}, 'e': {'a': False, 'b': False, 'c': False, 'd': False, 'e': True}} df1 = DataFrame(df1) df2 = DataFrame(df2) _check_bin_op(operator.and_) _check_bin_op(operator.or_) _check_bin_op(operator.xor) _check_unary_op(operator.inv) # TODO: belongs elsewhere
Example #28
Source File: test_Signal.py From myhdl with GNU Lesser General Public License v2.1 | 5 votes |
def testInvert(self): self.unaryCheck(operator.inv)
Example #29
Source File: test_operators.py From elasticintel with GNU General Public License v3.0 | 4 votes |
def test_logical_operators(self): def _check_bin_op(op): result = op(df1, df2) expected = DataFrame(op(df1.values, df2.values), index=df1.index, columns=df1.columns) assert result.values.dtype == np.bool_ assert_frame_equal(result, expected) def _check_unary_op(op): result = op(df1) expected = DataFrame(op(df1.values), index=df1.index, columns=df1.columns) assert result.values.dtype == np.bool_ assert_frame_equal(result, expected) df1 = {'a': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}, 'b': {'a': False, 'b': True, 'c': False, 'd': False, 'e': False}, 'c': {'a': False, 'b': False, 'c': True, 'd': False, 'e': False}, 'd': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}, 'e': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}} df2 = {'a': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False}, 'b': {'a': False, 'b': True, 'c': False, 'd': False, 'e': False}, 'c': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False}, 'd': {'a': False, 'b': False, 'c': False, 'd': True, 'e': False}, 'e': {'a': False, 'b': False, 'c': False, 'd': False, 'e': True}} df1 = DataFrame(df1) df2 = DataFrame(df2) _check_bin_op(operator.and_) _check_bin_op(operator.or_) _check_bin_op(operator.xor) # operator.neg is deprecated in numpy >= 1.9 _check_unary_op(operator.inv)
Example #30
Source File: test_operators.py From vnpy_crypto with MIT License | 4 votes |
def test_logical_operators(self): def _check_bin_op(op): result = op(df1, df2) expected = DataFrame(op(df1.values, df2.values), index=df1.index, columns=df1.columns) assert result.values.dtype == np.bool_ assert_frame_equal(result, expected) def _check_unary_op(op): result = op(df1) expected = DataFrame(op(df1.values), index=df1.index, columns=df1.columns) assert result.values.dtype == np.bool_ assert_frame_equal(result, expected) df1 = {'a': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}, 'b': {'a': False, 'b': True, 'c': False, 'd': False, 'e': False}, 'c': {'a': False, 'b': False, 'c': True, 'd': False, 'e': False}, 'd': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}, 'e': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}} df2 = {'a': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False}, 'b': {'a': False, 'b': True, 'c': False, 'd': False, 'e': False}, 'c': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False}, 'd': {'a': False, 'b': False, 'c': False, 'd': True, 'e': False}, 'e': {'a': False, 'b': False, 'c': False, 'd': False, 'e': True}} df1 = DataFrame(df1) df2 = DataFrame(df2) _check_bin_op(operator.and_) _check_bin_op(operator.or_) _check_bin_op(operator.xor) # operator.neg is deprecated in numpy >= 1.9 _check_unary_op(operator.inv)