Version 20 of matrix

Updated 2009-07-08 08:36:26 by dkf

Documentation can be found at http://tcllib.sourceforge.net/doc/matrix.html .

This module of the tcllib data structures collection provides a matrix structure, i.e. a 2-dimensional table of cells, organized in rows and columns.

People in search of vector operations should look at either the BLT vector functionality or VKIT.


LV Is there any intended, or expected, relationship between tcllib's matrix and Tktable's graphical display of rows and columns?

AK A tcllib matrix can be linked to a tcl array (via traces) which then can be linked to a Tktable widget. In this way changes to the matrix are reflected in the widget and vice versa.

LV Does anyone have a demo showing such a relationship?

AK Yes, see Displaying Tables.


LV Also, I recently saw a demo where an application used XML and XSLT to convert data into HTML in a Java client. One of the slick things the particular demo application did was to allow the user to specify via XML and XSLT how they wished to represent the data. The demo showed how they could via XSLT specify that the data be represented via a Java spreadsheet component and, without any specific support in the client (just by manipulating the stylesheet) were able to slide this off the shelf client into the visualization. Having some way to take data and visualize it seems to be particularly useful.

Certainly tcllib's report module can be used for some degree of visualization - but perhaps other forms and crossovers would be useful.


LV Anyone have a proc that is the equivalent of a parray only for a matrix? Also, what about a function that does searching of a matrix for information?

Bezoar 26Mar2008 - you can link an array to a matrix then use parray. e.g

  array set zero {} 
  struct::matrix x
  x insert column 0 "Who"
  x insert column 1 "Where" 
  x insert row 0 { "Who" "Where" } 
  x add row { "the man was" "in the house" } 
  x add row {  "the man was" "in the barn" }
  x add row {"the womman was" "in the barn" } 
  x link zero
  parray zero

outputs :

 zero(0,0) = Who
 zero(0,1) = the man was
 zero(0,2) = the man was
 zero(0,3) = the womman was
 zero(1,0) = Where
 zero(1,1) = in the house
 zero(1,2) = in the barn
 zero(1,3) = in the barn

AK The matrix in the CVS head of tcllib has searching and when printing without a formatter we get somethng like parray.


One can always represent matrices as pure-value lists of lists. Manipulating these is rather easy by nested iteration over rows and columns. Here is for instance the extraction of a rectangular submatrix:

 proc submatrix {m fromrow torow fromcol tocol} {
        set res {}
        foreach row [lrange $m $fromrow $torow] {
           lappend res [lrange $row $fromcol $tocol]
        }
        set res
 }
 % set m {{1 2 3 4} {5 6 7 8} {9 10 11 12}}
 {1 2 3 4} {5 6 7 8} {9 10 11 12}
 % submatrix $m 1 end 1 end
 {6 7 8} {10 11 12}

See also NAP.


See also module struct - A matrix gadget for API studies


vkv Bug - There seems to be a bug in 2.0.1 version . When I delete rows, it is not reflected in linked array variable.