Skip to content

SketchMap is not commutative  #1122

@Peilin-Yang

Description

@Peilin-Yang

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Add the following new test to the unit test algebird/algebird-test/src/test/scala/com/twitter/algebird/SketchMapTest.scala after line 57
    "plus should work commutatively" in {
      implicit val m = Monoid.longMonoid
      val valueTableLeft =
        DenseMatrix(
          PARAMS.width,
          PARAMS.depth,
          rowsByColumns = IndexedSeq(10L) ++ (1 until PARAMS.width * PARAMS.depth).map(_ => 0L)
        )
      val testLeft = SketchMap[Int, Long](
        valuesTable = valueTableLeft,
        heavyHitterKeys = List(1),
        totalValue = 10
      )

      val valueTableRight = SparseColumnMatrix(rowsByColumns =
        IndexedSeq(
          SparseVector(
            map = Map(1 -> 1L),
            sparseValue = 1L,
            length = PARAMS.width * PARAMS.depth
          )
        )
      )
      val testRight = SketchMap[Int, Long](
        valuesTable = valueTableRight,
        heavyHitterKeys = List(1),
        totalValue = 1
      )

      assert(MONOID.plus(testLeft, testRight) == MONOID.plus(testRight, testLeft))
    }
  1. Run the test and it would fail

Expected behavior

The test is expected to pass

Screenshots
N/A

Environment
N/A

Additional context
This is mainly because the algebird/algebird-core/src/main/scala/com/twitter/algebird/matrix/AdaptiveMatrix.scala doesn't handle the (SparseColumnMatrix, DenseMatrix) input (in that order) correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions