Skip to content

Conversation

@fshao816
Copy link

Here's a PR for your consideration; basically made the operators map an implicit. Note that this does change the way you call MathExp.parse however:

MathExp.parse[Double](str)

You'll have to explicitly supply the type since there's no way to infer it.

The way we are using it with saddle looks something like this:

import org.saddle.Vec
import org.saddle.ops._

    implicit object OperatorVector extends Operator[Vec[Double]] {

      val unary: Map[String, Vec[Double] => Vec[Double]] = Map.empty

      val binary: Map[String, (Vec[Double], Vec[Double]) => Vec[Double]] = {
        Map(
          "+" -> (_ + _),
          "-" -> (_ - _),
          "*" -> (_ * _),
          "/" -> (_ / _)
        )
      }
    }

We'll be building out unaryOps (for saddle Vecs) in the future.
Nice work on the library!

@facaiy
Copy link
Owner

facaiy commented Sep 12, 2017

Cool, @fshao816 ! The PR help to handle both Vector and Double, right?

I'm glad to take a review, however, CI run failed. Please check the Details links at the bottom.

Moreover, we'll be more confident after those points below are checked:

  • code style: follow Code Style Guide of Spark
  • add some unit tests to verify your changes.
  • add/modify documents (README.md) if necessary.

Be free to ping me if you need more help. Thanks.

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

Successfully merging this pull request may close these issues.

2 participants