code: def test_as_ndarray_memmap():
      # memmap
      filename = os.path.join(
          os.path.dirname(__file__), "data", "mmap.dat"
      )
  
      # same dtype, no copy requested
      arr1 = np.memmap(filename, dtype="float32", mode="w+", shape=(5,))
      arr2 = as_ndarray(arr1)
      assert not are_arrays_identical(arr1, arr2)
  
      # same dtype, copy requested
      arr1 = np.memmap(
          filename, dtype="float32", mode="readwrite", shape=(5,)
      )
      arr2 = as_ndarray(arr1, copy=True)
      assert not are_arrays_identical(arr1, arr2)
  
      # different dtype
      arr1 = np.memmap(
          filename, dtype="float32", mode="readwrite", shape=(5,)
      )
      arr2 = as_ndarray(arr1, dtype=int)
      assert arr2.dtype == int
      assert not are_arrays_identical(arr1, arr2)
  
      # same dtype, explicitly provided: must copy
      arr1 = np.memmap(
          filename, dtype="float32", mode="readwrite", shape=(5,)
      )
      arr2 = as_ndarray(arr1, dtype=np.float32)
      assert arr2.dtype == np.float32
      assert not are_arrays_identical(arr1, arr2)
  
      # same dtype, order provided
      arr1 = np.memmap(
          filename, dtype="float32", mode="readwrite", shape=(10, 10)
      )
      arr2 = as_ndarray(arr1, order="F")
      assert (
          arr2.flags["F_CONTIGUOUS"] and not arr2.flags["C_CONTIGUOUS"]
      )
      assert arr2.dtype == arr1.dtype
      assert not are_arrays_identical(arr1[0], arr2[0])
  
      # same dtype, order unchanged but provided
      arr1 = np.memmap(
          filename,
          dtype="float32",
          mode="readwrite",
          shape=(10, 10),
          order="F",
      )
      arr2 = as_ndarray(arr1, order="F")
      assert (
          arr2.flags["F_CONTIGUOUS"] and not arr2.flags["C_CONTIGUOUS"]
      )
      assert arr2.dtype == arr1.dtype
      assert not are_arrays_identical(arr1[0], arr2[0])
  
      # dtype and order specified
      arr1 = np.memmap(
          filename,
          dtype="float32",
          mode="readwrite",
          shape=(10, 10),
          order="F",
      )
      arr2 = as_ndarray(arr1, order="F", dtype=np.int32)
      assert (
          arr2.flags["F_CONTIGUOUS"] and not arr2.flags["C_CONTIGUOUS"]
      )
      assert arr2.dtype == np.int32
      assert not are_arrays_identical(arr1[0], arr2[0])
  
file_path: nilearn/nilearn/_utils/tests/test_numpy_conversions.py
imports: import os
  import tempfile
  import numpy
  import pytest
  from nilearn._utils.numpy_conversions import as_ndarray, csv_to_array
label_desc: Use image node_id 4 for calling a global function with example usage: test_as_ndarray_memmap() without return types