def test_sub(session): sess = session # session - session other = Session({'e': e - 1, 'f': ones_like(f)}) diff = sess - other assert_array_nan_equal(diff['e'], np.full((2, 3), 1, dtype=np.int32)) assert_array_nan_equal(diff['f'], f - ones_like(f)) assert isnan(diff['g']).all() assert diff.a is a assert diff.a01 is a01 assert diff.c is c # session - scalar diff = sess - 2 assert_array_nan_equal(diff['e'], e - 2) assert_array_nan_equal(diff['f'], f - 2) assert_array_nan_equal(diff['g'], g - 2) assert diff.a is a assert diff.a01 is a01 assert diff.c is c # session - dict(LArray and scalar) other = {'e': ones_like(e), 'f': 1} diff = sess - other assert_array_nan_equal(diff['e'], e - ones_like(e)) assert_array_nan_equal(diff['f'], f - 1) assert isnan(diff['g']).all() assert diff.a is a assert diff.a01 is a01 assert diff.c is c
def test_sub(self): sess = self.session.filter(kind=LArray) other = Session({'e': self.e - 1, 'f': 1}) diff = sess - other assert_array_nan_equal(diff['e'], np.full((2, 3), 1, dtype=np.int32)) assert_array_nan_equal(diff['f'], np.arange(-1, 5).reshape(3, 2)) self.assertTrue(isnan(diff['g']).all())
def test_sub(session): sess = session # session - session other = Session({'e': e, 'f': f}) other['e'] = e - 1 other['f'] = ones_like(f) diff = sess - other assert_array_nan_equal(diff['e'], np.full((2, 3), 1, dtype=np.int32)) assert_array_nan_equal(diff['f'], f - ones_like(f)) assert isnan(diff['g']).all() assert diff.a is a assert diff.a01 is a01 assert diff.c is c # session - scalar diff = sess - 2 assert_array_nan_equal(diff['e'], e - 2) assert_array_nan_equal(diff['f'], f - 2) assert_array_nan_equal(diff['g'], g - 2) assert diff.a is a assert diff.a01 is a01 assert diff.c is c # session - dict(Array and scalar) other = {'e': ones_like(e), 'f': 1} diff = sess - other assert_array_nan_equal(diff['e'], e - ones_like(e)) assert_array_nan_equal(diff['f'], f - 1) assert isnan(diff['g']).all() assert diff.a is a assert diff.a01 is a01 assert diff.c is c # session - array axes = [a, b] other = Session([('a', a), ('a01', a01), ('c', c), ('e', ndtest((a, b))), ('f', full((a, b), fill_value=3)), ('g', ndtest('c=c0..c2'))]) diff = other - ones(axes) assert_array_nan_equal(diff['e'], other['e'] - ones(axes)) assert_array_nan_equal(diff['f'], other['f'] - ones(axes)) assert_array_nan_equal(diff['g'], other['g'] - ones(axes)) assert diff.a is a assert diff.a01 is a01 assert diff.c is c
def test_rsub_cs(checkedsession): cs = checkedsession session_cls = cs.__class__ # scalar - session diff = 2 - cs assert isinstance(diff, session_cls) # --- non-array variables --- assert diff.b is b assert diff.b024 is b024 assert diff.a is a assert diff.a2 is a2 assert diff.anonymous is anonymous assert diff.a01 is a01 assert diff.ano01 is ano01 assert diff.c is c assert diff.d is d # --- non constant arrays --- assert_array_nan_equal(diff.e, 2 - e) assert_array_nan_equal(diff.g, 2 - g) assert_array_nan_equal(diff.f, 2 - f) assert_array_nan_equal(diff.h, 2 - h) # dict(Array and scalar) - session other = {'e': ones_like(e), 'h': 1} diff = other - cs assert isinstance(diff, session_cls) # --- non-array variables --- assert diff.b is b assert diff.b024 is b024 assert diff.a is a assert diff.a2 is a2 assert diff.anonymous is anonymous assert diff.a01 is a01 assert diff.ano01 is ano01 assert diff.c is c assert diff.d is d # --- non constant arrays --- assert_array_nan_equal(diff.e, ones_like(e) - e) assert isnan(diff.g).all() assert isnan(diff.f).all() assert_array_nan_equal(diff.h, 1 - h)
def test_neg_cs(checkedsession): cs = checkedsession neg_cs = -cs # --- non-array variables --- assert isnan(neg_cs.b) assert isnan(neg_cs.b024) assert isnan(neg_cs.a) assert isnan(neg_cs.a2) assert isnan(neg_cs.anonymous) assert isnan(neg_cs.a01) assert isnan(neg_cs.ano01) assert isnan(neg_cs.c) assert isnan(neg_cs.d) # --- non constant arrays --- assert_array_nan_equal(neg_cs.e, -e) assert_array_nan_equal(neg_cs.g, -g) assert_array_nan_equal(neg_cs.f, -f) assert_array_nan_equal(neg_cs.h, -h)
def test_sub(self): sess = self.session.filter(kind=LArray) # session - session other = Session({'e': self.e - 1, 'f': ones_like(self.f)}) diff = sess - other assert_array_nan_equal(diff['e'], np.full((2, 3), 1, dtype=np.int32)) assert_array_nan_equal(diff['f'], self.f - ones_like(self.f)) assert isnan(diff['g']).all() # session - scalar diff = sess - 2 assert_array_nan_equal(diff['e'], self.e - 2) assert_array_nan_equal(diff['f'], self.f - 2) assert_array_nan_equal(diff['g'], self.g - 2) # session - dict(LArray and scalar) other = {'e': ones_like(self.e), 'f': 1} diff = sess - other assert_array_nan_equal(diff['e'], self.e - ones_like(self.e)) assert_array_nan_equal(diff['f'], self.f - 1) assert isnan(diff['g']).all()
def test_rsub(self): sess = self.session.filter(kind=LArray) # scalar - session diff = 2 - sess assert_array_nan_equal(diff['e'], 2 - self.e) assert_array_nan_equal(diff['f'], 2 - self.f) assert_array_nan_equal(diff['g'], 2 - self.g) # dict(LArray and scalar) - session other = {'e': ones_like(self.e), 'f': 1} diff = other - sess assert_array_nan_equal(diff['e'], ones_like(self.e) - self.e) assert_array_nan_equal(diff['f'], 1 - self.f) assert isnan(diff['g']).all()
def test_div(session): sess = session other = Session({'e': e - 1, 'f': f + 1}) with pytest.warns(RuntimeWarning) as caught_warnings: res = sess / other assert len(caught_warnings) == 1 assert caught_warnings[0].message.args[0] == "divide by zero encountered during operation" assert caught_warnings[0].filename == __file__ with np.errstate(divide='ignore', invalid='ignore'): flat_e = np.arange(6) / np.arange(-1, 5) assert_array_nan_equal(res['e'], flat_e.reshape(2, 3)) flat_f = np.arange(6) / np.arange(1, 7) assert_array_nan_equal(res['f'], flat_f.reshape(3, 2)) assert isnan(res['g']).all()
def test_div(self): sess = self.session.filter(kind=LArray) other = Session({'e': self.e - 1, 'f': self.f + 1}) with pytest.warns(RuntimeWarning) as caught_warnings: res = sess / other assert len(caught_warnings) == 1 assert caught_warnings[0].message.args[ 0] == "divide by zero encountered during operation" assert caught_warnings[0].filename == __file__ with np.errstate(divide='ignore', invalid='ignore'): flat_e = np.arange(6) / np.arange(-1, 5) assert_array_nan_equal(res['e'], flat_e.reshape(2, 3)) flat_f = np.arange(6) / np.arange(1, 7) assert_array_nan_equal(res['f'], flat_f.reshape(3, 2)) self.assertTrue(isnan(res['g']).all())
def test_div(session): sess = session session_cls = session.__class__ other = session_cls({'e': e, 'f': f}) other['e'] = e - 1 other['f'] = f + 1 with must_warn(RuntimeWarning, msg="divide by zero encountered during operation"): res = sess / other with np.errstate(divide='ignore', invalid='ignore'): flat_e = np.arange(6) / np.arange(-1, 5) assert_array_nan_equal(res['e'], flat_e.reshape(2, 3)) flat_f = np.arange(6) / np.arange(1, 7) assert_array_nan_equal(res['f'], flat_f.reshape(3, 2)) assert isnan(res['g']).all()
def test_rsub(session): sess = session # scalar - session diff = 2 - sess assert_array_nan_equal(diff['e'], 2 - e) assert_array_nan_equal(diff['f'], 2 - f) assert_array_nan_equal(diff['g'], 2 - g) assert diff.a is a assert diff.a01 is a01 assert diff.c is c # dict(LArray and scalar) - session other = {'e': ones_like(e), 'f': 1} diff = other - sess assert_array_nan_equal(diff['e'], ones_like(e) - e) assert_array_nan_equal(diff['f'], 1 - f) assert isnan(diff['g']).all() assert diff.a is a assert diff.a01 is a01 assert diff.c is c
def test_rsub(session): sess = session # scalar - session diff = 2 - sess assert_array_nan_equal(diff['e'], 2 - e) assert_array_nan_equal(diff['f'], 2 - f) assert_array_nan_equal(diff['g'], 2 - g) assert diff.a is a assert diff.a01 is a01 assert diff.c is c # dict(Array and scalar) - session other = {'e': ones_like(e), 'f': 1} diff = other - sess assert_array_nan_equal(diff['e'], ones_like(e) - e) assert_array_nan_equal(diff['f'], 1 - f) assert isnan(diff['g']).all() assert diff.a is a assert diff.a01 is a01 assert diff.c is c
def nan_equal(a, b): return (a == b) | (isnan(a) & isnan(b))
def test_sub_cs(checkedsession): cs = checkedsession session_cls = cs.__class__ # session - session other = session_cls(a=a, a2=a2, a01=a01, e=e - 1, g=zeros_like(g), f=zeros_like(f), h=ones_like(h)) diff = cs - other assert isinstance(diff, session_cls) # --- non-array variables --- assert diff.b is b assert diff.b024 is b024 assert diff.a is a assert diff.a2 is a2 assert diff.anonymous is anonymous assert diff.a01 is a01 assert diff.ano01 is ano01 assert diff.c is c assert diff.d is d # --- array variables --- assert_array_nan_equal(diff.e, np.full((2, 3), 1, dtype=np.int32)) assert_array_nan_equal(diff.g, g) assert_array_nan_equal(diff.f, f) assert_array_nan_equal(diff.h, h - ones_like(h)) # session - scalar diff = cs - 2 assert isinstance(diff, session_cls) # --- non-array variables --- assert diff.b is b assert diff.b024 is b024 assert diff.a is a assert diff.a2 is a2 assert diff.anonymous is anonymous assert diff.a01 is a01 assert diff.ano01 is ano01 assert diff.c is c assert diff.d is d # --- non constant arrays --- assert_array_nan_equal(diff.e, e - 2) assert_array_nan_equal(diff.g, g - 2) assert_array_nan_equal(diff.f, f - 2) assert_array_nan_equal(diff.h, h - 2) # session - dict(Array and scalar) other = {'e': ones_like(e), 'h': 1} diff = cs - other assert isinstance(diff, session_cls) # --- non-array variables --- assert diff.b is b assert diff.b024 is b024 assert diff.a is a assert diff.a2 is a2 assert diff.anonymous is anonymous assert diff.a01 is a01 assert diff.ano01 is ano01 assert diff.c is c assert diff.d is d # --- non constant arrays --- assert_array_nan_equal(diff.e, e - ones_like(e)) assert isnan(diff.g).all() assert isnan(diff.f).all() assert_array_nan_equal(diff.h, h - 1) # session - array axes = cs.h.axes cs.e = ndtest(axes) cs.g = ones_like(cs.h) diff = cs - ones(axes) assert isinstance(diff, session_cls) # --- non-array variables --- assert diff.b is b assert diff.b024 is b024 assert diff.a is a assert diff.a2 is a2 assert diff.anonymous is anonymous assert diff.a01 is a01 assert diff.ano01 is ano01 assert diff.c is c assert diff.d is d # --- non constant arrays --- assert_array_nan_equal(diff.e, cs.e - ones(axes)) assert_array_nan_equal(diff.g, cs.g - ones(axes)) assert isnan(diff.f).all() assert_array_nan_equal(diff.h, cs.h - ones(axes))