#NEWLINE# def test_m_tensor_loops_multiple_contractions( ) : #NEWLINE# #INDENT# from sympy.tensor import IndexedBase , Idx #NEWLINE# from sympy import symbols #NEWLINE# ( n , m , o , p ) = symbols ( 'n m o p' , integer = True ) #NEWLINE# A = IndexedBase ( 'A' ) #NEWLINE# B = IndexedBase ( 'B' ) #NEWLINE# y = IndexedBase ( 'y' ) #NEWLINE# i = Idx ( 'i' , m ) #NEWLINE# j = Idx ( 'j' , n ) #NEWLINE# k = Idx ( 'k' , o ) #NEWLINE# l = Idx ( 'l' , p ) #NEWLINE# ( result , ) = codegen ( ( 'tensorthing' , Eq ( y [ i ] , ( B [ ( j , k , l ) ] * A [ ( i , j , k , j ) ] ) ) ) , 'Octave' , header = False , empty = False ) #NEWLINE# source = result [ 1 ] #NEWLINE# expected = 'function y = tensorthing(A, B, m, n, o, p)\n  for i = 1:m\n    y(i) = 0;\n  end\n  for i = 1:m\n    for j = 1:n\n      for k = 1:o\n        for l = 1:p\n          y(i) = y(i) + B(j, k, l).*A(i, j, k, l);\n        end\n      end\n    end\n  end\nend\n' #NEWLINE# assert ( source == expected )