bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.43k stars 576 forks source link

Multiple pointer types and automatic generation of function overloads #740

Open HGuillemet opened 5 months ago

HGuillemet commented 5 months ago

If we have in C++:

void f(T t);

and:

new Info("T").pointerTypes("T1", "T2");

we generate:

void f(T1 t);
void f(T2 t);

If the function takes 2 arguments:

void f(T t, U u);

with:

new Info("T").pointerTypes("T1", "T2");
new Info("U").pointerTypes("U1", "U2");

we now generate:

void f(T1 t, U1 u);
void f(T2 t, U2 u);

Is this intentional ? Shouldn't we generate all combinations ?

void f(T1 t, U1 u);
void f(T2 t, U1 u);
void f(T1 t, U2 u);
void f(T2 t, U2 u);

For instance in Pytorch, we have function einsum that takes as std::string and a ArrayRef. We used to have 2 java methods, one taking BytePointer and ArrayRef and another String and ArrayRef. But since I added Vector to pointer types for c10::ArrayRef, we now have a java method taking BytePointer and ArrayRef and another taking String and Vector. The overload taking String and ArrayRef is lost, which could break some user code.

saudet commented 5 months ago

If you want to generate more combinations, do something like this:

new Info("T").pointerTypes("T1", "T2", "T1", "T2");
new Info("U").pointerTypes("U1", "U2", "U2", "U1");