Mahout
  1. Mahout
  2. MAHOUT-182

New helper methods for Matrix: times(Vector), timesSquared(Vector), numRows() and numCols()

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.2
    • Fix Version/s: 0.3
    • Component/s: Math
    • Labels:
      None

      Description

      numRows()

      { return size()[ROW]; }

      and numCols()

      { return size()[COL]; }

      are pretty much no-brainer methods, right? Who wants to deal with a length-two array of ints all the time when getting the number of rows and columns of a matrix?

      Those are pretty trivial, but the key feature of a Matrix is to map Vector instances to Vector instances, and while you can do that currently by making a a row Matrix and doing Matrix.times(Matrix), it's silly to have to always do that. Matrix.times(Vector) is pretty needed.

      Even less trivial, for really big sparse Matrices, if you need to get (M'M)v for some matrix M, then this can be computed in one pass through M without ever computing the transpose of M by a simple reordering of the limits of summation.

      Attaching a patch with these implementations, including unit tests (as well as an improvement in the Matrix.times(Matrix) unit test to actually check the math).

      1. MAHOUT-182.patch
        8 kB
        Jake Mannix
      2. matrixTimes.patch
        8 kB
        Jake Mannix

        Activity

        Jake Mannix created issue -
        Hide
        Jake Mannix added a comment -

        Patch to add these methods with unit tests.

        Show
        Jake Mannix added a comment - Patch to add these methods with unit tests.
        Jake Mannix made changes -
        Field Original Value New Value
        Attachment matrixTimes.patch [ 12420971 ]
        Grant Ingersoll made changes -
        Assignee Grant Ingersoll [ gsingers ]
        Hide
        Jake Mannix added a comment -

        Patch updated: applies cleanly again.

        Show
        Jake Mannix added a comment - Patch updated: applies cleanly again.
        Jake Mannix made changes -
        Attachment MAHOUT-182.patch [ 12425192 ]
        Hide
        Sean Owen added a comment -

        Looks fine but for one comment – that "Integer rowKey = row" line looks redundant, yes, but without it the code is actually boxing ints millions of times, creating Integers each time. This at least cuts that down.

        Show
        Sean Owen added a comment - Looks fine but for one comment – that "Integer rowKey = row" line looks redundant, yes, but without it the code is actually boxing ints millions of times, creating Integers each time. This at least cuts that down.
        Hide
        Jake Mannix added a comment -

        Ah, fair enough, might as well save a millisecond or so here and there, that's removable, sure.

        Show
        Jake Mannix added a comment - Ah, fair enough, might as well save a millisecond or so here and there, that's removable, sure.
        Hide
        Jake Mannix added a comment -

        Grant, you assigned yourself this, do you have time to look at/commit it?

        Show
        Jake Mannix added a comment - Grant, you assigned yourself this, do you have time to look at/commit it?
        Hide
        Grant Ingersoll added a comment -

        reviewing this morning.

        Show
        Grant Ingersoll added a comment - reviewing this morning.
        Hide
        Grant Ingersoll added a comment -

        Committed revision 883094.

        Show
        Grant Ingersoll added a comment - Committed revision 883094.
        Grant Ingersoll made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 0.3 [ 12314281 ]
        Resolution Fixed [ 1 ]
        Sean Owen made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Grant Ingersoll
            Reporter:
            Jake Mannix
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development