Python numpy.einsum_path() Examples
The following are 30 code examples for showing how to use numpy.einsum_path(). 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_einsum.py License: Apache License 2.0 | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 2
Project: recruit Author: Frank-qlu File: test_einsum.py License: Apache License 2.0 | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') print(path) self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') print(path) self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
Example 3
Project: recruit Author: Frank-qlu File: test_einsum.py License: Apache License 2.0 | 6 votes |
def test_path_type_input(self): # Test explicit path handeling path_test = self.build_operands('dcc,fce,ea,dbf->ab') path, path_str = np.einsum_path(*path_test, optimize=False) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*path_test, optimize=True) self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 1), (0, 1)]) exp_path = ['einsum_path', (0, 2), (0, 2), (0, 1)] path, path_str = np.einsum_path(*path_test, optimize=exp_path) self.assert_path_equal(path, exp_path) # Double check einsum works on the input path noopt = np.einsum(*path_test, optimize=False) opt = np.einsum(*path_test, optimize=exp_path) assert_almost_equal(noopt, opt)
Example 4
Project: vnpy_crypto Author: birforce File: test_einsum.py License: MIT License | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 5
Project: vnpy_crypto Author: birforce File: test_einsum.py License: MIT License | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (1, 4), (2, 4), (1, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
Example 6
Project: vnpy_crypto Author: birforce File: test_einsum.py License: MIT License | 6 votes |
def test_path_type_input(self): # Test explicit path handeling path_test = self.build_operands('dcc,fce,ea,dbf->ab') path, path_str = np.einsum_path(*path_test, optimize=False) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*path_test, optimize=True) self.assert_path_equal(path, ['einsum_path', (0, 3), (0, 2), (0, 1)]) exp_path = ['einsum_path', (0, 2), (0, 2), (0, 1)] path, path_str = np.einsum_path(*path_test, optimize=exp_path) self.assert_path_equal(path, exp_path) # Double check einsum works on the input path noopt = np.einsum(*path_test, optimize=False) opt = np.einsum(*path_test, optimize=exp_path) assert_almost_equal(noopt, opt)
Example 7
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_einsum.py License: MIT License | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 8
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_einsum.py License: MIT License | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') print(path) self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') print(path) self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
Example 9
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_einsum.py License: MIT License | 6 votes |
def test_path_type_input(self): # Test explicit path handeling path_test = self.build_operands('dcc,fce,ea,dbf->ab') path, path_str = np.einsum_path(*path_test, optimize=False) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*path_test, optimize=True) self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 1), (0, 1)]) exp_path = ['einsum_path', (0, 2), (0, 2), (0, 1)] path, path_str = np.einsum_path(*path_test, optimize=exp_path) self.assert_path_equal(path, exp_path) # Double check einsum works on the input path noopt = np.einsum(*path_test, optimize=False) opt = np.einsum(*path_test, optimize=exp_path) assert_almost_equal(noopt, opt)
Example 10
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_einsum.py License: MIT License | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 11
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_einsum.py License: MIT License | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') print(path) self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') print(path) self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
Example 12
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_einsum.py License: MIT License | 6 votes |
def test_path_type_input(self): # Test explicit path handeling path_test = self.build_operands('dcc,fce,ea,dbf->ab') path, path_str = np.einsum_path(*path_test, optimize=False) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*path_test, optimize=True) self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 1), (0, 1)]) exp_path = ['einsum_path', (0, 2), (0, 2), (0, 1)] path, path_str = np.einsum_path(*path_test, optimize=exp_path) self.assert_path_equal(path, exp_path) # Double check einsum works on the input path noopt = np.einsum(*path_test, optimize=False) opt = np.einsum(*path_test, optimize=exp_path) assert_almost_equal(noopt, opt)
Example 13
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_einsum.py License: Apache License 2.0 | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 14
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_einsum.py License: Apache License 2.0 | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') print(path) self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') print(path) self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
Example 15
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_einsum.py License: Apache License 2.0 | 6 votes |
def test_path_type_input(self): # Test explicit path handeling path_test = self.build_operands('dcc,fce,ea,dbf->ab') path, path_str = np.einsum_path(*path_test, optimize=False) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*path_test, optimize=True) self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 1), (0, 1)]) exp_path = ['einsum_path', (0, 2), (0, 2), (0, 1)] path, path_str = np.einsum_path(*path_test, optimize=exp_path) self.assert_path_equal(path, exp_path) # Double check einsum works on the input path noopt = np.einsum(*path_test, optimize=False) opt = np.einsum(*path_test, optimize=exp_path) assert_almost_equal(noopt, opt)
Example 16
Project: pySINDy Author: luckystarufo File: test_einsum.py License: MIT License | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 17
Project: pySINDy Author: luckystarufo File: test_einsum.py License: MIT License | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') print(path) self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') print(path) self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
Example 18
Project: pySINDy Author: luckystarufo File: test_einsum.py License: MIT License | 6 votes |
def test_path_type_input(self): # Test explicit path handeling path_test = self.build_operands('dcc,fce,ea,dbf->ab') path, path_str = np.einsum_path(*path_test, optimize=False) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*path_test, optimize=True) self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 1), (0, 1)]) exp_path = ['einsum_path', (0, 2), (0, 2), (0, 1)] path, path_str = np.einsum_path(*path_test, optimize=exp_path) self.assert_path_equal(path, exp_path) # Double check einsum works on the input path noopt = np.einsum(*path_test, optimize=False) opt = np.einsum(*path_test, optimize=exp_path) assert_almost_equal(noopt, opt)
Example 19
Project: mxnet-lambda Author: awslabs File: test_einsum.py License: Apache License 2.0 | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 20
Project: mxnet-lambda Author: awslabs File: test_einsum.py License: Apache License 2.0 | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (1, 4), (2, 4), (1, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
Example 21
Project: mxnet-lambda Author: awslabs File: test_einsum.py License: Apache License 2.0 | 6 votes |
def test_path_type_input(self): # Test explicit path handeling path_test = self.build_operands('dcc,fce,ea,dbf->ab') path, path_str = np.einsum_path(*path_test, optimize=False) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*path_test, optimize=True) self.assert_path_equal(path, ['einsum_path', (0, 3), (0, 2), (0, 1)]) exp_path = ['einsum_path', (0, 2), (0, 2), (0, 1)] path, path_str = np.einsum_path(*path_test, optimize=exp_path) self.assert_path_equal(path, exp_path) # Double check einsum works on the input path noopt = np.einsum(*path_test, optimize=False) opt = np.einsum(*path_test, optimize=exp_path) assert_almost_equal(noopt, opt)
Example 22
Project: faceswap Author: deepfakes File: sort.py License: GNU General Public License v3.0 | 6 votes |
def _convert_color(imgs, same_size, method): """ Helper function to convert colorspaces """ if method.endswith('gray'): conversion = np.array([[0.0722], [0.7152], [0.2126]]) else: conversion = np.array([[0.25, 0.5, 0.25], [-0.5, 0.0, 0.5], [-0.25, 0.5, -0.25]]) if same_size: path = 'greedy' operation = 'bijk, kl -> bijl' if method.endswith('gray') else 'bijl, kl -> bijk' else: operation = 'ijk, kl -> ijl' if method.endswith('gray') else 'ijl, kl -> ijk' path = np.einsum_path(operation, imgs[0][..., :3], conversion, optimize='optimal')[0] progress_bar = tqdm(imgs, desc="Converting", file=sys.stdout) images = [np.einsum(operation, img[..., :3], conversion, optimize=path).astype('float32') for img in progress_bar] return images
Example 23
Project: elasticintel Author: securityclippy File: test_einsum.py License: GNU General Public License v3.0 | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 24
Project: elasticintel Author: securityclippy File: test_einsum.py License: GNU General Public License v3.0 | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (1, 4), (2, 4), (1, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
Example 25
Project: elasticintel Author: securityclippy File: test_einsum.py License: GNU General Public License v3.0 | 6 votes |
def test_path_type_input(self): # Test explicit path handeling path_test = self.build_operands('dcc,fce,ea,dbf->ab') path, path_str = np.einsum_path(*path_test, optimize=False) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*path_test, optimize=True) self.assert_path_equal(path, ['einsum_path', (0, 3), (0, 2), (0, 1)]) exp_path = ['einsum_path', (0, 2), (0, 2), (0, 1)] path, path_str = np.einsum_path(*path_test, optimize=exp_path) self.assert_path_equal(path, exp_path) # Double check einsum works on the input path noopt = np.einsum(*path_test, optimize=False) opt = np.einsum(*path_test, optimize=exp_path) assert_almost_equal(noopt, opt)
Example 26
Project: coffeegrindsize Author: jgagneastro File: test_einsum.py License: MIT License | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 27
Project: coffeegrindsize Author: jgagneastro File: test_einsum.py License: MIT License | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') print(path) self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') print(path) self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
Example 28
Project: coffeegrindsize Author: jgagneastro File: test_einsum.py License: MIT License | 6 votes |
def test_path_type_input(self): # Test explicit path handeling path_test = self.build_operands('dcc,fce,ea,dbf->ab') path, path_str = np.einsum_path(*path_test, optimize=False) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*path_test, optimize=True) self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 1), (0, 1)]) exp_path = ['einsum_path', (0, 2), (0, 2), (0, 1)] path, path_str = np.einsum_path(*path_test, optimize=exp_path) self.assert_path_equal(path, exp_path) # Double check einsum works on the input path noopt = np.einsum(*path_test, optimize=False) opt = np.einsum(*path_test, optimize=exp_path) assert_almost_equal(noopt, opt)
Example 29
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: test_einsum.py License: MIT License | 6 votes |
def test_memory_contraints(self): # Ensure memory constraints are satisfied outer_test = self.build_operands('a,b,c->abc') path, path_str = np.einsum_path(*outer_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) path, path_str = np.einsum_path(*outer_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2)]) long_test = self.build_operands('acdf,jbje,gihb,hfac') path, path_str = np.einsum_path(*long_test, optimize=('greedy', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)]) path, path_str = np.einsum_path(*long_test, optimize=('optimal', 0)) self.assert_path_equal(path, ['einsum_path', (0, 1, 2, 3)])
Example 30
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: test_einsum.py License: MIT License | 6 votes |
def test_long_paths(self): # Long complex cases # Long test 1 long_test1 = self.build_operands('acdf,jbje,gihb,hfac,gfac,gifabc,hfac') path, path_str = np.einsum_path(*long_test1, optimize='greedy') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test1, optimize='optimal') self.assert_path_equal(path, ['einsum_path', (3, 6), (3, 4), (2, 4), (2, 3), (0, 2), (0, 1)]) # Long test 2 long_test2 = self.build_operands('chd,bde,agbc,hiad,bdi,cgh,agdb') path, path_str = np.einsum_path(*long_test2, optimize='greedy') print(path) self.assert_path_equal(path, ['einsum_path', (3, 4), (0, 3), (3, 4), (1, 3), (1, 2), (0, 1)]) path, path_str = np.einsum_path(*long_test2, optimize='optimal') print(path) self.assert_path_equal(path, ['einsum_path', (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])