Download presentation
Presentation is loading. Please wait.
1
Mx? A programming language for scientific computation. Related Languages: Matlab IDL Maple, Mathcad, Mathematica
2
Goals Portability - interpreted and executed by a java interpreter. Efficiency - greatly improves programming efficiency. Program involving many matrix and vector operations are very short in Mx. Ease of use - very simple and quick to start
3
What can the language do? Basic matrix operations – addition, multiplication… Advanced operations – matrix slicing and masking. Internal functions – Print, input, load, save, plot, paint
4
Operations and Relations Arithmetic Operations *, /, %, /’, ‘, +, - Logical Operations not and or Relational Operations >, >=,, >=, <, <=, ==, !=
5
Array and Range Range Specifier : i.e.. A[1:10, 1:2] :: i.e.. A[1::2] Array Constructor [1,2;3,4]
6
Statements Block Statement {} iteration for (n = 1:100); loop Assignments= Conditional Statements if (exp) ; if (exp) else if (exp) else Break and Continue break;continue;
7
Functions and Function call Self Defined Functions func (para-list) = exp; func (para- list){} Function Call id(para-list); Note: can either be stand-lone or right value depends on if it has returned value
8
Internal functions Console output print() print arguments to the standard output one by one. Picture drawing paint() draws a matrix in a new window as an image plot() takes a matrix and plots it as a graph Color color() sets the current color (in RGB) colormap() take a matrix with rows as RGB, and sets a colormap. File I/O functions load( file, type, m, n ) save( matrix, file, type ) Matrix generator zeros( m, n ) random( m, n ) matrix operator inv( matrix ) flip( matrix )
9
Example 1: Mr. Potato A = load( "potato.dat", "byte", 128,128 ); colormap(1); paint( [ A, flip(A), mirror(A), flip(mirror(A)); A', flip(A'), mirror(A'), flip(mirror(A'))] ); return 0;
10
Overview of the interpreter Currently the Mx programming language is implemented interpretively. Currently the Mx programming language is implemented interpretively. The interpreter parses and executes the user input or programs in files, and generates printed output and/or pictures. The interpreter parses and executes the user input or programs in files, and generates printed output and/or pictures. The parser of the interpreter is written in Antlr, and the rest routines are in Java. The parser of the interpreter is written in Antlr, and the rest routines are in Java. For a small portion of our code, we tried macro expansion in Java. For a small portion of our code, we tried macro expansion in Java. Adequate functionalities made our project quite large, luckily most of the functions are tested and work well (maybe we have forgotten the existences of some functions?) Adequate functionalities made our project quite large, luckily most of the functions are tested and work well (maybe we have forgotten the existences of some functions?)
11
Code Statistics PartsFront- end Interpret er Matrix class test code Statistics (lines) 48120902731941 Total5891 lines (generated code not included) (partial, currently in CVS)
12
Why another matrix class? The Mx programming language has important functionalities: in-place matrix slicing and masking Existing Java matrix classes do not support these
13
What can we do in Mx with slicing and masking? A = zeros(256,256); A[10:40,:] = 1; A[25::50,60::50] = random(50,50); A[A>=0.75 or A<=0.25] = 0.5; A[100:199,100:199] = random(100,100) + A[0::100,0::100]*A[0::100, 100::100] ;
14
An example of masking: paint selected entries A = load( "mri-anat.sdt", "short", 256, 256 ); B = load( "mri-func.fdt", "float", 256, 256 ); A = flip(A'); B = flip(B'); paint( A ); colormap(4); opaint( B, B>0.7, 0, 0, 0.7, 1.0 );
15
The features of our matrix class Arithmetic operations: + - * /... Arithmetic operations: + - * /... Sharing data between matrices Sharing data between matrices Matrix slicing and masking Matrix slicing and masking Inversion and solving linear equations Inversion and solving linear equations Comparing matrices Comparing matrices Painting and plotting Painting and plotting Transpose, flipping and mirroring Transpose, flipping and mirroring And more... And more...
16
The type system
17
Testing Plan 3 Stages:3 Stages: Unit TestingUnit Testing Creation of our own library using Matlab as guidance. Creation of our own library using Matlab as guidance. Library contains its own unit testing program. Library contains its own unit testing program. Regressive TestingRegressive Testing Creation of a script to automate regressive testing written in tcl Creation of a script to automate regressive testing written in tcl Takes a database of one or more *.mx programs Takes a database of one or more *.mx programs See example See example
18
Example of the Testing Database ;;; samples.tdb: a sample of testing ;;; database for the Mx ;; assign 1 2 3 4 { a = [1,2;3.4]; return a; } ;; transpose 1 3 2 4 { a = [1.2;3,4]’ ; return a;} ;; transpose transpose 1 2 3 4 { a = [1,2;3,4]’’ ; return a;} ;; triple transposes 1 2 4 { return [1;2;4]’’’ ; } ;; matrix add 1 2 3 4 { return [1,1;1,1] + [0,1;2,3]; }
19
Testing Plan Advanced TestingAdvanced Testing Necessity for larger testing programs Necessity for larger testing programs Integrated all the examples from the tutorial and used them as our advanced testing examples. Integrated all the examples from the tutorial and used them as our advanced testing examples.
20
Lessons Learned 1.Fully investigate the feasibility of the supporting tools Original Matrix classes lacked many functions Original Matrix classes lacked many functions Plotting, painting, masking, etc. Plotting, painting, masking, etc. 2.Get advice from experienced 3.When an easier method of implementing classes of function exists, use it
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.