inconsistent numpy dtype in python and C++
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
提供された dummy.cpp 拡張機能と run_dummpy.py スクリプトを使用して報告を再現し、指定されたバージョンの Python、NumPy、Boost で実行します。2 つの ndarray 引数が Boost.NumPy binding にどのように到達するかを調査し、それぞれが dtype を保持していることを確認します。完了条件は、C++ の出力が一貫して float32 および float64 と一致することです。
索引モデルが issue の本文から書いたものです。
説明
Hi,
I'm trying to use the boost numpy bindings. If I pass two ndarray with different dtype to C++, they don't preserve the correct dtype. Here is a simple example:
dummy.cpp:
#include <iostream>
#include <boost/python.hpp>
#include <boost/python/numpy.hpp>
namespace py = boost::python;
namespace np = boost::python::numpy;
void dummy(np::ndarray const& a, np::ndarray const& b) {
char const* at = py::extract<char const* >(py::str(a.get_dtype()));
char const* bt = py::extract<char const* >(py::str(b.get_dtype()));
std::cout << at << std::endl;
std::cout << bt << std::endl;
}
BOOST_PYTHON_MODULE(dummy) {
Py_Initialize(); // need initialize in BOOST_PYTHON_MODULE, or will get segmentation fault and core dump
np::initialize();
py::def("dummy", dummy);
}
compile
g++ -lboost_python38 -lboost_numpy38 -L$CONDA_PREFIX/lib -I$CONDA_PREFIX/include -I$CONDA_PREFIX/include/python3.8 -fPIC --shared -o dummy.so dummy.cpp
run_dummpy.py
import numpy as np
import dummy
a = np.array([[1, 2, 3], [4, 5, 6]], dtype = np.float32)
print("python", a.dtype)
b = np.array([[1, 2, 3], [4, 5, 6]], dtype = np.double)
print("python", b.dtype)
dummy.dummy(a, b)
The output is inconsistent. The first time I run it by python run_dummy.py it gives
python float32
python float64
__str__
float64
If I re-run it python run_dummy.py , it gives
python float32
python float64
float64
float64
Still not the right output.
I'm using python 3.8.2, numpy 1.18.1, and boost 1.72.0. boost is installed from anaconda conda install -c conda-forge boost
Could you help? Thanks
- 主要言語
- C++
- スター
- 537
- フォーク
- 223
- 平均マージ
- 11時間 22分
- マージ済み PR(30日)
- 2
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
boostorg/python のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
BoostDetectToolset-1.90.0.cmake file not found in an include() call in boost_python-config.cmake オープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
boostorg/python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
objectionary/eo-graphs#74 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
enhancement
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
QuantStack/git2cpp#187 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100