data-apis / array-api

RFC document, tooling and other content related to the array API standard
https://data-apis.github.io/array-api/latest/
MIT License
214 stars 44 forks source link

RFC: Adding complex number support to the specification #373

Closed kgryte closed 1 year ago

kgryte commented 2 years ago

Complex Number Support

Plan for complex number support in the array API specification.

What follows is a plan for adding complex number support to the 2022 array API specification. This RFC is comprised of the following sections:

Prior Discussions

General Concerns

New APIs

real
conj (complex conjugate)
imag
arg/angle/phase (phase angle)
linalg.eig
linalg.eigvals

Decisions

Creation Functions

arange

asarray

empty

empty_like

eye

from_dlpack

full

full_like

linspace

meshgrid

ones

ones_like

tril

triu

zeros

zeros_like

Data Type Functions

astype

broadcast_arrays

broadcast_to

can_cast

finfo

iinfo

result_type

Data Types

Default Data Types

Data Type Categories

Element-wise Functions

abs

acos

acosh

add

asin

asinh

atan

atan2

atanh

bitwise_and

bitwise_left_shift

bitwise_invert

bitwise_or

bitwise_right_shift

bitwise_xor

ceil

cos

cosh

divide

equal

exp

expm1

floor

floor_divide

greater

greater_equal

isfinite

isinf

isnan

less

less_equal

log

log1p

log2

log10

logaddexp

logical_and

logical_not

logical_or

logical_xor

multiply

negative

not_equal

positive

pow

remainder

round

sign

sin

sinh

square

sqrt

subtract

tan

tanh

trunc

Linear Algebra Functions

matmul

matrix_transpose

tensordot

vecdot

Manipulation Functions

concat

expand_dims

flip

permute_dims

reshape

roll

squeeze

stack

Searching Functions

argmax

argmin

nonzero

where

Set Functions

unique_all

unique_counts

unique_inverse

unique_values

Sorting Functions

argsort

sort

Statistical Functions

max

mean

min

prod

std

sum

var

Type Promotion

Rules

Mixing arrays with Python Scalars

Utility Functions

all

any

Linear Algebra Extension

cholesky

cross

det (determinant)

diagonal

eigh

eigvalsh

inv

matmul

matrix_norm

matrix_power

matrix_rank

matrix_transpose

outer

pinv

qr

slogdet

solve

svd

svdvals

trace

vecdot

vector_norm

honno commented 2 years ago

Would we want a data type function for complex dtypes i.e. cinfo()? Currently NumPy and PyTorch don't have a dedicate method, but complex dtypes can fallback on finfo().

Interestingly there was a little discussion of a torch.cinfo() at https://github.com/pytorch/pytorch/issues/35954#issuecomment-620223025

leofang commented 2 years ago
  • branch cut policy?

I don't know why I missed it... CuPy uses Thrust (and it's likely being used by many other projects that depends on CUDA; IIUC the implementation was ported to libcudacxx) so it's worth mentioning.

Thrust's complex math funcs were based on FreeBSD's. In each FreeBSD man page the branch cut is clearly documented so it's a good starting point. However, as Thrust didn't document it clearly (I asked internally and was told to inspect the source directly, which is challenging given my lack of bandwidth) and it's unclear to me if the Thrust impl was a one-to-one translation of FreeBSD's since I don't have access to the FreeBSD source code, I'd proceed with caution.

kgryte commented 2 years ago

Tracking changes to existing APIs within the array API specification:

New APIs

kgryte commented 1 year ago

At this point, PRs have been submitted for all existing APIs for which we currently expect complex number support.

rgommers commented 1 year ago

All PRs have been merged - adding complex number support to the API is complete. Thanks a lot to everyone who contributed - and in particular @kgryte for all the spec writing.