{"action":"created","comment":{"url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/comments/173554183","pull_request_review_id":102772504,"id":173554183,"diff_hunk":"@@ -82,44 +82,141 @@ isl::aff makeIslAffFromInt(isl::space space, int64_t val) {\n   return isl::aff(isl::local_space(space), v);\n }\n \n-isl::aff makeIslAffFromExpr(isl::space space, const Expr& e) {\n+std::vector<isl::aff> makeIslAffBoundsFromExpr(\n+    isl::space space,\n+    const Expr& e,\n+    bool allowMin,\n+    bool allowMax);\n+\n+namespace {\n+/*\n+ * Convert Halide binary expression \"op\" into a list of isl affine functions by\n+ * converting its LHS and RHS into lists of affs and concatenating those lists.\n+ * This is intended to be used with Min/Max operations in upper/lower bound\n+ * computations, respectively.  Essentially, this allows for replacements\n+ *   x < min(a,min(b,c)) <=> x < a AND x < b AND x < c\n+ *   x > max(a,max(b,c)) <=> x > a AND x > b AND x > c\n+ */\n+template <typename T>\n+inline std::vector<isl::aff>\n+concatAffs(isl::space space, T op, bool allowMin, bool allowMax) {\n+  std::vector<isl::aff> result;\n+\n+  for (const auto& aff :\n+       makeIslAffBoundsFromExpr(space, op->a, allowMin, allowMax)) {\n+    result.push_back(aff);\n+  }\n+  for (const auto& aff :\n+       makeIslAffBoundsFromExpr(space, op->b, allowMin, allowMax)) {\n+    result.push_back(aff);\n+  }\n+\n+  return result;\n+}\n+\n+/*\n+ * Convert Halide binary expression \"op\" into an isl affine function by\n+ * converting its LHS and RHS into affs and combining them with \"combine\"\n+ * into a single expression.  LHS and RHS are expected to only produce a single\n+ * expression.\n+ * This is intended for use with operations other than Min/Max that do not\n+ * commute nicely in bounds, for example\n+ *   x < a + max(b,c)  NOT <=>  x < a + b AND x < a + c for negative values.\n+ */\n+template <typename T>\n+inline isl::aff combineSingleAffs(\n+    isl::space space,\n+    T op,\n+    isl::aff (isl::aff::*combine)(isl::aff) const) {\n+  auto left = makeIslAffBoundsFromExpr(space, op->a, false, false);\n+  auto right = makeIslAffBoundsFromExpr(space, op->b, false, false);\n+  CHECK_EQ(left.size(), 1);\n+  CHECK_EQ(right.size(), 1);\n+\n+  return (left[0].*combine)(right[0]);\n+}\n+\n+} // end namespace\n+\n+/*\n+ * Convert Halide expression into list of isl affine expressions usable for\n+ * defining constraints.  In particular, an expression starting with (nested)\n+ * Max operations can be used for lower bounds\n+ *   x > max(a,b) <=> x > a AND x > b\n+ * while an expression starting with (nested) Min operations can be used for\n+ * upper bounds\n+ *   x < min(a,b) <=> x < a AND x < b.\n+ * Arguments \"allowMin\" and \"allowMax\" control whether Min and Max operations,\n+ * respecitvely, are allowed to be present in the expression. Note that they\n+ * can only appear before any other operation and cannot appear together in an\n+ * expression.\n+ * If a Halide expression cannot be converted into a list of affine expressions,\n+ * return an empty list.\n+ */\n+std::vector<isl::aff> makeIslAffBoundsFromExpr(\n+    isl::space space,\n+    const Expr& e,\n+    bool allowMin,\n+    bool allowMax) {\n+  CHECK(!(allowMin && allowMax));","path":"src/core/halide2isl.cc","position":81,"original_position":81,"commit_id":"1ee5f542af3f06ca25fe590282c6031152cb84c0","original_commit_id":"1ee5f542af3f06ca25fe590282c6031152cb84c0","user":{"login":"nicolasvasilache","id":10148468,"avatar_url":"https://avatars3.githubusercontent.com/u/10148468?v=4","gravatar_id":"","url":"https://api.github.com/users/nicolasvasilache","html_url":"https://github.com/nicolasvasilache","followers_url":"https://api.github.com/users/nicolasvasilache/followers","following_url":"https://api.github.com/users/nicolasvasilache/following{/other_user}","gists_url":"https://api.github.com/users/nicolasvasilache/gists{/gist_id}","starred_url":"https://api.github.com/users/nicolasvasilache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicolasvasilache/subscriptions","organizations_url":"https://api.github.com/users/nicolasvasilache/orgs","repos_url":"https://api.github.com/users/nicolasvasilache/repos","events_url":"https://api.github.com/users/nicolasvasilache/events{/privacy}","received_events_url":"https://api.github.com/users/nicolasvasilache/received_events","type":"User","site_admin":false},"body":"Feels like this could actually happen with reasonable combinations of positive and negative indices.\r\nIn which case maybe this should be reported as a user-facing TC well-formedness error but scorch the earth via CHECK is too aggressive?","created_at":"2018-03-09T20:04:39Z","updated_at":"2018-03-09T20:04:39Z","html_url":"https://github.com/facebookresearch/TensorComprehensions/pull/127#discussion_r173554183","pull_request_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/127","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/comments/173554183"},"html":{"href":"https://github.com/facebookresearch/TensorComprehensions/pull/127#discussion_r173554183"},"pull_request":{"href":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/127"}}},"pull_request":{"url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/127","id":173798653,"html_url":"https://github.com/facebookresearch/TensorComprehensions/pull/127","diff_url":"https://github.com/facebookresearch/TensorComprehensions/pull/127.diff","patch_url":"https://github.com/facebookresearch/TensorComprehensions/pull/127.patch","issue_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues/127","number":127,"state":"open","locked":false,"title":"[hotfix] Support min max bounds","user":{"login":"ftynse","id":1512299,"avatar_url":"https://avatars1.githubusercontent.com/u/1512299?v=4","gravatar_id":"","url":"https://api.github.com/users/ftynse","html_url":"https://github.com/ftynse","followers_url":"https://api.github.com/users/ftynse/followers","following_url":"https://api.github.com/users/ftynse/following{/other_user}","gists_url":"https://api.github.com/users/ftynse/gists{/gist_id}","starred_url":"https://api.github.com/users/ftynse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ftynse/subscriptions","organizations_url":"https://api.github.com/users/ftynse/orgs","repos_url":"https://api.github.com/users/ftynse/repos","events_url":"https://api.github.com/users/ftynse/events{/privacy}","received_events_url":"https://api.github.com/users/ftynse/received_events","type":"User","site_admin":false},"body":"Loop bounds inferred by Halide may involve min or max operations, which\r\nare not convertible into affine functions.  For the sake of bound\r\ncomputation, compute lists of affine functions by recursively\r\nflattening arguments of nested min and max operations.  Use all\r\naffine functions from a list to define loop bounds.  In particular,\r\nallow min in upper bounds and max in lower bounds to exploit\r\n```\r\n  x < min(a, min(b, c)) <=> x < a and x < b and x < c,\r\n  x > max(a, max(b, c)) <=> x > a and x > b and x > c\r\n```\r\nequivalences.  Do not allow other cases.\r\n\r\nCloses #124 #125 ","created_at":"2018-03-08T17:23:45Z","updated_at":"2018-03-09T20:04:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7816d09408d5e165f197be0aaa66a80ae5ef0916","assignee":null,"assignees":[],"requested_reviewers":[{"login":"prigoyal","id":13488275,"avatar_url":"https://avatars0.githubusercontent.com/u/13488275?v=4","gravatar_id":"","url":"https://api.github.com/users/prigoyal","html_url":"https://github.com/prigoyal","followers_url":"https://api.github.com/users/prigoyal/followers","following_url":"https://api.github.com/users/prigoyal/following{/other_user}","gists_url":"https://api.github.com/users/prigoyal/gists{/gist_id}","starred_url":"https://api.github.com/users/prigoyal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prigoyal/subscriptions","organizations_url":"https://api.github.com/users/prigoyal/orgs","repos_url":"https://api.github.com/users/prigoyal/repos","events_url":"https://api.github.com/users/prigoyal/events{/privacy}","received_events_url":"https://api.github.com/users/prigoyal/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":829008246,"url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/labels/CLA%20Signed","name":"CLA Signed","color":"c2f4fc","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/127/commits","review_comments_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/127/comments","review_comment_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues/127/comments","statuses_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/statuses/1ee5f542af3f06ca25fe590282c6031152cb84c0","head":{"label":"facebookresearch:support-min-max-bounds","ref":"support-min-max-bounds","sha":"1ee5f542af3f06ca25fe590282c6031152cb84c0","user":{"login":"facebookresearch","id":16943930,"avatar_url":"https://avatars0.githubusercontent.com/u/16943930?v=4","gravatar_id":"","url":"https://api.github.com/users/facebookresearch","html_url":"https://github.com/facebookresearch","followers_url":"https://api.github.com/users/facebookresearch/followers","following_url":"https://api.github.com/users/facebookresearch/following{/other_user}","gists_url":"https://api.github.com/users/facebookresearch/gists{/gist_id}","starred_url":"https://api.github.com/users/facebookresearch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebookresearch/subscriptions","organizations_url":"https://api.github.com/users/facebookresearch/orgs","repos_url":"https://api.github.com/users/facebookresearch/repos","events_url":"https://api.github.com/users/facebookresearch/events{/privacy}","received_events_url":"https://api.github.com/users/facebookresearch/received_events","type":"Organization","site_admin":false},"repo":{"id":120494252,"name":"TensorComprehensions","full_name":"facebookresearch/TensorComprehensions","owner":{"login":"facebookresearch","id":16943930,"avatar_url":"https://avatars0.githubusercontent.com/u/16943930?v=4","gravatar_id":"","url":"https://api.github.com/users/facebookresearch","html_url":"https://github.com/facebookresearch","followers_url":"https://api.github.com/users/facebookresearch/followers","following_url":"https://api.github.com/users/facebookresearch/following{/other_user}","gists_url":"https://api.github.com/users/facebookresearch/gists{/gist_id}","starred_url":"https://api.github.com/users/facebookresearch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebookresearch/subscriptions","organizations_url":"https://api.github.com/users/facebookresearch/orgs","repos_url":"https://api.github.com/users/facebookresearch/repos","events_url":"https://api.github.com/users/facebookresearch/events{/privacy}","received_events_url":"https://api.github.com/users/facebookresearch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebookresearch/TensorComprehensions","description":"A domain specific language to express machine learning workloads.","fork":false,"url":"https://api.github.com/repos/facebookresearch/TensorComprehensions","forks_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/forks","keys_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/teams","hooks_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/hooks","issue_events_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues/events{/number}","events_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/events","assignees_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/assignees{/user}","branches_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/branches{/branch}","tags_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/tags","blobs_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/statuses/{sha}","languages_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/languages","stargazers_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/stargazers","contributors_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/contributors","subscribers_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/subscribers","subscription_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/subscription","commits_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/contents/{+path}","compare_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/merges","archive_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/downloads","issues_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues{/number}","pulls_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls{/number}","milestones_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/milestones{/number}","notifications_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/labels{/name}","releases_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/releases{/id}","deployments_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/deployments","created_at":"2018-02-06T17:11:07Z","updated_at":"2018-03-09T14:43:40Z","pushed_at":"2018-03-09T19:58:05Z","git_url":"git://github.com/facebookresearch/TensorComprehensions.git","ssh_url":"git@github.com:facebookresearch/TensorComprehensions.git","clone_url":"https://github.com/facebookresearch/TensorComprehensions.git","svn_url":"https://github.com/facebookresearch/TensorComprehensions","homepage":"https://facebookresearch.github.io/TensorComprehensions/","size":30674,"stargazers_count":906,"watchers_count":906,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":64,"mirror_url":null,"archived":false,"open_issues_count":32,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":64,"open_issues":32,"watchers":906,"default_branch":"master"}},"base":{"label":"facebookresearch:master","ref":"master","sha":"f315eaf7474bd4b7c042e4ba98f1195a26f52c67","user":{"login":"facebookresearch","id":16943930,"avatar_url":"https://avatars0.githubusercontent.com/u/16943930?v=4","gravatar_id":"","url":"https://api.github.com/users/facebookresearch","html_url":"https://github.com/facebookresearch","followers_url":"https://api.github.com/users/facebookresearch/followers","following_url":"https://api.github.com/users/facebookresearch/following{/other_user}","gists_url":"https://api.github.com/users/facebookresearch/gists{/gist_id}","starred_url":"https://api.github.com/users/facebookresearch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebookresearch/subscriptions","organizations_url":"https://api.github.com/users/facebookresearch/orgs","repos_url":"https://api.github.com/users/facebookresearch/repos","events_url":"https://api.github.com/users/facebookresearch/events{/privacy}","received_events_url":"https://api.github.com/users/facebookresearch/received_events","type":"Organization","site_admin":false},"repo":{"id":120494252,"name":"TensorComprehensions","full_name":"facebookresearch/TensorComprehensions","owner":{"login":"facebookresearch","id":16943930,"avatar_url":"https://avatars0.githubusercontent.com/u/16943930?v=4","gravatar_id":"","url":"https://api.github.com/users/facebookresearch","html_url":"https://github.com/facebookresearch","followers_url":"https://api.github.com/users/facebookresearch/followers","following_url":"https://api.github.com/users/facebookresearch/following{/other_user}","gists_url":"https://api.github.com/users/facebookresearch/gists{/gist_id}","starred_url":"https://api.github.com/users/facebookresearch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebookresearch/subscriptions","organizations_url":"https://api.github.com/users/facebookresearch/orgs","repos_url":"https://api.github.com/users/facebookresearch/repos","events_url":"https://api.github.com/users/facebookresearch/events{/privacy}","received_events_url":"https://api.github.com/users/facebookresearch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebookresearch/TensorComprehensions","description":"A domain specific language to express machine learning workloads.","fork":false,"url":"https://api.github.com/repos/facebookresearch/TensorComprehensions","forks_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/forks","keys_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/teams","hooks_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/hooks","issue_events_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues/events{/number}","events_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/events","assignees_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/assignees{/user}","branches_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/branches{/branch}","tags_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/tags","blobs_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/statuses/{sha}","languages_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/languages","stargazers_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/stargazers","contributors_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/contributors","subscribers_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/subscribers","subscription_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/subscription","commits_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/contents/{+path}","compare_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/merges","archive_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/downloads","issues_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues{/number}","pulls_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls{/number}","milestones_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/milestones{/number}","notifications_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/labels{/name}","releases_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/releases{/id}","deployments_url":"https://api.github.com/repos/facebookresearch/TensorComprehensions/deployments","created_at":"2018-02-06T17:11:07Z","updated_at":"2018-03-09T14:43:40Z","pushed_at":"2018-03-09T19:58:05Z","git_url":"git://github.com/facebookresearch/TensorComprehensions.git","ssh_url":"git@github.com:facebookresearch/TensorComprehensions.git","clone_url":"https://github.com/facebookresearch/TensorComprehensions.git","svn_url":"https://github.com/facebookresearch/TensorComprehensions","homepage":"https://facebookresearch.github.io/TensorComprehensions/","size":30674,"stargazers_count":906,"watchers_count":906,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":64,"mirror_url":null,"archived":false,"open_issues_count":32,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":64,"open_issues":32,"watchers":906,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/127"},"html":{"href":"https://github.com/facebookresearch/TensorComprehensions/pull/127"},"issue":{"href":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues/127"},"comments":{"href":"https://api.github.com/repos/facebookresearch/TensorComprehensions/issues/127/comments"},"review_comments":{"href":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/127/comments"},"review_comment":{"href":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebookresearch/TensorComprehensions/pulls/127/commits"},"statuses":{"href":"https://api.github.com/repos/facebookresearch/TensorComprehensions/statuses/1ee5f542af3f06ca25fe590282c6031152cb84c0"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"nicolasvasilache"}}