Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGenericMatrix class seems to have mistakes in its constructor and method copyDataTo()
Forum Updated to NodeBB v4.3 + New Features

QGenericMatrix class seems to have mistakes in its constructor and method copyDataTo()

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 805 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andruxin
    wrote on last edited by Andruxin
    #1

    Hello guys! I was trying to use QGenericMatrix class constructor: QGenericMatrix(const T *values).
    Here's an example:

    int values[] = { 1, 2, 3, //here's a matrix as i want it to see and as it must be passed into QGenericMatrix object
                     4, 5, 6, //as documentation(http://doc.qt.io/qt-5/qgenericmatrix.html#QGenericMatrix-2) says
                     7, 8, 9,
                     10,11,12 } 
    QGenericMatrix<3, 4, int> matrix(values); //creates matrix object with 3 columns and 4 rows and inits it with values 
    

    After that code matrix object won't look as we expected it to. I think there is a simple mistake which you can find in QGenericMatrix.h source code:

    template <int N, int M, typename T>
    Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T>::QGenericMatrix(const T *values)
    {
        for (int col = 0; col < N; ++col)
            for (int row = 0; row < M; ++row)
                m[col][row] = values[row * N + col];
    }
    

    I think instead there must be something like:

    template <int N, int M, typename T>
    Q_OUTOFLINE_TEMPLATE QGenericMatrix<N, M, T>::QGenericMatrix(const T *values)
    {   
        for (int row = 0; row < M; ++row)
            for (int col = 0; col < N; ++col)
                m[col][row] = values[row * N + col];
    }
    

    Same mistake seems to be in copyDataTo() method and may be in some other methods (i haven't investigated source code that much). I'm just asking because it's very huge and important functionality bug and it's hard to imagine that it could live so long without someone to see it.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi

      • After that code matrix object won't look as we expected it to.

      Hi the docs says
      "The contents of the array values is assumed to be in row-major order."

      https://stackoverflow.com/questions/33862730/row-major-vs-column-major-confusion

      So you are saying that it reads a row-major array wrongly?

      A 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi

        • After that code matrix object won't look as we expected it to.

        Hi the docs says
        "The contents of the array values is assumed to be in row-major order."

        https://stackoverflow.com/questions/33862730/row-major-vs-column-major-confusion

        So you are saying that it reads a row-major array wrongly?

        A Offline
        A Offline
        Andruxin
        wrote on last edited by
        #3

        @mrjj I'm sorry I wasn't right. I was looking on the Debug section of QtCreator trying to understand what is happening to matrix. It wasn't wise decision 'cause matrix's storing and displaying are two different things. Thanks for an answer.

        mrjjM 1 Reply Last reply
        1
        • A Andruxin

          @mrjj I'm sorry I wasn't right. I was looking on the Debug section of QtCreator trying to understand what is happening to matrix. It wasn't wise decision 'cause matrix's storing and displaying are two different things. Thanks for an answer.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Andruxin
          Indeed it is and easy to mix row/col but good it wasn't a bug :)O

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved