1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_TEST_TEST_MEMORY_H
18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_TEST_TEST_MEMORY_H
19
20 #include <stdio.h>
21
22 namespace {
23
24 typedef float Matrix3x4[3][4];
25
26 // Check that the values are the same. This works only if dealing with integer
27 // value, otherwise we should accept values that are similar if not exact.
CompareMatrices(const Matrix3x4 & expected,const Matrix3x4 & actual)28 int CompareMatrices(const Matrix3x4& expected, const Matrix3x4& actual) {
29 int errors = 0;
30 for (int i = 0; i < 3; i++) {
31 for (int j = 0; j < 4; j++) {
32 if (expected[i][j] != actual[i][j]) {
33 printf("expected[%d][%d] != actual[%d][%d], %f != %f\n", i, j, i, j,
34 static_cast<double>(expected[i][j]), static_cast<double>(actual[i][j]));
35 errors++;
36 }
37 }
38 }
39 return errors;
40 }
41
42 const Matrix3x4 matrix1 = {{1.f, 2.f, 3.f, 4.f}, {5.f, 6.f, 7.f, 8.f}, {9.f, 10.f, 11.f, 12.f}};
43 const Matrix3x4 matrix2 = {{100.f, 200.f, 300.f, 400.f},
44 {500.f, 600.f, 700.f, 800.f},
45 {900.f, 1000.f, 1100.f, 1200.f}};
46 const Matrix3x4 matrix3 = {
47 {20.f, 30.f, 40.f, 50.f}, {21.f, 22.f, 23.f, 24.f}, {31.f, 32.f, 33.f, 34.f}};
48 const Matrix3x4 expected3 = {{121.f, 232.f, 343.f, 454.f},
49 {526.f, 628.f, 730.f, 832.f},
50 {940.f, 1042.f, 1144.f, 1246.f}};
51
52 } // anonymous namespace
53
54 #endif // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_TEST_TEST_MEMORY_H
55