Python numpy.fmod() Examples

The following are 30 code examples for showing how to use numpy.fmod(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module numpy , or try the search function .

Example 1
Project: recruit   Author: Frank-qlu   File: test_ufunc.py    License: Apache License 2.0 6 votes vote down vote up
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 2
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_ufunc.py    License: MIT License 6 votes vote down vote up
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 3
Project: vnpy_crypto   Author: birforce   File: test_ufunc.py    License: MIT License 6 votes vote down vote up
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 4
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_ufunc.py    License: MIT License 6 votes vote down vote up
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
Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_ufunc.py    License: MIT License 6 votes vote down vote up
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 6
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 7
Project: pySINDy   Author: luckystarufo   File: test_ufunc.py    License: MIT License 6 votes vote down vote up
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 8
Project: mxnet-lambda   Author: awslabs   File: test_ufunc.py    License: Apache License 2.0 6 votes vote down vote up
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 9
Project: elasticintel   Author: securityclippy   File: test_ufunc.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 10
Project: coffeegrindsize   Author: jgagneastro   File: test_ufunc.py    License: MIT License 6 votes vote down vote up
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 11
Project: incubator-tvm   Author: apache   File: test_target_codegen_cuda.py    License: Apache License 2.0 6 votes vote down vote up
def test_vectorized_intrin2(dtype="float32"):
    c2 = tvm.tir.const(2, dtype=dtype)
    test_funcs = [
        (tvm.tir.power, lambda x : np.power(x, 2.0)),
        (tvm.tir.fmod,  lambda x : np.fmod(x, 2.0))
    ]
    def run_test(tvm_intrin, np_func):
        if not tvm.gpu(0).exist or not tvm.runtime.enabled("cuda"):
            print("skip because cuda is not enabled..")
            return

        n = 128
        A = te.placeholder((n,), dtype=dtype, name='A')
        B = te.compute((n,), lambda i: tvm_intrin(A[i], c2), name='B')
        s = sched(B)
        f = tvm.build(s, [A, B], "cuda")
        ctx = tvm.gpu(0)
        a = tvm.nd.array(np.random.uniform(0, 1, size=n).astype(A.dtype), ctx)
        b = tvm.nd.array(np.zeros(shape=(n,)).astype(A.dtype), ctx)
        f(a, b)
        tvm.testing.assert_allclose(b.asnumpy(), np_func(a.asnumpy()), atol=1e-3, rtol=1e-3)

    for func in test_funcs:
        run_test(*func) 
Example 12
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda   Author: PacktPublishing   File: test_ufunc.py    License: MIT License 6 votes vote down vote up
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 13
Project: twitter-stock-recommendation   Author: alvarobartt   File: test_ufunc.py    License: MIT License 6 votes vote down vote up
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
Project: keras-lambda   Author: sunilmallya   File: test_ufunc.py    License: MIT License 6 votes vote down vote up
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
Project: onnx-tensorflow   Author: onnx   File: test_node.py    License: Apache License 2.0 5 votes vote down vote up
def test_mod(self):
    if legacy_opset_pre_ver(10):
      raise unittest.SkipTest("ONNX version {} doesn't support Mod.".format(
          defs.onnx_opset_version()))
    x = self._get_rnd_float32(shape=[5, 5])
    y = self._get_rnd_float32(shape=[5, 5])
    node_def = helper.make_node("Mod", ["X", "Y"], ["Z"], fmod=0)
    output = run_node(node_def, [x, y])
    np.testing.assert_almost_equal(output["Z"], np.mod(x, y))
    node_def = helper.make_node("Mod", ["X", "Y"], ["Z"], fmod=1)
    output = run_node(node_def, [x, y])
    np.testing.assert_almost_equal(output["Z"], np.fmod(x, y)) 
Example 16
Project: K3D-jupyter   Author: K3D-tools   File: transform.py    License: MIT License 5 votes vote down vote up
def __setattr__(self, key, value):
        """Set attributes with conversion to ndarray where needed."""
        is_set = hasattr(self, key)  # == False in constructor

        # parameter canonicalization and some validation via reshaping
        if value is None:
            # TODO: maybe forbid for some fields
            pass
        elif key == 'translation':
            value = np.array(value, dtype=np.float32).reshape(3, 1)
        elif key == 'rotation':
            value = np.array(value, dtype=np.float32).reshape(4)
            value[0] = np.fmod(value[0], 2.0 * np.pi)

            if value[0] < 0.0:
                value[0] += 2.0 * np.pi

            value[0] = np.cos(value[0] / 2)

            norm = np.linalg.norm(value[1:4])
            needed_norm = np.sqrt(1 - value[0] * value[0])
            if abs(norm - needed_norm) > _epsilon:
                if norm < _epsilon:
                    raise ValueError('Norm of (x, y, z) part of quaternion too close to zero')
                value[1:4] = value[1:4] / norm * needed_norm
            # assert abs(np.linalg.norm(value) - 1.0) < _epsilon
        elif key == 'scaling':
            value = np.array(value, dtype=np.float32).reshape(3)
        elif key in ['parent_matrix', 'custom_matrix', 'model_matrix']:
            value = np.array(value, dtype=np.float32).reshape((4, 4))

        super(Transform, self).__setattr__(key, value)

        if is_set and key != 'model_matrix':
            self._recompute_matrix()
            self._notify_dependants() 
Example 17
Project: hcipy   Author: ehpor   File: periodic_optical_element.py    License: MIT License 5 votes vote down vote up
def __init__(self, input_grid, pitch, apodization, orientation=0, even_grid=False):
		'''An even asphere micro-lens array.

		Parameters
		----------
		input_grid : Grid
			The grid on which the periodic optical element is evaluated.
		pitch : scalar
			The pitch of the periodic optical element.
		apodization : Apodizer
			The apodizer that will be evaluated on the periodic grid.
		orientation : scalar
			The orientation of the periodic optical element.
		even_grid : bool
			This determines whether zero is in between two elements or if it is the center of an element.
		'''
		self.input_grid = input_grid.copy()
		self.input_grid = self.input_grid.rotated(orientation)

		if even_grid:
			xf = (np.fmod(abs(self.input_grid.x), pitch) - pitch / 2) * np.sign(self.input_grid.x)
			yf = (np.fmod(abs(self.input_grid.y), pitch) - pitch / 2) * np.sign(self.input_grid.y)
		else:
			xf = (np.fmod(abs(self.input_grid.x) + pitch / 2, pitch) - pitch / 2) * np.sign(self.input_grid.x)
			yf = (np.fmod(abs(self.input_grid.y) + pitch / 2, pitch) - pitch / 2) * np.sign(self.input_grid.y)

		periodic_grid = CartesianGrid(UnstructuredCoords((xf, yf)))
		self.apodization = apodization(periodic_grid) 
Example 18
Project: chainer   Author: chainer   File: test_fmod.py    License: MIT License 5 votes vote down vote up
def forward(self, inputs, device):
        x, divisor = inputs
        y = functions.fmod(x, divisor)
        return y, 
Example 19
Project: chainer   Author: chainer   File: test_fmod.py    License: MIT License 5 votes vote down vote up
def forward_expected(self, inputs):
        x, divisor = inputs
        expected = numpy.fmod(x, divisor)
        expected = numpy.asarray(expected)
        return expected, 
Example 20
Project: deep_image_model   Author: tobegit3hub   File: math_ops_test.py    License: Apache License 2.0 5 votes vote down vote up
def testFloat(self):
    x = [0.5, 0.7, 0.3]
    for dtype in [np.float32, np.double]:
      # Test scalar and vector versions.
      for denom in [x[0], [x[0]] * 3]:
        x_np = np.array(x, dtype=dtype)
        with self.test_session(use_gpu=True):
          x_tf = constant_op.constant(x_np, shape=x_np.shape)
          y_tf = math_ops.mod(x_tf, denom)
          y_tf_np = y_tf.eval()
          y_np = np.fmod(x_np, denom)
        self.assertAllClose(y_tf_np, y_np, atol=1e-2) 
Example 21
Project: deep_image_model   Author: tobegit3hub   File: math_ops_test.py    License: Apache License 2.0 5 votes vote down vote up
def testTruncateModInt(self):
    nums, divs = self.intTestData()
    with self.test_session():
      tf_result = math_ops.truncatemod(nums, divs).eval()
      np_result = np.fmod(nums, divs)
      self.assertAllEqual(tf_result, np_result) 
Example 22
Project: deep_image_model   Author: tobegit3hub   File: math_ops_test.py    License: Apache License 2.0 5 votes vote down vote up
def testTruncateModFloat(self):
    nums, divs = self.floatTestData()
    with self.test_session():
      tf_result = math_ops.truncatemod(nums, divs).eval()
      np_result = np.fmod(nums, divs)
      self.assertAllEqual(tf_result, np_result) 
Example 23
Project: flappy   Author: purdue-biorobotics   File: controller_maneuver.py    License: MIT License 5 votes vote down vote up
def wrap_180(self, angle):
		if (angle > 3*np.pi or angle < -3*np.pi):
			angle = np.fmod(angle,2*np.pi)
		if (angle > np.pi):
			angle = angle - 2*np.pi
		if (angle < - np.pi):
			angle = angle + 2*np.pi
		return angle; 
Example 24
Project: flappy   Author: purdue-biorobotics   File: pid_controller.py    License: MIT License 5 votes vote down vote up
def wrap_180(self, angle):
		if (angle > 3*np.pi or angle < -3*np.pi):
			angle = np.fmod(angle,2*np.pi)
		if (angle > np.pi):
			angle = angle - 2*np.pi
		if (angle < - np.pi):
			angle = angle + 2*np.pi
		return angle; 
Example 25
Project: flappy   Author: purdue-biorobotics   File: pid_xy_arc_z.py    License: MIT License 5 votes vote down vote up
def wrap_180(self, angle):
		if (angle > 3*np.pi or angle < -3*np.pi):
			angle = np.fmod(angle,2*np.pi)
		if (angle > np.pi):
			angle = angle - 2*np.pi
		if (angle < - np.pi):
			angle = angle + 2*np.pi
		return angle; 
Example 26
Project: flappy   Author: purdue-biorobotics   File: pid_xy_arc_z_maneuver.py    License: MIT License 5 votes vote down vote up
def wrap_180(self, angle):
		if (angle > 3*np.pi or angle < -3*np.pi):
			angle = np.fmod(angle,2*np.pi)
		if (angle > np.pi):
			angle = angle - 2*np.pi
		if (angle < - np.pi):
			angle = angle + 2*np.pi
		return angle; 
Example 27
Project: flappy   Author: purdue-biorobotics   File: controller_no_base.py    License: MIT License 5 votes vote down vote up
def wrap_180(self, angle):
		if (angle > 3*np.pi or angle < -3*np.pi):
			angle = np.fmod(angle,2*np.pi)
		if (angle > np.pi):
			angle = angle - 2*np.pi
		if (angle < - np.pi):
			angle = angle + 2*np.pi
		return angle; 
Example 28
Project: qkit   Author: qkitgroup   File: circlefit.py    License: GNU General Public License v2.0 5 votes vote down vote up
def _periodic_boundary(self,x,bound):
        return np.fmod(x,bound)-np.trunc(x/bound)*bound 
Example 29
Project: multi-modal-regression   Author: JHUVisionLab   File: evaluateGeodesicRegressionModel.py    License: MIT License 5 votes vote down vote up
def myProj(x):
	angle = torch.norm(x, 2, 1, True)
	axis = F.normalize(x)
	angle = torch.fmod(angle, 2*np.pi)
	return angle*axis


# my model for pose estimation: feature model + 1layer pose model x 12 
Example 30
Project: sparkit-learn   Author: lensacom   File: test_rdd.py    License: Apache License 2.0 5 votes vote down vote up
def test_fmod(self):
        A, A_rdd = self.make_dense_rdd((8, 3))
        B, B_rdd = self.make_dense_rdd((1, 3))
        np_res = np.fmod(A, B)
        assert_array_equal(
            A_rdd.fmod(B).toarray(), np_res
        )