diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index caefdbb4..b2652846 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,15 +4,15 @@ repos: hooks: - id: autoflake args: ["--in-place"] - exclude: ^torch_np/tests/numpy_tests/ + exclude: '^torch_np/tests/numpy_tests/|^e2e' - repo: https://github.com/timothycrosley/isort rev: 5.12.0 hooks: - id: isort args: ["--profile", "black", "--filter-files"] - exclude: ^torch_np/tests/numpy_tests/ + exclude: '^torch_np/tests/numpy_tests/|^e2e' - repo: https://github.com/psf/black rev: 22.12.0 hooks: - id: black - exclude: ^torch_np/tests/numpy_tests/ + exclude: '^torch_np/tests/numpy_tests/|^e2e' diff --git a/e2e/mandelbrot/mandelbrot.png b/e2e/mandelbrot/mandelbrot.png new file mode 100644 index 00000000..ef654186 Binary files /dev/null and b/e2e/mandelbrot/mandelbrot.png differ diff --git a/e2e/mandelbrot/mandelbrot.py b/e2e/mandelbrot/mandelbrot.py new file mode 100644 index 00000000..41884ee9 --- /dev/null +++ b/e2e/mandelbrot/mandelbrot.py @@ -0,0 +1,68 @@ +# ----------------------------------------------------------------------------- +# From Numpy to Python +# Copyright (2017) Nicolas P. Rougier - BSD license +# More information at https://github.com/rougier/numpy-book +# ----------------------------------------------------------------------------- +#import numpy as np +import torch_np as np + +# from mandelbrot_numpy_1 import mandelbrot # copy-paste below + +def mandelbrot(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon=2.0): + # Adapted from https://www.ibm.com/developerworks/community/blogs/jfp/... + # .../entry/How_To_Compute_Mandelbrodt_Set_Quickly?lang=en + X = np.linspace(xmin, xmax, xn, dtype=np.float32) + Y = np.linspace(ymin, ymax, yn, dtype=np.float32) + C = X + Y[:,None]*1j + N = np.zeros(C.shape, dtype=int) + Z = np.zeros(C.shape, np.complex64) + for n in range(maxiter): + I = np.less(abs(Z), horizon) + N[I] = n + Z[I] = Z[I]**2 + C[I] + N[N == maxiter-1] = 0 + return Z, N + + +if __name__ == '__main__': + from matplotlib import colors + import matplotlib.pyplot as plt + ## from timeit import timeit + + # Benchmark + xmin, xmax, xn = -2.25, +0.75, int(3000/3) + ymin, ymax, yn = -1.25, +1.25, int(2500/3) + maxiter = 200 + ## timeit("mandelbrot_1(xmin, xmax, ymin, ymax, xn, yn, maxiter)", globals()) + ## timeit("mandelbrot_2(xmin, xmax, ymin, ymax, xn, yn, maxiter)", globals()) + ## timeit("mandelbrot_3(xmin, xmax, ymin, ymax, xn, yn, maxiter)", globals()) + + # Visualization + xmin, xmax, xn = -2.25, +0.75, int(3000/2) + ymin, ymax, yn = -1.25, +1.25, int(2500/2) + maxiter = 200 + horizon = 2.0 ** 40 + log_horizon = np.log(np.log(horizon))/np.log(2) + Z, N = mandelbrot(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon) + + # Normalized recount as explained in: + # http://linas.org/art-gallery/escape/smooth.html + M = np.nan_to_num(N + 1 - np.log(np.log(abs(Z)))/np.log(2) + log_horizon) + + dpi = 72 + width = 10 + height = 10*yn/xn + + fig = plt.figure(figsize=(width, height), dpi=dpi) + ax = fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False, aspect=1) + + light = colors.LightSource(azdeg=315, altdeg=10) + + plt.imshow(light.shade(M.tensor.numpy(), cmap=plt.cm.hot, vert_exag=1.5, + norm = colors.PowerNorm(0.3), blend_mode='hsv'), + extent=[xmin, xmax, ymin, ymax], interpolation="bicubic") + ax.set_xticks([]) + ax.set_yticks([]) + plt.savefig("mandelbrot.png") + plt.show() + diff --git a/e2e/maze/maze.output.np.txt b/e2e/maze/maze.output.np.txt new file mode 100644 index 00000000..63c43619 --- /dev/null +++ b/e2e/maze/maze.output.np.txt @@ -0,0 +1,184 @@ +Z = [[ True True True ... True True True] + [ True False False ... True False True] + [ True False True ... True False True] + ... + [ True False True ... True False True] + [ True False False ... True False True] + [ True True True ... True True True]] +P = [[79 39] + [79 38] + [79 37] + [79 36] + [79 35] + [78 35] + [77 35] + [76 35] + [75 35] + [75 36] + [75 37] + [74 37] + [73 37] + [72 37] + [71 37] + [71 36] + [71 35] + [70 35] + [69 35] + [69 34] + [69 33] + [68 33] + [67 33] + [67 34] + [67 35] + [67 36] + [67 37] + [66 37] + [65 37] + [64 37] + [63 37] + [62 37] + [61 37] + [61 38] + [61 39] + [60 39] + [59 39] + [58 39] + [57 39] + [56 39] + [55 39] + [54 39] + [53 39] + [52 39] + [51 39] + [50 39] + [49 39] + [48 39] + [47 39] + [46 39] + [45 39] + [45 38] + [45 37] + [45 36] + [45 35] + [44 35] + [43 35] + [43 34] + [43 33] + [43 32] + [43 31] + [44 31] + [45 31] + [45 30] + [45 29] + [46 29] + [47 29] + [47 28] + [47 27] + [48 27] + [49 27] + [50 27] + [51 27] + [51 26] + [51 25] + [51 24] + [51 23] + [50 23] + [49 23] + [48 23] + [47 23] + [46 23] + [45 23] + [44 23] + [43 23] + [43 22] + [43 21] + [42 21] + [41 21] + [40 21] + [39 21] + [38 21] + [37 21] + [36 21] + [35 21] + [34 21] + [33 21] + [32 21] + [31 21] + [31 20] + [31 19] + [32 19] + [33 19] + [33 18] + [33 17] + [33 16] + [33 15] + [33 14] + [33 13] + [32 13] + [31 13] + [30 13] + [29 13] + [29 12] + [29 11] + [28 11] + [27 11] + [26 11] + [25 11] + [24 11] + [23 11] + [22 11] + [21 11] + [20 11] + [19 11] + [19 12] + [19 13] + [19 14] + [19 15] + [19 16] + [19 17] + [19 18] + [19 19] + [18 19] + [17 19] + [16 19] + [15 19] + [15 18] + [15 17] + [14 17] + [13 17] + [12 17] + [11 17] + [11 16] + [11 15] + [11 14] + [11 13] + [11 12] + [11 11] + [11 10] + [11 9] + [10 9] + [ 9 9] + [ 8 9] + [ 7 9] + [ 6 9] + [ 5 9] + [ 4 9] + [ 3 9] + [ 3 10] + [ 3 11] + [ 3 12] + [ 3 13] + [ 2 13] + [ 1 13] + [ 1 12] + [ 1 11] + [ 1 10] + [ 1 9] + [ 1 8] + [ 1 7] + [ 1 6] + [ 1 5] + [ 1 4] + [ 1 3] + [ 1 2] + [ 1 1]] diff --git a/e2e/maze/maze.output.tnp.txt b/e2e/maze/maze.output.tnp.txt new file mode 100644 index 00000000..f7cd5f7f --- /dev/null +++ b/e2e/maze/maze.output.tnp.txt @@ -0,0 +1,186 @@ +$ python maze_numpy.py +Z = array_w([[ True, True, True, ..., True, True, True], + [ True, False, False, ..., True, False, True], + [ True, False, True, ..., True, False, True], + ..., + [ True, False, True, ..., True, False, True], + [ True, False, False, ..., True, False, True], + [ True, True, True, ..., True, True, True]]) +P = array_w([[79, 39], + [79, 38], + [79, 37], + [79, 36], + [79, 35], + [78, 35], + [77, 35], + [76, 35], + [75, 35], + [75, 36], + [75, 37], + [74, 37], + [73, 37], + [72, 37], + [71, 37], + [71, 36], + [71, 35], + [70, 35], + [69, 35], + [69, 34], + [69, 33], + [68, 33], + [67, 33], + [67, 34], + [67, 35], + [67, 36], + [67, 37], + [66, 37], + [65, 37], + [64, 37], + [63, 37], + [62, 37], + [61, 37], + [61, 38], + [61, 39], + [60, 39], + [59, 39], + [58, 39], + [57, 39], + [56, 39], + [55, 39], + [54, 39], + [53, 39], + [52, 39], + [51, 39], + [50, 39], + [49, 39], + [48, 39], + [47, 39], + [46, 39], + [45, 39], + [45, 38], + [45, 37], + [45, 36], + [45, 35], + [44, 35], + [43, 35], + [43, 34], + [43, 33], + [43, 32], + [43, 31], + [44, 31], + [45, 31], + [45, 30], + [45, 29], + [46, 29], + [47, 29], + [47, 28], + [47, 27], + [48, 27], + [49, 27], + [50, 27], + [51, 27], + [51, 26], + [51, 25], + [51, 24], + [51, 23], + [50, 23], + [49, 23], + [48, 23], + [47, 23], + [46, 23], + [45, 23], + [44, 23], + [43, 23], + [43, 22], + [43, 21], + [42, 21], + [41, 21], + [40, 21], + [39, 21], + [38, 21], + [37, 21], + [36, 21], + [35, 21], + [34, 21], + [33, 21], + [32, 21], + [31, 21], + [31, 20], + [31, 19], + [32, 19], + [33, 19], + [33, 18], + [33, 17], + [33, 16], + [33, 15], + [33, 14], + [33, 13], + [32, 13], + [31, 13], + [30, 13], + [29, 13], + [29, 12], + [29, 11], + [28, 11], + [27, 11], + [26, 11], + [25, 11], + [24, 11], + [23, 11], + [22, 11], + [21, 11], + [20, 11], + [19, 11], + [19, 12], + [19, 13], + [19, 14], + [19, 15], + [19, 16], + [19, 17], + [19, 18], + [19, 19], + [18, 19], + [17, 19], + [16, 19], + [15, 19], + [15, 18], + [15, 17], + [14, 17], + [13, 17], + [12, 17], + [11, 17], + [11, 16], + [11, 15], + [11, 14], + [11, 13], + [11, 12], + [11, 11], + [11, 10], + [11, 9], + [10, 9], + [ 9, 9], + [ 8, 9], + [ 7, 9], + [ 6, 9], + [ 5, 9], + [ 4, 9], + [ 3, 9], + [ 3, 10], + [ 3, 11], + [ 3, 12], + [ 3, 13], + [ 2, 13], + [ 1, 13], + [ 1, 12], + [ 1, 11], + [ 1, 10], + [ 1, 9], + [ 1, 8], + [ 1, 7], + [ 1, 6], + [ 1, 5], + [ 1, 4], + [ 1, 3], + [ 1, 2], + [ 1, 1]]) + diff --git a/e2e/maze/maze_numpy.py b/e2e/maze/maze_numpy.py new file mode 100644 index 00000000..516dd84f --- /dev/null +++ b/e2e/maze/maze_numpy.py @@ -0,0 +1,215 @@ +# ----------------------------------------------------------------------------- +# From Numpy to Python +# Copyright (2017) Nicolas P. Rougier - BSD license +# More information at https://github.com/rougier/numpy-book +# ----------------------------------------------------------------------------- +import numpy as _np +import torch_np as np + +from collections import deque +import matplotlib.pyplot as plt +## from scipy.ndimage import generic_filter + +_np.random.seed(1234) + + +def build_maze(shape=(65,65), complexity=0.75, density = 0.50): + """ + Build a maze using given complexity and density + + Parameters + ========== + + shape : (rows,cols) + Size of the maze + + complexity: float + Mean length of islands (as a ratio of maze size) + + density: float + Mean numbers of highland (as a ratio of maze surface) + + """ + + # Only odd shapes + shape = ((shape[0]//2)*2+1, (shape[1]//2)*2+1) + + # Adjust complexity and density relatively to maze size + n_complexity = int(complexity*(shape[0]+shape[1])) + n_density = int(density*(shape[0]*shape[1])) + + # Build actual maze + Z = np.zeros(shape, dtype=bool) + + # Fill borders + Z[0,:] = Z[-1,:] = Z[:,0] = Z[:,-1] = 1 + + # Islands starting point with a bias in favor of border + P = _np.random.normal(0, 0.5, (n_density,2)) + P = np.asarray(P) + + P = 0.5 - np.maximum(-0.5, np.minimum(P, +0.5)) + P = (P*[shape[1],shape[0]]).astype(int) + P = 2*(P//2) + + # Create islands + for i in range(n_density): + + # Test for early stop: if all starting point are busy, this means we + # won't be able to connect any island, so we stop. + T = Z[2:-2:2,2:-2:2] + if T.sum() == T.size: + break + + x, y = P[i] + Z[y,x] = 1 + for j in range(n_complexity): + neighbours = [] + if x > 1: + neighbours.append([(y, x-1), (y, x-2)]) + if x < shape[1]-2: + neighbours.append([(y, x+1), (y, x+2)]) + if y > 1: + neighbours.append([(y-1, x), (y-2, x)]) + if y < shape[0]-2: + neighbours.append([(y+1, x), (y+2, x)]) + if len(neighbours): + choice = _np.random.randint(len(neighbours)) + choice = np.asarray(choice) + next_1, next_2 = neighbours[choice] + if Z[next_2] == 0: + Z[next_1] = Z[next_2] = 1 + y, x = next_2 + else: + break + return Z + + +# ------------------------------------------------------ find_shortest_path --- +def BellmanFord(Z, start, goal): + + # We reserve Z such that walls have value 0 + Z = 1 - Z + + # Build gradient array + G = np.zeros(Z.shape) + + # Initialize gradient at the entrance with value 1 + G[start] = 1 + + # Discount factor + gamma = 0.99 + + def diffuse(Z): + # North, West, Center, East, South + return max(gamma*Z[0], gamma*Z[1], Z[2], gamma*Z[3], gamma*Z[4]) + + # Shortest path in best case cannot be less the Manhattan distance + # from entrance to exit + length = Z.shape[0]+Z.shape[1] + + # We iterate until value at exit is > 0. This requires the maze + # to have a solution or it will be stuck in the loop. + + G_gamma = np.empty_like(G) + while G[goal] == 0.0: + # Slow + # G = Z * generic_filter(G, diffuse, footprint=[[0, 1, 0], + # [1, 1, 1], + # [0, 1, 0]]) + + # Fast + np.multiply(G, gamma, out=G_gamma) + N = G_gamma[0:-2,1:-1] + W = G_gamma[1:-1,0:-2] + C = G[1:-1,1:-1] + E = G_gamma[1:-1,2:] + S = G_gamma[2:,1:-1] + G[1:-1,1:-1] = Z[1:-1,1:-1]*np.maximum(N,np.maximum(W,np.maximum(C,np.maximum(E,S)))) + + # Descent gradient to find shortest path from entrance to exit + y, x = goal + P = [] + dirs = [(0,-1), (0,+1), (-1,0), (+1,0)] + while (x, y) != start: + P.append((x, y)) + neighbours = [-1, -1, -1, -1] + if x > 0: + neighbours[0] = G[y, x-1] + if x < G.shape[1]-1: + neighbours[1] = G[y, x+1] + if y > 0: + neighbours[2] = G[y-1, x] + if y < G.shape[0]-1: + neighbours[3] = G[y+1, x] + a = np.argmax(neighbours) + x, y = x + dirs[a][1], y + dirs[a][0] + P.append((x, y)) + return G, np.array(P) + +def build_graph(maze): + height, width = maze.shape + graph = {(i, j): [] for j in range(width) for i in range(height) if not maze[i][j]} + for row, col in graph.keys(): + if row < height - 1 and not maze[row + 1][col]: + graph[(row, col)].append(("S", (row + 1, col))) + graph[(row + 1, col)].append(("N", (row, col))) + if col < width - 1 and not maze[row][col + 1]: + graph[(row, col)].append(("E", (row, col + 1))) + graph[(row, col + 1)].append(("W", (row, col))) + return graph + +def BreadthFirst(maze, start, goal): + queue = deque([([start], start)]) + visited = set() + graph = build_graph(maze) + while queue: + path, current = queue.popleft() + if current == goal: + return np.array(path) + if current in visited: + continue + visited.add(current) + for direction, neighbour in graph[current]: + p = list(path) + p.append(neighbour) + queue.append((p, neighbour)) + return None + + +# -------------------------------------------------------------------- main --- +if __name__ == '__main__': + + Z = build_maze((41,81)) + start, goal = (1,1), (Z.shape[0]-2, Z.shape[1]-2) + + G, P = BellmanFord(Z, start, goal) + X, Y = P[:,0], P[:,1] + + # P = BreadthFirst(Z, start, goal) + # X, Y = P[:,1], P[:,0] + + print("Z = ", Z) + print("P = ", P) + + X = X.tensor.numpy() + Y = Y.tensor.numpy() + Z = Z.tensor.numpy() + G = G.tensor.numpy() + + # Visualization maze, gradient and shortest path + plt.figure(figsize=(13, 13*Z.shape[0]/Z.shape[1])) + ax = plt.subplot(1, 1, 1, frameon=False) + ax.imshow(Z, interpolation='nearest', cmap=plt.cm.gray_r, vmin=0.0, vmax=1.0) + cmap = plt.cm.hot + cmap.set_under(color='k', alpha=0.0) + ax.imshow(G, interpolation='nearest', cmap=cmap, vmin=0.01, vmax=G[start]) + ax.scatter(X[1:-1], Y[1:-1], s=60, + lw=1, marker='o', edgecolors='k', facecolors='w') + ax.scatter(X[[0,-1]], Y[[0,-1]], s=60, + lw=3, marker='x', color=['w','k']) + ax.set_xticks([]) + ax.set_yticks([]) + plt.tight_layout() + plt.savefig("maze_tnp.png") + plt.show() diff --git a/e2e/maze/maze_tnp.png b/e2e/maze/maze_tnp.png new file mode 100644 index 00000000..618b917e Binary files /dev/null and b/e2e/maze/maze_tnp.png differ diff --git a/e2e/nn_from_scratch/nn.py b/e2e/nn_from_scratch/nn.py new file mode 100644 index 00000000..c6a4a9b0 --- /dev/null +++ b/e2e/nn_from_scratch/nn.py @@ -0,0 +1,166 @@ +# from https://www.geeksforgeeks.org/implementation-of-neural-network-from-scratch-using-numpy/ + + +import numpy as _np +import torch_np as np + +# Creating data set + +# A +a =[0, 0, 1, 1, 0, 0, + 0, 1, 0, 0, 1, 0, + 1, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1] +# B +b =[0, 1, 1, 1, 1, 0, + 0, 1, 0, 0, 1, 0, + 0, 1, 1, 1, 1, 0, + 0, 1, 0, 0, 1, 0, + 0, 1, 1, 1, 1, 0] +# C +c =[0, 1, 1, 1, 1, 0, + 0, 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 0] + +# Creating labels +y =[[1, 0, 0], + [0, 1, 0], + [0, 0, 1]] + + +# converting data and labels into numpy array + +""" +Convert the matrix of 0 and 1 into one hot vector +so that we can directly feed it to the neural network, +these vectors are then stored in a list x. +""" + +x =[np.array(a).reshape(1, 30), np.array(b).reshape(1, 30), + np.array(c).reshape(1, 30)] + + +# Labels are also converted into NumPy array +y = np.array(y) + + +print(x, "\n\n", y) + + +# activation function + +def sigmoid(x): + return(1/(1 + np.exp(-x))) + +# Creating the Feed forward neural network +# 1 Input layer(1, 30) +# 1 hidden layer (1, 5) +# 1 output layer(3, 3) + +def f_forward(x, w1, w2): + # hidden + z1 = x.dot(w1)# input from layer 1 + a1 = sigmoid(z1)# out put of layer 2 + + # Output layer + z2 = a1.dot(w2)# input of out layer + a2 = sigmoid(z2)# output of out layer + return(a2) + +# initializing the weights randomly +def generate_wt(x, y): + + _np.random.seed(1234) + + l =[] + for i in range(x * y): + l.append(_np.random.randn()) + return(np.array(l).reshape(x, y)) + +# for loss we will be using mean square error(MSE) +def loss(out, Y): + s =(np.square(out-Y)) + s = np.sum(s)/len(y) + return(s) + +# Back propagation of error +def back_prop(x, y, w1, w2, alpha): + + # hidden layer + z1 = x.dot(w1)# input from layer 1 + a1 = sigmoid(z1)# output of layer 2 + + # Output layer + z2 = a1.dot(w2)# input of out layer + a2 = sigmoid(z2)# output of out layer + # error in output layer + d2 =(a2-y) + d1 = np.multiply((w2.dot((d2.transpose()))).transpose(), + (np.multiply(a1, 1-a1))) + + # Gradient for w1 and w2 + w1_adj = x.transpose().dot(d1) + w2_adj = a1.transpose().dot(d2) + + # Updating parameters + w1 = w1-(alpha*(w1_adj)) + w2 = w2-(alpha*(w2_adj)) + + return(w1, w2) + +def train(x, Y, w1, w2, alpha = 0.01, epoch = 10): + acc =[] + losss =[] + for j in range(epoch): + l =[] + for i in range(len(x)): + out = f_forward(x[i], w1, w2) + l.append((loss(out, Y[i]))) + w1, w2 = back_prop(x[i], y[i], w1, w2, alpha) + print("epochs:", j + 1, "======== acc:", (1-(sum(l)/len(x)))*100) + acc.append((1-(sum(l)/len(x)))*100) + losss.append(sum(l)/len(x)) + return(acc, losss, w1, w2) + +def predict(x, w1, w2): + Out = f_forward(x, w1, w2) + maxm = 0 + k = 0 + for i in range(len(Out[0])): + if(maxm 1e10) and assert_all(np.isfinite(vals[2])) - assert_equal(type(vals), np.ndarray) + assert isinstance(vals, np.ndarray) # perform the same tests but with nan, posinf and neginf keywords with np.errstate(divide='ignore', invalid='ignore'): @@ -341,45 +341,27 @@ def test_generic(self): nan=10, posinf=20, neginf=30) assert_equal(vals, [30, 10, 20]) assert_all(np.isfinite(vals[[0, 2]])) - assert_equal(type(vals), np.ndarray) - - # perform the same test but in-place - with np.errstate(divide='ignore', invalid='ignore'): - vals = np.array((-1., 0, 1))/0. - result = nan_to_num(vals, copy=False) - - assert_(result is vals) - assert_all(vals[0] < -1e10) and assert_all(np.isfinite(vals[0])) - assert_(vals[1] == 0) - assert_all(vals[2] > 1e10) and assert_all(np.isfinite(vals[2])) - assert_equal(type(vals), np.ndarray) - - # perform the same test but in-place - with np.errstate(divide='ignore', invalid='ignore'): - vals = np.array((-1., 0, 1))/0. - result = nan_to_num(vals, copy=False, nan=10, posinf=20, neginf=30) + assert isinstance(vals, np.ndarray) - assert_(result is vals) - assert_equal(vals, [30, 10, 20]) - assert_all(np.isfinite(vals[[0, 2]])) - assert_equal(type(vals), np.ndarray) def test_array(self): vals = nan_to_num([1]) assert_array_equal(vals, np.array([1], int)) - assert_equal(type(vals), np.ndarray) + assert isinstance(vals, np.ndarray) vals = nan_to_num([1], nan=10, posinf=20, neginf=30) assert_array_equal(vals, np.array([1], int)) - assert_equal(type(vals), np.ndarray) + assert isinstance(vals, np.ndarray) + @pytest.mark.skip(reason="we return OD arrays not scalars") def test_integer(self): vals = nan_to_num(1) assert_all(vals == 1) - assert_equal(type(vals), np.int_) + assert isinstance(vals, np.int_) vals = nan_to_num(1, nan=10, posinf=20, neginf=30) assert_all(vals == 1) - assert_equal(type(vals), np.int_) + assert isinstance(vals, np.int_) + @pytest.mark.skip(reason="we return OD arrays not scalars") def test_float(self): vals = nan_to_num(1.0) assert_all(vals == 1.0) @@ -388,14 +370,16 @@ def test_float(self): assert_all(vals == 1.1) assert_equal(type(vals), np.float_) + @pytest.mark.skip(reason="we return OD arrays not scalars") def test_complex_good(self): vals = nan_to_num(1+1j) assert_all(vals == 1+1j) - assert_equal(type(vals), np.complex_) + assert isinstance(vals, np.complex_) vals = nan_to_num(1+1j, nan=10, posinf=20, neginf=30) assert_all(vals == 1+1j) assert_equal(type(vals), np.complex_) + @pytest.mark.skip(reason="we return OD arrays not scalars") def test_complex_bad(self): with np.errstate(divide='ignore', invalid='ignore'): v = 1 + 1j @@ -405,6 +389,7 @@ def test_complex_bad(self): assert_all(np.isfinite(vals)) assert_equal(type(vals), np.complex_) + @pytest.mark.skip(reason="we return OD arrays not scalars") def test_complex_bad2(self): with np.errstate(divide='ignore', invalid='ignore'): v = 1 + 1j @@ -427,7 +412,7 @@ def test_do_not_rewrite_previous_keyword(self): assert_all(np.isfinite(vals[[0, 2]])) assert_all(vals[0] < -1e10) assert_equal(vals[[1, 2]], [np.inf, 999]) - assert_equal(type(vals), np.ndarray) + assert isinstance(vals, np.ndarray) class TestRealIfClose: