next up previous contents index
Next: Graphs and partial orders Up: Miscellaneous Previous: text_lines

matrix

A matrix is a two-dimensional indexable collection.

In matrix.cecil:


abstract object matrix[T]; 
extend type matrix[`T] subtypes matrix[`S >= T]; 
signature num_rows(matrix[`T]):int; 
signature num_cols(matrix[`T]):int; 
signature fetch(matrix[`T], row:int, col:int):T; 
method row(m@:matrix[`T], row:int):indexed[T]; 
method col(m@:matrix[`T], col:int):indexed[T]; 
method rows(m@:matrix[`T]):indexed[indexed[T]]; 
method indices_do(m@:matrix[`T], c:&(int,int):void):void; 
method do(m@:matrix[`T], c:&(int,int,T):void):void; 
method +(m1@:matrix[`T <= num], m2@:matrix[T]):matrix[T]; 
method *(m1@:matrix[`T <= num], m2@:matrix[T]):matrix[T|int]; 
method *_ugly(m1@:matrix[`T <= num], m2@:matrix[T]):matrix[T|int]; 
extend matrix[`T <= comparable[T]] isa comparable[matrix[T]]; 
method =(m1@:matrix[`T <= comparable[T]], m2@:matrix[`T]):bool; 
method print_string(m@:matrix[`T]):string; 
method copy_init(m@:matrix[`T], num_rows:int, num_cols:int, 
init:&(int,int):T):matrix[T];
signature copy_init[T](matrix[T], num_rows:int, num_cols:int, 
init:&(int,int):T):matrix[T];
method copy_mutable_init(m@:matrix[`T], num_rows:int, num_cols:int, 
init:&(int,int):T):m_matrix[T];
signature copy_mutable_init[T](matrix[T], num_rows:int, num_cols:int, 
init:&(int,int):T):m_matrix[T];
abstract object m_matrix[T] isa matrix[T]; 
signature store(matrix[`T], row:int, col:int, value:T):void; 
template representation vector_matrix[T] isa m_matrix[T]; 
field rows(@:vector_matrix[`T]):m_vector[m_vector[T]]; 
method num_rows(m@:vector_matrix[`T]):int; 
method num_cols(m@:vector_matrix[`T]):int; 
method fetch(m@:vector_matrix[`T], row:int, col:int):T; 
method store(m@:vector_matrix[`T], row:int, col:int, value:T):void; 
method row(m@:vector_matrix[`T], row:int):indexed[T]; 
method new_vector_matrix_init[T](num_rows:int, num_cols:int, 
init:&(int,int):T):m_matrix[T];
method copy_init[T](m@:vector_matrix[T], num_rows:int, num_cols:int, 
init:&(int,int):T):matrix[T];
method copy_mutable_init[T](m@:vector_matrix[T], num_rows:int, num_cols:int, 
init:&(int,int):T):m_matrix[T];
Matrices support querying the number of rows and columns of a matrix, extracting an element, a row, or a column of the matrix, and converting the matrix into a vector of row vectors. The do and indices_do methods support iterating over the matrix. Conformable matrices can be added and multiplied. A matrix of comparable values is itself comparable, pointwise. Mutable matrices support changing a given matrix element.

One concrete implementation of matrices exists, based on representing matrices by a vector of vectors. The new_vector_matrix_init functions supports creating a new vector_matrix of a given size with its elements initialized as specified by the init_fn closure.


next up previous contents index
Next: Graphs and partial orders Up: Miscellaneous Previous: text_lines

The Cecil project