code: def test_arithmetic():
      """Test evoked arithmetic."""
      ev = read_evokeds(fname, condition=0)
      ev20 = EvokedArray(
          np.ones_like(ev.data), ev.info, ev.times[0], nave=20
      )
      ev30 = EvokedArray(
          np.ones_like(ev.data), ev.info, ev.times[0], nave=30
      )
  
      tol = dict(rtol=1e-9, atol=0)
      # test subtraction
      sub1 = combine_evoked([ev, ev], weights=[1, -1])
      sub2 = combine_evoked([ev, -ev], weights=[1, 1])
      assert np.allclose(
          sub1.data, np.zeros_like(sub1.data), atol=1e-20
      )
      assert np.allclose(
          sub2.data, np.zeros_like(sub2.data), atol=1e-20
      )
      # test nave weighting. Expect signal ampl.: 1*(20/50) + 1*(30/50) == 1
      # and expect nave == ev1.nave + ev2.nave
      ev = combine_evoked([ev20, ev30], weights="nave")
      assert np.allclose(ev.nave, ev20.nave + ev30.nave)
      assert np.allclose(ev.data, np.ones_like(ev.data), **tol)
      # test equal-weighted sum. Expect signal ampl. == 2
      # and expect nave == 1/sum(1/naves) == 1/(1/20 + 1/30) == 12
      ev = combine_evoked([ev20, ev30], weights=[1, 1])
      assert np.allclose(ev.nave, 12.0)
      assert np.allclose(ev.data, ev20.data + ev30.data, **tol)
      # test equal-weighted average. Expect signal ampl. == 1
      # and expect nave == 1/sum(weights²/naves) == 1/(0.5²/20 + 0.5²/30) == 48
      ev = combine_evoked([ev20, ev30], weights="equal")
      assert np.allclose(ev.nave, 48.0)
      assert np.allclose(
          ev.data, np.mean([ev20.data, ev30.data], axis=0), **tol
      )
      # test zero weights
      ev = combine_evoked([ev20, ev30], weights=[1, 0])
      assert ev.nave == ev20.nave
      assert np.allclose(ev.data, ev20.data, **tol)
  
      # default comment behavior if evoked.comment is None
      old_comment1 = ev20.comment
      ev20.comment = None
      ev = combine_evoked([ev20, -ev30], weights=[1, -1])
      assert_equal(ev.comment.count("unknown"), 2)
      assert ev.comment == "unknown + unknown"
      ev20.comment = old_comment1
  
      with pytest.raises(
          ValueError, match="Invalid value for the 'weights'"
      ):
          combine_evoked([ev20, ev30], weights="foo")
      with pytest.raises(
          ValueError, match="weights must be the same size as"
      ):
          combine_evoked([ev20, ev30], weights=[1])
  
      # grand average
      evoked1, evoked2 = read_evokeds(
          fname, condition=[0, 1], proj=True
      )
      ch_names = evoked1.ch_names[2:]
      evoked1.info["bads"] = ["EEG 008"]  # test interpolation
      evoked1.drop_channels(evoked1.ch_names[:1])
      evoked2.drop_channels(evoked2.ch_names[1:2])
      gave = grand_average([evoked1, evoked2])
      assert_equal(
          gave.data.shape, [len(ch_names), evoked1.data.shape[1]]
      )
      assert_equal(ch_names, gave.ch_names)
      assert_equal(gave.nave, 2)
      with pytest.raises(
          TypeError, match="All elements must be an instance of"
      ):
          grand_average([1, evoked1])
      gave = grand_average(
          [ev20, ev20, -ev30]
      )  # (1 + 1 + -1) / 3  =  1/3
      assert_allclose(gave.data, np.full_like(gave.data, 1.0 / 3.0))
  
      # test channel (re)ordering
      evoked1, evoked2 = read_evokeds(
          fname, condition=[0, 1], proj=True
      )
      data2 = (
          evoked2.data
      )  # assumes everything is ordered to the first evoked
      data = (evoked1.data + evoked2.data) / 2.0
      evoked2.reorder_channels(evoked2.ch_names[::-1])
      assert not np.allclose(data2, evoked2.data)
      with pytest.warns(RuntimeWarning, match="reordering"):
          evoked3 = combine_evoked(
              [evoked1, evoked2], weights=[0.5, 0.5]
          )
      assert np.allclose(evoked3.data, data)
      assert evoked1.ch_names != evoked2.ch_names
      assert evoked1.ch_names == evoked3.ch_names
  
imports: import pickle
  from copy import deepcopy
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from scipy import fftpack
  from mne import Epochs, EpochsArray, combine_evoked, create_info, equalize_channels, pick_types, read_events, read_evokeds, write_evokeds
  from mne._fiff.constants import FIFF
  from mne.evoked import Evoked, EvokedArray, _get_peak
  from mne.io import read_raw_fif
  from mne.utils import grand_average
label_desc: Use image node_id 21 for calling a global function with example usage: test_arithmetic() without return types