code: def test_apply_scaling():
      # Null scaling, same array returned
      arr = np.zeros((3,), dtype=np.int16)
      assert apply_read_scaling(arr) is arr
      assert apply_read_scaling(arr, np.float64(1.0)) is arr
      assert apply_read_scaling(arr, inter=np.float64(0)) is arr
      f32, f64 = np.float32, np.float64
      f32_arr = np.zeros((1,), dtype=f32)
      i16_arr = np.zeros((1,), dtype=np.int16)
      # Check float upcast (not the normal numpy scalar rule)
      # This is the normal rule - no upcast from Python scalar
      assert (f32_arr * 1.0).dtype == np.float32
      assert (f32_arr + 1.0).dtype == np.float32
      # This is the normal rule - no upcast from scalar
      # before NumPy 2.0, after 2.0, it upcasts
      want_dtype = np.float64 if NP_2 else np.float32
      assert (f32_arr * f64(1)).dtype == want_dtype
      assert (f32_arr + f64(1)).dtype == want_dtype
      # The function does upcast though
      ret = apply_read_scaling(np.float32(0), np.float64(2))
      assert ret.dtype == np.float64
      ret = apply_read_scaling(np.float32(0), inter=np.float64(2))
      assert ret.dtype == np.float64
      # Check integer inf upcast
      big = f32(type_info(f32)["max"])
      # Normally this would not upcast
      assert (i16_arr * big).dtype == np.float32
      # An equivalent case is a little hard to find for the intercept
      nmant_32 = type_info(np.float32)["nmant"]
      big_delta = np.float32(2 ** (floor_log2(big) - nmant_32))
      assert (i16_arr * big_delta + big).dtype == np.float32
      # Upcasting does occur with this routine
      assert apply_read_scaling(i16_arr, big).dtype == np.float64
      assert (
          apply_read_scaling(i16_arr, big_delta, big).dtype
          == np.float64
      )
      # If float32 passed, no overflow, float32 returned
      assert (
          apply_read_scaling(np.int8(0), f32(-1.0), f32(0.0)).dtype
          == np.float32
      )
      # float64 passed, float64 returned
      assert (
          apply_read_scaling(np.int8(0), -1.0, 0.0).dtype == np.float64
      )
      # float32 passed, overflow, float64 returned
      assert (
          apply_read_scaling(np.int8(0), f32(1e38), f32(0.0)).dtype
          == np.float64
      )
      assert (
          apply_read_scaling(np.int8(0), f32(-1e38), f32(0.0)).dtype
          == np.float64
      )
      # Non-zero intercept still generates floats
      assert_dt_equal(
          apply_read_scaling(i16_arr, 1.0, 1.0).dtype, float
      )
      assert_dt_equal(
          apply_read_scaling(
              np.zeros((1,), dtype=np.int32), 1.0, 1.0
          ).dtype,
          float,
      )
      assert_dt_equal(
          apply_read_scaling(
              np.zeros((1,), dtype=np.int64), 1.0, 1.0
          ).dtype,
          float,
      )
  
imports: import bz2
  import functools
  import gzip
  import itertools
  import os
  import tempfile
  import threading
  import time
  import warnings
  from io import BytesIO
  from os.path import exists
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from packaging.version import Version
  from nibabel.testing import assert_allclose_safely, assert_dt_equal, error_warnings, suppress_warnings
  from ..casting import OK_FLOATS, floor_log2, sctypes, shared_range, type_info
  from ..openers import BZ2File, ImageOpener, Opener
  from ..optpkg import optional_package
  from ..tmpdirs import InTemporaryDirectory
  from ..volumeutils import _dt_min_max, _ftype4scaled_finite, _is_compressed_fobj, _write_data, apply_read_scaling, array_from_file, array_to_file, best_write_scale_ftype, better_float_of, fname_ext_ul_case, int_scinter_ftype, make_dt_codes, native_code, rec2dict, seek_tell, shape_zoom_affine, working_type, write_zeros
label_desc: Use image node_id 26 for calling a global function with example usage: test_apply_scaling() without return types