Git Product home page Git Product logo

unitdtype's Introduction

Experimental Unit DType for NumPy

(Please expect that this readme may get outdated, open an issue if it does.)

This currently requires my branch on NumPy (As of 2022-01-26):

https://github.com/seberg/numpy/tree/unit-dtype-extensions

It supports more than my previous prototype and is now in C.

Note that scalars are not really supported, but they will be created. They are currently necessary for printing, and you can create a new array using them. They will also work together with arrays, since they will be coerced to 0-D array (and that works).

Currently, casts within Units and to and from double (if dimensionless!) as well as to boolean (unit is ignored, so offset is also) is supported. The following ufuncs are supported:

  • negative, positive
  • add, subtract
  • multiple, divide
  • matmul
  • fmod
  • hypot (not sure if this is quite right)
  • maximum, minimum, fmax, fmin
  • comparisons (note that we never compare to 0 scalars, unlike some implementations).
  • Logical ufuncs (via casting to boolean)

More are likely to be added and I may not updated the README.

Many functions in NumPy should just work, however, e.g. sorting is not implemented. One caveat is that np.prod is not implemented as this requires some new API to be designed to make work (similar for theoretical generalized ufuncs if they need the number of elements to be worked on to figure out the result dtype).

Example?

import numpy as np; import unitdtype as udt

arr = np.arange(1000.).view(udt.Float64Unit("m"))

new = arr * arr
new_in_cm = new.astype(udt.Float64Unit("cm**2"))

new == new_in_cm  # luckily no rounding :).

unitdtype's People

Contributors

seberg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.