Python numpy.core.multiarray.dot() Examples

The following are 30 code examples of numpy.core.multiarray.dot(). 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.core.multiarray , or try the search function .
Example #1
Source File: test_multiarray.py    From ImageFusion with MIT License 6 votes vote down vote up
def test_dot(self):
        a = np.array([[1, 0], [0, 1]])
        b = np.array([[0, 1], [1, 0]])
        c = np.array([[9, 1], [1, -9]])

        assert_equal(np.dot(a, b), a.dot(b))
        assert_equal(np.dot(np.dot(a, b), c), a.dot(b).dot(c))

        # test passing in an output array
        c = np.zeros_like(a)
        a.dot(b, c)
        assert_equal(c, np.dot(a, b))

        # test keyword args
        c = np.zeros_like(a)
        a.dot(b=b, out=c)
        assert_equal(c, np.dot(a, b)) 
Example #2
Source File: numeric.py    From keras-lambda with MIT License 6 votes vote down vote up
def restoredot():
    """
    Restore `dot`, `vdot`, and `innerproduct` to the default non-BLAS
    implementations.

    Typically, the user will only need to call this when troubleshooting
    and installation problem, reproducing the conditions of a build without
    an accelerated BLAS, or when being very careful about benchmarking
    linear algebra operations.

    .. note:: Deprecated in Numpy 1.10
              The cblas functions have been integrated into the multarray
              module and restoredot now longer does anything. It will be
              removed in Numpy 1.11.0.

    See Also
    --------
    alterdot : `restoredot` undoes the effects of `alterdot`.

    """
    # 2014-08-13, 1.10
    warnings.warn("restoredot no longer does anything.", DeprecationWarning) 
Example #3
Source File: test_multiarray.py    From ImageFusion with MIT License 6 votes vote down vote up
def test_dot_3args(self):
        from numpy.core.multiarray import dot

        np.random.seed(22)
        f = np.random.random_sample((1024, 16))
        v = np.random.random_sample((16, 32))

        r = np.empty((1024, 32))
        for i in range(12):
            dot(f, v, r)
        assert_equal(sys.getrefcount(r), 2)
        r2 = dot(f, v, out=None)
        assert_array_equal(r2, r)
        assert_(r is dot(f, v, out=r))

        v = v[:, 0].copy() # v.shape == (16,)
        r = r[:, 0].copy() # r.shape == (1024,)
        r2 = dot(f, v)
        assert_(r is dot(f, v, r))
        assert_array_equal(r2, r) 
Example #4
Source File: test_multiarray.py    From ImageFusion with MIT License 6 votes vote down vote up
def test_dot_override(self):
        class A(object):
            def __numpy_ufunc__(self, ufunc, method, pos, inputs, **kwargs):
                return "A"

        class B(object):
            def __numpy_ufunc__(self, ufunc, method, pos, inputs, **kwargs):
                return NotImplemented

        a = A()
        b = B()
        c = np.array([[1]])

        assert_equal(np.dot(a, b), "A")
        assert_equal(c.dot(a), "A")
        assert_raises(TypeError, np.dot, b, c)
        assert_raises(TypeError, c.dot, b) 
Example #5
Source File: numeric.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def restoredot():
    """
    Restore `dot`, `vdot`, and `innerproduct` to the default non-BLAS
    implementations.

    Typically, the user will only need to call this when troubleshooting
    and installation problem, reproducing the conditions of a build without
    an accelerated BLAS, or when being very careful about benchmarking
    linear algebra operations.

    .. note:: Deprecated in Numpy 1.10
              The cblas functions have been integrated into the multarray
              module and restoredot now longer does anything. It will be
              removed in Numpy 1.11.0.

    See Also
    --------
    alterdot : `restoredot` undoes the effects of `alterdot`.

    """
    # 2014-08-13, 1.10
    warnings.warn("restoredot no longer does anything.", DeprecationWarning) 
Example #6
Source File: test_multiarray.py    From Computable with MIT License 6 votes vote down vote up
def test_dot(self):
        a = np.array([[1, 0], [0, 1]])
        b = np.array([[0, 1], [1, 0]])
        c = np.array([[9, 1], [1, -9]])

        assert_equal(np.dot(a, b), a.dot(b))
        assert_equal(np.dot(np.dot(a, b), c), a.dot(b).dot(c))

        # test passing in an output array
        c = np.zeros_like(a)
        a.dot(b, c)
        assert_equal(c, np.dot(a, b))

        # test keyword args
        c = np.zeros_like(a)
        a.dot(b=b, out=c)
        assert_equal(c, np.dot(a, b)) 
Example #7
Source File: test_multiarray.py    From Computable with MIT License 6 votes vote down vote up
def test_dot_3args(self):
        from numpy.core.multiarray import dot

        np.random.seed(22)
        f = np.random.random_sample((1024, 16))
        v = np.random.random_sample((16, 32))

        r = np.empty((1024, 32))
        for i in range(12):
            dot(f, v, r)
        assert_equal(sys.getrefcount(r), 2)
        r2 = dot(f, v, out=None)
        assert_array_equal(r2, r)
        assert_(r is dot(f, v, out=r))

        v = v[:, 0].copy() # v.shape == (16,)
        r = r[:, 0].copy() # r.shape == (1024,)
        r2 = dot(f, v)
        assert_(r is dot(f, v, r))
        assert_array_equal(r2, r) 
Example #8
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_all(self):
        dims = [(), (1,), (1, 1)]
        for dim1 in dims:
            for dim2 in dims:
                arg1 = rand(*dim1)
                arg2 = rand(*dim2)
                c1 = dot(arg1, arg2)
                c2 = dot_(arg1, arg2)
                assert_(c1.shape == c2.shape)
                assert_almost_equal(c1, c2, decimal=self.N) 
Example #9
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_vecscalar(self):
        b1 = rand(1, 1)
        b2 = rand(1, 8)
        c1 = dot(b1, b2)
        c2 = dot_(b1, b2)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #10
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_columnvect2(self):
        b1 = ones((3, 1)).transpose()
        b2 = [6.2]
        c1 = dot(b2, b1)
        c2 = dot_(b2, b1)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #11
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_columnvect1(self):
        b1 = ones((3, 1))
        b2 = [5.3]
        c1 = dot(b1, b2)
        c2 = dot_(b1, b2)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #12
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_vecvecinner(self):
        b1, b3 = self.b1, self.b3
        c1 = dot(b3, b1)
        c2 = dot_(b3, b1)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #13
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_vecvecouter(self):
        b1, b3 = self.b1, self.b3
        c1 = dot(b1, b3)
        c2 = dot_(b1, b3)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #14
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_vecmat2(self):
        b3, A = self.b3, self.A
        c1 = dot(b3, A.transpose())
        c2 = dot_(b3, A.transpose())
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #15
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_vecmat(self):
        A, b4 = self.A, self.b4
        c1 = dot(b4, A)
        c2 = dot_(b4, A)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #16
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_matvec2(self):
        A, b2 = self.A, self.b2
        c1 = dot(A, b2)
        c2 = dot_(A, b2)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #17
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_matvec(self):
        A, b1 = self.A, self.b1
        c1 = dot(A, b1)
        c2 = dot_(A, b1)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #18
Source File: test_numeric.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_matmat(self):
        A = self.A
        c1 = dot(A.transpose(), A)
        c2 = dot_(A.transpose(), A)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #19
Source File: test_multiarray.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_dot_3args_errors(self):
        from numpy.core.multiarray import dot

        np.random.seed(22)
        f = np.random.random_sample((1024, 16))
        v = np.random.random_sample((16, 32))

        r = np.empty((1024, 31))
        assert_raises(ValueError, dot, f, v, r)

        r = np.empty((1024,))
        assert_raises(ValueError, dot, f, v, r)

        r = np.empty((32,))
        assert_raises(ValueError, dot, f, v, r)

        r = np.empty((32, 1024))
        assert_raises(ValueError, dot, f, v, r)
        assert_raises(ValueError, dot, f, v, r.T)

        r = np.empty((1024, 64))
        assert_raises(ValueError, dot, f, v, r[:, ::2])
        assert_raises(ValueError, dot, f, v, r[:, :32])

        r = np.empty((1024, 32), dtype=np.float32)
        assert_raises(ValueError, dot, f, v, r)

        r = np.empty((1024, 32), dtype=int)
        assert_raises(ValueError, dot, f, v, r) 
Example #20
Source File: numeric.py    From keras-lambda with MIT License 5 votes vote down vote up
def alterdot():
    """
    Change `dot`, `vdot`, and `inner` to use accelerated BLAS functions.

    Typically, as a user of Numpy, you do not explicitly call this
    function. If Numpy is built with an accelerated BLAS, this function is
    automatically called when Numpy is imported.

    When Numpy is built with an accelerated BLAS like ATLAS, these
    functions are replaced to make use of the faster implementations.  The
    faster implementations only affect float32, float64, complex64, and
    complex128 arrays. Furthermore, the BLAS API only includes
    matrix-matrix, matrix-vector, and vector-vector products. Products of
    arrays with larger dimensionalities use the built in functions and are
    not accelerated.

    .. note:: Deprecated in Numpy 1.10
              The cblas functions have been integrated into the multarray
              module and alterdot now longer does anything. It will be
              removed in Numpy 1.11.0.

    See Also
    --------
    restoredot : `restoredot` undoes the effects of `alterdot`.

    """
    # 2014-08-13, 1.10
    warnings.warn("alterdot no longer does anything.", DeprecationWarning) 
Example #21
Source File: test_multiarray.py    From ImageFusion with MIT License 5 votes vote down vote up
def test_dot_2args(self):
        from numpy.core.multiarray import dot

        a = np.array([[1, 2], [3, 4]], dtype=float)
        b = np.array([[1, 0], [1, 1]], dtype=float)
        c = np.array([[3, 2], [7, 4]], dtype=float)

        d = dot(a, b)
        assert_allclose(c, d) 
Example #22
Source File: test_multiarray.py    From Computable with MIT License 5 votes vote down vote up
def test_dot_2args(self):
        from numpy.core.multiarray import dot

        a = np.array([[1, 2], [3, 4]], dtype=float)
        b = np.array([[1, 0], [1, 1]], dtype=float)
        c = np.array([[3, 2], [7, 4]], dtype=float)

        d = dot(a, b)
        assert_allclose(c, d) 
Example #23
Source File: numeric.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def alterdot():
    """
    Change `dot`, `vdot`, and `inner` to use accelerated BLAS functions.

    Typically, as a user of Numpy, you do not explicitly call this
    function. If Numpy is built with an accelerated BLAS, this function is
    automatically called when Numpy is imported.

    When Numpy is built with an accelerated BLAS like ATLAS, these
    functions are replaced to make use of the faster implementations.  The
    faster implementations only affect float32, float64, complex64, and
    complex128 arrays. Furthermore, the BLAS API only includes
    matrix-matrix, matrix-vector, and vector-vector products. Products of
    arrays with larger dimensionalities use the built in functions and are
    not accelerated.

    .. note:: Deprecated in Numpy 1.10
              The cblas functions have been integrated into the multarray
              module and alterdot now longer does anything. It will be
              removed in Numpy 1.11.0.

    See Also
    --------
    restoredot : `restoredot` undoes the effects of `alterdot`.

    """
    # 2014-08-13, 1.10
    warnings.warn("alterdot no longer does anything.", DeprecationWarning) 
Example #24
Source File: test_numeric.py    From Computable with MIT License 5 votes vote down vote up
def test_all(self):
        dims = [(), (1,), (1, 1)]
        for dim1 in dims:
            for dim2 in dims:
                arg1 = rand(*dim1)
                arg2 = rand(*dim2)
                c1 = dot(arg1, arg2)
                c2 = dot_(arg1, arg2)
                assert_(c1.shape == c2.shape)
                assert_almost_equal(c1, c2, decimal=self.N) 
Example #25
Source File: test_numeric.py    From Computable with MIT License 5 votes vote down vote up
def test_vecscalar2(self):
        b1 = rand(8, 1)
        b2 = rand(1, 1)
        c1 = dot(b1, b2)
        c2 = dot_(b1, b2)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #26
Source File: test_numeric.py    From Computable with MIT License 5 votes vote down vote up
def test_vecscalar(self):
        b1 = rand(1, 1)
        b2 = rand(1, 8)
        c1 = dot(b1, b2)
        c2 = dot_(b1, b2)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #27
Source File: test_numeric.py    From Computable with MIT License 5 votes vote down vote up
def test_columnvect2(self):
        b1 = ones((3, 1)).transpose()
        b2 = [6.2]
        c1 = dot(b2, b1)
        c2 = dot_(b2, b1)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #28
Source File: test_numeric.py    From Computable with MIT License 5 votes vote down vote up
def test_columnvect1(self):
        b1 = ones((3, 1))
        b2 = [5.3]
        c1 = dot(b1, b2)
        c2 = dot_(b1, b2)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #29
Source File: test_numeric.py    From Computable with MIT License 5 votes vote down vote up
def test_vecvecouter(self):
        b1, b3 = self.b1, self.b3
        c1 = dot(b1, b3)
        c2 = dot_(b1, b3)
        assert_almost_equal(c1, c2, decimal=self.N) 
Example #30
Source File: test_numeric.py    From Computable with MIT License 5 votes vote down vote up
def test_vecmat3(self):
        A, b4 = self.A, self.b4
        c1 = dot(A.transpose(), b4)
        c2 = dot_(A.transpose(), b4)
        assert_almost_equal(c1, c2, decimal=self.N)