Replies: 1 comment 2 replies
-
The issue lies in converting Python (Codon) arrays to C++ types. Codon uses numpy arrays and tensors (from PyTorch), which need to be converted to C++ data types. You can't directly assign the Python numpy array or tensor to C++ types. Here’s a techy workaround:
Example: @export
def foo(n: int):
x = np.array([1, 2, 3, 4]) * 10
return x.tolist()
@export
def get_matrix(n: int, m: int):
x = torch.rand(n, m)
return x.numpy().tolist()
You’ll need to adjust your If you're working with tensors, ensure you manage the memory properly and handle the multi-dimensional arrays correctly on the C++ side. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use Codon C++ integration, and I can call codon function in cpp successfully. However, I'm confused how to get the codon function return value in C++ code.
There is a example. I want to get function foo and get_matrix returned array value in C++, but I can't find the conversion from codon array to any C++ type.
Output is wrong.
Hope for answers as soon as possible. 🙏
Beta Was this translation helpful? Give feedback.
All reactions