Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 24 19:46
    scala-steward opened #876
  • Jan 23 20:30
    scala-steward opened #875
  • Jan 23 17:57
    scala-steward opened #874
  • Jan 18 00:50
    scala-steward opened #873
  • Jan 17 13:58
    codecov-io commented #872
  • Jan 17 13:57
    codecov-io commented #872
  • Jan 17 13:56
    codecov-io commented #872
  • Jan 17 13:04
    scala-steward opened #872
  • Jan 16 22:55
    codecov-io commented #871
  • Jan 16 22:53
    codecov-io commented #871
  • Jan 16 20:34
    scala-steward opened #871
  • Jan 16 09:31
    nigredo-tori opened #870
  • Jan 10 23:12
    bwignall closed #866
  • Jan 09 20:27
    codecov-io commented #869
  • Jan 09 20:27
    codecov-io commented #869
  • Jan 09 20:25
    codecov-io commented #869
  • Jan 09 19:59
    scala-steward opened #869
  • Dec 29 2019 19:11
    codecov-io commented #868
  • Dec 29 2019 19:10
    codecov-io commented #868
  • Dec 29 2019 19:09
    codecov-io commented #868
Cody Allen
@ceedubs
I started to do something with a structure that just has the Plus and Times constructors but I haven't pushed that code yet
Ghost
@ghost~529c6cf4ed5ab0b3bf04da61
Ah, I think that was the talk during which the fire alarm went off
Cody Allen
@ceedubs
that does sound familiar :)
Gabriel Jones
@gabrieljones
how do i run a specific unit test? sbt testOnly **.ComplexCheck did not seem to work.
Vinayak Pathak
@vinayakpathak
hi, is there some place that defines instances of cats typeclasses for some spire types? for example, an Eq for Rational etc?
Vinayak Pathak
@vinayakpathak
I'm trying to define an AbGroup instance for something, hoping to later use the |+| operator on it. Weirdly, it wants me to define a combine to create the AbGroup instance but wants me to define an op to use the |+| operator. Why can't the definition of the |+| use combine?
Denis Rosset
@denisrosset
@vinayakpathak Spire depends on algebra, which depends on cats-kernel, so Spire's Eq is cats Eq.
Normally AbGroup is a synonym for cats-kernel CommutativeGroup, and what you need to define is combine. Do you have an example where op is required? (That may be a syntax bug in a macro)
Vlad1Badilovskii
@Vlad1Badilovskii
hello everyone, can spire do something like that? NormalDistribution.cumulativeProbability(x.toDouble)
I really need this normalization
but Gaussian from spire didn't help or I don`t know how to use it
NormalDistribution by apache
Denis Rosset
@denisrosset
Wow, I have no idea about the statistics part of Spire
Is there somebody that can help?
jeremyrsmith
@jeremyrsmith
I think the Dist in spire just supports drawing, plus algebraic structures over distributions. I don’t think it supports actual statistics stuff. You might want to look at breeze for that https://github.com/scalanlp/breeze/blob/master/math/src/main/scala/breeze/stats/distributions/Gaussian.scala#L67
Paul Snively
@paul-snively
Hi everyone! How concerned should I be that Spire 0.16.1 apparently uses cats-kernel 2.0.0-M1 if I also want to depend on fs2 1.0.5, which transitively brings in the 2.0.0 final world?
Ghost
@ghost~529c6cf4ed5ab0b3bf04da61
unless you depend on the laws, this should be fine – the rest is binary compatible
Paul Snively
@paul-snively
That’s what I thought. Thanks!
Ionuț G. Stan
@igstan
Folks, is there a way built-in conversion from scala.math.Ordering to spire's Order? I know there is one in the other direction via spire.compat.ordering.
Denis Rosset
@denisrosset
Converting an Ordering to an Order would defeat optimizations in Spire's Order related to specialization.
Denis Rosset
@denisrosset
To my knowledge there is no such conversion provided (I quickly searched through the spire repo)
Thijs
@ThijsBroersen
I started exploring the rng-types of Spire and how the seeding functions. I would expect seeding functions to be deterministic but spire.random.rng.MersenneTwister64.fromTime is not deterministic as it used longFromTime (why? it is already a long..) and this functions has increments a @volatile private var seedUniquifier. So my only conclusion is that fromTime is not ment as a seeding function, but I do not think this is intuitive.
Denis Rosset
@denisrosset
I haven't used the rng/dist part of Spire; maybe @non or @tixxit could help you with that part of the code.
That's pretty weird indeed, and not well documented. Would you mind adding a comment to that respect, documenting the current weirdness (i.e. the function is not deterministic) and submitting a PR?
moritz bust
@busti
Fun trivia: I have never had a library that made IntelliJ take as much CPU power while hilighting code as spire does lol
Still, it is worth it every step of the way
moritz bust
@busti
When should I use CRing over Ring? Only when commutative multiplication is used, or everywhere?
def +(that: A)(implicit r: Ring[A]): Vec2[A] = Vec2(this.x + that, this.y + that)
def *(that: A)(implicit r: CRing[A]): Vec2[A] = Vec2(this.x * that, this.y * that)
Should I only use CRing in the second function? Or should I just default to CRing everywhere?
moritz bust
@busti
Also, would that mean that I could also use Field everywhere since I am expecting real numbers anyways?
moritz bust
@busti
One more thing before I go to sleep...
How do I use numerical constants? I know that there is Trig[T].pi and so on, but what do I do when I want 0.5?
There must be a better way than doing one / (one + one)
Ghost
@ghost~529c6cf4ed5ab0b3bf04da61
@busti You could try using 1/2 as a Rational and then converting it to your target type
I'm unsure if that notion is captured in a type class somewhere
But perhaps Fractional is what you want?
moritz bust
@busti
@larsrh Thanks, looks like that does what I need.
I have one more question.
How can I make spire work with the @inline annotation?
In our library we heavily rely on inlining since it provides a major performance improvement in scalajs.
val foo = Vec2(2, 3).length is currently defined as @inline def length: Double = x * y and will be inlined by the compiler into val foo = 5 when the annotation is present.
I have not been able to replicate this behavior with the following code using spire:
case class Vec2[@sp(Int, Float, Double) T](x: T, y: T) {
  @inline def length(implicit r: CRing[T]): T = x * y
}
moritz bust
@busti
Sorry, obviously length is defined as (a * a + b * b).sqrt using NRoot[T]
I guess I make mistakes when I am tired
I wanted to write area.
math.sqrt is not optimized to a single value at compile time, it actually calls the javascript native sqrt function.
Curiously, when using spire, it "manually" calculates the square root using a loop.
moritz bust
@busti
I cannot even make this up:
a = (new S).g("Vec2Spec.scala",
    "Please set the environment variable SCALACTIC_FILL_FILE_PATHNAMES to yes at compile time to enable this feature.", 105);
Mo(Ao(this, "length", a), K(function (b) {
    return function () {
        W();
        var c = n(3, 3), d = n(4, 4);
        c = c + d | 0;
        d = (new S).g("Vec2Spec.scala", "Please set the environment variable SCALACTIC_FILL_FILE_PATHNAMES to yes at compile time to enable this feature.", 106);
        var e = J().o;
        V(T(b, c, d, e), 25);
        W();
        W();
        c = n(3, 3);
        d = n(4, 4);
        a:{
            c = c + d | 0;
            var g = 32768;
            d = 0;
            for (; ;) {
                e = d | g;
                var h = +ea.Math.pow(e, 2);
                if (h === c || 0 === g) {
                    c = e;
                    break a
                }
                0 >=
                h || h > c ? g >>= 1 : (g >>= 1, d = e)
            }
        }
        d = (new S).g("Vec2Spec.scala", "Please set the environment variable SCALACTIC_FILL_FILE_PATHNAMES to yes at compile time to enable this feature.", 107);
        e = J().o;
        return V(T(b, c, d, e), 5)
    }
}(this)));
For comparasion, this is the generated code when not using spire:
a = (new P).f("Vec2Spec.scala", "Please set the environment variable SCALACTIC_FILL_FILE_PATHNAMES to yes at compile time to enable this feature.", 102);
yn(mn(this, "length", a), G(function (b) {
    return function () {
        var c = (new P).f("Vec2Spec.scala", "Please set the environment variable SCALACTIC_FILL_FILE_PATHNAMES to yes at compile time to enable this feature.", 103),
            d = D().n;
        T(R(b, 25, c, d), 25);
        c = +ba.Math.sqrt(25);
        d = (new P).f("Vec2Spec.scala", "Please set the environment variable SCALACTIC_FILL_FILE_PATHNAMES to yes at compile time to enable this feature.",
            104);
        var e = D().n;
        return T(R(b, c, d, e), 5)
    }
}(this)));
moritz bust
@busti
Maybe there is also something that goes wrong in the closure optimization step.
Because the fastopt code uses Math.sqrt
Denis Rosset
@denisrosset
A few things: it seems you are using the NRoot[Int] instance, which indeed is implemented using a loop. I don't know why it's that.
There is indeed a java.lang.Math.sqrt function, but only for double types, and indeed that's what the NRoot[Double] instance uses.
Regarding Ring vs CRing: there are no additional methods on the CRing trait compared to Ring. The trait CRing simply expresses that x*y == y*x which may be used in code to perform additional optimization.
It's always a good idea to use the most general (or basic) typeclass that the implemented algorithm requires, as it extends the applicability of generic code.
Now, the examples of Ring[A] that are not CRing[A] are quite academic. I'm using them in my research -- in quantum physics, variables do not commute; but I'd be hard pressed to find simple examples of that. Long story short: use CRing[A], or even, if you're just adding, use AdditiveCSemigroup[A] which provides just the + operator. Same story for MultiplicativeCSemigroup[A] etc
Denis Rosset
@denisrosset
In this library: https://github.com/denisrosset/scalin I've tried to implement linear algebra using the minimal typeclasses for each operation
Final word: NRoot[Int] should not really be a thing, as there are integers that do not have an integer square root, and thus rounding is involved. But NRoot doesn't specify what rounding should be in that case, and thus the instance is not really principled. It may disappear in the future.
(At that time, if you want to bring back the non-principled behaviour, just provide the integer NRoot instances yourself)