Signature
Description
Finds and returns the value in an array that is numerically closest to a target value. This utility method is commonly used to find the nearest supported scale factor or noise level when the exact desired value is not available. For example, if a model supports scales[2, 3, 4] and you want to upscale by 3.5x, this method will return 4 as the closest supported scale.
Parameters
number[]
required
Array of numbers to search. Typically contains supported scale factors or noise levels from a model.
number
required
The target value to find the closest match for.
Returns
number
The value from the array that is numerically closest to the target. If two values are equally close, returns the smaller value.
Examples
Find closest supported scale
Find closest noise level
Validate and adjust scale
Find closest from custom array
Dynamic scale selection
Handling edge cases
Build UI with valid options
Related
- model - Get model information with supported scales
- pipeline - Process images with validated scales
- ModelObject - Model information including scales and noise levels