1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
4//
5//  This file is distributed under the same license as the Scilab package.
6// =============================================================================
7//
8// <-- CLI SHELL MODE -->
9//
10// <-- Non-regression test for bug 10998 -->
11//
12// <-- Bugzilla URL -->
13// http://bugzilla.scilab.org/show_bug.cgi?id=10998
14//
15// <-- Short Description -->
16// matrix*hypermatrix operation failed.
17//---------------------------------------------------
18// Matrix * Hypermatrix
19clear
20rand("seed", 0);
21test1 = rand(3, 3, 3);
22test2 = rand(3, 3, 3);
23// Multiply a 3x3 matrix by a 3x1x3 hypermatrix.
24c = test1(:, :, 1) * test2(:, 2, :);
25// Build the expected result. Its size is 3x1x3.
26refC = zeros(3, 1, 3);
27for i=1:3
28    refC(:, :, i) = test1(:, :, 1) * test2(:, 2, i);
29end
30assert_checkequal(c, refC);
31// Now with harder dimensions
32test1 = rand(5, 3);
33test2 = rand(3, 4, 3);
34// Multiply a 5x3 matrix by a 3x2x3 hypermatrix.
35c = test1(:, :) * test2(:, 1:2, :);
36// Build the expected result. Its size is 5x2x3.
37refC = zeros(5, 2, 3);
38for i=1:3
39    refC(:, :, i) = test1(:, :) * test2(:, 1:2, i);
40end
41assert_checkequal(c, refC);
42//---------------------------------------------------
43// Hypermatrix * Matrix
44test1 = rand(4, 3);
45// Multiply a 3x4x3 matrix by a 4x3 hypermatrix.
46c = test2(:, :, :) * test1(:, :);
47// Build the expected result. Its size is 3x3x3.
48refC = zeros(3, 3, 3);
49for i=1:3
50    refC(:, :, i) = test2(:, :, i) * test1(:, :);
51end
52assert_checkequal(c, refC);
53