(
actual: Tensor|number[], expected: Tensor|number[], epsilon?: number)
| 24 | * @param expected |
| 25 | */ |
| 26 | export function expectTensorsClose( |
| 27 | actual: Tensor|number[], expected: Tensor|number[], epsilon?: number) { |
| 28 | if (actual == null) { |
| 29 | throw new ValueError( |
| 30 | 'First argument to expectTensorsClose() is not defined.'); |
| 31 | } |
| 32 | if (expected == null) { |
| 33 | throw new ValueError( |
| 34 | 'Second argument to expectTensorsClose() is not defined.'); |
| 35 | } |
| 36 | if (actual instanceof Tensor && expected instanceof Tensor) { |
| 37 | if (actual.dtype !== expected.dtype) { |
| 38 | throw new Error( |
| 39 | `Data types do not match. Actual: '${actual.dtype}'. ` + |
| 40 | `Expected: '${expected.dtype}'`); |
| 41 | } |
| 42 | if (!util.arraysEqual(actual.shape, expected.shape)) { |
| 43 | throw new Error( |
| 44 | `Shapes do not match. Actual: [${actual.shape}]. ` + |
| 45 | `Expected: [${expected.shape}].`); |
| 46 | } |
| 47 | } |
| 48 | const actualData = actual instanceof Tensor ? actual.dataSync() : actual; |
| 49 | const expectedData = |
| 50 | expected instanceof Tensor ? expected.dataSync() : expected; |
| 51 | test_util.expectArraysClose(actualData, expectedData, epsilon); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Expect values are not close between a Tensor or number array. |
no test coverage detected
searching dependent graphs…