std::complex support

31 views
Skip to first unread message

Ben Shiffman

unread,
Apr 12, 2024, 7:05:09 PM4/12/24
to javacpp
Hi all,

I'm new to this forum, but a frequent user and novice contributor to JavaCPP.

JavaCPP is essential to a project I'm currently working on, and to improve its efficacy, I have made some significant improvements on a local branch to add support for std::complex<double> and std::complex<float>. I would like to probe for ideas, concerns, and advice regarding the implementation.

My implementation adds ComplexDouble/Float and ComplexDouble/FloatPointer classes for value and pointerTypes. I have been able to wrap my project using this new local version without any issues and am currently in the testing phase. I haven't verified yet that it is memory-safe, but I believe I have a solid understanding of the Generator and drew inspiration from how double(*,[]) and String types are handled.

In the coming weeks I will be verifying with my company if there any intellectual property-related issues with pushing my changes to the Github repo. Until then, any high-level feedback would be greatly appreciated.

Cheers,

Ben Shiffman

Samuel Audet

unread,
Apr 13, 2024, 4:26:15 AM4/13/24
to javacpp
Hi,

Sounds like something useful, sure! The ComplexFloatPointer and ComplexDoublePointer should suffice to model the values as well though. They would essentially be wrapping std::complex. That should work, right?

Samuel 

--
You received this message because you are subscribed to the Google Groups "javacpp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacpp-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/javacpp-project/512e501f-88b3-47fa-99cc-0c28040d1d25n%40googlegroups.com.

Ben Shiffman

unread,
Apr 13, 2024, 1:42:02 PM4/13/24
to javacpp
That's definitely a way to go about it, but differentiation between the Complex(type) and Complex(type)Pointer classes allows a couple extra benefits. We open up the use of Complex(type)[] arrays as well as variable-length arguments. The convenience of being able to treat a complex value as a pointer type and a more primitive type allows more comparable functionality across the different types that our library supports. It's also nice to have a way to implicitly show the user that only a single value is accepted or returned from a function, since the Pointer types can hold dynamic arrays.

Samuel Audet

unread,
Apr 13, 2024, 7:31:49 PM4/13/24
to javacpp
I understand, but I don't want to make that the responsibility of JavaCPP. The idea of "value type" is when we have a type in Java whose representation in memory matches exactly with C++. It's not possible to do that in the case of complex types or any other custom type in Java. In will become possible with Valhalla though, so if this is something you'd like to work on...

Ben Shiffman

unread,
Apr 13, 2024, 10:42:34 PM4/13/24
to javacpp
I see what you mean now. My implementation of those pseudo-value types do have memory overhead which I agree is something that shouldn't be included with JavaCPP. I'm still interested in contributing the pointer-type additions if I can.

I'm somewhat embarrassed as a Java dev (albeit a green one) that I wasn't aware of Valhalla. Will be reading up more on this and would be very interested in helping make JavaCPP compatible.

Samuel Audet

unread,
Apr 14, 2024, 8:28:56 AM4/14/24
to javacpp
Sounds good! Let me know when you have an update

Samuel

Reply all
Reply to author
Forward
0 new messages