SquareMatrix.st
changeset 5123 0a006004102a
parent 5084 5f942ac93795
--- a/SquareMatrix.st	Wed Aug 21 11:47:41 2019 +0200
+++ b/SquareMatrix.st	Wed Aug 21 11:47:50 2019 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "{ Package: 'stx:libbasic2' }"
 
 "{ NameSpace: Smalltalk }"
@@ -10,6 +12,23 @@
 !
 
 
+!SquareMatrix class methodsFor:'instance creation'!
+
+withAll:elements
+    |numElements nRows|
+
+    numElements := elements size.
+    nRows := numElements integerSqrt.
+    self assert:(nRows * nRows == numElements) description:'number of elements is not square'.
+    ^ (self new:numElements) 
+        replaceFrom:1 with:elements;
+        setDimensions:{nRows . nRows }
+
+    "
+     Matrix3_3  withAll:#(11 12 13 21 22 23 31 32 33) 
+    "
+! !
+
 !SquareMatrix methodsFor:'matrix operations'!
 
 determinant