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

SketchMap is not commutative #1122

Open
Peilin-Yang opened this issue Jun 30, 2023 · 0 comments
Open

SketchMap is not commutative #1122

Peilin-Yang opened this issue Jun 30, 2023 · 0 comments

Comments

@Peilin-Yang
Copy link

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.

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