public static Tensor Tanh(Tensor input) { #if ENABLE_COMPUTE return(GpuHelper.InvokeFunctionKernel("Tanh", input)); #else var data = new float[input.Data.Length]; for (var i = 0; i < data.Length; i++) { data[i] = (float)System.Math.Tanh(input.Data[i]); } return(new Tensor(input.Shape, data)); #endif }
public static Tensor Relu(Tensor input) { #if ENABLE_COMPUTE return(GpuHelper.InvokeFunctionKernel("Relu", input)); #else var data = new float[input.Data.Length]; for (var i = 0; i < data.Length; i++) { var v = input.Data[i]; data[i] = v < 0 ? 0 : v; } return(new Tensor(input.Shape, data)); #endif }
public static Tensor LeakyRelu(Tensor input, float alpha) { #if ENABLE_COMPUTE Pix2PixResources.Compute.SetFloat("Alpha", alpha); return(GpuHelper.InvokeFunctionKernel("LeakyRelu", input)); #else var data = new float[input.Data.Length]; for (var i = 0; i < data.Length; i++) { var v = input.Data[i]; data[i] = v < 0 ? v * alpha : v; } return(new Tensor(input.Shape, data)); #endif }