dan-fritchman / Hdl21

Hardware Description Library
BSD 3-Clause "New" or "Revised" License
60 stars 13 forks source link

extended prefixed arithmetic to work with other types #170

Closed ThomasPluck closed 11 months ago

ThomasPluck commented 11 months ago

Notice that I couldn't do things like 1 + (1 * UNIT), so I decided to iron everything out so that all Prefixed gets along with other common numerical types, so all operations should work and return the correct Prefixed answer:

Exponent arithmetic could also be improved but I'm not sure exactly when e(3) - 500 = e(2.69897000434) would ever be relevant, if just to have perfectly round corners.

codecov[bot] commented 11 months ago

Codecov Report

Merging #170 (c2d5f3e) into main (5c0daad) will increase coverage by 0.01%. The diff coverage is 95.68%.

@@            Coverage Diff             @@
##             main     #170      +/-   ##
==========================================
+ Coverage   87.20%   87.22%   +0.01%     
==========================================
  Files         109      109              
  Lines        9577     9678     +101     
==========================================
+ Hits         8352     8442      +90     
- Misses       1225     1236      +11     
Files Changed Coverage Δ
hdl21/prefix.py 95.98% <90.00%> (-0.56%) :arrow_down:
hdl21/tests/test_prefix.py 97.53% <100.00%> (-2.47%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

ThomasPluck commented 11 months ago

Fails with error:

[2023-08-17T19:52:47.390Z] ['error'] There was an error running the uploader: Error uploading to [https://codecov.io:](https://codecov.io/) Error: There was an error fetching the storage URL during POST: 404 - {'detail': ErrorDetail(string='Unable to locate build via Github Actions API. Please upload with the Codecov repository upload token to resolve issue.', code='not_found')}
[2023-08-17T19:52:47.391Z] ['verbose'] The error stack is: Error: Error uploading to [https://codecov.io:](https://codecov.io/) Error: There was an error fetching the storage URL during POST: 404 - {'detail': ErrorDetail(string='Unable to locate build via Github Actions API. Please upload with the Codecov repository upload token to resolve issue.', code='not_found')}
    at main (/snapshot/repo/dist/src/index.js)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2023-08-17T19:52:47.391Z] ['verbose'] End of uploader: 2350 milliseconds
Error: Codecov: Failed to properly upload: The process '/__w/_actions/codecov/codecov-action/v3/dist/codecov' failed with exit code 255
ThomasPluck commented 11 months ago

Cool new thing I learnt, you can also do Prefixed linear algebra with numpy for free!

Haha, this might be worth adding to documentation.

>>> np.eye(3)*n @ (np.eye(3)*m + 0.02)

array([[21.00000000000000000000000000*PICO,
        20.00000000000000000000000000*PICO,
        20.00000000000000000000000000*PICO],
       [20.00000000000000000000000000*PICO,
        21.00000000000000000000000000*PICO,
        20.00000000000000000000000000*PICO],
       [20.000000000000000*PICO, 20.000000000000000*PICO,
        21.000000000000000*PICO]], dtype=object)

Edit: numpy arrays are unhashable - so they can't be passed as h.Param's to h.Paramclass's - I get around this by tuple-izing and untuple-izing my arrays, but is there a more elegant solution from a Pydantic standpoint?

dan-fritchman commented 11 months ago

Awesome stuff, merge time!