def foo(x): with objmode_context(y='int64[:]'): y = np.asarray([1, 2, 3], dtype='int64') with objmode_context(): # Note: `y` is not an output. y[2] = 10 return y
def foo(x): # would nested ctx in the same scope ever make sense? Is this # pattern useful? with objmode_context(): #with npmmode_context(): not implemented yet with objmode_context(): print(x) return x
def foo(x, z): x[2] = z with objmode_context(): # should print [1, 2, 15] print(x) with objmode_context(): x[2] = 2 * z # should print [1, 2, 30] print(x) return x
def foo(x): # should specifying the wrong type info be considered valid? # z is complex. # Note: for now, we will coerce for scalar and raise for array with objmode_context(z="float64[:]"): z = x + 1.j return z
def foo(x): np.random.seed(0) y = np.random.rand() with objmode_context(z="float64"): # It's known that the random state does not sync z = np.random.rand() return x + z + y
def foo(x): with objmode_context(): def bar(y): return y + 1 return x
def foo(x): with objmode_context(y="float64[:]"): print(x) x[0] = 4 print(x) y = [1, 2, 3] + x y = np.asarray([1 / i for i in y]) return x, y
def foo(x): for i in range(len(x)): with objmode_context(): k = str(i) v = x[i] d[k] = v print(d['2']) return x
def foo(x): np.random.seed(0) y = np.random.rand() with objmode_context(z="float64"): # Similar to test_case20_rng_works_ok but call seed np.random.seed(0) z = np.random.rand() return x + z + y
def foo(x, wobj): if wobj: with objmode_context(y='int64[:]'): y = (x + 1).astype('int64') else: y = x + 2 return x + y
def foo(x): with objmode_context(k='int64'): print(x) spx = sp.csr_matrix(x) # the np.int64 call is pointless, works around: # https://github.com/scipy/scipy/issues/10206 # which hit the SciPy 1.3 release. k = np.int64(spx[0, 0]) return k
def foo(x): for x in range(x): pass if x: x += 1 with objmode_context(x="intp"): print(x) x -= 1 print(x) for i in range(x): x += i print(x) return x
def foo(x): with objmode_context(): dis.dis(foo)
def foo(x): with objmode_context(k='int64'): print(x) spx = sp.csr_matrix(x) k = spx[0, 0] return k
def bar(x): with objmode_context(x='int64[:]'): print(x) return x + j
def foo(x): with objmode_context(x='int64[:]'): return x
def foo(x): with objmode_context(y='int64[:]'): y = njit(bar)(x).astype('int64') return x + y
def foo(x): with objmode_context(): y = 2 + x # defined but unused outside a = np.arange(y) # defined but unused outside bar(a) return x
def foo(x): with objmode_context(y='List(int64)'): y = [1, 2, 3] with objmode_context(): y[2] = 10 return y
def foo(x): with objmode_context(y="float64"): y = inverse(x) return x, y
def foo(x): with objmode_context(): t = {'a': x} return x, t
def foo(x): with objmode_context(y="float64[:]", z="int64"): y = inverse(x) z = int(y[0]) return x, y, z
def foo(func, x): with objmode_context(): func(x[0])
def foo(x): with objmode_context(): if x == 0: return 7 ret = foo(x - 1) return ret
def foo(x): # should specifying nonsense type info be considered valid? with objmode_context(k="float64[:]"): print(x) return x
def foo(x): with objmode_context(): raise ValueError() return x
def foo(x): np.random.seed(0) y = np.random.rand() with objmode_context(z="float64"): z = np.random.rand() return x + z