{"action":"created","issue":{"url":"https://api.github.com/repos/kyonifer/koma/issues/47","repository_url":"https://api.github.com/repos/kyonifer/koma","labels_url":"https://api.github.com/repos/kyonifer/koma/issues/47/labels{/name}","comments_url":"https://api.github.com/repos/kyonifer/koma/issues/47/comments","events_url":"https://api.github.com/repos/kyonifer/koma/issues/47/events","html_url":"https://github.com/kyonifer/koma/issues/47","id":308405358,"node_id":"MDU6SXNzdWUzMDg0MDUzNTg=","number":47,"title":"Make NDArray's map function generic","user":{"login":"drmoose","id":5732028,"node_id":"MDQ6VXNlcjU3MzIwMjg=","avatar_url":"https://avatars2.githubusercontent.com/u/5732028?v=4","gravatar_id":"","url":"https://api.github.com/users/drmoose","html_url":"https://github.com/drmoose","followers_url":"https://api.github.com/users/drmoose/followers","following_url":"https://api.github.com/users/drmoose/following{/other_user}","gists_url":"https://api.github.com/users/drmoose/gists{/gist_id}","starred_url":"https://api.github.com/users/drmoose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drmoose/subscriptions","organizations_url":"https://api.github.com/users/drmoose/orgs","repos_url":"https://api.github.com/users/drmoose/repos","events_url":"https://api.github.com/users/drmoose/events{/privacy}","received_events_url":"https://api.github.com/users/drmoose/received_events","type":"User","site_admin":false},"labels":[{"id":331362849,"node_id":"MDU6TGFiZWwzMzEzNjI4NDk=","url":"https://api.github.com/repos/kyonifer/koma/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":26,"created_at":"2018-03-26T01:13:33Z","updated_at":"2018-10-13T19:57:08Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"[`NDArray`'s `map`](https://github.com/kyonifer/koma/blob/master/koma-core-api/common/src/koma/ndarray/NDArray.kt#L51) is defined as `fun map(f: (T) -> T): NDArray<T>`. It would be more useful if  `map` were a generic, in the sense of `fun map<R>(f: (T) -> R): NDArray<R>`.\r\n\r\nHere's some sample code which I'd like to compile, but can't:\r\n\r\n```\r\nvar counter = 0\r\nval ints: NDArray<Int> = DefaultNDArray(3, 4, 5) { ++counter }\r\nval doubles: NDArray<Double> = ints.map { it.toDouble() }\r\n```\r\n\r\nCurrently I'm using the following hacky workaround, which is dangerous and insane but seems to work.\r\n\r\n```\r\nfun <TIn, TOut> NDArray<TIn>.crazyMapWorkaround(fn: (TIn) -> TOut) = \r\n    toIterable().iterator().let { itr ->\r\n        DefaultNDArray(*(shape().toIntArray())) { fn(itr.next()) }\r\n    }\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/kyonifer/koma/issues/comments/429570698","html_url":"https://github.com/kyonifer/koma/issues/47#issuecomment-429570698","issue_url":"https://api.github.com/repos/kyonifer/koma/issues/47","id":429570698,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTU3MDY5OA==","user":{"login":"peastman","id":4379786,"node_id":"MDQ6VXNlcjQzNzk3ODY=","avatar_url":"https://avatars3.githubusercontent.com/u/4379786?v=4","gravatar_id":"","url":"https://api.github.com/users/peastman","html_url":"https://github.com/peastman","followers_url":"https://api.github.com/users/peastman/followers","following_url":"https://api.github.com/users/peastman/following{/other_user}","gists_url":"https://api.github.com/users/peastman/gists{/gist_id}","starred_url":"https://api.github.com/users/peastman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peastman/subscriptions","organizations_url":"https://api.github.com/users/peastman/orgs","repos_url":"https://api.github.com/users/peastman/repos","events_url":"https://api.github.com/users/peastman/events{/privacy}","received_events_url":"https://api.github.com/users/peastman/received_events","type":"User","site_admin":false},"created_at":"2018-10-13T19:57:08Z","updated_at":"2018-10-13T19:57:08Z","author_association":"NONE","body":"```kotliin\r\ninline fun <reified T> NDArray<Double>.testMap(crossinline f: (Double) -> T)\r\n        = NDArray(*shape().toIntArray(), filler={ f(this.getDouble(*it)) } )\r\n```\r\n\r\nThis version turns out to be about 50% slower in my test.  The reason is that `NDArray.invoke()` uses `fill()` instead of `fillLinear()`.  I'd like to create an alternate version where `filler` is an `(Int) -> T` instead of `(IntArray) -> T`, so it can use the more efficient `fillLinear()`.  But that would break type inference when `filler` was a lambda (the compiler couldn't automatically determine what its input was meant to be).  So it would have to have a different name, or go in a different class, or perhaps just be private.  What do you prefer?"}}
{"actor":{"display_login":"peastman"}}