{"action":"created","comment":{"url":"https://api.github.com/repos/dmlc/mxnet/pulls/comments/44168254","id":44168254,"diff_hunk":"@@ -0,0 +1,252 @@\n+/*!\n+ * Copyright (c) 2015 by Contributors\n+ * \\file swapaxis-inl.h\n+ * \\brief\n+ * \\author Ming Zhang\n+*/\n+#ifndef MXNET_OPERATOR_SWAPAXIS_INL_H_\n+#define MXNET_OPERATOR_SWAPAXIS_INL_H_\n+\n+#include <dmlc/logging.h>\n+#include <dmlc/parameter.h>\n+#include <mxnet/operator.h>\n+#include <algorithm>\n+#include <map>\n+#include <vector>\n+#include <string>\n+#include <utility>\n+#include \"./operator_common.h\"\n+\n+#define SWAPAXIS_DBG 0\n+\n+namespace mxnet {\n+namespace op {\n+\n+struct SwapAxis{\n+enum SwapAxisOpInputs {kData};\n+enum SwapAxisOpOutputs {kOut};\n+};\n+\n+using namespace mshadow;\n+using namespace mshadow::expr;\n+\n+struct SwapAxisParam : public dmlc::Parameter<SwapAxisParam> {\n+  // use int for enumeration\n+  uint32_t dim1, dim2;\n+  DMLC_DECLARE_PARAMETER(SwapAxisParam) {\n+    DMLC_DECLARE_FIELD(dim1)\n+    .set_default(0)\n+    .describe(\"the first axis to be swapped.\");\n+    DMLC_DECLARE_FIELD(dim2)\n+    .set_default(0)\n+    .describe(\"the second axis to be swapped.\");\n+  }\n+};\n+\n+//a1 higher dimension to be swapped, assert a1 > a2\n+//a2 lower dimension to be swapped\n+template<typename xpu>\n+class SwapAxisOp : public Operator {\n+ public:\n+  explicit SwapAxisOp(SwapAxisParam p) {\n+    CHECK_LT(p.dim1, p.dim2) << \"dim1 must be lower than dim2.\";\n+#if SWAPAXIS_DBG\n+    printf(\"hello swapaxis SwapAxisOp:dim1:%d, dim2:%d!\\n\", p.dim1, p.dim2);\n+#endif\n+  \tthis->param_ = p;\n+  }\n+  \n+  \n+  void Reshape2Five(Shape<5> &inter_shape, TShape &shape, uint32_t dim1, uint32_t dim2)\n+  {\n+    int ndim_in = shape.ndim();\n+    int si;\n+    for (si = 0; si < 5; si++)\n+    {\n+      inter_shape[si] = 1;\n+    }\n+    //dim_0\n+    for (si = 0; si < dim1; si++)\n+    {\n+      inter_shape[0] *= shape[si];\n+    }\n+    //dim_1\n+    inter_shape[1] = shape[dim1];\n+    //dim_2\n+    for (si = dim1+1; si < dim2; si++)\n+    {\n+      inter_shape[2] *= shape[si];\n+    }\n+    //dim_3\n+    inter_shape[3] = shape[dim2];\n+    //dim_4\n+    for (si = dim2+1; si < ndim_in; si++)\n+    {\n+      inter_shape[4] *= shape[si];\n+    }\n+  }\n+  \n+  void __swapaxis(Stream<xpu> *s, const std::vector<TBlob> &in_data, const std::vector<TBlob> &out_data)\n+  {\n+    uint32_t dim1 = param_.dim1;\n+    uint32_t dim2 = param_.dim2;\n+    \n+    TBlob data_in = in_data[SwapAxis::kData];\n+    TBlob data_out = out_data[SwapAxis::kData];\n+    \n+    TShape shape_in = data_in.shape_;\n+    TShape shape_out = data_out.shape_;\n+    \n+    Shape<5> inter_shape;\n+    \n+    Reshape2Five(inter_shape, shape_in, dim1, dim2);\n+    \n+    Tensor<xpu, 5> inter_data_in = data_in.get_with_shape<xpu, 5, real_t>(inter_shape, s);\n+    \n+    int dwTmp = 0;\n+    \n+    Shape<5> inter_shape2 = inter_shape;\n+    inter_shape2[1] = inter_shape[3];","path":"src/operator/swapaxis-inl.h","position":109,"original_position":109,"commit_id":"a0ec24dc99360eb65b9001d7d44ad9cc9a024022","original_commit_id":"a0ec24dc99360eb65b9001d7d44ad9cc9a024022","user":{"login":"tqchen","id":2577440,"avatar_url":"https://avatars.githubusercontent.com/u/2577440?v=3","gravatar_id":"","url":"https://api.github.com/users/tqchen","html_url":"https://github.com/tqchen","followers_url":"https://api.github.com/users/tqchen/followers","following_url":"https://api.github.com/users/tqchen/following{/other_user}","gists_url":"https://api.github.com/users/tqchen/gists{/gist_id}","starred_url":"https://api.github.com/users/tqchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tqchen/subscriptions","organizations_url":"https://api.github.com/users/tqchen/orgs","repos_url":"https://api.github.com/users/tqchen/repos","events_url":"https://api.github.com/users/tqchen/events{/privacy}","received_events_url":"https://api.github.com/users/tqchen/received_events","type":"User","site_admin":false},"body":"use std::swap","created_at":"2015-11-06T18:11:01Z","updated_at":"2015-11-06T18:11:01Z","html_url":"https://github.com/dmlc/mxnet/pull/502#discussion_r44168254","pull_request_url":"https://api.github.com/repos/dmlc/mxnet/pulls/502","_links":{"self":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/comments/44168254"},"html":{"href":"https://github.com/dmlc/mxnet/pull/502#discussion_r44168254"},"pull_request":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/502"}}},"pull_request":{"url":"https://api.github.com/repos/dmlc/mxnet/pulls/502","id":49925188,"html_url":"https://github.com/dmlc/mxnet/pull/502","diff_url":"https://github.com/dmlc/mxnet/pull/502.diff","patch_url":"https://github.com/dmlc/mxnet/pull/502.patch","issue_url":"https://api.github.com/repos/dmlc/mxnet/issues/502","number":502,"state":"open","locked":false,"title":"add symbol.SwapAxis operator, just can do Forward().","user":{"login":"starimpact","id":2155428,"avatar_url":"https://avatars.githubusercontent.com/u/2155428?v=3","gravatar_id":"","url":"https://api.github.com/users/starimpact","html_url":"https://github.com/starimpact","followers_url":"https://api.github.com/users/starimpact/followers","following_url":"https://api.github.com/users/starimpact/following{/other_user}","gists_url":"https://api.github.com/users/starimpact/gists{/gist_id}","starred_url":"https://api.github.com/users/starimpact/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/starimpact/subscriptions","organizations_url":"https://api.github.com/users/starimpact/orgs","repos_url":"https://api.github.com/users/starimpact/repos","events_url":"https://api.github.com/users/starimpact/events{/privacy}","received_events_url":"https://api.github.com/users/starimpact/received_events","type":"User","site_admin":false},"body":"this is a early version, can run now, but haven't been tested.\r\nThis is just a look-version, means let you have a look and give me some ideas.","created_at":"2015-11-06T07:53:50Z","updated_at":"2015-11-06T18:11:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dmlc/mxnet/pulls/502/commits","review_comments_url":"https://api.github.com/repos/dmlc/mxnet/pulls/502/comments","review_comment_url":"https://api.github.com/repos/dmlc/mxnet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dmlc/mxnet/issues/502/comments","statuses_url":"https://api.github.com/repos/dmlc/mxnet/statuses/a0ec24dc99360eb65b9001d7d44ad9cc9a024022","head":{"label":"starimpact:master","ref":"master","sha":"a0ec24dc99360eb65b9001d7d44ad9cc9a024022","user":{"login":"starimpact","id":2155428,"avatar_url":"https://avatars.githubusercontent.com/u/2155428?v=3","gravatar_id":"","url":"https://api.github.com/users/starimpact","html_url":"https://github.com/starimpact","followers_url":"https://api.github.com/users/starimpact/followers","following_url":"https://api.github.com/users/starimpact/following{/other_user}","gists_url":"https://api.github.com/users/starimpact/gists{/gist_id}","starred_url":"https://api.github.com/users/starimpact/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/starimpact/subscriptions","organizations_url":"https://api.github.com/users/starimpact/orgs","repos_url":"https://api.github.com/users/starimpact/repos","events_url":"https://api.github.com/users/starimpact/events{/privacy}","received_events_url":"https://api.github.com/users/starimpact/received_events","type":"User","site_admin":false},"repo":{"id":44857673,"name":"mxnet","full_name":"starimpact/mxnet","owner":{"login":"starimpact","id":2155428,"avatar_url":"https://avatars.githubusercontent.com/u/2155428?v=3","gravatar_id":"","url":"https://api.github.com/users/starimpact","html_url":"https://github.com/starimpact","followers_url":"https://api.github.com/users/starimpact/followers","following_url":"https://api.github.com/users/starimpact/following{/other_user}","gists_url":"https://api.github.com/users/starimpact/gists{/gist_id}","starred_url":"https://api.github.com/users/starimpact/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/starimpact/subscriptions","organizations_url":"https://api.github.com/users/starimpact/orgs","repos_url":"https://api.github.com/users/starimpact/repos","events_url":"https://api.github.com/users/starimpact/events{/privacy}","received_events_url":"https://api.github.com/users/starimpact/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/starimpact/mxnet","description":" Efficient and Flexible Distributed Deep Learning Framework, for python, R, Julia and more","fork":true,"url":"https://api.github.com/repos/starimpact/mxnet","forks_url":"https://api.github.com/repos/starimpact/mxnet/forks","keys_url":"https://api.github.com/repos/starimpact/mxnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/starimpact/mxnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/starimpact/mxnet/teams","hooks_url":"https://api.github.com/repos/starimpact/mxnet/hooks","issue_events_url":"https://api.github.com/repos/starimpact/mxnet/issues/events{/number}","events_url":"https://api.github.com/repos/starimpact/mxnet/events","assignees_url":"https://api.github.com/repos/starimpact/mxnet/assignees{/user}","branches_url":"https://api.github.com/repos/starimpact/mxnet/branches{/branch}","tags_url":"https://api.github.com/repos/starimpact/mxnet/tags","blobs_url":"https://api.github.com/repos/starimpact/mxnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/starimpact/mxnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/starimpact/mxnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/starimpact/mxnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/starimpact/mxnet/statuses/{sha}","languages_url":"https://api.github.com/repos/starimpact/mxnet/languages","stargazers_url":"https://api.github.com/repos/starimpact/mxnet/stargazers","contributors_url":"https://api.github.com/repos/starimpact/mxnet/contributors","subscribers_url":"https://api.github.com/repos/starimpact/mxnet/subscribers","subscription_url":"https://api.github.com/repos/starimpact/mxnet/subscription","commits_url":"https://api.github.com/repos/starimpact/mxnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/starimpact/mxnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/starimpact/mxnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/starimpact/mxnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/starimpact/mxnet/contents/{+path}","compare_url":"https://api.github.com/repos/starimpact/mxnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/starimpact/mxnet/merges","archive_url":"https://api.github.com/repos/starimpact/mxnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/starimpact/mxnet/downloads","issues_url":"https://api.github.com/repos/starimpact/mxnet/issues{/number}","pulls_url":"https://api.github.com/repos/starimpact/mxnet/pulls{/number}","milestones_url":"https://api.github.com/repos/starimpact/mxnet/milestones{/number}","notifications_url":"https://api.github.com/repos/starimpact/mxnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/starimpact/mxnet/labels{/name}","releases_url":"https://api.github.com/repos/starimpact/mxnet/releases{/id}","created_at":"2015-10-24T08:03:44Z","updated_at":"2015-10-24T08:03:46Z","pushed_at":"2015-11-06T10:01:28Z","git_url":"git://github.com/starimpact/mxnet.git","ssh_url":"git@github.com:starimpact/mxnet.git","clone_url":"https://github.com/starimpact/mxnet.git","svn_url":"https://github.com/starimpact/mxnet","homepage":"http://mxnet.rtfd.org","size":2669,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dmlc:master","ref":"master","sha":"488feec97163c7851a919b13d895b00ec0f663ff","user":{"login":"dmlc","id":11508361,"avatar_url":"https://avatars.githubusercontent.com/u/11508361?v=3","gravatar_id":"","url":"https://api.github.com/users/dmlc","html_url":"https://github.com/dmlc","followers_url":"https://api.github.com/users/dmlc/followers","following_url":"https://api.github.com/users/dmlc/following{/other_user}","gists_url":"https://api.github.com/users/dmlc/gists{/gist_id}","starred_url":"https://api.github.com/users/dmlc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmlc/subscriptions","organizations_url":"https://api.github.com/users/dmlc/orgs","repos_url":"https://api.github.com/users/dmlc/repos","events_url":"https://api.github.com/users/dmlc/events{/privacy}","received_events_url":"https://api.github.com/users/dmlc/received_events","type":"Organization","site_admin":false},"repo":{"id":34864402,"name":"mxnet","full_name":"dmlc/mxnet","owner":{"login":"dmlc","id":11508361,"avatar_url":"https://avatars.githubusercontent.com/u/11508361?v=3","gravatar_id":"","url":"https://api.github.com/users/dmlc","html_url":"https://github.com/dmlc","followers_url":"https://api.github.com/users/dmlc/followers","following_url":"https://api.github.com/users/dmlc/following{/other_user}","gists_url":"https://api.github.com/users/dmlc/gists{/gist_id}","starred_url":"https://api.github.com/users/dmlc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmlc/subscriptions","organizations_url":"https://api.github.com/users/dmlc/orgs","repos_url":"https://api.github.com/users/dmlc/repos","events_url":"https://api.github.com/users/dmlc/events{/privacy}","received_events_url":"https://api.github.com/users/dmlc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dmlc/mxnet","description":"Lightweight, Efficient and Flexible Distributed Deep Learning, for python, R, Julia, Go and more","fork":false,"url":"https://api.github.com/repos/dmlc/mxnet","forks_url":"https://api.github.com/repos/dmlc/mxnet/forks","keys_url":"https://api.github.com/repos/dmlc/mxnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dmlc/mxnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dmlc/mxnet/teams","hooks_url":"https://api.github.com/repos/dmlc/mxnet/hooks","issue_events_url":"https://api.github.com/repos/dmlc/mxnet/issues/events{/number}","events_url":"https://api.github.com/repos/dmlc/mxnet/events","assignees_url":"https://api.github.com/repos/dmlc/mxnet/assignees{/user}","branches_url":"https://api.github.com/repos/dmlc/mxnet/branches{/branch}","tags_url":"https://api.github.com/repos/dmlc/mxnet/tags","blobs_url":"https://api.github.com/repos/dmlc/mxnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dmlc/mxnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dmlc/mxnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/dmlc/mxnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dmlc/mxnet/statuses/{sha}","languages_url":"https://api.github.com/repos/dmlc/mxnet/languages","stargazers_url":"https://api.github.com/repos/dmlc/mxnet/stargazers","contributors_url":"https://api.github.com/repos/dmlc/mxnet/contributors","subscribers_url":"https://api.github.com/repos/dmlc/mxnet/subscribers","subscription_url":"https://api.github.com/repos/dmlc/mxnet/subscription","commits_url":"https://api.github.com/repos/dmlc/mxnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/dmlc/mxnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/dmlc/mxnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/dmlc/mxnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/dmlc/mxnet/contents/{+path}","compare_url":"https://api.github.com/repos/dmlc/mxnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dmlc/mxnet/merges","archive_url":"https://api.github.com/repos/dmlc/mxnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dmlc/mxnet/downloads","issues_url":"https://api.github.com/repos/dmlc/mxnet/issues{/number}","pulls_url":"https://api.github.com/repos/dmlc/mxnet/pulls{/number}","milestones_url":"https://api.github.com/repos/dmlc/mxnet/milestones{/number}","notifications_url":"https://api.github.com/repos/dmlc/mxnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dmlc/mxnet/labels{/name}","releases_url":"https://api.github.com/repos/dmlc/mxnet/releases{/id}","created_at":"2015-04-30T16:21:15Z","updated_at":"2015-11-06T17:57:47Z","pushed_at":"2015-11-06T18:00:34Z","git_url":"git://github.com/dmlc/mxnet.git","ssh_url":"git@github.com:dmlc/mxnet.git","clone_url":"https://github.com/dmlc/mxnet.git","svn_url":"https://github.com/dmlc/mxnet","homepage":"http://mxnet.rtfd.org","size":7226,"stargazers_count":813,"watchers_count":813,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":239,"mirror_url":null,"open_issues_count":55,"forks":239,"open_issues":55,"watchers":813,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/502"},"html":{"href":"https://github.com/dmlc/mxnet/pull/502"},"issue":{"href":"https://api.github.com/repos/dmlc/mxnet/issues/502"},"comments":{"href":"https://api.github.com/repos/dmlc/mxnet/issues/502/comments"},"review_comments":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/502/comments"},"review_comment":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/502/commits"},"statuses":{"href":"https://api.github.com/repos/dmlc/mxnet/statuses/a0ec24dc99360eb65b9001d7d44ad9cc9a024022"}}}}