[BUG]: Eigen::SparseMatrix -> unexpected overload-resolution / template-instantiation
Los mantenedores suelen responder en 4 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
Línea de trabajo
Comienza con el ejemplo reproducible enlazado y el comportamiento mostrado en tests/test_basic.py. Compara los registros de sobrecargas Dense y Sparse de Eigen, incluidos los casos RowMajor y ColMajor, y rastrea por qué la llamada Sparse informa bool en lugar de float. Se considera terminado cuando el dispatch de la sobrecarga Sparse conserva el tipo escalar de entrada y una prueba de regresión cubre los casos indicados.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
723307283ed7dc03c901fba1da1127c7b16a4a0d
Problem description
I'm trying to wrap dense as well as sparse-matrices (py -> c++): specifically
Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic>Eigen::SparseMatrix<T, Eigen::RowMajor>Eigen::SparseMatrix<T, Eigen::ColMajor>
Having tried two approaches, one being based on EigenBase<Derived>, the other being based on splitting the target functions into a dense and a sparse variant (as shown in example).
In both cases, something unexpected is happening to the type in the sparse-case while the dense case works as expected.
tests/test_basic.py
Dense matrix @ python
[[1. 2. 3. 4.]
[5. 6. 7. 8.]]
float32
Sparse matrix @ python
(0, 0) 1.0
(0, 1) 2.0
(0, 2) 3.0
(0, 3) 4.0
(1, 0) 5.0
(1, 1) 6.0
(1, 2) 7.0
(1, 3) 8.0
float32
CALL instantiation -> with dense => c++ receives type?
Dense overload
float
CALL instantiation -> with sparse => c++ receives type?
Sparse overload
bool ??? WHY ???
Reproducible example: https://github.com/sschnug/cmake_example/tree/eigen_sparse_matrix_overload_issue_example
Reproducible example code
See: https://github.com/sschnug/cmake_example/tree/eigen_sparse_matrix_overload_issue_example
But basically:
// OKAY BEHAVIOUR -> dense
template <typename ScalarT>
static void take_matrix(const Eigen::Array<ScalarT, Eigen::Dynamic, Eigen::Dynamic> matrix_in) {
std::cout << "Dense overload" << std::endl;
if constexpr(std::is_same_v<ScalarT, float>) {
std::cout << "float" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, double>) {
std::cout << "double" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, bool>) {
std::cout << "bool" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, int8_t>) {
std::cout << "int8_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, int16_t>) {
std::cout << "int16_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, int32_t>) {
std::cout << "int32_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, int64_t>) {
std::cout << "int64_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, uint8_t>) {
std::cout << "uint8_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, uint16_t>) {
std::cout << "uint16_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, uint32_t>) {
std::cout << "uint32_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, uint64_t>) {
std::cout << "uint64_t" << std::endl;
}
else
std::cout << "some other type" << std::endl;
}
// NOT OKAY BEHAVIOUR -> sparse
template<typename ScalarT, int Options>
static void take_matrix(const Eigen::SparseMatrix<ScalarT, Options> matrix_in) {
std::cout << "Sparse overload" << std::endl;
if constexpr(std::is_same_v<ScalarT, float>) {
std::cout << "float" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, double>) {
std::cout << "double" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, bool>) {
std::cout << "bool" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, int8_t>) {
std::cout << "int8_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, int16_t>) {
std::cout << "int16_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, int32_t>) {
std::cout << "int32_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, int64_t>) {
std::cout << "int64_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, uint8_t>) {
std::cout << "uint8_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, uint16_t>) {
std::cout << "uint16_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, uint32_t>) {
std::cout << "uint32_t" << std::endl;
}
else if constexpr(std::is_same_v<ScalarT, uint64_t>) {
std::cout << "uint64_t" << std::endl;
}
else
std::cout << "some other type" << std::endl;
}
PYBIND11_MODULE(cmake_example, m) {
// dense
// -----
m.def("take_matrix", &take_matrix<bool>, pybind11::arg("matrix_in").noconvert());
m.def("take_matrix", &take_matrix<float>, pybind11::arg("matrix_in").noconvert());
m.def("take_matrix", &take_matrix<double>, pybind11::arg("matrix_in").noconvert());
// sparse
// ------
m.def("take_matrix", &take_matrix<bool, Eigen::ColMajor>, pybind11::arg("matrix_in").noconvert());
m.def("take_matrix", &take_matrix<bool, Eigen::RowMajor>, pybind11::arg("matrix_in").noconvert());
m.def("take_matrix", &take_matrix<float, Eigen::ColMajor>, pybind11::arg("matrix_in").noconvert());
m.def("take_matrix", &take_matrix<float, Eigen::RowMajor>, pybind11::arg("matrix_in").noconvert());
m.def("take_matrix", &take_matrix<double, Eigen::ColMajor>, pybind11::arg("matrix_in").noconvert());
m.def("take_matrix", &take_matrix<double, Eigen::RowMajor>, pybind11::arg("matrix_in").noconvert());
Is this a regression? Put the last known working version here if it is.
Not a regression
- Lenguaje dominante
- C++
- Estrellas
- 18k
- Forks
- 2.3k
- Merge medio
- 5 d 7 h
- PR fusionados (30 d)
- 53
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pybind/pybind11
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 4 días
-
triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
pybind/pybind11#5604 · 1 comentario ·
Los mantenedores suelen responder en 4 días
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 4 días
-
docs
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
pybind/pybind11#747 · 2 comentarios ·
Los mantenedores suelen responder en 4 días
-
array_t::at() returns a misaligned reference when the stride is not a multiple of alignof(T)Posiblemente ocupada @henryiii la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 4 días
Todos los issues de pybind/pybind11
Issues similares
-
[Bug] Windows Ghidra provider rejects a PATH-only JDK: bare `java.exe` probe fails with Win32 87Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
tenstorrent/tt-umd#4084 ·
Los mantenedores suelen responder en 5 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
ToffelsKater/X4_VR#34 ·
-
difficulty:easy prio:low refactor
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
NatronGitHub/openfx-supportext#220 ·
Los mantenedores suelen responder en 1 día