{"action":"created","comment":{"url":"https://api.github.com/repos/dmlc/mxnet/pulls/comments/59778490","id":59778490,"diff_hunk":"@@ -0,0 +1,189 @@\n+/*!\n+ *  Copyright (c) 2015 by Contributors\n+ * \\file broadcast_reduce_op-inl.h\n+ * \\brief Function defintion of broadcast/reduce operators.\n+ */\n+#ifndef MXNET_OPERATOR_BROADCAST_REDUCE_OP_INL_H_\n+#define MXNET_OPERATOR_BROADCAST_REDUCE_OP_INL_H_\n+\n+#include <mxnet/operator_util.h>\n+#include <vector>\n+#include \"./mshadow_op.h\"\n+\n+#if defined(__CUDACC__)\n+#define XPU gpu\n+#else\n+#define XPU cpu\n+#endif\n+\n+namespace mxnet {\n+namespace op {\n+// return a shape of scalar\n+inline TShape ScalarShape(const TShape& ishape,\n+                          const EnvArguments& env) {\n+  mshadow::index_t shape[] = {1};\n+  return TShape(shape, shape + 1);\n+}\n+\n+template<typename xpu>\n+void L2Norm(const TBlob &src,\n+            const EnvArguments& env,\n+            TBlob *ret,\n+            OpReqType req,\n+            RunContext ctx) {\n+  mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();\n+  mshadow::Tensor<xpu, 1> out = ret->get<xpu, 1, real_t>(s);\n+  mshadow::Tensor<xpu, 1> in =\n+      src.get_with_shape<xpu, 1, real_t>(mshadow::Shape1(src.shape_.Size()), s);\n+  mshadow::VectorDot(out, in, in);\n+  out = mshadow::expr::F<mxnet::op::mshadow_op::square_root>(out);\n+}\n+\n+template<typename xpu, typename Reducer>\n+void Reduce(const TBlob &src,\n+            const EnvArguments& env,\n+            TBlob *ret,\n+            OpReqType req,\n+            RunContext ctx) {\n+  mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();\n+  mshadow::Tensor<xpu, 1> out = ret->get<xpu, 1, real_t>(s);\n+  mshadow::Tensor<xpu, 2> in =\n+      src.get_with_shape<xpu, 2, real_t>(mshadow::Shape2(1, src.shape_.Size()), s);\n+  out = mshadow::expr::reduce_except_dim<0, Reducer>(in);\n+}\n+\n+template <typename xpu, typename Reducer>\n+void ReduceMid(TBlob const& src,","path":"src/operator/broadcast_reduce_op-inl.h","position":56,"original_position":56,"commit_id":"df79905b9001347f9d9baf7b7bf0b425bc79cd28","original_commit_id":"df79905b9001347f9d9baf7b7bf0b425bc79cd28","user":{"login":"piiswrong","id":568948,"avatar_url":"https://avatars.githubusercontent.com/u/568948?v=3","gravatar_id":"","url":"https://api.github.com/users/piiswrong","html_url":"https://github.com/piiswrong","followers_url":"https://api.github.com/users/piiswrong/followers","following_url":"https://api.github.com/users/piiswrong/following{/other_user}","gists_url":"https://api.github.com/users/piiswrong/gists{/gist_id}","starred_url":"https://api.github.com/users/piiswrong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/piiswrong/subscriptions","organizations_url":"https://api.github.com/users/piiswrong/orgs","repos_url":"https://api.github.com/users/piiswrong/repos","events_url":"https://api.github.com/users/piiswrong/events{/privacy}","received_events_url":"https://api.github.com/users/piiswrong/received_events","type":"User","site_admin":false},"body":"merge this with the previous one since we have kwargs now?","created_at":"2016-04-14T19:42:20Z","updated_at":"2016-04-14T19:42:20Z","html_url":"https://github.com/dmlc/mxnet/pull/1839#discussion_r59778490","pull_request_url":"https://api.github.com/repos/dmlc/mxnet/pulls/1839","_links":{"self":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/comments/59778490"},"html":{"href":"https://github.com/dmlc/mxnet/pull/1839#discussion_r59778490"},"pull_request":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/1839"}}},"pull_request":{"url":"https://api.github.com/repos/dmlc/mxnet/pulls/1839","id":66269344,"html_url":"https://github.com/dmlc/mxnet/pull/1839","diff_url":"https://github.com/dmlc/mxnet/pull/1839.diff","patch_url":"https://github.com/dmlc/mxnet/pull/1839.patch","issue_url":"https://api.github.com/repos/dmlc/mxnet/issues/1839","number":1839,"state":"open","locked":false,"title":"[Refactor][OP] Add Simple registration mechanism","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":"This PR add simplified operator registration that registers functions into both imperative and symbolic API. This PR ***does not*** change the operator API, instead, it provides a wrapper layer to make registration to the current API easier for some simple functions.\r\n\r\nSee https://github.com/tqchen/mxnet/blob/master/include/mxnet/operator_util.h for the library.\r\nThis is a plugin on top of existing registration API, to register special functions.\r\n\r\nSupported functions\r\n---------------------------\r\n- Unary functions\r\n- Binary functions\r\n- All functions allow additional scalar argument, or keyword argument.\r\n\r\nHow to Use\r\n---------------\r\n- Register a forward function\r\n- Optionally register a gradient function\r\n- Optionally register a shape inference function when shape relation is complicated\r\n\r\nSee https://github.com/tqchen/mxnet/blob/master/src/operator/elementwise_unary_op-inl.h#L83 for examples.\r\n\r\nCurrent Status\r\n-------------------\r\nThis refactor removed old tblob functions to operator_util.h and enhanced it to support more function types. The old implementation of unary functions are moved to operator folder\r\n\r\nGuideline for Next Step\r\n-------------------------------\r\nThese can be in a seperate PR\r\n- The old registration interface remains the same and always works\r\n- When possible, use the simple op interface, which allows one definition for both API.\r\n- Let us also work on migrating some of the old operators to simple op interface.\r\n","created_at":"2016-04-13T05:56:55Z","updated_at":"2016-04-14T19:42:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3c4f65e28f9fe7e41f2bc5382d7e1246fcdb7fa4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dmlc/mxnet/pulls/1839/commits","review_comments_url":"https://api.github.com/repos/dmlc/mxnet/pulls/1839/comments","review_comment_url":"https://api.github.com/repos/dmlc/mxnet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dmlc/mxnet/issues/1839/comments","statuses_url":"https://api.github.com/repos/dmlc/mxnet/statuses/df79905b9001347f9d9baf7b7bf0b425bc79cd28","head":{"label":"tqchen:master","ref":"master","sha":"df79905b9001347f9d9baf7b7bf0b425bc79cd28","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},"repo":{"id":42364986,"name":"mxnet","full_name":"tqchen/mxnet","owner":{"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},"private":false,"html_url":"https://github.com/tqchen/mxnet","description":"An efficient and flexible distributed framework for deep learning","fork":true,"url":"https://api.github.com/repos/tqchen/mxnet","forks_url":"https://api.github.com/repos/tqchen/mxnet/forks","keys_url":"https://api.github.com/repos/tqchen/mxnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tqchen/mxnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tqchen/mxnet/teams","hooks_url":"https://api.github.com/repos/tqchen/mxnet/hooks","issue_events_url":"https://api.github.com/repos/tqchen/mxnet/issues/events{/number}","events_url":"https://api.github.com/repos/tqchen/mxnet/events","assignees_url":"https://api.github.com/repos/tqchen/mxnet/assignees{/user}","branches_url":"https://api.github.com/repos/tqchen/mxnet/branches{/branch}","tags_url":"https://api.github.com/repos/tqchen/mxnet/tags","blobs_url":"https://api.github.com/repos/tqchen/mxnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tqchen/mxnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tqchen/mxnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/tqchen/mxnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tqchen/mxnet/statuses/{sha}","languages_url":"https://api.github.com/repos/tqchen/mxnet/languages","stargazers_url":"https://api.github.com/repos/tqchen/mxnet/stargazers","contributors_url":"https://api.github.com/repos/tqchen/mxnet/contributors","subscribers_url":"https://api.github.com/repos/tqchen/mxnet/subscribers","subscription_url":"https://api.github.com/repos/tqchen/mxnet/subscription","commits_url":"https://api.github.com/repos/tqchen/mxnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/tqchen/mxnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/tqchen/mxnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/tqchen/mxnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/tqchen/mxnet/contents/{+path}","compare_url":"https://api.github.com/repos/tqchen/mxnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tqchen/mxnet/merges","archive_url":"https://api.github.com/repos/tqchen/mxnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tqchen/mxnet/downloads","issues_url":"https://api.github.com/repos/tqchen/mxnet/issues{/number}","pulls_url":"https://api.github.com/repos/tqchen/mxnet/pulls{/number}","milestones_url":"https://api.github.com/repos/tqchen/mxnet/milestones{/number}","notifications_url":"https://api.github.com/repos/tqchen/mxnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tqchen/mxnet/labels{/name}","releases_url":"https://api.github.com/repos/tqchen/mxnet/releases{/id}","deployments_url":"https://api.github.com/repos/tqchen/mxnet/deployments","created_at":"2015-09-12T16:51:54Z","updated_at":"2016-04-13T04:03:32Z","pushed_at":"2016-04-13T05:47:46Z","git_url":"git://github.com/tqchen/mxnet.git","ssh_url":"git@github.com:tqchen/mxnet.git","clone_url":"https://github.com/tqchen/mxnet.git","svn_url":"https://github.com/tqchen/mxnet","homepage":"http://mxnet.rtfd.org","size":6708,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"master"}},"base":{"label":"dmlc:master","ref":"master","sha":"1dced30952e158feb07732dda3383abc1973924b","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, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Go, Javascript 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}","deployments_url":"https://api.github.com/repos/dmlc/mxnet/deployments","created_at":"2015-04-30T16:21:15Z","updated_at":"2016-04-14T15:20:50Z","pushed_at":"2016-04-14T15:02:18Z","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":9484,"stargazers_count":3355,"watchers_count":3355,"language":"Jupyter Notebook","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1156,"mirror_url":null,"open_issues_count":299,"forks":1156,"open_issues":299,"watchers":3355,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/1839"},"html":{"href":"https://github.com/dmlc/mxnet/pull/1839"},"issue":{"href":"https://api.github.com/repos/dmlc/mxnet/issues/1839"},"comments":{"href":"https://api.github.com/repos/dmlc/mxnet/issues/1839/comments"},"review_comments":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/1839/comments"},"review_comment":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dmlc/mxnet/pulls/1839/commits"},"statuses":{"href":"https://api.github.com/repos/dmlc/mxnet/statuses/df79905b9001347f9d9baf7b7bf0b425bc79cd28"}}}}