Title: difference in promotion between py2 and py3 · Issue #41 · ndarray/ndarray · GitHub
Open Graph Title: difference in promotion between py2 and py3 · Issue #41 · ndarray/ndarray
X Title: difference in promotion between py2 and py3 · Issue #41 · ndarray/ndarray
Description: Here's a weird one. I have a histogram class that overloads += operator: bp::class_
Open Graph Description: Here's a weird one. I have a histogram class that overloads += operator: bp::class_
X Description: Here's a weird one. I have a histogram class that overloads += operator: bp::class_<hist_t> ("histogram", bp::init<double,double,double,bool> ( (bp::arg ("min"),...
Opengraph URL: https://github.com/ndarray/ndarray/issues/41
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"difference in promotion between py2 and py3","articleBody":"Here's a weird one. I have a histogram class that overloads += operator:\n\n``` python\n bp::class_\u003chist_t\u003e (\"histogram\", bp::init\u003cdouble,double,double,bool\u003e (\n (bp::arg (\"min\"),\n bp::arg (\"max\"),\n bp::arg (\"delta\"),\n bp::arg (\"clip\")=true\n )))\n .def (bp::init\u003cnd::Array\u003cint64_t,1,1\u003e,double,double,double,bool\u003e())\n .def (bp::self += hist_t::value_type())\n .def (bp::self += nd::Array\u003cdouble,1,0\u003e())\n .def (\"__call__\", \u0026hist_t::operator())\n .def_readwrite (\"results\", \u0026hist_t::buckets)\n .add_property (\"buckets\", \u0026get_buckets\u003chist_t,nd::Array\u003cdouble,1,1\u003e \u003e)\n .def (\"mean\", \u0026hist_t::Mean)\n .def (\"rms\", \u0026hist_t::RMS)\n .def (\"cumulative\", \u0026hist_t::Cumulative\u003cnd::Array\u003cdouble,1,1\u003e \u003e)\n .def (\"inv_cumulative\", \u0026hist_t::OneMinusCumulative\u003cnd::Array\u003cdouble,1,1\u003e \u003e)\n .def_pickle(hist_pickle_suite\u003chist_t\u003e())\n\n .def_readonly (\"min\", \u0026hist_t::min)\n .def_readonly (\"max\", \u0026hist_t::max)\n .def_readonly (\"delta\", \u0026hist_t::delta)\n .add_property (\"rc\", \u0026getrc\u003chist_t\u003e) // just for info\n ;\n```\n\nI call it:\n remod_out_hist += np.sum (np.max (remod_out_cnts, axis=1))\n\nNow if we print out the type (np.sum (np.max ...)) on \npy2: `\u003ctype 'numpy.int64'\u003e`\n\nbut on py3: `\u003cclass 'numpy.int64'\u003e`\n\nWhen run on py2, the type numpy.int64 seems to be promoted to double, which matches the 1st self += (value_type should be double).\n\nBut when run on py3, the promotion fails:\nBoost.Python.ArgumentError: Python argument types in\n histogram.**iadd**(histogram, numpy.int64)\ndid not match C++ signature:\n **iadd**(boost::python::back_reference\u003cHistogram\u003clong, double, ndarray::Array\u003clong, 1, 1\u003e \u003e\u0026\u003e, ndarray::Array\u003cdouble, 1, 0\u003e)\n **iadd**(boost::python::back_reference\u003cHistogram\u003clong, double, ndarray::Array\u003clong, 1, 1\u003e \u003e\u0026\u003e, double)\n\nIf I explicitly write\n remod_out_hist += float(np.sum (np.max (remod_out_cnts, axis=1)))\n\nthen it runs on py3\n\nI'm wondering if the difference in type() on py2 and py3 might explain the different behavior.\n","author":{"url":"https://github.com/nbecker","@type":"Person","name":"nbecker"},"datePublished":"2015-06-11T18:02:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/41/ndarray/issues/41"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f5b7ab3f-f4cc-6dff-d9dd-3711db4c95c8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A846:2FC763:17635B0:20C6530:6970D6BA |
| html-safe-nonce | 35165f02530d471252833aaedfbe4c11ceb02f4ab8924225c177eff7a9488b6c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODQ2OjJGQzc2MzoxNzYzNUIwOjIwQzY1MzA6Njk3MEQ2QkEiLCJ2aXNpdG9yX2lkIjoiMzYwMjIwMjk5NzIwODE3NjMxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 63b6ea5f78094f6a8923a968010ac8dbcff263febf12b946350dafc35f11217b |
| hovercard-subject-tag | issue:87431963 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/ndarray/ndarray/41/issue_layout |
| twitter:image | https://opengraph.githubassets.com/136d2de81747a1e42f98cb26edffa076f195b5519f3c03624525fdfbb925f5b9/ndarray/ndarray/issues/41 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/136d2de81747a1e42f98cb26edffa076f195b5519f3c03624525fdfbb925f5b9/ndarray/ndarray/issues/41 |
| og:image:alt | Here's a weird one. I have a histogram class that overloads += operator: bp::class_ |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nbecker |
| hostname | github.com |
| expected-hostname | github.com |
| None | 034aaee9edccd455c18591b13122193c6e12dc773e8a203be73abe934f3e3a72 |
| turbo-cache-control | no-preview |
| go-import | github.com/ndarray/ndarray git https://github.com/ndarray/ndarray.git |
| octolytics-dimension-user_id | 1451802 |
| octolytics-dimension-user_login | ndarray |
| octolytics-dimension-repository_id | 3487413 |
| octolytics-dimension-repository_nwo | ndarray/ndarray |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3487413 |
| octolytics-dimension-repository_network_root_nwo | ndarray/ndarray |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 52d1d534d0b88c64972e852deb460d09b433b8b2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width