File size: 820 Bytes
fc0f7bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import numpy as np


def logging_all_close(a, b, rtol=1e-05, atol=1e-08, equal_nan=False):
    """Wrap numpy.all_close functionality with print() on failure.

    Function arguments match numpy.all_close (assuming that it uses
    numpy.isclose), but if there are failures, then some diagnostics
    will be printed to stdout.
    """
    aa = np.asarray(a)
    ba = np.asarray(b)

    match_mask = np.isclose(aa, ba, rtol=rtol, atol=atol, equal_nan=equal_nan)
    if not np.all(match_mask):
        print("a mismatches: ", aa[np.logical_not(match_mask)])
        print("b mismatches: ", ba[np.logical_not(match_mask)])
        print("mismatch indices: ", np.where(np.logical_not(match_mask)))

    return np.all(match_mask)