Skip to content

Support complex numbers in DLPack - #58

Merged
tqchen merged 6 commits into
dmlc:mainfrom
leofang:complex
Feb 8, 2021
Merged

tqchen merged 6 commits into
dmlc:mainfrom
leofang:complex

Conversation

@leofang

@leofang leofang commented Jan 21, 2021 •

Copy link
Copy Markdown
Collaborator

Close #50.

This PR adds the last missing piece IMHO to DLPack, namely to support complex numbers commonly used in scientific computing and also increasingly in certain machine learning tasks.

As discussed in #50, there seems to be a need to support two different kinds of formats, namely structs of arrays (SoA) and arrays of structs (AoS). The latter (AoS) is the standard choice in C/C++/CUDA/HIP/Python/Numpy/CuPy/etc, so I took the liberty of simply calling it kDLComplex. We haven't converged on naming in #50, though, and I'm open to suggestions 🙂

UPDATE: this PR is merged for supporting AoS (kDLComplex); the support of SoA is to be discussed in #60.

QUESTION: Should I bump the DLPack version in this PR, or we can wait until the actual release?

cc: @rgommers @tqchen @hawkinsp

Comment thread include/dlpack/dlpack.h Outdated
kDLUInt = 1U,
kDLFloat = 2U,
kDLBfloat = 4U,
kDLComplex = 8U, // C/C++/Python layout (compact struct per complex number)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do do not need to assign bitmasking. the number 3U was reserved for opaque handle, we can directly assign 5 here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, changed in b6a64fa. @tqchen What's it for? I don't find it documented anywhere.

Comment thread include/dlpack/dlpack.h Outdated
kDLComplex = 8U, // C/C++/Python layout (compact struct per complex number)
kDLComplexS = 16U, // alternative layout (a struct with two pointers to real & imag arrays)
kDLComplex = 5U, // C/C++/Python layout (compact struct per complex number)
kDLComplexS = 6U, // alternative layout (a struct with two pointers to real & imag arrays)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the Struct of Array is less conventionally defined(we need to define how the layout is, right now seems only well defined for compact array), let us first start with Complex(which is easier to agree on) then discuss the SOA case later.

@leofang leofang Feb 7, 2021 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, @tqchen. This is also what I suggested in #50 🙂 I removed kDLComplexS in 40beada. PTAL.

@leofang

leofang commented Feb 7, 2021

Copy link
Copy Markdown
Collaborator Author

btw @tqchen Should I bump the DLPack version in this PR?

@leofang

leofang commented Feb 8, 2021

Copy link
Copy Markdown
Collaborator Author

@tqchen I noticed there appeared a conflict with the main branch. I just fixed it.

@tqchen
tqchen merged commit 56e6b6c into dmlc:main Feb 8, 2021
@leofang
leofang deleted the complex branch February 8, 2021 14:28
@leofang

leofang commented Feb 8, 2021

Copy link
Copy Markdown
Collaborator Author

Thanks, @tqchen! I still need to know when the DLPack version will be bumped, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support complex numbers in DLPack protocol

2 participants