{"action":"created","comment":{"url":"https://api.github.com/repos/odlgroup/odl/pulls/comments/101460255","pull_request_review_id":22188052,"id":101460255,"diff_hunk":"@@ -692,6 +696,141 @@ def __init__(self, vfspace, weighting=None):\n         super().__init__(vfspace, vecfield=ones, weighting=weighting)\n \n \n+class MatrixOperator(Operator):\n+\n+    \"\"\"Matrix multiply operator :math:`\\mathbb{F}^n -> \\mathbb{F}^m`.\n+\n+    This operator uses a matrix to represent an operator, and get its adjoint\n+    and inverse by doing computations on the matrix. This is in general a\n+    rather slow approach, and users are recommended to use other alternatives\n+    if available.\n+    \"\"\"\n+\n+    def __init__(self, matrix, domain=None, range=None):\n+        \"\"\"Initialize a new instance.\n+\n+        Parameters\n+        ----------\n+        matrix : `array-like` or  `scipy.sparse.spmatrix`\n+            Matrix representing the linear operator. Its shape must be\n+            ``(m, n)``, where ``n`` is the size of ``domain`` and ``m`` the\n+            size of ``range``. Its dtype must be castable to the range\n+            ``dtype``.\n+        domain : `FnBase`, optional\n+            Space on whose elements the matrix acts. If not provided,\n+            the domain is inferred from the matrix ``dtype`` and\n+            ``shape``. If provided, its dtype must be castable to the\n+            range dtype.\n+        range : `FnBase`, optional\n+            Space to which the matrix maps. If not provided,\n+            the domain is inferred from the matrix ``dtype`` and\n+            ``shape``.\n+        \"\"\"\n+        # TODO: fix dead link `scipy.sparse.spmatrix`\n+        if scipy.sparse.isspmatrix(matrix):\n+            self.__matrix = matrix\n+        else:\n+            self.__matrix = np.asarray(matrix)\n+\n+        if self.matrix.ndim != 2:\n+            raise ValueError('matrix {} has {} axes instead of 2'\n+                             ''.format(matrix, self.matrix.ndim))\n+\n+        # Infer domain and range from matrix if necessary\n+        if domain is None:\n+            domain = NumpyFn(self.matrix.shape[1], dtype=self.matrix.dtype)\n+        elif not isinstance(domain, FnBase):\n+            raise TypeError('`domain` {!r} is not an `FnBase` instance'\n+                            ''.format(domain))\n+\n+        if range is None:\n+            range = NumpyFn(self.matrix.shape[0], dtype=self.matrix.dtype)\n+        elif not isinstance(range, FnBase):\n+            raise TypeError('`range` {!r} is not an `FnBase` instance'\n+                            ''.format(range))\n+\n+        # Check compatibility of matrix with domain and range\n+        if not np.can_cast(domain.dtype, range.dtype):\n+            raise TypeError('domain data type {!r} cannot be safely cast to '\n+                            'range data type {!r}'\n+                            ''.format(domain.dtype, range.dtype))\n+\n+        if self.matrix.shape != (range.size, domain.size):\n+            raise ValueError('matrix shape {} does not match the required '\n+                             'shape {} of a matrix {} --> {}'\n+                             ''.format(self.matrix.shape,\n+                                       (range.size, domain.size),\n+                                       domain, range))\n+        if not np.can_cast(self.matrix.dtype, range.dtype):","path":"odl/operator/tensor_ops.py","position":88,"original_position":88,"commit_id":"4981375dac09b212311721d5abf50481de8502a9","original_commit_id":"4981375dac09b212311721d5abf50481de8502a9","user":{"login":"adler-j","id":2202312,"avatar_url":"https://avatars.githubusercontent.com/u/2202312?v=3","gravatar_id":"","url":"https://api.github.com/users/adler-j","html_url":"https://github.com/adler-j","followers_url":"https://api.github.com/users/adler-j/followers","following_url":"https://api.github.com/users/adler-j/following{/other_user}","gists_url":"https://api.github.com/users/adler-j/gists{/gist_id}","starred_url":"https://api.github.com/users/adler-j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adler-j/subscriptions","organizations_url":"https://api.github.com/users/adler-j/orgs","repos_url":"https://api.github.com/users/adler-j/repos","events_url":"https://api.github.com/users/adler-j/events{/privacy}","received_events_url":"https://api.github.com/users/adler-j/received_events","type":"User","site_admin":false},"body":"weird order of the dtype checks, shape check shouldnt be interlaced","created_at":"2017-02-16T07:46:49Z","updated_at":"2017-02-16T07:51:32Z","html_url":"https://github.com/odlgroup/odl/pull/911#discussion_r101460255","pull_request_url":"https://api.github.com/repos/odlgroup/odl/pulls/911","_links":{"self":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/comments/101460255"},"html":{"href":"https://github.com/odlgroup/odl/pull/911#discussion_r101460255"},"pull_request":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/911"}}},"pull_request":{"url":"https://api.github.com/repos/odlgroup/odl/pulls/911","id":106398794,"html_url":"https://github.com/odlgroup/odl/pull/911","diff_url":"https://github.com/odlgroup/odl/pull/911.diff","patch_url":"https://github.com/odlgroup/odl/pull/911.patch","issue_url":"https://api.github.com/repos/odlgroup/odl/issues/911","number":911,"state":"open","locked":false,"title":"Issue 910  matvec op","user":{"login":"kohr-h","id":5030250,"avatar_url":"https://avatars.githubusercontent.com/u/5030250?v=3","gravatar_id":"","url":"https://api.github.com/users/kohr-h","html_url":"https://github.com/kohr-h","followers_url":"https://api.github.com/users/kohr-h/followers","following_url":"https://api.github.com/users/kohr-h/following{/other_user}","gists_url":"https://api.github.com/users/kohr-h/gists{/gist_id}","starred_url":"https://api.github.com/users/kohr-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kohr-h/subscriptions","organizations_url":"https://api.github.com/users/kohr-h/orgs","repos_url":"https://api.github.com/users/kohr-h/repos","events_url":"https://api.github.com/users/kohr-h/events{/privacy}","received_events_url":"https://api.github.com/users/kohr-h/received_events","type":"User","site_admin":false},"body":"Fix for #910 and move of `MatVecOperator` from `space/npy_ntuples` to `operator/tensor_ops`, plus rename from `MatVecOperator` to `MatrixOperator`.\r\nNo other work like docs or test improvement since #861 also has its part in it.","created_at":"2017-02-15T21:04:09Z","updated_at":"2017-02-16T07:51:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8b18eabeb61d8c352e87e12735c69369f05d0986","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/odlgroup/odl/pulls/911/commits","review_comments_url":"https://api.github.com/repos/odlgroup/odl/pulls/911/comments","review_comment_url":"https://api.github.com/repos/odlgroup/odl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odlgroup/odl/issues/911/comments","statuses_url":"https://api.github.com/repos/odlgroup/odl/statuses/4981375dac09b212311721d5abf50481de8502a9","head":{"label":"kohr-h:issue-910__matvec_op","ref":"issue-910__matvec_op","sha":"4981375dac09b212311721d5abf50481de8502a9","user":{"login":"kohr-h","id":5030250,"avatar_url":"https://avatars.githubusercontent.com/u/5030250?v=3","gravatar_id":"","url":"https://api.github.com/users/kohr-h","html_url":"https://github.com/kohr-h","followers_url":"https://api.github.com/users/kohr-h/followers","following_url":"https://api.github.com/users/kohr-h/following{/other_user}","gists_url":"https://api.github.com/users/kohr-h/gists{/gist_id}","starred_url":"https://api.github.com/users/kohr-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kohr-h/subscriptions","organizations_url":"https://api.github.com/users/kohr-h/orgs","repos_url":"https://api.github.com/users/kohr-h/repos","events_url":"https://api.github.com/users/kohr-h/events{/privacy}","received_events_url":"https://api.github.com/users/kohr-h/received_events","type":"User","site_admin":false},"repo":{"id":66929595,"name":"odl","full_name":"kohr-h/odl","owner":{"login":"kohr-h","id":5030250,"avatar_url":"https://avatars.githubusercontent.com/u/5030250?v=3","gravatar_id":"","url":"https://api.github.com/users/kohr-h","html_url":"https://github.com/kohr-h","followers_url":"https://api.github.com/users/kohr-h/followers","following_url":"https://api.github.com/users/kohr-h/following{/other_user}","gists_url":"https://api.github.com/users/kohr-h/gists{/gist_id}","starred_url":"https://api.github.com/users/kohr-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kohr-h/subscriptions","organizations_url":"https://api.github.com/users/kohr-h/orgs","repos_url":"https://api.github.com/users/kohr-h/repos","events_url":"https://api.github.com/users/kohr-h/events{/privacy}","received_events_url":"https://api.github.com/users/kohr-h/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kohr-h/odl","description":"Operator Discretization Library","fork":true,"url":"https://api.github.com/repos/kohr-h/odl","forks_url":"https://api.github.com/repos/kohr-h/odl/forks","keys_url":"https://api.github.com/repos/kohr-h/odl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kohr-h/odl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kohr-h/odl/teams","hooks_url":"https://api.github.com/repos/kohr-h/odl/hooks","issue_events_url":"https://api.github.com/repos/kohr-h/odl/issues/events{/number}","events_url":"https://api.github.com/repos/kohr-h/odl/events","assignees_url":"https://api.github.com/repos/kohr-h/odl/assignees{/user}","branches_url":"https://api.github.com/repos/kohr-h/odl/branches{/branch}","tags_url":"https://api.github.com/repos/kohr-h/odl/tags","blobs_url":"https://api.github.com/repos/kohr-h/odl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kohr-h/odl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kohr-h/odl/git/refs{/sha}","trees_url":"https://api.github.com/repos/kohr-h/odl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kohr-h/odl/statuses/{sha}","languages_url":"https://api.github.com/repos/kohr-h/odl/languages","stargazers_url":"https://api.github.com/repos/kohr-h/odl/stargazers","contributors_url":"https://api.github.com/repos/kohr-h/odl/contributors","subscribers_url":"https://api.github.com/repos/kohr-h/odl/subscribers","subscription_url":"https://api.github.com/repos/kohr-h/odl/subscription","commits_url":"https://api.github.com/repos/kohr-h/odl/commits{/sha}","git_commits_url":"https://api.github.com/repos/kohr-h/odl/git/commits{/sha}","comments_url":"https://api.github.com/repos/kohr-h/odl/comments{/number}","issue_comment_url":"https://api.github.com/repos/kohr-h/odl/issues/comments{/number}","contents_url":"https://api.github.com/repos/kohr-h/odl/contents/{+path}","compare_url":"https://api.github.com/repos/kohr-h/odl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kohr-h/odl/merges","archive_url":"https://api.github.com/repos/kohr-h/odl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kohr-h/odl/downloads","issues_url":"https://api.github.com/repos/kohr-h/odl/issues{/number}","pulls_url":"https://api.github.com/repos/kohr-h/odl/pulls{/number}","milestones_url":"https://api.github.com/repos/kohr-h/odl/milestones{/number}","notifications_url":"https://api.github.com/repos/kohr-h/odl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kohr-h/odl/labels{/name}","releases_url":"https://api.github.com/repos/kohr-h/odl/releases{/id}","deployments_url":"https://api.github.com/repos/kohr-h/odl/deployments","created_at":"2016-08-30T10:07:24Z","updated_at":"2016-08-30T10:07:26Z","pushed_at":"2017-02-16T00:05:51Z","git_url":"git://github.com/kohr-h/odl.git","ssh_url":"git@github.com:kohr-h/odl.git","clone_url":"https://github.com/kohr-h/odl.git","svn_url":"https://github.com/kohr-h/odl","homepage":null,"size":20176,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"odlgroup:master","ref":"master","sha":"32842320ad5b91ef07da17a5dc6f9292318706df","user":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"repo":{"id":45596393,"name":"odl","full_name":"odlgroup/odl","owner":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odlgroup/odl","description":"Operator Discretization Library","fork":false,"url":"https://api.github.com/repos/odlgroup/odl","forks_url":"https://api.github.com/repos/odlgroup/odl/forks","keys_url":"https://api.github.com/repos/odlgroup/odl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odlgroup/odl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odlgroup/odl/teams","hooks_url":"https://api.github.com/repos/odlgroup/odl/hooks","issue_events_url":"https://api.github.com/repos/odlgroup/odl/issues/events{/number}","events_url":"https://api.github.com/repos/odlgroup/odl/events","assignees_url":"https://api.github.com/repos/odlgroup/odl/assignees{/user}","branches_url":"https://api.github.com/repos/odlgroup/odl/branches{/branch}","tags_url":"https://api.github.com/repos/odlgroup/odl/tags","blobs_url":"https://api.github.com/repos/odlgroup/odl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odlgroup/odl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odlgroup/odl/git/refs{/sha}","trees_url":"https://api.github.com/repos/odlgroup/odl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odlgroup/odl/statuses/{sha}","languages_url":"https://api.github.com/repos/odlgroup/odl/languages","stargazers_url":"https://api.github.com/repos/odlgroup/odl/stargazers","contributors_url":"https://api.github.com/repos/odlgroup/odl/contributors","subscribers_url":"https://api.github.com/repos/odlgroup/odl/subscribers","subscription_url":"https://api.github.com/repos/odlgroup/odl/subscription","commits_url":"https://api.github.com/repos/odlgroup/odl/commits{/sha}","git_commits_url":"https://api.github.com/repos/odlgroup/odl/git/commits{/sha}","comments_url":"https://api.github.com/repos/odlgroup/odl/comments{/number}","issue_comment_url":"https://api.github.com/repos/odlgroup/odl/issues/comments{/number}","contents_url":"https://api.github.com/repos/odlgroup/odl/contents/{+path}","compare_url":"https://api.github.com/repos/odlgroup/odl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odlgroup/odl/merges","archive_url":"https://api.github.com/repos/odlgroup/odl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odlgroup/odl/downloads","issues_url":"https://api.github.com/repos/odlgroup/odl/issues{/number}","pulls_url":"https://api.github.com/repos/odlgroup/odl/pulls{/number}","milestones_url":"https://api.github.com/repos/odlgroup/odl/milestones{/number}","notifications_url":"https://api.github.com/repos/odlgroup/odl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odlgroup/odl/labels{/name}","releases_url":"https://api.github.com/repos/odlgroup/odl/releases{/id}","deployments_url":"https://api.github.com/repos/odlgroup/odl/deployments","created_at":"2015-11-05T07:57:55Z","updated_at":"2016-12-22T17:15:26Z","pushed_at":"2017-02-15T21:16:29Z","git_url":"git://github.com/odlgroup/odl.git","ssh_url":"git@github.com:odlgroup/odl.git","clone_url":"https://github.com/odlgroup/odl.git","svn_url":"https://github.com/odlgroup/odl","homepage":null,"size":36945,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":11,"mirror_url":null,"open_issues_count":162,"forks":11,"open_issues":162,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/911"},"html":{"href":"https://github.com/odlgroup/odl/pull/911"},"issue":{"href":"https://api.github.com/repos/odlgroup/odl/issues/911"},"comments":{"href":"https://api.github.com/repos/odlgroup/odl/issues/911/comments"},"review_comments":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/911/comments"},"review_comment":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/911/commits"},"statuses":{"href":"https://api.github.com/repos/odlgroup/odl/statuses/4981375dac09b212311721d5abf50481de8502a9"}}}}
{"actor":{"display_login":"adler-j"}}