scalanlp / breeze

Breeze is a numerical processing library for Scala.
www.scalanlp.org
Apache License 2.0
3.44k stars 692 forks source link

Units of Measure #196

Open ktakagaki opened 10 years ago

ktakagaki commented 10 years ago

discussion continued from: https://github.com/scalanlp/breeze/pull/193

Here is a list of some of the projects I found...

And a lot more... some of the simple systems just have multiplication factors, but I don't see how that works vis-a-vis eg Fahrenheit und Celcius...

Discussions

dlwh commented 10 years ago

I like https://github.com/soc/scalax-units, https://github.com/zzorn/ScalaQuantity, https://github.com/KarolS/units in the order.

I strongly dislike the dynamic typing in frins.

ktakagaki commented 10 years ago

OK, so we can try to see how it goes with scalax-units then, perhaps it works well with Spire integration. Or ScalaQuantity. I really don't like the syntax for the last one.

I didn't know the 'symbol syntax, and so I missed that the frins package had dynamic typing... and you don't like it because we're trying to have everything resolve at compile time, right?

ktakagaki commented 10 years ago

Hi @soc, (cc @dlwh)

We've been discussing a framework for units for the package breeze (we = David @dlwh, the maintainer of breeze and Kenta Takagaki @ktakagaki). Your package scalax-units seems to fit best as a basis to work from.

breeze already depends on spire, so I think it would just be a matter of incorporating your work, and adding:

  1. some more non-standard unit methods to implicit class scalax.units.QuantityConstructor, and
  2. adding a conversion function to scalax.units.Quantity (?scalax.Quantity.in()?), so that you can do conversions like (1 F) in k or (3 yard) in mile.

I have two questions:

  1. You haven't specified a license for scalax-units, would you be able to make it something compatible with Apache 2?
  2. Would you by any chance be interested in integrating your code into breeze?

Thanks for the great work. I'm a Scala newbie, and reading through your project was very educational!

Sincerely, Kenta Takagaki @ktakagaki

soc commented 10 years ago

Hi @ktakagaki, @dlwh!

Would you by any chance be interested in integrating your code into breeze?

Sounds like a nice idea! (Although it might make sense to make sure that it still can be used independently, without requiring any breeze dependencies, for those existing 0.2341 users of scalax-units :-D)

You haven't specified a license for scalax-units, would you be able to make it something compatible with Apache 2?

Thanks for the hint regarding the license! It's BSD-licensed, see here: http://svn.assembla.com/svn/metascala/license.txt I'll add the LICENSE file to the repo, as soon as I'm at my workstation again.

Regarding additional conversions ... I have taken the stance to not support non-standard units to encourage people to use standard units consistently, instead of sprinkling conversions all over the place. Feel free to disagree with that ... what conversions do you have in mind?

Thanks for the great work. I'm a Scala newbie, and reading through your project was very educational!

Please note that most of the code is taken mostly verbatim from the original author of metascala, Jesper Nordenberg!

Regarding the status of the project: It's working quite nicely, but here are some potential caveats: https://github.com/soc/scalax-units/blob/master/src/test/scala/scalax/example/UnitExample.scala

Additionally, the question of equality is probably the biggest issue: Because the type information is erased, we have no way to tell 1 m apart from 1 s. Maybe the sanest thing would be to always throw an UnsupportedOperationException which tells people to use a typesafe === method instead.

My stance regarding the project as a whole was to wait and see what macros bring to the table and then review all available options again.

Bye, Simon

dlwh commented 10 years ago

this seems like a winner: https://github.com/garyKeorkunian/squants

ktakagaki commented 10 years ago

It does, I like the syntax a lot too. In particular I was wondering how to handle C <=> F temperature given that zero is not absolute zero, and none of the others seem to get it right, but he has it elegantly sorted out.

It looks like it is ready to use without much modification, except for perhaps adding UFunc mapping and basic arithmetic for DenseVector/DenseMatrix, some default changes (default should be SI units in breeze, I would say), and eliminating some redundancy with the units stuff I put in (eg. SI prefixes).

So then, how would this work?

(A) I guess I can just try to pull the whole thing into a breeze.units and modify as above?

(B) Depend on it and create a scala.Predef type of wrapper for units?

(C) We could also just provide a link in the wiki/documentation and say to use the package itself, and provide something importable to use it on DenseVector/DenseMatrix

dlwh commented 10 years ago

We probably can just depend on it and add Semiring/Ring/Field instances for the types as necessary. Basically option (B), I think.

I'd only want to do (A) if it's not being actively developed, which doesn't seem to be the case here.