Scaling Quantities by Scalar values #408
benhutchison
started this conversation in
General
Replies: 3 comments 1 reply
|
So I tried defining code: extension [VL, UL] (ql: Quantity[VL, UL])
transparent inline def scale(n: Int)(using tq: coulomb.ops.Mul[VL, UL, Int, 1]): Quantity[tq.VO, tq.UO] =
ql * Quantity[1](n)
transparent inline def scale(n: Double)(using tq: coulomb.ops.Mul[VL, UL, Double, 1]): Quantity[tq.VO, tq.UO] =
ql * Quantity[1](n)compiler error: What caught my eye was But I wasn't able to figure out why compiler had widened the singleton type. It is something Scala is a bit notorious for.. |
0 replies
extension [VL, UL] (ql: Quantity[VL, UL])
transparent inline def scale(n: Int)(using mul: coulomb.ops.Mul[VL, UL, Int, 1]): Quantity[mul.VO, mul.UO] =
mul.eval(ql, Quantity[1](n))
transparent inline def scale(n: Double)(using mul: coulomb.ops.Mul[VL, UL, Double, 1]): Quantity[mul.VO, mul.UO] =
mul.eval(ql, Quantity[1](n))my new heuristic: when defining custom operations that take an implicit operator like |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Is there a way to scale Quantities by a scalar, dimensionless number, without first lifting the scalar into a Quantity?
In my use case, I have a bunch of millisecond timestamps that I want to group/bin depending on which time window they fall into. The time window width is specified by an Int parameter, and I want to scale a base window size by the int multiple.
This seems to be just one example of a common need, to scale/multiply a dimensioned quantity by a dimensionless quantity.
ATM does that require lifting the scalar into a Quantity with unit
1to enable multiply?All reactions