Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • d14115e
  • /
  • tensorly
  • /
  • tenalg
  • /
  • tests
  • /
  • test_generalised_inner_product.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:d02f97ce3d9a47707691e6136c86b0baf4ac8fea
directory badge
swh:1:dir:d31a36253ad717d426817ff94d50b880627049e2

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
test_generalised_inner_product.py
from ... import backend as T
from ..generalised_inner_product import inner
import numpy as np

# Author: Jean Kossaifi
# License: BSD 3 clause

def test_inner():
    tensor_1 = T.tensor(np.arange(3*4).reshape((3, 4)))
    tensor_2 = T.tensor(np.arange(4*2).reshape((4, 2)))
    
    # For one common mode, equivalent to dot product
    res = inner(tensor_1, tensor_2, n_modes=1)
    true_res = T.dot(tensor_1, tensor_2)
    T.assert_array_almost_equal(res, true_res)
    
    # For no common mode, equivalent to inner product
    res = inner(tensor_1, tensor_1, n_modes=None)
    true_res = T.sum(tensor_1**2)
    T.assert_equal(res, true_res)
    
    # Inner product of tensors with different shapes is not defined
    with T.assert_raises(ValueError):
        inner(tensor_1, tensor_2)

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API