{
"id": "fn-gpu-apply_activation",
"dataComponent": "gpu",
"heading": {
"title": "apply_activation",
"badges": ["GPU"]
},
"synopsis": "Applies a specified activation function (e.g., 'relu', 'sigmoid', 'tanh') elementwise to a tensor on the GPU.",
"codeBlocks": [
"extend(\"gpu\")\n\nA = gpu:to_tensor([[1.0,-2.0],[3.0,-4.5]])\nB = gpu:apply_activation(\"relu\", A)\n# => [[1.0,0.0],[3.0,0.0]]\nsput(B)\n\nC = gpu:apply_activation(\"sigmoid\", A)\n# => each element => 1 / (1 + exp(-x))\n\n# Use cases:\n# 1) Neural network forward pass for hidden layers.\n# 2) Custom elementwise activation in GPU-based data pipelines."
],
"notes": [
"gpu:apply_activation expects 2 arguments: (Str activationName, Tensor).",
"Supported strings might be 'relu', 'sigmoid', 'tanh', or others depending on bridging. If unknown, raises an error.",
"Returns a new tensor of the same shape, with each element replaced by the activation function result."
]
}