Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread David Sweeris via swift-users
> On Dec 16, 2016, at 15:54, Richard Wei via swift-users > wrote: > > Thanks. That’s true, but there are cases (like making BLAS calls) where I > have to nest more than 4 `withUnsafeMutable…` closures. It’s safe by really > clumsy. I just wish there were a cleaner way

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Richard Wei via swift-users
Thanks. That’s true, but there are cases (like making BLAS calls) where I have to nest more than 4 `withUnsafeMutable…` closures. It’s safe by really clumsy. I just wish there were a cleaner way that looks like the do-notation in Haskell or for-notation in Scala. -Richard > On Dec 16, 2016,

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Joe Groff via swift-users
> On Dec 16, 2016, at 12:10 PM, Richard Wei wrote: > > `sync` is not escaping. Shadow copy causes the device memory to make a copy, > which can’t be a solution either. I’ll file a radar. > >> Note that, independently, this part looks fishy: >> >>> try! fill<<<(blockSize,

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Joe Groff via swift-users
> On Dec 15, 2016, at 11:46 PM, Richard Wei via swift-users > wrote: > > Hi, > > Swift 3.0.2 seems to have broken my code due to mutating self capture. But I > have to pass inout self to the closure. Any workaround? > > let blockSize = min(512, count) > let

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Zhao Xin via swift-users
Below code should work: let blockSize = min(512, count) let blockCount = (count+blockSize-1)/blockSize let boxedClosure = { (foo:inout MutableDeviceCollection) -> () in device.sync { // Launch CUDA kernel try! fill<<<(blockSize, blockCount)>>>[

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Richard Wei via swift-users
It’s not the correct choice here :) > On Dec 16, 2016, at 03:04, Rien wrote: > > Just because it is called “Unsafe” does not mean it is unsafe :-) > It all depends on how you use it. > > Regards, > Rien > > Site: http://balancingrock.nl > Blog:

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Rien via swift-users
Just because it is called “Unsafe” does not mean it is unsafe :-) It all depends on how you use it. Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 16 Dec 2016, at 09:52, Richard Wei

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Zhao Xin via swift-users
What is the type of self? If it is a class, try [unowned self]. Zhaoxin On Fri, Dec 16, 2016 at 4:33 PM, Rien via swift-users wrote: > How about using: > > UnsafeMutablePointer > > ? > > Regards, > Rien > > Site: http://balancingrock.nl > Blog:

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Rien via swift-users
How about using: UnsafeMutablePointer ? Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Swiftrien Project: http://swiftfire.nl > On 16 Dec 2016, at 09:10, Richard Wei via swift-users > wrote: > > Capturing

Re: [swift-users] Implicitly capture a mutating self

2016-12-16 Thread Zhao Xin via swift-users
I did not test the code. But if you cannot implicitly capture a mutating self, you should do it explicitly, right? let blockSize = min(512, count) let blockCount = (count+blockSize-1)/blockSize device.sync { *[self] () -> () in* // Launch CUDA kernel try! fill<<<(blockSize, blockCount)>>>[

[swift-users] Implicitly capture a mutating self

2016-12-15 Thread Richard Wei via swift-users
Hi, Swift 3.0.2 seems to have broken my code due to mutating self capture. But I have to pass inout self to the closure. Any workaround? let blockSize = min(512, count) let blockCount = (count+blockSize-1)/blockSize device.sync { // Launch CUDA kernel try! fill<<<(blockSize,