swift-numerics icon indicating copy to clipboard operation
swift-numerics copied to clipboard

BFloat16

Open ivarflakstad opened this issue 1 year ago • 3 comments
trafficstars

Hi there! I’ve implemented bfloat in swift over here.

If you want to I am open to having it be part of numerics. If so lmk what changes would be needed to include it :)

Any feedback you have is very welcome ☺️

ivarflakstad avatar May 25 '24 18:05 ivarflakstad

Tagging you @stephentyrone since you're active in the repo, it's been a little while, and I don't know if anyone has seen this :)

ivarflakstad avatar Jul 20 '24 07:07 ivarflakstad

I've had a look out of curiosity (I'm not a project member here), and I've found a few points:

  1. ExpressibleByIntegerLiteral should not be used to supply bit masks. It should produce the same BFloat16 value for e.g. 8 as for 8.0.
  2. Having functions named fromFloat(_) and toFloat() isn't idiomatic Swift code. It's probably better to change the latter to a getter named float.
  3. On that note, it's surprising to me that fromFloat(_) and init(_ value: Float) do different things. I would expect only the initializer to exist.

And some tiny suggestions:

  1. BFloat16 could have a no-argument constructor that produces a zero value.
  2. Add conformance to the Sendable protocol.
  3. There could be an extension to the Float type that adds a constructor taking a BFloat16 parameter.

x-sheep avatar Apr 17 '25 09:04 x-sheep

Thank you so much for the detailed feedback! As you probably saw in the repo description this is my first time writing any swift so I really need any feedback and critique you have to offer ;)

I'll go through your points, make a PR, and add you for a review if you're up for it? ☺️ (May take a while until I have time to do it)

ivarflakstad avatar Apr 17 '25 12:04 ivarflakstad