Skip to content

Commit c4f0f6a

Browse files
committed
move random_paragraph function to testing utils
1 parent 80e274b commit c4f0f6a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

utils/testing.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import numpy as np
33

44

5+
#######################################################################
6+
# Assertions #
7+
#######################################################################
8+
9+
510
def is_symmetric(X):
611
return np.allclose(X, X.T)
712

@@ -72,3 +77,36 @@ def random_tensor(shape, standardize=False):
7277

7378
def random_binary_tensor(shape, sparsity=0.5):
7479
return (np.random.rand(*shape) >= (1 - sparsity)).astype(float)
80+
81+
82+
def random_paragraph(n_words, vocab=None):
83+
if vocab is None:
84+
vocab = [
85+
"at",
86+
"stet",
87+
"accusam",
88+
"aliquyam",
89+
"clita",
90+
"lorem",
91+
"ipsum",
92+
"dolor",
93+
"dolore",
94+
"dolores",
95+
"sit",
96+
"amet",
97+
"consetetur",
98+
"sadipscing",
99+
"elitr",
100+
"sed",
101+
"diam",
102+
"nonumy",
103+
"eirmod",
104+
"duo",
105+
"ea",
106+
"eos",
107+
"erat",
108+
"est",
109+
"et",
110+
"gubergren",
111+
]
112+
return [np.random.choice(vocab) for _ in range(n_words)]

utils/tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import numpy as np
22

33
import scipy
4+
45
from sklearn.neighbors import BallTree as sk_BallTree
56
from sklearn.metrics.pairwise import rbf_kernel as sk_rbf
67
from sklearn.metrics.pairwise import linear_kernel as sk_linear
78
from sklearn.metrics.pairwise import polynomial_kernel as sk_poly
89

10+
911
from distance_metrics import euclidean
1012
from kernels import LinearKernel, PolynomialKernel, RBFKernel
1113
from data_structures import BallTree

0 commit comments

Comments
 (0)