summaryrefslogtreecommitdiff
path: root/nn/runtime/test/TestMemory.h
blob: 3ce179026a6a1677854413b2e32c44a22f830892 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TEST_TEST_MEMORY_H
#define ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TEST_TEST_MEMORY_H

#include <stdio.h>

namespace {

typedef float Matrix3x4[3][4];

// Check that the values are the same. This works only if dealing with integer
// value, otherwise we should accept values that are similar if not exact.
int CompareMatrices(const Matrix3x4& expected, const Matrix3x4& actual) {
    int errors = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 4; j++) {
            if (expected[i][j] != actual[i][j]) {
                printf("expected[%d][%d] != actual[%d][%d], %f != %f\n", i, j, i, j,
                       static_cast<double>(expected[i][j]), static_cast<double>(actual[i][j]));
                errors++;
            }
        }
    }
    return errors;
}

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}};
const Matrix3x4 matrix2 = {{100.f, 200.f, 300.f, 400.f},
                           {500.f, 600.f, 700.f, 800.f},
                           {900.f, 1000.f, 1100.f, 1200.f}};
const Matrix3x4 matrix3 = {
        {20.f, 30.f, 40.f, 50.f}, {21.f, 22.f, 23.f, 24.f}, {31.f, 32.f, 33.f, 34.f}};
const Matrix3x4 expected3 = {{121.f, 232.f, 343.f, 454.f},
                             {526.f, 628.f, 730.f, 832.f},
                             {940.f, 1042.f, 1144.f, 1246.f}};

}  // anonymous namespace

#endif  // ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TEST_TEST_MEMORY_H