tenlab when matrices are not enough
play

TENLAB: When Matrices Are Not Enough Mehmet Turkcan, Dallas R. - PowerPoint PPT Presentation

TENLAB: When Matrices Are Not Enough Mehmet Turkcan, Dallas R. Jones, Cem Subakan May 11, 2016 TENLAB in One Slide (Or So) The name gives away the focus of the language! TENLAB in One Slide (Or So) The name gives away the


  1. TENLAB: When Matrices Are Not Enough Mehmet Turkcan, Dallas R. Jones, Cem Subakan May 11, 2016

  2. ✯ TENLAB in One Slide (Or So) ◮ The name gives away the focus of the language!

  3. ✯ TENLAB in One Slide (Or So) ◮ The name gives away the focus of the language! ◮ The example: let A ∈ R I 1 × I 2 × I 3 , B ∈ R J 1 × J 2 , in � C i 1 = A i 1 , k 1 , k 2 B k 1 , k 2 k 1 , k 2

  4. ✯ TENLAB in One Slide (Or So) ◮ The name gives away the focus of the language! ◮ The example: let A ∈ R I 1 × I 2 × I 3 , B ∈ R J 1 × J 2 , in � C i 1 = A i 1 , k 1 , k 2 B k 1 , k 2 k 1 , k 2 ◮ In MATLAB this does not work really well: C = sum(sum( bsxfun ( @times ,A, s h i f t d i m (B, − 1) ) ,3) ,2) ; and requires some thinking. Worse if the problem is not trivial.

  5. TENLAB in One Slide (Or So) ◮ The name gives away the focus of the language! ◮ The example: let A ∈ R I 1 × I 2 × I 3 , B ∈ R J 1 × J 2 , in � C i 1 = A i 1 , k 1 , k 2 B k 1 , k 2 k 1 , k 2 ◮ In MATLAB this does not work really well: C = sum(sum( bsxfun ( @times ,A, s h i f t d i m (B, − 1) ) ,3) ,2) ; and requires some thinking. Worse if the problem is not trivial. ◮ What if we could just write: C = { 1 ,1 } A { 2 ,3 } . ✯ B { 1 ,2 } ; Now that’s some cool imperative laziness!

  6. MATLAB’s Solution

  7. Summary of TENLAB ◮ Imperative multi-dimensional array manipulation language. ◮ Built to address the needs people in Machine Learning or similar disciplines who want to work with multi-dimensional arrays. ◮ Compiles into C (Fast!). ◮ Effortlessly interfaces with MATLAB. ◮ Includes a very powerful Tensor Product implementation.

  8. Generalized Tensor-Tensor Product � C i 1 = A i 1 , k 1 , k 2 B k 1 , k 2 k 1 , k 2 C = { 1,1 } A { 2,3 } . ∗ B { 1,2 } ; Output tensor Matched dimensions Collapse or not collapse of B Matched dimensions of A

  9. TENLAB: Even More Generalized Tensor-Tensor Product TENLAB is even more flexible: � C i 1 = A i 1 , k 1 , k 2 B k 1 , k 2 k 1 , k 2 C = { 1,1 } { 5,3,7 } A { 2,3 } . ∗ { 3,7 } B { 1,2 } ; Output tensor Matched dimensions Collapse or not collapse of B Shape to use for B Shape to use for A Matched dimensions of A

  10. Current List of Features & Ideology ◮ Generalized Tensor Product ◮ Be Like Water (When It Comes to Tensors) ◮ Memory Safety ◮ Functions and Scripts ◮ Full MATLAB Integration (With Multiple Outputs!)

  11. Compiler Architecture Compiler Setting (MEX/C) Scanner Parser .ten Source File AST Compiled Compiled IF Setting = C IF Setting = MEX Code Program Program Generation (.c) (.c) TENLAB TENLAB C GCC MEX MATLAB Library Library Binary .mex File

  12. Language Design Function definitions followed by scripts: % Beginning of Function Declarations 1 function gcd (Z, X, Y); 2 Z = X != Y; 3 while (Z); 4 if (X > Y); 5 X = X - Y; 6 else; 7 Y = Y - X; 8 end; 9 Z = X != Y; 10 end; 11 return X; 12 end; 13 % Beginning of the Script 14 tensor A; 15 tensor B; 16 tensor C; 17 A = 12; 18 B = 14; 19 A = gcd(C,A,B); 20 print(A); 21

  13. Tensor Products For simplicity, let’s consider a matrix product: % Beginning of the Script 1 tensor X; 2 tensor Y; 3 tensor Z; 4 X = [[3 ,4] ,[4 ,5] ,[6 ,7]]; 5 Y = [[1 ,2 ,3] ,[4 ,5 ,6]]; 6 Z = [[0 ,0 ,0] ,[0 ,0 ,0] ,[0 ,0 ,0]]; 7 Z = {1} {3 ,2} X {2} .* {2 ,3} Y {1}; 8 print(Z); 9

  14. MATLAB Integration MATLAB integration works as follows: % Beginning of the Script 1 tensor A; 2 tensor B; 3 tensor C; 4 input(A ,1); 5 input(B ,2); 6 input(C ,3); 7 C = {1} {11 ,8 ,2} A {3} .* {22 ,44 ,2} B {3}; 8 print(C); 9 output(C ,1); 10

  15. Built-in Functions Design Constraint: Avoid the Standard Library Syndrome, but remain versatile. ◮ print and shape : Display Results ◮ input and output : Get Data from MATLAB ◮ set , length , pop and dequeue : Change the Content ◮ reshape : Alter the Shape using Content ◮ clear and clean : Clear and Clean the Tensors

  16. Testing ◮ A total of 61 test cases included. ◮ 35 for TENLAB, 18 for C libraries, 4 for low-level MEX integration and 4 demos. ◮ Fundamental to the success of the team, automated test suites were the first to be built.

  17. Lessons Learned ◮ OCaml is not the enemy. ◮ Each member of the team should know everything about the codebase. ◮ Testing and test automation is key. Without automation, we would have had nothing. ◮ Gained a lot of ideas for future languages and implementation improvements. ◮ Don’t lose hope or panic near the end, keep on going!

  18. Demo Let’s have some bsxfun!

  19. The End: Q&A Thanks a lot for listening! Any questions?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend