{"action":"created","comment":{"url":"https://api.github.com/repos/nengo/nengo/pulls/comments/56098567","id":56098567,"diff_hunk":"@@ -68,17 +68,23 @@ def __init__(self, input_vocab, output_vocab=None,  # noqa: C901\n             input_keys = input_vocab.keys\n             input_vectors = input_vocab.vectors\n         else:\n-            input_vectors = input_vocab.create_subset(input_keys).vectors\n+            # parse keys (allows expressions as keys)\n+            input_vectors = [input_vocab.parse(key).v for key in\n+                             input_keys]\n \n         # If output vocabulary is not specified, use input vocabulary\n         # (i.e autoassociative memory)\n         if output_vocab is None:\n             output_vocab = input_vocab\n             output_vectors = input_vectors\n+            output_keys = input_keys","path":"nengo/spa/assoc_mem.py","position":14,"original_position":14,"commit_id":"c8b477a5bfd4599565953425f9a7c082e7925099","original_commit_id":"c8b477a5bfd4599565953425f9a7c082e7925099","user":{"login":"jgosmann","id":850157,"avatar_url":"https://avatars.githubusercontent.com/u/850157?v=3","gravatar_id":"","url":"https://api.github.com/users/jgosmann","html_url":"https://github.com/jgosmann","followers_url":"https://api.github.com/users/jgosmann/followers","following_url":"https://api.github.com/users/jgosmann/following{/other_user}","gists_url":"https://api.github.com/users/jgosmann/gists{/gist_id}","starred_url":"https://api.github.com/users/jgosmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgosmann/subscriptions","organizations_url":"https://api.github.com/users/jgosmann/orgs","repos_url":"https://api.github.com/users/jgosmann/repos","events_url":"https://api.github.com/users/jgosmann/events{/privacy}","received_events_url":"https://api.github.com/users/jgosmann/received_events","type":"User","site_admin":false},"body":"It only gets used in the `else` block which initializes it itself if necessary.","created_at":"2016-03-15T00:20:57Z","updated_at":"2016-03-15T00:20:57Z","html_url":"https://github.com/nengo/nengo/pull/982#discussion_r56098567","pull_request_url":"https://api.github.com/repos/nengo/nengo/pulls/982","_links":{"self":{"href":"https://api.github.com/repos/nengo/nengo/pulls/comments/56098567"},"html":{"href":"https://github.com/nengo/nengo/pull/982#discussion_r56098567"},"pull_request":{"href":"https://api.github.com/repos/nengo/nengo/pulls/982"}}},"pull_request":{"url":"https://api.github.com/repos/nengo/nengo/pulls/982","id":62813294,"html_url":"https://github.com/nengo/nengo/pull/982","diff_url":"https://github.com/nengo/nengo/pull/982.diff","patch_url":"https://github.com/nengo/nengo/pull/982.patch","issue_url":"https://api.github.com/repos/nengo/nengo/issues/982","number":982,"state":"open","locked":false,"title":"Provide SP expressions as keys to the SPA associative memory","user":{"login":"ikajic","id":2485670,"avatar_url":"https://avatars.githubusercontent.com/u/2485670?v=3","gravatar_id":"","url":"https://api.github.com/users/ikajic","html_url":"https://github.com/ikajic","followers_url":"https://api.github.com/users/ikajic/followers","following_url":"https://api.github.com/users/ikajic/following{/other_user}","gists_url":"https://api.github.com/users/ikajic/gists{/gist_id}","starred_url":"https://api.github.com/users/ikajic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ikajic/subscriptions","organizations_url":"https://api.github.com/users/ikajic/orgs","repos_url":"https://api.github.com/users/ikajic/repos","events_url":"https://api.github.com/users/ikajic/events{/privacy}","received_events_url":"https://api.github.com/users/ikajic/received_events","type":"User","site_admin":false},"body":"I needed this scenario for my model, so I decided to submit a PR in case it might be of interest for others. Currently, only single keys can be passed as the input and output keys to the associative memory module. This PR slightly changes the existing code so that it also supports expressions in both input or output keys. Then something like this can be done:\r\n\r\n```python\r\nimport nengo\r\nfrom nengo import spa\r\n\r\nwith spa.SPA() as model:\r\n    D = 16\r\n    \r\n    voc1 = spa.Vocabulary(D)\r\n    voc2 = spa.Vocabulary(D)\r\n    \r\n    voc1.parse('A+B+C')\r\n    voc2.parse('D+E+F')\r\n    \r\n    in_keys = ['A', 'B+C']\r\n    out_keys = ['D-E', '0.4*F']\r\n    \r\n    model.am = spa.AssociativeMemory(input_vocab=voc1,\r\n                                     output_vocab=voc2,\r\n                                     input_keys=in_keys,\r\n                                     output_keys=out_keys\r\n                                    )\r\n    model.inp = spa.State(D, vocab=voc1)\r\n    nengo.Connection(model.inp.output, model.am.input)\r\n```","created_at":"2016-03-14T20:37:52Z","updated_at":"2016-03-15T00:20:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"470ddd06aa34ce48aa284b317ce2b960aed77b52","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nengo/nengo/pulls/982/commits","review_comments_url":"https://api.github.com/repos/nengo/nengo/pulls/982/comments","review_comment_url":"https://api.github.com/repos/nengo/nengo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nengo/nengo/issues/982/comments","statuses_url":"https://api.github.com/repos/nengo/nengo/statuses/c8b477a5bfd4599565953425f9a7c082e7925099","head":{"label":"nengo:spaassocmem-keys-as-expr","ref":"spaassocmem-keys-as-expr","sha":"c8b477a5bfd4599565953425f9a7c082e7925099","user":{"login":"nengo","id":9197486,"avatar_url":"https://avatars.githubusercontent.com/u/9197486?v=3","gravatar_id":"","url":"https://api.github.com/users/nengo","html_url":"https://github.com/nengo","followers_url":"https://api.github.com/users/nengo/followers","following_url":"https://api.github.com/users/nengo/following{/other_user}","gists_url":"https://api.github.com/users/nengo/gists{/gist_id}","starred_url":"https://api.github.com/users/nengo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nengo/subscriptions","organizations_url":"https://api.github.com/users/nengo/orgs","repos_url":"https://api.github.com/users/nengo/repos","events_url":"https://api.github.com/users/nengo/events{/privacy}","received_events_url":"https://api.github.com/users/nengo/received_events","type":"Organization","site_admin":false},"repo":{"id":9568894,"name":"nengo","full_name":"nengo/nengo","owner":{"login":"nengo","id":9197486,"avatar_url":"https://avatars.githubusercontent.com/u/9197486?v=3","gravatar_id":"","url":"https://api.github.com/users/nengo","html_url":"https://github.com/nengo","followers_url":"https://api.github.com/users/nengo/followers","following_url":"https://api.github.com/users/nengo/following{/other_user}","gists_url":"https://api.github.com/users/nengo/gists{/gist_id}","starred_url":"https://api.github.com/users/nengo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nengo/subscriptions","organizations_url":"https://api.github.com/users/nengo/orgs","repos_url":"https://api.github.com/users/nengo/repos","events_url":"https://api.github.com/users/nengo/events{/privacy}","received_events_url":"https://api.github.com/users/nengo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nengo/nengo","description":"A Python library for creating and simulating large-scale brain models","fork":false,"url":"https://api.github.com/repos/nengo/nengo","forks_url":"https://api.github.com/repos/nengo/nengo/forks","keys_url":"https://api.github.com/repos/nengo/nengo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nengo/nengo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nengo/nengo/teams","hooks_url":"https://api.github.com/repos/nengo/nengo/hooks","issue_events_url":"https://api.github.com/repos/nengo/nengo/issues/events{/number}","events_url":"https://api.github.com/repos/nengo/nengo/events","assignees_url":"https://api.github.com/repos/nengo/nengo/assignees{/user}","branches_url":"https://api.github.com/repos/nengo/nengo/branches{/branch}","tags_url":"https://api.github.com/repos/nengo/nengo/tags","blobs_url":"https://api.github.com/repos/nengo/nengo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nengo/nengo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nengo/nengo/git/refs{/sha}","trees_url":"https://api.github.com/repos/nengo/nengo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nengo/nengo/statuses/{sha}","languages_url":"https://api.github.com/repos/nengo/nengo/languages","stargazers_url":"https://api.github.com/repos/nengo/nengo/stargazers","contributors_url":"https://api.github.com/repos/nengo/nengo/contributors","subscribers_url":"https://api.github.com/repos/nengo/nengo/subscribers","subscription_url":"https://api.github.com/repos/nengo/nengo/subscription","commits_url":"https://api.github.com/repos/nengo/nengo/commits{/sha}","git_commits_url":"https://api.github.com/repos/nengo/nengo/git/commits{/sha}","comments_url":"https://api.github.com/repos/nengo/nengo/comments{/number}","issue_comment_url":"https://api.github.com/repos/nengo/nengo/issues/comments{/number}","contents_url":"https://api.github.com/repos/nengo/nengo/contents/{+path}","compare_url":"https://api.github.com/repos/nengo/nengo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nengo/nengo/merges","archive_url":"https://api.github.com/repos/nengo/nengo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nengo/nengo/downloads","issues_url":"https://api.github.com/repos/nengo/nengo/issues{/number}","pulls_url":"https://api.github.com/repos/nengo/nengo/pulls{/number}","milestones_url":"https://api.github.com/repos/nengo/nengo/milestones{/number}","notifications_url":"https://api.github.com/repos/nengo/nengo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nengo/nengo/labels{/name}","releases_url":"https://api.github.com/repos/nengo/nengo/releases{/id}","deployments_url":"https://api.github.com/repos/nengo/nengo/deployments","created_at":"2013-04-20T18:46:06Z","updated_at":"2016-03-11T18:08:55Z","pushed_at":"2016-03-14T21:16:49Z","git_url":"git://github.com/nengo/nengo.git","ssh_url":"git@github.com:nengo/nengo.git","clone_url":"https://github.com/nengo/nengo.git","svn_url":"https://github.com/nengo/nengo","homepage":"","size":24585,"stargazers_count":105,"watchers_count":105,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":238,"forks":35,"open_issues":238,"watchers":105,"default_branch":"master"}},"base":{"label":"nengo:master","ref":"master","sha":"b428223719b337b2fee72c8f7b2b652b0b1aa59f","user":{"login":"nengo","id":9197486,"avatar_url":"https://avatars.githubusercontent.com/u/9197486?v=3","gravatar_id":"","url":"https://api.github.com/users/nengo","html_url":"https://github.com/nengo","followers_url":"https://api.github.com/users/nengo/followers","following_url":"https://api.github.com/users/nengo/following{/other_user}","gists_url":"https://api.github.com/users/nengo/gists{/gist_id}","starred_url":"https://api.github.com/users/nengo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nengo/subscriptions","organizations_url":"https://api.github.com/users/nengo/orgs","repos_url":"https://api.github.com/users/nengo/repos","events_url":"https://api.github.com/users/nengo/events{/privacy}","received_events_url":"https://api.github.com/users/nengo/received_events","type":"Organization","site_admin":false},"repo":{"id":9568894,"name":"nengo","full_name":"nengo/nengo","owner":{"login":"nengo","id":9197486,"avatar_url":"https://avatars.githubusercontent.com/u/9197486?v=3","gravatar_id":"","url":"https://api.github.com/users/nengo","html_url":"https://github.com/nengo","followers_url":"https://api.github.com/users/nengo/followers","following_url":"https://api.github.com/users/nengo/following{/other_user}","gists_url":"https://api.github.com/users/nengo/gists{/gist_id}","starred_url":"https://api.github.com/users/nengo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nengo/subscriptions","organizations_url":"https://api.github.com/users/nengo/orgs","repos_url":"https://api.github.com/users/nengo/repos","events_url":"https://api.github.com/users/nengo/events{/privacy}","received_events_url":"https://api.github.com/users/nengo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nengo/nengo","description":"A Python library for creating and simulating large-scale brain models","fork":false,"url":"https://api.github.com/repos/nengo/nengo","forks_url":"https://api.github.com/repos/nengo/nengo/forks","keys_url":"https://api.github.com/repos/nengo/nengo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nengo/nengo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nengo/nengo/teams","hooks_url":"https://api.github.com/repos/nengo/nengo/hooks","issue_events_url":"https://api.github.com/repos/nengo/nengo/issues/events{/number}","events_url":"https://api.github.com/repos/nengo/nengo/events","assignees_url":"https://api.github.com/repos/nengo/nengo/assignees{/user}","branches_url":"https://api.github.com/repos/nengo/nengo/branches{/branch}","tags_url":"https://api.github.com/repos/nengo/nengo/tags","blobs_url":"https://api.github.com/repos/nengo/nengo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nengo/nengo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nengo/nengo/git/refs{/sha}","trees_url":"https://api.github.com/repos/nengo/nengo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nengo/nengo/statuses/{sha}","languages_url":"https://api.github.com/repos/nengo/nengo/languages","stargazers_url":"https://api.github.com/repos/nengo/nengo/stargazers","contributors_url":"https://api.github.com/repos/nengo/nengo/contributors","subscribers_url":"https://api.github.com/repos/nengo/nengo/subscribers","subscription_url":"https://api.github.com/repos/nengo/nengo/subscription","commits_url":"https://api.github.com/repos/nengo/nengo/commits{/sha}","git_commits_url":"https://api.github.com/repos/nengo/nengo/git/commits{/sha}","comments_url":"https://api.github.com/repos/nengo/nengo/comments{/number}","issue_comment_url":"https://api.github.com/repos/nengo/nengo/issues/comments{/number}","contents_url":"https://api.github.com/repos/nengo/nengo/contents/{+path}","compare_url":"https://api.github.com/repos/nengo/nengo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nengo/nengo/merges","archive_url":"https://api.github.com/repos/nengo/nengo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nengo/nengo/downloads","issues_url":"https://api.github.com/repos/nengo/nengo/issues{/number}","pulls_url":"https://api.github.com/repos/nengo/nengo/pulls{/number}","milestones_url":"https://api.github.com/repos/nengo/nengo/milestones{/number}","notifications_url":"https://api.github.com/repos/nengo/nengo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nengo/nengo/labels{/name}","releases_url":"https://api.github.com/repos/nengo/nengo/releases{/id}","deployments_url":"https://api.github.com/repos/nengo/nengo/deployments","created_at":"2013-04-20T18:46:06Z","updated_at":"2016-03-11T18:08:55Z","pushed_at":"2016-03-14T21:16:49Z","git_url":"git://github.com/nengo/nengo.git","ssh_url":"git@github.com:nengo/nengo.git","clone_url":"https://github.com/nengo/nengo.git","svn_url":"https://github.com/nengo/nengo","homepage":"","size":24585,"stargazers_count":105,"watchers_count":105,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":238,"forks":35,"open_issues":238,"watchers":105,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nengo/nengo/pulls/982"},"html":{"href":"https://github.com/nengo/nengo/pull/982"},"issue":{"href":"https://api.github.com/repos/nengo/nengo/issues/982"},"comments":{"href":"https://api.github.com/repos/nengo/nengo/issues/982/comments"},"review_comments":{"href":"https://api.github.com/repos/nengo/nengo/pulls/982/comments"},"review_comment":{"href":"https://api.github.com/repos/nengo/nengo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nengo/nengo/pulls/982/commits"},"statuses":{"href":"https://api.github.com/repos/nengo/nengo/statuses/c8b477a5bfd4599565953425f9a7c082e7925099"}}}}