additional math operations #64

Closed
opened 2020-07-17 10:03:37 +08:00 by sb10q · 7 comments
Owner
https://github.com/m-labs/artiq/issues/1485
sb10q added the
priority:medium
label 2020-07-17 10:03:37 +08:00
Collaborator

Contract items:

  • 3.2.1 natural logarithm (base e) of a floating point number
  • 3.2.2 logarithm (base 10) of a floating point number
  • 3.2.3 base e exponentiation: ex, where x is a floating point number
  • 3.2.4 exponentiation: xy, where x is a floating point number, for both the case where y is an integer and the case where y is a floating point number
  • 3.2.5 sine of a floating point number
  • 3.2.6 cosine of a floating point number
  • 3.2.7 tangent of a floating point number
  • 3.2.8 arcsine of a floating point number
  • 3.2.9 arccosine of a floating point number
  • 3.2.10 arctangent of a floating point number
  • 3.2.11 matrix addition for 1D or 2D matrices of the same dimensions
  • 3.2.12 matrix subtraction for 1D or 2D matrices of the same dimensions
  • 3.2.13 matrix multiplication of an N x M matrix with an M x P matrix to produce an N x P matrix, where N, M, and P are positive integers (can be 1). This covers the case of multiplication of matrices, vectors, and combinations of matrices and vectors.
  • 3.2.14 multiplication of a 1D or 2D matrix by a scalar of the same type as the matrix
  • 3.2.15 transpose of a 1D or 2D matrix
  • 3.2.16 determinant of a square 2D matrix
  • 3.2.17 perform any of the mathematical functions 3.2.1 – 3.2.10 on a 1D or 2D matrix of floating point numbers, element-wise. For operation 3.2.4, the matrix elements can be either the base (x) or the exponent (y) in the operation.
  • 3.2.18 cast all elements of a matrix to floating point numbers
  • 3.2.19 cast all elements of a matrix to integers

  • Decide on/expose user-facing API for casting.
  • Provide core-device libm functions necessary for the above.

Missing features and limitations not explicitly mentioned in #1485 that are probably just about necessary for real-world use:

  • Embedding of host values
  • RPCs
  • array() from other TArrays
  • Decide whether to always expand all iterables in array() (i.e. assume them to be rectangular)
  • Multi-dimensional indexing
  • core_log for multidimensional arrays (or just don't support)
  • Reshaping (as vec.T is the same 1D vec in NumPy)
  • Throw range/domain errors? (log, asin, ... just return NaN in NumPy, but check all) They seem to just generate RuntimeWarnings and return NaN (the latter of which we do already).
  • Fix numpy.full

Nice-to-haves:

  • arctan2 (which is almost always what one really wants) and other binary libm functions
  • Expose Bessel functions/... available from libm from their respective SciPy symbols
  • Add more array constructors ({empty, zeros, ones}[_like])
  • Basic support for comparing arrays and associated bool array handling:
  • Array comparison (or cleanly forbid)
  • all/any
  • Negation of bool ararys

Tests to add:

  • Array shape mismatch in binops
  • Full feature coverage, comparing kernel/host
  • String element types (shouldn't be expanded)
  • Explicit dtypes
  • numpy.float()
  • Assigning binops
Contract items: - [x] 3.2.1 natural logarithm (base e) of a floating point number - [x] 3.2.2 logarithm (base 10) of a floating point number - [x] 3.2.3 base e exponentiation: ex, where x is a floating point number - [x] 3.2.4 exponentiation: xy, where x is a floating point number, for both the case where y is an integer and the case where y is a floating point number - [x] 3.2.5 sine of a floating point number - [x] 3.2.6 cosine of a floating point number - [x] 3.2.7 tangent of a floating point number - [x] 3.2.8 arcsine of a floating point number - [x] 3.2.9 arccosine of a floating point number - [x] 3.2.10 arctangent of a floating point number - [x] 3.2.11 matrix addition for 1D or 2D matrices of the same dimensions - [x] 3.2.12 matrix subtraction for 1D or 2D matrices of the same dimensions - [x] 3.2.13 matrix multiplication of an N x M matrix with an M x P matrix to produce an N x P matrix, where N, M, and P are positive integers (can be 1). This covers the case of multiplication of matrices, vectors, and combinations of matrices and vectors. - [x] 3.2.14 multiplication of a 1D or 2D matrix by a scalar of the same type as the matrix - [x] 3.2.15 transpose of a 1D or 2D matrix - <del>[ ] 3.2.16 determinant of a square 2D matrix</del> - [x] 3.2.17 perform any of the mathematical functions 3.2.1 – 3.2.10 on a 1D or 2D matrix of floating point numbers, element-wise. For operation 3.2.4, the matrix elements can be either the base (x) or the exponent (y) in the operation. - [x] 3.2.18 cast all elements of a matrix to floating point numbers - [x] 3.2.19 cast all elements of a matrix to integers --- - [x] Decide on/expose user-facing API for casting. - [x] Provide core-device libm functions necessary for the above. --- Missing features and limitations not explicitly mentioned in #1485 that are probably just about necessary for real-world use: - [x] Embedding of host values - [x] RPCs - [x] array() from other TArrays - [x] Decide whether to always expand all iterables in `array()` (i.e. assume them to be rectangular) - [x] Multi-dimensional indexing - [x] core_log for multidimensional arrays (or just don't support) - [ ] Reshaping (as vec.T is the same 1D vec in NumPy) - [x] <del>Throw range/domain errors? (log, asin, ... just return NaN in NumPy, but check all)</del> They seem to just generate RuntimeWarnings and return NaN (the latter of which we do already). - [x] Fix `numpy.full` --- Nice-to-haves: - [x] arctan2 (which is almost always what one really wants) and other binary libm functions - [x] Expose Bessel functions/... available from libm from their respective SciPy symbols - [ ] Add more array constructors (`{empty, zeros, ones}[_like]`) - Basic support for comparing arrays and associated bool array handling: - [ ] Array comparison (or cleanly forbid) - [ ] all/any - [ ] Negation of bool ararys --- Tests to add: - [ ] Array shape mismatch in binops - [x] Full feature coverage, comparing kernel/host - [x] String element types (shouldn't be expanded) - [ ] Explicit dtypes - [ ] `numpy.float()` - [x] Assigning binops
Contributor

If we want to support faster math operations on slices, maybe we can have a look at NEON optimized math libraries like Ne10 later. SIMD really improves the performance by a lot if we need to perform operations on large arrays.

One problem with the Ne10 library is that it seems to be dead for 2 years. Other libraries seems to target AArch64 instead of Cortex-A devices.

If we want to support faster math operations on slices, maybe we can have a look at NEON optimized math libraries like [Ne10](https://github.com/projectNe10/Ne10) later. SIMD really improves the performance by a lot if we need to perform operations on large arrays. One problem with the Ne10 library is that it seems to be dead for 2 years. Other libraries seems to target AArch64 instead of Cortex-A devices.
Author
Owner

Other libraries seems to target AArch64 instead of Cortex-A devices.

If we have Zynq Ultrascale+ devices at some point, we could use those.

> Other libraries seems to target AArch64 instead of Cortex-A devices. If we have Zynq Ultrascale+ devices at some point, we could use those.
Collaborator

The LLVM autovectorizer should handle array operations quite nicely – we might need to enable a higher optimization level (and possibly switch to a newer LLVM), though.

The LLVM autovectorizer should handle array operations quite nicely – we might need to enable a higher optimization level (and possibly switch to a newer LLVM), though.
Collaborator

core_log will simply log things row by row, i.e. as array([array([…]), …]), which is imho acceptable, given how rare that use case will actually be in practice. Just wanted to make sure it doesn't crash and burn. Also covered by the test suite already.

`core_log` will simply log things row by row, i.e. as `array([array([…]), …])`, which is imho acceptable, given how rare that use case will actually be in practice. Just wanted to make sure it doesn't crash and burn. Also covered by the test suite already.
Author
Owner

@dpn Is there still more to be done here or should we close this issue?

@dpn Is there still more to be done here or should we close this issue?
Collaborator

Opened #122, #123, #124, #125 for the remaining features. (These are not on the contract, but potentially quite useful, at least for writing tests.)

Opened #122, #123, #124, #125 for the remaining features. (These are not on the contract, but potentially quite useful, at least for writing tests.)
dpn closed this issue 2021-01-20 06:35:04 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/artiq-zynq#64
No description provided.