{"action":"created","comment":{"url":"https://api.github.com/repos/QuantStack/xtensor/pulls/comments/209867032","pull_request_review_id":145961398,"id":209867032,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwOTg2NzAzMg==","diff_hunk":"@@ -2402,6 +2402,82 @@ XTENSOR_INT_SPECIALIZATION_IMPL(FUNC_NAME, RETURN_VAL, unsigned long long);\n \n         return eval(sum(trap, {saxis}));\n     }\n+\n+    /**\n+     * @ingroup basic_functions\n+     * @brief Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x.\n+     *\n+     * @param The x-coordinates at which to evaluate the interpolated values (sorted).\n+     * @param The x-coordinates of the data points (sorted).\n+     * @param The y-coordinates of the data points, same length as xp.\n+     * @param Value to return for x < xp[0].\n+     * @param Value to return for x > xp[-1]\n+     * @return an one-dimensional xarray, same length as x.\n+     */\n+    template<class E>\n+    inline E interp(const E &x, const E &xp, const E &fp, double left, double right)\n+    {\n+        // basic checks\n+        #ifdef XTENSOR_ENABLE_ASSERT\n+\n+            XTENSOR_ASSERT( xp.dimension() == 1 );\n+\n+            for ( size_t i = 1 ; i < x.size() ; ++i ) {\n+                XTENSOR_ASSERT( x[i] >= x[i-1] );\n+            }\n+\n+            for ( size_t ip = 1 ; ip < xp.size() ; ++ip ) {\n+                XTENSOR_ASSERT( xp[ip] >= xp[ip-1] );\n+            }\n+\n+        #endif\n+\n+        // allocate output\n+        E f = E::from_shape(x.shape());\n+\n+        // counter in \"x\"\n+        size_t i    = 0;\n+        size_t imax = x.size();\n+\n+        // fill f[i] for x[i] <= xp[0]\n+        for ( ; i < x.size() ; ++i ) {\n+            if ( x[i] > xp[0] ) { break; }\n+            f[i] = left;\n+        }\n+\n+        // fill f[i] for x[-1] >= xp[-1]\n+        for ( ; imax-- > 0 ; ) {\n+            if ( x[imax] < xp[xp.size()-1] ) { break; }\n+            f[imax] = right;\n+        }\n+\n+        // counter in \"xp\"\n+        size_t ip = 1;\n+\n+        // fill f[i] for the interior\n+        for ( ; i <= imax ; ++i ) {\n+            while ( x[i] > xp[ip] ) { ++ip; }\n+            f[i] = fp[ip-1] + ( fp[ip] - fp[ip-1] ) / ( xp[ip] - xp[ip-1] ) * ( x[i] - xp[ip-1] );\n+        }\n+\n+        return f;\n+    }\n+\n+    /**\n+     * @ingroup basic_functions\n+     * @brief Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x.\n+     *\n+     * @param The x-coordinates at which to evaluate the interpolated values (sorted).\n+     * @param The x-coordinates of the data points (sorted).\n+     * @param The y-coordinates of the data points, same length as xp.\n+     * @return an one-dimensional xarray, same length as x.\n+     */\n+    template<class E>\n+    inline E interp(const E &x, const E &xp, const E &fp)\n+    {\n+        return interp(x,xp,fp,fp[0],fp[fp.size()-1]);\n+    }","path":"include/xtensor/xmath.hpp","position":78,"original_position":78,"commit_id":"718d4e36f18dcd208715f522656b5ad3eb9d259c","original_commit_id":"718d4e36f18dcd208715f522656b5ad3eb9d259c","user":{"login":"SylvainCorlay","id":2397974,"node_id":"MDQ6VXNlcjIzOTc5NzQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2397974?v=4","gravatar_id":"","url":"https://api.github.com/users/SylvainCorlay","html_url":"https://github.com/SylvainCorlay","followers_url":"https://api.github.com/users/SylvainCorlay/followers","following_url":"https://api.github.com/users/SylvainCorlay/following{/other_user}","gists_url":"https://api.github.com/users/SylvainCorlay/gists{/gist_id}","starred_url":"https://api.github.com/users/SylvainCorlay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SylvainCorlay/subscriptions","organizations_url":"https://api.github.com/users/SylvainCorlay/orgs","repos_url":"https://api.github.com/users/SylvainCorlay/repos","events_url":"https://api.github.com/users/SylvainCorlay/events{/privacy}","received_events_url":"https://api.github.com/users/SylvainCorlay/received_events","type":"User","site_admin":false},"body":"```\r\ntemplate<class E>\r\ninline E interp(const E& x, const E& xp, const E& fp)\r\n{\r\n    return interp(x, xp, fp, fp[0], fp[fp.size() - 1]);\r\n}\r\n```","created_at":"2018-08-14T08:27:31Z","updated_at":"2018-08-14T08:27:31Z","html_url":"https://github.com/QuantStack/xtensor/pull/1071#discussion_r209867032","pull_request_url":"https://api.github.com/repos/QuantStack/xtensor/pulls/1071","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/QuantStack/xtensor/pulls/comments/209867032"},"html":{"href":"https://github.com/QuantStack/xtensor/pull/1071#discussion_r209867032"},"pull_request":{"href":"https://api.github.com/repos/QuantStack/xtensor/pulls/1071"}}},"pull_request":{"url":"https://api.github.com/repos/QuantStack/xtensor/pulls/1071","id":208202756,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA4MjAyNzU2","html_url":"https://github.com/QuantStack/xtensor/pull/1071","diff_url":"https://github.com/QuantStack/xtensor/pull/1071.diff","patch_url":"https://github.com/QuantStack/xtensor/pull/1071.patch","issue_url":"https://api.github.com/repos/QuantStack/xtensor/issues/1071","number":1071,"state":"open","locked":false,"title":"Added \"interp\" function to xmath, updated the doc","user":{"login":"tdegeus","id":7030445,"node_id":"MDQ6VXNlcjcwMzA0NDU=","avatar_url":"https://avatars0.githubusercontent.com/u/7030445?v=4","gravatar_id":"","url":"https://api.github.com/users/tdegeus","html_url":"https://github.com/tdegeus","followers_url":"https://api.github.com/users/tdegeus/followers","following_url":"https://api.github.com/users/tdegeus/following{/other_user}","gists_url":"https://api.github.com/users/tdegeus/gists{/gist_id}","starred_url":"https://api.github.com/users/tdegeus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdegeus/subscriptions","organizations_url":"https://api.github.com/users/tdegeus/orgs","repos_url":"https://api.github.com/users/tdegeus/repos","events_url":"https://api.github.com/users/tdegeus/events{/privacy}","received_events_url":"https://api.github.com/users/tdegeus/received_events","type":"User","site_admin":false},"body":"* The function is equivalent to NumPy's `interp`, whereby the `left` and `right` options are allowed using the overload.\r\n* The `period` option in NumPy's `interp` is not currently implemented.\r\n\r\n> Note: I'm not fully confident that I followed all (implicit) conventions.","created_at":"2018-08-14T08:19:04Z","updated_at":"2018-08-14T08:27:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"054440b80b46123c1c25e1363c7ef305b4e83cf6","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/QuantStack/xtensor/pulls/1071/commits","review_comments_url":"https://api.github.com/repos/QuantStack/xtensor/pulls/1071/comments","review_comment_url":"https://api.github.com/repos/QuantStack/xtensor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/QuantStack/xtensor/issues/1071/comments","statuses_url":"https://api.github.com/repos/QuantStack/xtensor/statuses/718d4e36f18dcd208715f522656b5ad3eb9d259c","head":{"label":"tdegeus:interp","ref":"interp","sha":"718d4e36f18dcd208715f522656b5ad3eb9d259c","user":{"login":"tdegeus","id":7030445,"node_id":"MDQ6VXNlcjcwMzA0NDU=","avatar_url":"https://avatars0.githubusercontent.com/u/7030445?v=4","gravatar_id":"","url":"https://api.github.com/users/tdegeus","html_url":"https://github.com/tdegeus","followers_url":"https://api.github.com/users/tdegeus/followers","following_url":"https://api.github.com/users/tdegeus/following{/other_user}","gists_url":"https://api.github.com/users/tdegeus/gists{/gist_id}","starred_url":"https://api.github.com/users/tdegeus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdegeus/subscriptions","organizations_url":"https://api.github.com/users/tdegeus/orgs","repos_url":"https://api.github.com/users/tdegeus/repos","events_url":"https://api.github.com/users/tdegeus/events{/privacy}","received_events_url":"https://api.github.com/users/tdegeus/received_events","type":"User","site_admin":false},"repo":{"id":142275881,"node_id":"MDEwOlJlcG9zaXRvcnkxNDIyNzU4ODE=","name":"xtensor","full_name":"tdegeus/xtensor","owner":{"login":"tdegeus","id":7030445,"node_id":"MDQ6VXNlcjcwMzA0NDU=","avatar_url":"https://avatars0.githubusercontent.com/u/7030445?v=4","gravatar_id":"","url":"https://api.github.com/users/tdegeus","html_url":"https://github.com/tdegeus","followers_url":"https://api.github.com/users/tdegeus/followers","following_url":"https://api.github.com/users/tdegeus/following{/other_user}","gists_url":"https://api.github.com/users/tdegeus/gists{/gist_id}","starred_url":"https://api.github.com/users/tdegeus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdegeus/subscriptions","organizations_url":"https://api.github.com/users/tdegeus/orgs","repos_url":"https://api.github.com/users/tdegeus/repos","events_url":"https://api.github.com/users/tdegeus/events{/privacy}","received_events_url":"https://api.github.com/users/tdegeus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tdegeus/xtensor","description":"C++ tensors with broadcasting and lazy computing","fork":true,"url":"https://api.github.com/repos/tdegeus/xtensor","forks_url":"https://api.github.com/repos/tdegeus/xtensor/forks","keys_url":"https://api.github.com/repos/tdegeus/xtensor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tdegeus/xtensor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tdegeus/xtensor/teams","hooks_url":"https://api.github.com/repos/tdegeus/xtensor/hooks","issue_events_url":"https://api.github.com/repos/tdegeus/xtensor/issues/events{/number}","events_url":"https://api.github.com/repos/tdegeus/xtensor/events","assignees_url":"https://api.github.com/repos/tdegeus/xtensor/assignees{/user}","branches_url":"https://api.github.com/repos/tdegeus/xtensor/branches{/branch}","tags_url":"https://api.github.com/repos/tdegeus/xtensor/tags","blobs_url":"https://api.github.com/repos/tdegeus/xtensor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tdegeus/xtensor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tdegeus/xtensor/git/refs{/sha}","trees_url":"https://api.github.com/repos/tdegeus/xtensor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tdegeus/xtensor/statuses/{sha}","languages_url":"https://api.github.com/repos/tdegeus/xtensor/languages","stargazers_url":"https://api.github.com/repos/tdegeus/xtensor/stargazers","contributors_url":"https://api.github.com/repos/tdegeus/xtensor/contributors","subscribers_url":"https://api.github.com/repos/tdegeus/xtensor/subscribers","subscription_url":"https://api.github.com/repos/tdegeus/xtensor/subscription","commits_url":"https://api.github.com/repos/tdegeus/xtensor/commits{/sha}","git_commits_url":"https://api.github.com/repos/tdegeus/xtensor/git/commits{/sha}","comments_url":"https://api.github.com/repos/tdegeus/xtensor/comments{/number}","issue_comment_url":"https://api.github.com/repos/tdegeus/xtensor/issues/comments{/number}","contents_url":"https://api.github.com/repos/tdegeus/xtensor/contents/{+path}","compare_url":"https://api.github.com/repos/tdegeus/xtensor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tdegeus/xtensor/merges","archive_url":"https://api.github.com/repos/tdegeus/xtensor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tdegeus/xtensor/downloads","issues_url":"https://api.github.com/repos/tdegeus/xtensor/issues{/number}","pulls_url":"https://api.github.com/repos/tdegeus/xtensor/pulls{/number}","milestones_url":"https://api.github.com/repos/tdegeus/xtensor/milestones{/number}","notifications_url":"https://api.github.com/repos/tdegeus/xtensor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tdegeus/xtensor/labels{/name}","releases_url":"https://api.github.com/repos/tdegeus/xtensor/releases{/id}","deployments_url":"https://api.github.com/repos/tdegeus/xtensor/deployments","created_at":"2018-07-25T09:09:39Z","updated_at":"2018-08-13T10:13:03Z","pushed_at":"2018-08-14T08:15:43Z","git_url":"git://github.com/tdegeus/xtensor.git","ssh_url":"git@github.com:tdegeus/xtensor.git","clone_url":"https://github.com/tdegeus/xtensor.git","svn_url":"https://github.com/tdegeus/xtensor","homepage":"http://quantstack.net/xtensor","size":4221,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"QuantStack:master","ref":"master","sha":"98fcaae8b6d1be74ba8fca9d15b6861c9aa46966","user":{"login":"QuantStack","id":19627246,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5NjI3MjQ2","avatar_url":"https://avatars1.githubusercontent.com/u/19627246?v=4","gravatar_id":"","url":"https://api.github.com/users/QuantStack","html_url":"https://github.com/QuantStack","followers_url":"https://api.github.com/users/QuantStack/followers","following_url":"https://api.github.com/users/QuantStack/following{/other_user}","gists_url":"https://api.github.com/users/QuantStack/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantStack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantStack/subscriptions","organizations_url":"https://api.github.com/users/QuantStack/orgs","repos_url":"https://api.github.com/users/QuantStack/repos","events_url":"https://api.github.com/users/QuantStack/events{/privacy}","received_events_url":"https://api.github.com/users/QuantStack/received_events","type":"Organization","site_admin":false},"repo":{"id":72343220,"node_id":"MDEwOlJlcG9zaXRvcnk3MjM0MzIyMA==","name":"xtensor","full_name":"QuantStack/xtensor","owner":{"login":"QuantStack","id":19627246,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5NjI3MjQ2","avatar_url":"https://avatars1.githubusercontent.com/u/19627246?v=4","gravatar_id":"","url":"https://api.github.com/users/QuantStack","html_url":"https://github.com/QuantStack","followers_url":"https://api.github.com/users/QuantStack/followers","following_url":"https://api.github.com/users/QuantStack/following{/other_user}","gists_url":"https://api.github.com/users/QuantStack/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantStack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantStack/subscriptions","organizations_url":"https://api.github.com/users/QuantStack/orgs","repos_url":"https://api.github.com/users/QuantStack/repos","events_url":"https://api.github.com/users/QuantStack/events{/privacy}","received_events_url":"https://api.github.com/users/QuantStack/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/QuantStack/xtensor","description":"C++ tensors with broadcasting and lazy computing","fork":false,"url":"https://api.github.com/repos/QuantStack/xtensor","forks_url":"https://api.github.com/repos/QuantStack/xtensor/forks","keys_url":"https://api.github.com/repos/QuantStack/xtensor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/QuantStack/xtensor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/QuantStack/xtensor/teams","hooks_url":"https://api.github.com/repos/QuantStack/xtensor/hooks","issue_events_url":"https://api.github.com/repos/QuantStack/xtensor/issues/events{/number}","events_url":"https://api.github.com/repos/QuantStack/xtensor/events","assignees_url":"https://api.github.com/repos/QuantStack/xtensor/assignees{/user}","branches_url":"https://api.github.com/repos/QuantStack/xtensor/branches{/branch}","tags_url":"https://api.github.com/repos/QuantStack/xtensor/tags","blobs_url":"https://api.github.com/repos/QuantStack/xtensor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/QuantStack/xtensor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/QuantStack/xtensor/git/refs{/sha}","trees_url":"https://api.github.com/repos/QuantStack/xtensor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/QuantStack/xtensor/statuses/{sha}","languages_url":"https://api.github.com/repos/QuantStack/xtensor/languages","stargazers_url":"https://api.github.com/repos/QuantStack/xtensor/stargazers","contributors_url":"https://api.github.com/repos/QuantStack/xtensor/contributors","subscribers_url":"https://api.github.com/repos/QuantStack/xtensor/subscribers","subscription_url":"https://api.github.com/repos/QuantStack/xtensor/subscription","commits_url":"https://api.github.com/repos/QuantStack/xtensor/commits{/sha}","git_commits_url":"https://api.github.com/repos/QuantStack/xtensor/git/commits{/sha}","comments_url":"https://api.github.com/repos/QuantStack/xtensor/comments{/number}","issue_comment_url":"https://api.github.com/repos/QuantStack/xtensor/issues/comments{/number}","contents_url":"https://api.github.com/repos/QuantStack/xtensor/contents/{+path}","compare_url":"https://api.github.com/repos/QuantStack/xtensor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/QuantStack/xtensor/merges","archive_url":"https://api.github.com/repos/QuantStack/xtensor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/QuantStack/xtensor/downloads","issues_url":"https://api.github.com/repos/QuantStack/xtensor/issues{/number}","pulls_url":"https://api.github.com/repos/QuantStack/xtensor/pulls{/number}","milestones_url":"https://api.github.com/repos/QuantStack/xtensor/milestones{/number}","notifications_url":"https://api.github.com/repos/QuantStack/xtensor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/QuantStack/xtensor/labels{/name}","releases_url":"https://api.github.com/repos/QuantStack/xtensor/releases{/id}","deployments_url":"https://api.github.com/repos/QuantStack/xtensor/deployments","created_at":"2016-10-30T10:40:13Z","updated_at":"2018-08-13T20:07:11Z","pushed_at":"2018-08-14T08:19:04Z","git_url":"git://github.com/QuantStack/xtensor.git","ssh_url":"git@github.com:QuantStack/xtensor.git","clone_url":"https://github.com/QuantStack/xtensor.git","svn_url":"https://github.com/QuantStack/xtensor","homepage":"http://quantstack.net/xtensor","size":4227,"stargazers_count":732,"watchers_count":732,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":91,"mirror_url":null,"archived":false,"open_issues_count":100,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":91,"open_issues":100,"watchers":732,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/QuantStack/xtensor/pulls/1071"},"html":{"href":"https://github.com/QuantStack/xtensor/pull/1071"},"issue":{"href":"https://api.github.com/repos/QuantStack/xtensor/issues/1071"},"comments":{"href":"https://api.github.com/repos/QuantStack/xtensor/issues/1071/comments"},"review_comments":{"href":"https://api.github.com/repos/QuantStack/xtensor/pulls/1071/comments"},"review_comment":{"href":"https://api.github.com/repos/QuantStack/xtensor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/QuantStack/xtensor/pulls/1071/commits"},"statuses":{"href":"https://api.github.com/repos/QuantStack/xtensor/statuses/718d4e36f18dcd208715f522656b5ad3eb9d259c"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"SylvainCorlay"}}