Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Last active November 3, 2017 12:12
Show Gist options
  • Save SimonDanisch/40b174729152578eb21b5edab7cca4ca to your computer and use it in GitHub Desktop.
Save SimonDanisch/40b174729152578eb21b5edab7cca4ca to your computer and use it in GitHub Desktop.
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