Last active
November 3, 2017 12:12
-
-
Save SimonDanisch/40b174729152578eb21b5edab7cca4ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using CLArrays | |
| # `where T` is Julias way of declaring a free type parameter | |
| function replace_with(input::AbstractArray{T}, name, with) where T | |
| fsname, fswith = T(name), T(with) # convert args to element type | |
| # creates an unitiliazed array similar to input | |
| output = similar(input) | |
| # now replace elements on the gpu | |
| map!(n-> n == fsname ? fswith : n, output, input) | |
| output | |
| end | |
| # Inheritance: CLArray <: GPUArray <: AbstractArray | |
| test = CLArray([1, 2, 3, 4, 5]) | |
| julia> replace_with(test, 2, 42) | |
| GPU: 5-element Array{Int64,1}: | |
| 1 | |
| 42 | |
| 3 | |
| 4 | |
| 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment