Title: ostream::operator<< output shows wrong # of values for 2-d array if strides unusual · Issue #57 · ndarray/ndarray · GitHub
Open Graph Title: ostream::operator<< output shows wrong # of values for 2-d array if strides unusual · Issue #57 · ndarray/ndarray
X Title: ostream::operator<< output shows wrong # of values for 2-d array if strides unusual · Issue #57 · ndarray/ndarray
Description: The following sample code produces very odd output to cout using operator<< in the second case (doTranspose == 1): #include
Open Graph Description: The following sample code produces very odd output to cout using operator<< in the second case (doTranspose == 1): #include
X Description: The following sample code produces very odd output to cout using operator<< in the second case (doTranspose == 1): #include <iostream> #include <vector> #include "ndarray.h&q...
Opengraph URL: https://github.com/ndarray/ndarray/issues/57
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ostream::operator\u003c\u003c output shows wrong # of values for 2-d array if strides unusual","articleBody":"The following sample code produces very odd output to cout using `operator\u003c\u003c` in the second case (`doTranspose == 1`):\r\n```\r\n#include \u003ciostream\u003e\r\n#include \u003cvector\u003e\r\n#include \"ndarray.h\"\r\n\r\nint main() {\r\n // include extra values to avoid reading off the end\r\n std::vector\u003cdouble\u003e xvec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};\r\n\r\n int const len = 3;\r\n auto shape1d = ndarray::makeVector(len);\r\n auto strides1d = ndarray::makeVector(1);\r\n // create x = {1, 2, 3} and y = {4, 5, 6}\r\n ndarray::Array\u003cdouble, 1, 1\u003e x = ndarray::external(xvec.data(), shape1d, strides1d);\r\n ndarray::Array\u003cdouble, 1, 1\u003e y = ndarray::external(xvec.data() + len, shape1d, strides1d);\r\n std::cout \u003c\u003c \"x = \" \u003c\u003c x \u003c\u003c std::endl;\r\n std::cout \u003c\u003c \"y = \" \u003c\u003c y \u003c\u003c std::endl;\r\n\r\n for (int doTranspose = 0; doTranspose \u003c 2; ++doTranspose) {\r\n auto xyshape = ndarray::makeVector(2, static_cast\u003cint\u003e(x.getSize\u003c0\u003e()));\r\n std::cout \u003c\u003c \"\\nxyshape = \" \u003c\u003c xyshape \u003c\u003c std::endl;\r\n auto xystrides = ndarray::makeVector(\u0026y[0] - \u0026x[0], static_cast\u003cstd::ptrdiff_t\u003e(1));\r\n if (doTranspose) {\r\n std::cout \u003c\u003c \"transpose xystrides: [[1, 4, 7], [2, 5, 8]]\" \u003c\u003c std::endl;\r\n xystrides[1] = xystrides[0];\r\n xystrides[0] = 1;\r\n } else {\r\n std::cout \u003c\u003c \"normal xystrides: [[1, 2, 3], [4, 5, 6]])\" \u003c\u003c std::endl;\r\n }\r\n std::cout \u003c\u003c \"xystrides = \" \u003c\u003c xystrides \u003c\u003c std::endl;\r\n ndarray::Array\u003cdouble, 2, 1\u003e xy = ndarray::external(x.getData(), xyshape, xystrides);\r\n std::cout \u003c\u003c \"xy.getSize\u003c0\u003e() = \" \u003c\u003c xy.getSize\u003c0\u003e() \u003c\u003c \"; xy.getSize\u003c1\u003e() = \" \u003c\u003c xy.getSize\u003c1\u003e() \u003c\u003c std::endl;\r\n\r\n for (auto row = 0; row \u003c xy.getSize\u003c0\u003e(); ++row) {\r\n for (int col = 0; col \u003c xy.getSize\u003c1\u003e(); ++col) {\r\n std::cout \u003c\u003c \"xy[\" \u003c\u003c row \u003c\u003c \"][\" \u003c\u003c col \u003c\u003c \"] = \" \u003c\u003c xy[row][col] \u003c\u003c std::endl;\r\n }\r\n }\r\n\r\n std::cout \u003c\u003c \"xy = \" \u003c\u003c xy \u003c\u003c std::endl;\r\n }\r\n}\r\n```\r\n\r\nOn my system (clang 8.1.0 on macOS) all output is as expected except the final cout\u003c\u003c, which looks screwy and has far too many values:\r\n```\r\nx = [ 1, 2, 3]\r\ny = [ 4, 5, 6]\r\n\r\nxyshape = (2,3,)\r\nnormal xystrides: [[1, 2, 3], [4, 5, 6]])\r\nxystrides = (3,1,)\r\nxy.getSize\u003c0\u003e() = 2; xy.getSize\u003c1\u003e() = 3\r\nxy[0][0] = 1\r\nxy[0][1] = 2\r\nxy[0][2] = 3\r\nxy[1][0] = 4\r\nxy[1][1] = 5\r\nxy[1][2] = 6\r\nxy = [[ 1, 2, 3], \r\n[ 4, 5, 6]]\r\n\r\nxyshape = (2,3,)\r\ntranspose xystrides: [[1, 4, 7], [2, 5, 8]]\r\nxystrides = (1,3,)\r\nxy.getSize\u003c0\u003e() = 2; xy.getSize\u003c1\u003e() = 3\r\nxy[0][0] = 1\r\nxy[0][1] = 4\r\nxy[0][2] = 7\r\nxy[1][0] = 2\r\nxy[1][1] = 5\r\nxy[1][2] = 8\r\nxy = [[ 1, 2, 3, 4, 5, 6, 7, 8, 9], \r\n[ 2, 3, 4, 5, 6, 7, 8, 9, 10]]\r\n```","author":{"url":"https://github.com/r-owen","@type":"Person","name":"r-owen"},"datePublished":"2017-07-05T20:33:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/57/ndarray/issues/57"}
| 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:8c0410df-6dc6-a4f1-fe5a-a0579b1b6052 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DEF0:C8498:268DDEC:364C420:6970F678 |
| html-safe-nonce | 69b6410f944d62181023ebd31974e3238d032b6bb928ed49d16f973ee43db8c1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUYwOkM4NDk4OjI2OERERUM6MzY0QzQyMDo2OTcwRjY3OCIsInZpc2l0b3JfaWQiOiIxMTIwMzU2MTE1MTQ5ODEzMzY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 87f8286c9f6e185b9dc34eebcf2d9bec8c14eb65b887714fa16c2ef38a8c9c6c |
| hovercard-subject-tag | issue:240768011 |
| 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/57/issue_layout |
| twitter:image | https://opengraph.githubassets.com/96d4590973d7f1fb66f0d663c3f52154914b764c79f4a7e2150adb4ff09daf03/ndarray/ndarray/issues/57 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/96d4590973d7f1fb66f0d663c3f52154914b764c79f4a7e2150adb4ff09daf03/ndarray/ndarray/issues/57 |
| og:image:alt | The following sample code produces very odd output to cout using operator<< in the second case (doTranspose == 1): #include |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | r-owen |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1b239ebed690c3053869ff31a3b7597834c25673659d63e7b6fd6a9b5d7853de |
| 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 | aeacfd55297f3de5395c83f200ac35d1f474115e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width