1/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 3Licensed under the Apache License, Version 2.0 (the "License"); 4you may not use this file except in compliance with the License. 5You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9Unless required by applicable law or agreed to in writing, software 10distributed under the License is distributed on an "AS IS" BASIS, 11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12See the License for the specific language governing permissions and 13limitations under the License. 14==============================================================================*/ 15 16#import <XCTest/XCTest.h> 17 18#include "tensorflow/lite/delegates/gpu/common/status.h" 19#include "tensorflow/lite/delegates/gpu/common/tasks/mean_stddev_normalization_test_util.h" 20#include "tensorflow/lite/delegates/gpu/metal/kernels/test_util.h" 21 22@interface MeanStddevNormalizationTest : XCTestCase 23@end 24 25@implementation MeanStddevNormalizationTest { 26 tflite::gpu::metal::MetalExecutionEnvironment exec_env_; 27} 28 29// note: 100.01 is not representable in FP16 (is in FP32), so use 101.0 instead. 30- (void)testMeanStddevNormSeparateBatches { 31 // zero mean, zero variance 32 auto status = MeanStddevNormSeparateBatchesTest(0.0f, 0.0f, 0.0f, &exec_env_); 33 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 34 35 // zero mean, small variance 36 status = MeanStddevNormSeparateBatchesTest(0.0f, 0.01f, 2.63e-4f, &exec_env_); 37 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 38 39 // zero mean, large variance 40 status = MeanStddevNormSeparateBatchesTest(0.0f, 100.0f, 2.63e-4f, &exec_env_); 41 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 42 43 // small mean, zero variance 44 status = MeanStddevNormSeparateBatchesTest(0.01f, 0.0f, 0.0f, &exec_env_); 45 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 46 47 // small mean, small variance 48 status = MeanStddevNormSeparateBatchesTest(0.01f, 0.01f, 3.57e-4f, &exec_env_); 49 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 50 51 // small mean, large variance 52 status = MeanStddevNormSeparateBatchesTest(1.0f, 100.0f, 2.63e-4f, &exec_env_); 53 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 54 55 // large mean, zero variance 56 status = MeanStddevNormSeparateBatchesTest(100.0f, 0.0f, 0.0f, &exec_env_); 57 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 58 59 // large mean, small variance 60 status = MeanStddevNormSeparateBatchesTest(100.0f, 1.0f, 2.63e-4f, &exec_env_); 61 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 62 63 // large mean, large variance 64 status = MeanStddevNormSeparateBatchesTest(100.0f, 100.0f, 2.63e-4f, &exec_env_); 65 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 66} 67 68- (void)testMeanStddevNormalizationAllBatches { 69 auto status = MeanStddevNormalizationAllBatchesTest(&exec_env_); 70 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 71} 72 73- (void)testMeanStddevNormalizationLargeVector { 74 auto status = MeanStddevNormalizationLargeVectorTest(&exec_env_); 75 XCTAssertTrue(status.ok(), @"%s", std::string(status.message()).c_str()); 76} 77 78@end 79