What does the asinh function do in MATLAB / RunMat?
Y = asinh(X) evaluates the inverse hyperbolic sine of every element in X. Results match MATLAB
semantics for real, logical, character, and complex inputs, including branch cut handling for complex
numbers.
How does the asinh function behave in MATLAB / RunMat?
- Accepts scalars, vectors, matrices, and N-D tensors and applies the operation element-wise using MATLAB's broadcasting rules.
- Logical inputs are promoted to doubles (
true → 1.0,false → 0.0) before the inverse hyperbolic sine is applied. - Character arrays are interpreted as numeric code points and return dense double arrays with the same shape.
- Real inputs produce real outputs for all finite values. Complex inputs follow MATLAB's principal branch definition
asinh(z) = log(z + sqrt(z^2 + 1)). - NaNs and infinities propagate according to IEEE arithmetic and match MATLAB's special-case tables.
asinh Function GPU Execution Behaviour
RunMat Accelerate keeps tensors on the GPU when:
- A provider is registered and implements the
unary_asinhhook. - The inputs do not require complex promotion that the provider cannot represent.
If either condition is not met, RunMat gathers the data to the host, evaluates asinh with the CPU
reference implementation, and returns the correct MATLAB result. This guarantees correctness without
forcing users to manually call gpuArray or gather.
Examples of using the asinh function in MATLAB / RunMat
Inverse hyperbolic sine of a scalar
y = asinh(0.5);
Expected output:
y = 0.4812
Applying asinh to every element of a vector
x = linspace(-2, 2, 5);
y = asinh(x);
Expected output:
y = [-1.4436 -0.9624 0 0.9624 1.4436]
Evaluating asinh on a matrix
A = [0 -0.5 1.0; 1.5 -2.0 3.0];
B = asinh(A);
Expected output:
B =
0 -0.4812 0.8814
1.1948 -1.4436 1.8184
Computing asinh on GPU data
G = gpuArray([0.25 0.5; 0.75 1.0]);
result_gpu = asinh(G);
result = gather(result_gpu);
Expected output:
result = [0.2470 0.4812; 0.6931 0.8814]
Handling complex arguments with asinh
z = [1 + 2i, -0.5 + 0.75i];
w = asinh(z);
Expected output:
w =
1.4694 + 1.0634i
-0.4306 + 0.5770i
Using asinh inside fused GPU expressions
G = gpuArray(rand(1024, 1));
Y = sinh(G) + asinh(G);
Expected behavior: The fusion planner keeps the entire expression on the GPU when the provider
implements unary_sinh and unary_asinh.
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 hooks (unary_asinh) and the runtime can keep
the data in real form. When the GPU path is incomplete, RunMat gathers to the host automatically and
still returns MATLAB-compatible results. Manual gpuArray / gather remains available for workflows
that require explicit residency control.
FAQ
Does asinh ever return complex numbers for real inputs?
No. Real arguments always produce real results. Complex outputs arise only when the inputs themselves are complex.
How are logical or integer inputs handled?
They are promoted to double precision before evaluation, mirroring MATLAB's behavior. The result is returned as a dense double tensor (or complex tensor for complex inputs).
What happens if the GPU provider lacks unary_asinh?
RunMat gathers the data to the host, evaluates asinh on the CPU, and keeps the result on the host
unless a downstream operation requests GPU residency.
Is there a precision difference between CPU and GPU outputs?
Both paths operate in the provider's precision (f32 or f64). Small rounding differences may appear
near very large magnitudes, but the results stay within MATLAB's tolerance specs.
Can asinh participate in fusion?
Yes. Element-wise fusion templates include asinh, allowing the fusion planner to inline it alongside
other unary operations when generating WGSL kernels.
How are character arrays processed?
They are interpreted as their Unicode code points, converted to doubles, and then passed through
asinh, producing a numeric array that matches MATLAB's output.
What happens with NaN or Inf values?
NaNs propagate unchanged. Positive and negative infinities map to infinities with the same sign, matching MATLAB's special-case rules.
Can I keep complex results on the GPU?
Currently GPU tensor handles represent real data. When complex values arise, RunMat returns host-resident
Value::Complex or Value::ComplexTensor results to remain MATLAB-compatible.
Does asinh support automatic differentiation plans?
Yes. The fusion and acceleration metadata mark asinh as an element-wise operation, so future autodiff
infrastructure can reuse the same kernel hooks.
See Also
sinh, tanh, sin, gpuArray, gather
Source & Feedback
- The full source code for the implementation of the
asinhfunction is available at:crates/runmat-runtime/src/builtins/math/trigonometry/asinh.rs - Found a bug or behavioral difference? Please open an issue with details and a minimal repro.