我试图从C++到golang获得一系列张量流盒预测,但无论我做什么,我都无法做到这一点。我有一个GO程序,它调用一个函数,该函数使用cgo在C++中执行张量流检测。这一切都有效,我能够在C++中得到预测。问题是将这些预测转换为GO作为100个结构的数组,每个结构包含一个预测。
我可以在GO中设置一个指针,并使用此指针地址在C++中设置一个结构。下面显示了此代码。
我想在 C++ 中设置一个结构数组,并在 GO 中检索此数组。我认为使用与之前相同的指针地址并将其用作我的C++数组的地址应该很容易。然后,我可以从 GO 中的指针还原结构。有没有人对此有解决方案?
去
type PredictResult struct {
Loc [4]float32
Score int
Label int
}
var predictions PredictResult
predictions_ptr := unsafe.Pointer(&predictions)
C.LIB_predict(predictions_ptr)
fmt.Println("GO predictions; ", predictions)
桥
struct PredictResult{
float Loc[4];
int64_t Score;
int64_t Label;
};
void LIB_predict(void* predictions);
桥.cpp
void LIB_predict(void* predictions){
PredictResult *p = (PredictResult*)predictions;
p->Score = 6;
p->Label = 95;
}
指纹:
GO predictions; {[0 0 0 0] 6 95}
慕容708150
largeQ
相关分类