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

Update to algebra 2.7.0 #1115

Merged
merged 11 commits into from
Nov 30, 2021
Merged
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lazy val scalaCheckVersion = "1.15.4"
lazy val munit = "0.7.29"
lazy val munitDiscipline = "1.0.9"

lazy val algebraVersion = "2.2.3"
lazy val algebraVersion = "2.7.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be rename to catsVersion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, catsVersion = algebraVersion now. But since we don't explicitly depend on cats, I think this is fine for now.


lazy val apfloatVersion = "1.10.1"
lazy val jscienceVersion = "4.3.1"
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala-2/spire/macros/Auto.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ abstract class AutoAlgebra extends AutoOps { ops =>
def EuclideanRing[A: c.WeakTypeTag](z: c.Expr[A], o: c.Expr[A])(ev: c.Expr[Eq[A]]): c.Expr[EuclideanRing[A]] = {
c.universe.reify {
new EuclideanRing[A] { self =>
// default implementations from EuclideanRing.WithEuclideanAlgorithm
// default implementations from EuclideanRing
@tailrec final def euclid(a: A, b: A)(implicit ev: Eq[A]): A =
if (isZero(b)) a else euclid(b, emod(a, b))
def gcd(a: A, b: A)(implicit ev: Eq[A]): A =
override def gcd(a: A, b: A)(implicit ev: Eq[A]): A =
euclid(a, b)(ev)
def lcm(a: A, b: A)(implicit ev: Eq[A]): A =
override def lcm(a: A, b: A)(implicit ev: Eq[A]): A =
if (isZero(a) || isZero(b)) zero else times(equot(a, gcd(a, b)), b)

def zero: A = z.splice
Expand All @@ -186,7 +186,7 @@ abstract class AutoAlgebra extends AutoOps { ops =>
def Field[A: c.WeakTypeTag](z: c.Expr[A], o: c.Expr[A])(ev: c.Expr[Eq[A]]): c.Expr[Field[A]] = {
c.universe.reify {
new Field[A] {
// default implementations from Field.WithDefaultGCD
// default implementations from Field
override def gcd(a: A, b: A)(implicit eqA: Eq[A]): A =
if (isZero(a) && isZero(b)) zero else one
override def lcm(a: A, b: A)(implicit eqA: Eq[A]): A = times(a, b)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala-3/spire/syntax/Ops.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class SignedOps[A](a: A)(using s: Signed[A]):
def isSignNonNegative: Boolean = s.isSignNonNegative(a)

final class TruncatedDivisionOps[A](lhs: A)(using ev: TruncatedDivision[A]):
def toBigIntOpt: Opt[BigInt] = ev.toBigIntOpt(lhs)
// def toBigIntOpt: Opt[BigInt] = ev.toBigIntOpt(lhs) // TODO port to algebra?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be an API change, why?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be implemented in spire?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason it wasn't included in typelevel/algebra#247.

I think it would be good if we could continue to implement it in spire, but I wasn't sure how unless we introduce a new typeclass? Any ideas?

def tquot(rhs: A): A = ev.tquot(lhs, rhs)
def tmod(rhs: A): A = ev.tmod(lhs, rhs)
def tquotmod(rhs: A): (A, A) = ev.tquotmod(lhs, rhs)
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/scala/spire/algebra/Action.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,15 @@ trait MultiplicativeAction[@sp(Int) P, G] extends Any { self =>
def gtimesl(g: G, p: P): P
def gtimesr(p: P, g: G): P
}

object MultiplicativeAction {
implicit def SignAction[A](implicit A: AdditiveGroup[A]): MultiplicativeAction[A, Sign] =
new MultiplicativeAction[A, Sign] {
def gtimesl(s: Sign, a: A): A = s match {
case Signed.Positive => a
case Signed.Negative => A.negate(a)
case Signed.Zero => A.zero
}
def gtimesr(a: A, s: Sign): A = gtimesl(s, a)
}
}
30 changes: 0 additions & 30 deletions core/src/main/scala/spire/algebra/DivisionRing.scala

This file was deleted.

68 changes: 0 additions & 68 deletions core/src/main/scala/spire/algebra/EuclideanRing.scala

This file was deleted.

81 changes: 0 additions & 81 deletions core/src/main/scala/spire/algebra/Field.scala

This file was deleted.

59 changes: 0 additions & 59 deletions core/src/main/scala/spire/algebra/GCDRing.scala

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/main/scala/spire/algebra/IsReal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import spire.math.{Algebraic, Rational, Real}
/**
* A simple type class for numeric types that are a subset of the reals.
*/
trait IsReal[@sp A] extends Any with Signed[A] {
trait IsReal[@sp A] extends Any with Order[A] with Signed[A] {

/**
* Rounds `a` the nearest integer that is greater than or equal to `a`.
Expand Down
69 changes: 0 additions & 69 deletions core/src/main/scala/spire/algebra/Sign.scala

This file was deleted.

Loading