{"action":"created","comment":{"url":"https://api.github.com/repos/google/swift/pulls/comments/186272534","pull_request_review_id":117825301,"id":186272534,"diff_hunk":"@@ -0,0 +1,68 @@\n+//===-- TensorFlow+NumPy.swift --------------------------------*- swift -*-===//\n+//\n+// This source file is part of the Swift.org open source project\n+//\n+// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors\n+// Licensed under Apache License v2.0 with Runtime Library Exception\n+//\n+// See https://swift.org/LICENSE.txt for license information\n+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors\n+//\n+//===----------------------------------------------------------------------===//\n+//\n+// This file defines bridging from `numpy.ndarray` to `ShapedArray` and\n+// `Tensor`.\n+//\n+//===----------------------------------------------------------------------===//\n+\n+import Python\n+\n+public extension ShapedArray {\n+  init?(numpyArray: PyValue) {\n+    guard let np = try? Python.attemptImport(\"numpy\") else {\n+      return nil\n+    }\n+    // Check if input is a `numpy.ndarray` instance.\n+    guard Python.isinstance.call(with: numpyArray, np.ndarray) == true else {\n+      return nil\n+    }\n+\n+    // Check if the array's dtype matches the `Scalar` type.\n+    // (e.g. `np.float32` and `Float`).\n+    var scalarTypeMatch = false\n+    switch numpyArray.dtype {","path":"stdlib/public/TensorFlow/TensorFlow+NumPy.swift","position":33,"original_position":33,"commit_id":"d8dfa71504fd1619f3c749fcec2022d7064fe90c","original_commit_id":"d8dfa71504fd1619f3c749fcec2022d7064fe90c","user":{"login":"rxwei","id":856507,"avatar_url":"https://avatars0.githubusercontent.com/u/856507?v=4","gravatar_id":"","url":"https://api.github.com/users/rxwei","html_url":"https://github.com/rxwei","followers_url":"https://api.github.com/users/rxwei/followers","following_url":"https://api.github.com/users/rxwei/following{/other_user}","gists_url":"https://api.github.com/users/rxwei/gists{/gist_id}","starred_url":"https://api.github.com/users/rxwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rxwei/subscriptions","organizations_url":"https://api.github.com/users/rxwei/orgs","repos_url":"https://api.github.com/users/rxwei/repos","events_url":"https://api.github.com/users/rxwei/events{/privacy}","received_events_url":"https://api.github.com/users/rxwei/received_events","type":"User","site_admin":false},"body":"Use a `let` here and initialize it entirely in the `switch` statement. Assign `false` to it in `default:`.","created_at":"2018-05-05T21:25:38Z","updated_at":"2018-05-05T21:31:47Z","html_url":"https://github.com/google/swift/pull/31#discussion_r186272534","pull_request_url":"https://api.github.com/repos/google/swift/pulls/31","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/google/swift/pulls/comments/186272534"},"html":{"href":"https://github.com/google/swift/pull/31#discussion_r186272534"},"pull_request":{"href":"https://api.github.com/repos/google/swift/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/google/swift/pulls/31","id":186176492,"html_url":"https://github.com/google/swift/pull/31","diff_url":"https://github.com/google/swift/pull/31.diff","patch_url":"https://github.com/google/swift/pull/31.patch","issue_url":"https://api.github.com/repos/google/swift/issues/31","number":31,"state":"open","locked":false,"title":"Bridge `numpy.ndarray` to `Array`, `ShapedArray`, and `Tensor`.","user":{"login":"dan-zheng","id":5590046,"avatar_url":"https://avatars0.githubusercontent.com/u/5590046?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-zheng","html_url":"https://github.com/dan-zheng","followers_url":"https://api.github.com/users/dan-zheng/followers","following_url":"https://api.github.com/users/dan-zheng/following{/other_user}","gists_url":"https://api.github.com/users/dan-zheng/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-zheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-zheng/subscriptions","organizations_url":"https://api.github.com/users/dan-zheng/orgs","repos_url":"https://api.github.com/users/dan-zheng/repos","events_url":"https://api.github.com/users/dan-zheng/events{/privacy}","received_events_url":"https://api.github.com/users/dan-zheng/received_events","type":"User","site_admin":false},"body":"Addresses #30.\r\n\r\nThe bridging implementation is cost-free: the raw data pointer from\r\n`numpy.ndarray` (via `ndarray.__array_interface__[\"data\"]`) is converted to\r\n`UnsafeBufferPointer`.\r\n\r\nThe conversion initializers for `Array` and `ShapedArray` are basically\r\ninstantaneous.\r\n\r\nThe conversion initializer for `Tensor` takes more time since there's no\r\ncost-free bridge to `TF_Tensor` so `TF_AllocateTensor` is called.","created_at":"2018-05-05T21:22:32Z","updated_at":"2018-05-05T21:31:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"570976545dd8c8c067d72515503516b85977e901","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":915157936,"url":"https://api.github.com/repos/google/swift/labels/tensorflow","name":"tensorflow","color":"f6921e","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/google/swift/pulls/31/commits","review_comments_url":"https://api.github.com/repos/google/swift/pulls/31/comments","review_comment_url":"https://api.github.com/repos/google/swift/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/swift/issues/31/comments","statuses_url":"https://api.github.com/repos/google/swift/statuses/d8dfa71504fd1619f3c749fcec2022d7064fe90c","head":{"label":"dan-zheng:numpy-bridging","ref":"numpy-bridging","sha":"d8dfa71504fd1619f3c749fcec2022d7064fe90c","user":{"login":"dan-zheng","id":5590046,"avatar_url":"https://avatars0.githubusercontent.com/u/5590046?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-zheng","html_url":"https://github.com/dan-zheng","followers_url":"https://api.github.com/users/dan-zheng/followers","following_url":"https://api.github.com/users/dan-zheng/following{/other_user}","gists_url":"https://api.github.com/users/dan-zheng/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-zheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-zheng/subscriptions","organizations_url":"https://api.github.com/users/dan-zheng/orgs","repos_url":"https://api.github.com/users/dan-zheng/repos","events_url":"https://api.github.com/users/dan-zheng/events{/privacy}","received_events_url":"https://api.github.com/users/dan-zheng/received_events","type":"User","site_admin":false},"repo":{"id":132274836,"name":"swift","full_name":"dan-zheng/swift","owner":{"login":"dan-zheng","id":5590046,"avatar_url":"https://avatars0.githubusercontent.com/u/5590046?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-zheng","html_url":"https://github.com/dan-zheng","followers_url":"https://api.github.com/users/dan-zheng/followers","following_url":"https://api.github.com/users/dan-zheng/following{/other_user}","gists_url":"https://api.github.com/users/dan-zheng/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-zheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-zheng/subscriptions","organizations_url":"https://api.github.com/users/dan-zheng/orgs","repos_url":"https://api.github.com/users/dan-zheng/repos","events_url":"https://api.github.com/users/dan-zheng/events{/privacy}","received_events_url":"https://api.github.com/users/dan-zheng/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dan-zheng/swift","description":"The Swift Programming Language","fork":true,"url":"https://api.github.com/repos/dan-zheng/swift","forks_url":"https://api.github.com/repos/dan-zheng/swift/forks","keys_url":"https://api.github.com/repos/dan-zheng/swift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dan-zheng/swift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dan-zheng/swift/teams","hooks_url":"https://api.github.com/repos/dan-zheng/swift/hooks","issue_events_url":"https://api.github.com/repos/dan-zheng/swift/issues/events{/number}","events_url":"https://api.github.com/repos/dan-zheng/swift/events","assignees_url":"https://api.github.com/repos/dan-zheng/swift/assignees{/user}","branches_url":"https://api.github.com/repos/dan-zheng/swift/branches{/branch}","tags_url":"https://api.github.com/repos/dan-zheng/swift/tags","blobs_url":"https://api.github.com/repos/dan-zheng/swift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dan-zheng/swift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dan-zheng/swift/git/refs{/sha}","trees_url":"https://api.github.com/repos/dan-zheng/swift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dan-zheng/swift/statuses/{sha}","languages_url":"https://api.github.com/repos/dan-zheng/swift/languages","stargazers_url":"https://api.github.com/repos/dan-zheng/swift/stargazers","contributors_url":"https://api.github.com/repos/dan-zheng/swift/contributors","subscribers_url":"https://api.github.com/repos/dan-zheng/swift/subscribers","subscription_url":"https://api.github.com/repos/dan-zheng/swift/subscription","commits_url":"https://api.github.com/repos/dan-zheng/swift/commits{/sha}","git_commits_url":"https://api.github.com/repos/dan-zheng/swift/git/commits{/sha}","comments_url":"https://api.github.com/repos/dan-zheng/swift/comments{/number}","issue_comment_url":"https://api.github.com/repos/dan-zheng/swift/issues/comments{/number}","contents_url":"https://api.github.com/repos/dan-zheng/swift/contents/{+path}","compare_url":"https://api.github.com/repos/dan-zheng/swift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dan-zheng/swift/merges","archive_url":"https://api.github.com/repos/dan-zheng/swift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dan-zheng/swift/downloads","issues_url":"https://api.github.com/repos/dan-zheng/swift/issues{/number}","pulls_url":"https://api.github.com/repos/dan-zheng/swift/pulls{/number}","milestones_url":"https://api.github.com/repos/dan-zheng/swift/milestones{/number}","notifications_url":"https://api.github.com/repos/dan-zheng/swift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dan-zheng/swift/labels{/name}","releases_url":"https://api.github.com/repos/dan-zheng/swift/releases{/id}","deployments_url":"https://api.github.com/repos/dan-zheng/swift/deployments","created_at":"2018-05-05T18:38:07Z","updated_at":"2018-05-05T18:38:15Z","pushed_at":"2018-05-05T21:21:34Z","git_url":"git://github.com/dan-zheng/swift.git","ssh_url":"git@github.com:dan-zheng/swift.git","clone_url":"https://github.com/dan-zheng/swift.git","svn_url":"https://github.com/dan-zheng/swift","homepage":"https://swift.org/","size":285373,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"contributing"}},"base":{"label":"google:tensorflow","ref":"tensorflow","sha":"3595570e087da19d08ec716f288f3ec1902a938c","user":{"login":"google","id":1342004,"avatar_url":"https://avatars1.githubusercontent.com/u/1342004?v=4","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":110616531,"name":"swift","full_name":"google/swift","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars1.githubusercontent.com/u/1342004?v=4","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/swift","description":"The Swift Programming Language","fork":true,"url":"https://api.github.com/repos/google/swift","forks_url":"https://api.github.com/repos/google/swift/forks","keys_url":"https://api.github.com/repos/google/swift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/swift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/swift/teams","hooks_url":"https://api.github.com/repos/google/swift/hooks","issue_events_url":"https://api.github.com/repos/google/swift/issues/events{/number}","events_url":"https://api.github.com/repos/google/swift/events","assignees_url":"https://api.github.com/repos/google/swift/assignees{/user}","branches_url":"https://api.github.com/repos/google/swift/branches{/branch}","tags_url":"https://api.github.com/repos/google/swift/tags","blobs_url":"https://api.github.com/repos/google/swift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/swift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/swift/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/swift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/swift/statuses/{sha}","languages_url":"https://api.github.com/repos/google/swift/languages","stargazers_url":"https://api.github.com/repos/google/swift/stargazers","contributors_url":"https://api.github.com/repos/google/swift/contributors","subscribers_url":"https://api.github.com/repos/google/swift/subscribers","subscription_url":"https://api.github.com/repos/google/swift/subscription","commits_url":"https://api.github.com/repos/google/swift/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/swift/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/swift/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/swift/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/swift/contents/{+path}","compare_url":"https://api.github.com/repos/google/swift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/swift/merges","archive_url":"https://api.github.com/repos/google/swift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/swift/downloads","issues_url":"https://api.github.com/repos/google/swift/issues{/number}","pulls_url":"https://api.github.com/repos/google/swift/pulls{/number}","milestones_url":"https://api.github.com/repos/google/swift/milestones{/number}","notifications_url":"https://api.github.com/repos/google/swift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/swift/labels{/name}","releases_url":"https://api.github.com/repos/google/swift/releases{/id}","deployments_url":"https://api.github.com/repos/google/swift/deployments","created_at":"2017-11-13T23:55:51Z","updated_at":"2018-05-05T16:03:48Z","pushed_at":"2018-05-05T21:22:33Z","git_url":"git://github.com/google/swift.git","ssh_url":"git@github.com:google/swift.git","clone_url":"https://github.com/google/swift.git","svn_url":"https://github.com/google/swift","homepage":"https://swift.org/","size":285392,"stargazers_count":651,"watchers_count":651,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":35,"mirror_url":null,"archived":false,"open_issues_count":23,"license":null,"forks":35,"open_issues":23,"watchers":651,"default_branch":"contributing"}},"_links":{"self":{"href":"https://api.github.com/repos/google/swift/pulls/31"},"html":{"href":"https://github.com/google/swift/pull/31"},"issue":{"href":"https://api.github.com/repos/google/swift/issues/31"},"comments":{"href":"https://api.github.com/repos/google/swift/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/google/swift/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/google/swift/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/swift/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/google/swift/statuses/d8dfa71504fd1619f3c749fcec2022d7064fe90c"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"rxwei"}}