Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Why is sparse * 3D full array allowed?
Date: Fri, 16 Oct 2009 06:36:03 +0000 (UTC)
Organization: Boeing
Lines: 46
Message-ID: <hb948j$28q$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1255674963 2330 172.30.248.37 (16 Oct 2009 06:36:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 16 Oct 2009 06:36:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:577724


I noticed that if a sparse matrix is multiplied by a full nD matrix that can be squeezed to a 2D matrix, the multiplication takes place by doing the squeeze. But the same calculation for a full matrix is not allowed. Anybody know why this behavior should be different for sparse vs full?  Seems like it should work the same both ways, either both allow it or both not allow it. e.g.,

>> A = sprand(10,10,.1)
A =
   (7,1)       0.5940
     :               :
   (6,10)      0.6831
>> B = rand(10,1,3)
B(:,:,1) =
    0.9147
        :
B(:,:,2) =
    0.1615
        :
B(:,:,3) =
    0.4279
        :
>> A*B
ans =
    0.1185    0.0032    0.0492
    0.1139    0.0031    0.0473
         0         0         0
    0.0338    0.0261    0.0550
    0.9378    0.7062    0.5906
    0.2056    0.4609    0.1696
    0.5433    0.0959    0.2542
    0.2788    0.2448    0.1858
         0         0         0
    0.4363    0.0469    0.2382
>> full(A)*B
??? Error using ==> mtimes
Input arguments must be 2-D.
>> full(A)*squeeze(B)
ans =
    0.1185    0.0032    0.0492
    0.1139    0.0031    0.0473
         0         0         0
    0.0338    0.0261    0.0550
    0.9378    0.7062    0.5906
    0.2056    0.4609    0.1696
    0.5433    0.0959    0.2542
    0.2788    0.2448    0.1858
         0         0         0
    0.4363    0.0469    0.2382

James Tursa