eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Matrix':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Matrix


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--AbstractMultidimensionalArray
            |
            +--AbstractMatrix
               |
               +--Matrix
                  |
                  +--SquareMatrix

Package:
stx:libbasic2
Category:
Collections-MultiDimensional
Version:
rev: 1.14 date: 2023/06/04 13:03:21
user: cg
file: Matrix.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


Generic Matrix with arbitrary number of dimensions.
Especially useful with the ArrayIndexing-Parser extension.


[instance variables:]

[class variables:]

copyright

COPYRIGHT (c) 2018 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

instance creation
o  _at: nIndices
Generate a 1 dimensional matrix (actually, a vector).
This is a synthetic selector, generated by the compiler,
if a construct of the form expr[idx...] is parsed.
I.e.
Matrix[n]
generates
Matrix _at: n
which instantiates a vector with n cols.

o  _at: dim1 at: dim2
Generate a 2 dimensional matrix.
This is a synthetic selector, generated by the compiler,
if a construct of the form expr[idx...] is parsed.
I.e.
Matrix[n][m]
generates
Matrix _at:n at:m
which instantiates a matrix with n rows and m cols.

o  _at: dim1 at: dim2 at: dim3
Generate a 3 dimensional matrix.
This is a synthetic selector, generated by the compiler,
if a construct of the form expr[idx...] is parsed.
I.e.
Matrix[n][m][o]
generates
Matrix _at:n at:m at:o

o  _at: dim1 at: dim2 at: dim3 at: dim4
Generate a 4 dimensional matrix.
This is a synthetic selector, generated by the compiler,
if a construct of the form expr[idx...] is parsed.
I.e.
Matrix[n][m][o][p]
generates
Matrix _at:n at:m at:o at:p

o  identity: sizeArg
Answer an identity matrix of order 'anInteger @ anInteger'.

Usage example(s):

     self identity:2 
     self identity:3  
     self identity:5 

o  js_new: dim1 new: dim2
( an extension from the stx:libjavascript package )
this is a synthetic selector, generated by the JS compiler,
if a construct of the form new Matrix(dim1, dim2) is parsed.
I.e.
new Matrix(n,m)
generates
Matrix js_new:n new:m

o  newForRows: nRows cols: nCols
Answer a new empty matrix of 'nRows @ nCols'.

o  ones: aPoint
Answer a matrix of order 'aPoint' filled with ones.
The point's y coordinate defines the number of rows

Usage example(s):

     self ones:(3 @ 3)
     self ones:(3 @ 2)
     self ones:(5 @ 5)

o  rows: collectionOfRows
given the contents as a vector of rows.
Does not verify, but assumes that each row has the same number of columns.

Usage example(s):

     |m|
     m := Matrix rows:#( (1 2 3)
                         (4 5 6)
                         (7 8 9) ).
     self assert:(m = (Matrix[3][3] contents:#(1 2 3  4 5 6  7 8 9)))

o  zero: aPoint
Answer a matrix of order 'aPoint' filled with zeros.
The point's y coordinate defines the number of rows

Usage example(s):

     self zero:(3 @ 3)
     self zero:(3 @ 2)
     self zero:(5 @ 5)


Instance protocol:

accessing
o  size
the overall number of elements

comparing
o  = aMatrix
Answer true, if the argument represents the same matrix

o  hash
Matrix[5][5] = Matrix[5][5]
Matrix[5][5] hash = Matrix[5][5] hash

|m1 m2|
m1 := Matrix[5][5]. m1[1][2] := 99.
m2 := Matrix[5][5]. m2[1][2] := 88.
m1 = m2.
m1 hash = m2 hash.

|m1 m2|
m1 := Matrix[5][5]. m1[1][2] := 99.
m2 := Matrix[5][5]. m2[1][2] := 88.
m1 = m2.
m1 hash = m2 hash.

Usage example(s):

     Matrix[5][5] = Matrix[5][5]  
     Matrix[5][5] hash = Matrix[5][5] hash 

     |m1 m2|
     m1 := Matrix[5][5]. m1[1][2] := 99.
     m2 := Matrix[5][5]. m2[1][2] := 88. 
     m1 = m2.   
     m1 hash = m2 hash.

     |m1 m2|
     m1 := Matrix[5][5]. m1[1][2] := 99.
     m2 := Matrix[5][5]. m2[1][2] := 88. 
     m1 = m2.   
     m1 hash = m2 hash.

species instance creation
o  speciesNew: size
create a new instance of my species.
MUST be redefined especially for MatrixAccessor


Examples:


You have to enable the Parser's arrayIndexingExtension support in order to be able to execute the examples below. Parser allowArrayIndexSyntaxExtension:true
  |m3|
  m3 := (Matrix[3][2][2]) contents:#(
          1 2
          3 4

          10 20
          30 40

          100 200
          300 400
      ).
  Transcript showCR:(m3 displayString).
  Transcript showCR: e'm3[1][1][1] : {m3[1][1][1]}'.
  Transcript showCR: e'm3[2][1][1] : {m3[2][1][1]}'.
  Transcript showCR: e'm3[3][1][1] : {m3[3][1][1]}'.

  Transcript showCR: e'm3[1][2][1] : {m3[1][2][1]}'.
  Transcript showCR: e'm3[2][2][1] : {m3[2][2][1]}'.
  Transcript showCR: e'm3[3][2][1] : {m3[3][2][1]}'.

  Transcript showCR: e'm3[1][1][2] : {m3[1][1][2]}'.
  Transcript showCR: e'm3[2][1][2] : {m3[2][1][2]}'.
  Transcript showCR: e'm3[3][1][2] : {m3[3][1][2]}'.
  |m|

  m := (Matrix[3][3]) contents:#(
                          1 2 3
                          4 5 6
                          7 8 9).
  m       
  |m|

  m := (Matrix3_3 new) contents:#(
                          1 2 3
                          4 5 6
                          7 8 9).
  m       
  |m|

  m := Matrix3_3 new.
  m[2][1] := 11.
  m[2][2] := 12.
  m[2][3] := 13.
  m       
  |m|

  m := Matrix3_3 identity.
  m       
  |m1 m2|

  m1 := Matrix3_3 new.
  m1 atAllPut:1.

  m2 := Matrix3_3 new.
  m2 atAllPut:2.

  m1 - m2    
  |m1 m2|

  m1 := Matrix3_3 new.
  m1 atAllPut:1.

  m2 := Matrix3_3 new.
  m2 atAllPut:2.

  m1 + m2    


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 22 Dec 2024 01:06:26 GMT