• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

POptUS / IBCDFO / 11672510357

04 Nov 2024 08:54PM UTC coverage: 96.855%. Remained the same
11672510357

push

github

mmenickelly
A gradient-based POUNDers along with a simple test

1386 of 1431 relevant lines covered (96.86%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.87
/manifold_sampling/py/call_user_scripts.py
1
import numpy as np
1✔
2

3

4
def call_user_scripts(nf, X, F, h, Hash, Ffun, hfun, x_in, tol, L, U, allow_recalc=0):
1✔
5
    if len(x_in) != len(U) or len(x_in) != len(L):
1✔
6
        raise ValueError("Input vector dimensions do not match the bounds.")
×
7

8
    if allow_recalc is None:
1✔
9
        allow_recalc = 0
×
10

11
    xnew = np.minimum(U, np.maximum(L, x_in))
1✔
12

13
    for i in range(len(xnew)):
1✔
14
        if U[i] - xnew[i] < np.finfo(float).eps * np.abs(U[i]) and U[i] > xnew[i]:
1✔
15
            xnew[i] = U[i]
1✔
16
            print("eps project!")
1✔
17
        elif xnew[i] - L[i] < np.finfo(float).eps * np.abs(L[i]) and L[i] < xnew[i]:
1✔
18
            xnew[i] = L[i]
×
19
            print("eps project!")
×
20

21
    xnew_hashable = tuple(xnew)
1✔
22

23
    if not allow_recalc and xnew_hashable in [tuple(row) for row in X[:nf, :]]:
1✔
24
        raise ValueError("Your method requested a point that has already been requested. FAIL!")
×
25

26
    nf += 1
1✔
27
    X[nf] = xnew
1✔
28
    F[nf] = Ffun(X[nf])
1✔
29
    h[nf], _, hashes_at_nf = hfun(F[nf])
1✔
30
    Hash[nf] = hashes_at_nf
1✔
31
    if np.any(np.isnan(F[nf, :])):
1✔
32
        raise ValueError("Got a NaN. FAIL!")
1✔
33

34
    if tol["hfun_test_mode"]:
1✔
35
        assert isinstance(hashes_at_nf, list), "hfun must return a list of hashes"
1✔
36
        # assert all(isinstance(hash_val, str) for hash_val in hashes_at_nf), "Hashes must be strings"
37

38
        h_dummy1, grad_dummy1, hash_dummy = hfun(F[nf, :])
1✔
39
        h_dummy2, grad_dummy2 = hfun(F[nf, :], hash_dummy)
1✔
40
        # if not np.any(np.abs(h_dummy1 - h_dummy2) <= 1e-16):
41
        #     print("DEBUG: ", np.abs(h_dummy1 - h_dummy2), flush=True)
42
        assert np.any(np.abs(h_dummy1 - h_dummy2) <= 1e-8), "hfun values don't agree when " + hfun.__name__ + " is re-called with the same inputs"
1✔
43
        assert np.all(grad_dummy1 == grad_dummy2), "hfun gradients don't agree when " + hfun.__name__ + " is being re-called with the same inputs"
1✔
44

45
    return nf, X, F, h, Hash, hashes_at_nf
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc