flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tillrohrmann <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-1745] Add exact k-nearest-neighbours al...
Date Thu, 08 Oct 2015 09:39:47 GMT
Github user tillrohrmann commented on the pull request:

    https://github.com/apache/flink/pull/1220#issuecomment-146474169
  
    A more scalaesque solution for the `partitionBox` method without using vars and for loops
would be
    
    ```
    def partitionBox(center: Vector, width: Vector): Seq[Vector] = {
        def partitionHelper(box: Seq[Vector], dim: Int): Seq[Vector] = {
          if (dim >= width.size) {
            box
          } else {
            val newBox = box.flatMap {
              vector =>
                val (up, down) = (vector.copy, vector)
                up.update(dim, up(dim) - width(dim) / 4)
                down.update(dim, down(dim) + width(dim) / 4)
    
                Seq(up, down)
            }
            partitionHelper(newBox, dim + 1)
          }
        }
    
        partitionHelper(Seq(center), 0)
      }
    ```



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message