UNPKG

minigrace

Version:

A compiler for the Grace programming language

750 lines 281 kB
let gracecode_matrix_sourceFile = "/Users/black/Development/mg/gracelang/minigrace/modules/matrix.grace"; let gracecode_matrix_sha256 = "ecf2ecfbcdaddaf9747260021f4530985da34972d4d376b211561fb1cb19bfee"; let gracecode_matrix_minigraceRevision = "b57591d29fc5ee5270d114920bf671367b8c3ecb"; let gracecode_matrix_minigraceGeneration = "5171"; if (typeof gctCache !== "undefined") gctCache["matrix"] = "dialect:\n standard\nfreshScopes:\n $103\n $104 trait\n $105\n $106\n $107\n $108\n $109\n $110\n $111\n $112\n $113\n $114\nmethodTypes:$102:\n dot(v1:Collection, v2:Collection) \u2192 Unknown\n lazyZipperSequence\u27e6T\u27e7(source1:Collection\u27e6Collection\u27e6T\u27e7\u27e7, source2:Collection\u27e6T\u27e7) \u2192 Unknown\n mapColumnsToRows(columns:Collection\u27e6Collection\u27e7) \u2192 Unknown\n matrix\u27e6T\u27e7(rs:Unknown, cs:Unknown) \u2192 MatrixFactory\u27e6T\u27e7\n with\u27e6T\u27e7(x:T) \u2192 Matrix\u27e6T\u27e7\nmethodTypes:$104:\n columns(c:Collection\u27e6Collection\u27e6T\u27e7\u27e7) \u2192 Matrix\u27e6T\u27e7\n rows(r:Collection\u27e6Collection\u27e6T\u27e7\u27e7) \u2192 Matrix\u27e6T\u27e7\n value(v:T) \u2192 Matrix\u27e6T\u27e7\n values(vs:Collection\u27e6T\u27e7) \u2192 Matrix\u27e6T\u27e7\n withAll(a:Collection\u27e6T\u27e7) \u2192 Matrix\u27e6T\u27e7\n zeros \u2192 Matrix\u27e6Number\u27e7\nmethodTypes:$106:\n +(other:Matrix\u27e6T\u27e7) \u2192 Unknown\n -(other:Matrix\u27e6T\u27e7) \u2192 Unknown\n atRow(r:Unknown)column(c:Unknown)put(v:T) \u2192 Unknown\n columns \u2192 Enumerable\u27e6Enumerable\u27e6T\u27e7\u27e7\n rows \u2192 Enumerable\u27e6Enumerable\u27e6T\u27e7\u27e7\n values \u2192 Enumerable\u27e6T\u27e7\nmodules:\n collections\n standard\npath:\n /Users/black/Development/mg/gracelang/minigrace/modules/matrix.grace\nscope:$102:\n ComparableToMatrix type\n ImplementsTimesOperator type\n Matrix type\n MatrixDimensionsError Unknown (def) $scope_done public\n MatrixFactory type\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n basicAsString String (go) $scope_string\n dot(2) Unknown (mth) $scope_done\n empty Unknown (mth) $scope_done public\n isMe(1) Boolean (go) $scope_boolean\n lazyZipperSequence(2) Unknown (mth) $103\n listOfSize(1)withValue(1) Unknown (mth) $scope_done confidential\n mapColumnsToRows(1) Unknown (mth) $scope_done\n matrix(2) MatrixFactory (mth) $104\n myIdentityHash Number (go) $scope_number\n with(1) Matrix (mth) $scope_done public\nscope:$103:\n ++(1) Enumerable (mth) $scope_done\n <<(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n >>(1) Unknown (mth) $scope_done\n allSatisfy(1) Unknown (mth) $scope_done\n anySatisfy(1) Unknown (mth) $scope_done\n asDebugString Unknown (mth) $scope_done\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n contains(1) Unknown (mth) $scope_done\n do(1) Done (mth) $scope_done\n do(1)separatedBy(1) Unknown (mth) $scope_done\n filter(1) Enumerable (mth) $scope_done\n first Unknown (mth) $scope_done\n fold(1)startingWith(1) R (mth) $scope_done\n isEmpty Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n iterator Unknown (mth) $105\n keysAndValuesDo(1) Done (mth) $scope_done\n map(1) Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n size Unknown (mth) $scope_done\n sizeIfUnknown(1) Unknown (mth) $scope_done\n sorted List (mth) $scope_done\n sortedBy(1) List (mth) $scope_done\n values Collection (mth) $scope_done\n while(1)do(1) Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\nscope:$104:\n <<(1) Unknown (mth) $scope_done\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n columns(1) Matrix (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n rows(1) Matrix (mth) $scope_done\n value(1) Matrix (mth) $scope_done\n values(1) Matrix (mth) $106\n withAll(1) Matrix (mth) $scope_done\n zeros Matrix (mth) $scope_done\nscope:$105:\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n hasNext Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n iterator1 Unknown (def) $scopeEmpty\n iterator2 Unknown (def) $scopeEmpty\n myIdentityHash Number (go) $scope_number\n next Unknown (mth) $scope_done\nscope:$106:\n *(1) Unknown (mth) $scope_done\n +(1) Unknown (mth) $scope_done\n ++(1) Unknown (mth) $scope_done\n -(1) Unknown (mth) $scope_done\n /(1) Unknown (mth) $scope_done\n <<(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n >>(1) Unknown (mth) $scope_done\n addColumn(1)at(1) Unknown (mth) $scope_done\n addRow(1)at(1) Unknown (mth) $scope_done\n allSatisfy(1) Unknown (mth) $scope_done\n anySatisfy(1) Unknown (mth) $scope_done\n applyMatrixOperation(1)with(1) Unknown (mth) $scope_done confidential\n applyScalarOperation(1)with(1) Unknown (mth) $scope_done confidential\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n atRow(1)column(1) Unknown (mth) $scope_done\n atRow(1)column(1)ifAbsent(1) Unknown (mth) $scope_done\n atRow(1)column(1)put(1) Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n column(1) Unknown (mth) $110\n columns Enumerable (mth) $108\n contains(1) Unknown (mth) $scope_done\n copy Unknown (mth) $scope_done\n deleteColumn(1) Unknown (mth) $scope_done\n deleteRow(1) Unknown (mth) $scope_done\n do(1) Unknown (mth) $scope_done\n do(1)separatedBy(1) Unknown (mth) $scope_done\n filter(1) Enumerable (mth) $scope_done\n first Unknown (mth) $scope_done\n fold(1)startingWith(1) Unknown (mth) $scope_done\n impl Unknown (var) $scopeEmpty\n impl:=(1) Unknown (var) $scopeEmpty\n indexFromRow(1)column(1) Unknown (mth) $scope_done confidential\n indexFromRow(1)column(1)ifOutOfBounds(1) Unknown (mth) $scope_done confidential\n isColumnValid(1) Unknown (mth) $scope_done confidential\n isEmpty Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n isRowValid(1) Unknown (mth) $scope_done confidential\n iterator Unknown (mth) $scope_done\n map(1) Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n numColumns Unknown (var) $scopeEmpty public\n numColumns:=(1) Unknown (var) $scopeEmpty public\n numRows Unknown (var) $scopeEmpty public\n numRows:=(1) Unknown (var) $scopeEmpty public\n replaceColumnAt(1)with(1) Unknown (mth) $scope_done\n replaceRowAt(1)with(1) Unknown (mth) $scope_done\n reshapeWithNumRows(1)numColumns(1) Unknown (mth) $scope_done\n reshapeWithNumRows(1)numColumns(1)additionalValues(1) Unknown (mth) $scope_done\n reverseDivideNumber(1) Unknown (mth) $scope_done\n reverseMinusNumber(1) Unknown (mth) $scope_done\n reversePlusNumber(1) Unknown (mth) $scope_done\n reverseTimesNumber(1) Unknown (mth) $scope_done\n row(1) Unknown (mth) $109\n rows Enumerable (mth) $107\n size Unknown (mth) $scope_done\n sizeIfUnknown(1) Unknown (mth) $scope_done\n times(1) Unknown (mth) $scope_done\n transpose Unknown (mth) $scope_done\n values Enumerable (mth) $scope_done\n while(1)do(1) Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\nscope:$107:\n ++(1) Enumerable (mth) $scope_done\n <<(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n >>(1) Unknown (mth) $scope_done\n allSatisfy(1) Unknown (mth) $scope_done\n anySatisfy(1) Unknown (mth) $scope_done\n asDebugString Unknown (mth) $scope_done\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n contains(1) Unknown (mth) $scope_done\n do(1) Done (mth) $scope_done\n do(1)separatedBy(1) Unknown (mth) $scope_done\n filter(1) Enumerable (mth) $scope_done\n first Unknown (mth) $scope_done\n fold(1)startingWith(1) R (mth) $scope_done\n isEmpty Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n iterator Unknown (mth) $111\n keysAndValuesDo(1) Done (mth) $scope_done\n map(1) Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n size Unknown (def) $scopeEmpty public\n sizeIfUnknown(1) Unknown (mth) $scope_done\n sorted List (mth) $scope_done\n sortedBy(1) List (mth) $scope_done\n values Collection (mth) $scope_done\n while(1)do(1) Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\nscope:$108:\n ++(1) Enumerable (mth) $scope_done\n <<(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n >>(1) Unknown (mth) $scope_done\n allSatisfy(1) Unknown (mth) $scope_done\n anySatisfy(1) Unknown (mth) $scope_done\n asDebugString Unknown (mth) $scope_done\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n contains(1) Unknown (mth) $scope_done\n do(1) Done (mth) $scope_done\n do(1)separatedBy(1) Unknown (mth) $scope_done\n filter(1) Enumerable (mth) $scope_done\n first Unknown (mth) $scope_done\n fold(1)startingWith(1) R (mth) $scope_done\n isEmpty Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n iterator Unknown (mth) $112\n keysAndValuesDo(1) Done (mth) $scope_done\n map(1) Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n size Unknown (def) $scopeEmpty public\n sizeIfUnknown(1) Unknown (mth) $scope_done\n sorted List (mth) $scope_done\n sortedBy(1) List (mth) $scope_done\n values Collection (mth) $scope_done\n while(1)do(1) Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\nscope:$109:\n ++(1) Enumerable (mth) $scope_done\n <<(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n >>(1) Unknown (mth) $scope_done\n allSatisfy(1) Unknown (mth) $scope_done\n anySatisfy(1) Unknown (mth) $scope_done\n asDebugString Unknown (mth) $scope_done\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n contains(1) Unknown (mth) $scope_done\n do(1) Done (mth) $scope_done\n do(1)separatedBy(1) Unknown (mth) $scope_done\n filter(1) Enumerable (mth) $scope_done\n first Unknown (mth) $scope_done\n fold(1)startingWith(1) R (mth) $scope_done\n isEmpty Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n iterator Unknown (mth) $113\n keysAndValuesDo(1) Done (mth) $scope_done\n map(1) Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n size Unknown (def) $scopeEmpty public\n sizeIfUnknown(1) Unknown (mth) $scope_done\n sorted List (mth) $scope_done\n sortedBy(1) List (mth) $scope_done\n values Collection (mth) $scope_done\n while(1)do(1) Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\nscope:$110:\n ++(1) Enumerable (mth) $scope_done\n <<(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n >>(1) Unknown (mth) $scope_done\n allSatisfy(1) Unknown (mth) $scope_done\n anySatisfy(1) Unknown (mth) $scope_done\n asDebugString Unknown (mth) $scope_done\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n contains(1) Unknown (mth) $scope_done\n do(1) Done (mth) $scope_done\n do(1)separatedBy(1) Unknown (mth) $scope_done\n filter(1) Enumerable (mth) $scope_done\n first Unknown (mth) $scope_done\n fold(1)startingWith(1) R (mth) $scope_done\n isEmpty Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n iterator Unknown (mth) $114\n keysAndValuesDo(1) Done (mth) $scope_done\n map(1) Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n size Unknown (def) $scopeEmpty public\n sizeIfUnknown(1) Unknown (mth) $scope_done\n sorted List (mth) $scope_done\n sortedBy(1) List (mth) $scope_done\n values Collection (mth) $scope_done\n while(1)do(1) Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\nscope:$111:\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n currentRow Unknown (var) $scopeEmpty\n currentRow:=(1) Unknown (var) $scopeEmpty\n hasNext Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n next Unknown (mth) $scope_done\nscope:$112:\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n currentColumn Unknown (var) $scopeEmpty\n currentColumn:=(1) Unknown (var) $scopeEmpty\n hasNext Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n next Unknown (mth) $scope_done\nscope:$113:\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n currentColumn Unknown (var) $scopeEmpty\n currentColumn:=(1) Unknown (var) $scopeEmpty\n hasNext Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n next Unknown (mth) $scope_done\nscope:$114:\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n currentRow Unknown (var) $scopeEmpty\n currentRow:=(1) Unknown (var) $scopeEmpty\n hasNext Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n next Unknown (mth) $scope_done\nself:\n $102\ntypedec:$102.ComparableToMatrix:\n type ComparableToMatrix\u27e6T\u27e7 = interface {\n numRows \u2192 Number\n numColumns \u2192 Number\n atRow(r:Number)column(c:Number)ifAbsent(_) \u2192 T}\ntypedec:$102.ImplementsTimesOperator:\n type ImplementsTimesOperator\u27e6K\u27e7 = interface {\n *(other) \u2192 K}\ntypedec:$102.Matrix:\n type Matrix\u27e6T\u27e7 = Collection\u27e6T\u27e7 & interface {\n size \u2192 Number\n numRows \u2192 Number\n numColumns \u2192 Number\n atRow(r:Number)column(c:Number)put(v:T) \u2192 Matrix\n atRow(r:Number)column(c:Number) \u2192 T\n atRow(r:Number)column(c:Number)ifAbsent(action:Procedure0) \u2192 T\n row(r:Number) \u2192 Collection\u27e6T\u27e7\n column(c:Number) \u2192 Collection\u27e6T\u27e7\n rows \u2192 Enumerable\u27e6Enumerable\u27e6T\u27e7\u27e7\n columns \u2192 Enumerable\u27e6Enumerable\u27e6T\u27e7\u27e7\n values \u2192 Enumerable\u27e6T\u27e7\n +(other:Matrix\u27e6T\u27e7) \u2192 Matrix\u27e6T\u27e7\n -(other:Matrix\u27e6T\u27e7) \u2192 Matrix\u27e6T\u27e7\n *(other) \u2192 Matrix\u27e6T\u27e7\n /(other) \u2192 Matrix\u27e6T\u27e7\n transpose \u2192 Matrix\u27e6T\u27e7\n times(other:Matrix\u27e6T\u27e7) \u2192 Matrix\u27e6T\u27e7\n reshapeWithNumRows(rs:Number)numColumns(cs:Number) \u2192 Matrix\u27e6T\u27e7\n reshapeWithNumRows(rs:Number)numColumns(cs:Number)additionalValues(vs:Collection\u27e6T\u27e7) \u2192 Matrix\u27e6T\u27e7\n addRow(row:Collection\u27e6T\u27e7)at(index:Number) \u2192 Matrix\u27e6T\u27e7\n deleteRow(r:Number) \u2192 Matrix\u27e6T\u27e7\n addColumn(column:Collection\u27e6T\u27e7)at(index:Number) \u2192 Matrix\u27e6T\u27e7\n deleteColumn(c:Number) \u2192 Matrix\u27e6T\u27e7\n replaceRowAt(r:Number)with(row:Collection\u27e6T\u27e7) \u2192 Matrix\u27e6T\u27e7\n replaceColumnAt(c:Number)with(column:Collection\u27e6T\u27e7) \u2192 Matrix\u27e6T\u27e7\n copy \u2192 Matrix\u27e6T\u27e7}\ntypedec:$102.MatrixFactory:\n type MatrixFactory\u27e6T\u27e7 = interface {\n zeros \u2192 Matrix\u27e6Number\u27e7\n rows(rows:Collection\u27e6Collection\u27e6T\u27e7\u27e7) \u2192 Matrix\u27e6T\u27e7\n columns(columns:Collection\u27e6Collection\u27e6T\u27e7\u27e7) \u2192 Matrix\u27e6T\u27e7\n value(v:T) \u2192 Matrix\u27e6T\u27e7\n values(vs:Collection\u27e6T\u27e7) \u2192 Matrix\u27e6T\u27e7}\ntypes:\n $102.ComparableToMatrix\n $102.ImplementsTimesOperator\n $102.Matrix\n $102.MatrixFactory\n"; if (typeof originalSourceLines !== "undefined") { originalSourceLines["matrix"] = [ "dialect \"standard\"", "// This module defines a 2-dimensional matrix datatype", "", "import \"collections\" as coll", "", "type Matrix⟦T⟧ = Collection⟦T⟧ & interface {", " size -> Number", " // returns the number of values in self", "", " numRows → Number", " // returns the number of rows in self", "", " numColumns → Number", " // returns the number of columns in self", "", " atRow(r:Number) column(c:Number) put (v:T) → Matrix", " // adds the value 'v' at row r, column c", " // raises BoundsError if index at r,c does not exist", "", " atRow(r:Number) column(c:Number) → T", " // returns the value at row r, column c", " // raises BoundsError if index at r,c does not exist", "", " atRow(r:Number) column(c:Number) ifAbsent(action:Procedure0) → T", " // returns the value at row r, column c", " // executes 'action' if index at r,c does not exist", "", " row(r:Number) → Collection⟦T⟧", " // returns row r as a collection", " // raises BoundsError if row index r does not exist", "", " column(c:Number) → Collection⟦T⟧", " // returns column c as a collection", " // raises BoundsError if column index c does not exist", "", " rows → Enumerable⟦Enumerable⟦T⟧⟧", " // returns an enumerable collection over the rows of the matrix", "", " columns → Enumerable⟦Enumerable⟦T⟧⟧", " // returns an enumerable collection over the columns of the matrix", "", " values → Enumerable⟦T⟧", " // returns an enumerable collection over the values of the matrix", "", " +(other:Matrix⟦T⟧) → Matrix⟦T⟧", " // returns the value-wise sum of self and other;", " // raises MatrixDimensionsError if the dimensions of other don't match those of 'self'", "", " -(other:Matrix⟦T⟧) → Matrix⟦T⟧", " // returns the value-wise difference of two matrices", " // raises MatrixDimensionsError if the dimensions of other don't match those of 'self'", "", " *(other) → Matrix⟦T⟧", " // returns the value-wise product of self and other if the argument other is a matrix;", " // returns the product of other mapped over all the elements of self if other is a scalar.", " // Raises MatrixDimensionsError if the dimensions of other don't match the dimesions of self", "", " /(other) → Matrix⟦T⟧", " // returns the value-wise quotient of self and other if the argument other is a matrix;", " // returns the quotient of other mapped over all the elements of self if other is a scalar.", " // Raises MatrixDimensionsError if the dimensions of other don't match the dimesions of 'self'", "", " transpose → Matrix⟦T⟧", " // returns the transpose of self", "", " times(other:Matrix⟦T⟧) → Matrix⟦T⟧", " // returns the matrix product of self and other", " // raises MatrixDimensionsError if the dimensions of other are not compatible with the dimensions of self", "", " reshapeWithNumRows(rs:Number) numColumns(cs:Number) → Matrix⟦T⟧", " // redefines the number of rows and columns in self, if compatible with the number of values", " // raises MatrixDimensionsError if the product of the new dimensions is not", " // the same as the product of the current dimensions.", "", " reshapeWithNumRows(rs:Number) numColumns(cs:Number)", " additionalValues(vs:Collection⟦T⟧) → Matrix⟦T⟧", " // redefines the number of rows and columns in self,", " // raises MatrixDimensionsError if the product of the new dimensions", " // is not equal to the product of the current dimensions plus the size of the additional values", "", " addRow(row:Collection⟦T⟧) at(index:Number) → Matrix⟦T⟧", " // adds a row to the matrix at the specified index", " // raises MatrixDimensionsError if the length of the row is not equal to the number of columns in self", "", " deleteRow(r:Number) → Matrix⟦T⟧", " // removes the row at the specified index from the matrix", " // raises BoundsError if the index r is not within the number of rows in self", "", " addColumn(column:Collection⟦T⟧) at(index:Number) → Matrix⟦T⟧", " // adds a column to the matrix at the specified index", " // raises MatrixDimensionsError if the length of the column is not equal to the number of rows in self", "", " deleteColumn(c:Number) → Matrix⟦T⟧", " // removes the column at the specified index from self", " // raises BoundsError if the index c is not within the number of columns of self", "", " replaceRowAt(r:Number) with(row:Collection⟦T⟧) → Matrix⟦T⟧", " // replaces the row at index r with row.", " // Raises MatrixDimensionsError if the row.size is not equal to the number of columns in self;", " // raises BoundsError if the index r is not within the number of rows of self", "", " replaceColumnAt(c:Number) with(column:Collection⟦T⟧) → Matrix⟦T⟧", " // replaces the column at index c with the given collection.", " // Raises MatrixDimensionsError if column.size is not equal to the number of rows in self;", " // raises BoundsError if the index c is not within the number of columns of self", "", " copy → Matrix⟦T⟧", " // returns a new matrix with the same values and dimensions as self", "}", "", "type MatrixFactory⟦T⟧ = interface {", " zeros → Matrix⟦Number⟧", " // a matrix with the specified dimensions where all values are equal to 0", " ", " rows(rows: Collection⟦Collection⟦T⟧⟧) → Matrix⟦T⟧", " // a matrix with the specified collection as rows", " // throws an error if the rows are not all the same length", " ", " columns(columns: Collection⟦Collection⟦T⟧⟧) → Matrix⟦T⟧", " // a matrix with the specified collection as columns", " // throws an error if the columns are not all the same length", " ", " value(v:T) → Matrix⟦T⟧", " // a matrix with the specified dimensions where all values are equal to v", " // (more general case of zeros)", "", " values(vs: Collection⟦T⟧) → Matrix⟦T⟧", " // a matrix with the specified dimensions where the values are given by vs", " // throws an error if vs.size ≠ rows * columns", "}", "", "def MatrixDimensionsError is public = ProgrammingError.refine \"MatrixDimensionsError\"", "", "type ComparableToMatrix⟦T⟧ = interface {", " numRows → Number", " numColumns → Number", " atRow(r:Number) column(c:Number) ifAbsent(_) → T", "}", "", "type ImplementsTimesOperator⟦K⟧ = interface {", " *(other) → K", "}", "", "method dot(v1: Collection, v2: Collection) {", " var dotProduct := 0", " def iteratorV1 = v1.iterator", " def iteratorV2 = v2.iterator", " ", " while { iteratorV1.hasNext && iteratorV2.hasNext } do {", " dotProduct := dotProduct + (iteratorV1.next * iteratorV2.next)", " }", " dotProduct", "}", "", "method listOfSize(size) withValue(v) is confidential {", " def l = list.empty", " repeat (size) times { l.add(v) }", " l", "}", "", "class lazyZipperSequence⟦T⟧ (source1: Collection⟦Collection⟦T⟧⟧, source2: Collection⟦T⟧) {", " // takes a collection of collections (source1) and adds a value from the given ", " // collection (source2) to the end of each collection ", " // example: lazyZipperSequence([ [1], [2] ], [3, 4]) = ([ [1, 3], [2, 4] ]) ", " use coll.enumerable⟦Collection⟦T⟧⟧", " if (source1.size ≠ source2.size) then { TypeError.raise \"must be same size\" }", " method iterator {", " object {", " def iterator1 = source1.iterator", " def iterator2 = source2.iterator", " ", " method asString { \"a zipper iterator over {iterator1} and {iterator2}\" }", " method hasNext { iterator1.hasNext }", " method next { coll.lazyConcatenation(iterator1.next, [iterator2.next]) }", " }", " }", " method size { source1.size }", " method isEmpty { (source1.size == 0) && (source2.size == 0) }", " method asDebugString { \"a lazy sequence zippering over {source1} and {source2}\" }", "}", "", "method mapColumnsToRows(columns: Collection⟦Collection⟧) {", " if (columns.size == 0) then { return [] }", " columns.fold{ rs, c → lazyZipperSequence(rs, c) } startingWith( listOfSize(columns.first.size) withValue([]) )", "}", "", "method empty is public { matrix(0, 0).values([]) }", "", "method with⟦T⟧(x:T) → Matrix⟦T⟧ is public { matrix⟦T⟧(1,1).value(x) }", " ", "class matrix⟦T⟧(rs, cs) → MatrixFactory⟦T⟧ {", " method asString { \"the matrix factory\" } ", " ", " method withAll(a: Collection⟦T⟧) -> Matrix⟦T⟧ { values(a) }", " ", " method << (source) { values(source) }", " ", " method zeros → Matrix⟦Number⟧ {", " value(0)", " }", " ", " method rows(r: Collection⟦Collection⟦T⟧⟧) → Matrix⟦T⟧{", " values( r.fold{ r1, r2 → coll.lazyConcatenation(r1,r2) } startingWith([]) )", " }", " ", " method columns(c: Collection⟦Collection⟦T⟧⟧) → Matrix⟦T⟧ {", " rows(mapColumnsToRows(c))", " }", " ", " method value(v:T) → Matrix⟦T⟧ {", " values (listOfSize(rs*cs) withValue(v))", " }", " ", " class values(vs: Collection⟦T⟧) → Matrix⟦T⟧ {", " use coll.collection⟦T⟧", " ", " if ( (rs * cs) ≠ vs.size) then { MatrixDimensionsError.raise \"dimensions {rs}x{cs} is not compatible with values of size {vs.size}\" }", " var impl := vs >> list", " ", " var numRows is public := rs", " var numColumns is public := cs", " ", " method isRowValid(r) is confidential { (r > 0) && (r ≤ numRows) }", " method isColumnValid(c) is confidential { (c > 0) && (c ≤ numColumns) }", " ", " method indexFromRow(r) column (c) ifOutOfBounds(action) is confidential {", " if ( (isRowValid(r) && isColumnValid(c)).not ) then {action.apply}", " (r - 1) * numColumns + c", " }", " ", " method indexFromRow(r) column(c) is confidential {", " indexFromRow(r) column(c) ifOutOfBounds { BoundsError.raise \"position {r}, {c} is out of bounds\" }", " }", " ", " method size { impl.size }", " ", " method sizeIfUnknown(_) { size }", " ", " method atRow(r) column(c) put (v:T) {", " impl.at( indexFromRow(r) column(c) ) put (v)", " self", " }", " ", " method atRow(r) column(c) {", " impl.at( indexFromRow(r) column(c) )", " }", " ", " method atRow(r) column(c) ifAbsent(action) {", " impl.at( indexFromRow(r) column(c) ifOutOfBounds (action) )", " }", " ", " method do(action) {", " impl.do { each → action.apply(each) }", " }", " ", " method values → Enumerable⟦T⟧ { impl }", " ", " method iterator { impl.iterator }", " ", " method rows -> Enumerable⟦Enumerable⟦T⟧⟧ {", " def sourceMatrix = self", " object {", " use coll.enumerable⟦Enumerable⟦T⟧⟧", " class iterator {", " var currentRow := 1", " method hasNext { currentRow ≤ numRows }", " method next { ", " def r = currentRow", " currentRow := currentRow + 1", " sourceMatrix.row(r)", " }", " method asString {", " \"an iterator over rows of {sourceMatrix}\"", " }", " }", " def size is public = numRows", " method asDebugString {", " \"a lazy sequence over rows of {sourceMatrix}\"", " }", " }", " }", " ", " method columns -> Enumerable⟦Enumerable⟦T⟧⟧ {", " def sourceMatrix = self", " object {", " use coll.enumerable⟦Enumerable⟦T⟧⟧", " class iterator {", " var currentColumn := 1", " method hasNext { currentColumn ≤ numColumns }", " method next { ", " def c = currentColumn", " currentColumn := currentColumn + 1", " sourceMatrix.column(c)", " }", " method asString {", " \"an iterator over columns of {sourceMatrix}\"", " }", " }", " def size is public = numColumns", " method asDebugString {", " \"a lazy sequence over columns of {sourceMatrix}\"", " }", " }", " }", " ", " method row(r) {", " def sourceMatrix = self", " object {", " use coll.enumerable⟦T⟧", " class iterator {", " var currentColumn := 1", " method hasNext { currentColumn ≤ numColumns }", " method next { ", " def c = currentColumn", " currentColumn := currentColumn + 1", " sourceMatrix.atRow(r) column(c)", " }", " method asString {", " \"an iterator over row {r} of {sourceMatrix}\"", " }", " }", " def size is public = numColumns", " method asDebugString {", " \"a lazy sequence over row {r} of {sourceMatrix}\"", " }", " }", " }", " ", " method column(c) {", " def sourceMatrix = self", " object {", " use coll.enumerable⟦T⟧", " class iterator {", " var currentRow := 1", " method hasNext { currentRow ≤ numRows }", " method next { ", " def r = currentRow", " currentRow := currentRow + 1", " sourceMatrix.atRow(r) column(c)", " }", " method asString {", " \"an iterator over column {c} of {sourceMatrix}\"", " }", " }", " def size is public = numRows", " method asDebugString {", " \"a lazy sequence over column {c} of {sourceMatrix}\"", " }", " }", " }", " ", " method applyScalarOperation(op) with (num) is confidential {", " matrix(self.numRows, self.numColumns).values(impl.map{each → op.apply(each, num)})", " }", " ", " method applyMatrixOperation(op) with (other) is confidential {", " if ( (other.numRows ≠ self.numRows) || (other.numColumns ≠ self.numColumns) ) then {", " MatrixDimensionsError.raise \"Dimensions of {other} are not compatible with dimensions of {self}\"", " }", " ", " def newMatrix = self.copy", " (1..numColumns).do { c →", " (1..numRows).do { r →", " newMatrix.atRow(r) column(c) put (op.apply(newMatrix.atRow(r) column(c), other.atRow(r) column(c)))", " }", " }", " newMatrix ", " }", " ", " method +(other : Matrix⟦T⟧) {", " // This operation only makes sense with another matrix as argument, not a scalar", " applyMatrixOperation{a, b → a+b} with (other) ", " }", " ", " method -(other : Matrix⟦T⟧) {", " // This operation only makes sense with another matrix as argument, not a scalar", " applyMatrixOperation{a, b → a - b} with(other)", " }", " ", " method *(other) {", " // This operation makes sense both with another matrix as argument, and with a scalar as argument", " // Since it is not possible to add a selfTimesMatrix method to the Number type, it is necessary", " // to check the type of the argument", " if ( ComparableToMatrix.matches(other) ) then { applyMatrixOperation{a, b → a*b} with (other) ", " } elseif { ImplementsTimesOperator.matches(other) } then { applyScalarOperation{a, b → a*b} with(other) ", " } else { TypeError.raise \"Type of {other} does not support operator *\" }", " }", " ", " method /(other) {", " // This operation makes sense both with another matrix as argument, and with a scalar as argument", " // Since it is not possible to add a selfTimesMatrix method to the Number type, it is necessary", " // to check the type of the argument", " if ( ComparableToMatrix.matches(other) ) then { applyMatrixOperation{a, b → a/b} with (other) ", " } elseif { ImplementsTimesOperator.matches(other) } then { applyScalarOperation{a, b → a/b} with(other) ", " } else { TypeError.raise \"Type of {other} does not support operator /\" }", " }", " ", " method transpose {", " matrix(self.numColumns, self.numRows).rows(self.columns)", " }", " ", " method reverseTimesNumber(num) {", " self*num", " }", " ", " method reverseDivideNumber(num) {", " TypeError.raise \"Cannot divide a number by a matrix\"", " }", " ", " method reverseMinusNumber(num) {", " TypeError.raise \"Cannot subtract a number from a matrix\"", " }", " ", " method reversePlusNumber(num) {", " TypeError.raise \"Cannot add a number to a matrix\"", " }", " ", " method times(other) {", " // This method performs matrix multiplication, whereas the * operation performs value-wise multiplication", " if ( (other.numRows ≠ self.numColumns) || (other.numColumns ≠ self.numRows) ) then {", " MatrixDimensionsError.raise \"Dimensions of {other} are not compatible with dimensions of {self}\"", " }", " ", " def newValues = list.empty", " self.rows.do { row →", " other.columns.do { col →", " newValues.add(dot(row, col))", " }", " }", " matrix(self.numRows, other.numColumns).values(newValues)", " }", " ", " method reshapeWithNumRows(newRs) numColumns(newCs) {", " if ( (newRs * newCs) ≠ impl.size) then { MatrixDimensionsError.raise \"dimensions {newRs}x{newCs} are not compatible with values of size {vs.size}\" }", " numRows := newRs", " numColumns := newCs", " self", " }", " ", " method reshapeWithNumRows(newRs) numColumns(newCs) additionalValues(newVs) {", " if ( (newRs * newCs) ≠ (impl.size + newVs.size) ) then { MatrixDimensionsError.raise \"dimensions {newRs}x{newCs} are not compatible with values of size {vs.size}\" }", " impl.addAll(newVs)", " numRows := newRs", " numColumns := newCs", " self", " }", " ", " method addRow(row) at(r) {", " if (row.size ≠ numColumns) then { MatrixDimensionsError.raise \"row size must be equal to {numColumns}\" } ", " if ( (r ≤ 0) || (r > (numRows + 1) ) ) then { BoundsError.raise \"invalid row number {r}\" }", " ", " var index := indexFromRow(r) column(1) ifOutOfBounds { size } ", " row.do {each →", " impl.insert(each) at (index)", " index := index + 1", " }", " numRows := numRows + 1", " self", " }", " ", " method deleteRow(r) {", " if ( (r ≤ 0) || (r > numRows) ) then { BoundsError.raise \"row {r} does not exist\" } ", " ", " def index = indexFromRow(r) column(1)", " repeat (numColumns) times {", " impl.removeAt(index)", " }", " ", " numRows := numRows - 1", " self", " }", " ", " method addColumn(column) at(c) {", " if (column.size ≠ numRows) then { MatrixDimensionsError.raise \"column size must be equal to {numRows}\" } ", " if ( (c ≤ 0) || (c > (numColumns + 1) ) ) then { BoundsError.raise \"invalid column number {c}\" }", " ", " var index := indexFromRow(1) column(c) ifOutOfBounds { numColumns + 1 } ", " column.do {each →", " impl.insert(each) at (index)", " index := index + numColumns + 1", " }", " numColumns := numColumns + 1", " self", " }", " ", " method deleteColumn(c) {", " if ( (c ≤ 0) || (c > numColumns) ) then { BoundsError.raise \"column {c} does not exist\" } ", " ", " var index := indexFromRow(1) column(c)", " repeat (numRows) times {", " impl.removeAt(index)", " index := index + numColumns - 1", " }", " ", " numColumns := numColumns - 1", " self", " }", "", " method replaceRowAt(r) with(row) {", " if (row.size ≠ numColumns) then { MatrixDimensionsError.raise \"row size must be equal to {numColumns}\" } ", " if ( (r ≤ 0) || (r > numRows ) ) then { BoundsError.raise \"invalid row number {r}\" }", " ", " var c := 1", " row.do { each →", " self.atRow(r) column(c) put (each)", " c := c + 1", " }", " self", " }", " ", " method replaceColumnAt(c) with(column) {", " if (column.size ≠ numRows) then { MatrixDimensionsError.raise \"row size must be equal to {numRows}\" } ", " if ( (c ≤ 0) || (c > numColumns ) ) then { BoundsError.raise \"invalid row number {c}\" }", " ", " var r := 1", " column.do { each →", " self.atRow(r) column(c) put (each)", " r := r + 1", " }", " self", " }", " ", " method ==(other) { ", " if ( ComparableToMatrix.matches(other).not ) then { return false }", " if ( (other.numRows ≠ self.numRows) || (other.numColumns ≠ self.numColumns) ) then { return false }", " ", " (1..numColumns).do { c →", " (1..numRows).do { r →", " def currentValue = self.atRow(r) column(c) ifAbsent { return false }", " def otherValue = other.atRow(r) column(c) ifAbsent { return false }", " if (currentValue ≠ otherValue) then { return false }", " }", " }", " ", " return true", " }", " ", " method copy {", " matrix(numRows, numColumns).values(impl)", " }", " ", " method ≠ (other) { (self == other).not }", " ", " method ++(other) {", " if ( (other.size % self.numColumns) ≠ 0) then { MatrixDimensionsError.raise \"size of {other} is incompatible with dimensions {numRows}x{numColumns}\" }", " matrix((impl.size + other.size) / self.numColumns, self.numColumns).values(coll.lazyConcatenation(impl, other.values))", " }", " ", " method asString {", " var string := \"matrix [\"", " self.rows.do { each →", " string := string ++ each.asString", " } separatedBy { string := string ++ \", \" }", " string ++ \"]\"", " }", " }", "}" ]; } function gracecode_matrix() { importedModules["matrix"] = this; const var_$module = this; this.definitionModule = "matrix"; this.definitionLine = 1; setLineNumber(1); // compilenode dialect // Dialect "standard" const var_$dialect = do_import("standard", gracecode_standard); this.outer = var_$dialect; setLineNumber(4); // compilenode import // Import of "collections" as coll if (typeof gracecode_collections == "undefined") throw new GraceExceptionPacket(EnvironmentExceptionObject, new GraceString("could not find module collections")); var var_coll = do_import("collections", gracecode_collections); var func0 = function(argcv) { // accessor method coll, line 4 const numArgs = arguments.length - 1; if (numArgs > 0) raiseTypeArgError("coll", 0, numArgs - 0); return var_coll; }; // end of method coll this.methods["coll"] = func0; func0.methodName = "coll"; func0.paramCounts = [0]; func0.paramNames = []; func0.definitionLine = 4; func0.definitionModule = "matrix"; func0.debug = "import"; func0.confidential = true; this.closureKeys = this.closureKeys || []; this.closureKeys.push("outer_matrix_1"); this.outer_matrix_1 = var_$dialect; setLineNumber(6); // compilenode typedec // Type decl Matrix var func2 = function(argcv, var_T) { // method Matrix, line 1 var returnTarget = invocationCount; invocationCount++; setLineNumber(1); // compilenode string var string4 = new GraceString("Matrix"); // call case 4: other requests setLineNumber(6); // compilenode interfaceliteral // interface literal var iface6 = new GraceInterface("\u2039anon\u203a"); sig7 = () => { setLineNumber(7); // compilenode member var call8 = selfRequest(var_$dialect, "Number", [0]); return new GraceSignature("size", [], [], [], call8); } sig9 = () => { setLineNumber(10); // compilenode member var call10 = selfRequest(var_$dialect, "Number", [0]); return new GraceSignature("numRows", [], [], [], call10); } sig11 = () => { setLineNumber(13); // compilenode member var call12 = selfRequest(var_$dialect, "Number", [0]); return new GraceSignature("numColumns", [], [], [], call12); } sig13 = () => { setLineNumber(16); // compilenode member var call14 = selfRequest(var_$dialect, "Number", [0]); var call15 = selfRequest(var_$dialect, "Number", [0]); var call16 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("atRow(1)column(1)put(1)", ["r", "c", "v"], [], [call14, call15, var_T], call16); } sig17 = () => { setLineNumber(20); // compilenode member var call18 = selfRequest(var_$dialect, "Number", [0]); var call19 = selfRequest(var_$dialect, "Number", [0]); return new GraceSignature("atRow(1)column(1)", ["r", "c"], [], [call18, call19], var_T); } sig20 = () => { setLineNumber(24); // compilenode member var call21 = selfRequest(var_$dialect, "Number", [0]); var call22 = selfRequest(var_$dialect, "Number", [0]); var call23 = selfRequest(var_$dialect, "Procedure0", [0]); return new GraceSignature("atRow(1)column(1)ifAbsent(1)", ["r", "c", "action"], [], [call21, call22, call23], var_T); } sig24 = () => { setLineNumber(28); // compilenode member var call25 = selfRequest(var_$dialect, "Number", [0]); var call26 = selfRequest(var_$dialect, "Collection", [0]); return new GraceSignature("row(1)", ["r"], [], [call25], call26); } sig27 = () => { setLineNumber(32); // compilenode member var call28 = selfRequest(var_$dialect, "Number", [0]); var call29 = selfRequest(var_$dialect, "Collection", [0]); return new GraceSignature("column(1)", ["c"], [], [call28], call29); } sig30 = () => { setLineNumber(36); // compilenode member var call31 = selfRequest(var_$dialect, "Enumerable", [0]); return new GraceSignature("rows", [], [], [], call31); } sig32 = () => { setLineNumber(39); // compilenode member var call33 = selfRequest(var_$dialect, "Enumerable", [0]); return new GraceSignature("columns", [], [], [], call33); } sig34 = () => { setLineNumber(42); // compilenode member var call35 = selfRequest(var_$dialect, "Enumerable", [0]); return new GraceSignature("values", [], [], [], call35); } sig36 = () => { setLineNumber(45); // compilenode member var call37 = selfRequest(var_$module, "Matrix", [0]); var call38 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("+(1)", ["other"], [], [call37], call38); } sig39 = () => { setLineNumber(49); // compilenode member var call40 = selfRequest(var_$module, "Matrix", [0]); var call41 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("-(1)", ["other"], [], [call40], call41); } sig42 = () => { setLineNumber(53); // compilenode member var call43 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("*(1)", ["other"], [], [type_Unknown], call43); } sig44 = () => { setLineNumber(58); // compilenode member var call45 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("/(1)", ["other"], [], [type_Unknown], call45); } sig46 = () => { setLineNumber(63); // compilenode member var call47 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("transpose", [], [], [], call47); } sig48 = () => { setLineNumber(66); // compilenode member var call49 = selfRequest(var_$module, "Matrix", [0]); var call50 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("times(1)", ["other"], [], [call49], call50); } sig51 = () => { setLineNumber(70); // compilenode member var call52 = selfRequest(var_$dialect, "Number", [0]); var call53 = selfRequest(var_$dialect, "Number", [0]); var call54 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("reshapeWithNumRows(1)numColumns(1)", ["rs", "cs"], [], [call52, call53], call54); } sig55 = () => { setLineNumber(75); // compilenode member var call56 = selfRequest(var_$dialect, "Number", [0]); var call57 = selfRequest(var_$dialect, "Number", [0]); setLineNumber(76); // compilenode member var call58 = selfRequest(var_$dialect, "Collection", [0]); var call59 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("reshapeWithNumRows(1)numColumns(1)additionalValues(1)", ["rs", "cs", "vs"], [], [call56, call57, call58], call59); } sig60 = () => { setLineNumber(81); // compilenode member var call61 = selfRequest(var_$dialect, "Collection", [0]); var call62 = selfRequest(var_$dialect, "Number", [0]); var call63 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("addRow(1)at(1)", ["row", "index"], [], [call61, call62], call63); } sig64 = () => { setLineNumber(85); // compilenode member var call65 = selfRequest(var_$dialect, "Number", [0]); var call66 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("deleteRow(1)", ["r"], [], [call65], call66); } sig67 = () => { setLineNumber(89); // compilenode member var call68 = selfRequest(var_$dialect, "Collection", [0]); var call69 = selfRequest(var_$dialect, "Number", [0]); var call70 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("addColumn(1)at(1)", ["column", "index"], [], [call68, call69], call70); } sig71 = () => { setLineNumber(93); // compilenode member var call72 = selfRequest(var_$dialect, "Number", [0]); var call73 = selfRequest(var_$module, "Matrix", [0]); return new GraceSignature("deleteColumn(1)", ["c"], [], [call72], call73); } sig74 = () => { setLineNumber(97); // compilenode member var call75 = selfRequest(var_$dialect, "Number", [0]); var call76 = selfRequest(var_$dialect, "Collection", [0]); var call77 = selfRequest(var_$module, "Matrix",