What does the sinh function do in MATLAB / RunMat?
Y = sinh(X) computes the hyperbolic sine of every element in X, treating angles as real numbers and extending naturally to complex values.
How does the sinh function behave in MATLAB / RunMat?
- Works on scalars, vectors, matrices, and N-D tensors with MATLAB broadcasting semantics.
- Logical inputs are converted to double precision (
true → 1.0,false → 0.0) before evaluation. - Complex inputs follow the analytic definition
sinh(a + bi) = sinh(a)cos(b) + i·cosh(a)sin(b), propagatingNaN/Infcomponents independently. - Character arrays are converted to their numeric code points prior to evaluation, returning double arrays of the same size.
- Empty arrays return empty results that respect MATLAB’s shape semantics.
sinh Function GPU Execution Behaviour
When RunMat Accelerate is active, tensors that already reside on the GPU stay there. Providers that implement unary_sinh execute the operation entirely on the device (and fused elementwise kernels can inline sinh as part of a larger expression). If the active provider lacks this hook, RunMat gathers the data back to the host, computes the result, and re-uploads only when later operations require GPU residency.
Examples of using the sinh function in MATLAB / RunMat
Compute the hyperbolic sine of a scalar value
y = sinh(1);
Expected output:
y = 1.1752;
Apply sinh to each element of a vector
x = linspace(-1, 1, 5);
y = sinh(x);
Expected output:
y = [-1.1752 -0.5211 0 0.5211 1.1752];
Evaluate sinh on a matrix
A = [0 1; 2 3];
B = sinh(A);
Expected output:
B = [0 1.1752; 3.6269 10.0179];
Compute the hyperbolic sine on the GPU
G = gpuArray([0.25 0.5; 0.75 1.0]);
result_gpu = sinh(G);
result = gather(result_gpu);
Expected output:
result = [0.2526 0.5211; 0.8223 1.1752];
Work with complex inputs
z = 1 + 2i;
w = sinh(z);
Expected output:
w = -0.4891 + 1.4031i;
GPU residency in RunMat (Do I need gpuArray?)
You usually do not need to call gpuArray explicitly. The fusion planner keeps tensors on the GPU whenever the active provider exposes the necessary kernels (such as unary_sinh). Manual gpuArray / gather calls remain supported for MATLAB compatibility or when you need to pin residency before interacting with external code.
FAQ
When should I use sinh?
Use sinh for hyperbolic sine transformations, signal-processing workflows, and analytic continuations where the hyperbolic trigonometric family is required.
Does sinh work with complex numbers?
Yes. The real and imaginary parts are evaluated using the analytic definition sinh(a + bi) = sinh(a)cos(b) + i·cosh(a)sin(b).
What happens if the provider does not implement unary_sinh?
RunMat gathers the GPU tensor to host memory, performs the computation on the CPU, and leaves the result on the host unless later operations require GPU residency.
Can sinh participate in fusion?
Yes. The fusion planner can inline sinh inside elementwise groups, generating WGSL kernels that execute directly on the GPU.
Does sinh respect MATLAB broadcasting rules?
It operates elementwise and therefore respects the same scalar-expansion (broadcasting) semantics as other MATLAB math functions in RunMat.
Are integers preserved?
Inputs are promoted to double precision before evaluation. To keep data in integer form, perform downstream casting explicitly.
How does sinh handle NaN or Inf values?
Hyperbolic functions propagate NaN and Inf components consistently with MATLAB. For complex inputs, each component is treated independently.
Can I combine sinh with other hyperbolic functions?
Yes. sinh, cosh, and tanh will share the same residency rules. Fused expressions can include any combination of elementwise builtins.
Is there a GPU warmup penalty?
Providers may warm up pipelines during initialization. If unary_sinh is unavailable, the CPU fallback ensures correctness without warmup.
See Also
sin, cos, tan, gpuArray, gather
Source & Feedback
- The full source code for the implementation of the
sinhfunction is available at:crates/runmat-runtime/src/builtins/math/trigonometry/sinh.rs - Found a bug or behavioral difference? Please open an issue with details and a minimal repro.