Skip to content

Matrix multiplication gives wrong output and throws error for compatible matrices #42

@Maxouwe

Description

@Maxouwe

It seems that sometimes the output of Matrix.mul is incorrect. For example:
a = [[1, 3, -5], [-6, 3, -2]]; b = [[1, 3, 4, 6], [1, 2, 3, 5], [1, 2, 34, 2]]; Matrix.mul(a, b)
Which gives the output [ [ -1, -1 ], [ -5, -16 ] ]
and which should be [ [ -1, -1, -157, 11 ], [ -5, -16, -83, -25 ] ]
I also get an error for certain multiplications eventhough the matrices are elligible for multiplication.
For example:
a = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]; b = [[1, 1], [1, 1], [1, 1]]; Matrix.mul(a, b)
This should have an output of [ [ 3, 3 ], [ 3, 3 ], [ 3, 3 ] ]
But instead this is shown in the post window:
`ERROR: binary operator '' failed.
RECEIVER:
nil
ARGS:
Instance of Array { (00000219D9F9C378, gc=F0, fmt=01, flg=00, set=02)
indexed slots [3]
0 : Integer 1
1 : Integer 1
2 : Integer 1
}
nil
CALL STACK:
DoesNotUnderstandError:reportError
arg this =
Nil:handleError
arg this = nil
arg error =
Thread:handleError
arg this =
arg error =
Object:throw
arg this =
Object:performBinaryOpOnSomething
arg this = nil
arg aSelector = '
'
arg thing = [*3]
arg adverb = nil
< FunctionDef in Method Meta_Matrix:mul >
arg u = 2
Integer:do
arg this = 3
arg function =
var i = 2
ArrayedCollection:do
arg this = [*3]
arg function =
var i = 0
Meta_Matrix:mul
arg this =
arg m1 = [*3]
arg m2 = [*3]
var m2s = [*2]
var out = [3]
var size = 3
Interpreter:interpretPrintCmdLine
arg this =
var res = nil
var func =
var code = "Matrix.mul(a, b)"
var doc = nil
var ideClass =
Process:interpretPrintCmdLine
arg this =
^^ ERROR: binary operator '
' failed.
RECEIVER: nil

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions