Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mul() gives wrong answer? #23

Closed
tjyuyao opened this issue Jun 3, 2020 · 1 comment
Closed

mul() gives wrong answer? #23

tjyuyao opened this issue Jun 3, 2020 · 1 comment

Comments

@tjyuyao
Copy link

tjyuyao commented Jun 3, 2020

#include "linalg.h"
#include <iostream>

using namespace linalg::aliases;
using namespace linalg::ostream_overloads;
using namespace std;

int main() {

    float3x3 A = {
        {1.f, 0.f, 3.f},
        {0.f, 1.f, 3.f},
        {0.f, 0.f, 1.f},
    };

    float3x3 B = {
        {2.f, 0.f, 0.f},
        {0.f, 2.f, 0.f},
        {0.f, 0.f, 1.f},
    };

    cout << mul(A, B) << endl;

    /* 
     * the result output by this program is {{2,0,6},{0,2,6},{0,0,1}}, while by Octave:
     *
     * >> a = [ [1 0 3]; [0 1 3]; [0 0 1] ]
     * a =
     * 
     *    1   0   3
     *    0   1   3
     *    0   0   1
     * 
     * >> b = [[2 0 0]; [0 2 0]; [0 0 1]]
     * b =
     * 
     *    2   0   0
     *    0   2   0
     *    0   0   1
     * 
     * >> a * b
     * ans =
     * 
     *    2   0   3
     *    0   2   3
     *    0   0   1
     * */

    return 0;
}

while the document states mul(mat<T,M,N> a, mat<T,N,P> b) -> mat<T,M,P>, the library seems to calculate mul(b, a).

Is something I made wrong? or there is a bug in the library?

@tjyuyao
Copy link
Author

tjyuyao commented Jun 3, 2020

Ohh, I understand why. I mixed the rows and columns of the initialization list.

@tjyuyao tjyuyao closed this as completed Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant