* won't accept rectangular arrays like (* 3x2 2x3)

Asked by Raymond Laning

When I try multiplying two rectangular matrices such as a 2X3 times a 3X2, I get the error
The dimensions of the mathematical objects do not agree: 3 vs 2.
This is a legitimate multiplication, is it not? It seems to be limited to square arrays and vectors.
Two rectangular arrays should yield:
(* 2X3 3X2) => 2X2
(* 3X2 2X3) => 3X3

Question information

Language:
English Edit question
Status:
Solved
For:
L-MATH Edit question
Assignee:
No assignee Edit question
Solved by:
Raymond Laning
Solved:
Last query:
Last reply:
Revision history for this message
Rudy Neeser (the-river) said :
#1

Could you provide an example of this not working? This seems to be working fine for me. For example:

(lm:* (lm:make-matrix 2 3 :initial-elements '(1 0 0
             0 1 0))
        (lm:make-matrix 3 2 :initial-elements '(1 0
             0 0
             0 1)))

is a 2×3 matrix multiplied by a 3×2 matrix, and provides the answer:

#<L-MATH:MATRIX 2 x 2
1.000 0.000
0.000 0.000 >

Revision history for this message
Raymond Laning (rlaning) said :
#2

I'm using CCL,perhaps there is a problem there? For your example, I get
1 doesn't match array element type of #(0.0D0
                                        0.0D0
                                        0.0D0
                                        0.0D0
                                        0.0D0
                                        0.0D0).
   [Condition of type CCL::ARRAY-ELEMENT-TYPE-ERROR]
If I try
(lm:* (lm:make-matrix 2 3 :initial-elements '(1.0D0 0.0D0 0.0D0
             0.0D0 1.0D0 0.0D0))
        (lm:make-matrix 3 2 :initial-elements '(1.0D0 0.0D0
             0.0D0 0.0D0
             0.0D0 1.0D0)))
I get the previously mentioned errror. I see that the code for c* in operations.lisp contains the logic for transposing the second array for dimension comparison but it doesn't seem to get applied in this case.

Revision history for this message
Rudy Neeser (the-river) said :
#3

I've never come across CCL, actually. L-MATH hasn't been tested against it. What version of L-MATH are you using? The ASDF version is a fare bit behind the latest repo code, which you can find here: https://github.com/TheRiver/L-MATH I'm not sure if this will work any better on CCL, unfortunately.

Revision history for this message
Raymond Laning (rlaning) said :
#4

Good news, bad news.
You are right, the asdf version was missing one of your patches which fixed the problem for the case where the output was a square array (lm:* NXM MXN) => NXN or (lm:* MXN NXM) => MXM.
But I still get an error for the more general case
(lm:* NXM MXL) => NXL

Revision history for this message
Rudy Neeser (the-river) said :
#5

That seems like quite a serious problem :-/ If you would like to submit a patch via github, I will gladly look it over. Otherwise, the library does run fine on SBCL.

Revision history for this message
Raymond Laning (rlaning) said :
#6

Hello Rudy,

I find that, having recompiled and reloaded the system, the observed bug has vanished, (lm:* arr23 arr34) => arr24. Please forgive the never mind.

Revision history for this message
Rudy Neeser (the-river) said :
#7

Am glad it's working! :)