python - 用 C++ 编写的函数在 python 中重载 + 运算符
问题描述
是否可以使用 Python C API 重载 pythons + 运算符。
例如,如果我在 python 中运行此代码:
C = A+B
我希望能够调用这个用 C++ 编写的函数
template<typename T>
QSMatrix<T> QSMatrix<T>::operator+(const QSMatrix<T>& rhs) {
QSMatrix result(rows, cols, 0.0);
for (unsigned i=0; i<rows; i++) {
for (unsigned j=0; j<cols; j++) {
result(i,j) = this->mat[i][j] + rhs(i,j);
}
}
return result;}
这样做可能吗?
解决方案
推荐阅读
- sql - 存储过程 ora-06550 和 ora-00905
- c++ - 捕获屏幕的错误部分
- swift - init(staff: String...) 在 Swift 中是什么意思?
- javascript - Webpack 无法解析 Windows 上的 core-js 路径
- python - 如何将空格分隔列表转换为由 chunksize 生成的“TextFileReader 对象”
- sql - 根据其他列选择值
- python - 找到具有 0 个特征的数组(形状 = (2794,0)),而 check_pair_arrays 需要至少 1 个
- python - 运行代码时,Raspberry Pi Flask 服务器无法处理 SQLite 数据
- python - 如何在 Windows 中添加 pydub(最后是 ffmpeg)和 python 路径?
- swiftui - SwiftUI textFieldStyle 修饰符 RoundedBorderTextFieldStyle 和 PlainTextFieldStyle 之间的类型不匹配