[
  {
    "path": "CMakeLists.txt",
    "content": "cmake_minimum_required(VERSION 2.8.7)\n\n# ---[ Caffe project\nproject(Caffe C CXX)\n\n# ---[ Using cmake scripts and modules\nlist(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)\n\ninclude(ExternalProject)\n\ninclude(cmake/Utils.cmake)\ninclude(cmake/Targets.cmake)\ninclude(cmake/Misc.cmake)\ninclude(cmake/Summary.cmake)\ninclude(cmake/ConfigGen.cmake)\n\n# ---[ Options\ncaffe_option(CPU_ONLY  \"Build Caffe without CUDA support\" OFF) # TODO: rename to USE_CUDA\ncaffe_option(USE_CUDNN \"Build Caffe with cuDNN libary support\" ON IF NOT CPU_ONLY)\ncaffe_option(BUILD_SHARED_LIBS \"Build shared libraries\" ON)\ncaffe_option(BUILD_python \"Build Python wrapper\" ON)\nset(python_version \"2\" CACHE STRING \"Specify which python version to use\")\ncaffe_option(BUILD_matlab \"Build Matlab wrapper\" OFF IF UNIX OR APPLE)\ncaffe_option(BUILD_docs   \"Build documentation\" ON IF UNIX OR APPLE)\ncaffe_option(BUILD_python_layer \"Build the Caffe python layer\" ON)\n\n# ---[ Dependencies\ninclude(cmake/Dependencies.cmake)\n\n# ---[ Flags\nif(UNIX OR APPLE)\n  set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -fPIC -Wall\")\nendif()\n\nif(USE_libstdcpp)\n  set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -stdlib=libstdc++\")\n  message(\"-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)\")\nendif()\n\nadd_definitions(-DGTEST_USE_OWN_TR1_TUPLE)\n\n# ---[ Warnings\ncaffe_warnings_disable(CMAKE_CXX_FLAGS -Wno-sign-compare -Wno-uninitialized)\n\n# ---[ Config generation\nconfigure_file(cmake/Templates/caffe_config.h.in \"${PROJECT_BINARY_DIR}/caffe_config.h\")\n\n# ---[ Includes\nset(Caffe_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)\ninclude_directories(${Caffe_INCLUDE_DIR} ${PROJECT_BINARY_DIR})\ninclude_directories(BEFORE src) # This is needed for gtest.\n\n# ---[ Subdirectories\nadd_subdirectory(src/gtest)\nadd_subdirectory(src/caffe)\nadd_subdirectory(tools)\nadd_subdirectory(examples)\nadd_subdirectory(python)\nadd_subdirectory(matlab)\nadd_subdirectory(docs)\n\n# ---[ Linter target\nadd_custom_target(lint COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/lint.cmake)\n\n# ---[ pytest target\nadd_custom_target(pytest COMMAND python${python_version} -m unittest discover -s caffe/test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python )\nadd_dependencies(pytest pycaffe)\n\n# ---[ Configuration summary\ncaffe_print_configuration_summary()\n\n# ---[ Export configs generation\ncaffe_generate_export_configs()\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Contributing\n\n## Issues\n\nSpecific Caffe design and development issues, bugs, and feature requests are maintained by GitHub Issues.\n\n_Please do not post usage, installation, or modeling questions, or other requests for help to Issues._\nUse the [caffe-users list](https://groups.google.com/forum/#!forum/caffe-users) instead. This helps developers maintain a clear, uncluttered, and efficient view of the state of Caffe.\n\nWhen reporting a bug, it's most helpful to provide the following information, where applicable:\n\n* What steps reproduce the bug?\n* Can you reproduce the bug using the latest [master](https://github.com/BVLC/caffe/tree/master), compiled with the `DEBUG` make option?\n* What hardware and operating system/distribution are you running?\n* If the bug is a crash, provide the backtrace (usually printed by Caffe; always obtainable with `gdb`).\n\nTry to give your issue a title that is succinct and specific. The devs will rename issues as needed to keep track of them.\n\n## Pull Requests\n\nCaffe welcomes all contributions.\n\nSee the [contributing guide](http://caffe.berkeleyvision.org/development.html) for details.\n\nBriefly: read commit by commit, a PR should tell a clean, compelling story of _one_ improvement to Caffe. In particular:\n\n* A PR should do one clear thing that obviously improves Caffe, and nothing more. Making many smaller PRs is better than making one large PR; review effort is superlinear in the amount of code involved.\n* Similarly, each commit should be a small, atomic change representing one step in development. PRs should be made of many commits where appropriate.\n* Please do rewrite PR history to be clean rather than chronological. Within-PR bugfixes, style cleanups, reversions, etc. should be squashed and should not appear in merged PR history.\n* Anything nonobvious from the code should be explained in comments, commit messages, or the PR description, as appropriate.\n"
  },
  {
    "path": "CONTRIBUTORS.md",
    "content": "# Contributors\n\nCaffe is developed by a core set of BVLC members and the open-source community.\n\nWe thank all of our [contributors](https://github.com/BVLC/caffe/graphs/contributors)!\n\n**For the detailed history of contributions** of a given file, try\n\n    git blame file\n\nto see line-by-line credits and\n\n    git log --follow file\n\nto see the change log even across renames and rewrites.\n\nPlease refer to the [acknowledgements](http://caffe.berkeleyvision.org/#acknowledgements) on the Caffe site for further details.\n\n**Copyright** is held by the original contributor according to the versioning history; see LICENSE.\n"
  },
  {
    "path": "INSTALL.md",
    "content": "# Installation\n\nSee http://caffe.berkeleyvision.org/installation.html for the latest\ninstallation instructions.\n\nCheck the issue tracker in case you need help:\nhttps://github.com/BVLC/caffe/issues\n"
  },
  {
    "path": "LICENSE",
    "content": "COPYRIGHT\n\nAll contributions by the University of California:\nCopyright (c) 2014, 2015, The Regents of the University of California (Regents)\nAll rights reserved.\n\nAll other contributions:\nCopyright (c) 2014, 2015, the respective contributors\nAll rights reserved.\n\nCaffe uses a shared copyright model: each contributor holds copyright over\ntheir contributions to Caffe. The project versioning records all such\ncontribution and copyright details. If a contributor wants to further mark\ntheir specific copyright on a particular contribution, they should indicate\ntheir copyright solely in the commit message of the change when it is\ncommitted.\n\nLICENSE\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met: \n\n1. Redistributions of source code must retain the above copyright notice, this\n   list of conditions and the following disclaimer. \n2. Redistributions in binary form must reproduce the above copyright notice,\n   this list of conditions and the following disclaimer in the documentation\n   and/or other materials provided with the distribution. \n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\nON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nCONTRIBUTION AGREEMENT\n\nBy contributing to the BVLC/caffe repository through pull-request, comment,\nor otherwise, the contributor releases their content to the\nlicense and copyright terms herein.\n\nINTEL LICENSE ON THE SURGETY PARTS\n\nIntel Corporation holds license for the surgery related code. \n"
  },
  {
    "path": "Makefile",
    "content": "PROJECT := caffe\n\nCONFIG_FILE := Makefile.config\n# Explicitly check for the config file, otherwise make -k will proceed anyway.\nifeq ($(wildcard $(CONFIG_FILE)),)\n$(error $(CONFIG_FILE) not found. See $(CONFIG_FILE).example.)\nendif\ninclude $(CONFIG_FILE)\n\nBUILD_DIR_LINK := $(BUILD_DIR)\nifeq ($(RELEASE_BUILD_DIR),)\n\tRELEASE_BUILD_DIR := .$(BUILD_DIR)_release\nendif\nifeq ($(DEBUG_BUILD_DIR),)\n\tDEBUG_BUILD_DIR := .$(BUILD_DIR)_debug\nendif\n\nDEBUG ?= 0\nifeq ($(DEBUG), 1)\n\tBUILD_DIR := $(DEBUG_BUILD_DIR)\n\tOTHER_BUILD_DIR := $(RELEASE_BUILD_DIR)\nelse\n\tBUILD_DIR := $(RELEASE_BUILD_DIR)\n\tOTHER_BUILD_DIR := $(DEBUG_BUILD_DIR)\nendif\n\n# All of the directories containing code.\nSRC_DIRS := $(shell find * -type d -exec bash -c \"find {} -maxdepth 1 \\\n\t\\( -name '*.cpp' -o -name '*.proto' \\) | grep -q .\" \\; -print)\n\n# The target shared library name\nLIB_BUILD_DIR := $(BUILD_DIR)/lib\nSTATIC_NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).a\nDYNAMIC_NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).so\n\n##############################\n# Get all source files\n##############################\n# CXX_SRCS are the source files excluding the test ones.\nCXX_SRCS := $(shell find src/$(PROJECT) ! -name \"test_*.cpp\" -name \"*.cpp\")\n# CU_SRCS are the cuda source files\nCU_SRCS := $(shell find src/$(PROJECT) ! -name \"test_*.cu\" -name \"*.cu\")\n# TEST_SRCS are the test source files\nTEST_MAIN_SRC := src/$(PROJECT)/test/test_caffe_main.cpp\nTEST_SRCS := $(shell find src/$(PROJECT) -name \"test_*.cpp\")\nTEST_SRCS := $(filter-out $(TEST_MAIN_SRC), $(TEST_SRCS))\nTEST_CU_SRCS := $(shell find src/$(PROJECT) -name \"test_*.cu\")\nGTEST_SRC := src/gtest/gtest-all.cpp\n# TOOL_SRCS are the source files for the tool binaries\nTOOL_SRCS := $(shell find tools -name \"*.cpp\")\n# EXAMPLE_SRCS are the source files for the example binaries\nEXAMPLE_SRCS := $(shell find examples -name \"*.cpp\")\n# BUILD_INCLUDE_DIR contains any generated header files we want to include.\nBUILD_INCLUDE_DIR := $(BUILD_DIR)/src\n# PROTO_SRCS are the protocol buffer definitions\nPROTO_SRC_DIR := src/$(PROJECT)/proto\nPROTO_SRCS := $(wildcard $(PROTO_SRC_DIR)/*.proto)\n# PROTO_BUILD_DIR will contain the .cc and obj files generated from\n# PROTO_SRCS; PROTO_BUILD_INCLUDE_DIR will contain the .h header files\nPROTO_BUILD_DIR := $(BUILD_DIR)/$(PROTO_SRC_DIR)\nPROTO_BUILD_INCLUDE_DIR := $(BUILD_INCLUDE_DIR)/$(PROJECT)/proto\n# NONGEN_CXX_SRCS includes all source/header files except those generated\n# automatically (e.g., by proto).\nNONGEN_CXX_SRCS := $(shell find \\\n\tsrc/$(PROJECT) \\\n\tinclude/$(PROJECT) \\\n\tpython/$(PROJECT) \\\n\tmatlab/+$(PROJECT)/private \\\n\texamples \\\n\ttools \\\n\t-name \"*.cpp\" -or -name \"*.hpp\" -or -name \"*.cu\" -or -name \"*.cuh\")\nLINT_SCRIPT := scripts/cpp_lint.py\nLINT_OUTPUT_DIR := $(BUILD_DIR)/.lint\nLINT_EXT := lint.txt\nLINT_OUTPUTS := $(addsuffix .$(LINT_EXT), $(addprefix $(LINT_OUTPUT_DIR)/, $(NONGEN_CXX_SRCS)))\nEMPTY_LINT_REPORT := $(BUILD_DIR)/.$(LINT_EXT)\nNONEMPTY_LINT_REPORT := $(BUILD_DIR)/$(LINT_EXT)\n# PY$(PROJECT)_SRC is the python wrapper for $(PROJECT)\nPY$(PROJECT)_SRC := python/$(PROJECT)/_$(PROJECT).cpp\nPY$(PROJECT)_SO := python/$(PROJECT)/_$(PROJECT).so\nPY$(PROJECT)_HXX := include/$(PROJECT)/python_layer.hpp\n# MAT$(PROJECT)_SRC is the mex entrance point of matlab package for $(PROJECT)\nMAT$(PROJECT)_SRC := matlab/+$(PROJECT)/private/$(PROJECT)_.cpp\nifneq ($(MATLAB_DIR),)\n\tMAT_SO_EXT := $(shell $(MATLAB_DIR)/bin/mexext)\nendif\nMAT$(PROJECT)_SO := matlab/+$(PROJECT)/private/$(PROJECT)_.$(MAT_SO_EXT)\n\n##############################\n# Derive generated files\n##############################\n# The generated files for protocol buffers\nPROTO_GEN_HEADER_SRCS := $(addprefix $(PROTO_BUILD_DIR)/, \\\n\t\t$(notdir ${PROTO_SRCS:.proto=.pb.h}))\nPROTO_GEN_HEADER := $(addprefix $(PROTO_BUILD_INCLUDE_DIR)/, \\\n\t\t$(notdir ${PROTO_SRCS:.proto=.pb.h}))\nPROTO_GEN_CC := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.cc})\nPY_PROTO_BUILD_DIR := python/$(PROJECT)/proto\nPY_PROTO_INIT := python/$(PROJECT)/proto/__init__.py\nPROTO_GEN_PY := $(foreach file,${PROTO_SRCS:.proto=_pb2.py}, \\\n\t\t$(PY_PROTO_BUILD_DIR)/$(notdir $(file)))\n# The objects corresponding to the source files\n# These objects will be linked into the final shared library, so we\n# exclude the tool, example, and test objects.\nCXX_OBJS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o})\nCU_OBJS := $(addprefix $(BUILD_DIR)/cuda/, ${CU_SRCS:.cu=.o})\nPROTO_OBJS := ${PROTO_GEN_CC:.cc=.o}\nOBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS)\n# tool, example, and test objects\nTOOL_OBJS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o})\nTOOL_BUILD_DIR := $(BUILD_DIR)/tools\nTEST_CXX_BUILD_DIR := $(BUILD_DIR)/src/$(PROJECT)/test\nTEST_CU_BUILD_DIR := $(BUILD_DIR)/cuda/src/$(PROJECT)/test\nTEST_CXX_OBJS := $(addprefix $(BUILD_DIR)/, ${TEST_SRCS:.cpp=.o})\nTEST_CU_OBJS := $(addprefix $(BUILD_DIR)/cuda/, ${TEST_CU_SRCS:.cu=.o})\nTEST_OBJS := $(TEST_CXX_OBJS) $(TEST_CU_OBJS)\nGTEST_OBJ := $(addprefix $(BUILD_DIR)/, ${GTEST_SRC:.cpp=.o})\nEXAMPLE_OBJS := $(addprefix $(BUILD_DIR)/, ${EXAMPLE_SRCS:.cpp=.o})\n# Output files for automatic dependency generation\nDEPS := ${CXX_OBJS:.o=.d} ${CU_OBJS:.o=.d} ${TEST_CXX_OBJS:.o=.d} \\\n\t${TEST_CU_OBJS:.o=.d} $(BUILD_DIR)/${MAT$(PROJECT)_SO:.$(MAT_SO_EXT)=.d}\n# tool, example, and test bins\nTOOL_BINS := ${TOOL_OBJS:.o=.bin}\nEXAMPLE_BINS := ${EXAMPLE_OBJS:.o=.bin}\n# symlinks to tool bins without the \".bin\" extension\nTOOL_BIN_LINKS := ${TOOL_BINS:.bin=}\n# Put the test binaries in build/test for convenience.\nTEST_BIN_DIR := $(BUILD_DIR)/test\nTEST_CU_BINS := $(addsuffix .testbin,$(addprefix $(TEST_BIN_DIR)/, \\\n\t\t$(foreach obj,$(TEST_CU_OBJS),$(basename $(notdir $(obj))))))\nTEST_CXX_BINS := $(addsuffix .testbin,$(addprefix $(TEST_BIN_DIR)/, \\\n\t\t$(foreach obj,$(TEST_CXX_OBJS),$(basename $(notdir $(obj))))))\nTEST_BINS := $(TEST_CXX_BINS) $(TEST_CU_BINS)\n# TEST_ALL_BIN is the test binary that links caffe dynamically.\nTEST_ALL_BIN := $(TEST_BIN_DIR)/test_all.testbin\n\n##############################\n# Derive compiler warning dump locations\n##############################\nWARNS_EXT := warnings.txt\nCXX_WARNS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o.$(WARNS_EXT)})\nCU_WARNS := $(addprefix $(BUILD_DIR)/cuda/, ${CU_SRCS:.cu=.o.$(WARNS_EXT)})\nTOOL_WARNS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o.$(WARNS_EXT)})\nEXAMPLE_WARNS := $(addprefix $(BUILD_DIR)/, ${EXAMPLE_SRCS:.cpp=.o.$(WARNS_EXT)})\nTEST_WARNS := $(addprefix $(BUILD_DIR)/, ${TEST_SRCS:.cpp=.o.$(WARNS_EXT)})\nTEST_CU_WARNS := $(addprefix $(BUILD_DIR)/cuda/, ${TEST_CU_SRCS:.cu=.o.$(WARNS_EXT)})\nALL_CXX_WARNS := $(CXX_WARNS) $(TOOL_WARNS) $(EXAMPLE_WARNS) $(TEST_WARNS)\nALL_CU_WARNS := $(CU_WARNS) $(TEST_CU_WARNS)\nALL_WARNS := $(ALL_CXX_WARNS) $(ALL_CU_WARNS)\n\nEMPTY_WARN_REPORT := $(BUILD_DIR)/.$(WARNS_EXT)\nNONEMPTY_WARN_REPORT := $(BUILD_DIR)/$(WARNS_EXT)\n\n##############################\n# Derive include and lib directories\n##############################\nCUDA_INCLUDE_DIR := $(CUDA_DIR)/include\n\nCUDA_LIB_DIR :=\n# add <cuda>/lib64 only if it exists\nifneq (\"$(wildcard $(CUDA_DIR)/lib64)\",\"\")\n\tCUDA_LIB_DIR += $(CUDA_DIR)/lib64\nendif\nCUDA_LIB_DIR += $(CUDA_DIR)/lib\n\nINCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include\nifneq ($(CPU_ONLY), 1)\n\tINCLUDE_DIRS += $(CUDA_INCLUDE_DIR)\n\tLIBRARY_DIRS += $(CUDA_LIB_DIR)\n\tLIBRARIES := cudart cublas curand\nendif\nLIBRARIES += glog gflags protobuf leveldb snappy \\\n\tlmdb boost_system hdf5_hl hdf5 m \\\n\topencv_core opencv_highgui opencv_imgproc\nPYTHON_LIBRARIES := boost_python python2.7\nWARNINGS := -Wall -Wno-sign-compare\n\n##############################\n# Set build directories\n##############################\n\nDISTRIBUTE_DIR ?= distribute\nDISTRIBUTE_SUBDIRS := $(DISTRIBUTE_DIR)/bin $(DISTRIBUTE_DIR)/lib\nDIST_ALIASES := dist\nifneq ($(strip $(DISTRIBUTE_DIR)),distribute)\n\t\tDIST_ALIASES += distribute\nendif\n\nALL_BUILD_DIRS := $(sort $(BUILD_DIR) $(addprefix $(BUILD_DIR)/, $(SRC_DIRS)) \\\n\t$(addprefix $(BUILD_DIR)/cuda/, $(SRC_DIRS)) \\\n\t$(LIB_BUILD_DIR) $(TEST_BIN_DIR) $(PY_PROTO_BUILD_DIR) $(LINT_OUTPUT_DIR) \\\n\t$(DISTRIBUTE_SUBDIRS) $(PROTO_BUILD_INCLUDE_DIR))\n\n##############################\n# Set directory for Doxygen-generated documentation\n##############################\nDOXYGEN_CONFIG_FILE ?= ./.Doxyfile\n# should be the same as OUTPUT_DIRECTORY in the .Doxyfile\nDOXYGEN_OUTPUT_DIR ?= ./doxygen\nDOXYGEN_COMMAND ?= doxygen\n# All the files that might have Doxygen documentation.\nDOXYGEN_SOURCES := $(shell find \\\n\tsrc/$(PROJECT) \\\n\tinclude/$(PROJECT) \\\n\tpython/ \\\n\tmatlab/ \\\n\texamples \\\n\ttools \\\n\t-name \"*.cpp\" -or -name \"*.hpp\" -or -name \"*.cu\" -or -name \"*.cuh\" -or \\\n        -name \"*.py\" -or -name \"*.m\")\nDOXYGEN_SOURCES += $(DOXYGEN_CONFIG_FILE)\n\n\n##############################\n# Configure build\n##############################\n\n# Determine platform\nUNAME := $(shell uname -s)\nifeq ($(UNAME), Linux)\n\tLINUX := 1\nelse ifeq ($(UNAME), Darwin)\n\tOSX := 1\nendif\n\n# Linux\nifeq ($(LINUX), 1)\n\tCXX ?= /usr/bin/g++\n\tGCCVERSION := $(shell $(CXX) -dumpversion | cut -f1,2 -d.)\n\t# older versions of gcc are too dumb to build boost with -Wuninitalized\n\tifeq ($(shell echo | awk '{exit $(GCCVERSION) < 4.6;}'), 1)\n\t\tWARNINGS += -Wno-uninitialized\n\tendif\n\t# boost::thread is reasonably called boost_thread (compare OS X)\n\t# We will also explicitly add stdc++ to the link target.\n\tLIBRARIES += boost_thread stdc++\nendif\n\n# OS X:\n# clang++ instead of g++\n# libstdc++ for NVCC compatibility on OS X >= 10.9 with CUDA < 7.0\nifeq ($(OSX), 1)\n\tCXX := /usr/bin/clang++\n\tifneq ($(CPU_ONLY), 1)\n\t\tCUDA_VERSION := $(shell $(CUDA_DIR)/bin/nvcc -V | grep -o 'release \\d' | grep -o '\\d')\n\t\tifeq ($(shell echo | awk '{exit $(CUDA_VERSION) < 7.0;}'), 1)\n\t\t\tCXXFLAGS += -stdlib=libstdc++\n\t\t\tLINKFLAGS += -stdlib=libstdc++\n\t\tendif\n\t\t# clang throws this warning for cuda headers\n\t\tWARNINGS += -Wno-unneeded-internal-declaration\n\tendif\n\t# gtest needs to use its own tuple to not conflict with clang\n\tCOMMON_FLAGS += -DGTEST_USE_OWN_TR1_TUPLE=1\n\t# boost::thread is called boost_thread-mt to mark multithreading on OS X\n\tLIBRARIES += boost_thread-mt\n\t# we need to explicitly ask for the rpath to be obeyed\n\tDYNAMIC_FLAGS := -install_name @rpath/libcaffe.so\n\tORIGIN := @loader_path\nelse\n\tORIGIN := \\$$ORIGIN\nendif\n\n# Custom compiler\nifdef CUSTOM_CXX\n\tCXX := $(CUSTOM_CXX)\nendif\n\n# Static linking\nifneq (,$(findstring clang++,$(CXX)))\n\tSTATIC_LINK_COMMAND := -Wl,-force_load $(STATIC_NAME)\nelse ifneq (,$(findstring g++,$(CXX)))\n\tSTATIC_LINK_COMMAND := -Wl,--whole-archive $(STATIC_NAME) -Wl,--no-whole-archive\nelse\n  # The following line must not be indented with a tab, since we are not inside a target\n  $(error Cannot static link with the $(CXX) compiler)\nendif\n\n# Debugging\nifeq ($(DEBUG), 1)\n\tCOMMON_FLAGS += -DDEBUG -g -O0\n\tNVCCFLAGS += -G\nelse\n\tCOMMON_FLAGS += -DNDEBUG -O2\nendif\n\n# cuDNN acceleration configuration.\nifeq ($(USE_CUDNN), 1)\n\tLIBRARIES += cudnn\n\tCOMMON_FLAGS += -DUSE_CUDNN\nendif\n\n# CPU-only configuration\nifeq ($(CPU_ONLY), 1)\n\tOBJS := $(PROTO_OBJS) $(CXX_OBJS)\n\tTEST_OBJS := $(TEST_CXX_OBJS)\n\tTEST_BINS := $(TEST_CXX_BINS)\n\tALL_WARNS := $(ALL_CXX_WARNS)\n\tTEST_FILTER := --gtest_filter=\"-*GPU*\"\n\tCOMMON_FLAGS += -DCPU_ONLY\nendif\n\n# Python layer support\nifeq ($(WITH_PYTHON_LAYER), 1)\n\tCOMMON_FLAGS += -DWITH_PYTHON_LAYER\n\tLIBRARIES += $(PYTHON_LIBRARIES)\nendif\n\n# BLAS configuration (default = ATLAS)\nBLAS ?= atlas\nifeq ($(BLAS), mkl)\n\t# MKL\n\tLIBRARIES += mkl_rt\n\tCOMMON_FLAGS += -DUSE_MKL\n\tMKL_DIR ?= /opt/intel/mkl\n\tBLAS_INCLUDE ?= $(MKL_DIR)/include\n\tBLAS_LIB ?= $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64\nelse ifeq ($(BLAS), open)\n\t# OpenBLAS\n\tLIBRARIES += openblas\nelse\n\t# ATLAS\n\tifeq ($(LINUX), 1)\n\t\tifeq ($(BLAS), atlas)\n\t\t\t# Linux simply has cblas and atlas\n\t\t\tLIBRARIES += cblas atlas\n\t\tendif\n\telse ifeq ($(OSX), 1)\n\t\t# OS X packages atlas as the vecLib framework\n\t\tLIBRARIES += cblas\n\t\t# 10.10 has accelerate while 10.9 has veclib\n\t\tXCODE_CLT_VER := $(shell pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep -o 'version: 6')\n\t\tifneq (,$(findstring version: 6,$(XCODE_CLT_VER)))\n\t\t\tBLAS_INCLUDE ?= /System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Headers/\n\t\t\tLDFLAGS += -framework Accelerate\n\t\telse\n\t\t\tBLAS_INCLUDE ?= /System/Library/Frameworks/vecLib.framework/Versions/Current/Headers/\n\t\t\tLDFLAGS += -framework vecLib\n\t\tendif\n\tendif\nendif\nINCLUDE_DIRS += $(BLAS_INCLUDE)\nLIBRARY_DIRS += $(BLAS_LIB)\n\nLIBRARY_DIRS += $(LIB_BUILD_DIR)\n\n# Automatic dependency generation (nvcc is handled separately)\nCXXFLAGS += -MMD -MP\n\n# Complete build flags.\nCOMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))\nCXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)\nNVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)\n# mex may invoke an older gcc that is too liberal with -Wuninitalized\nMATLAB_CXXFLAGS := $(CXXFLAGS) -Wno-uninitialized\nLINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)\n\nUSE_PKG_CONFIG ?= 0\nifeq ($(USE_PKG_CONFIG), 1)\n\tPKG_CONFIG := $(shell pkg-config opencv --libs)\nelse\n\tPKG_CONFIG :=\nendif\nLDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \\\n\t\t$(foreach library,$(LIBRARIES),-l$(library))\nPYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library))\n\n# 'superclean' target recursively* deletes all files ending with an extension\n# in $(SUPERCLEAN_EXTS) below.  This may be useful if you've built older\n# versions of Caffe that do not place all generated files in a location known\n# to the 'clean' target.\n#\n# 'supercleanlist' will list the files to be deleted by make superclean.\n#\n# * Recursive with the exception that symbolic links are never followed, per the\n# default behavior of 'find'.\nSUPERCLEAN_EXTS := .so .a .o .bin .testbin .pb.cc .pb.h _pb2.py .cuo\n\n# Set the sub-targets of the 'everything' target.\nEVERYTHING_TARGETS := all py$(PROJECT) test warn lint\n# Only build matcaffe as part of \"everything\" if MATLAB_DIR is specified.\nifneq ($(MATLAB_DIR),)\n\tEVERYTHING_TARGETS += mat$(PROJECT)\nendif\n\n##############################\n# Define build targets\n##############################\n.PHONY: all lib test clean docs linecount lint lintclean tools examples $(DIST_ALIASES) \\\n\tpy mat py$(PROJECT) mat$(PROJECT) proto runtest \\\n\tsuperclean supercleanlist supercleanfiles warn everything\n\nall: lib tools examples\n\nlib: $(STATIC_NAME) $(DYNAMIC_NAME)\n\neverything: $(EVERYTHING_TARGETS)\n\nlinecount:\n\tcloc --read-lang-def=$(PROJECT).cloc \\\n\t\tsrc/$(PROJECT) include/$(PROJECT) tools examples \\\n\t\tpython matlab\n\nlint: $(EMPTY_LINT_REPORT)\n\nlintclean:\n\t@ $(RM) -r $(LINT_OUTPUT_DIR) $(EMPTY_LINT_REPORT) $(NONEMPTY_LINT_REPORT)\n\ndocs: $(DOXYGEN_OUTPUT_DIR)\n\t@ cd ./docs ; ln -sfn ../$(DOXYGEN_OUTPUT_DIR)/html doxygen\n\n$(DOXYGEN_OUTPUT_DIR): $(DOXYGEN_CONFIG_FILE) $(DOXYGEN_SOURCES)\n\t$(DOXYGEN_COMMAND) $(DOXYGEN_CONFIG_FILE)\n\n$(EMPTY_LINT_REPORT): $(LINT_OUTPUTS) | $(BUILD_DIR)\n\t@ cat $(LINT_OUTPUTS) > $@\n\t@ if [ -s \"$@\" ]; then \\\n\t\tcat $@; \\\n\t\tmv $@ $(NONEMPTY_LINT_REPORT); \\\n\t\techo \"Found one or more lint errors.\"; \\\n\t\texit 1; \\\n\t  fi; \\\n\t  $(RM) $(NONEMPTY_LINT_REPORT); \\\n\t  echo \"No lint errors!\";\n\n$(LINT_OUTPUTS): $(LINT_OUTPUT_DIR)/%.lint.txt : % $(LINT_SCRIPT) | $(LINT_OUTPUT_DIR)\n\t@ mkdir -p $(dir $@)\n\t@ python $(LINT_SCRIPT) $< 2>&1 \\\n\t\t| grep -v \"^Done processing \" \\\n\t\t| grep -v \"^Total errors found: 0\" \\\n\t\t> $@ \\\n\t\t|| true\n\ntest: $(TEST_ALL_BIN) $(TEST_ALL_DYNLINK_BIN) $(TEST_BINS)\n\ntools: $(TOOL_BINS) $(TOOL_BIN_LINKS)\n\nexamples: $(EXAMPLE_BINS)\n\npy$(PROJECT): py\n\npy: $(PY$(PROJECT)_SO) $(PROTO_GEN_PY)\n\n$(PY$(PROJECT)_SO): $(PY$(PROJECT)_SRC) $(PY$(PROJECT)_HXX) | $(DYNAMIC_NAME)\n\t@ echo CXX/LD -o $@ $<\n\t$(Q)$(CXX) -shared -o $@ $(PY$(PROJECT)_SRC) \\\n\t\t-o $@ $(LINKFLAGS) -l$(PROJECT) $(PYTHON_LDFLAGS) \\\n\t\t-Wl,-rpath,$(ORIGIN)/../../build/lib\n\nmat$(PROJECT): mat\n\nmat: $(MAT$(PROJECT)_SO)\n\n$(MAT$(PROJECT)_SO): $(MAT$(PROJECT)_SRC) $(STATIC_NAME)\n\t@ if [ -z \"$(MATLAB_DIR)\" ]; then \\\n\t\techo \"MATLAB_DIR must be specified in $(CONFIG_FILE)\" \\\n\t\t\t\"to build mat$(PROJECT).\"; \\\n\t\texit 1; \\\n\tfi\n\t@ echo MEX $<\n\t$(Q)$(MATLAB_DIR)/bin/mex $(MAT$(PROJECT)_SRC) \\\n\t\t\tCXX=\"$(CXX)\" \\\n\t\t\tCXXFLAGS=\"\\$$CXXFLAGS $(MATLAB_CXXFLAGS)\" \\\n\t\t\tCXXLIBS=\"\\$$CXXLIBS $(STATIC_LINK_COMMAND) $(LDFLAGS)\" -output $@\n\t@ if [ -f \"$(PROJECT)_.d\" ]; then \\\n\t\tmv -f $(PROJECT)_.d $(BUILD_DIR)/${MAT$(PROJECT)_SO:.$(MAT_SO_EXT)=.d}; \\\n\tfi\n\nruntest: $(TEST_ALL_BIN)\n\t$(TOOL_BUILD_DIR)/caffe\n\t$(TEST_ALL_BIN) $(TEST_GPUID) --gtest_shuffle $(TEST_FILTER)\n\npytest: py\n\tcd python; python -m unittest discover -s caffe/test\n\t\nmattest: mat\n\tcd matlab; $(MATLAB_DIR)/bin/matlab -nodisplay -r 'caffe.run_tests(), exit()'\n\nwarn: $(EMPTY_WARN_REPORT)\n\n$(EMPTY_WARN_REPORT): $(ALL_WARNS) | $(BUILD_DIR)\n\t@ cat $(ALL_WARNS) > $@\n\t@ if [ -s \"$@\" ]; then \\\n\t\tcat $@; \\\n\t\tmv $@ $(NONEMPTY_WARN_REPORT); \\\n\t\techo \"Compiler produced one or more warnings.\"; \\\n\t\texit 1; \\\n\t  fi; \\\n\t  $(RM) $(NONEMPTY_WARN_REPORT); \\\n\t  echo \"No compiler warnings!\";\n\n$(ALL_WARNS): %.o.$(WARNS_EXT) : %.o\n\n$(BUILD_DIR_LINK): $(BUILD_DIR)/.linked\n\n# Create a target \".linked\" in this BUILD_DIR to tell Make that the \"build\" link\n# is currently correct, then delete the one in the OTHER_BUILD_DIR in case it\n# exists and $(DEBUG) is toggled later.\n$(BUILD_DIR)/.linked:\n\t@ mkdir -p $(BUILD_DIR)\n\t@ $(RM) $(OTHER_BUILD_DIR)/.linked\n\t@ $(RM) -r $(BUILD_DIR_LINK)\n\t@ ln -s $(BUILD_DIR) $(BUILD_DIR_LINK)\n\t@ touch $@\n\n$(ALL_BUILD_DIRS): | $(BUILD_DIR_LINK)\n\t@ mkdir -p $@\n\n$(DYNAMIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)\n\t@ echo LD -o $@\n\t$(Q)$(CXX) -shared -o $@ $(OBJS) $(LINKFLAGS) $(LDFLAGS) $(DYNAMIC_FLAGS)\n\n$(STATIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)\n\t@ echo AR -o $@\n\t$(Q)ar rcs $@ $(OBJS)\n\n$(BUILD_DIR)/%.o: %.cpp | $(ALL_BUILD_DIRS)\n\t@ echo CXX $<\n\t$(Q)$(CXX) $< $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \\\n\t\t|| (cat $@.$(WARNS_EXT); exit 1)\n\t@ cat $@.$(WARNS_EXT)\n\n$(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_GEN_HEADER) \\\n\t\t| $(PROTO_BUILD_DIR)\n\t@ echo CXX $<\n\t$(Q)$(CXX) $< $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \\\n\t\t|| (cat $@.$(WARNS_EXT); exit 1)\n\t@ cat $@.$(WARNS_EXT)\n\n$(BUILD_DIR)/cuda/%.o: %.cu | $(ALL_BUILD_DIRS)\n\t@ echo NVCC $<\n\t$(Q)$(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -M $< -o ${@:.o=.d} \\\n\t\t-odir $(@D)\n\t$(Q)$(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@ 2> $@.$(WARNS_EXT) \\\n\t\t|| (cat $@.$(WARNS_EXT); exit 1)\n\t@ cat $@.$(WARNS_EXT)\n\n$(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \\\n\t\t| $(DYNAMIC_NAME) $(TEST_BIN_DIR)\n\t@ echo CXX/LD -o $@ $<\n\t$(Q)$(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \\\n\t\t-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(ORIGIN)/../lib\n\n$(TEST_CU_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CU_BUILD_DIR)/%.o \\\n\t$(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)\n\t@ echo LD $<\n\t$(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \\\n\t\t-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(ORIGIN)/../lib\n\n$(TEST_CXX_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CXX_BUILD_DIR)/%.o \\\n\t$(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)\n\t@ echo LD $<\n\t$(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \\\n\t\t-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(PROJECT) -Wl,-rpath,$(ORIGIN)/../lib\n\n# Target for extension-less symlinks to tool binaries with extension '*.bin'.\n$(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR)\n\t@ $(RM) $@\n\t@ ln -s $(abspath $<) $@\n\n$(TOOL_BINS): %.bin : %.o | $(DYNAMIC_NAME)\n\t@ echo CXX/LD -o $@\n\t$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(PROJECT) $(LDFLAGS) \\\n\t\t-Wl,-rpath,$(ORIGIN)/../lib\n\n$(EXAMPLE_BINS): %.bin : %.o | $(DYNAMIC_NAME)\n\t@ echo CXX/LD -o $@\n\t$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(PROJECT) $(LDFLAGS) \\\n\t\t-Wl,-rpath,$(ORIGIN)/../../lib\n\nproto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER)\n\n$(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \\\n\t\t$(PROTO_SRC_DIR)/%.proto | $(PROTO_BUILD_DIR)\n\t@ echo PROTOC $<\n\t$(Q)protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<\n\n$(PY_PROTO_BUILD_DIR)/%_pb2.py : $(PROTO_SRC_DIR)/%.proto \\\n\t\t$(PY_PROTO_INIT) | $(PY_PROTO_BUILD_DIR)\n\t@ echo PROTOC \\(python\\) $<\n\t$(Q)protoc --proto_path=$(PROTO_SRC_DIR) --python_out=$(PY_PROTO_BUILD_DIR) $<\n\n$(PY_PROTO_INIT): | $(PY_PROTO_BUILD_DIR)\n\ttouch $(PY_PROTO_INIT)\n\nclean:\n\t@- $(RM) -rf $(ALL_BUILD_DIRS)\n\t@- $(RM) -rf $(OTHER_BUILD_DIR)\n\t@- $(RM) -rf $(BUILD_DIR_LINK)\n\t@- $(RM) -rf $(DISTRIBUTE_DIR)\n\t@- $(RM) $(PY$(PROJECT)_SO)\n\t@- $(RM) $(MAT$(PROJECT)_SO)\n\nsupercleanfiles:\n\t$(eval SUPERCLEAN_FILES := $(strip \\\n\t\t\t$(foreach ext,$(SUPERCLEAN_EXTS), $(shell find . -name '*$(ext)' \\\n\t\t\t-not -path './data/*'))))\n\nsupercleanlist: supercleanfiles\n\t@ \\\n\tif [ -z \"$(SUPERCLEAN_FILES)\" ]; then \\\n\t\techo \"No generated files found.\"; \\\n\telse \\\n\t\techo $(SUPERCLEAN_FILES) | tr ' ' '\\n'; \\\n\tfi\n\nsuperclean: clean supercleanfiles\n\t@ \\\n\tif [ -z \"$(SUPERCLEAN_FILES)\" ]; then \\\n\t\techo \"No generated files found.\"; \\\n\telse \\\n\t\techo \"Deleting the following generated files:\"; \\\n\t\techo $(SUPERCLEAN_FILES) | tr ' ' '\\n'; \\\n\t\t$(RM) $(SUPERCLEAN_FILES); \\\n\tfi\n\n$(DIST_ALIASES): $(DISTRIBUTE_DIR)\n\n$(DISTRIBUTE_DIR): all py | $(DISTRIBUTE_SUBDIRS)\n\t# add include\n\tcp -r include $(DISTRIBUTE_DIR)/\n\tmkdir -p $(DISTRIBUTE_DIR)/include/caffe/proto\n\tcp $(PROTO_GEN_HEADER_SRCS) $(DISTRIBUTE_DIR)/include/caffe/proto\n\t# add tool and example binaries\n\tcp $(TOOL_BINS) $(DISTRIBUTE_DIR)/bin\n\tcp $(EXAMPLE_BINS) $(DISTRIBUTE_DIR)/bin\n\t# add libraries\n\tcp $(STATIC_NAME) $(DISTRIBUTE_DIR)/lib\n\tcp $(DYNAMIC_NAME) $(DISTRIBUTE_DIR)/lib\n\t# add python - it's not the standard way, indeed...\n\tcp -r python $(DISTRIBUTE_DIR)/python\n\n-include $(DEPS)\n"
  },
  {
    "path": "Makefile.config.example",
    "content": "## Refer to http://caffe.berkeleyvision.org/installation.html\n# Contributions simplifying and improving our build system are welcome!\n\n# cuDNN acceleration switch (uncomment to build with cuDNN).\n# USE_CUDNN := 1\n\n# CPU-only switch (uncomment to build without GPU support).\n# CPU_ONLY := 1\n\n# To customize your choice of compiler, uncomment and set the following.\n# N.B. the default for Linux is g++ and the default for OSX is clang++\n# CUSTOM_CXX := g++\n\n# CUDA directory contains bin/ and lib/ directories that we need.\nCUDA_DIR := /usr/local/cuda\n# On Ubuntu 14.04, if cuda tools are installed via\n# \"sudo apt-get install nvidia-cuda-toolkit\" then use this instead:\n# CUDA_DIR := /usr\n\n# CUDA architecture setting: going with all of them.\n# For CUDA < 6.0, comment the *_50 lines for compatibility.\nCUDA_ARCH := -gencode arch=compute_20,code=sm_20 \\\n\t\t-gencode arch=compute_20,code=sm_21 \\\n\t\t-gencode arch=compute_30,code=sm_30 \\\n\t\t-gencode arch=compute_35,code=sm_35 \\\n\t\t-gencode arch=compute_50,code=sm_50 \\\n\t\t-gencode arch=compute_50,code=compute_50\n\n# BLAS choice:\n# atlas for ATLAS (default)\n# mkl for MKL\n# open for OpenBlas\nBLAS := atlas\n# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.\n# Leave commented to accept the defaults for your choice of BLAS\n# (which should work)!\n# BLAS_INCLUDE := /path/to/your/blas\n# BLAS_LIB := /path/to/your/blas\n\n# Homebrew puts openblas in a directory that is not on the standard search path\n# BLAS_INCLUDE := $(shell brew --prefix openblas)/include\n# BLAS_LIB := $(shell brew --prefix openblas)/lib\n\n# This is required only if you will compile the matlab interface.\n# MATLAB directory should contain the mex binary in /bin.\n# MATLAB_DIR := /usr/local\n# MATLAB_DIR := /Applications/MATLAB_R2012b.app\n\n# NOTE: this is required only if you will compile the python interface.\n# We need to be able to find Python.h and numpy/arrayobject.h.\nPYTHON_INCLUDE := /usr/include/python2.7 \\\n\t\t/usr/lib/python2.7/dist-packages/numpy/core/include\n# Anaconda Python distribution is quite popular. Include path:\n# Verify anaconda location, sometimes it's in root.\n# ANACONDA_HOME := $(HOME)/anaconda\n# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \\\n\t\t# $(ANACONDA_HOME)/include/python2.7 \\\n\t\t# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \\\n\n# We need to be able to find libpythonX.X.so or .dylib.\nPYTHON_LIB := /usr/lib\n# PYTHON_LIB := $(ANACONDA_HOME)/lib\n\n# Homebrew installs numpy in a non standard path (keg only)\n# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include\n# PYTHON_LIB += $(shell brew --prefix numpy)/lib\n\n# Uncomment to support layers written in Python (will link against Python libs)\n# WITH_PYTHON_LAYER := 1\n\n# Whatever else you find you need goes here.\nINCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include\nLIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib\n\n# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies\n# INCLUDE_DIRS += $(shell brew --prefix)/include\n# LIBRARY_DIRS += $(shell brew --prefix)/lib\n\n# Uncomment to use `pkg-config` to specify OpenCV library paths.\n# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)\n# USE_PKG_CONFIG := 1\n\nBUILD_DIR := build\nDISTRIBUTE_DIR := distribute\n\n# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171\n# DEBUG := 1\n\n# The ID of the GPU that 'make runtest' will use to run unit tests.\nTEST_GPUID := 0\n\n# enable pretty build (comment to see full commands)\nQ ?= @\n"
  },
  {
    "path": "README.md",
    "content": "# Dynamic network surgery\n\nDynamic network surgery is a very effective method for DNN pruning. To better use it with python and matlab, you may also need a [classic version](https://github.com/BVLC/caffe/tree/aa2a6f55b9e50b29d607aaee0fae19bd085d6565) of the [Caffe framework](http://caffe.berkeleyvision.org).\nFor the convolutional and fully-connected layers to be pruned, change their layer types to \"CConvolution\" and \"CInnerProduct\" respectively. Then, pass \"cconvolution_param\" and \"cinner_product_param\" messages to these modified layers for better pruning performance. \n\n# Example for usage\n\nBelow is an example for pruning the \"ip1\" layer in LeNet5:\n\n    layer {\n      name: \"ip1\"\n      type: \"CInnerProduct\"\n      bottom: \"pool2\"\n      top: \"ip1\"\n      param {\n        lr_mult: 1\n      }\n      param {\n        lr_mult: 2\n      }\n      inner_product_param {\n        num_output: 500\n        weight_filler {\n          type: \"xavier\"\n        }\n        bias_filler {\n          type: \"constant\"\n        }\n      }\n      cinner_product_param {\n        gamma: 0.0001\n        power: 1\n        c_rate: 4\n        iter_stop: 14000  \n        weight_mask_filler {\n          type: \"constant\"\n          value: 1\n        }\n        bias_mask_filler {\n          type: \"constant\"\n          value: 1\n        }        \n      }   \n    }\n\n# Citation\n\nPlease cite our work in your publications if it helps your research:\n\n    @inproceedings{guo2016dynamic,\t\t\n      title = {Dynamic Network Surgery for Efficient DNNs},\n      author = {Guo, Yiwen and Yao, Anbang and Chen, Yurong},\n      booktitle = {Advances in neural information processing systems (NIPS)},\n      year = {2016}\n    } \n\t\t\nand\tdo not forget about Caffe:\t\n\n    @article{jia2014caffe,\n      Author = {Jia, Yangqing and Shelhamer, Evan and Donahue, Jeff and Karayev, Sergey and Long, Jonathan and Girshick, Ross and Guadarrama, Sergio and Darrell, Trevor},\n      Journal = {arXiv preprint arXiv:1408.5093},\n      Title = {Caffe: Convolutional Architecture for Fast Feature Embedding},\n      Year = {2014}\n    }\n\nEnjoy your own surgeries!\n"
  },
  {
    "path": "caffe.cloc",
    "content": "Bourne Shell\n    filter remove_matches ^\\s*#\n    filter remove_inline #.*$\n    extension sh\n    script_exe sh\nC\n    filter remove_matches ^\\s*//\n    filter call_regexp_common C\n    filter remove_inline //.*$\n    extension c\n    extension ec\n    extension pgc\nC++\n    filter remove_matches ^\\s*//\n    filter remove_inline //.*$\n    filter call_regexp_common C\n    extension C\n    extension cc\n    extension cpp\n    extension cxx\n    extension pcc\nC/C++ Header\n    filter remove_matches ^\\s*//\n    filter call_regexp_common C\n    filter remove_inline //.*$\n    extension H\n    extension h\n    extension hh\n    extension hpp\nCUDA\n    filter remove_matches ^\\s*//\n    filter remove_inline //.*$\n    filter call_regexp_common C\n    extension cu\nPython\n    filter remove_matches ^\\s*#\n    filter docstring_to_C\n    filter call_regexp_common C\n    filter remove_inline #.*$\n    extension py\nmake\n    filter remove_matches ^\\s*#\n    filter remove_inline #.*$\n    extension Gnumakefile\n    extension Makefile\n    extension am\n    extension gnumakefile\n    extension makefile\n    filename Gnumakefile\n    filename Makefile\n    filename gnumakefile\n    filename makefile\n    script_exe make\n"
  },
  {
    "path": "cmake/ConfigGen.cmake",
    "content": "\n################################################################################################\n# Helper function to fetch caffe includes which will be passed to dependent projects\n# Usage:\n#   caffe_get_current_includes(<includes_list_variable>)\nfunction(caffe_get_current_includes includes_variable)\n  get_property(current_includes DIRECTORY PROPERTY INCLUDE_DIRECTORIES)\n  caffe_convert_absolute_paths(current_includes)\n\n  # remove at most one ${PROJECT_BINARY_DIR} include added for caffe_config.h\n  list(FIND current_includes ${PROJECT_BINARY_DIR} __index)\n  list(REMOVE_AT current_includes ${__index})\n\n  # removing numpy includes (since not required for client libs)\n  set(__toremove \"\")\n  foreach(__i ${current_includes})\n    if(${__i} MATCHES \"python\")\n      list(APPEND __toremove ${__i})\n    endif()\n  endforeach()\n  if(__toremove)\n    list(REMOVE_ITEM current_includes ${__toremove})\n  endif()\n\n  caffe_list_unique(current_includes)\n  set(${includes_variable} ${current_includes} PARENT_SCOPE)\nendfunction()\n\n################################################################################################\n# Helper function to get all list items that begin with given prefix\n# Usage:\n#   caffe_get_items_with_prefix(<prefix> <list_variable> <output_variable>)\nfunction(caffe_get_items_with_prefix prefix list_variable output_variable)\n  set(__result \"\")\n  foreach(__e ${${list_variable}})\n    if(__e MATCHES \"^${prefix}.*\")\n      list(APPEND __result ${__e})\n    endif()\n  endforeach()\n  set(${output_variable} ${__result} PARENT_SCOPE)\nendfunction()\n\n################################################################################################\n# Function for generation Caffe build- and install- tree export config files\n# Usage:\n#  caffe_generate_export_configs()\nfunction(caffe_generate_export_configs)\n  set(install_cmake_suffix \"share/Caffe\")\n\n  # ---[ Configure build-tree CaffeConfig.cmake file ]---\n  caffe_get_current_includes(Caffe_INCLUDE_DIRS)\n\n  set(Caffe_DEFINITIONS \"\")\n  if(NOT HAVE_CUDA)\n    set(HAVE_CUDA FALSE)\n    list(APPEND Caffe_DEFINITIONS -DCPU_ONLY)\n  endif()\n\n  if(NOT HAVE_CUDNN)\n    set(HAVE_CUDNN FALSE)\n  else()\n    list(APPEND DEFINITIONS -DUSE_CUDNN)\n  endif()\n\n  if(BLAS STREQUAL \"MKL\" OR BLAS STREQUAL \"mkl\")\n    list(APPEND Caffe_DEFINITIONS -DUSE_MKL)\n  endif()\n\n  configure_file(\"cmake/Templates/CaffeConfig.cmake.in\" \"${PROJECT_BINARY_DIR}/CaffeConfig.cmake\" @ONLY)\n\n  # Add targets to the build-tree export set\n  export(TARGETS caffe proto FILE \"${PROJECT_BINARY_DIR}/CaffeTargets.cmake\")\n  export(PACKAGE Caffe)\n\n  # ---[ Configure install-tree CaffeConfig.cmake file ]---\n\n  # remove source and build dir includes\n  caffe_get_items_with_prefix(${PROJECT_SOURCE_DIR} Caffe_INCLUDE_DIRS __insource)\n  caffe_get_items_with_prefix(${PROJECT_BINARY_DIR} Caffe_INCLUDE_DIRS __inbinary)\n  list(REMOVE_ITEM Caffe_INCLUDE_DIRS ${__insource} ${__inbinary})\n\n  # add `install` include folder\n  set(lines\n     \"get_filename_component(__caffe_include \\\"\\${Caffe_CMAKE_DIR}/../../include\\\" ABSOLUTE)\\n\"\n     \"list(APPEND Caffe_INCLUDE_DIRS \\${__caffe_include})\\n\"\n     \"unset(__caffe_include)\\n\")\n  string(REPLACE \";\" \"\" Caffe_INSTALL_INCLUDE_DIR_APPEND_COMMAND ${lines})\n\n  configure_file(\"cmake/Templates/CaffeConfig.cmake.in\" \"${PROJECT_BINARY_DIR}/cmake/CaffeConfig.cmake\" @ONLY)\n\n  # Install the CaffeConfig.cmake and export set to use with install-tree\n  install(FILES \"${PROJECT_BINARY_DIR}/cmake/CaffeConfig.cmake\" DESTINATION ${install_cmake_suffix})\n  install(EXPORT CaffeTargets DESTINATION ${install_cmake_suffix})\n\n  # ---[ Configure and install version file ]---\n\n  # TODO: Lines below are commented because Caffe does't declare its version in headers.\n  # When the declarations are added, modify `caffe_extract_caffe_version()` macro and uncomment\n\n  # configure_file(cmake/Templates/CaffeConfigVersion.cmake.in \"${PROJECT_BINARY_DIR}/CaffeConfigVersion.cmake\" @ONLY)\n  # install(FILES \"${PROJECT_BINARY_DIR}/CaffeConfigVersion.cmake\" DESTINATION ${install_cmake_suffix})\nendfunction()\n\n\n"
  },
  {
    "path": "cmake/Cuda.cmake",
    "content": "if(CPU_ONLY)\n  return()\nendif()\n\n# Known NVIDIA GPU achitectures Caffe can be compiled for.\n# This list will be used for CUDA_ARCH_NAME = All option\nset(Caffe_known_gpu_archs \"20 21(20) 30 35 50\")\n\n################################################################################################\n# A function for automatic detection of GPUs installed  (if autodetection is enabled)\n# Usage:\n#   caffe_detect_installed_gpus(out_variable)\nfunction(caffe_detect_installed_gpus out_variable)\n  if(NOT CUDA_gpu_detect_output)\n    set(__cufile ${PROJECT_BINARY_DIR}/detect_cuda_archs.cu)\n\n    file(WRITE ${__cufile} \"\"\n      \"#include <cstdio>\\n\"\n      \"int main()\\n\"\n      \"{\\n\"\n      \"  int count = 0;\\n\"\n      \"  if (cudaSuccess != cudaGetDeviceCount(&count)) return -1;\\n\"\n      \"  if (count == 0) return -1;\\n\"\n      \"  for (int device = 0; device < count; ++device)\\n\"\n      \"  {\\n\"\n      \"    cudaDeviceProp prop;\\n\"\n      \"    if (cudaSuccess == cudaGetDeviceProperties(&prop, device))\\n\"\n      \"      std::printf(\\\"%d.%d \\\", prop.major, prop.minor);\\n\"\n      \"  }\\n\"\n      \"  return 0;\\n\"\n      \"}\\n\")\n\n    execute_process(COMMAND \"${CUDA_NVCC_EXECUTABLE}\" \"--run\" \"${__cufile}\"\n                    WORKING_DIRECTORY \"${PROJECT_BINARY_DIR}/CMakeFiles/\"\n                    RESULT_VARIABLE __nvcc_res OUTPUT_VARIABLE __nvcc_out\n                    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)\n\n    if(__nvcc_res EQUAL 0)\n      string(REPLACE \"2.1\" \"2.1(2.0)\" __nvcc_out \"${__nvcc_out}\")\n      set(CUDA_gpu_detect_output ${__nvcc_out} CACHE INTERNAL \"Returned GPU architetures from caffe_detect_gpus tool\" FORCE)\n    endif()\n  endif()\n\n  if(NOT CUDA_gpu_detect_output)\n    message(STATUS \"Automatic GPU detection failed. Building for all known architectures.\")\n    set(${out_variable} ${Caffe_known_gpu_archs} PARENT_SCOPE)\n  else()\n    set(${out_variable} ${CUDA_gpu_detect_output} PARENT_SCOPE)\n  endif()\nendfunction()\n\n\n################################################################################################\n# Function for selecting GPU arch flags for nvcc based on CUDA_ARCH_NAME\n# Usage:\n#   caffe_select_nvcc_arch_flags(out_variable)\nfunction(caffe_select_nvcc_arch_flags out_variable)\n  # List of arch names\n  set(__archs_names \"Fermi\" \"Kepler\" \"Maxwell\" \"All\" \"Manual\")\n  set(__archs_name_default \"All\")\n  if(NOT CMAKE_CROSSCOMPILING)\n    list(APPEND __archs_names \"Auto\")\n    set(__archs_name_default \"Auto\")\n  endif()\n\n  # set CUDA_ARCH_NAME strings (so it will be seen as dropbox in CMake-Gui)\n  set(CUDA_ARCH_NAME ${__archs_name_default} CACHE STRING \"Select target NVIDIA GPU achitecture.\")\n  set_property( CACHE CUDA_ARCH_NAME PROPERTY STRINGS \"\" ${__archs_names} )\n  mark_as_advanced(CUDA_ARCH_NAME)\n\n  # verify CUDA_ARCH_NAME value\n  if(NOT \";${__archs_names};\" MATCHES \";${CUDA_ARCH_NAME};\")\n    string(REPLACE \";\" \", \" __archs_names \"${__archs_names}\")\n    message(FATAL_ERROR \"Only ${__archs_names} architeture names are supported.\")\n  endif()\n\n  if(${CUDA_ARCH_NAME} STREQUAL \"Manual\")\n    set(CUDA_ARCH_BIN ${Caffe_known_gpu_archs} CACHE STRING \"Specify 'real' GPU architectures to build binaries for, BIN(PTX) format is supported\")\n    set(CUDA_ARCH_PTX \"50\"                     CACHE STRING \"Specify 'virtual' PTX architectures to build PTX intermediate code for\")\n    mark_as_advanced(CUDA_ARCH_BIN CUDA_ARCH_PTX)\n  else()\n    unset(CUDA_ARCH_BIN CACHE)\n    unset(CUDA_ARCH_PTX CACHE)\n  endif()\n\n  if(${CUDA_ARCH_NAME} STREQUAL \"Fermi\")\n    set(__cuda_arch_bin \"20 21(20)\")\n  elseif(${CUDA_ARCH_NAME} STREQUAL \"Kepler\")\n    set(__cuda_arch_bin \"30 35\")\n  elseif(${CUDA_ARCH_NAME} STREQUAL \"Maxwell\")\n    set(__cuda_arch_bin \"50\")\n  elseif(${CUDA_ARCH_NAME} STREQUAL \"All\")\n    set(__cuda_arch_bin ${Caffe_known_gpu_archs})\n  elseif(${CUDA_ARCH_NAME} STREQUAL \"Auto\")\n    caffe_detect_installed_gpus(__cuda_arch_bin)\n  else()  # (${CUDA_ARCH_NAME} STREQUAL \"Manual\")\n    set(__cuda_arch_bin ${CUDA_ARCH_BIN})\n  endif()\n\n  # remove dots and convert to lists\n  string(REGEX REPLACE \"\\\\.\" \"\" __cuda_arch_bin \"${__cuda_arch_bin}\")\n  string(REGEX REPLACE \"\\\\.\" \"\" __cuda_arch_ptx \"${CUDA_ARCH_PTX}\")\n  string(REGEX MATCHALL \"[0-9()]+\" __cuda_arch_bin \"${__cuda_arch_bin}\")\n  string(REGEX MATCHALL \"[0-9]+\"   __cuda_arch_ptx \"${__cuda_arch_ptx}\")\n  caffe_list_unique(__cuda_arch_bin __cuda_arch_ptx)\n\n  set(__nvcc_flags \"\")\n  set(__nvcc_archs_readable \"\")\n\n  # Tell NVCC to add binaries for the specified GPUs\n  foreach(__arch ${__cuda_arch_bin})\n    if(__arch MATCHES \"([0-9]+)\\\\(([0-9]+)\\\\)\")\n      # User explicitly specified PTX for the concrete BIN\n      list(APPEND __nvcc_flags -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})\n      list(APPEND __nvcc_archs_readable sm_${CMAKE_MATCH_1})\n    else()\n      # User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN\n      list(APPEND __nvcc_flags -gencode arch=compute_${__arch},code=sm_${__arch})\n      list(APPEND __nvcc_archs_readable sm_${__arch})\n    endif()\n  endforeach()\n\n  # Tell NVCC to add PTX intermediate code for the specified architectures\n  foreach(__arch ${__cuda_arch_ptx})\n    list(APPEND __nvcc_flags -gencode arch=compute_${__arch},code=compute_${__arch})\n    list(APPEND __nvcc_archs_readable compute_${__arch})\n  endforeach()\n\n  string(REPLACE \";\" \" \" __nvcc_archs_readable \"${__nvcc_archs_readable}\")\n  set(${out_variable}          ${__nvcc_flags}          PARENT_SCOPE)\n  set(${out_variable}_readable ${__nvcc_archs_readable} PARENT_SCOPE)\nendfunction()\n\n################################################################################################\n# Short command for cuda comnpilation\n# Usage:\n#   caffe_cuda_compile(<objlist_variable> <cuda_files>)\nmacro(caffe_cuda_compile objlist_variable)\n  foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)\n    set(${var}_backup_in_cuda_compile_ \"${${var}}\")\n\n    # we remove /EHa as it generates warnings under windows\n    string(REPLACE \"/EHa\" \"\" ${var} \"${${var}}\")\n\n  endforeach()\n\n  if(UNIX OR APPLE)\n    list(APPEND CUDA_NVCC_FLAGS -Xcompiler -fPIC)\n  endif()\n\n  if(APPLE)\n    list(APPEND CUDA_NVCC_FLAGS -Xcompiler -Wno-unused-function)\n  endif()\n\n  cuda_compile(cuda_objcs ${ARGN})\n\n  foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)\n    set(${var} \"${${var}_backup_in_cuda_compile_}\")\n    unset(${var}_backup_in_cuda_compile_)\n  endforeach()\n\n  set(${objlist_variable} ${cuda_objcs})\nendmacro()\n\n################################################################################################\n# Short command for cuDNN detection. Believe it soon will be a part of CUDA toolkit distribution.\n# That's why not FindcuDNN.cmake file, but just the macro\n# Usage:\n#   detect_cuDNN()\nfunction(detect_cuDNN)\n  set(CUDNN_ROOT \"\" CACHE PATH \"CUDNN root folder\")\n\n  find_path(CUDNN_INCLUDE cudnn.h\n            PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT} ${CUDA_TOOLKIT_INCLUDE}\n            DOC \"Path to cuDNN include directory.\" )\n\n  get_filename_component(__libpath_hist ${CUDA_CUDART_LIBRARY} PATH)\n  find_library(CUDNN_LIBRARY NAMES libcudnn.so # libcudnn_static.a\n                             PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT} ${CUDNN_INCLUDE} ${__libpath_hist}\n                             DOC \"Path to cuDNN library.\")\n\n  if(CUDNN_INCLUDE AND CUDNN_LIBRARY)\n    set(HAVE_CUDNN  TRUE PARENT_SCOPE)\n    set(CUDNN_FOUND TRUE PARENT_SCOPE)\n\n    mark_as_advanced(CUDNN_INCLUDE CUDNN_LIBRARY CUDNN_ROOT)\n    message(STATUS \"Found cuDNN (include: ${CUDNN_INCLUDE}, library: ${CUDNN_LIBRARY})\")\n  endif()\nendfunction()\n\n\n################################################################################################\n###  Non macro section\n################################################################################################\n\nfind_package(CUDA 5.5 QUIET)\nfind_cuda_helper_libs(curand)  # cmake 2.8.7 compartibility which doesn't search for curand\n\nif(NOT CUDA_FOUND)\n  return()\nendif()\n\nset(HAVE_CUDA TRUE)\nmessage(STATUS \"CUDA detected: \" ${CUDA_VERSION})\ninclude_directories(SYSTEM ${CUDA_INCLUDE_DIRS})\nlist(APPEND Caffe_LINKER_LIBS ${CUDA_CUDART_LIBRARY}\n                              ${CUDA_curand_LIBRARY} ${CUDA_CUBLAS_LIBRARIES})\n\n# cudnn detection\nif(USE_CUDNN)\n  detect_cuDNN()\n  if(HAVE_CUDNN)\n    add_definitions(-DUSE_CUDNN)\n    include_directories(SYSTEM ${CUDNN_INCLUDE})\n    list(APPEND Caffe_LINKER_LIBS ${CUDNN_LIBRARY})\n  endif()\nendif()\n\n# setting nvcc arch flags\ncaffe_select_nvcc_arch_flags(NVCC_FLAGS_EXTRA)\nlist(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA})\nmessage(STATUS \"Added CUDA NVCC flags for: ${NVCC_FLAGS_EXTRA_readable}\")\n\n# Boost 1.55 workaround, see https://svn.boost.org/trac/boost/ticket/9392 or\n# https://github.com/ComputationalRadiationPhysics/picongpu/blob/master/src/picongpu/CMakeLists.txt\nif(Boost_VERSION EQUAL 105500)\n  message(STATUS \"Cuda + Boost 1.55: Applying noinline work around\")\n  # avoid warning for CMake >= 2.8.12\n  set(CUDA_NVCC_FLAGS \"${CUDA_NVCC_FLAGS} \\\"-DBOOST_NOINLINE=__attribute__((noinline))\\\" \")\nendif()\n\n# disable some nvcc diagnostic that apears in boost, glog, glags, opencv, etc.\nforeach(diag cc_clobber_ignored integer_sign_change useless_using_declaration set_but_not_used)\n  list(APPEND CUDA_NVCC_FLAGS -Xcudafe --diag_suppress=${diag})\nendforeach()\n\n# setting default testing device\nif(NOT CUDA_TEST_DEVICE)\n  set(CUDA_TEST_DEVICE -1)\nendif()\n\nmark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD)\nmark_as_advanced(CUDA_SDK_ROOT_DIR CUDA_SEPARABLE_COMPILATION)\n\n# Handle clang/libc++ issue\nif(APPLE)\n  caffe_detect_darwin_version(OSX_VERSION)\n\n  # OSX 10.9 and higher uses clang/libc++ by default which is incompartible with old CUDA toolkits\n  if(OSX_VERSION VERSION_GREATER 10.8)\n    # enabled by default if and only if CUDA version is less than 7.0\n    caffe_option(USE_libstdcpp \"Use libstdc++ instead of libc++\" (CUDA_VERSION VERSION_LESS 7.0))\n  endif()\nendif()\n"
  },
  {
    "path": "cmake/Dependencies.cmake",
    "content": "# This list is required for static linking and exported to CaffeConfig.cmake\nset(Caffe_LINKER_LIBS \"\")\n\n# ---[ Boost\nfind_package(Boost 1.46 REQUIRED COMPONENTS system thread)\ninclude_directories(SYSTEM ${Boost_INCLUDE_DIR})\nlist(APPEND Caffe_LINKER_LIBS ${Boost_LIBRARIES})\n\n# ---[ Threads\nfind_package(Threads REQUIRED)\nlist(APPEND Caffe_LINKER_LIBS ${CMAKE_THREAD_LIBS_INIT})\n\n# ---[ Google-glog\ninclude(\"cmake/External/glog.cmake\")\ninclude_directories(SYSTEM ${GLOG_INCLUDE_DIRS})\nlist(APPEND Caffe_LINKER_LIBS ${GLOG_LIBRARIES})\n\n# ---[ Google-gflags\ninclude(\"cmake/External/gflags.cmake\")\ninclude_directories(SYSTEM ${GFLAGS_INCLUDE_DIRS})\nlist(APPEND Caffe_LINKER_LIBS ${GFLAGS_LIBRARIES})\n\n# ---[ Google-protobuf\ninclude(cmake/ProtoBuf.cmake)\n\n# ---[ HDF5\nfind_package(HDF5 COMPONENTS HL REQUIRED)\ninclude_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})\nlist(APPEND Caffe_LINKER_LIBS ${HDF5_LIBRARIES})\n\n# ---[ LMDB\nfind_package(LMDB REQUIRED)\ninclude_directories(SYSTEM ${LMDB_INCLUDE_DIR})\nlist(APPEND Caffe_LINKER_LIBS ${LMDB_LIBRARIES})\n\n# ---[ LevelDB\nfind_package(LevelDB REQUIRED)\ninclude_directories(SYSTEM ${LevelDB_INCLUDE})\nlist(APPEND Caffe_LINKER_LIBS ${LevelDB_LIBRARIES})\n\n# ---[ Snappy\nfind_package(Snappy REQUIRED)\ninclude_directories(SYSTEM ${Snappy_INCLUDE_DIR})\nlist(APPEND Caffe_LINKER_LIBS ${Snappy_LIBRARIES})\n\n# ---[ CUDA\ninclude(cmake/Cuda.cmake)\nif(NOT HAVE_CUDA)\n  if(CPU_ONLY)\n    message(\"-- CUDA is disabled. Building without it...\")\n  else()\n    message(\"-- CUDA is not detected by cmake. Building without it...\")\n  endif()\n\n  # TODO: remove this not cross platform define in future. Use caffe_config.h instead.\n  add_definitions(-DCPU_ONLY)\nendif()\n\n# ---[ OpenCV\nfind_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)\nif(NOT OpenCV_FOUND) # if not OpenCV 3.x, then imgcodecs are not found\n  find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)\nendif()\ninclude_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})\nlist(APPEND Caffe_LINKER_LIBS ${OpenCV_LIBS})\nmessage(STATUS \"OpenCV found (${OpenCV_CONFIG_PATH})\")\n\n# ---[ BLAS\nif(NOT APPLE)\n  set(BLAS \"Atlas\" CACHE STRING \"Selected BLAS library\")\n  set_property(CACHE BLAS PROPERTY STRINGS \"Atlas;Open;MKL\")\n\n  if(BLAS STREQUAL \"Atlas\" OR BLAS STREQUAL \"atlas\")\n    find_package(Atlas REQUIRED)\n    include_directories(SYSTEM ${Atlas_INCLUDE_DIR})\n    list(APPEND Caffe_LINKER_LIBS ${Atlas_LIBRARIES})\n  elseif(BLAS STREQUAL \"Open\" OR BLAS STREQUAL \"open\")\n    find_package(OpenBLAS REQUIRED)\n    include_directories(SYSTEM ${OpenBLAS_INCLUDE_DIR})\n    list(APPEND Caffe_LINKER_LIBS ${OpenBLAS_LIB})\n  elseif(BLAS STREQUAL \"MKL\" OR BLAS STREQUAL \"mkl\")\n    find_package(MKL REQUIRED)\n    include_directories(SYSTEM ${MKL_INCLUDE_DIR})\n    list(APPEND Caffe_LINKER_LIBS ${MKL_LIBRARIES})\n    add_definitions(-DUSE_MKL)\n  endif()\nelseif(APPLE)\n  find_package(vecLib REQUIRED)\n  include_directories(SYSTEM ${vecLib_INCLUDE_DIR})\n  list(APPEND Caffe_LINKER_LIBS ${vecLib_LINKER_LIBS})\nendif()\n\n# ---[ Python\nif(BUILD_python)\n  if(NOT \"${python_version}\" VERSION_LESS \"3.0.0\")\n    # use python3\n    find_package(PythonInterp 3.0)\n    find_package(PythonLibs 3.0)\n    find_package(NumPy 1.7.1)\n    # Find the matching boost python implementation\n    set(version ${PYTHONLIBS_VERSION_STRING})\n    \n    STRING( REPLACE \".\" \"\" boost_py_version ${version} )\n    find_package(Boost 1.46 COMPONENTS \"python-py${boost_py_version}\")\n    set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})\n    \n    while(NOT \"${version}\" STREQUAL \"\" AND NOT Boost_PYTHON_FOUND)\n      STRING( REGEX REPLACE \"([0-9.]+).[0-9]+\" \"\\\\1\" version ${version} )\n      \n      STRING( REPLACE \".\" \"\" boost_py_version ${version} )\n      find_package(Boost 1.46 COMPONENTS \"python-py${boost_py_version}\")\n      set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})\n      \n      STRING( REGEX MATCHALL \"([0-9.]+).[0-9]+\" has_more_version ${version} )\n      if(\"${has_more_version}\" STREQUAL \"\")\n        break()\n      endif()\n    endwhile()\n    if(NOT Boost_PYTHON_FOUND)\n      find_package(Boost 1.46 COMPONENTS python)\n    endif()\n  else()\n    # disable Python 3 search\n    find_package(PythonInterp 2.7)\n    find_package(PythonLibs 2.7)\n    find_package(NumPy 1.7.1)\n    find_package(Boost 1.46 COMPONENTS python)\n  endif()\n  if(PYTHONLIBS_FOUND AND NUMPY_FOUND AND Boost_PYTHON_FOUND)\n    set(HAVE_PYTHON TRUE)\n    if(BUILD_python_layer)\n      add_definitions(-DWITH_PYTHON_LAYER)\n      include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})\n      list(APPEND Caffe_LINKER_LIBS ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})\n    endif()\n  endif()\nendif()\n\n# ---[ Matlab\nif(BUILD_matlab)\n  find_package(MatlabMex)\n  if(MATLABMEX_FOUND)\n    set(HAVE_MATLAB TRUE)\n  endif()\n\n  # sudo apt-get install liboctave-dev\n  find_program(Octave_compiler NAMES mkoctfile DOC \"Octave C++ compiler\")\n\n  if(HAVE_MATLAB AND Octave_compiler)\n    set(Matlab_build_mex_using \"Matlab\" CACHE STRING \"Select Matlab or Octave if both detected\")\n    set_property(CACHE Matlab_build_mex_using PROPERTY STRINGS \"Matlab;Octave\")\n  endif()\nendif()\n\n# ---[ Doxygen\nif(BUILD_docs)\n  find_package(Doxygen)\nendif()\n"
  },
  {
    "path": "cmake/External/gflags.cmake",
    "content": "if (NOT __GFLAGS_INCLUDED) # guard against multiple includes\n  set(__GFLAGS_INCLUDED TRUE)\n\n  # use the system-wide gflags if present\n  find_package(GFlags)\n  if (GFLAGS_FOUND)\n    set(GFLAGS_EXTERNAL FALSE)\n  else()\n    # gflags will use pthreads if it's available in the system, so we must link with it\n    find_package(Threads)\n\n    # build directory\n    set(gflags_PREFIX ${CMAKE_BINARY_DIR}/external/gflags-prefix)\n    # install directory\n    set(gflags_INSTALL ${CMAKE_BINARY_DIR}/external/gflags-install)\n\n    # we build gflags statically, but want to link it into the caffe shared library\n    # this requires position-independent code\n    if (UNIX)\n        set(GFLAGS_EXTRA_COMPILER_FLAGS \"-fPIC\")\n    endif()\n\n    set(GFLAGS_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${GFLAGS_EXTRA_COMPILER_FLAGS})\n    set(GFLAGS_C_FLAGS ${CMAKE_C_FLAGS} ${GFLAGS_EXTRA_COMPILER_FLAGS})\n\n    ExternalProject_Add(gflags\n      PREFIX ${gflags_PREFIX}\n      GIT_REPOSITORY \"https://github.com/gflags/gflags.git\"\n      GIT_TAG \"v2.1.2\"\n      UPDATE_COMMAND \"\"\n      INSTALL_DIR ${gflags_INSTALL}\n      CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}\n                 -DCMAKE_INSTALL_PREFIX=${gflags_INSTALL}\n                 -DBUILD_SHARED_LIBS=OFF\n                 -DBUILD_STATIC_LIBS=ON\n                 -DBUILD_PACKAGING=OFF\n                 -DBUILD_TESTING=OFF\n                 -DBUILD_NC_TESTS=OFF\n                 -BUILD_CONFIG_TESTS=OFF\n                 -DINSTALL_HEADERS=ON\n                 -DCMAKE_C_FLAGS=${GFLAGS_C_FLAGS}\n                 -DCMAKE_CXX_FLAGS=${GFLAGS_CXX_FLAGS}\n      LOG_DOWNLOAD 1\n      LOG_INSTALL 1\n      )\n\n    set(GFLAGS_FOUND TRUE)\n    set(GFLAGS_INCLUDE_DIRS ${gflags_INSTALL}/include)\n    set(GFLAGS_LIBRARIES ${gflags_INSTALL}/lib/libgflags.a ${CMAKE_THREAD_LIBS_INIT})\n    set(GFLAGS_LIBRARY_DIRS ${gflags_INSTALL}/lib)\n    set(GFLAGS_EXTERNAL TRUE)\n\n    list(APPEND external_project_dependencies gflags)\n  endif()\n\nendif()\n"
  },
  {
    "path": "cmake/External/glog.cmake",
    "content": "# glog depends on gflags\ninclude(\"cmake/External/gflags.cmake\")\n\nif (NOT __GLOG_INCLUDED)\n  set(__GLOG_INCLUDED TRUE)\n\n  # try the system-wide glog first\n  find_package(Glog)\n  if (GLOG_FOUND)\n      set(GLOG_EXTERNAL FALSE)\n  else()\n    # fetch and build glog from github\n\n    # build directory\n    set(glog_PREFIX ${CMAKE_BINARY_DIR}/external/glog-prefix)\n    # install directory\n    set(glog_INSTALL ${CMAKE_BINARY_DIR}/external/glog-install)\n\n    # we build glog statically, but want to link it into the caffe shared library\n    # this requires position-independent code\n    if (UNIX)\n      set(GLOG_EXTRA_COMPILER_FLAGS \"-fPIC\")\n    endif()\n\n    set(GLOG_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${GLOG_EXTRA_COMPILER_FLAGS})\n    set(GLOG_C_FLAGS ${CMAKE_C_FLAGS} ${GLOG_EXTRA_COMPILER_FLAGS})\n\n    # depend on gflags if we're also building it\n    if (GFLAGS_EXTERNAL)\n      set(GLOG_DEPENDS gflags)\n    endif()\n\n    ExternalProject_Add(glog\n      DEPENDS ${GLOG_DEPENDS}\n      PREFIX ${glog_PREFIX}\n      GIT_REPOSITORY \"https://github.com/google/glog\"\n      GIT_TAG \"v0.3.4\"\n      UPDATE_COMMAND \"\"\n      INSTALL_DIR ${gflags_INSTALL}\n      CONFIGURE_COMMAND env \"CFLAGS=${GLOG_C_FLAGS}\" \"CXXFLAGS=${GLOG_CXX_FLAGS}\" ${glog_PREFIX}/src/glog/configure --prefix=${glog_INSTALL} --enable-shared=no --enable-static=yes --with-gflags=${GFLAGS_LIBRARY_DIRS}/..\n      LOG_DOWNLOAD 1\n      LOG_CONFIGURE 1\n      LOG_INSTALL 1\n      )\n\n    set(GLOG_FOUND TRUE)\n    set(GLOG_INCLUDE_DIRS ${glog_INSTALL}/include)\n    set(GLOG_LIBRARIES ${GFLAGS_LIBRARIES} ${glog_INSTALL}/lib/libglog.a)\n    set(GLOG_LIBRARY_DIRS ${glog_INSTALL}/lib)\n    set(GLOG_EXTERNAL TRUE)\n\n    list(APPEND external_project_dependencies glog)\n  endif()\n\nendif()\n\n"
  },
  {
    "path": "cmake/Misc.cmake",
    "content": "# ---[ Configuration types\nset(CMAKE_CONFIGURATION_TYPES \"Debug;Release\" CACHE STRING \"Possible configurations\" FORCE)\nmark_as_advanced(CMAKE_CONFIGURATION_TYPES)\n\nif(DEFINED CMAKE_BUILD_TYPE)\n  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})\nendif()\n\n# --[ If user doesn't specify build type then assume release\nif(\"${CMAKE_BUILD_TYPE}\" STREQUAL \"\")\n  set(CMAKE_BUILD_TYPE Release)\nendif()\n\nif(\"${CMAKE_CXX_COMPILER_ID}\" STREQUAL \"Clang\")\n  set(CMAKE_COMPILER_IS_CLANGXX TRUE)\nendif()\n\n# ---[ Solution folders\ncaffe_option(USE_PROJECT_FOLDERS \"IDE Solution folders\" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )\n\nif(USE_PROJECT_FOLDERS)\n  set_property(GLOBAL PROPERTY USE_FOLDERS ON)\n  set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER \"CMakeTargets\")\nendif()\n\n# ---[ Install options\nif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)\n  set(CMAKE_INSTALL_PREFIX \"${PROJECT_BINARY_DIR}/install\" CACHE PATH \"Default install path\" FORCE)\nendif()\n\n# ---[ RPATH settings\nset(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOLEAN \"Use link paths for shared library rpath\")\nset(CMAKE_MACOSX_RPATH TRUE)\n\nlist(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/lib __is_systtem_dir)\nif(${__is_systtem_dir} STREQUAL -1)\n  set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)\nendif()\n\n# ---[ Funny target\nif(UNIX OR APPLE)\n  add_custom_target(symlink_to_build COMMAND \"ln\" \"-sf\" \"${PROJECT_BINARY_DIR}\" \"${PROJECT_SOURCE_DIR}/build\"\n                                     COMMENT \"Adding symlink: <caffe_root>/build -> ${PROJECT_BINARY_DIR}\" )\nendif()\n\n# ---[ Set debug postfix\nset(Caffe_DEBUG_POSTFIX \"-d\")\n\nset(CAffe_POSTFIX \"\")\nif(CMAKE_BUILD_TYPE MATCHES \"Debug\")\n  set(CAffe_POSTFIX ${Caffe_DEBUG_POSTFIX})\nendif()\n"
  },
  {
    "path": "cmake/Modules/FindAtlas.cmake",
    "content": "# Find the Atlas (and Lapack) libraries\n#\n# The following variables are optionally searched for defaults\n#  Atlas_ROOT_DIR:            Base directory where all Atlas components are found\n#\n# The following are set after configuration is done:\n#  Atlas_FOUND\n#  Atlas_INCLUDE_DIRS\n#  Atlas_LIBRARIES\n#  Atlas_LIBRARYRARY_DIRS\n\nset(Atlas_INCLUDE_SEARCH_PATHS\n  /usr/include/atlas\n  /usr/include/atlas-base\n  $ENV{Atlas_ROOT_DIR}\n  $ENV{Atlas_ROOT_DIR}/include\n)\n\nset(Atlas_LIB_SEARCH_PATHS\n  /usr/lib/atlas\n  /usr/lib/atlas-base\n  $ENV{Atlas_ROOT_DIR}\n  $ENV{Atlas_ROOT_DIR}/lib\n)\n\nfind_path(Atlas_CBLAS_INCLUDE_DIR   NAMES cblas.h   PATHS ${Atlas_INCLUDE_SEARCH_PATHS})\nfind_path(Atlas_CLAPACK_INCLUDE_DIR NAMES clapack.h PATHS ${Atlas_INCLUDE_SEARCH_PATHS})\n\nfind_library(Atlas_CBLAS_LIBRARY NAMES  ptcblas_r ptcblas cblas_r cblas PATHS ${Atlas_LIB_SEARCH_PATHS})\nfind_library(Atlas_BLAS_LIBRARY NAMES   atlas_r   atlas                 PATHS ${Atlas_LIB_SEARCH_PATHS})\nfind_library(Atlas_LAPACK_LIBRARY NAMES alapack_r alapack lapack_atlas  PATHS ${Atlas_LIB_SEARCH_PATHS})\n\nset(LOOKED_FOR\n  Atlas_CBLAS_INCLUDE_DIR\n  Atlas_CLAPACK_INCLUDE_DIR\n\n  Atlas_CBLAS_LIBRARY\n  Atlas_BLAS_LIBRARY\n  Atlas_LAPACK_LIBRARY\n)\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(Atlas DEFAULT_MSG ${LOOKED_FOR})\n\nif(ATLAS_FOUND)\n  set(Atlas_INCLUDE_DIR ${Atlas_CBLAS_INCLUDE_DIR} ${Atlas_CLAPACK_INCLUDE_DIR})\n  set(Atlas_LIBRARIES ${Atlas_LAPACK_LIBRARY} ${Atlas_CBLAS_LIBRARY} ${Atlas_BLAS_LIBRARY})\n  mark_as_advanced(${LOOKED_FOR})\n\n  message(STATUS \"Found Atlas (include: ${Atlas_CBLAS_INCLUDE_DIR}, library: ${Atlas_BLAS_LIBRARY})\")\nendif(ATLAS_FOUND)\n\n"
  },
  {
    "path": "cmake/Modules/FindGFlags.cmake",
    "content": "# - Try to find GFLAGS\n#\n# The following variables are optionally searched for defaults\n#  GFLAGS_ROOT_DIR:            Base directory where all GFLAGS components are found\n#\n# The following are set after configuration is done:\n#  GFLAGS_FOUND\n#  GFLAGS_INCLUDE_DIRS\n#  GFLAGS_LIBRARIES\n#  GFLAGS_LIBRARYRARY_DIRS\n\ninclude(FindPackageHandleStandardArgs)\n\nset(GFLAGS_ROOT_DIR \"\" CACHE PATH \"Folder contains Gflags\")\n\n# We are testing only a couple of files in the include directories\nif(WIN32)\n    find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h\n        PATHS ${GFLAGS_ROOT_DIR}/src/windows)\nelse()\n    find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h\n        PATHS ${GFLAGS_ROOT_DIR})\nendif()\n\nif(MSVC)\n    find_library(GFLAGS_LIBRARY_RELEASE\n        NAMES libgflags\n        PATHS ${GFLAGS_ROOT_DIR}\n        PATH_SUFFIXES Release)\n\n    find_library(GFLAGS_LIBRARY_DEBUG\n        NAMES libgflags-debug\n        PATHS ${GFLAGS_ROOT_DIR}\n        PATH_SUFFIXES Debug)\n\n    set(GFLAGS_LIBRARY optimized ${GFLAGS_LIBRARY_RELEASE} debug ${GFLAGS_LIBRARY_DEBUG})\nelse()\n    find_library(GFLAGS_LIBRARY gflags)\nendif()\n\nfind_package_handle_standard_args(GFlags DEFAULT_MSG GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)\n\n\nif(GFLAGS_FOUND)\n    set(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR})\n    set(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY})\n    message(STATUS \"Found gflags  (include: ${GFLAGS_INCLUDE_DIR}, library: ${GFLAGS_LIBRARY})\")\n    mark_as_advanced(GFLAGS_LIBRARY_DEBUG GFLAGS_LIBRARY_RELEASE\n                     GFLAGS_LIBRARY GFLAGS_INCLUDE_DIR GFLAGS_ROOT_DIR)\nendif()\n"
  },
  {
    "path": "cmake/Modules/FindGlog.cmake",
    "content": "# - Try to find Glog\n#\n# The following variables are optionally searched for defaults\n#  GLOG_ROOT_DIR:            Base directory where all GLOG components are found\n#\n# The following are set after configuration is done:\n#  GLOG_FOUND\n#  GLOG_INCLUDE_DIRS\n#  GLOG_LIBRARIES\n#  GLOG_LIBRARYRARY_DIRS\n\ninclude(FindPackageHandleStandardArgs)\n\nset(GLOG_ROOT_DIR \"\" CACHE PATH \"Folder contains Google glog\")\n\nif(WIN32)\n    find_path(GLOG_INCLUDE_DIR glog/logging.h\n        PATHS ${GLOG_ROOT_DIR}/src/windows)\nelse()\n    find_path(GLOG_INCLUDE_DIR glog/logging.h\n        PATHS ${GLOG_ROOT_DIR})\nendif()\n\nif(MSVC)\n    find_library(GLOG_LIBRARY_RELEASE libglog_static\n        PATHS ${GLOG_ROOT_DIR}\n        PATH_SUFFIXES Release)\n\n    find_library(GLOG_LIBRARY_DEBUG libglog_static\n        PATHS ${GLOG_ROOT_DIR}\n        PATH_SUFFIXES Debug)\n\n    set(GLOG_LIBRARY optimized ${GLOG_LIBRARY_RELEASE} debug ${GLOG_LIBRARY_DEBUG})\nelse()\n    find_library(GLOG_LIBRARY glog\n        PATHS ${GLOG_ROOT_DIR}\n        PATH_SUFFIXES lib lib64)\nendif()\n\nfind_package_handle_standard_args(Glog DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY)\n\nif(GLOG_FOUND)\n  set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})\n  set(GLOG_LIBRARIES ${GLOG_LIBRARY})\n  message(STATUS \"Found glog    (include: ${GLOG_INCLUDE_DIR}, library: ${GLOG_LIBRARY})\")\n  mark_as_advanced(GLOG_ROOT_DIR GLOG_LIBRARY_RELEASE GLOG_LIBRARY_DEBUG\n                                 GLOG_LIBRARY GLOG_INCLUDE_DIR)\nendif()\n"
  },
  {
    "path": "cmake/Modules/FindLAPACK.cmake",
    "content": "# - Find LAPACK library\n# This module finds an installed fortran library that implements the LAPACK\n# linear-algebra interface (see http://www.netlib.org/lapack/).\n#\n# The approach follows that taken for the autoconf macro file, acx_lapack.m4\n# (distributed at http://ac-archive.sourceforge.net/ac-archive/acx_lapack.html).\n#\n# This module sets the following variables:\n#  LAPACK_FOUND - set to true if a library implementing the LAPACK interface is found\n#  LAPACK_LIBRARIES - list of libraries (using full path name) for LAPACK\n\n# Note: I do not think it is a good idea to mixup different BLAS/LAPACK versions\n# Hence, this script wants to find a Lapack library matching your Blas library\n\n# Do nothing if LAPACK was found before\nIF(NOT LAPACK_FOUND)\n\nSET(LAPACK_LIBRARIES)\nSET(LAPACK_INFO)\n\nIF(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)\n  FIND_PACKAGE(BLAS)\nELSE(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)\n  FIND_PACKAGE(BLAS REQUIRED)\nENDIF(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)\n\n# Old search lapack script\ninclude(CheckFortranFunctionExists)\n\nmacro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas)\n  # This macro checks for the existence of the combination of fortran libraries\n  # given by _list.  If the combination is found, this macro checks (using the\n  # Check_Fortran_Function_Exists macro) whether can link against that library\n  # combination using the name of a routine given by _name using the linker\n  # flags given by _flags.  If the combination of libraries is found and passes\n  # the link test, LIBRARIES is set to the list of complete library paths that\n  # have been found.  Otherwise, LIBRARIES is set to FALSE.\n  # N.B. _prefix is the prefix applied to the names of all cached variables that\n  # are generated internally and marked advanced by this macro.\n  set(_libraries_work TRUE)\n  set(${LIBRARIES})\n  set(_combined_name)\n  foreach(_library ${_list})\n    set(_combined_name ${_combined_name}_${_library})\n    if(_libraries_work)\n      if (WIN32)\n        find_library(${_prefix}_${_library}_LIBRARY\n          NAMES ${_library} PATHS ENV LIB PATHS ENV PATH)\n      else (WIN32)\n        if(APPLE)\n          find_library(${_prefix}_${_library}_LIBRARY\n            NAMES ${_library}\n            PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64\n            ENV DYLD_LIBRARY_PATH)\n        else(APPLE)\n          find_library(${_prefix}_${_library}_LIBRARY\n            NAMES ${_library}\n            PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64\n            ENV LD_LIBRARY_PATH)\n        endif(APPLE)\n      endif(WIN32)\n      mark_as_advanced(${_prefix}_${_library}_LIBRARY)\n      set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})\n      set(_libraries_work ${${_prefix}_${_library}_LIBRARY})\n    endif(_libraries_work)\n  endforeach(_library ${_list})\n  if(_libraries_work)\n    # Test this combination of libraries.\n    set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas})\n    if (CMAKE_Fortran_COMPILER_WORKS)\n      check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)\n    else (CMAKE_Fortran_COMPILER_WORKS)\n      check_function_exists(\"${_name}_\" ${_prefix}${_combined_name}_WORKS)\n    endif (CMAKE_Fortran_COMPILER_WORKS)\n    set(CMAKE_REQUIRED_LIBRARIES)\n    mark_as_advanced(${_prefix}${_combined_name}_WORKS)\n    set(_libraries_work ${${_prefix}${_combined_name}_WORKS})\n  endif(_libraries_work)\n  if(NOT _libraries_work)\n    set(${LIBRARIES} FALSE)\n  endif(NOT _libraries_work)\nendmacro(Check_Lapack_Libraries)\n\n\nif(BLAS_FOUND)\n\n  # Intel MKL\n  IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL \"mkl\"))\n    IF(MKL_LAPACK_LIBRARIES)\n      SET(LAPACK_LIBRARIES ${MKL_LAPACK_LIBRARIES} ${MKL_LIBRARIES})\n    ELSE(MKL_LAPACK_LIBRARIES)\n      SET(LAPACK_LIBRARIES ${MKL_LIBRARIES})\n    ENDIF(MKL_LAPACK_LIBRARIES)\n    SET(LAPACK_INCLUDE_DIR ${MKL_INCLUDE_DIR})\n    SET(LAPACK_INFO \"mkl\")\n  ENDIF()\n\n  # OpenBlas\n  IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL \"open\"))\n    SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})\n    check_function_exists(\"cheev_\" OPEN_LAPACK_WORKS)\n    if(OPEN_LAPACK_WORKS)\n      SET(LAPACK_INFO \"open\")\n    else()\n      message(STATUS \"It seems OpenBlas has not been compiled with Lapack support\")\n    endif()\n  endif()\n\n  # GotoBlas\n  IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL \"goto\"))\n    SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})\n    check_function_exists(\"cheev_\" GOTO_LAPACK_WORKS)\n    if(GOTO_LAPACK_WORKS)\n      SET(LAPACK_INFO \"goto\")\n    else()\n      message(STATUS \"It seems GotoBlas has not been compiled with Lapack support\")\n    endif()\n  endif()\n\n  # ACML\n  IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL \"acml\"))\n    SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})\n    check_function_exists(\"cheev_\" ACML_LAPACK_WORKS)\n    if(ACML_LAPACK_WORKS)\n      SET(LAPACK_INFO \"acml\")\n    else()\n      message(STATUS \"Strangely, this ACML library does not support Lapack?!\")\n    endif()\n  endif()\n\n  # Accelerate\n  IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL \"accelerate\"))\n    SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})\n    check_function_exists(\"cheev_\" ACCELERATE_LAPACK_WORKS)\n    if(ACCELERATE_LAPACK_WORKS)\n      SET(LAPACK_INFO \"accelerate\")\n    else()\n      message(STATUS \"Strangely, this Accelerate library does not support Lapack?!\")\n    endif()\n  endif()\n\n  # vecLib\n  IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL \"veclib\"))\n    SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})\n    check_function_exists(\"cheev_\" VECLIB_LAPACK_WORKS)\n    if(VECLIB_LAPACK_WORKS)\n      SET(LAPACK_INFO \"veclib\")\n    else()\n      message(STATUS \"Strangely, this vecLib library does not support Lapack?!\")\n    endif()\n  endif()\n\n  # Generic LAPACK library?\n  IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL \"generic\"))\n    check_lapack_libraries(\n      LAPACK_LIBRARIES\n      LAPACK\n      cheev\n      \"\"\n      \"lapack\"\n      \"${BLAS_LIBRARIES}\"\n      )\n    if(LAPACK_LIBRARIES)\n      SET(LAPACK_INFO \"generic\")\n    endif(LAPACK_LIBRARIES)\n  endif()\n\nelse(BLAS_FOUND)\n  message(STATUS \"LAPACK requires BLAS\")\nendif(BLAS_FOUND)\n\nif(LAPACK_INFO)\n  set(LAPACK_FOUND TRUE)\nelse(LAPACK_INFO)\n  set(LAPACK_FOUND FALSE)\nendif(LAPACK_INFO)\n\nIF (NOT LAPACK_FOUND AND LAPACK_FIND_REQUIRED)\n  message(FATAL_ERROR \"Cannot find a library with LAPACK API. Please specify library location.\")\nENDIF (NOT LAPACK_FOUND AND LAPACK_FIND_REQUIRED)\nIF(NOT LAPACK_FIND_QUIETLY)\n  IF(LAPACK_FOUND)\n    MESSAGE(STATUS \"Found a library with LAPACK API. (${LAPACK_INFO})\")\n  ELSE(LAPACK_FOUND)\n    MESSAGE(STATUS \"Cannot find a library with LAPACK API. Not using LAPACK.\")\n  ENDIF(LAPACK_FOUND)\nENDIF(NOT LAPACK_FIND_QUIETLY)\n\n# Do nothing if LAPACK was found before\nENDIF(NOT LAPACK_FOUND)\n"
  },
  {
    "path": "cmake/Modules/FindLMDB.cmake",
    "content": "# Try to find the LMBD libraries and headers\n#  LMDB_FOUND - system has LMDB lib\n#  LMDB_INCLUDE_DIR - the LMDB include directory\n#  LMDB_LIBRARIES - Libraries needed to use LMDB\n\n# FindCWD based on FindGMP by:\n# Copyright (c) 2006, Laurent Montel, <montel@kde.org>\n#\n# Redistribution and use is allowed according to the terms of the BSD license.\n\n# Adapted from FindCWD by:\n# Copyright 2013 Conrad Steenberg <conrad.steenberg@gmail.com>\n# Aug 31, 2013\n\nfind_path(LMDB_INCLUDE_DIR NAMES  lmdb.h PATHS \"$ENV{LMDB_DIR}/include\")\nfind_library(LMDB_LIBRARIES NAMES lmdb   PATHS \"$ENV{LMDB_DIR}/lib\" )\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(LMDB DEFAULT_MSG LMDB_INCLUDE_DIR LMDB_LIBRARIES)\n\nif(LMDB_FOUND)\n  message(STATUS \"Found lmdb    (include: ${LMDB_INCLUDE_DIR}, library: ${LMDB_LIBRARIES})\")\n  mark_as_advanced(LMDB_INCLUDE_DIR LMDB_LIBRARIES)\n\n  caffe_parse_header(${LMDB_INCLUDE_DIR}/lmdb.h\n                     LMDB_VERSION_LINES MDB_VERSION_MAJOR MDB_VERSION_MINOR MDB_VERSION_PATCH)\n  set(LMDB_VERSION \"${MDB_VERSION_MAJOR}.${MDB_VERSION_MINOR}.${MDB_VERSION_PATCH}\")\nendif()\n"
  },
  {
    "path": "cmake/Modules/FindLevelDB.cmake",
    "content": "# - Find LevelDB\n#\n#  LevelDB_INCLUDES  - List of LevelDB includes\n#  LevelDB_LIBRARIES - List of libraries when using LevelDB.\n#  LevelDB_FOUND     - True if LevelDB found.\n\n# Look for the header file.\nfind_path(LevelDB_INCLUDE NAMES leveldb/db.h\n                          PATHS $ENV{LEVELDB_ROOT}/include /opt/local/include /usr/local/include /usr/include\n                          DOC \"Path in which the file leveldb/db.h is located.\" )\n\n# Look for the library.\nfind_library(LevelDB_LIBRARY NAMES leveldb\n                             PATHS /usr/lib $ENV{LEVELDB_ROOT}/lib\n                             DOC \"Path to leveldb library.\" )\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(LevelDB DEFAULT_MSG LevelDB_INCLUDE LevelDB_LIBRARY)\n\nif(LEVELDB_FOUND)\n  message(STATUS \"Found LevelDB (include: ${LevelDB_INCLUDE}, library: ${LevelDB_LIBRARY})\")\n  set(LevelDB_INCLUDES ${LevelDB_INCLUDE})\n  set(LevelDB_LIBRARIES ${LevelDB_LIBRARY})\n  mark_as_advanced(LevelDB_INCLUDE LevelDB_LIBRARY)\n\n  if(EXISTS \"${LevelDB_INCLUDE}/leveldb/db.h\")\n    file(STRINGS \"${LevelDB_INCLUDE}/leveldb/db.h\" __version_lines\n           REGEX \"static const int k[^V]+Version[ \\t]+=[ \\t]+[0-9]+;\")\n\n    foreach(__line ${__version_lines})\n      if(__line MATCHES \"[^k]+kMajorVersion[ \\t]+=[ \\t]+([0-9]+);\")\n        set(LEVELDB_VERSION_MAJOR ${CMAKE_MATCH_1})\n      elseif(__line MATCHES \"[^k]+kMinorVersion[ \\t]+=[ \\t]+([0-9]+);\")\n        set(LEVELDB_VERSION_MINOR ${CMAKE_MATCH_1})\n      endif()\n    endforeach()\n\n    if(LEVELDB_VERSION_MAJOR AND LEVELDB_VERSION_MINOR)\n      set(LEVELDB_VERSION \"${LEVELDB_VERSION_MAJOR}.${LEVELDB_VERSION_MINOR}\")\n    endif()\n\n    caffe_clear_vars(__line __version_lines)\n  endif()\nendif()\n"
  },
  {
    "path": "cmake/Modules/FindMKL.cmake",
    "content": "# Find the MKL libraries\n#\n# Options:\n#\n#   MKL_USE_SINGLE_DYNAMIC_LIBRARY  : use single dynamic library interface\n#   MKL_USE_STATIC_LIBS             : use static libraries\n#   MKL_MULTI_THREADED              : use multi-threading\n#\n# This module defines the following variables:\n#\n#   MKL_FOUND            : True mkl is found\n#   MKL_INCLUDE_DIR      : unclude directory\n#   MKL_LIBRARIES        : the libraries to link against.\n\n\n# ---[ Options\ncaffe_option(MKL_USE_SINGLE_DYNAMIC_LIBRARY \"Use single dynamic library interface\" ON)\ncaffe_option(MKL_USE_STATIC_LIBS \"Use static libraries\" OFF IF NOT MKL_USE_SINGLE_DYNAMIC_LIBRARY)\ncaffe_option(MKL_MULTI_THREADED  \"Use multi-threading\"   ON IF NOT MKL_USE_SINGLE_DYNAMIC_LIBRARY)\n\n# ---[ Root folders\nset(INTEL_ROOT \"/opt/intel\" CACHE PATH \"Folder contains intel libs\")\nfind_path(MKL_ROOT include/mkl.h PATHS $ENV{MKL_ROOT} ${INTEL_ROOT}/mkl\n                                   DOC \"Folder contains MKL\")\n\n# ---[ Find include dir\nfind_path(MKL_INCLUDE_DIR mkl.h PATHS ${MKL_ROOT} PATH_SUFFIXES include)\nset(__looked_for MKL_INCLUDE_DIR)\n\n# ---[ Find libraries\nif(CMAKE_SIZEOF_VOID_P EQUAL 4)\n  set(__path_suffixes lib lib/ia32)\nelse()\n  set(__path_suffixes lib lib/intel64)\nendif()\n\nset(__mkl_libs \"\")\nif(MKL_USE_SINGLE_DYNAMIC_LIBRARY)\n  list(APPEND __mkl_libs rt)\nelse()\n  if(CMAKE_SIZEOF_VOID_P EQUAL 4)\n    if(WIN32)\n      list(APPEND __mkl_libs intel_c)\n    else()\n      list(APPEND __mkl_libs intel gf)\n    endif()\n  else()\n    list(APPEND __mkl_libs intel_lp64 gf_lp64)\n  endif()\n\n  if(MKL_MULTI_THREADED)\n    list(APPEND __mkl_libs intel_thread)\n  else()\n     list(APPEND __mkl_libs sequential)\n  endif()\n\n  list(APPEND __mkl_libs core cdft_core)\nendif()\n\n\nforeach (__lib ${__mkl_libs})\n  set(__mkl_lib \"mkl_${__lib}\")\n  string(TOUPPER ${__mkl_lib} __mkl_lib_upper)\n\n  if(MKL_USE_STATIC_LIBS)\n    set(__mkl_lib \"lib${__mkl_lib}.a\")\n  endif()\n\n  find_library(${__mkl_lib_upper}_LIBRARY\n        NAMES ${__mkl_lib}\n        PATHS ${MKL_ROOT} \"${MKL_INCLUDE_DIR}/..\"\n        PATH_SUFFIXES ${__path_suffixes}\n        DOC \"The path to Intel(R) MKL ${__mkl_lib} library\")\n  mark_as_advanced(${__mkl_lib_upper}_LIBRARY)\n\n  list(APPEND __looked_for ${__mkl_lib_upper}_LIBRARY)\n  list(APPEND MKL_LIBRARIES ${${__mkl_lib_upper}_LIBRARY})\nendforeach()\n\n\nif(NOT MKL_USE_SINGLE_DYNAMIC_LIBRARY)\n  if (MKL_USE_STATIC_LIBS)\n    set(__iomp5_libs iomp5 libiomp5mt.lib)\n  else()\n    set(__iomp5_libs iomp5 libiomp5md.lib)\n  endif()\n\n  if(WIN32)\n    find_path(INTEL_INCLUDE_DIR omp.h PATHS ${INTEL_ROOT} PATH_SUFFIXES include)\n    list(APPEND __looked_for INTEL_INCLUDE_DIR)\n  endif()\n\n  find_library(MKL_RTL_LIBRARY ${__iomp5_libs}\n     PATHS ${INTEL_RTL_ROOT} ${INTEL_ROOT}/compiler ${MKL_ROOT}/.. ${MKL_ROOT}/../compiler\n     PATH_SUFFIXES ${__path_suffixes}\n     DOC \"Path to Path to OpenMP runtime library\")\n\n  list(APPEND __looked_for MKL_RTL_LIBRARY)\n  list(APPEND MKL_LIBRARIES ${MKL_RTL_LIBRARY})\nendif()\n\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(MKL DEFAULT_MSG ${__looked_for})\n\nif(MKL_FOUND)\n  message(STATUS \"Found MKL (include: ${MKL_INCLUDE_DIR}, lib: ${MKL_LIBRARIES}\")\nendif()\n\ncaffe_clear_vars(__looked_for __mkl_libs __path_suffixes __lib_suffix __iomp5_libs)\n"
  },
  {
    "path": "cmake/Modules/FindMatlabMex.cmake",
    "content": "# This module looks for MatlabMex compiler\n# Defines variables:\n#    Matlab_DIR    - Matlab root dir\n#    Matlab_mex    - path to mex compiler\n#    Matlab_mexext - path to mexext\n\nif(MSVC)\n  foreach(__ver \"9.30\" \"7.14\" \"7.11\" \"7.10\" \"7.9\" \"7.8\" \"7.7\")\n    get_filename_component(__matlab_root \"[HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\MathWorks\\\\MATLAB\\\\${__ver};MATLABROOT]\" ABSOLUTE)\n    if(__matlab_root)\n      break()\n    endif()\n  endforeach()\nendif()\n\nif(APPLE)\n  foreach(__ver \"R2014b\" \"R2014a\" \"R2013b\" \"R2013a\" \"R2012b\" \"R2012a\" \"R2011b\" \"R2011a\" \"R2010b\" \"R2010a\")\n    if(EXISTS /Applications/MATLAB_${__ver}.app)\n      set(__matlab_root /Applications/MATLAB_${__ver}.app)\n      break()\n    endif()\n  endforeach()\nendif()\n\nif(UNIX)\n   execute_process(COMMAND which matlab OUTPUT_STRIP_TRAILING_WHITESPACE\n                   OUTPUT_VARIABLE __out RESULT_VARIABLE __res)\n\n   if(__res MATCHES 0) # Suppress `readlink` warning if `which` returned nothing\n     execute_process(COMMAND which matlab  COMMAND xargs readlink\n                     COMMAND xargs dirname COMMAND xargs dirname COMMAND xargs echo -n\n                     OUTPUT_VARIABLE __matlab_root OUTPUT_STRIP_TRAILING_WHITESPACE)\n   endif()\nendif()\n\n\nfind_path(Matlab_DIR NAMES bin/mex bin/mexext PATHS ${__matlab_root}\n                     DOC \"Matlab directory\" NO_DEFAULT_PATH)\n\nfind_program(Matlab_mex    NAMES mex    mex.bat    HINTS ${Matlab_DIR} PATH_SUFFIXES bin NO_DEFAULT_PATH)\nfind_program(Matlab_mexext NAMES mexext mexext.bat HINTS ${Matlab_DIR} PATH_SUFFIXES bin NO_DEFAULT_PATH)\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(MatlabMex DEFAULT_MSG Matlab_mex Matlab_mexext)\n\nif(MATLABMEX_FOUND)\n  mark_as_advanced(Matlab_mex Matlab_mexext)\nendif()\n"
  },
  {
    "path": "cmake/Modules/FindNumPy.cmake",
    "content": "# - Find the NumPy libraries\n# This module finds if NumPy is installed, and sets the following variables\n# indicating where it is.\n#\n# TODO: Update to provide the libraries and paths for linking npymath lib.\n#\n#  NUMPY_FOUND               - was NumPy found\n#  NUMPY_VERSION             - the version of NumPy found as a string\n#  NUMPY_VERSION_MAJOR       - the major version number of NumPy\n#  NUMPY_VERSION_MINOR       - the minor version number of NumPy\n#  NUMPY_VERSION_PATCH       - the patch version number of NumPy\n#  NUMPY_VERSION_DECIMAL     - e.g. version 1.6.1 is 10601\n#  NUMPY_INCLUDE_DIR         - path to the NumPy include files\n\nunset(NUMPY_VERSION)\nunset(NUMPY_INCLUDE_DIR)\n\nif(PYTHONINTERP_FOUND)\n  execute_process(COMMAND \"${PYTHON_EXECUTABLE}\" \"-c\"\n    \"import numpy as n; print(n.__version__); print(n.get_include());\"\n    RESULT_VARIABLE __result\n    OUTPUT_VARIABLE __output\n    OUTPUT_STRIP_TRAILING_WHITESPACE)\n\n  if(__result MATCHES 0)\n    string(REGEX REPLACE \";\" \"\\\\\\\\;\" __values ${__output})\n    string(REGEX REPLACE \"\\r?\\n\" \";\"    __values ${__values})\n    list(GET __values 0 NUMPY_VERSION)\n    list(GET __values 1 NUMPY_INCLUDE_DIR)\n\n    string(REGEX MATCH \"^([0-9])+\\\\.([0-9])+\\\\.([0-9])+\" __ver_check \"${NUMPY_VERSION}\")\n    if(NOT \"${__ver_check}\" STREQUAL \"\")\n      set(NUMPY_VERSION_MAJOR ${CMAKE_MATCH_1})\n      set(NUMPY_VERSION_MINOR ${CMAKE_MATCH_2})\n      set(NUMPY_VERSION_PATCH ${CMAKE_MATCH_3})\n      math(EXPR NUMPY_VERSION_DECIMAL\n        \"(${NUMPY_VERSION_MAJOR} * 10000) + (${NUMPY_VERSION_MINOR} * 100) + ${NUMPY_VERSION_PATCH}\")\n      string(REGEX REPLACE \"\\\\\\\\\" \"/\"  NUMPY_INCLUDE_DIR ${NUMPY_INCLUDE_DIR})\n    else()\n     unset(NUMPY_VERSION)\n     unset(NUMPY_INCLUDE_DIR)\n     message(STATUS \"Requested NumPy version and include path, but got instead:\\n${__output}\\n\")\n    endif()\n  endif()\nelse()\n  message(STATUS \"To find NumPy Python interpretator is required to be found.\")\nendif()\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(NumPy REQUIRED_VARS NUMPY_INCLUDE_DIR NUMPY_VERSION\n                                        VERSION_VAR   NUMPY_VERSION)\n\nif(NUMPY_FOUND)\n  message(STATUS \"NumPy ver. ${NUMPY_VERSION} found (include: ${NUMPY_INCLUDE_DIR})\")\nendif()\n\ncaffe_clear_vars(__result __output __error_value __values __ver_check __error_value)\n\n"
  },
  {
    "path": "cmake/Modules/FindOpenBLAS.cmake",
    "content": "\n\nSET(Open_BLAS_INCLUDE_SEARCH_PATHS\n  /usr/include\n  /usr/include/openblas-base\n  /usr/local/include\n  /usr/local/include/openblas-base\n  /opt/OpenBLAS/include\n  $ENV{OpenBLAS_HOME}\n  $ENV{OpenBLAS_HOME}/include\n)\n\nSET(Open_BLAS_LIB_SEARCH_PATHS\n        /lib/\n        /lib/openblas-base\n        /lib64/\n        /usr/lib\n        /usr/lib/openblas-base\n        /usr/lib64\n        /usr/local/lib\n        /usr/local/lib64\n        /opt/OpenBLAS/lib\n        $ENV{OpenBLAS}cd\n        $ENV{OpenBLAS}/lib\n        $ENV{OpenBLAS_HOME}\n        $ENV{OpenBLAS_HOME}/lib\n )\n\nFIND_PATH(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS})\nFIND_LIBRARY(OpenBLAS_LIB NAMES openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS})\n\nSET(OpenBLAS_FOUND ON)\n\n#    Check include files\nIF(NOT OpenBLAS_INCLUDE_DIR)\n    SET(OpenBLAS_FOUND OFF)\n    MESSAGE(STATUS \"Could not find OpenBLAS include. Turning OpenBLAS_FOUND off\")\nENDIF()\n\n#    Check libraries\nIF(NOT OpenBLAS_LIB)\n    SET(OpenBLAS_FOUND OFF)\n    MESSAGE(STATUS \"Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off\")\nENDIF()\n\nIF (OpenBLAS_FOUND)\n  IF (NOT OpenBLAS_FIND_QUIETLY)\n    MESSAGE(STATUS \"Found OpenBLAS libraries: ${OpenBLAS_LIB}\")\n    MESSAGE(STATUS \"Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}\")\n  ENDIF (NOT OpenBLAS_FIND_QUIETLY)\nELSE (OpenBLAS_FOUND)\n  IF (OpenBLAS_FIND_REQUIRED)\n    MESSAGE(FATAL_ERROR \"Could not find OpenBLAS\")\n  ENDIF (OpenBLAS_FIND_REQUIRED)\nENDIF (OpenBLAS_FOUND)\n\nMARK_AS_ADVANCED(\n    OpenBLAS_INCLUDE_DIR\n    OpenBLAS_LIB\n    OpenBLAS\n)\n\n"
  },
  {
    "path": "cmake/Modules/FindSnappy.cmake",
    "content": "# Find the Snappy libraries\n#\n# The following variables are optionally searched for defaults\n#  Snappy_ROOT_DIR:    Base directory where all Snappy components are found\n#\n# The following are set after configuration is done:\n#  SNAPPY_FOUND\n#  Snappy_INCLUDE_DIR\n#  Snappy_LIBRARIES\n\nfind_path(Snappy_INCLUDE_DIR NAMES snappy.h\n                             PATHS ${SNAPPY_ROOT_DIR} ${SNAPPY_ROOT_DIR}/include)\n\nfind_library(Snappy_LIBRARIES NAMES snappy\n                              PATHS ${SNAPPY_ROOT_DIR} ${SNAPPY_ROOT_DIR}/lib)\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(Snappy DEFAULT_MSG Snappy_INCLUDE_DIR Snappy_LIBRARIES)\n\nif(SNAPPY_FOUND)\n  message(STATUS \"Found Snappy  (include: ${Snappy_INCLUDE_DIR}, library: ${Snappy_LIBRARIES})\")\n  mark_as_advanced(Snappy_INCLUDE_DIR Snappy_LIBRARIES)\n\n  caffe_parse_header(${Snappy_INCLUDE_DIR}/snappy-stubs-public.h\n                     SNAPPY_VERION_LINES SNAPPY_MAJOR SNAPPY_MINOR SNAPPY_PATCHLEVEL)\n  set(Snappy_VERSION \"${SNAPPY_MAJOR}.${SNAPPY_MINOR}.${SNAPPY_PATCHLEVEL}\")\nendif()\n\n"
  },
  {
    "path": "cmake/Modules/FindvecLib.cmake",
    "content": "# Find the vecLib libraries as part of Accelerate.framework or as standalon framework\n#\n# The following are set after configuration is done:\n#  VECLIB_FOUND\n#  vecLib_INCLUDE_DIR\n#  vecLib_LINKER_LIBS\n\n\nif(NOT APPLE)\n  return()\nendif()\n\nset(__veclib_include_suffix \"Frameworks/vecLib.framework/Versions/Current/Headers\")\n\nfind_path(vecLib_INCLUDE_DIR vecLib.h\n          DOC \"vecLib include directory\"\n          PATHS /System/Library/${__veclib_include_suffix}\n                /System/Library/Frameworks/Accelerate.framework/Versions/Current/${__veclib_include_suffix}\n                /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Headers/)\n\ninclude(FindPackageHandleStandardArgs)\nfind_package_handle_standard_args(vecLib DEFAULT_MSG vecLib_INCLUDE_DIR)\n\nif(VECLIB_FOUND)\n  if(vecLib_INCLUDE_DIR MATCHES \"^/System/Library/Frameworks/vecLib.framework.*\")\n    set(vecLib_LINKER_LIBS -lcblas \"-framework vecLib\")\n    message(STATUS \"Found standalone vecLib.framework\")\n  else()\n    set(vecLib_LINKER_LIBS -lcblas \"-framework Accelerate\")\n    message(STATUS \"Found vecLib as part of Accelerate.framework\")\n  endif()\n\n  mark_as_advanced(vecLib_INCLUDE_DIR)\nendif()\n"
  },
  {
    "path": "cmake/ProtoBuf.cmake",
    "content": "# Finds Google Protocol Buffers library and compilers and extends\n# the standard cmake script with version and python generation support\n\nfind_package( Protobuf REQUIRED )\ninclude_directories(SYSTEM ${PROTOBUF_INCLUDE_DIR})\nlist(APPEND Caffe_LINKER_LIBS ${PROTOBUF_LIBRARIES})\n\n# As of Ubuntu 14.04 protoc is no longer a part of libprotobuf-dev package\n# and should be installed separately as in: sudo apt-get install protobuf-compiler\nif(EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})\n  message(STATUS \"Found PROTOBUF Compiler: ${PROTOBUF_PROTOC_EXECUTABLE}\")\nelse()\n  message(FATAL_ERROR \"Could not find PROTOBUF Compiler\")\nendif()\n\nif(PROTOBUF_FOUND)\n  # fetches protobuf version\n  caffe_parse_header(${PROTOBUF_INCLUDE_DIR}/google/protobuf/stubs/common.h VERION_LINE GOOGLE_PROTOBUF_VERSION)\n  string(REGEX MATCH \"([0-9])00([0-9])00([0-9])\" PROTOBUF_VERSION ${GOOGLE_PROTOBUF_VERSION})\n  set(PROTOBUF_VERSION \"${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}\")\n  unset(GOOGLE_PROTOBUF_VERSION)\nendif()\n\n# place where to generate protobuf sources\nset(proto_gen_folder \"${PROJECT_BINARY_DIR}/include/caffe/proto\")\ninclude_directories(SYSTEM \"${PROJECT_BINARY_DIR}/include\")\n\nset(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE)\n\n################################################################################################\n# Modification of standard 'protobuf_generate_cpp()' with output dir parameter and python support\n# Usage:\n#   caffe_protobuf_generate_cpp_py(<output_dir> <srcs_var> <hdrs_var> <python_var> <proto_files>)\nfunction(caffe_protobuf_generate_cpp_py output_dir srcs_var hdrs_var python_var)\n  if(NOT ARGN)\n    message(SEND_ERROR \"Error: caffe_protobuf_generate_cpp_py() called without any proto files\")\n    return()\n  endif()\n\n  if(PROTOBUF_GENERATE_CPP_APPEND_PATH)\n    # Create an include path for each file specified\n    foreach(fil ${ARGN})\n      get_filename_component(abs_fil ${fil} ABSOLUTE)\n      get_filename_component(abs_path ${abs_fil} PATH)\n      list(FIND _protoc_include ${abs_path} _contains_already)\n      if(${_contains_already} EQUAL -1)\n        list(APPEND _protoc_include -I ${abs_path})\n      endif()\n    endforeach()\n  else()\n    set(_protoc_include -I ${CMAKE_CURRENT_SOURCE_DIR})\n  endif()\n\n  if(DEFINED PROTOBUF_IMPORT_DIRS)\n    foreach(dir ${PROTOBUF_IMPORT_DIRS})\n      get_filename_component(abs_path ${dir} ABSOLUTE)\n      list(FIND _protoc_include ${abs_path} _contains_already)\n      if(${_contains_already} EQUAL -1)\n        list(APPEND _protoc_include -I ${abs_path})\n      endif()\n    endforeach()\n  endif()\n\n  set(${srcs_var})\n  set(${hdrs_var})\n  set(${python_var})\n  foreach(fil ${ARGN})\n    get_filename_component(abs_fil ${fil} ABSOLUTE)\n    get_filename_component(fil_we ${fil} NAME_WE)\n\n    list(APPEND ${srcs_var} \"${output_dir}/${fil_we}.pb.cc\")\n    list(APPEND ${hdrs_var} \"${output_dir}/${fil_we}.pb.h\")\n    list(APPEND ${python_var} \"${output_dir}/${fil_we}_pb2.py\")\n\n    add_custom_command(\n      OUTPUT \"${output_dir}/${fil_we}.pb.cc\"\n             \"${output_dir}/${fil_we}.pb.h\"\n             \"${output_dir}/${fil_we}_pb2.py\"\n      COMMAND ${CMAKE_COMMAND} -E make_directory \"${output_dir}\"\n      COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out    ${output_dir} ${_protoc_include} ${abs_fil}\n      COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --python_out ${output_dir} ${_protoc_include} ${abs_fil}\n      DEPENDS ${abs_fil}\n      COMMENT \"Running C++/Python protocol buffer compiler on ${fil}\" VERBATIM )\n  endforeach()\n\n  set_source_files_properties(${${srcs_var}} ${${hdrs_var}} ${${python_var}} PROPERTIES GENERATED TRUE)\n  set(${srcs_var} ${${srcs_var}} PARENT_SCOPE)\n  set(${hdrs_var} ${${hdrs_var}} PARENT_SCOPE)\n  set(${python_var} ${${python_var}} PARENT_SCOPE)\nendfunction()\n"
  },
  {
    "path": "cmake/Summary.cmake",
    "content": "################################################################################################\n# Caffe status report function.\n# Automatically align right column and selects text based on condition.\n# Usage:\n#   caffe_status(<text>)\n#   caffe_status(<heading> <value1> [<value2> ...])\n#   caffe_status(<heading> <condition> THEN <text for TRUE> ELSE <text for FALSE> )\nfunction(caffe_status text)\n  set(status_cond)\n  set(status_then)\n  set(status_else)\n\n  set(status_current_name \"cond\")\n  foreach(arg ${ARGN})\n    if(arg STREQUAL \"THEN\")\n      set(status_current_name \"then\")\n    elseif(arg STREQUAL \"ELSE\")\n      set(status_current_name \"else\")\n    else()\n      list(APPEND status_${status_current_name} ${arg})\n    endif()\n  endforeach()\n\n  if(DEFINED status_cond)\n    set(status_placeholder_length 23)\n    string(RANDOM LENGTH ${status_placeholder_length} ALPHABET \" \" status_placeholder)\n    string(LENGTH \"${text}\" status_text_length)\n    if(status_text_length LESS status_placeholder_length)\n      string(SUBSTRING \"${text}${status_placeholder}\" 0 ${status_placeholder_length} status_text)\n    elseif(DEFINED status_then OR DEFINED status_else)\n      message(STATUS \"${text}\")\n      set(status_text \"${status_placeholder}\")\n    else()\n      set(status_text \"${text}\")\n    endif()\n\n    if(DEFINED status_then OR DEFINED status_else)\n      if(${status_cond})\n        string(REPLACE \";\" \" \" status_then \"${status_then}\")\n        string(REGEX REPLACE \"^[ \\t]+\" \"\" status_then \"${status_then}\")\n        message(STATUS \"${status_text} ${status_then}\")\n      else()\n        string(REPLACE \";\" \" \" status_else \"${status_else}\")\n        string(REGEX REPLACE \"^[ \\t]+\" \"\" status_else \"${status_else}\")\n        message(STATUS \"${status_text} ${status_else}\")\n      endif()\n    else()\n      string(REPLACE \";\" \" \" status_cond \"${status_cond}\")\n      string(REGEX REPLACE \"^[ \\t]+\" \"\" status_cond \"${status_cond}\")\n      message(STATUS \"${status_text} ${status_cond}\")\n    endif()\n  else()\n    message(STATUS \"${text}\")\n  endif()\nendfunction()\n\n\n################################################################################################\n# Function for fetching Caffe version from git and headers\n# Usage:\n#   caffe_extract_caffe_version()\nfunction(caffe_extract_caffe_version)\n  set(Caffe_GIT_VERSION \"unknown\")\n  find_package(Git)\n  if(GIT_FOUND)\n    execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty\n                    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE\n                    WORKING_DIRECTORY \"${PROJECT_SOURCE_DIR}\"\n                    OUTPUT_VARIABLE Caffe_GIT_VERSION\n                    RESULT_VARIABLE __git_result)\n    if(NOT ${__git_result} EQUAL 0)\n      set(Caffe_GIT_VERSION \"unknown\")\n    endif()\n  endif()\n\n  set(Caffe_GIT_VERSION ${Caffe_GIT_VERSION} PARENT_SCOPE)\n  set(Caffe_VERSION \"<TODO> (Caffe doesn't declare its version in headers)\" PARENT_SCOPE)\n\n  # caffe_parse_header(${Caffe_INCLUDE_DIR}/caffe/version.hpp Caffe_VERSION_LINES CAFFE_MAJOR CAFFE_MINOR CAFFE_PATCH)\n  # set(Caffe_VERSION \"${CAFFE_MAJOR}.${CAFFE_MINOR}.${CAFFE_PATCH}\" PARENT_SCOPE)\n\n  # or for #define Caffe_VERSION \"x.x.x\"\n  # caffe_parse_header_single_define(Caffe ${Caffe_INCLUDE_DIR}/caffe/version.hpp Caffe_VERSION)\n  # set(Caffe_VERSION ${Caffe_VERSION_STRING} PARENT_SCOPE)\n\nendfunction()\n\n\n################################################################################################\n# Prints accumulated caffe configuration summary\n# Usage:\n#   caffe_print_configuration_summary()\n\nfunction(caffe_print_configuration_summary)\n  caffe_extract_caffe_version()\n  set(Caffe_VERSION ${Caffe_VERSION} PARENT_SCOPE)\n\n  caffe_merge_flag_lists(__flags_rel CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS)\n  caffe_merge_flag_lists(__flags_deb CMAKE_CXX_FLAGS_DEBUG   CMAKE_CXX_FLAGS)\n\n  caffe_status(\"\")\n  caffe_status(\"******************* Caffe Configuration Summary *******************\")\n  caffe_status(\"General:\")\n  caffe_status(\"  Version           :   ${Caffe_VERSION}\")\n  caffe_status(\"  Git               :   ${Caffe_GIT_VERSION}\")\n  caffe_status(\"  System            :   ${CMAKE_SYSTEM_NAME}\")\n  caffe_status(\"  C++ compiler      :   ${CMAKE_CXX_COMPILER}\")\n  caffe_status(\"  Release CXX flags :   ${__flags_rel}\")\n  caffe_status(\"  Debug CXX flags   :   ${__flags_deb}\")\n  caffe_status(\"  Build type        :   ${CMAKE_BUILD_TYPE}\")\n  caffe_status(\"\")\n  caffe_status(\"  BUILD_SHARED_LIBS :   ${BUILD_SHARED_LIBS}\")\n  caffe_status(\"  BUILD_python      :   ${BUILD_python}\")\n  caffe_status(\"  BUILD_matlab      :   ${BUILD_matlab}\")\n  caffe_status(\"  BUILD_docs        :   ${BUILD_docs}\")\n  caffe_status(\"  CPU_ONLY          :   ${CPU_ONLY}\")\n  caffe_status(\"\")\n  caffe_status(\"Dependencies:\")\n  caffe_status(\"  BLAS              : \" APPLE THEN \"Yes (vecLib)\" ELSE \"Yes (${BLAS})\")\n  caffe_status(\"  Boost             :   Yes (ver. ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION})\")\n  caffe_status(\"  glog              :   Yes\")\n  caffe_status(\"  gflags            :   Yes\")\n  caffe_status(\"  protobuf          : \" PROTOBUF_FOUND THEN \"Yes (ver. ${PROTOBUF_VERSION})\" ELSE \"No\" )\n  caffe_status(\"  lmdb              : \" LMDB_FOUND THEN \"Yes (ver. ${LMDB_VERSION})\" ELSE \"No\")\n  caffe_status(\"  Snappy            : \" SNAPPY_FOUND THEN \"Yes (ver. ${Snappy_VERSION})\" ELSE \"No\" )\n  caffe_status(\"  LevelDB           : \" LEVELDB_FOUND THEN  \"Yes (ver. ${LEVELDB_VERSION})\" ELSE \"No\")\n  caffe_status(\"  OpenCV            :   Yes (ver. ${OpenCV_VERSION})\")\n  caffe_status(\"  CUDA              : \" HAVE_CUDA THEN \"Yes (ver. ${CUDA_VERSION})\" ELSE \"No\" )\n  caffe_status(\"\")\n  if(HAVE_CUDA)\n    caffe_status(\"NVIDIA CUDA:\")\n    caffe_status(\"  Target GPU(s)     :   ${CUDA_ARCH_NAME}\" )\n    caffe_status(\"  GPU arch(s)       :   ${NVCC_FLAGS_EXTRA_readable}\")\n    if(USE_CUDNN)\n      caffe_status(\"  cuDNN             : \" HAVE_CUDNN THEN \"Yes\" ELSE \"Not found\")\n    else()\n      caffe_status(\"  cuDNN             :   Disabled\")\n    endif()\n    caffe_status(\"\")\n  endif()\n  if(HAVE_PYTHON)\n    caffe_status(\"Python:\")\n    caffe_status(\"  Interpreter       :\" PYTHON_EXECUTABLE THEN \"${PYTHON_EXECUTABLE} (ver. ${PYTHON_VERSION_STRING})\" ELSE \"No\")\n    caffe_status(\"  Libraries         :\" PYTHONLIBS_FOUND  THEN \"${PYTHON_LIBRARIES} (ver ${PYTHONLIBS_VERSION_STRING})\" ELSE \"No\")\n    caffe_status(\"  NumPy             :\" NUMPY_FOUND  THEN \"${NUMPY_INCLUDE_DIR} (ver ${NUMPY_VERSION})\" ELSE \"No\")\n    caffe_status(\"\")\n  endif()\n  if(BUILD_matlab)\n    caffe_status(\"Matlab:\")\n    caffe_status(\"  Matlab            :\" HAVE_MATLAB THEN \"Yes (${Matlab_mex}, ${Matlab_mexext}\" ELSE \"No\")\n    caffe_status(\"  Octave            :\" Octave_compiler THEN  \"Yes (${Octave_compiler})\" ELSE \"No\")\n    if(HAVE_MATLAB AND Octave_compiler)\n      caffe_status(\"  Build mex using   :   ${Matlab_build_mex_using}\")\n    endif()\n    caffe_status(\"\")\n  endif()\n  if(BUILD_docs)\n    caffe_status(\"Documentaion:\")\n    caffe_status(\"  Doxygen           :\" DOXYGEN_FOUND THEN \"${DOXYGEN_EXECUTABLE} (${DOXYGEN_VERSION})\" ELSE \"No\")\n    caffe_status(\"  config_file       :   ${DOXYGEN_config_file}\")\n\n    caffe_status(\"\")\n  endif()\n  caffe_status(\"Install:\")\n  caffe_status(\"  Install path      :   ${CMAKE_INSTALL_PREFIX}\")\n  caffe_status(\"\")\nendfunction()\n\n"
  },
  {
    "path": "cmake/Targets.cmake",
    "content": "################################################################################################\n# Defines global Caffe_LINK flag, This flag is required to prevent linker from excluding\n# some objects which are not addressed directly but are registered via static constructors\nif(BUILD_SHARED_LIBS)\n  set(Caffe_LINK caffe)\nelse()\n  if(\"${CMAKE_CXX_COMPILER_ID}\" STREQUAL \"Clang\")\n    set(Caffe_LINK -Wl,-force_load caffe)\n  elseif(\"${CMAKE_CXX_COMPILER_ID}\" STREQUAL \"GNU\")\n    set(Caffe_LINK -Wl,--whole-archive caffe -Wl,--no-whole-archive)\n  endif()\nendif()\n\n################################################################################################\n# Convenient command to setup source group for IDEs that support this feature (VS, XCode)\n# Usage:\n#   caffe_source_group(<group> GLOB[_RECURSE] <globbing_expression>)\nfunction(caffe_source_group group)\n  cmake_parse_arguments(CAFFE_SOURCE_GROUP \"\" \"\" \"GLOB;GLOB_RECURSE\" ${ARGN})\n  if(CAFFE_SOURCE_GROUP_GLOB)\n    file(GLOB srcs1 ${CAFFE_SOURCE_GROUP_GLOB})\n    source_group(${group} FILES ${srcs1})\n  endif()\n\n  if(CAFFE_SOURCE_GROUP_GLOB_RECURSE)\n    file(GLOB_RECURSE srcs2 ${CAFFE_SOURCE_GROUP_GLOB_RECURSE})\n    source_group(${group} FILES ${srcs2})\n  endif()\nendfunction()\n\n################################################################################################\n# Collecting sources from globbing and appending to output list variable\n# Usage:\n#   caffe_collect_sources(<output_variable> GLOB[_RECURSE] <globbing_expression>)\nfunction(caffe_collect_sources variable)\n  cmake_parse_arguments(CAFFE_COLLECT_SOURCES \"\" \"\" \"GLOB;GLOB_RECURSE\" ${ARGN})\n  if(CAFFE_COLLECT_SOURCES_GLOB)\n    file(GLOB srcs1 ${CAFFE_COLLECT_SOURCES_GLOB})\n    set(${variable} ${variable} ${srcs1})\n  endif()\n\n  if(CAFFE_COLLECT_SOURCES_GLOB_RECURSE)\n    file(GLOB_RECURSE srcs2 ${CAFFE_COLLECT_SOURCES_GLOB_RECURSE})\n    set(${variable} ${variable} ${srcs2})\n  endif()\nendfunction()\n\n################################################################################################\n# Short command getting caffe sources (assuming standard Caffe code tree)\n# Usage:\n#   caffe_pickup_caffe_sources(<root>)\nfunction(caffe_pickup_caffe_sources root)\n  # put all files in source groups (visible as subfolder in many IDEs)\n  caffe_source_group(\"Include\"        GLOB \"${root}/include/caffe/*.h*\")\n  caffe_source_group(\"Include\\\\Util\"  GLOB \"${root}/include/caffe/util/*.h*\")\n  caffe_source_group(\"Include\"        GLOB \"${PROJECT_BINARY_DIR}/caffe_config.h*\")\n  caffe_source_group(\"Source\"         GLOB \"${root}/src/caffe/*.cpp\")\n  caffe_source_group(\"Source\\\\Util\"   GLOB \"${root}/src/caffe/util/*.cpp\")\n  caffe_source_group(\"Source\\\\Layers\" GLOB \"${root}/src/caffe/layers/*.cpp\")\n  caffe_source_group(\"Source\\\\Cuda\"   GLOB \"${root}/src/caffe/layers/*.cu\")\n  caffe_source_group(\"Source\\\\Cuda\"   GLOB \"${root}/src/caffe/util/*.cu\")\n  caffe_source_group(\"Source\\\\Proto\"  GLOB \"${root}/src/caffe/proto/*.proto\")\n\n  # source groups for test target\n  caffe_source_group(\"Include\"      GLOB \"${root}/include/caffe/test/test_*.h*\")\n  caffe_source_group(\"Source\"       GLOB \"${root}/src/caffe/test/test_*.cpp\")\n  caffe_source_group(\"Source\\\\Cuda\" GLOB \"${root}/src/caffe/test/test_*.cu\")\n\n  # collect files\n  file(GLOB test_hdrs    ${root}/include/caffe/test/test_*.h*)\n  file(GLOB test_srcs    ${root}/src/caffe/test/test_*.cpp)\n  file(GLOB_RECURSE hdrs ${root}/include/caffe/*.h*)\n  file(GLOB_RECURSE srcs ${root}/src/caffe/*.cpp)\n  list(REMOVE_ITEM  hdrs ${test_hdrs})\n  list(REMOVE_ITEM  srcs ${test_srcs})\n\n  # adding headers to make the visible in some IDEs (Qt, VS, Xcode)\n  list(APPEND srcs ${hdrs} ${PROJECT_BINARY_DIR}/caffe_config.h)\n  list(APPEND test_srcs ${test_hdrs})\n\n  # collect cuda files\n  file(GLOB    test_cuda ${root}/src/caffe/test/test_*.cu)\n  file(GLOB_RECURSE cuda ${root}/src/caffe/*.cu)\n  list(REMOVE_ITEM  cuda ${test_cuda})\n\n  # add proto to make them editable in IDEs too\n  file(GLOB_RECURSE proto_files ${root}/src/caffe/*.proto)\n  list(APPEND srcs ${proto_files})\n\n  # convet to absolute paths\n  caffe_convert_absolute_paths(srcs)\n  caffe_convert_absolute_paths(cuda)\n  caffe_convert_absolute_paths(test_srcs)\n  caffe_convert_absolute_paths(test_cuda)\n\n  # propogate to parent scope\n  set(srcs ${srcs} PARENT_SCOPE)\n  set(cuda ${cuda} PARENT_SCOPE)\n  set(test_srcs ${test_srcs} PARENT_SCOPE)\n  set(test_cuda ${test_cuda} PARENT_SCOPE)\nendfunction()\n\n################################################################################################\n# Short command for setting defeault target properties\n# Usage:\n#   caffe_default_properties(<target>)\nfunction(caffe_default_properties target)\n  set_target_properties(${target} PROPERTIES\n    DEBUG_POSTFIX ${Caffe_DEBUG_POSTFIX}\n    ARCHIVE_OUTPUT_DIRECTORY \"${PROJECT_BINARY_DIR}/lib\"\n    LIBRARY_OUTPUT_DIRECTORY \"${PROJECT_BINARY_DIR}/lib\"\n    RUNTIME_OUTPUT_DIRECTORY \"${PROJECT_BINARY_DIR}/bin\")\n  # make sure we build all external depepdencies first\n  if (DEFINED external_project_dependencies)\n    add_dependencies(${target} ${external_project_dependencies})\n  endif()\nendfunction()\n\n################################################################################################\n# Short command for setting runtime directory for build target\n# Usage:\n#   caffe_set_runtime_directory(<target> <dir>)\nfunction(caffe_set_runtime_directory target dir)\n  set_target_properties(${target} PROPERTIES\n    RUNTIME_OUTPUT_DIRECTORY \"${dir}\")\nendfunction()\n\n################################################################################################\n# Short command for setting solution folder property for target\n# Usage:\n#   caffe_set_solution_folder(<target> <folder>)\nfunction(caffe_set_solution_folder target folder)\n  if(USE_PROJECT_FOLDERS)\n    set_target_properties(${target} PROPERTIES FOLDER \"${folder}\")\n  endif()\nendfunction()\n\n################################################################################################\n# Reads lines from input file, prepends source directory to each line and writes to output file\n# Usage:\n#   caffe_configure_testdatafile(<testdatafile>)\nfunction(caffe_configure_testdatafile file)\n  file(STRINGS ${file} __lines)\n  set(result \"\")\n  foreach(line ${__lines})\n    set(result \"${result}${PROJECT_SOURCE_DIR}/${line}\\n\")\n  endforeach()\n  file(WRITE ${file}.gen.cmake ${result})\nendfunction()\n\n################################################################################################\n# Filter out all files that are not included in selected list\n# Usage:\n#   caffe_leave_only_selected_tests(<filelist_variable> <selected_list>)\nfunction(caffe_leave_only_selected_tests file_list)\n  if(NOT ARGN)\n    return() # blank list means leave all\n  endif()\n  string(REPLACE \",\" \";\" __selected ${ARGN})\n  list(APPEND __selected caffe_main)\n\n  set(result \"\")\n  foreach(f ${${file_list}})\n    get_filename_component(name ${f} NAME_WE)\n    string(REGEX REPLACE \"^test_\" \"\" name ${name})\n    list(FIND __selected ${name} __index)\n    if(NOT __index EQUAL -1)\n      list(APPEND result ${f})\n    endif()\n  endforeach()\n  set(${file_list} ${result} PARENT_SCOPE)\nendfunction()\n\n"
  },
  {
    "path": "cmake/Templates/CaffeConfig.cmake.in",
    "content": "# Config file for the Caffe package.\n#\n# Note:\n#   Caffe and this config file depends on opencv,\n#   so put `find_package(OpenCV)` before searching Caffe\n#   via `find_package(Caffe)`. All other lib/includes\n#   dependencies are hard coded in the file\n#\n# After successful configuration the following variables\n# will be defined:\n#\n#   Caffe_INCLUDE_DIRS - Caffe include directories\n#   Caffe_LIBRARIES    - libraries to link against\n#   Caffe_DEFINITIONS  - a list of definitions to pass to compiler\n#\n#   Caffe_HAVE_CUDA    - signals about CUDA support\n#   Caffe_HAVE_CUDNN   - signals about cuDNN support\n\n\n# OpenCV dependency\n\nif(NOT OpenCV_FOUND)\n  set(Caffe_OpenCV_CONFIG_PATH \"@OpenCV_CONFIG_PATH@\")\n  if(Caffe_OpenCV_CONFIG_PATH)\n    get_filename_component(Caffe_OpenCV_CONFIG_PATH ${Caffe_OpenCV_CONFIG_PATH} ABSOLUTE)\n\n    if(EXISTS ${Caffe_OpenCV_CONFIG_PATH} AND NOT TARGET opencv_core)\n      message(STATUS \"Caffe: using OpenCV config from ${Caffe_OpenCV_CONFIG_PATH}\")\n      include(${Caffe_OpenCV_CONFIG_PATH}/OpenCVModules.cmake)\n    endif()\n\n  else()\n    find_package(OpenCV REQUIRED)\n  endif()\n  unset(Caffe_OpenCV_CONFIG_PATH)\nendif()\n\n# Compute paths\nget_filename_component(Caffe_CMAKE_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\nset(Caffe_INCLUDE_DIRS \"@Caffe_INCLUDE_DIRS@\")\n\n@Caffe_INSTALL_INCLUDE_DIR_APPEND_COMMAND@\n\n# Our library dependencies\nif(NOT TARGET caffe AND NOT caffe_BINARY_DIR)\n  include(\"${Caffe_CMAKE_DIR}/CaffeTargets.cmake\")\nendif()\n\n# List of IMPORTED libs created by CaffeTargets.cmake\nset(Caffe_LIBRARIES caffe)\n\n# Definitions\nset(Caffe_DEFINITIONS \"@Caffe_DEFINITIONS@\")\n\n# Cuda support variables\nset(Caffe_CPU_ONLY @CPU_ONLY@)\nset(Caffe_HAVE_CUDA @HAVE_CUDA@)\nset(Caffe_HAVE_CUDNN @HAVE_CUDNN@)\n"
  },
  {
    "path": "cmake/Templates/CaffeConfigVersion.cmake.in",
    "content": "set(PACKAGE_VERSION \"@Caffe_VERSION@\")\n\n# Check whether the requested PACKAGE_FIND_VERSION is compatible\nif(\"${PACKAGE_VERSION}\" VERSION_LESS \"${PACKAGE_FIND_VERSION}\")\n  set(PACKAGE_VERSION_COMPATIBLE FALSE)\nelse()\n  set(PACKAGE_VERSION_COMPATIBLE TRUE)\n  if (\"${PACKAGE_VERSION}\" VERSION_EQUAL \"${PACKAGE_FIND_VERSION}\")\n    set(PACKAGE_VERSION_EXACT TRUE)\n  endif()\nendif()\n"
  },
  {
    "path": "cmake/Templates/caffe_config.h.in",
    "content": "/* Sources directory */\n#define SOURCE_FOLDER \"${PROJECT_SOURCE_DIR}\"\n\n/* Binaries directory */\n#define BINARY_FOLDER \"${PROJECT_BINARY_DIR}\"\n\n/* NVIDA Cuda */\n#cmakedefine HAVE_CUDA\n\n/* NVIDA cuDNN */\n#cmakedefine HAVE_CUDNN\n#cmakedefine USE_CUDNN\n\n/* NVIDA cuDNN */\n#cmakedefine CPU_ONLY\n\n/* Test device */\n#define CUDA_TEST_DEVICE ${CUDA_TEST_DEVICE}\n\n/* Temporary (TODO: remove) */\n#if 1\n  #define CMAKE_SOURCE_DIR SOURCE_FOLDER \"/src/\"\n  #define EXAMPLES_SOURCE_DIR BINARY_FOLDER \"/examples/\"\n  #define CMAKE_EXT \".gen.cmake\"\n#else\n  #define CMAKE_SOURCE_DIR \"src/\"\n  #define EXAMPLES_SOURCE_DIR \"examples/\"\n  #define CMAKE_EXT \"\"\n#endif\n\n/* Matlab */\n#cmakedefine HAVE_MATLAB\n"
  },
  {
    "path": "cmake/Utils.cmake",
    "content": "################################################################################################\n# Command alias for debugging messages\n# Usage:\n#   dmsg(<message>)\nfunction(dmsg)\n  message(STATUS ${ARGN})\nendfunction()\n\n################################################################################################\n# Removes duplicates from list(s)\n# Usage:\n#   caffe_list_unique(<list_variable> [<list_variable>] [...])\nmacro(caffe_list_unique)\n  foreach(__lst ${ARGN})\n    if(${__lst})\n      list(REMOVE_DUPLICATES ${__lst})\n    endif()\n  endforeach()\nendmacro()\n\n################################################################################################\n# Clears variables from list\n# Usage:\n#   caffe_clear_vars(<variables_list>)\nmacro(caffe_clear_vars)\n  foreach(_var ${ARGN})\n    unset(${_var})\n  endforeach()\nendmacro()\n\n################################################################################################\n# Removes duplicates from string\n# Usage:\n#   caffe_string_unique(<string_variable>)\nfunction(caffe_string_unique __string)\n  if(${__string})\n    set(__list ${${__string}})\n    separate_arguments(__list)\n    list(REMOVE_DUPLICATES __list)\n    foreach(__e ${__list})\n      set(__str \"${__str} ${__e}\")\n    endforeach()\n    set(${__string} ${__str} PARENT_SCOPE)\n  endif()\nendfunction()\n\n################################################################################################\n# Prints list element per line\n# Usage:\n#   caffe_print_list(<list>)\nfunction(caffe_print_list)\n  foreach(e ${ARGN})\n    message(STATUS ${e})\n  endforeach()\nendfunction()\n\n################################################################################################\n# Function merging lists of compiler flags to single string.\n# Usage:\n#   caffe_merge_flag_lists(out_variable <list1> [<list2>] [<list3>] ...)\nfunction(caffe_merge_flag_lists out_var)\n  set(__result \"\")\n  foreach(__list ${ARGN})\n    foreach(__flag ${${__list}})\n      string(STRIP ${__flag} __flag)\n      set(__result \"${__result} ${__flag}\")\n    endforeach()\n  endforeach()\n  string(STRIP ${__result} __result)\n  set(${out_var} ${__result} PARENT_SCOPE)\nendfunction()\n\n################################################################################################\n# Converts all paths in list to absolute\n# Usage:\n#   caffe_convert_absolute_paths(<list_variable>)\nfunction(caffe_convert_absolute_paths variable)\n  set(__dlist \"\")\n  foreach(__s ${${variable}})\n    get_filename_component(__abspath ${__s} ABSOLUTE)\n    list(APPEND __list ${__abspath})\n  endforeach()\n  set(${variable} ${__list} PARENT_SCOPE)\nendfunction()\n\n################################################################################################\n# Reads set of version defines from the header file\n# Usage:\n#   caffe_parse_header(<file> <define1> <define2> <define3> ..)\nmacro(caffe_parse_header FILENAME FILE_VAR)\n  set(vars_regex \"\")\n  set(__parnet_scope OFF)\n  set(__add_cache OFF)\n  foreach(name ${ARGN})\n    if(\"${name}\" STREQUAL \"PARENT_SCOPE\")\n      set(__parnet_scope ON)\n    elseif(\"${name}\" STREQUAL \"CACHE\")\n      set(__add_cache ON)\n    elseif(vars_regex)\n      set(vars_regex \"${vars_regex}|${name}\")\n    else()\n      set(vars_regex \"${name}\")\n    endif()\n  endforeach()\n  if(EXISTS \"${FILENAME}\")\n    file(STRINGS \"${FILENAME}\" ${FILE_VAR} REGEX \"#define[ \\t]+(${vars_regex})[ \\t]+[0-9]+\" )\n  else()\n    unset(${FILE_VAR})\n  endif()\n  foreach(name ${ARGN})\n    if(NOT \"${name}\" STREQUAL \"PARENT_SCOPE\" AND NOT \"${name}\" STREQUAL \"CACHE\")\n      if(${FILE_VAR})\n        if(${FILE_VAR} MATCHES \".+[ \\t]${name}[ \\t]+([0-9]+).*\")\n          string(REGEX REPLACE \".+[ \\t]${name}[ \\t]+([0-9]+).*\" \"\\\\1\" ${name} \"${${FILE_VAR}}\")\n        else()\n          set(${name} \"\")\n        endif()\n        if(__add_cache)\n          set(${name} ${${name}} CACHE INTERNAL \"${name} parsed from ${FILENAME}\" FORCE)\n        elseif(__parnet_scope)\n          set(${name} \"${${name}}\" PARENT_SCOPE)\n        endif()\n      else()\n        unset(${name} CACHE)\n      endif()\n    endif()\n  endforeach()\nendmacro()\n\n################################################################################################\n# Reads single version define from the header file and parses it\n# Usage:\n#   caffe_parse_header_single_define(<library_name> <file> <define_name>)\nfunction(caffe_parse_header_single_define LIBNAME HDR_PATH VARNAME)\n  set(${LIBNAME}_H \"\")\n  if(EXISTS \"${HDR_PATH}\")\n    file(STRINGS \"${HDR_PATH}\" ${LIBNAME}_H REGEX \"^#define[ \\t]+${VARNAME}[ \\t]+\\\"[^\\\"]*\\\".*$\" LIMIT_COUNT 1)\n  endif()\n\n  if(${LIBNAME}_H)\n    string(REGEX REPLACE \"^.*[ \\t]${VARNAME}[ \\t]+\\\"([0-9]+).*$\" \"\\\\1\" ${LIBNAME}_VERSION_MAJOR \"${${LIBNAME}_H}\")\n    string(REGEX REPLACE \"^.*[ \\t]${VARNAME}[ \\t]+\\\"[0-9]+\\\\.([0-9]+).*$\" \"\\\\1\" ${LIBNAME}_VERSION_MINOR  \"${${LIBNAME}_H}\")\n    string(REGEX REPLACE \"^.*[ \\t]${VARNAME}[ \\t]+\\\"[0-9]+\\\\.[0-9]+\\\\.([0-9]+).*$\" \"\\\\1\" ${LIBNAME}_VERSION_PATCH \"${${LIBNAME}_H}\")\n    set(${LIBNAME}_VERSION_MAJOR ${${LIBNAME}_VERSION_MAJOR} ${ARGN} PARENT_SCOPE)\n    set(${LIBNAME}_VERSION_MINOR ${${LIBNAME}_VERSION_MINOR} ${ARGN} PARENT_SCOPE)\n    set(${LIBNAME}_VERSION_PATCH ${${LIBNAME}_VERSION_PATCH} ${ARGN} PARENT_SCOPE)\n    set(${LIBNAME}_VERSION_STRING \"${${LIBNAME}_VERSION_MAJOR}.${${LIBNAME}_VERSION_MINOR}.${${LIBNAME}_VERSION_PATCH}\" PARENT_SCOPE)\n\n    # append a TWEAK version if it exists:\n    set(${LIBNAME}_VERSION_TWEAK \"\")\n    if(\"${${LIBNAME}_H}\" MATCHES \"^.*[ \\t]${VARNAME}[ \\t]+\\\"[0-9]+\\\\.[0-9]+\\\\.[0-9]+\\\\.([0-9]+).*$\")\n      set(${LIBNAME}_VERSION_TWEAK \"${CMAKE_MATCH_1}\" ${ARGN} PARENT_SCOPE)\n    endif()\n    if(${LIBNAME}_VERSION_TWEAK)\n      set(${LIBNAME}_VERSION_STRING \"${${LIBNAME}_VERSION_STRING}.${${LIBNAME}_VERSION_TWEAK}\" ${ARGN} PARENT_SCOPE)\n    else()\n      set(${LIBNAME}_VERSION_STRING \"${${LIBNAME}_VERSION_STRING}\" ${ARGN} PARENT_SCOPE)\n    endif()\n  endif()\nendfunction()\n\n########################################################################################################\n# An option that the user can select. Can accept condition to control when option is available for user.\n# Usage:\n#   caffe_option(<option_variable> \"doc string\" <initial value or boolean expression> [IF <condition>])\nfunction(caffe_option variable description value)\n  set(__value ${value})\n  set(__condition \"\")\n  set(__varname \"__value\")\n  foreach(arg ${ARGN})\n    if(arg STREQUAL \"IF\" OR arg STREQUAL \"if\")\n      set(__varname \"__condition\")\n    else()\n      list(APPEND ${__varname} ${arg})\n    endif()\n  endforeach()\n  unset(__varname)\n  if(\"${__condition}\" STREQUAL \"\")\n    set(__condition 2 GREATER 1)\n  endif()\n\n  if(${__condition})\n    if(\"${__value}\" MATCHES \";\")\n      if(${__value})\n        option(${variable} \"${description}\" ON)\n      else()\n        option(${variable} \"${description}\" OFF)\n      endif()\n    elseif(DEFINED ${__value})\n      if(${__value})\n        option(${variable} \"${description}\" ON)\n      else()\n        option(${variable} \"${description}\" OFF)\n      endif()\n    else()\n      option(${variable} \"${description}\" ${__value})\n    endif()\n  else()\n    unset(${variable} CACHE)\n  endif()\nendfunction()\n\n################################################################################################\n# Utility macro for comparing two lists. Used for CMake debugging purposes\n# Usage:\n#   caffe_compare_lists(<list_variable> <list2_variable> [description])\nfunction(caffe_compare_lists list1 list2 desc)\n  set(__list1 ${${list1}})\n  set(__list2 ${${list2}})\n  list(SORT __list1)\n  list(SORT __list2)\n  list(LENGTH __list1 __len1)\n  list(LENGTH __list2 __len2)\n\n  if(NOT ${__len1} EQUAL ${__len2})\n    message(FATAL_ERROR \"Lists are not equal. ${__len1} != ${__len2}. ${desc}\")\n  endif()\n\n  foreach(__i RANGE 1 ${__len1})\n    math(EXPR __index \"${__i}- 1\")\n    list(GET __list1 ${__index} __item1)\n    list(GET __list2 ${__index} __item2)\n    if(NOT ${__item1} STREQUAL ${__item2})\n      message(FATAL_ERROR \"Lists are not equal. Differ at element ${__index}. ${desc}\")\n    endif()\n  endforeach()\nendfunction()\n\n################################################################################################\n# Command for disabling warnings for different platforms (see below for gcc and VisualStudio)\n# Usage:\n#   caffe_warnings_disable(<CMAKE_[C|CXX]_FLAGS[_CONFIGURATION]> -Wshadow /wd4996 ..,)\nmacro(caffe_warnings_disable)\n  set(_flag_vars \"\")\n  set(_msvc_warnings \"\")\n  set(_gxx_warnings \"\")\n\n  foreach(arg ${ARGN})\n    if(arg MATCHES \"^CMAKE_\")\n      list(APPEND _flag_vars ${arg})\n    elseif(arg MATCHES \"^/wd\")\n      list(APPEND _msvc_warnings ${arg})\n    elseif(arg MATCHES \"^-W\")\n      list(APPEND _gxx_warnings ${arg})\n    endif()\n  endforeach()\n\n  if(NOT _flag_vars)\n    set(_flag_vars CMAKE_C_FLAGS CMAKE_CXX_FLAGS)\n  endif()\n\n  if(MSVC AND _msvc_warnings)\n    foreach(var ${_flag_vars})\n      foreach(warning ${_msvc_warnings})\n        set(${var} \"${${var}} ${warning}\")\n      endforeach()\n    endforeach()\n  elseif((CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) AND _gxx_warnings)\n    foreach(var ${_flag_vars})\n      foreach(warning ${_gxx_warnings})\n        if(NOT warning MATCHES \"^-Wno-\")\n          string(REPLACE \"${warning}\" \"\" ${var} \"${${var}}\")\n          string(REPLACE \"-W\" \"-Wno-\" warning \"${warning}\")\n        endif()\n        set(${var} \"${${var}} ${warning}\")\n      endforeach()\n    endforeach()\n  endif()\n  caffe_clear_vars(_flag_vars _msvc_warnings _gxx_warnings)\nendmacro()\n\n################################################################################################\n# Helper function get current definitions\n# Usage:\n#   caffe_get_current_definitions(<definitions_variable>)\nfunction(caffe_get_current_definitions definitions_var)\n  get_property(current_definitions DIRECTORY PROPERTY COMPILE_DEFINITIONS)\n  set(result \"\")\n\n  foreach(d ${current_definitions})\n    list(APPEND result -D${d})\n  endforeach()\n\n  caffe_list_unique(result)\n  set(${definitions_var} ${result} PARENT_SCOPE)\nendfunction()\n\n################################################################################################\n# Helper function get current includes/definitions\n# Usage:\n#   caffe_get_current_cflags(<cflagslist_variable>)\nfunction(caffe_get_current_cflags cflags_var)\n  get_property(current_includes DIRECTORY PROPERTY INCLUDE_DIRECTORIES)\n  caffe_convert_absolute_paths(current_includes)\n  caffe_get_current_definitions(cflags)\n\n  foreach(i ${current_includes})\n    list(APPEND cflags \"-I${i}\")\n  endforeach()\n\n  caffe_list_unique(cflags)\n  set(${cflags_var} ${cflags} PARENT_SCOPE)\nendfunction()\n\n################################################################################################\n# Helper function to parse current linker libs into link directories, libflags and osx frameworks\n# Usage:\n#   caffe_parse_linker_libs(<Caffe_LINKER_LIBS_var> <directories_var> <libflags_var> <frameworks_var>)\nfunction(caffe_parse_linker_libs Caffe_LINKER_LIBS_variable folders_var flags_var frameworks_var)\n\n  set(__unspec \"\")\n  set(__debug \"\")\n  set(__optimized \"\")\n  set(__framework \"\")\n  set(__varname \"__unspec\")\n\n  # split libs into debug, optimized, unspecified and frameworks\n  foreach(list_elem ${${Caffe_LINKER_LIBS_variable}})\n    if(list_elem STREQUAL \"debug\")\n      set(__varname \"__debug\")\n    elseif(list_elem STREQUAL \"optimized\")\n      set(__varname \"__optimized\")\n    elseif(list_elem MATCHES \"^-framework[ \\t]+([^ \\t].*)\")\n      list(APPEND __framework -framework ${CMAKE_MATCH_1})\n    else()\n      list(APPEND ${__varname} ${list_elem})\n      set(__varname \"__unspec\")\n    endif()\n  endforeach()\n\n  # attach debug or optimized libs to unspecified according to current configuration\n  if(CMAKE_BUILD_TYPE MATCHES \"Debug\")\n    set(__libs ${__unspec} ${__debug})\n  else()\n    set(__libs ${__unspec} ${__optimized})\n  endif()\n\n  set(libflags \"\")\n  set(folders \"\")\n\n  # convert linker libraries list to link flags\n  foreach(lib ${__libs})\n    if(TARGET ${lib})\n      list(APPEND folders $<TARGET_LINKER_FILE_DIR:${lib}>)\n      list(APPEND libflags -l${lib})\n    elseif(lib MATCHES \"^-l.*\")\n      list(APPEND libflags ${lib})\n    elseif(IS_ABSOLUTE ${lib})\n      get_filename_component(name_we ${lib} NAME_WE)\n      get_filename_component(folder  ${lib} PATH)\n\n      string(REGEX MATCH \"^lib(.*)\" __match ${name_we})\n      list(APPEND libflags -l${CMAKE_MATCH_1})\n      list(APPEND folders    ${folder})\n    else()\n      message(FATAL_ERROR \"Logic error. Need to update cmake script\")\n    endif()\n  endforeach()\n\n  caffe_list_unique(libflags folders)\n\n  set(${folders_var} ${folders} PARENT_SCOPE)\n  set(${flags_var} ${libflags} PARENT_SCOPE)\n  set(${frameworks_var} ${__framework} PARENT_SCOPE)\nendfunction()\n\n################################################################################################\n# Helper function to detect Darwin version, i.e. 10.8, 10.9, 10.10, ....\n# Usage:\n#   caffe_detect_darwin_version(<version_variable>)\nfunction(caffe_detect_darwin_version output_var)\n  if(APPLE)\n    execute_process(COMMAND /usr/bin/sw_vers -productVersion\n                    RESULT_VARIABLE __sw_vers OUTPUT_VARIABLE __sw_vers_out\n                    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)\n\n    set(${output_var} ${__sw_vers_out} PARENT_SCOPE)\n  else()\n    set(${output_var} \"\" PARENT_SCOPE)\n  endif()\nendfunction()\n"
  },
  {
    "path": "cmake/lint.cmake",
    "content": "\nset(CMAKE_SOURCE_DIR ..)\nset(LINT_COMMAND ${CMAKE_SOURCE_DIR}/scripts/cpp_lint.py)\nset(SRC_FILE_EXTENSIONS h hpp hu c cpp cu cc)\nset(EXCLUDE_FILE_EXTENSTIONS pb.h pb.cc)\nset(LINT_DIRS include src/caffe examples tools python matlab)\n\ncmake_policy(SET CMP0009 NEW)  # suppress cmake warning\n\n# find all files of interest\nforeach(ext ${SRC_FILE_EXTENSIONS})\n    foreach(dir ${LINT_DIRS})\n        file(GLOB_RECURSE FOUND_FILES ${CMAKE_SOURCE_DIR}/${dir}/*.${ext})\n        set(LINT_SOURCES ${LINT_SOURCES} ${FOUND_FILES})\n    endforeach()\nendforeach()\n\n# find all files that should be excluded\nforeach(ext ${EXCLUDE_FILE_EXTENSTIONS})\n    file(GLOB_RECURSE FOUND_FILES ${CMAKE_SOURCE_DIR}/*.${ext})\n    set(EXCLUDED_FILES ${EXCLUDED_FILES} ${FOUND_FILES})\nendforeach()\n\n# exclude generated pb files\nlist(REMOVE_ITEM LINT_SOURCES ${EXCLUDED_FILES})\n\nexecute_process(\n    COMMAND ${LINT_COMMAND} ${LINT_SOURCES}\n    ERROR_VARIABLE LINT_OUTPUT\n    ERROR_STRIP_TRAILING_WHITESPACE\n)\n\nstring(REPLACE \"\\n\" \";\" LINT_OUTPUT ${LINT_OUTPUT})\n\nlist(GET LINT_OUTPUT -1 LINT_RESULT)\nlist(REMOVE_AT LINT_OUTPUT -1)\nstring(REPLACE \" \" \";\" LINT_RESULT ${LINT_RESULT})\nlist(GET LINT_RESULT -1 NUM_ERRORS)\nif(NUM_ERRORS GREATER 0)\n    foreach(msg ${LINT_OUTPUT})\n        string(FIND ${msg} \"Done\" result)\n        if(result LESS 0)\n            message(STATUS ${msg})\n        endif()\n    endforeach()\n    message(FATAL_ERROR \"Lint found ${NUM_ERRORS} errors!\")\nelse()\n    message(STATUS \"Lint did not find any errors!\")\nendif()\n\n"
  },
  {
    "path": "include/caffe/blob.hpp",
    "content": "#ifndef CAFFE_BLOB_HPP_\n#define CAFFE_BLOB_HPP_\n\n#include <algorithm>\n#include <string>\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nconst int kMaxBlobAxes = 32;\n\nnamespace caffe {\n\n/**\n * @brief A wrapper around SyncedMemory holders serving as the basic\n *        computational unit through which Layer%s, Net%s, and Solver%s\n *        interact.\n *\n * TODO(dox): more thorough description.\n */\ntemplate <typename Dtype>\nclass Blob {\n public:\n  Blob()\n       : data_(), diff_(), count_(0), capacity_(0) {}\n\n  /// @brief Deprecated; use <code>Blob(const vector<int>& shape)</code>.\n  explicit Blob(const int num, const int channels, const int height,\n      const int width);\n  explicit Blob(const vector<int>& shape);\n\n  /// @brief Deprecated; use <code>Reshape(const vector<int>& shape)</code>.\n  void Reshape(const int num, const int channels, const int height,\n      const int width);\n  /**\n   * @brief Change the dimensions of the blob, allocating new memory if\n   *        necessary.\n   *\n   * This function can be called both to create an initial allocation\n   * of memory, and to adjust the dimensions of a top blob during Layer::Reshape\n   * or Layer::Forward. When changing the size of blob, memory will only be\n   * reallocated if sufficient memory does not already exist, and excess memory\n   * will never be freed.\n   *\n   * Note that reshaping an input blob and immediately calling Net::Backward is\n   * an error; either Net::Forward or Net::Reshape need to be called to\n   * propagate the new input shape to higher layers.\n   */\n  void Reshape(const vector<int>& shape);\n  void Reshape(const BlobShape& shape);\n  void ReshapeLike(const Blob& other);\n  inline string shape_string() const {\n    ostringstream stream;\n    for (int i = 0; i < shape_.size(); ++i) {\n      stream << shape_[i] << \" \";\n    }\n    stream << \"(\" << count_ << \")\";\n    return stream.str();\n  }\n  inline const vector<int>& shape() const { return shape_; }\n  /**\n   * @brief Returns the dimension of the index-th axis (or the negative index-th\n   *        axis from the end, if index is negative).\n   *\n   * @param index the axis index, which may be negative as it will be\n   *        \"canonicalized\" using CanonicalAxisIndex.\n   *        Dies on out of range index.\n   */\n  inline int shape(int index) const {\n    return shape_[CanonicalAxisIndex(index)];\n  }\n  inline int num_axes() const { return shape_.size(); }\n  inline int count() const { return count_; }\n\n  /**\n   * @brief Compute the volume of a slice; i.e., the product of dimensions\n   *        among a range of axes.\n   *\n   * @param start_axis The first axis to include in the slice.\n   *\n   * @param end_axis The first axis to exclude from the slice.\n   */\n  inline int count(int start_axis, int end_axis) const {\n    CHECK_LE(start_axis, end_axis);\n    CHECK_GE(start_axis, 0);\n    CHECK_GE(end_axis, 0);\n    CHECK_LE(start_axis, num_axes());\n    CHECK_LE(end_axis, num_axes());\n    int count = 1;\n    for (int i = start_axis; i < end_axis; ++i) {\n      count *= shape(i);\n    }\n    return count;\n  }\n  /**\n   * @brief Compute the volume of a slice spanning from a particular first\n   *        axis to the final axis.\n   *\n   * @param start_axis The first axis to include in the slice.\n   */\n  inline int count(int start_axis) const {\n    return count(start_axis, num_axes());\n  }\n\n  /**\n   * @brief Returns the 'canonical' version of a (usually) user-specified axis,\n   *        allowing for negative indexing (e.g., -1 for the last axis).\n   *\n   * @param index the axis index.\n   *        If 0 <= index < num_axes(), return index.\n   *        If -num_axes <= index <= -1, return (num_axes() - (-index)),\n   *        e.g., the last axis index (num_axes() - 1) if index == -1,\n   *        the second to last if index == -2, etc.\n   *        Dies on out of range index.\n   */\n  inline int CanonicalAxisIndex(int axis_index) const {\n    CHECK_GE(axis_index, -num_axes())\n        << \"axis \" << axis_index << \" out of range for \" << num_axes()\n        << \"-D Blob with shape \" << shape_string();\n    CHECK_LT(axis_index, num_axes())\n        << \"axis \" << axis_index << \" out of range for \" << num_axes()\n        << \"-D Blob with shape \" << shape_string();\n    if (axis_index < 0) {\n      return axis_index + num_axes();\n    }\n    return axis_index;\n  }\n\n  /// @brief Deprecated legacy shape accessor num: use shape(0) instead.\n  inline int num() const { return LegacyShape(0); }\n  /// @brief Deprecated legacy shape accessor channels: use shape(1) instead.\n  inline int channels() const { return LegacyShape(1); }\n  /// @brief Deprecated legacy shape accessor height: use shape(2) instead.\n  inline int height() const { return LegacyShape(2); }\n  /// @brief Deprecated legacy shape accessor width: use shape(3) instead.\n  inline int width() const { return LegacyShape(3); }\n  inline int LegacyShape(int index) const {\n    CHECK_LE(num_axes(), 4)\n        << \"Cannot use legacy accessors on Blobs with > 4 axes.\";\n    CHECK_LT(index, 4);\n    CHECK_GE(index, -4);\n    if (index >= num_axes() || index < -num_axes()) {\n      // Axis is out of range, but still in [0, 3] (or [-4, -1] for reverse\n      // indexing) -- this special case simulates the one-padding used to fill\n      // extraneous axes of legacy blobs.\n      return 1;\n    }\n    return shape(index);\n  }\n\n  inline int offset(const int n, const int c = 0, const int h = 0,\n      const int w = 0) const {\n    CHECK_GE(n, 0);\n    CHECK_LE(n, num());\n    CHECK_GE(channels(), 0);\n    CHECK_LE(c, channels());\n    CHECK_GE(height(), 0);\n    CHECK_LE(h, height());\n    CHECK_GE(width(), 0);\n    CHECK_LE(w, width());\n    return ((n * channels() + c) * height() + h) * width() + w;\n  }\n\n  inline int offset(const vector<int>& indices) const {\n    CHECK_LE(indices.size(), num_axes());\n    int offset = 0;\n    for (int i = 0; i < num_axes(); ++i) {\n      offset *= shape(i);\n      if (indices.size() > i) {\n        CHECK_GE(indices[i], 0);\n        CHECK_LT(indices[i], shape(i));\n        offset += indices[i];\n      }\n    }\n    return offset;\n  }\n  /**\n   * @brief Copy from a source Blob.\n   *\n   * @param source the Blob to copy from\n   * @param copy_diff if false, copy the data; if true, copy the diff\n   * @param reshape if false, require this Blob to be pre-shaped to the shape\n   *        of other (and die otherwise); if true, Reshape this Blob to other's\n   *        shape if necessary\n   */\n  void CopyFrom(const Blob<Dtype>& source, bool copy_diff = false,\n      bool reshape = false);\n\n  inline Dtype data_at(const int n, const int c, const int h,\n      const int w) const {\n    return cpu_data()[offset(n, c, h, w)];\n  }\n\n  inline Dtype diff_at(const int n, const int c, const int h,\n      const int w) const {\n    return cpu_diff()[offset(n, c, h, w)];\n  }\n\n  inline Dtype data_at(const vector<int>& index) const {\n    return cpu_data()[offset(index)];\n  }\n\n  inline Dtype diff_at(const vector<int>& index) const {\n    return cpu_diff()[offset(index)];\n  }\n\n  inline const shared_ptr<SyncedMemory>& data() const {\n    CHECK(data_);\n    return data_;\n  }\n\n  inline const shared_ptr<SyncedMemory>& diff() const {\n    CHECK(diff_);\n    return diff_;\n  }\n\n  const Dtype* cpu_data() const;\n  void set_cpu_data(Dtype* data);\n  const Dtype* gpu_data() const;\n  const Dtype* cpu_diff() const;\n  const Dtype* gpu_diff() const;\n  Dtype* mutable_cpu_data();\n  Dtype* mutable_gpu_data();\n  Dtype* mutable_cpu_diff();\n  Dtype* mutable_gpu_diff();\n  void Update();\n  void FromProto(const BlobProto& proto, bool reshape = true);\n  void ToProto(BlobProto* proto, bool write_diff = false) const;\n\n  /// @brief Compute the sum of absolute values (L1 norm) of the data.\n  Dtype asum_data() const;\n  /// @brief Compute the sum of absolute values (L1 norm) of the diff.\n  Dtype asum_diff() const;\n  /// @brief Compute the sum of squares (L2 norm squared) of the data.\n  Dtype sumsq_data() const;\n  /// @brief Compute the sum of squares (L2 norm squared) of the diff.\n  Dtype sumsq_diff() const;\n\n  /// @brief Scale the blob data by a constant factor.\n  void scale_data(Dtype scale_factor);\n  /// @brief Scale the blob diff by a constant factor.\n  void scale_diff(Dtype scale_factor);\n\n  /**\n   * @brief Set the data_ shared_ptr to point to the SyncedMemory holding the\n   *        data_ of Blob other -- useful in Layer%s which simply perform a copy\n   *        in their Forward pass.\n   *\n   * This deallocates the SyncedMemory holding this Blob's data_, as\n   * shared_ptr calls its destructor when reset with the \"=\" operator.\n   */\n  void ShareData(const Blob& other);\n  /**\n   * @brief Set the diff_ shared_ptr to point to the SyncedMemory holding the\n   *        diff_ of Blob other -- useful in Layer%s which simply perform a copy\n   *        in their Forward pass.\n   *\n   * This deallocates the SyncedMemory holding this Blob's diff_, as\n   * shared_ptr calls its destructor when reset with the \"=\" operator.\n   */\n  void ShareDiff(const Blob& other);\n\n  bool ShapeEquals(const BlobProto& other);\n\n protected:\n  shared_ptr<SyncedMemory> data_;\n  shared_ptr<SyncedMemory> diff_;\n  vector<int> shape_;\n  int count_;\n  int capacity_;\n\n  DISABLE_COPY_AND_ASSIGN(Blob);\n};  // class Blob\n\n}  // namespace caffe\n\n#endif  // CAFFE_BLOB_HPP_\n"
  },
  {
    "path": "include/caffe/caffe.hpp",
    "content": "// caffe.hpp is the header file that you need to include in your code. It wraps\n// all the internal caffe header files into one for simpler inclusion.\n\n#ifndef CAFFE_CAFFE_HPP_\n#define CAFFE_CAFFE_HPP_\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/layer_factory.hpp\"\n#include \"caffe/net.hpp\"\n#include \"caffe/parallel.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/solver.hpp\"\n#include \"caffe/util/benchmark.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#endif  // CAFFE_CAFFE_HPP_\n"
  },
  {
    "path": "include/caffe/common.hpp",
    "content": "#ifndef CAFFE_COMMON_HPP_\n#define CAFFE_COMMON_HPP_\n\n#include <boost/shared_ptr.hpp>\n#include <gflags/gflags.h>\n#include <glog/logging.h>\n\n#include <climits>\n#include <cmath>\n#include <fstream>  // NOLINT(readability/streams)\n#include <iostream>  // NOLINT(readability/streams)\n#include <map>\n#include <set>\n#include <sstream>\n#include <string>\n#include <utility>  // pair\n#include <vector>\n\n#include \"caffe/util/device_alternate.hpp\"\n\n// gflags 2.1 issue: namespace google was changed to gflags without warning.\n// Luckily we will be able to use GFLAGS_GFLAGS_H_ to detect if it is version\n// 2.1. If yes, we will add a temporary solution to redirect the namespace.\n// TODO(Yangqing): Once gflags solves the problem in a more elegant way, let's\n// remove the following hack.\n#ifndef GFLAGS_GFLAGS_H_\nnamespace gflags = google;\n#endif  // GFLAGS_GFLAGS_H_\n\n// Disable the copy and assignment operator for a class.\n#define DISABLE_COPY_AND_ASSIGN(classname) \\\nprivate:\\\n  classname(const classname&);\\\n  classname& operator=(const classname&)\n\n// Instantiate a class with float and double specifications.\n#define INSTANTIATE_CLASS(classname) \\\n  char gInstantiationGuard##classname; \\\n  template class classname<float>; \\\n  template class classname<double>\n\n#define INSTANTIATE_LAYER_GPU_FORWARD(classname) \\\n  template void classname<float>::Forward_gpu( \\\n      const std::vector<Blob<float>*>& bottom, \\\n      const std::vector<Blob<float>*>& top); \\\n  template void classname<double>::Forward_gpu( \\\n      const std::vector<Blob<double>*>& bottom, \\\n      const std::vector<Blob<double>*>& top);\n\n#define INSTANTIATE_LAYER_GPU_BACKWARD(classname) \\\n  template void classname<float>::Backward_gpu( \\\n      const std::vector<Blob<float>*>& top, \\\n      const std::vector<bool>& propagate_down, \\\n      const std::vector<Blob<float>*>& bottom); \\\n  template void classname<double>::Backward_gpu( \\\n      const std::vector<Blob<double>*>& top, \\\n      const std::vector<bool>& propagate_down, \\\n      const std::vector<Blob<double>*>& bottom)\n\n#define INSTANTIATE_LAYER_GPU_FUNCS(classname) \\\n  INSTANTIATE_LAYER_GPU_FORWARD(classname); \\\n  INSTANTIATE_LAYER_GPU_BACKWARD(classname)\n\n// A simple macro to mark codes that are not implemented, so that when the code\n// is executed we will see a fatal log.\n#define NOT_IMPLEMENTED LOG(FATAL) << \"Not Implemented Yet\"\n\n// See PR #1236\nnamespace cv { class Mat; }\n\nnamespace caffe {\n\n// We will use the boost shared_ptr instead of the new C++11 one mainly\n// because cuda does not work (at least now) well with C++11 features.\nusing boost::shared_ptr;\n\n// Common functions and classes from std that caffe often uses.\nusing std::fstream;\nusing std::ios;\nusing std::isnan;\nusing std::isinf;\nusing std::iterator;\nusing std::make_pair;\nusing std::map;\nusing std::ostringstream;\nusing std::pair;\nusing std::set;\nusing std::string;\nusing std::stringstream;\nusing std::vector;\n\n// A global initialization function that you should call in your main function.\n// Currently it initializes google flags and google logging.\nvoid GlobalInit(int* pargc, char*** pargv);\n\n// A singleton class to hold common caffe stuff, such as the handler that\n// caffe is going to use for cublas, curand, etc.\nclass Caffe {\n public:\n  ~Caffe();\n\n  // Thread local context for Caffe. Moved to common.cpp instead of\n  // including boost/thread.hpp to avoid a boost/NVCC issues (#1009, #1010)\n  // on OSX. Also fails on Linux with CUDA 7.0.18.\n  static Caffe& Get();\n\n  enum Brew { CPU, GPU };\n\n  // This random number generator facade hides boost and CUDA rng\n  // implementation from one another (for cross-platform compatibility).\n  class RNG {\n   public:\n    RNG();\n    explicit RNG(unsigned int seed);\n    explicit RNG(const RNG&);\n    RNG& operator=(const RNG&);\n    void* generator();\n   private:\n    class Generator;\n    shared_ptr<Generator> generator_;\n  };\n\n  // Getters for boost rng, curand, and cublas handles\n  inline static RNG& rng_stream() {\n    if (!Get().random_generator_) {\n      Get().random_generator_.reset(new RNG());\n    }\n    return *(Get().random_generator_);\n  }\n#ifndef CPU_ONLY\n  inline static cublasHandle_t cublas_handle() { return Get().cublas_handle_; }\n  inline static curandGenerator_t curand_generator() {\n    return Get().curand_generator_;\n  }\n#endif\n\n  // Returns the mode: running on CPU or GPU.\n  inline static Brew mode() { return Get().mode_; }\n  // The setters for the variables\n  // Sets the mode. It is recommended that you don't change the mode halfway\n  // into the program since that may cause allocation of pinned memory being\n  // freed in a non-pinned way, which may cause problems - I haven't verified\n  // it personally but better to note it here in the header file.\n  inline static void set_mode(Brew mode) { Get().mode_ = mode; }\n  // Sets the random seed of both boost and curand\n  static void set_random_seed(const unsigned int seed);\n  // Sets the device. Since we have cublas and curand stuff, set device also\n  // requires us to reset those values.\n  static void SetDevice(const int device_id);\n  // Prints the current GPU status.\n  static void DeviceQuery();\n  // Parallel training info\n  inline static int solver_count() { return Get().solver_count_; }\n  inline static void set_solver_count(int val) { Get().solver_count_ = val; }\n  inline static bool root_solver() { return Get().root_solver_; }\n  inline static void set_root_solver(bool val) { Get().root_solver_ = val; }\n\n protected:\n#ifndef CPU_ONLY\n  cublasHandle_t cublas_handle_;\n  curandGenerator_t curand_generator_;\n#endif\n  shared_ptr<RNG> random_generator_;\n\n  Brew mode_;\n  int solver_count_;\n  bool root_solver_;\n\n private:\n  // The private constructor to avoid duplicate instantiation.\n  Caffe();\n\n  DISABLE_COPY_AND_ASSIGN(Caffe);\n};\n\n}  // namespace caffe\n\n#endif  // CAFFE_COMMON_HPP_\n"
  },
  {
    "path": "include/caffe/common_layers.hpp",
    "content": "#ifndef CAFFE_COMMON_LAYERS_HPP_\n#define CAFFE_COMMON_LAYERS_HPP_\n\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/loss_layers.hpp\"\n#include \"caffe/neuron_layers.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\n/**\n * @brief Compute the index of the @f$ K @f$ max values for each datum across\n *        all dimensions @f$ (C \\times H \\times W) @f$.\n *\n * Intended for use after a classification layer to produce a prediction.\n * If parameter out_max_val is set to true, output is a vector of pairs\n * (max_ind, max_val) for each image.\n *\n * NOTE: does not implement Backwards operation.\n */\ntemplate <typename Dtype>\nclass ArgMaxLayer : public Layer<Dtype> {\n public:\n  /**\n   * @param param provides ArgMaxParameter argmax_param,\n   *     with ArgMaxLayer options:\n   *   - top_k (\\b optional uint, default 1).\n   *     the number @f$ K @f$ of maximal items to output.\n   *   - out_max_val (\\b optional bool, default false).\n   *     if set, output a vector of pairs (max_ind, max_val) for each image.\n   */\n  explicit ArgMaxLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"ArgMax\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times 1 \\times K \\times 1) @f$ or, if out_max_val\n   *      @f$ (N \\times 2 \\times K \\times 1) @f$\n   *      the computed outputs @f$\n   *       y_n = \\arg\\max\\limits_i x_{ni}\n   *      @f$ (for @f$ K = 1 @f$).\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  /// @brief Not implemented (non-differentiable function)\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n    NOT_IMPLEMENTED;\n  }\n  bool out_max_val_;\n  size_t top_k_;\n};\n\n/**\n * @brief Takes at least two Blob%s and concatenates them along either the num\n *        or channel dimension, outputting the result.\n */\ntemplate <typename Dtype>\nclass ConcatLayer : public Layer<Dtype> {\n public:\n  explicit ConcatLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Concat\"; }\n  virtual inline int MinBottomBlobs() const { return 2; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 2+)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x_1 @f$\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x_2 @f$\n   *   -# ...\n   *   - K @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x_K @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (KN \\times C \\times H \\times W) @f$ if axis == 0, or\n   *      @f$ (N \\times KC \\times H \\times W) @f$ if axis == 1:\n   *      the concatenated output @f$\n   *        y = [\\begin{array}{cccc} x_1 & x_2 & ... & x_K \\end{array}]\n   *      @f$\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the concatenate inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *        respect to the outputs\n   *   -# @f$ (KN \\times C \\times H \\times W) @f$ if axis == 0, or\n   *      @f$ (N \\times KC \\times H \\times W) @f$ if axis == 1:\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to concatenated outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length K), into which the top gradient\n   *        @f$ \\frac{\\partial E}{\\partial y} @f$ is deconcatenated back to the\n   *        inputs @f$\n   *        \\left[ \\begin{array}{cccc}\n   *          \\frac{\\partial E}{\\partial x_1} &\n   *          \\frac{\\partial E}{\\partial x_2} &\n   *          ... &\n   *          \\frac{\\partial E}{\\partial x_K}\n   *        \\end{array} \\right] =\n   *        \\frac{\\partial E}{\\partial y}\n   *        @f$\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  int count_;\n  int num_concats_;\n  int concat_input_size_;\n  int concat_axis_;\n};\n\n/**\n * @brief Compute elementwise operations, such as product and sum,\n *        along multiple input Blobs.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass EltwiseLayer : public Layer<Dtype> {\n public:\n  explicit EltwiseLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Eltwise\"; }\n  virtual inline int MinBottomBlobs() const { return 2; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  EltwiseParameter_EltwiseOp op_;\n  vector<Dtype> coeffs_;\n  Blob<int> max_idx_;\n\n  bool stable_prod_grad_;\n};\n\n/**\n * @brief Takes two+ Blobs, interprets last Blob as a selector and\n *  filter remaining Blobs accordingly with selector data (0 means that\n * the corresponding item has to be filtered, non-zero means that corresponding\n * item needs to stay).\n */\ntemplate <typename Dtype>\nclass FilterLayer : public Layer<Dtype> {\n public:\n  explicit FilterLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Filter\"; }\n  virtual inline int MinBottomBlobs() const { return 2; }\n  virtual inline int MinTopBlobs() const { return 1; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 2+)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs to be filtered @f$ x_1 @f$\n   *   -# ...\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs to be filtered @f$ x_K @f$\n   *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n   *      the selector blob\n   * @param top output Blob vector (length 1+)\n   *   -# @f$ (S \\times C \\times H \\times W) @f$ ()\n   *        the filtered output @f$ x_1 @f$\n   *        where S is the number of items\n   *        that haven't been filtered\n   *      @f$ (S \\times C \\times H \\times W) @f$\n   *        the filtered output @f$ x_K @f$\n   *        where S is the number of items\n   *        that haven't been filtered\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the forwarded inputs.\n   *\n   * @param top output Blob vector (length 1+), providing the error gradient with\n   *        respect to the outputs\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 2+), into which the top error\n   *        gradient is copied\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  bool first_reshape_;\n  vector<int> indices_to_forward_;\n};\n\n/**\n * @brief Reshapes the input Blob into flat vectors.\n *\n * Note: because this layer does not change the input values -- merely the\n * dimensions -- it can simply copy the input. The copy happens \"virtually\"\n * (thus taking effectively 0 real time) by setting, in Forward, the data\n * pointer of the top Blob to that of the bottom Blob (see Blob::ShareData),\n * and in Backward, the diff pointer of the bottom Blob to that of the top Blob\n * (see Blob::ShareDiff).\n */\ntemplate <typename Dtype>\nclass FlattenLayer : public Layer<Dtype> {\n public:\n  explicit FlattenLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Flatten\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 2+)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times CHW \\times 1 \\times 1) @f$\n   *      the outputs -- i.e., the (virtually) copied, flattened inputs\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the concatenate inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *        respect to the outputs\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length K), into which the top error\n   *        gradient is (virtually) copied\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n};\n\n/**\n * @brief Also known as a \"fully-connected\" layer, computes an inner product\n *        with a set of learned weights, and (optionally) adds biases.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass InnerProductLayer : public Layer<Dtype> {\n public:\n  explicit InnerProductLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"InnerProduct\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  int M_;\n  int K_;\n  int N_;\n  bool bias_term_;\n  Blob<Dtype> bias_multiplier_;\n};\n\n\n/**\n * @brief The compressed InnerProduct layer, also known as a compressed \n *  \"fully-connected\" layer\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass CInnerProductLayer : public Layer<Dtype> {\n public:\n  explicit CInnerProductLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"CInnerProduct\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  int M_;\n  int K_;\n  int N_;\n  bool bias_term_;\n  Blob<Dtype> bias_multiplier_;\n\n private:\n  Blob<Dtype> weight_tmp_;\n  Blob<Dtype> bias_tmp_;   \n  Blob<Dtype> rand_weight_m_;\n  Blob<Dtype> rand_bias_m_;    \n  Dtype gamma,power; \n  Dtype crate;  \n  Dtype mu,std;  \n  int iter_stop_;\n};\n\n\n/**\n * @brief Normalizes the input to have 0-mean and/or unit (1) variance.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass MVNLayer : public Layer<Dtype> {\n public:\n  explicit MVNLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"MVN\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n     const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  Blob<Dtype> mean_, variance_, temp_;\n\n  /// sum_multiplier is used to carry out sum using BLAS\n  Blob<Dtype> sum_multiplier_;\n  Dtype eps_;\n};\n\n/*\n * @brief Reshapes the input Blob into an arbitrary-sized output Blob.\n *\n * Note: similarly to FlattenLayer, this layer does not change the input values\n * (see FlattenLayer, Blob::ShareData and Blob::ShareDiff).\n */\ntemplate <typename Dtype>\nclass ReshapeLayer : public Layer<Dtype> {\n public:\n  explicit ReshapeLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Reshape\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {}\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {}\n\n  /// @brief vector of axes indices whose dimensions we'll copy from the bottom\n  vector<int> copy_axes_;\n  /// @brief the index of the axis whose dimension we infer, or -1 if none\n  int inferred_axis_;\n  /// @brief the product of the \"constant\" output dimensions\n  int constant_count_;\n};\n\n/**\n * @brief Compute \"reductions\" -- operations that return a scalar output Blob\n *        for an input Blob of arbitrary size, such as the sum, absolute sum,\n *        and sum of squares.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass ReductionLayer : public Layer<Dtype> {\n public:\n  explicit ReductionLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Reduction\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  /// @brief the reduction operation performed by the layer\n  ReductionParameter_ReductionOp op_;\n  /// @brief a scalar coefficient applied to all outputs\n  Dtype coeff_;\n  /// @brief the index of the first input axis to reduce\n  int axis_;\n  /// @brief the number of reductions performed\n  int num_;\n  /// @brief the input size of each reduction\n  int dim_;\n  /// @brief a helper Blob used for summation (op_ == SUM)\n  Blob<Dtype> sum_multiplier_;\n};\n\n/**\n * @brief Ignores bottom blobs while producing no top blobs. (This is useful\n *        to suppress outputs during testing.)\n */\ntemplate <typename Dtype>\nclass SilenceLayer : public Layer<Dtype> {\n public:\n  explicit SilenceLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n\n  virtual inline const char* type() const { return \"Silence\"; }\n  virtual inline int MinBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 0; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n  // We can't define Forward_gpu here, since STUB_GPU will provide\n  // its own definition for CPU_ONLY mode.\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n};\n\n/**\n * @brief Computes the softmax function.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass SoftmaxLayer : public Layer<Dtype> {\n public:\n  explicit SoftmaxLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Softmax\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n     const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  int outer_num_;\n  int inner_num_;\n  int softmax_axis_;\n  /// sum_multiplier is used to carry out sum using BLAS\n  Blob<Dtype> sum_multiplier_;\n  /// scale is an intermediate Blob to hold temporary results.\n  Blob<Dtype> scale_;\n};\n\n#ifdef USE_CUDNN\n/**\n * @brief cuDNN implementation of SoftmaxLayer.\n *        Fallback to SoftmaxLayer for CPU mode.\n */\ntemplate <typename Dtype>\nclass CuDNNSoftmaxLayer : public SoftmaxLayer<Dtype> {\n public:\n  explicit CuDNNSoftmaxLayer(const LayerParameter& param)\n      : SoftmaxLayer<Dtype>(param), handles_setup_(false) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual ~CuDNNSoftmaxLayer();\n\n protected:\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n     const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  bool handles_setup_;\n  cudnnHandle_t             handle_;\n  cudnnTensorDescriptor_t bottom_desc_;\n  cudnnTensorDescriptor_t top_desc_;\n};\n#endif\n\n/**\n * @brief Creates a \"split\" path in the network by copying the bottom Blob\n *        into multiple top Blob%s to be used by multiple consuming layers.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass SplitLayer : public Layer<Dtype> {\n public:\n  explicit SplitLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Split\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int MinTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  int count_;\n};\n\n/**\n * @brief Takes a Blob and slices it along either the num or channel dimension,\n *        outputting multiple sliced Blob results.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass SliceLayer : public Layer<Dtype> {\n public:\n  explicit SliceLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Slice\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int MinTopBlobs() const { return 2; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  int count_;\n  int num_slices_;\n  int slice_size_;\n  int slice_axis_;\n  vector<int> slice_point_;\n};\n\n}  // namespace caffe\n\n#endif  // CAFFE_COMMON_LAYERS_HPP_\n"
  },
  {
    "path": "include/caffe/data_layers.hpp",
    "content": "#ifndef CAFFE_DATA_LAYERS_HPP_\n#define CAFFE_DATA_LAYERS_HPP_\n\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"hdf5.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/data_reader.hpp\"\n#include \"caffe/data_transformer.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/internal_thread.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/blocking_queue.hpp\"\n#include \"caffe/util/db.hpp\"\n\nnamespace caffe {\n\n/**\n * @brief Provides base for data layers that feed blobs to the Net.\n *\n * TODO(dox): thorough documentation for Forward and proto params.\n */\ntemplate <typename Dtype>\nclass BaseDataLayer : public Layer<Dtype> {\n public:\n  explicit BaseDataLayer(const LayerParameter& param);\n  // LayerSetUp: implements common data layer setup functionality, and calls\n  // DataLayerSetUp to do special data layer setup for individual layer types.\n  // This method may not be overridden except by the BasePrefetchingDataLayer.\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  // Data layers should be shared by multiple solvers in parallel\n  virtual inline bool ShareInParallel() const { return true; }\n  virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n  // Data layers have no bottoms, so reshaping is trivial.\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {}\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {}\n\n protected:\n  TransformationParameter transform_param_;\n  shared_ptr<DataTransformer<Dtype> > data_transformer_;\n  bool output_labels_;\n};\n\ntemplate <typename Dtype>\nclass Batch {\n public:\n  Blob<Dtype> data_, label_;\n};\n\ntemplate <typename Dtype>\nclass BasePrefetchingDataLayer :\n    public BaseDataLayer<Dtype>, public InternalThread {\n public:\n  explicit BasePrefetchingDataLayer(const LayerParameter& param);\n  // LayerSetUp: implements common data layer setup functionality, and calls\n  // DataLayerSetUp to do special data layer setup for individual layer types.\n  // This method may not be overridden.\n  void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  // Prefetches batches (asynchronously if to GPU memory)\n  static const int PREFETCH_COUNT = 3;\n\n protected:\n  virtual void InternalThreadEntry();\n  virtual void load_batch(Batch<Dtype>* batch) = 0;\n\n  Batch<Dtype> prefetch_[PREFETCH_COUNT];\n  BlockingQueue<Batch<Dtype>*> prefetch_free_;\n  BlockingQueue<Batch<Dtype>*> prefetch_full_;\n\n  Blob<Dtype> transformed_data_;\n};\n\ntemplate <typename Dtype>\nclass DataLayer : public BasePrefetchingDataLayer<Dtype> {\n public:\n  explicit DataLayer(const LayerParameter& param);\n  virtual ~DataLayer();\n  virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  // DataLayer uses DataReader instead for sharing for parallelism\n  virtual inline bool ShareInParallel() const { return false; }\n  virtual inline const char* type() const { return \"Data\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 0; }\n  virtual inline int MinTopBlobs() const { return 1; }\n  virtual inline int MaxTopBlobs() const { return 2; }\n\n protected:\n  virtual void load_batch(Batch<Dtype>* batch);\n\n  DataReader reader_;\n};\n\n/**\n * @brief Provides data to the Net generated by a Filler.\n *\n * TODO(dox): thorough documentation for Forward and proto params.\n */\ntemplate <typename Dtype>\nclass DummyDataLayer : public Layer<Dtype> {\n public:\n  explicit DummyDataLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  // Data layers should be shared by multiple solvers in parallel\n  virtual inline bool ShareInParallel() const { return true; }\n  // Data layers have no bottoms, so reshaping is trivial.\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n\n  virtual inline const char* type() const { return \"DummyData\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 0; }\n  virtual inline int MinTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {}\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {}\n\n  vector<shared_ptr<Filler<Dtype> > > fillers_;\n  vector<bool> refill_;\n};\n\n/**\n * @brief Provides data to the Net from HDF5 files.\n *\n * TODO(dox): thorough documentation for Forward and proto params.\n */\ntemplate <typename Dtype>\nclass HDF5DataLayer : public Layer<Dtype> {\n public:\n  explicit HDF5DataLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual ~HDF5DataLayer();\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  // Data layers should be shared by multiple solvers in parallel\n  virtual inline bool ShareInParallel() const { return true; }\n  // Data layers have no bottoms, so reshaping is trivial.\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n\n  virtual inline const char* type() const { return \"HDF5Data\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 0; }\n  virtual inline int MinTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {}\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {}\n  virtual void LoadHDF5FileData(const char* filename);\n\n  std::vector<std::string> hdf_filenames_;\n  unsigned int num_files_;\n  unsigned int current_file_;\n  hsize_t current_row_;\n  std::vector<shared_ptr<Blob<Dtype> > > hdf_blobs_;\n  std::vector<unsigned int> data_permutation_;\n  std::vector<unsigned int> file_permutation_;\n};\n\n/**\n * @brief Write blobs to disk as HDF5 files.\n *\n * TODO(dox): thorough documentation for Forward and proto params.\n */\ntemplate <typename Dtype>\nclass HDF5OutputLayer : public Layer<Dtype> {\n public:\n  explicit HDF5OutputLayer(const LayerParameter& param)\n      : Layer<Dtype>(param), file_opened_(false) {}\n  virtual ~HDF5OutputLayer();\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  // Data layers should be shared by multiple solvers in parallel\n  virtual inline bool ShareInParallel() const { return true; }\n  // Data layers have no bottoms, so reshaping is trivial.\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n\n  virtual inline const char* type() const { return \"HDF5Output\"; }\n  // TODO: no limit on the number of blobs\n  virtual inline int ExactNumBottomBlobs() const { return 2; }\n  virtual inline int ExactNumTopBlobs() const { return 0; }\n\n  inline std::string file_name() const { return file_name_; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void SaveBlobs();\n\n  bool file_opened_;\n  std::string file_name_;\n  hid_t file_id_;\n  Blob<Dtype> data_blob_;\n  Blob<Dtype> label_blob_;\n};\n\n/**\n * @brief Provides data to the Net from image files.\n *\n * TODO(dox): thorough documentation for Forward and proto params.\n */\ntemplate <typename Dtype>\nclass ImageDataLayer : public BasePrefetchingDataLayer<Dtype> {\n public:\n  explicit ImageDataLayer(const LayerParameter& param)\n      : BasePrefetchingDataLayer<Dtype>(param) {}\n  virtual ~ImageDataLayer();\n  virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"ImageData\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 0; }\n  virtual inline int ExactNumTopBlobs() const { return 2; }\n\n protected:\n  shared_ptr<Caffe::RNG> prefetch_rng_;\n  virtual void ShuffleImages();\n  virtual void load_batch(Batch<Dtype>* batch);\n\n  vector<std::pair<std::string, int> > lines_;\n  int lines_id_;\n};\n\n/**\n * @brief Provides data to the Net from memory.\n *\n * TODO(dox): thorough documentation for Forward and proto params.\n */\ntemplate <typename Dtype>\nclass MemoryDataLayer : public BaseDataLayer<Dtype> {\n public:\n  explicit MemoryDataLayer(const LayerParameter& param)\n      : BaseDataLayer<Dtype>(param), has_new_data_(false) {}\n  virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"MemoryData\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 0; }\n  virtual inline int ExactNumTopBlobs() const { return 2; }\n\n  virtual void AddDatumVector(const vector<Datum>& datum_vector);\n  virtual void AddMatVector(const vector<cv::Mat>& mat_vector,\n      const vector<int>& labels);\n\n  // Reset should accept const pointers, but can't, because the memory\n  //  will be given to Blob, which is mutable\n  void Reset(Dtype* data, Dtype* label, int n);\n  void set_batch_size(int new_size);\n\n  int batch_size() { return batch_size_; }\n  int channels() { return channels_; }\n  int height() { return height_; }\n  int width() { return width_; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  int batch_size_, channels_, height_, width_, size_;\n  Dtype* data_;\n  Dtype* labels_;\n  int n_;\n  size_t pos_;\n  Blob<Dtype> added_data_;\n  Blob<Dtype> added_label_;\n  bool has_new_data_;\n};\n\n/**\n * @brief Provides data to the Net from windows of images files, specified\n *        by a window data file.\n *\n * TODO(dox): thorough documentation for Forward and proto params.\n */\ntemplate <typename Dtype>\nclass WindowDataLayer : public BasePrefetchingDataLayer<Dtype> {\n public:\n  explicit WindowDataLayer(const LayerParameter& param)\n      : BasePrefetchingDataLayer<Dtype>(param) {}\n  virtual ~WindowDataLayer();\n  virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"WindowData\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 0; }\n  virtual inline int ExactNumTopBlobs() const { return 2; }\n\n protected:\n  virtual unsigned int PrefetchRand();\n  virtual void load_batch(Batch<Dtype>* batch);\n\n  shared_ptr<Caffe::RNG> prefetch_rng_;\n  vector<std::pair<std::string, vector<int> > > image_database_;\n  enum WindowField { IMAGE_INDEX, LABEL, OVERLAP, X1, Y1, X2, Y2, NUM };\n  vector<vector<float> > fg_windows_;\n  vector<vector<float> > bg_windows_;\n  Blob<Dtype> data_mean_;\n  vector<Dtype> mean_values_;\n  bool has_mean_file_;\n  bool has_mean_values_;\n  bool cache_images_;\n  vector<std::pair<std::string, Datum > > image_database_cache_;\n};\n\n}  // namespace caffe\n\n#endif  // CAFFE_DATA_LAYERS_HPP_\n"
  },
  {
    "path": "include/caffe/data_reader.hpp",
    "content": "#ifndef CAFFE_DATA_READER_HPP_\n#define CAFFE_DATA_READER_HPP_\n\n#include <map>\n#include <string>\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/internal_thread.hpp\"\n#include \"caffe/util/blocking_queue.hpp\"\n#include \"caffe/util/db.hpp\"\n\nnamespace caffe {\n\n/**\n * @brief Reads data from a source to queues available to data layers.\n * A single reading thread is created per source, even if multiple solvers\n * are running in parallel, e.g. for multi-GPU training. This makes sure\n * databases are read sequentially, and that each solver accesses a different\n * subset of the database. Data is distributed to solvers in a round-robin\n * way to keep parallel training deterministic.\n */\nclass DataReader {\n public:\n  explicit DataReader(const LayerParameter& param);\n  ~DataReader();\n\n  inline BlockingQueue<Datum*>& free() const {\n    return queue_pair_->free_;\n  }\n  inline BlockingQueue<Datum*>& full() const {\n    return queue_pair_->full_;\n  }\n\n protected:\n  // Queue pairs are shared between a body and its readers\n  class QueuePair {\n   public:\n    explicit QueuePair(int size);\n    ~QueuePair();\n\n    BlockingQueue<Datum*> free_;\n    BlockingQueue<Datum*> full_;\n\n  DISABLE_COPY_AND_ASSIGN(QueuePair);\n  };\n\n  // A single body is created per source\n  class Body : public InternalThread {\n   public:\n    explicit Body(const LayerParameter& param);\n    virtual ~Body();\n\n   protected:\n    void InternalThreadEntry();\n    void read_one(db::Cursor* cursor, QueuePair* qp);\n\n    const LayerParameter param_;\n    BlockingQueue<shared_ptr<QueuePair> > new_queue_pairs_;\n\n    friend class DataReader;\n\n  DISABLE_COPY_AND_ASSIGN(Body);\n  };\n\n  // A source is uniquely identified by its layer name + path, in case\n  // the same database is read from two different locations in the net.\n  static inline string source_key(const LayerParameter& param) {\n    return param.name() + \":\" + param.data_param().source();\n  }\n\n  const shared_ptr<QueuePair> queue_pair_;\n  shared_ptr<Body> body_;\n\n  static map<const string, boost::weak_ptr<DataReader::Body> > bodies_;\n\nDISABLE_COPY_AND_ASSIGN(DataReader);\n};\n\n}  // namespace caffe\n\n#endif  // CAFFE_DATA_READER_HPP_\n"
  },
  {
    "path": "include/caffe/data_transformer.hpp",
    "content": "#ifndef CAFFE_DATA_TRANSFORMER_HPP\n#define CAFFE_DATA_TRANSFORMER_HPP\n\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\n/**\n * @brief Applies common transformations to the input data, such as\n * scaling, mirroring, substracting the image mean...\n */\ntemplate <typename Dtype>\nclass DataTransformer {\n public:\n  explicit DataTransformer(const TransformationParameter& param, Phase phase);\n  virtual ~DataTransformer() {}\n\n  /**\n   * @brief Initialize the Random number generations if needed by the\n   *    transformation.\n   */\n  void InitRand();\n\n  /**\n   * @brief Applies the transformation defined in the data layer's\n   * transform_param block to the data.\n   *\n   * @param datum\n   *    Datum containing the data to be transformed.\n   * @param transformed_blob\n   *    This is destination blob. It can be part of top blob's data if\n   *    set_cpu_data() is used. See data_layer.cpp for an example.\n   */\n  void Transform(const Datum& datum, Blob<Dtype>* transformed_blob);\n\n  /**\n   * @brief Applies the transformation defined in the data layer's\n   * transform_param block to a vector of Datum.\n   *\n   * @param datum_vector\n   *    A vector of Datum containing the data to be transformed.\n   * @param transformed_blob\n   *    This is destination blob. It can be part of top blob's data if\n   *    set_cpu_data() is used. See memory_layer.cpp for an example.\n   */\n  void Transform(const vector<Datum> & datum_vector,\n                Blob<Dtype>* transformed_blob);\n\n  /**\n   * @brief Applies the transformation defined in the data layer's\n   * transform_param block to a vector of Mat.\n   *\n   * @param mat_vector\n   *    A vector of Mat containing the data to be transformed.\n   * @param transformed_blob\n   *    This is destination blob. It can be part of top blob's data if\n   *    set_cpu_data() is used. See memory_layer.cpp for an example.\n   */\n  void Transform(const vector<cv::Mat> & mat_vector,\n                Blob<Dtype>* transformed_blob);\n\n  /**\n   * @brief Applies the transformation defined in the data layer's\n   * transform_param block to a cv::Mat\n   *\n   * @param cv_img\n   *    cv::Mat containing the data to be transformed.\n   * @param transformed_blob\n   *    This is destination blob. It can be part of top blob's data if\n   *    set_cpu_data() is used. See image_data_layer.cpp for an example.\n   */\n  void Transform(const cv::Mat& cv_img, Blob<Dtype>* transformed_blob);\n\n  /**\n   * @brief Applies the same transformation defined in the data layer's\n   * transform_param block to all the num images in a input_blob.\n   *\n   * @param input_blob\n   *    A Blob containing the data to be transformed. It applies the same\n   *    transformation to all the num images in the blob.\n   * @param transformed_blob\n   *    This is destination blob, it will contain as many images as the\n   *    input blob. It can be part of top blob's data.\n   */\n  void Transform(Blob<Dtype>* input_blob, Blob<Dtype>* transformed_blob);\n\n  /**\n   * @brief Infers the shape of transformed_blob will have when\n   *    the transformation is applied to the data.\n   *\n   * @param datum\n   *    Datum containing the data to be transformed.\n   */\n  vector<int> InferBlobShape(const Datum& datum);\n  /**\n   * @brief Infers the shape of transformed_blob will have when\n   *    the transformation is applied to the data.\n   *    It uses the first element to infer the shape of the blob.\n   *\n   * @param datum_vector\n   *    A vector of Datum containing the data to be transformed.\n   */\n  vector<int> InferBlobShape(const vector<Datum> & datum_vector);\n  /**\n   * @brief Infers the shape of transformed_blob will have when\n   *    the transformation is applied to the data.\n   *    It uses the first element to infer the shape of the blob.\n   *\n   * @param mat_vector\n   *    A vector of Mat containing the data to be transformed.\n   */\n  vector<int> InferBlobShape(const vector<cv::Mat> & mat_vector);\n  /**\n   * @brief Infers the shape of transformed_blob will have when\n   *    the transformation is applied to the data.\n   *\n   * @param cv_img\n   *    cv::Mat containing the data to be transformed.\n   */\n  vector<int> InferBlobShape(const cv::Mat& cv_img);\n\n protected:\n   /**\n   * @brief Generates a random integer from Uniform({0, 1, ..., n-1}).\n   *\n   * @param n\n   *    The upperbound (exclusive) value of the random number.\n   * @return\n   *    A uniformly random integer value from ({0, 1, ..., n-1}).\n   */\n  virtual int Rand(int n);\n\n  void Transform(const Datum& datum, Dtype* transformed_data);\n  // Tranformation parameters\n  TransformationParameter param_;\n\n\n  shared_ptr<Caffe::RNG> rng_;\n  Phase phase_;\n  Blob<Dtype> data_mean_;\n  vector<Dtype> mean_values_;\n};\n\n}  // namespace caffe\n\n#endif  // CAFFE_DATA_TRANSFORMER_HPP_\n\n"
  },
  {
    "path": "include/caffe/filler.hpp",
    "content": "// Fillers are random number generators that fills a blob using the specified\n// algorithm. The expectation is that they are only going to be used during\n// initialization time and will not involve any GPUs.\n\n#ifndef CAFFE_FILLER_HPP\n#define CAFFE_FILLER_HPP\n\n#include <string>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\n/// @brief Fills a Blob with constant or randomly-generated data.\ntemplate <typename Dtype>\nclass Filler {\n public:\n  explicit Filler(const FillerParameter& param) : filler_param_(param) {}\n  virtual ~Filler() {}\n  virtual void Fill(Blob<Dtype>* blob) = 0;\n protected:\n  FillerParameter filler_param_;\n};  // class Filler\n\n\n/// @brief Fills a Blob with constant values @f$ x = 0 @f$.\ntemplate <typename Dtype>\nclass ConstantFiller : public Filler<Dtype> {\n public:\n  explicit ConstantFiller(const FillerParameter& param)\n      : Filler<Dtype>(param) {}\n  virtual void Fill(Blob<Dtype>* blob) {\n    Dtype* data = blob->mutable_cpu_data();\n    const int count = blob->count();\n    const Dtype value = this->filler_param_.value();\n    CHECK(count);\n    for (int i = 0; i < count; ++i) {\n      data[i] = value;\n    }\n    CHECK_EQ(this->filler_param_.sparse(), -1)\n         << \"Sparsity not supported by this Filler.\";\n  }\n};\n\n/// @brief Fills a Blob with uniformly distributed values @f$ x\\sim U(a, b) @f$.\ntemplate <typename Dtype>\nclass UniformFiller : public Filler<Dtype> {\n public:\n  explicit UniformFiller(const FillerParameter& param)\n      : Filler<Dtype>(param) {}\n  virtual void Fill(Blob<Dtype>* blob) {\n    CHECK(blob->count());\n    caffe_rng_uniform<Dtype>(blob->count(), Dtype(this->filler_param_.min()),\n        Dtype(this->filler_param_.max()), blob->mutable_cpu_data());\n    CHECK_EQ(this->filler_param_.sparse(), -1)\n         << \"Sparsity not supported by this Filler.\";\n  }\n};\n\n/// @brief Fills a Blob with Gaussian-distributed values @f$ x = a @f$.\ntemplate <typename Dtype>\nclass GaussianFiller : public Filler<Dtype> {\n public:\n  explicit GaussianFiller(const FillerParameter& param)\n      : Filler<Dtype>(param) {}\n  virtual void Fill(Blob<Dtype>* blob) {\n    Dtype* data = blob->mutable_cpu_data();\n    CHECK(blob->count());\n    caffe_rng_gaussian<Dtype>(blob->count(), Dtype(this->filler_param_.mean()),\n        Dtype(this->filler_param_.std()), blob->mutable_cpu_data());\n    int sparse = this->filler_param_.sparse();\n    CHECK_GE(sparse, -1);\n    if (sparse >= 0) {\n      // Sparse initialization is implemented for \"weight\" blobs; i.e. matrices.\n      // These have num == channels == 1; width is number of inputs; height is\n      // number of outputs.  The 'sparse' variable specifies the mean number\n      // of non-zero input weights for a given output.\n      CHECK_GE(blob->num_axes(), 1);\n      const int num_outputs = blob->shape(0);\n      Dtype non_zero_probability = Dtype(sparse) / Dtype(num_outputs);\n      rand_vec_.reset(new SyncedMemory(blob->count() * sizeof(int)));\n      int* mask = reinterpret_cast<int*>(rand_vec_->mutable_cpu_data());\n      caffe_rng_bernoulli(blob->count(), non_zero_probability, mask);\n      for (int i = 0; i < blob->count(); ++i) {\n        data[i] *= mask[i];\n      }\n    }\n  }\n\n protected:\n  shared_ptr<SyncedMemory> rand_vec_;\n};\n\n/** @brief Fills a Blob with values @f$ x \\in [0, 1] @f$\n *         such that @f$ \\forall i \\sum_j x_{ij} = 1 @f$.\n */\ntemplate <typename Dtype>\nclass PositiveUnitballFiller : public Filler<Dtype> {\n public:\n  explicit PositiveUnitballFiller(const FillerParameter& param)\n      : Filler<Dtype>(param) {}\n  virtual void Fill(Blob<Dtype>* blob) {\n    Dtype* data = blob->mutable_cpu_data();\n    DCHECK(blob->count());\n    caffe_rng_uniform<Dtype>(blob->count(), 0, 1, blob->mutable_cpu_data());\n    // We expect the filler to not be called very frequently, so we will\n    // just use a simple implementation\n    int dim = blob->count() / blob->num();\n    CHECK(dim);\n    for (int i = 0; i < blob->num(); ++i) {\n      Dtype sum = 0;\n      for (int j = 0; j < dim; ++j) {\n        sum += data[i * dim + j];\n      }\n      for (int j = 0; j < dim; ++j) {\n        data[i * dim + j] /= sum;\n      }\n    }\n    CHECK_EQ(this->filler_param_.sparse(), -1)\n         << \"Sparsity not supported by this Filler.\";\n  }\n};\n\n/**\n * @brief Fills a Blob with values @f$ x \\sim U(-a, +a) @f$ where @f$ a @f$ is\n *        set inversely proportional to number of incoming nodes, outgoing\n *        nodes, or their average.\n *\n * A Filler based on the paper [Bengio and Glorot 2010]: Understanding\n * the difficulty of training deep feedforward neuralnetworks.\n *\n * It fills the incoming matrix by randomly sampling uniform data from [-scale,\n * scale] where scale = sqrt(3 / n) where n is the fan_in, fan_out, or their\n * average, depending on the variance_norm option. You should make sure the\n * input blob has shape (num, a, b, c) where a * b * c = fan_in and num * b * c\n * = fan_out. Note that this is currently not the case for inner product layers.\n *\n * TODO(dox): make notation in above comment consistent with rest & use LaTeX.\n */\ntemplate <typename Dtype>\nclass XavierFiller : public Filler<Dtype> {\n public:\n  explicit XavierFiller(const FillerParameter& param)\n      : Filler<Dtype>(param) {}\n  virtual void Fill(Blob<Dtype>* blob) {\n    CHECK(blob->count());\n    int fan_in = blob->count() / blob->num();\n    int fan_out = blob->count() / blob->channels();\n    Dtype n = fan_in;  // default to fan_in\n    if (this->filler_param_.variance_norm() ==\n        FillerParameter_VarianceNorm_AVERAGE) {\n      n = (fan_in + fan_out) / Dtype(2);\n    } else if (this->filler_param_.variance_norm() ==\n        FillerParameter_VarianceNorm_FAN_OUT) {\n      n = fan_out;\n    }\n    Dtype scale = sqrt(Dtype(3) / n);\n    caffe_rng_uniform<Dtype>(blob->count(), -scale, scale,\n        blob->mutable_cpu_data());\n    CHECK_EQ(this->filler_param_.sparse(), -1)\n         << \"Sparsity not supported by this Filler.\";\n  }\n};\n\n/**\n * @brief Fills a Blob with values @f$ x \\sim N(0, \\sigma^2) @f$ where\n *        @f$ \\sigma^2 @f$ is set inversely proportional to number of incoming\n *        nodes, outgoing nodes, or their average.\n *\n * A Filler based on the paper [He, Zhang, Ren and Sun 2015]: Specifically\n * accounts for ReLU nonlinearities.\n *\n * Aside: for another perspective on the scaling factor, see the derivation of\n * [Saxe, McClelland, and Ganguli 2013 (v3)].\n *\n * It fills the incoming matrix by randomly sampling Gaussian data with std =\n * sqrt(2 / n) where n is the fan_in, fan_out, or their average, depending on\n * the variance_norm option. You should make sure the input blob has shape (num,\n * a, b, c) where a * b * c = fan_in and num * b * c = fan_out. Note that this\n * is currently not the case for inner product layers.\n */\ntemplate <typename Dtype>\nclass MSRAFiller : public Filler<Dtype> {\n public:\n  explicit MSRAFiller(const FillerParameter& param)\n      : Filler<Dtype>(param) {}\n  virtual void Fill(Blob<Dtype>* blob) {\n    CHECK(blob->count());\n    int fan_in = blob->count() / blob->num();\n    int fan_out = blob->count() / blob->channels();\n    Dtype n = fan_in;  // default to fan_in\n    if (this->filler_param_.variance_norm() ==\n        FillerParameter_VarianceNorm_AVERAGE) {\n      n = (fan_in + fan_out) / Dtype(2);\n    } else if (this->filler_param_.variance_norm() ==\n        FillerParameter_VarianceNorm_FAN_OUT) {\n      n = fan_out;\n    }\n    Dtype std = sqrt(Dtype(2) / n);\n    caffe_rng_gaussian<Dtype>(blob->count(), Dtype(0), std,\n        blob->mutable_cpu_data());\n    CHECK_EQ(this->filler_param_.sparse(), -1)\n         << \"Sparsity not supported by this Filler.\";\n  }\n};\n\n/*!\n@brief Fills a Blob with coefficients for bilinear interpolation.\n\nA common use case is with the DeconvolutionLayer acting as upsampling.\nYou can upsample a feature map with shape of (B, C, H, W) by any integer factor\nusing the following proto.\n\\code\nlayer {\n  name: \"upsample\", type: \"Deconvolution\"\n  bottom: \"{{bottom_name}}\" top: \"{{top_name}}\"\n  convolution_param {\n    kernel_size: {{2 * factor - factor % 2}} stride: {{factor}}\n    num_output: {{C}} group: {{C}}\n    pad: {{ceil((factor - 1) / 2.)}}\n    weight_filler: { type: \"bilinear\" } bias_term: false\n  }\n  param { lr_mult: 0 decay_mult: 0 }\n}\n\\endcode\nPlease use this by replacing `{{}}` with your values. By specifying\n`num_output: {{C}} group: {{C}}`, it behaves as\nchannel-wise convolution. The filter shape of this deconvolution layer will be\n(C, 1, K, K) where K is `kernel_size`, and this filler will set a (K, K)\ninterpolation kernel for every channel of the filter identically. The resulting\nshape of the top feature map will be (B, C, factor * H, factor * W).\nNote that the learning rate and the\nweight decay are set to 0 in order to keep coefficient values of bilinear\ninterpolation unchanged during training. If you apply this to an image, this\noperation is equivalent to the following call in Python with Scikit.Image.\n\\code{.py}\nout = skimage.transform.rescale(img, factor, mode='constant', cval=0)\n\\endcode\n */\ntemplate <typename Dtype>\nclass BilinearFiller : public Filler<Dtype> {\n public:\n  explicit BilinearFiller(const FillerParameter& param)\n      : Filler<Dtype>(param) {}\n  virtual void Fill(Blob<Dtype>* blob) {\n    CHECK_EQ(blob->num_axes(), 4) << \"Blob must be 4 dim.\";\n    CHECK_EQ(blob->width(), blob->height()) << \"Filter must be square\";\n    Dtype* data = blob->mutable_cpu_data();\n    int f = ceil(blob->width() / 2.);\n    float c = (2 * f - 1 - f % 2) / (2. * f);\n    for (int i = 0; i < blob->count(); ++i) {\n      float x = i % blob->width();\n      float y = (i / blob->width()) % blob->height();\n      data[i] = (1 - fabs(x / f - c)) * (1 - fabs(y / f - c));\n    }\n    CHECK_EQ(this->filler_param_.sparse(), -1)\n         << \"Sparsity not supported by this Filler.\";\n  }\n};\n\n/**\n * @brief Get a specific filler from the specification given in FillerParameter.\n *\n * Ideally this would be replaced by a factory pattern, but we will leave it\n * this way for now.\n */\ntemplate <typename Dtype>\nFiller<Dtype>* GetFiller(const FillerParameter& param) {\n  const std::string& type = param.type();\n  if (type == \"constant\") {\n    return new ConstantFiller<Dtype>(param);\n  } else if (type == \"gaussian\") {\n    return new GaussianFiller<Dtype>(param);\n  } else if (type == \"positive_unitball\") {\n    return new PositiveUnitballFiller<Dtype>(param);\n  } else if (type == \"uniform\") {\n    return new UniformFiller<Dtype>(param);\n  } else if (type == \"xavier\") {\n    return new XavierFiller<Dtype>(param);\n  } else if (type == \"msra\") {\n    return new MSRAFiller<Dtype>(param);\n  } else if (type == \"bilinear\") {\n    return new BilinearFiller<Dtype>(param);\n  } else {\n    CHECK(false) << \"Unknown filler name: \" << param.type();\n  }\n  return (Filler<Dtype>*)(NULL);\n}\n\n}  // namespace caffe\n\n#endif  // CAFFE_FILLER_HPP_\n"
  },
  {
    "path": "include/caffe/internal_thread.hpp",
    "content": "#ifndef CAFFE_INTERNAL_THREAD_HPP_\n#define CAFFE_INTERNAL_THREAD_HPP_\n\n#include \"caffe/common.hpp\"\n\n/**\n Forward declare boost::thread instead of including boost/thread.hpp\n to avoid a boost/NVCC issues (#1009, #1010) on OSX.\n */\nnamespace boost { class thread; }\n\nnamespace caffe {\n\n/**\n * Virtual class encapsulate boost::thread for use in base class\n * The child class will acquire the ability to run a single thread,\n * by reimplementing the virtual function InternalThreadEntry.\n */\nclass InternalThread {\n public:\n  InternalThread() : thread_() {}\n  virtual ~InternalThread();\n\n  /**\n   * Caffe's thread local state will be initialized using the current\n   * thread values, e.g. device id, solver index etc. The random seed\n   * is initialized using caffe_rng_rand.\n   */\n  void StartInternalThread();\n\n  /** Will not return until the internal thread has exited. */\n  void StopInternalThread();\n\n  bool is_started() const;\n\n protected:\n  /* Implement this method in your subclass\n      with the code you want your thread to run. */\n  virtual void InternalThreadEntry() {}\n\n  /* Should be tested when running loops to exit when requested. */\n  bool must_stop();\n\n private:\n  void entry(int device, Caffe::Brew mode, int rand_seed, int solver_count,\n      bool root_solver);\n\n  shared_ptr<boost::thread> thread_;\n};\n\n}  // namespace caffe\n\n#endif  // CAFFE_INTERNAL_THREAD_HPP_\n"
  },
  {
    "path": "include/caffe/layer.hpp",
    "content": "#ifndef CAFFE_LAYER_H_\n#define CAFFE_LAYER_H_\n\n#include <algorithm>\n#include <string>\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/layer_factory.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/device_alternate.hpp\"\n\n/**\n Forward declare boost::thread instead of including boost/thread.hpp\n to avoid a boost/NVCC issues (#1009, #1010) on OSX.\n */\nnamespace boost { class mutex; }\n\nnamespace caffe {\n\n/**\n * @brief An interface for the units of computation which can be composed into a\n *        Net.\n *\n * Layer%s must implement a Forward function, in which they take their input\n * (bottom) Blob%s (if any) and compute their output Blob%s (if any).\n * They may also implement a Backward function, in which they compute the error\n * gradients with respect to their input Blob%s, given the error gradients with\n * their output Blob%s.\n */\ntemplate <typename Dtype>\nclass Layer {\n public:\n  /**\n   * You should not implement your own constructor. Any set up code should go\n   * to SetUp(), where the dimensions of the bottom blobs are provided to the\n   * layer.\n   */\n  explicit Layer(const LayerParameter& param)\n    : layer_param_(param), is_shared_(false) {\n      // Set phase and copy blobs (if there are any).\n      phase_ = param.phase();\n      if (layer_param_.blobs_size() > 0) {\n        blobs_.resize(layer_param_.blobs_size());\n        for (int i = 0; i < layer_param_.blobs_size(); ++i) {\n          blobs_[i].reset(new Blob<Dtype>());\n          blobs_[i]->FromProto(layer_param_.blobs(i));\n        }\n      }\n    }\n  virtual ~Layer() {}\n\n  /**\n   * @brief Implements common layer setup functionality.\n   *\n   * @param bottom the preshaped input blobs\n   * @param top\n   *     the allocated but unshaped output blobs, to be shaped by Reshape\n   *\n   * Checks that the number of bottom and top blobs is correct.\n   * Calls LayerSetUp to do special layer setup for individual layer types,\n   * followed by Reshape to set up sizes of top blobs and internal buffers.\n   * Sets up the loss weight multiplier blobs for any non-zero loss weights.\n   * This method may not be overridden.\n   */\n  void SetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n    InitMutex();\n    CheckBlobCounts(bottom, top);\n    LayerSetUp(bottom, top);\n    Reshape(bottom, top);\n    SetLossWeights(top);\n  }\n\n  /**\n   * @brief Does layer-specific setup: your layer should implement this function\n   *        as well as Reshape.\n   *\n   * @param bottom\n   *     the preshaped input blobs, whose data fields store the input data for\n   *     this layer\n   * @param top\n   *     the allocated but unshaped output blobs\n   *\n   * This method should do one-time layer specific setup. This includes reading\n   * and processing relevent parameters from the <code>layer_param_</code>.\n   * Setting up the shapes of top blobs and internal buffers should be done in\n   * <code>Reshape</code>, which will be called before the forward pass to\n   * adjust the top blob sizes.\n   */\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {}\n\n  /**\n   * @brief Whether a layer should be shared by multiple nets during data\n   *        parallelism. By default, all layers except for data layers should\n   *        not be shared. data layers should be shared to ensure each worker\n   *        solver access data sequentially during data parallelism.\n   */\n  virtual inline bool ShareInParallel() const { return false; }\n\n  /** @brief Return whether this layer is actually shared by other nets.\n   *         If ShareInParallel() is true and using more than one GPU and the\n   *         net has TRAIN phase, then this function is expected return true.\n   */\n  inline bool IsShared() const { return is_shared_; }\n\n  /** @brief Set whether this layer is actually shared by other nets\n   *         If ShareInParallel() is true and using more than one GPU and the\n   *         net has TRAIN phase, then is_shared should be set true.\n   */\n  inline void SetShared(bool is_shared) {\n    CHECK(ShareInParallel() || !is_shared)\n        << type() << \"Layer does not support sharing.\";\n    is_shared_ = is_shared;\n  }\n\n  /**\n   * @brief Adjust the shapes of top blobs and internal buffers to accommodate\n   *        the shapes of the bottom blobs.\n   *\n   * @param bottom the input blobs, with the requested input shapes\n   * @param top the top blobs, which should be reshaped as needed\n   *\n   * This method should reshape top blobs as needed according to the shapes\n   * of the bottom (input) blobs, as well as reshaping any internal buffers\n   * and making any other necessary adjustments so that the layer can\n   * accommodate the bottom blobs.\n   */\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) = 0;\n\n  /**\n   * @brief Given the bottom blobs, compute the top blobs and the loss.\n   *\n   * @param bottom\n   *     the input blobs, whose data fields store the input data for this layer\n   * @param top\n   *     the preshaped output blobs, whose data fields will store this layers'\n   *     outputs\n   * \\return The total loss from the layer.\n   *\n   * The Forward wrapper calls the relevant device wrapper function\n   * (Forward_cpu or Forward_gpu) to compute the top blob values given the\n   * bottom blobs.  If the layer has any non-zero loss_weights, the wrapper\n   * then computes and returns the loss.\n   *\n   * Your layer should implement Forward_cpu and (optionally) Forward_gpu.\n   */\n  inline Dtype Forward(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Given the top blob error gradients, compute the bottom blob error\n   *        gradients.\n   *\n   * @param top\n   *     the output blobs, whose diff fields store the gradient of the error\n   *     with respect to themselves\n   * @param propagate_down\n   *     a vector with equal length to bottom, with each index indicating\n   *     whether to propagate the error gradients down to the bottom blob at\n   *     the corresponding index\n   * @param bottom\n   *     the input blobs, whose diff fields will store the gradient of the error\n   *     with respect to themselves after Backward is run\n   *\n   * The Backward wrapper calls the relevant device wrapper function\n   * (Backward_cpu or Backward_gpu) to compute the bottom blob diffs given the\n   * top blob diffs.\n   *\n   * Your layer should implement Backward_cpu and (optionally) Backward_gpu.\n   */\n  inline void Backward(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down,\n      const vector<Blob<Dtype>*>& bottom);\n\n  /**\n   * @brief Returns the vector of learnable parameter blobs.\n   */\n  vector<shared_ptr<Blob<Dtype> > >& blobs() {\n    return blobs_;\n  }\n\n  /**\n   * @brief Returns the layer parameter.\n   */\n  const LayerParameter& layer_param() const { return layer_param_; }\n\n  /**\n   * @brief Writes the layer parameter to a protocol buffer\n   */\n  virtual void ToProto(LayerParameter* param, bool write_diff = false);\n\n  /**\n   * @brief Returns the scalar loss associated with a top blob at a given index.\n   */\n  inline Dtype loss(const int top_index) const {\n    return (loss_.size() > top_index) ? loss_[top_index] : Dtype(0);\n  }\n\n  /**\n   * @brief Sets the loss associated with a top blob at a given index.\n   */\n  inline void set_loss(const int top_index, const Dtype value) {\n    if (loss_.size() <= top_index) {\n      loss_.resize(top_index + 1, Dtype(0));\n    }\n    loss_[top_index] = value;\n  }\n\n  /**\n   * @brief Returns the layer type.\n   */\n  virtual inline const char* type() const { return \"\"; }\n\n  /**\n   * @brief Returns the exact number of bottom blobs required by the layer,\n   *        or -1 if no exact number is required.\n   *\n   * This method should be overridden to return a non-negative value if your\n   * layer expects some exact number of bottom blobs.\n   */\n  virtual inline int ExactNumBottomBlobs() const { return -1; }\n  /**\n   * @brief Returns the minimum number of bottom blobs required by the layer,\n   *        or -1 if no minimum number is required.\n   *\n   * This method should be overridden to return a non-negative value if your\n   * layer expects some minimum number of bottom blobs.\n   */\n  virtual inline int MinBottomBlobs() const { return -1; }\n  /**\n   * @brief Returns the maximum number of bottom blobs required by the layer,\n   *        or -1 if no maximum number is required.\n   *\n   * This method should be overridden to return a non-negative value if your\n   * layer expects some maximum number of bottom blobs.\n   */\n  virtual inline int MaxBottomBlobs() const { return -1; }\n  /**\n   * @brief Returns the exact number of top blobs required by the layer,\n   *        or -1 if no exact number is required.\n   *\n   * This method should be overridden to return a non-negative value if your\n   * layer expects some exact number of top blobs.\n   */\n  virtual inline int ExactNumTopBlobs() const { return -1; }\n  /**\n   * @brief Returns the minimum number of top blobs required by the layer,\n   *        or -1 if no minimum number is required.\n   *\n   * This method should be overridden to return a non-negative value if your\n   * layer expects some minimum number of top blobs.\n   */\n  virtual inline int MinTopBlobs() const { return -1; }\n  /**\n   * @brief Returns the maximum number of top blobs required by the layer,\n   *        or -1 if no maximum number is required.\n   *\n   * This method should be overridden to return a non-negative value if your\n   * layer expects some maximum number of top blobs.\n   */\n  virtual inline int MaxTopBlobs() const { return -1; }\n  /**\n   * @brief Returns true if the layer requires an equal number of bottom and\n   *        top blobs.\n   *\n   * This method should be overridden to return true if your layer expects an\n   * equal number of bottom and top blobs.\n   */\n  virtual inline bool EqualNumBottomTopBlobs() const { return false; }\n\n  /**\n   * @brief Return whether \"anonymous\" top blobs are created automatically\n   *        by the layer.\n   *\n   * If this method returns true, Net::Init will create enough \"anonymous\" top\n   * blobs to fulfill the requirement specified by ExactNumTopBlobs() or\n   * MinTopBlobs().\n   */\n  virtual inline bool AutoTopBlobs() const { return false; }\n\n  /**\n   * @brief Return whether to allow force_backward for a given bottom blob\n   *        index.\n   *\n   * If AllowForceBackward(i) == false, we will ignore the force_backward\n   * setting and backpropagate to blob i only if it needs gradient information\n   * (as is done when force_backward == false).\n   */\n  virtual inline bool AllowForceBackward(const int bottom_index) const {\n    return true;\n  }\n\n  /**\n   * @brief Specifies whether the layer should compute gradients w.r.t. a\n   *        parameter at a particular index given by param_id.\n   *\n   * You can safely ignore false values and always compute gradients\n   * for all parameters, but possibly with wasteful computation.\n   */\n  inline bool param_propagate_down(const int param_id) {\n    return (param_propagate_down_.size() > param_id) ?\n        param_propagate_down_[param_id] : false;\n  }\n  /**\n   * @brief Sets whether the layer should compute gradients w.r.t. a\n   *        parameter at a particular index given by param_id.\n   */\n  inline void set_param_propagate_down(const int param_id, const bool value) {\n    if (param_propagate_down_.size() <= param_id) {\n      param_propagate_down_.resize(param_id + 1, true);\n    }\n    param_propagate_down_[param_id] = value;\n  }\n  /************ For dynamic network surgery ***************/  \n  inline void set_current_iter_num(const int iter_num) {\n    iter_ = iter_num;\n  }\n  /********************************************************/\n protected:\n  /** The protobuf that stores the layer parameters */\n  LayerParameter layer_param_;\n  /** The phase: TRAIN or TEST */\n  Phase phase_;\n  /** The current iteration number */\n  int iter_;\n  /** The vector that stores the learnable parameters as a set of blobs. */\n  vector<shared_ptr<Blob<Dtype> > > blobs_;\n  /** Vector indicating whether to compute the diff of each param blob. */\n  vector<bool> param_propagate_down_;\n\n  /** The vector that indicates whether each top blob has a non-zero weight in\n   *  the objective function. */\n  vector<Dtype> loss_;\n\n  /** @brief Using the CPU device, compute the layer output. */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) = 0;\n  /**\n   * @brief Using the GPU device, compute the layer output.\n   *        Fall back to Forward_cpu() if unavailable.\n   */\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n    // LOG(WARNING) << \"Using CPU code as backup.\";\n    return Forward_cpu(bottom, top);\n  }\n\n  /**\n   * @brief Using the CPU device, compute the gradients for any parameters and\n   *        for the bottom blobs if propagate_down is true.\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down,\n      const vector<Blob<Dtype>*>& bottom) = 0;\n  /**\n   * @brief Using the GPU device, compute the gradients for any parameters and\n   *        for the bottom blobs if propagate_down is true.\n   *        Fall back to Backward_cpu() if unavailable.\n   */\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down,\n      const vector<Blob<Dtype>*>& bottom) {\n    // LOG(WARNING) << \"Using CPU code as backup.\";\n    Backward_cpu(top, propagate_down, bottom);\n  }\n\n  /**\n   * Called by the parent Layer's SetUp to check that the number of bottom\n   * and top Blobs provided as input match the expected numbers specified by\n   * the {ExactNum,Min,Max}{Bottom,Top}Blobs() functions.\n   */\n  virtual void CheckBlobCounts(const vector<Blob<Dtype>*>& bottom,\n                               const vector<Blob<Dtype>*>& top) {\n    if (ExactNumBottomBlobs() >= 0) {\n      CHECK_EQ(ExactNumBottomBlobs(), bottom.size())\n          << type() << \" Layer takes \" << ExactNumBottomBlobs()\n          << \" bottom blob(s) as input.\";\n    }\n    if (MinBottomBlobs() >= 0) {\n      CHECK_LE(MinBottomBlobs(), bottom.size())\n          << type() << \" Layer takes at least \" << MinBottomBlobs()\n          << \" bottom blob(s) as input.\";\n    }\n    if (MaxBottomBlobs() >= 0) {\n      CHECK_GE(MaxBottomBlobs(), bottom.size())\n          << type() << \" Layer takes at most \" << MaxBottomBlobs()\n          << \" bottom blob(s) as input.\";\n    }\n    if (ExactNumTopBlobs() >= 0) {\n      CHECK_EQ(ExactNumTopBlobs(), top.size())\n          << type() << \" Layer produces \" << ExactNumTopBlobs()\n          << \" top blob(s) as output.\";\n    }\n    if (MinTopBlobs() >= 0) {\n      CHECK_LE(MinTopBlobs(), top.size())\n          << type() << \" Layer produces at least \" << MinTopBlobs()\n          << \" top blob(s) as output.\";\n    }\n    if (MaxTopBlobs() >= 0) {\n      CHECK_GE(MaxTopBlobs(), top.size())\n          << type() << \" Layer produces at most \" << MaxTopBlobs()\n          << \" top blob(s) as output.\";\n    }\n    if (EqualNumBottomTopBlobs()) {\n      CHECK_EQ(bottom.size(), top.size())\n          << type() << \" Layer produces one top blob as output for each \"\n          << \"bottom blob input.\";\n    }\n  }\n\n  /**\n   * Called by SetUp to initialize the weights associated with any top blobs in\n   * the loss function. Store non-zero loss weights in the diff blob.\n   */\n  inline void SetLossWeights(const vector<Blob<Dtype>*>& top) {\n    const int num_loss_weights = layer_param_.loss_weight_size();\n    if (num_loss_weights) {\n      CHECK_EQ(top.size(), num_loss_weights) << \"loss_weight must be \"\n          \"unspecified or specified once per top blob.\";\n      for (int top_id = 0; top_id < top.size(); ++top_id) {\n        const Dtype loss_weight = layer_param_.loss_weight(top_id);\n        if (loss_weight == Dtype(0)) { continue; }\n        this->set_loss(top_id, loss_weight);\n        const int count = top[top_id]->count();\n        Dtype* loss_multiplier = top[top_id]->mutable_cpu_diff();\n        caffe_set(count, loss_weight, loss_multiplier);\n      }\n    }\n  }\n\n private:\n  /** Whether this layer is actually shared by other nets*/\n  bool is_shared_;\n\n  /** The mutex for sequential forward if this layer is shared */\n  shared_ptr<boost::mutex> forward_mutex_;\n\n  /** Initialize forward_mutex_ */\n  void InitMutex();\n  /** Lock forward_mutex_ if this layer is shared */\n  void Lock();\n  /** Unlock forward_mutex_ if this layer is shared */\n  void Unlock();\n\n  DISABLE_COPY_AND_ASSIGN(Layer);\n};  // class Layer\n\n// Forward and backward wrappers. You should implement the cpu and\n// gpu specific implementations instead, and should not change these\n// functions.\ntemplate <typename Dtype>\ninline Dtype Layer<Dtype>::Forward(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  // Lock during forward to ensure sequential forward\n  Lock();\n  Dtype loss = 0;\n  Reshape(bottom, top);\n  switch (Caffe::mode()) {\n  case Caffe::CPU:\n    Forward_cpu(bottom, top);\n    for (int top_id = 0; top_id < top.size(); ++top_id) {\n      if (!this->loss(top_id)) { continue; }\n      const int count = top[top_id]->count();\n      const Dtype* data = top[top_id]->cpu_data();\n      const Dtype* loss_weights = top[top_id]->cpu_diff();\n      loss += caffe_cpu_dot(count, data, loss_weights);\n    }\n    break;\n  case Caffe::GPU:\n    Forward_gpu(bottom, top);\n#ifndef CPU_ONLY\n    for (int top_id = 0; top_id < top.size(); ++top_id) {\n      if (!this->loss(top_id)) { continue; }\n      const int count = top[top_id]->count();\n      const Dtype* data = top[top_id]->gpu_data();\n      const Dtype* loss_weights = top[top_id]->gpu_diff();\n      Dtype blob_loss = 0;\n      caffe_gpu_dot(count, data, loss_weights, &blob_loss);\n      loss += blob_loss;\n    }\n#endif\n    break;\n  default:\n    LOG(FATAL) << \"Unknown caffe mode.\";\n  }\n  Unlock();\n  return loss;\n}\n\ntemplate <typename Dtype>\ninline void Layer<Dtype>::Backward(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  switch (Caffe::mode()) {\n  case Caffe::CPU:\n    Backward_cpu(top, propagate_down, bottom);\n    break;\n  case Caffe::GPU:\n    Backward_gpu(top, propagate_down, bottom);\n    break;\n  default:\n    LOG(FATAL) << \"Unknown caffe mode.\";\n  }\n}\n\n// Serialize LayerParameter to protocol buffer\ntemplate <typename Dtype>\nvoid Layer<Dtype>::ToProto(LayerParameter* param, bool write_diff) {\n  param->Clear();\n  param->CopyFrom(layer_param_);\n  param->clear_blobs();\n  for (int i = 0; i < blobs_.size(); ++i) {\n    blobs_[i]->ToProto(param->add_blobs(), write_diff);\n  }\n}\n\n}  // namespace caffe\n\n#endif  // CAFFE_LAYER_H_\n"
  },
  {
    "path": "include/caffe/layer_factory.hpp",
    "content": "/**\n * @brief A layer factory that allows one to register layers.\n * During runtime, registered layers could be called by passing a LayerParameter\n * protobuffer to the CreateLayer function:\n *\n *     LayerRegistry<Dtype>::CreateLayer(param);\n *\n * There are two ways to register a layer. Assuming that we have a layer like:\n *\n *   template <typename Dtype>\n *   class MyAwesomeLayer : public Layer<Dtype> {\n *     // your implementations\n *   };\n *\n * and its type is its C++ class name, but without the \"Layer\" at the end\n * (\"MyAwesomeLayer\" -> \"MyAwesome\").\n *\n * If the layer is going to be created simply by its constructor, in your c++\n * file, add the following line:\n *\n *    REGISTER_LAYER_CLASS(MyAwesome);\n *\n * Or, if the layer is going to be created by another creator function, in the\n * format of:\n *\n *    template <typename Dtype>\n *    Layer<Dtype*> GetMyAwesomeLayer(const LayerParameter& param) {\n *      // your implementation\n *    }\n *\n * (for example, when your layer has multiple backends, see GetConvolutionLayer\n * for a use case), then you can register the creator function instead, like\n *\n * REGISTER_LAYER_CREATOR(MyAwesome, GetMyAwesomeLayer)\n *\n * Note that each layer type should only be registered once.\n */\n\n#ifndef CAFFE_LAYER_FACTORY_H_\n#define CAFFE_LAYER_FACTORY_H_\n\n#include <map>\n#include <string>\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nclass Layer;\n\ntemplate <typename Dtype>\nclass LayerRegistry {\n public:\n  typedef shared_ptr<Layer<Dtype> > (*Creator)(const LayerParameter&);\n  typedef std::map<string, Creator> CreatorRegistry;\n\n  static CreatorRegistry& Registry() {\n    static CreatorRegistry* g_registry_ = new CreatorRegistry();\n    return *g_registry_;\n  }\n\n  // Adds a creator.\n  static void AddCreator(const string& type, Creator creator) {\n    CreatorRegistry& registry = Registry();\n    CHECK_EQ(registry.count(type), 0)\n        << \"Layer type \" << type << \" already registered.\";\n    registry[type] = creator;\n  }\n\n  // Get a layer using a LayerParameter.\n  static shared_ptr<Layer<Dtype> > CreateLayer(const LayerParameter& param) {\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"Creating layer \" << param.name();\n    }\n    const string& type = param.type();\n    CreatorRegistry& registry = Registry();\n    CHECK_EQ(registry.count(type), 1) << \"Unknown layer type: \" << type\n        << \" (known types: \" << LayerTypeListString() << \")\";\n    return registry[type](param);\n  }\n\n  static vector<string> LayerTypeList() {\n    CreatorRegistry& registry = Registry();\n    vector<string> layer_types;\n    for (typename CreatorRegistry::iterator iter = registry.begin();\n         iter != registry.end(); ++iter) {\n      layer_types.push_back(iter->first);\n    }\n    return layer_types;\n  }\n\n private:\n  // Layer registry should never be instantiated - everything is done with its\n  // static variables.\n  LayerRegistry() {}\n\n  static string LayerTypeListString() {\n    vector<string> layer_types = LayerTypeList();\n    string layer_types_str;\n    for (vector<string>::iterator iter = layer_types.begin();\n         iter != layer_types.end(); ++iter) {\n      if (iter != layer_types.begin()) {\n        layer_types_str += \", \";\n      }\n      layer_types_str += *iter;\n    }\n    return layer_types_str;\n  }\n};\n\n\ntemplate <typename Dtype>\nclass LayerRegisterer {\n public:\n  LayerRegisterer(const string& type,\n                  shared_ptr<Layer<Dtype> > (*creator)(const LayerParameter&)) {\n    // LOG(INFO) << \"Registering layer type: \" << type;\n    LayerRegistry<Dtype>::AddCreator(type, creator);\n  }\n};\n\n\n#define REGISTER_LAYER_CREATOR(type, creator)                                  \\\n  static LayerRegisterer<float> g_creator_f_##type(#type, creator<float>);     \\\n  static LayerRegisterer<double> g_creator_d_##type(#type, creator<double>)    \\\n\n#define REGISTER_LAYER_CLASS(type)                                             \\\n  template <typename Dtype>                                                    \\\n  shared_ptr<Layer<Dtype> > Creator_##type##Layer(const LayerParameter& param) \\\n  {                                                                            \\\n    return shared_ptr<Layer<Dtype> >(new type##Layer<Dtype>(param));           \\\n  }                                                                            \\\n  REGISTER_LAYER_CREATOR(type, Creator_##type##Layer)\n\n}  // namespace caffe\n\n#endif  // CAFFE_LAYER_FACTORY_H_\n"
  },
  {
    "path": "include/caffe/loss_layers.hpp",
    "content": "#ifndef CAFFE_LOSS_LAYERS_HPP_\n#define CAFFE_LOSS_LAYERS_HPP_\n\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/neuron_layers.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\nconst float kLOG_THRESHOLD = 1e-20;\n\n/**\n * @brief Computes the classification accuracy for a one-of-many\n *        classification task.\n */\ntemplate <typename Dtype>\nclass AccuracyLayer : public Layer<Dtype> {\n public:\n  /**\n   * @param param provides AccuracyParameter accuracy_param,\n   *     with AccuracyLayer options:\n   *   - top_k (\\b optional, default 1).\n   *     Sets the maximum rank @f$ k @f$ at which a prediction is considered\n   *     correct.  For example, if @f$ k = 5 @f$, a prediction is counted\n   *     correct if the correct label is among the top 5 predicted labels.\n   */\n  explicit AccuracyLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Accuracy\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 2; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 2)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the predictions @f$ x @f$, a Blob with values in\n   *      @f$ [-\\infty, +\\infty] @f$ indicating the predicted score for each of\n   *      the @f$ K = CHW @f$ classes. Each @f$ x_n @f$ is mapped to a predicted\n   *      label @f$ \\hat{l}_n @f$ given by its maximal index:\n   *      @f$ \\hat{l}_n = \\arg\\max\\limits_k x_{nk} @f$\n   *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n   *      the labels @f$ l @f$, an integer-valued Blob with values\n   *      @f$ l_n \\in [0, 1, 2, ..., K - 1] @f$\n   *      indicating the correct class label among the @f$ K @f$ classes\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n   *      the computed accuracy: @f$\n   *        \\frac{1}{N} \\sum\\limits_{n=1}^N \\delta\\{ \\hat{l}_n = l_n \\}\n   *      @f$, where @f$\n   *      \\delta\\{\\mathrm{condition}\\} = \\left\\{\n   *         \\begin{array}{lr}\n   *            1 & \\mbox{if condition} \\\\\n   *            0 & \\mbox{otherwise}\n   *         \\end{array} \\right.\n   *      @f$\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n\n  /// @brief Not implemented -- AccuracyLayer cannot be used as a loss.\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n    for (int i = 0; i < propagate_down.size(); ++i) {\n      if (propagate_down[i]) { NOT_IMPLEMENTED; }\n    }\n  }\n\n  int label_axis_, outer_num_, inner_num_;\n\n  int top_k_;\n\n  /// Whether to ignore instances with a certain label.\n  bool has_ignore_label_;\n  /// The label indicating that an instance should be ignored.\n  int ignore_label_;\n};\n\n/**\n * @brief An interface for Layer%s that take two Blob%s as input -- usually\n *        (1) predictions and (2) ground-truth labels -- and output a\n *        singleton Blob representing the loss.\n *\n * LossLayers are typically only capable of backpropagating to their first input\n * -- the predictions.\n */\ntemplate <typename Dtype>\nclass LossLayer : public Layer<Dtype> {\n public:\n  explicit LossLayer(const LayerParameter& param)\n     : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(\n      const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(\n      const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top);\n\n  virtual inline int ExactNumBottomBlobs() const { return 2; }\n\n  /**\n   * @brief For convenience and backwards compatibility, instruct the Net to\n   *        automatically allocate a single top Blob for LossLayers, into which\n   *        they output their singleton loss, (even if the user didn't specify\n   *        one in the prototxt, etc.).\n   */\n  virtual inline bool AutoTopBlobs() const { return true; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n  /**\n   * We usually cannot backpropagate to the labels; ignore force_backward for\n   * these inputs.\n   */\n  virtual inline bool AllowForceBackward(const int bottom_index) const {\n    return bottom_index != 1;\n  }\n};\n\n/**\n * @brief Computes the contrastive loss @f$\n *          E = \\frac{1}{2N} \\sum\\limits_{n=1}^N \\left(y\\right) d +\n *              \\left(1-y\\right) \\max \\left(margin-d, 0\\right)^2\n *          @f$ where @f$\n *          d = \\left| \\left| a_n - b_n \\right| \\right|_2 @f$. This can be\n *          used to train siamese networks.\n *\n * @param bottom input Blob vector (length 3)\n *   -# @f$ (N \\times C \\times 1 \\times 1) @f$\n *      the features @f$ a \\in [-\\infty, +\\infty]@f$\n *   -# @f$ (N \\times C \\times 1 \\times 1) @f$\n *      the features @f$ b \\in [-\\infty, +\\infty]@f$\n *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n *      the binary similarity @f$ s \\in [0, 1]@f$\n * @param top output Blob vector (length 1)\n *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n *      the computed contrastive loss: @f$ E =\n *          \\frac{1}{2N} \\sum\\limits_{n=1}^N \\left(y\\right) d +\n *          \\left(1-y\\right) \\max \\left(margin-d, 0\\right)^2\n *          @f$ where @f$\n *          d = \\left| \\left| a_n - b_n \\right| \\right|_2 @f$.\n * This can be used to train siamese networks.\n */\ntemplate <typename Dtype>\nclass ContrastiveLossLayer : public LossLayer<Dtype> {\n public:\n  explicit ContrastiveLossLayer(const LayerParameter& param)\n      : LossLayer<Dtype>(param), diff_() {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline int ExactNumBottomBlobs() const { return 3; }\n  virtual inline const char* type() const { return \"ContrastiveLoss\"; }\n  /**\n   * Unlike most loss layers, in the ContrastiveLossLayer we can backpropagate\n   * to the first two inputs.\n   */\n  virtual inline bool AllowForceBackward(const int bottom_index) const {\n    return bottom_index != 2;\n  }\n\n protected:\n  /// @copydoc ContrastiveLossLayer\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the Contrastive error gradient w.r.t. the inputs.\n   *\n   * Computes the gradients with respect to the two input vectors (bottom[0] and\n   * bottom[1]), but not the similarity label (bottom[2]).\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n   *      This Blob's diff will simply contain the loss_weight* @f$ \\lambda @f$,\n   *      as @f$ \\lambda @f$ is the coefficient of this layer's output\n   *      @f$\\ell_i@f$ in the overall Net loss\n   *      @f$ E = \\lambda_i \\ell_i + \\mbox{other loss terms}@f$; hence\n   *      @f$ \\frac{\\partial E}{\\partial \\ell_i} = \\lambda_i @f$.\n   *      (*Assuming that this top Blob is not used as a bottom (input) by any\n   *      other layer of the Net.)\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 2)\n   *   -# @f$ (N \\times C \\times 1 \\times 1) @f$\n   *      the features @f$a@f$; Backward fills their diff with\n   *      gradients if propagate_down[0]\n   *   -# @f$ (N \\times C \\times 1 \\times 1) @f$\n   *      the features @f$b@f$; Backward fills their diff with gradients if\n   *      propagate_down[1]\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  Blob<Dtype> diff_;  // cached for backward pass\n  Blob<Dtype> dist_sq_;  // cached for backward pass\n  Blob<Dtype> diff_sq_;  // tmp storage for gpu forward pass\n  Blob<Dtype> summer_vec_;  // tmp storage for gpu forward pass\n};\n\n/**\n * @brief Computes the Euclidean (L2) loss @f$\n *          E = \\frac{1}{2N} \\sum\\limits_{n=1}^N \\left| \\left| \\hat{y}_n - y_n\n *        \\right| \\right|_2^2 @f$ for real-valued regression tasks.\n *\n * @param bottom input Blob vector (length 2)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the predictions @f$ \\hat{y} \\in [-\\infty, +\\infty]@f$\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the targets @f$ y \\in [-\\infty, +\\infty]@f$\n * @param top output Blob vector (length 1)\n *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n *      the computed Euclidean loss: @f$ E =\n *          \\frac{1}{2n} \\sum\\limits_{n=1}^N \\left| \\left| \\hat{y}_n - y_n\n *        \\right| \\right|_2^2 @f$\n *\n * This can be used for least-squares regression tasks.  An InnerProductLayer\n * input to a EuclideanLossLayer exactly formulates a linear least squares\n * regression problem. With non-zero weight decay the problem becomes one of\n * ridge regression -- see src/caffe/test/test_sgd_solver.cpp for a concrete\n * example wherein we check that the gradients computed for a Net with exactly\n * this structure match hand-computed gradient formulas for ridge regression.\n *\n * (Note: Caffe, and SGD in general, is certainly \\b not the best way to solve\n * linear least squares problems! We use it only as an instructive example.)\n */\ntemplate <typename Dtype>\nclass EuclideanLossLayer : public LossLayer<Dtype> {\n public:\n  explicit EuclideanLossLayer(const LayerParameter& param)\n      : LossLayer<Dtype>(param), diff_() {}\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"EuclideanLoss\"; }\n  /**\n   * Unlike most loss layers, in the EuclideanLossLayer we can backpropagate\n   * to both inputs -- override to return true and always allow force_backward.\n   */\n  virtual inline bool AllowForceBackward(const int bottom_index) const {\n    return true;\n  }\n\n protected:\n  /// @copydoc EuclideanLossLayer\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the Euclidean error gradient w.r.t. the inputs.\n   *\n   * Unlike other children of LossLayer, EuclideanLossLayer \\b can compute\n   * gradients with respect to the label inputs bottom[1] (but still only will\n   * if propagate_down[1] is set, due to being produced by learnable parameters\n   * or if force_backward is set). In fact, this layer is \"commutative\" -- the\n   * result is the same regardless of the order of the two bottoms.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n   *      This Blob's diff will simply contain the loss_weight* @f$ \\lambda @f$,\n   *      as @f$ \\lambda @f$ is the coefficient of this layer's output\n   *      @f$\\ell_i@f$ in the overall Net loss\n   *      @f$ E = \\lambda_i \\ell_i + \\mbox{other loss terms}@f$; hence\n   *      @f$ \\frac{\\partial E}{\\partial \\ell_i} = \\lambda_i @f$.\n   *      (*Assuming that this top Blob is not used as a bottom (input) by any\n   *      other layer of the Net.)\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 2)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the predictions @f$\\hat{y}@f$; Backward fills their diff with\n   *      gradients @f$\n   *        \\frac{\\partial E}{\\partial \\hat{y}} =\n   *            \\frac{1}{n} \\sum\\limits_{n=1}^N (\\hat{y}_n - y_n)\n   *      @f$ if propagate_down[0]\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the targets @f$y@f$; Backward fills their diff with gradients\n   *      @f$ \\frac{\\partial E}{\\partial y} =\n   *          \\frac{1}{n} \\sum\\limits_{n=1}^N (y_n - \\hat{y}_n)\n   *      @f$ if propagate_down[1]\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  Blob<Dtype> diff_;\n};\n\n/**\n * @brief Computes the hinge loss for a one-of-many classification task.\n *\n * @param bottom input Blob vector (length 2)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the predictions @f$ t @f$, a Blob with values in\n *      @f$ [-\\infty, +\\infty] @f$ indicating the predicted score for each of\n *      the @f$ K = CHW @f$ classes. In an SVM, @f$ t @f$ is the result of\n *      taking the inner product @f$ X^T W @f$ of the D-dimensional features\n *      @f$ X \\in \\mathcal{R}^{D \\times N} @f$ and the learned hyperplane\n *      parameters @f$ W \\in \\mathcal{R}^{D \\times K} @f$, so a Net with just\n *      an InnerProductLayer (with num_output = D) providing predictions to a\n *      HingeLossLayer and no other learnable parameters or losses is\n *      equivalent to an SVM.\n *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n *      the labels @f$ l @f$, an integer-valued Blob with values\n *      @f$ l_n \\in [0, 1, 2, ..., K - 1] @f$\n *      indicating the correct class label among the @f$ K @f$ classes\n * @param top output Blob vector (length 1)\n *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n *      the computed hinge loss: @f$ E =\n *        \\frac{1}{N} \\sum\\limits_{n=1}^N \\sum\\limits_{k=1}^K\n *        [\\max(0, 1 - \\delta\\{l_n = k\\} t_{nk})] ^ p\n *      @f$, for the @f$ L^p @f$ norm\n *      (defaults to @f$ p = 1 @f$, the L1 norm; L2 norm, as in L2-SVM,\n *      is also available), and @f$\n *      \\delta\\{\\mathrm{condition}\\} = \\left\\{\n *         \\begin{array}{lr}\n *            1 & \\mbox{if condition} \\\\\n *           -1 & \\mbox{otherwise}\n *         \\end{array} \\right.\n *      @f$\n *\n * In an SVM, @f$ t \\in \\mathcal{R}^{N \\times K} @f$ is the result of taking\n * the inner product @f$ X^T W @f$ of the features\n * @f$ X \\in \\mathcal{R}^{D \\times N} @f$\n * and the learned hyperplane parameters\n * @f$ W \\in \\mathcal{R}^{D \\times K} @f$. So, a Net with just an\n * InnerProductLayer (with num_output = @f$k@f$) providing predictions to a\n * HingeLossLayer is equivalent to an SVM (assuming it has no other learned\n * outside the InnerProductLayer and no other losses outside the\n * HingeLossLayer).\n */\ntemplate <typename Dtype>\nclass HingeLossLayer : public LossLayer<Dtype> {\n public:\n  explicit HingeLossLayer(const LayerParameter& param)\n      : LossLayer<Dtype>(param) {}\n\n  virtual inline const char* type() const { return \"HingeLoss\"; }\n\n protected:\n  /// @copydoc HingeLossLayer\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the hinge loss error gradient w.r.t. the predictions.\n   *\n   * Gradients cannot be computed with respect to the label inputs (bottom[1]),\n   * so this method ignores bottom[1] and requires !propagate_down[1], crashing\n   * if propagate_down[1] is set.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n   *      This Blob's diff will simply contain the loss_weight* @f$ \\lambda @f$,\n   *      as @f$ \\lambda @f$ is the coefficient of this layer's output\n   *      @f$\\ell_i@f$ in the overall Net loss\n   *      @f$ E = \\lambda_i \\ell_i + \\mbox{other loss terms}@f$; hence\n   *      @f$ \\frac{\\partial E}{\\partial \\ell_i} = \\lambda_i @f$.\n   *      (*Assuming that this top Blob is not used as a bottom (input) by any\n   *      other layer of the Net.)\n   * @param propagate_down see Layer::Backward.\n   *      propagate_down[1] must be false as we can't compute gradients with\n   *      respect to the labels.\n   * @param bottom input Blob vector (length 2)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the predictions @f$t@f$; Backward computes diff\n   *      @f$ \\frac{\\partial E}{\\partial t} @f$\n   *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n   *      the labels -- ignored as we can't compute their error gradients\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n};\n\n/**\n * @brief A generalization of MultinomialLogisticLossLayer that takes an\n *        \"information gain\" (infogain) matrix specifying the \"value\" of all label\n *        pairs.\n *\n * Equivalent to the MultinomialLogisticLossLayer if the infogain matrix is the\n * identity.\n *\n * @param bottom input Blob vector (length 2-3)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the predictions @f$ \\hat{p} @f$, a Blob with values in\n *      @f$ [0, 1] @f$ indicating the predicted probability of each of the\n *      @f$ K = CHW @f$ classes.  Each prediction vector @f$ \\hat{p}_n @f$\n *      should sum to 1 as in a probability distribution: @f$\n *      \\forall n \\sum\\limits_{k=1}^K \\hat{p}_{nk} = 1 @f$.\n *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n *      the labels @f$ l @f$, an integer-valued Blob with values\n *      @f$ l_n \\in [0, 1, 2, ..., K - 1] @f$\n *      indicating the correct class label among the @f$ K @f$ classes\n *   -# @f$ (1 \\times 1 \\times K \\times K) @f$\n *      (\\b optional) the infogain matrix @f$ H @f$.  This must be provided as\n *      the third bottom blob input if not provided as the infogain_mat in the\n *      InfogainLossParameter. If @f$ H = I @f$, this layer is equivalent to the\n *      MultinomialLogisticLossLayer.\n * @param top output Blob vector (length 1)\n *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n *      the computed infogain multinomial logistic loss: @f$ E =\n *        \\frac{-1}{N} \\sum\\limits_{n=1}^N H_{l_n} \\log(\\hat{p}_n) =\n *        \\frac{-1}{N} \\sum\\limits_{n=1}^N \\sum\\limits_{k=1}^{K} H_{l_n,k}\n *        \\log(\\hat{p}_{n,k})\n *      @f$, where @f$ H_{l_n} @f$ denotes row @f$l_n@f$ of @f$H@f$.\n */\ntemplate <typename Dtype>\nclass InfogainLossLayer : public LossLayer<Dtype> {\n public:\n  explicit InfogainLossLayer(const LayerParameter& param)\n      : LossLayer<Dtype>(param), infogain_() {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  // InfogainLossLayer takes 2-3 bottom Blobs; if there are 3 the third should\n  // be the infogain matrix.  (Otherwise the infogain matrix is loaded from a\n  // file specified by LayerParameter.)\n  virtual inline int ExactNumBottomBlobs() const { return -1; }\n  virtual inline int MinBottomBlobs() const { return 2; }\n  virtual inline int MaxBottomBlobs() const { return 3; }\n\n  virtual inline const char* type() const { return \"InfogainLoss\"; }\n\n protected:\n  /// @copydoc InfogainLossLayer\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the infogain loss error gradient w.r.t. the predictions.\n   *\n   * Gradients cannot be computed with respect to the label inputs (bottom[1]),\n   * so this method ignores bottom[1] and requires !propagate_down[1], crashing\n   * if propagate_down[1] is set. (The same applies to the infogain matrix, if\n   * provided as bottom[2] rather than in the layer_param.)\n   *\n   * @param top output Blob vector (length 1), providing the error gradient\n   *      with respect to the outputs\n   *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n   *      This Blob's diff will simply contain the loss_weight* @f$ \\lambda @f$,\n   *      as @f$ \\lambda @f$ is the coefficient of this layer's output\n   *      @f$\\ell_i@f$ in the overall Net loss\n   *      @f$ E = \\lambda_i \\ell_i + \\mbox{other loss terms}@f$; hence\n   *      @f$ \\frac{\\partial E}{\\partial \\ell_i} = \\lambda_i @f$.\n   *      (*Assuming that this top Blob is not used as a bottom (input) by any\n   *      other layer of the Net.)\n   * @param propagate_down see Layer::Backward.\n   *      propagate_down[1] must be false as we can't compute gradients with\n   *      respect to the labels (similarly for propagate_down[2] and the\n   *      infogain matrix, if provided as bottom[2])\n   * @param bottom input Blob vector (length 2-3)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the predictions @f$ \\hat{p} @f$; Backward computes diff\n   *      @f$ \\frac{\\partial E}{\\partial \\hat{p}} @f$\n   *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n   *      the labels -- ignored as we can't compute their error gradients\n   *   -# @f$ (1 \\times 1 \\times K \\times K) @f$\n   *      (\\b optional) the information gain matrix -- ignored as its error\n   *      gradient computation is not implemented.\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  Blob<Dtype> infogain_;\n};\n\n/**\n * @brief Computes the multinomial logistic loss for a one-of-many\n *        classification task, directly taking a predicted probability\n *        distribution as input.\n *\n * When predictions are not already a probability distribution, you should\n * instead use the SoftmaxWithLossLayer, which maps predictions to a\n * distribution using the SoftmaxLayer, before computing the multinomial\n * logistic loss. The SoftmaxWithLossLayer should be preferred over separate\n * SoftmaxLayer + MultinomialLogisticLossLayer\n * as its gradient computation is more numerically stable.\n *\n * @param bottom input Blob vector (length 2)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the predictions @f$ \\hat{p} @f$, a Blob with values in\n *      @f$ [0, 1] @f$ indicating the predicted probability of each of the\n *      @f$ K = CHW @f$ classes.  Each prediction vector @f$ \\hat{p}_n @f$\n *      should sum to 1 as in a probability distribution: @f$\n *      \\forall n \\sum\\limits_{k=1}^K \\hat{p}_{nk} = 1 @f$.\n *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n *      the labels @f$ l @f$, an integer-valued Blob with values\n *      @f$ l_n \\in [0, 1, 2, ..., K - 1] @f$\n *      indicating the correct class label among the @f$ K @f$ classes\n * @param top output Blob vector (length 1)\n *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n *      the computed multinomial logistic loss: @f$ E =\n *        \\frac{-1}{N} \\sum\\limits_{n=1}^N \\log(\\hat{p}_{n,l_n})\n *      @f$\n */\ntemplate <typename Dtype>\nclass MultinomialLogisticLossLayer : public LossLayer<Dtype> {\n public:\n  explicit MultinomialLogisticLossLayer(const LayerParameter& param)\n      : LossLayer<Dtype>(param) {}\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"MultinomialLogisticLoss\"; }\n\n protected:\n  /// @copydoc MultinomialLogisticLossLayer\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the multinomial logistic loss error gradient w.r.t. the\n   *        predictions.\n   *\n   * Gradients cannot be computed with respect to the label inputs (bottom[1]),\n   * so this method ignores bottom[1] and requires !propagate_down[1], crashing\n   * if propagate_down[1] is set.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n   *      This Blob's diff will simply contain the loss_weight* @f$ \\lambda @f$,\n   *      as @f$ \\lambda @f$ is the coefficient of this layer's output\n   *      @f$\\ell_i@f$ in the overall Net loss\n   *      @f$ E = \\lambda_i \\ell_i + \\mbox{other loss terms}@f$; hence\n   *      @f$ \\frac{\\partial E}{\\partial \\ell_i} = \\lambda_i @f$.\n   *      (*Assuming that this top Blob is not used as a bottom (input) by any\n   *      other layer of the Net.)\n   * @param propagate_down see Layer::Backward.\n   *      propagate_down[1] must be false as we can't compute gradients with\n   *      respect to the labels.\n   * @param bottom input Blob vector (length 2)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the predictions @f$ \\hat{p} @f$; Backward computes diff\n   *      @f$ \\frac{\\partial E}{\\partial \\hat{p}} @f$\n   *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n   *      the labels -- ignored as we can't compute their error gradients\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n};\n\n/**\n * @brief Computes the cross-entropy (logistic) loss @f$\n *          E = \\frac{-1}{n} \\sum\\limits_{n=1}^N \\left[\n *                  p_n \\log \\hat{p}_n +\n *                  (1 - p_n) \\log(1 - \\hat{p}_n)\n *              \\right]\n *        @f$, often used for predicting targets interpreted as probabilities.\n *\n * This layer is implemented rather than separate\n * SigmoidLayer + CrossEntropyLayer\n * as its gradient computation is more numerically stable.\n * At test time, this layer can be replaced simply by a SigmoidLayer.\n *\n * @param bottom input Blob vector (length 2)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the scores @f$ x \\in [-\\infty, +\\infty]@f$,\n *      which this layer maps to probability predictions\n *      @f$ \\hat{p}_n = \\sigma(x_n) \\in [0, 1] @f$\n *      using the sigmoid function @f$ \\sigma(.) @f$ (see SigmoidLayer).\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the targets @f$ y \\in [0, 1] @f$\n * @param top output Blob vector (length 1)\n *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n *      the computed cross-entropy loss: @f$\n *          E = \\frac{-1}{n} \\sum\\limits_{n=1}^N \\left[\n *                  p_n \\log \\hat{p}_n + (1 - p_n) \\log(1 - \\hat{p}_n)\n *              \\right]\n *      @f$\n */\ntemplate <typename Dtype>\nclass SigmoidCrossEntropyLossLayer : public LossLayer<Dtype> {\n public:\n  explicit SigmoidCrossEntropyLossLayer(const LayerParameter& param)\n      : LossLayer<Dtype>(param),\n          sigmoid_layer_(new SigmoidLayer<Dtype>(param)),\n          sigmoid_output_(new Blob<Dtype>()) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"SigmoidCrossEntropyLoss\"; }\n\n protected:\n  /// @copydoc SigmoidCrossEntropyLossLayer\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the sigmoid cross-entropy loss error gradient w.r.t. the\n   *        predictions.\n   *\n   * Gradients cannot be computed with respect to the target inputs (bottom[1]),\n   * so this method ignores bottom[1] and requires !propagate_down[1], crashing\n   * if propagate_down[1] is set.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n   *      This Blob's diff will simply contain the loss_weight* @f$ \\lambda @f$,\n   *      as @f$ \\lambda @f$ is the coefficient of this layer's output\n   *      @f$\\ell_i@f$ in the overall Net loss\n   *      @f$ E = \\lambda_i \\ell_i + \\mbox{other loss terms}@f$; hence\n   *      @f$ \\frac{\\partial E}{\\partial \\ell_i} = \\lambda_i @f$.\n   *      (*Assuming that this top Blob is not used as a bottom (input) by any\n   *      other layer of the Net.)\n   * @param propagate_down see Layer::Backward.\n   *      propagate_down[1] must be false as gradient computation with respect\n   *      to the targets is not implemented.\n   * @param bottom input Blob vector (length 2)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the predictions @f$x@f$; Backward computes diff\n   *      @f$ \\frac{\\partial E}{\\partial x} =\n   *          \\frac{1}{n} \\sum\\limits_{n=1}^N (\\hat{p}_n - p_n)\n   *      @f$\n   *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n   *      the labels -- ignored as we can't compute their error gradients\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  /// The internal SigmoidLayer used to map predictions to probabilities.\n  shared_ptr<SigmoidLayer<Dtype> > sigmoid_layer_;\n  /// sigmoid_output stores the output of the SigmoidLayer.\n  shared_ptr<Blob<Dtype> > sigmoid_output_;\n  /// bottom vector holder to call the underlying SigmoidLayer::Forward\n  vector<Blob<Dtype>*> sigmoid_bottom_vec_;\n  /// top vector holder to call the underlying SigmoidLayer::Forward\n  vector<Blob<Dtype>*> sigmoid_top_vec_;\n};\n\n// Forward declare SoftmaxLayer for use in SoftmaxWithLossLayer.\ntemplate <typename Dtype> class SoftmaxLayer;\n\n/**\n * @brief Computes the multinomial logistic loss for a one-of-many\n *        classification task, passing real-valued predictions through a\n *        softmax to get a probability distribution over classes.\n *\n * This layer should be preferred over separate\n * SoftmaxLayer + MultinomialLogisticLossLayer\n * as its gradient computation is more numerically stable.\n * At test time, this layer can be replaced simply by a SoftmaxLayer.\n *\n * @param bottom input Blob vector (length 2)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the predictions @f$ x @f$, a Blob with values in\n *      @f$ [-\\infty, +\\infty] @f$ indicating the predicted score for each of\n *      the @f$ K = CHW @f$ classes. This layer maps these scores to a\n *      probability distribution over classes using the softmax function\n *      @f$ \\hat{p}_{nk} = \\exp(x_{nk}) /\n *      \\left[\\sum_{k'} \\exp(x_{nk'})\\right] @f$ (see SoftmaxLayer).\n *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n *      the labels @f$ l @f$, an integer-valued Blob with values\n *      @f$ l_n \\in [0, 1, 2, ..., K - 1] @f$\n *      indicating the correct class label among the @f$ K @f$ classes\n * @param top output Blob vector (length 1)\n *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n *      the computed cross-entropy classification loss: @f$ E =\n *        \\frac{-1}{N} \\sum\\limits_{n=1}^N \\log(\\hat{p}_{n,l_n})\n *      @f$, for softmax output class probabilites @f$ \\hat{p} @f$\n */\ntemplate <typename Dtype>\nclass SoftmaxWithLossLayer : public LossLayer<Dtype> {\n public:\n   /**\n    * @param param provides LossParameter loss_param, with options:\n    *  - ignore_label (optional)\n    *    Specify a label value that should be ignored when computing the loss.\n    *  - normalize (optional, default true)\n    *    If true, the loss is normalized by the number of (nonignored) labels\n    *    present; otherwise the loss is simply summed over spatial locations.\n    */\n  explicit SoftmaxWithLossLayer(const LayerParameter& param)\n      : LossLayer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"SoftmaxWithLoss\"; }\n  virtual inline int ExactNumTopBlobs() const { return -1; }\n  virtual inline int MinTopBlobs() const { return 1; }\n  virtual inline int MaxTopBlobs() const { return 2; }\n\n protected:\n  /// @copydoc SoftmaxWithLossLayer\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  /**\n   * @brief Computes the softmax loss error gradient w.r.t. the predictions.\n   *\n   * Gradients cannot be computed with respect to the label inputs (bottom[1]),\n   * so this method ignores bottom[1] and requires !propagate_down[1], crashing\n   * if propagate_down[1] is set.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (1 \\times 1 \\times 1 \\times 1) @f$\n   *      This Blob's diff will simply contain the loss_weight* @f$ \\lambda @f$,\n   *      as @f$ \\lambda @f$ is the coefficient of this layer's output\n   *      @f$\\ell_i@f$ in the overall Net loss\n   *      @f$ E = \\lambda_i \\ell_i + \\mbox{other loss terms}@f$; hence\n   *      @f$ \\frac{\\partial E}{\\partial \\ell_i} = \\lambda_i @f$.\n   *      (*Assuming that this top Blob is not used as a bottom (input) by any\n   *      other layer of the Net.)\n   * @param propagate_down see Layer::Backward.\n   *      propagate_down[1] must be false as we can't compute gradients with\n   *      respect to the labels.\n   * @param bottom input Blob vector (length 2)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the predictions @f$ x @f$; Backward computes diff\n   *      @f$ \\frac{\\partial E}{\\partial x} @f$\n   *   -# @f$ (N \\times 1 \\times 1 \\times 1) @f$\n   *      the labels -- ignored as we can't compute their error gradients\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n\n  /// The internal SoftmaxLayer used to map predictions to a distribution.\n  shared_ptr<Layer<Dtype> > softmax_layer_;\n  /// prob stores the output probability predictions from the SoftmaxLayer.\n  Blob<Dtype> prob_;\n  /// bottom vector holder used in call to the underlying SoftmaxLayer::Forward\n  vector<Blob<Dtype>*> softmax_bottom_vec_;\n  /// top vector holder used in call to the underlying SoftmaxLayer::Forward\n  vector<Blob<Dtype>*> softmax_top_vec_;\n  /// Whether to ignore instances with a certain label.\n  bool has_ignore_label_;\n  /// The label indicating that an instance should be ignored.\n  int ignore_label_;\n  /// Whether to normalize the loss by the total number of values present\n  /// (otherwise just by the batch size).\n  bool normalize_;\n\n  int softmax_axis_, outer_num_, inner_num_;\n};\n\n}  // namespace caffe\n\n#endif  // CAFFE_LOSS_LAYERS_HPP_\n"
  },
  {
    "path": "include/caffe/net.hpp",
    "content": "#ifndef CAFFE_NET_HPP_\n#define CAFFE_NET_HPP_\n\n#include <map>\n#include <set>\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\n/**\n * @brief Connects Layer%s together into a directed acyclic graph (DAG)\n *        specified by a NetParameter.\n *\n * TODO(dox): more thorough description.\n */\ntemplate <typename Dtype>\nclass Net {\n public:\n  explicit Net(const NetParameter& param, const Net* root_net = NULL);\n  explicit Net(const string& param_file, Phase phase,\n      const Net* root_net = NULL);\n  virtual ~Net() {}\n\n  /// @brief Initialize a network with a NetParameter.\n  void Init(const NetParameter& param);\n\n  /**\n   * @brief Run Forward with the input Blob%s already fed separately.\n   *\n   * You can get the input blobs using input_blobs().\n   */\n  const vector<Blob<Dtype>*>& ForwardPrefilled(Dtype* loss = NULL);\n\n  /**\n   * The From and To variants of Forward and Backward operate on the\n   * (topological) ordering by which the net is specified. For general DAG\n   * networks, note that (1) computing from one layer to another might entail\n   * extra computation on unrelated branches, and (2) computation starting in\n   * the middle may be incorrect if all of the layers of a fan-in are not\n   * included.\n   */\n  Dtype ForwardFromTo(int start, int end);\n  Dtype ForwardFrom(int start);\n  Dtype ForwardTo(int end);\n  /// @brief Run forward using a set of bottom blobs, and return the result.\n  const vector<Blob<Dtype>*>& Forward(const vector<Blob<Dtype>* > & bottom,\n      Dtype* loss = NULL);\n  /**\n   * @brief Run forward using a serialized BlobProtoVector and return the\n   *        result as a serialized BlobProtoVector\n   */\n  string Forward(const string& input_blob_protos, Dtype* loss = NULL);\n\n  /**\n   * @brief Zeroes out the diffs of all net parameters.\n   *        Should be run before Backward.\n   */\n  void ClearParamDiffs();\n\n  /**\n   * The network backward should take no input and output, since it solely\n   * computes the gradient w.r.t the parameters, and the data has already been\n   * provided during the forward pass.\n   */\n  void Backward();\n  void BackwardFromTo(int start, int end);\n  void BackwardFrom(int start);\n  void BackwardTo(int end);\n\n  /**\n   * @brief Reshape all layers from bottom to top.\n   *\n   * This is useful to propagate changes to layer sizes without running\n   * a forward pass, e.g. to compute output feature size.\n   */\n  void Reshape();\n\n  Dtype ForwardBackward(const vector<Blob<Dtype>* > & bottom) {\n    Dtype loss;\n    Forward(bottom, &loss);\n    Backward();\n    return loss;\n  }\n\n  /// @brief Updates the network weights based on the diff values computed.\n  void Update();\n  /**\n   * @brief Shares weight data of owner blobs with shared blobs.\n   *\n   * Note: this is called by Net::Init, and thus should normally not be\n   * called manually.\n   */\n  void ShareWeights();\n\n  /**\n   * @brief For an already initialized net, implicitly copies (i.e., using no\n   *        additional memory) the pre-trained layers from another Net.\n   */\n  void ShareTrainedLayersWith(const Net* other);\n  // For an already initialized net, CopyTrainedLayersFrom() copies the already\n  // trained layers from another net parameter instance.\n  /**\n   * @brief For an already initialized net, copies the pre-trained layers from\n   *        another Net.\n   */\n  void CopyTrainedLayersFrom(const NetParameter& param);\n  void CopyTrainedLayersFrom(const string trained_filename);\n  void CopyTrainedLayersFromBinaryProto(const string trained_filename);\n  void CopyTrainedLayersFromHDF5(const string trained_filename);\n  /// @brief Writes the net to a proto.\n  void ToProto(NetParameter* param, bool write_diff = false) const;\n  /// @brief Writes the net to an HDF5 file.\n  void ToHDF5(const string& filename, bool write_diff = false) const;\n\n  /// @brief returns the network name.\n  inline const string& name() const { return name_; }\n  /// @brief returns the layer names\n  inline const vector<string>& layer_names() const { return layer_names_; }\n  /// @brief returns the blob names\n  inline const vector<string>& blob_names() const { return blob_names_; }\n  /// @brief returns the blobs\n  inline const vector<shared_ptr<Blob<Dtype> > >& blobs() const {\n    return blobs_;\n  }\n  /// @brief returns the layers\n  inline const vector<shared_ptr<Layer<Dtype> > >& layers() const {\n    return layers_;\n  }\n  /// @brief returns the phase: TRAIN or TEST\n  inline Phase phase() const { return phase_; }\n  /**\n   * @brief returns the bottom vecs for each layer -- usually you won't\n   *        need this unless you do per-layer checks such as gradients.\n   */\n  inline const vector<vector<Blob<Dtype>*> >& bottom_vecs() const {\n    return bottom_vecs_;\n  }\n  /**\n   * @brief returns the top vecs for each layer -- usually you won't\n   *        need this unless you do per-layer checks such as gradients.\n   */\n  inline const vector<vector<Blob<Dtype>*> >& top_vecs() const {\n    return top_vecs_;\n  }\n  inline const vector<vector<bool> >& bottom_need_backward() const {\n    return bottom_need_backward_;\n  }\n  inline const vector<Dtype>& blob_loss_weights() const {\n    return blob_loss_weights_;\n  }\n  inline const vector<bool>& layer_need_backward() const {\n    return layer_need_backward_;\n  }\n  /// @brief returns the parameters\n  inline const vector<shared_ptr<Blob<Dtype> > >& params() const {\n    return params_;\n  }\n  inline const vector<Blob<Dtype>*>& learnable_params() const {\n    return learnable_params_;\n  }\n  /// @brief returns the learnable parameter learning rate multipliers\n  inline const vector<float>& params_lr() const { return params_lr_; }\n  inline const vector<bool>& has_params_lr() const { return has_params_lr_; }\n  /// @brief returns the learnable parameter decay multipliers\n  inline const vector<float>& params_weight_decay() const {\n    return params_weight_decay_;\n  }\n  inline const vector<bool>& has_params_decay() const {\n    return has_params_decay_;\n  }\n  const map<string, int>& param_names_index() const {\n    return param_names_index_;\n  }\n  inline const vector<int>& param_owners() const { return param_owners_; }\n  /// @brief Input and output blob numbers\n  inline int num_inputs() const { return net_input_blobs_.size(); }\n  inline int num_outputs() const { return net_output_blobs_.size(); }\n  inline const vector<Blob<Dtype>*>& input_blobs() const {\n    return net_input_blobs_;\n  }\n  inline const vector<Blob<Dtype>*>& output_blobs() const {\n    return net_output_blobs_;\n  }\n  inline const vector<int>& input_blob_indices() const {\n    return net_input_blob_indices_;\n  }\n  inline const vector<int>& output_blob_indices() const {\n    return net_output_blob_indices_;\n  }\n  /************ For dynamic network surgery ***************/\n  inline void set_current_iter_num(const int iter_num) {\n    iter_ = iter_num;\n    for (int layer_id = 0; layer_id < layers_.size(); ++layer_id) {\n      layers_[layer_id]->set_current_iter_num(iter_num);\n    }\n  }  \n  /********************************************************/\n  bool has_blob(const string& blob_name) const;\n  const shared_ptr<Blob<Dtype> > blob_by_name(const string& blob_name) const;\n  bool has_layer(const string& layer_name) const;\n  const shared_ptr<Layer<Dtype> > layer_by_name(const string& layer_name) const;\n\n  void set_debug_info(const bool value) { debug_info_ = value; }\n\n  // Helpers for Init.\n  /**\n   * @brief Remove layers that the user specified should be excluded given the current\n   *        phase, level, and stage.\n   */\n  static void FilterNet(const NetParameter& param,\n      NetParameter* param_filtered);\n  /// @brief return whether NetState state meets NetStateRule rule\n  static bool StateMeetsRule(const NetState& state, const NetStateRule& rule,\n      const string& layer_name);\n\n protected:\n  // Helpers for Init.\n  /// @brief Append a new input or top blob to the net.\n  void AppendTop(const NetParameter& param, const int layer_id,\n                 const int top_id, set<string>* available_blobs,\n                 map<string, int>* blob_name_to_idx);\n  /// @brief Append a new bottom blob to the net.\n  int AppendBottom(const NetParameter& param, const int layer_id,\n                   const int bottom_id, set<string>* available_blobs,\n                   map<string, int>* blob_name_to_idx);\n  /// @brief Append a new parameter blob to the net.\n  void AppendParam(const NetParameter& param, const int layer_id,\n                   const int param_id);\n\n  /// @brief Helper for displaying debug info in Forward about input Blobs.\n  void InputDebugInfo(const int layer_id);\n  /// @brief Helper for displaying debug info in Forward.\n  void ForwardDebugInfo(const int layer_id);\n  /// @brief Helper for displaying debug info in Backward.\n  void BackwardDebugInfo(const int layer_id);\n  /// @brief Helper for displaying debug info in Update.\n  void UpdateDebugInfo(const int param_id);\n\n  /// @brief The network name\n  string name_;\n  /// @brief The phase: TRAIN or TEST\n  Phase phase_;\n  /// @brief The current iteration number \n  int iter_;  \n  /// @brief Individual layers in the net\n  vector<shared_ptr<Layer<Dtype> > > layers_;\n  vector<string> layer_names_;\n  map<string, int> layer_names_index_;\n  vector<bool> layer_need_backward_;\n  /// @brief the blobs storing intermediate results between the layer.\n  vector<shared_ptr<Blob<Dtype> > > blobs_;\n  vector<string> blob_names_;\n  map<string, int> blob_names_index_;\n  vector<bool> blob_need_backward_;\n  /// bottom_vecs stores the vectors containing the input for each layer.\n  /// They don't actually host the blobs (blobs_ does), so we simply store\n  /// pointers.\n  vector<vector<Blob<Dtype>*> > bottom_vecs_;\n  vector<vector<int> > bottom_id_vecs_;\n  vector<vector<bool> > bottom_need_backward_;\n  /// top_vecs stores the vectors containing the output for each layer\n  vector<vector<Blob<Dtype>*> > top_vecs_;\n  vector<vector<int> > top_id_vecs_;\n  /// Vector of weight in the loss (or objective) function of each net blob,\n  /// indexed by blob_id.\n  vector<Dtype> blob_loss_weights_;\n  vector<vector<int> > param_id_vecs_;\n  vector<int> param_owners_;\n  vector<string> param_display_names_;\n  vector<pair<int, int> > param_layer_indices_;\n  map<string, int> param_names_index_;\n  /// blob indices for the input and the output of the net\n  vector<int> net_input_blob_indices_;\n  vector<int> net_output_blob_indices_;\n  vector<Blob<Dtype>*> net_input_blobs_;\n  vector<Blob<Dtype>*> net_output_blobs_;\n  /// The parameters in the network.\n  vector<shared_ptr<Blob<Dtype> > > params_;\n  vector<Blob<Dtype>*> learnable_params_;\n  /**\n   * The mapping from params_ -> learnable_params_: we have\n   * learnable_param_ids_.size() == params_.size(),\n   * and learnable_params_[learnable_param_ids_[i]] == params_[i].get()\n   * if and only if params_[i] is an \"owner\"; otherwise, params_[i] is a sharer\n   * and learnable_params_[learnable_param_ids_[i]] gives its owner.\n   */\n  vector<int> learnable_param_ids_;\n  /// the index of mask parameters\n  vector<int> mask_param_ids_;   \n  /// the learning rate multipliers for learnable_params_\n  vector<float> params_lr_;\n  vector<bool> has_params_lr_;\n  /// the weight decay multipliers for learnable_params_\n  vector<float> params_weight_decay_;\n  vector<bool> has_params_decay_;\n  /// The bytes of memory used by this net\n  size_t memory_used_;\n  /// Whether to compute and display debug info for the net.\n  bool debug_info_;\n  /// The root net that actually holds the shared layers in data parallelism\n  const Net* const root_net_;\n  DISABLE_COPY_AND_ASSIGN(Net);\n};\n\n\n}  // namespace caffe\n\n#endif  // CAFFE_NET_HPP_\n"
  },
  {
    "path": "include/caffe/neuron_layers.hpp",
    "content": "#ifndef CAFFE_NEURON_LAYERS_HPP_\n#define CAFFE_NEURON_LAYERS_HPP_\n\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\n#define HDF5_DATA_DATASET_NAME \"data\"\n#define HDF5_DATA_LABEL_NAME \"label\"\n\nnamespace caffe {\n\n/**\n * @brief An interface for layers that take one blob as input (@f$ x @f$)\n *        and produce one equally-sized blob as output (@f$ y @f$), where\n *        each element of the output depends only on the corresponding input\n *        element.\n */\ntemplate <typename Dtype>\nclass NeuronLayer : public Layer<Dtype> {\n public:\n  explicit NeuronLayer(const LayerParameter& param)\n     : Layer<Dtype>(param) {}\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n};\n\n/**\n * @brief Computes @f$ y = |x| @f$\n *\n * @param bottom input Blob vector (length 1)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the inputs @f$ x @f$\n * @param top output Blob vector (length 1)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the computed outputs @f$ y = |x| @f$\n */\ntemplate <typename Dtype>\nclass AbsValLayer : public NeuronLayer<Dtype> {\n public:\n  explicit AbsValLayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"AbsVal\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  /// @copydoc AbsValLayer\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the absolute value inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to computed outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 2)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$; Backward fills their diff with\n   *      gradients @f$\n   *        \\frac{\\partial E}{\\partial x} =\n   *            \\mathrm{sign}(x) \\frac{\\partial E}{\\partial y}\n   *      @f$ if propagate_down[0]\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n};\n\n/**\n * @brief Computes @f$ y = x + \\log(1 + \\exp(-x)) @f$ if @f$ x > 0 @f$;\n *        @f$ y = \\log(1 + \\exp(x)) @f$ otherwise.\n *\n * @param bottom input Blob vector (length 1)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the inputs @f$ x @f$\n * @param top output Blob vector (length 1)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the computed outputs @f$\n *      y = \\left\\{\n *         \\begin{array}{ll}\n *            x + \\log(1 + \\exp(-x)) & \\mbox{if } x > 0 \\\\\n *            \\log(1 + \\exp(x)) & \\mbox{otherwise}\n *         \\end{array} \\right.\n *      @f$\n */\ntemplate <typename Dtype>\nclass BNLLLayer : public NeuronLayer<Dtype> {\n public:\n  explicit BNLLLayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n\n  virtual inline const char* type() const { return \"BNLL\"; }\n\n protected:\n  /// @copydoc BNLLLayer\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the BNLL inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to computed outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 2)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$; Backward fills their diff with\n   *      gradients @f$\n   *        \\frac{\\partial E}{\\partial x}\n   *      @f$ if propagate_down[0]\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n};\n\n/**\n * @brief During training only, sets a random portion of @f$x@f$ to 0, adjusting\n *        the rest of the vector magnitude accordingly.\n *\n * @param bottom input Blob vector (length 1)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the inputs @f$ x @f$\n * @param top output Blob vector (length 1)\n *   -# @f$ (N \\times C \\times H \\times W) @f$\n *      the computed outputs @f$ y = |x| @f$\n */\ntemplate <typename Dtype>\nclass DropoutLayer : public NeuronLayer<Dtype> {\n public:\n  /**\n   * @param param provides DropoutParameter dropout_param,\n   *     with DropoutLayer options:\n   *   - dropout_ratio (\\b optional, default 0.5).\n   *     Sets the probability @f$ p @f$ that any given unit is dropped.\n   */\n  explicit DropoutLayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Dropout\"; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the computed outputs. At training time, we have @f$\n   *      y_{\\mbox{train}} = \\left\\{\n   *         \\begin{array}{ll}\n   *            \\frac{x}{1 - p} & \\mbox{if } u > p \\\\\n   *            0 & \\mbox{otherwise}\n   *         \\end{array} \\right.\n   *      @f$, where @f$ u \\sim U(0, 1)@f$ is generated independently for each\n   *      input at each iteration. At test time, we simply have\n   *      @f$ y_{\\mbox{test}} = \\mathbb{E}[y_{\\mbox{train}}] = x @f$.\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  /// when divided by UINT_MAX, the randomly generated values @f$u\\sim U(0,1)@f$\n  Blob<unsigned int> rand_vec_;\n  /// the probability @f$ p @f$ of dropping any input\n  Dtype threshold_;\n  /// the scale for undropped inputs at train time @f$ 1 / (1 - p) @f$\n  Dtype scale_;\n  unsigned int uint_thres_;\n};\n\n/**\n * @brief Computes @f$ y = \\gamma ^ {\\alpha x + \\beta} @f$,\n *        as specified by the scale @f$ \\alpha @f$, shift @f$ \\beta @f$,\n *        and base @f$ \\gamma @f$.\n */\ntemplate <typename Dtype>\nclass ExpLayer : public NeuronLayer<Dtype> {\n public:\n  /**\n   * @param param provides ExpParameter exp_param,\n   *     with ExpLayer options:\n   *   - scale (\\b optional, default 1) the scale @f$ \\alpha @f$\n   *   - shift (\\b optional, default 0) the shift @f$ \\beta @f$\n   *   - base (\\b optional, default -1 for a value of @f$ e \\approx 2.718 @f$)\n   *         the base @f$ \\gamma @f$\n   */\n  explicit ExpLayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Exp\"; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the computed outputs @f$\n   *        y = \\gamma ^ {\\alpha x + \\beta}\n   *      @f$\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the exp inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to computed outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$; Backward fills their diff with\n   *      gradients @f$\n   *        \\frac{\\partial E}{\\partial x} =\n   *            \\frac{\\partial E}{\\partial y} y \\alpha \\log_e(gamma)\n   *      @f$ if propagate_down[0]\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  Dtype inner_scale_, outer_scale_;\n};\n\n/**\n * @brief Computes @f$ y = log_{\\gamma}(\\alpha x + \\beta) @f$,\n *        as specified by the scale @f$ \\alpha @f$, shift @f$ \\beta @f$,\n *        and base @f$ \\gamma @f$.\n */\ntemplate <typename Dtype>\nclass LogLayer : public NeuronLayer<Dtype> {\n public:\n  /**\n   * @param param provides LogParameter log_param,\n   *     with LogLayer options:\n   *   - scale (\\b optional, default 1) the scale @f$ \\alpha @f$\n   *   - shift (\\b optional, default 0) the shift @f$ \\beta @f$\n   *   - base (\\b optional, default -1 for a value of @f$ e \\approx 2.718 @f$)\n   *         the base @f$ \\gamma @f$\n   */\n  explicit LogLayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Log\"; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the computed outputs @f$\n   *        y = log_{\\gamma}(\\alpha x + \\beta)\n   *      @f$\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the exp inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to computed outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$; Backward fills their diff with\n   *      gradients @f$\n   *        \\frac{\\partial E}{\\partial x} =\n   *            \\frac{\\partial E}{\\partial y} y \\alpha \\log_e(gamma)\n   *      @f$ if propagate_down[0]\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  Dtype base_scale_;\n  Dtype input_scale_, input_shift_;\n  Dtype backward_num_scale_;\n};\n\n/**\n * @brief Computes @f$ y = (\\alpha x + \\beta) ^ \\gamma @f$,\n *        as specified by the scale @f$ \\alpha @f$, shift @f$ \\beta @f$,\n *        and power @f$ \\gamma @f$.\n */\ntemplate <typename Dtype>\nclass PowerLayer : public NeuronLayer<Dtype> {\n public:\n  /**\n   * @param param provides PowerParameter power_param,\n   *     with PowerLayer options:\n   *   - scale (\\b optional, default 1) the scale @f$ \\alpha @f$\n   *   - shift (\\b optional, default 0) the shift @f$ \\beta @f$\n   *   - power (\\b optional, default 1) the power @f$ \\gamma @f$\n   */\n  explicit PowerLayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Power\"; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the computed outputs @f$\n   *        y = (\\alpha x + \\beta) ^ \\gamma\n   *      @f$\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the power inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to computed outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$; Backward fills their diff with\n   *      gradients @f$\n   *        \\frac{\\partial E}{\\partial x} =\n   *            \\frac{\\partial E}{\\partial y}\n   *            \\alpha \\gamma (\\alpha x + \\beta) ^ {\\gamma - 1} =\n   *            \\frac{\\partial E}{\\partial y}\n   *            \\frac{\\alpha \\gamma y}{\\alpha x + \\beta}\n   *      @f$ if propagate_down[0]\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  /// @brief @f$ \\gamma @f$ from layer_param_.power_param()\n  Dtype power_;\n  /// @brief @f$ \\alpha @f$ from layer_param_.power_param()\n  Dtype scale_;\n  /// @brief @f$ \\beta @f$ from layer_param_.power_param()\n  Dtype shift_;\n  /// @brief Result of @f$ \\alpha \\gamma @f$\n  Dtype diff_scale_;\n};\n\n/**\n * @brief Rectified Linear Unit non-linearity @f$ y = \\max(0, x) @f$.\n *        The simple max is fast to compute, and the function does not saturate.\n */\ntemplate <typename Dtype>\nclass ReLULayer : public NeuronLayer<Dtype> {\n public:\n  /**\n   * @param param provides ReLUParameter relu_param,\n   *     with ReLULayer options:\n   *   - negative_slope (\\b optional, default 0).\n   *     the value @f$ \\nu @f$ by which negative values are multiplied.\n   */\n  explicit ReLULayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n\n  virtual inline const char* type() const { return \"ReLU\"; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the computed outputs @f$\n   *        y = \\max(0, x)\n   *      @f$ by default.  If a non-zero negative_slope @f$ \\nu @f$ is provided,\n   *      the computed outputs are @f$ y = \\max(0, x) + \\nu \\min(0, x) @f$.\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the ReLU inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to computed outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$; Backward fills their diff with\n   *      gradients @f$\n   *        \\frac{\\partial E}{\\partial x} = \\left\\{\n   *        \\begin{array}{lr}\n   *            0 & \\mathrm{if} \\; x \\le 0 \\\\\n   *            \\frac{\\partial E}{\\partial y} & \\mathrm{if} \\; x > 0\n   *        \\end{array} \\right.\n   *      @f$ if propagate_down[0], by default.\n   *      If a non-zero negative_slope @f$ \\nu @f$ is provided,\n   *      the computed gradients are @f$\n   *        \\frac{\\partial E}{\\partial x} = \\left\\{\n   *        \\begin{array}{lr}\n   *            \\nu \\frac{\\partial E}{\\partial y} & \\mathrm{if} \\; x \\le 0 \\\\\n   *            \\frac{\\partial E}{\\partial y} & \\mathrm{if} \\; x > 0\n   *        \\end{array} \\right.\n   *      @f$.\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n};\n\n#ifdef USE_CUDNN\n/**\n * @brief CuDNN acceleration of ReLULayer.\n */\ntemplate <typename Dtype>\nclass CuDNNReLULayer : public ReLULayer<Dtype> {\n public:\n  explicit CuDNNReLULayer(const LayerParameter& param)\n      : ReLULayer<Dtype>(param), handles_setup_(false) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual ~CuDNNReLULayer();\n\n protected:\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  bool handles_setup_;\n  cudnnHandle_t             handle_;\n  cudnnTensorDescriptor_t bottom_desc_;\n  cudnnTensorDescriptor_t top_desc_;\n};\n#endif\n\n/**\n * @brief Sigmoid function non-linearity @f$\n *         y = (1 + \\exp(-x))^{-1}\n *     @f$, a classic choice in neural networks.\n *\n * Note that the gradient vanishes as the values move away from 0.\n * The ReLULayer is often a better choice for this reason.\n */\ntemplate <typename Dtype>\nclass SigmoidLayer : public NeuronLayer<Dtype> {\n public:\n  explicit SigmoidLayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n\n  virtual inline const char* type() const { return \"Sigmoid\"; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the computed outputs @f$\n   *        y = (1 + \\exp(-x))^{-1}\n   *      @f$\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the sigmoid inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to computed outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$; Backward fills their diff with\n   *      gradients @f$\n   *        \\frac{\\partial E}{\\partial x}\n   *            = \\frac{\\partial E}{\\partial y} y (1 - y)\n   *      @f$ if propagate_down[0]\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n};\n\n#ifdef USE_CUDNN\n/**\n * @brief CuDNN acceleration of SigmoidLayer.\n */\ntemplate <typename Dtype>\nclass CuDNNSigmoidLayer : public SigmoidLayer<Dtype> {\n public:\n  explicit CuDNNSigmoidLayer(const LayerParameter& param)\n      : SigmoidLayer<Dtype>(param), handles_setup_(false) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual ~CuDNNSigmoidLayer();\n\n protected:\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  bool handles_setup_;\n  cudnnHandle_t             handle_;\n  cudnnTensorDescriptor_t bottom_desc_;\n  cudnnTensorDescriptor_t top_desc_;\n};\n#endif\n\n/**\n * @brief TanH hyperbolic tangent non-linearity @f$\n *         y = \\frac{\\exp(2x) - 1}{\\exp(2x) + 1}\n *     @f$, popular in auto-encoders.\n *\n * Note that the gradient vanishes as the values move away from 0.\n * The ReLULayer is often a better choice for this reason.\n */\ntemplate <typename Dtype>\nclass TanHLayer : public NeuronLayer<Dtype> {\n public:\n  explicit TanHLayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n\n  virtual inline const char* type() const { return \"TanH\"; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the computed outputs @f$\n   *        y = \\frac{\\exp(2x) - 1}{\\exp(2x) + 1}\n   *      @f$\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the sigmoid inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to computed outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$; Backward fills their diff with\n   *      gradients @f$\n   *        \\frac{\\partial E}{\\partial x}\n   *            = \\frac{\\partial E}{\\partial y}\n   *              \\left(1 - \\left[\\frac{\\exp(2x) - 1}{exp(2x) + 1} \\right]^2 \\right)\n   *            = \\frac{\\partial E}{\\partial y} (1 - y^2)\n   *      @f$ if propagate_down[0]\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n};\n\n#ifdef USE_CUDNN\n/**\n * @brief CuDNN acceleration of TanHLayer.\n */\ntemplate <typename Dtype>\nclass CuDNNTanHLayer : public TanHLayer<Dtype> {\n public:\n  explicit CuDNNTanHLayer(const LayerParameter& param)\n      : TanHLayer<Dtype>(param), handles_setup_(false) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual ~CuDNNTanHLayer();\n\n protected:\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  bool handles_setup_;\n  cudnnHandle_t             handle_;\n  cudnnTensorDescriptor_t bottom_desc_;\n  cudnnTensorDescriptor_t top_desc_;\n};\n#endif\n\n/**\n * @brief Tests whether the input exceeds a threshold: outputs 1 for inputs\n *        above threshold; 0 otherwise.\n */\ntemplate <typename Dtype>\nclass ThresholdLayer : public NeuronLayer<Dtype> {\n public:\n  /**\n   * @param param provides ThresholdParameter threshold_param,\n   *     with ThresholdLayer options:\n   *   - threshold (\\b optional, default 0).\n   *     the threshold value @f$ t @f$ to which the input values are compared.\n   */\n  explicit ThresholdLayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Threshold\"; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times H \\times W) @f$\n   *      the computed outputs @f$\n   *       y = \\left\\{\n   *       \\begin{array}{lr}\n   *         0 & \\mathrm{if} \\; x \\le t \\\\\n   *         1 & \\mathrm{if} \\; x > t\n   *       \\end{array} \\right.\n   *      @f$\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  /// @brief Not implemented (non-differentiable function)\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n    NOT_IMPLEMENTED;\n  }\n\n  Dtype threshold_;\n};\n\n/**\n * @brief Parameterized Rectified Linear Unit non-linearity @f$\n *        y_i = \\max(0, x_i) + a_i \\min(0, x_i)\n *        @f$. The differences from ReLULayer are 1) negative slopes are\n *        learnable though backprop and 2) negative slopes can vary across\n *        channels. The number of axes of input blob should be greater than or\n *        equal to 2. The 1st axis (0-based) is seen as channels.\n */\ntemplate <typename Dtype>\nclass PReLULayer : public NeuronLayer<Dtype> {\n public:\n  /**\n   * @param param provides PReLUParameter prelu_param,\n   *     with PReLULayer options:\n   *   - filler (\\b optional, FillerParameter,\n   *     default {'type': constant 'value':0.25}).\n   *   - channel_shared (\\b optional, default false).\n   *     negative slopes are shared across channels.\n   */\n  explicit PReLULayer(const LayerParameter& param)\n      : NeuronLayer<Dtype>(param) {}\n\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"PReLU\"; }\n\n protected:\n  /**\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times ...) @f$\n   *      the inputs @f$ x @f$\n   * @param top output Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times ...) @f$\n   *      the computed outputs for each channel @f$i@f$ @f$\n   *        y_i = \\max(0, x_i) + a_i \\min(0, x_i)\n   *      @f$.\n   */\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  /**\n   * @brief Computes the error gradient w.r.t. the PReLU inputs.\n   *\n   * @param top output Blob vector (length 1), providing the error gradient with\n   *      respect to the outputs\n   *   -# @f$ (N \\times C \\times ...) @f$\n   *      containing error gradients @f$ \\frac{\\partial E}{\\partial y} @f$\n   *      with respect to computed outputs @f$ y @f$\n   * @param propagate_down see Layer::Backward.\n   * @param bottom input Blob vector (length 1)\n   *   -# @f$ (N \\times C \\times ...) @f$\n   *      the inputs @f$ x @f$; For each channel @f$i@f$, backward fills their\n   *      diff with gradients @f$\n   *        \\frac{\\partial E}{\\partial x_i} = \\left\\{\n   *        \\begin{array}{lr}\n   *            a_i \\frac{\\partial E}{\\partial y_i} & \\mathrm{if} \\; x_i \\le 0 \\\\\n   *            \\frac{\\partial E}{\\partial y_i} & \\mathrm{if} \\; x_i > 0\n   *        \\end{array} \\right.\n   *      @f$.\n   *      If param_propagate_down_[0] is true, it fills the diff with gradients\n   *      @f$\n   *        \\frac{\\partial E}{\\partial a_i} = \\left\\{\n   *        \\begin{array}{lr}\n   *            \\sum_{x_i} x_i \\frac{\\partial E}{\\partial y_i} & \\mathrm{if} \\; x_i \\le 0 \\\\\n   *            0 & \\mathrm{if} \\; x_i > 0\n   *        \\end{array} \\right.\n   *      @f$.\n   */\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  bool channel_shared_;\n  Blob<Dtype> multiplier_;  // dot multiplier for backward computation of params\n  Blob<Dtype> backward_buff_;  // temporary buffer for backward computation\n  Blob<Dtype> bottom_memory_;  // memory for in-place computation\n};\n\n}  // namespace caffe\n\n#endif  // CAFFE_NEURON_LAYERS_HPP_\n"
  },
  {
    "path": "include/caffe/parallel.hpp",
    "content": "#ifndef CAFFE_PARALLEL_HPP_\n#define CAFFE_PARALLEL_HPP_\n\n#include <boost/date_time/posix_time/posix_time.hpp>\n\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/internal_thread.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/solver.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/blocking_queue.hpp\"\n\nnamespace caffe {\n\n// Represents a net parameters. Once a net is created, its parameter buffers can\n// be replaced by ones from Params, to allow parallelization. Params ensures\n// parameters are allocated in one consecutive array.\ntemplate<typename Dtype>\nclass Params {\n public:\n  explicit Params(shared_ptr<Solver<Dtype> > root_solver);\n  virtual ~Params() {\n  }\n\n  inline size_t size() const {\n    return size_;\n  }\n  inline Dtype* data() const {\n    return data_;\n  }\n  inline Dtype* diff() const {\n    return diff_;\n  }\n\n protected:\n  const size_t size_;           // Size of buffers\n  Dtype* data_;                 // Network parameters\n  Dtype* diff_;                 // Gradient\n\nDISABLE_COPY_AND_ASSIGN(Params);\n};\n\n// Params stored in GPU memory.\ntemplate<typename Dtype>\nclass GPUParams : public Params<Dtype> {\n public:\n  GPUParams(shared_ptr<Solver<Dtype> > root_solver, int device);\n  virtual ~GPUParams();\n\n  void configure(Solver<Dtype>* solver) const;\n\n protected:\n  using Params<Dtype>::size_;\n  using Params<Dtype>::data_;\n  using Params<Dtype>::diff_;\n};\n\nclass DevicePair {\n public:\n  DevicePair(int parent, int device)\n      : parent_(parent),\n        device_(device) {\n  }\n  inline int parent() {\n    return parent_;\n  }\n  inline int device() {\n    return device_;\n  }\n\n  // Group GPUs in pairs, by proximity depending on machine's topology\n  static void compute(const vector<int> devices, vector<DevicePair>* pairs);\n\n protected:\n  int parent_;\n  int device_;\n};\n\n// Synchronous data parallelism using map-reduce between local GPUs.\ntemplate<typename Dtype>\nclass P2PSync : public GPUParams<Dtype>, public Solver<Dtype>::Callback,\n    public InternalThread {\n public:\n  explicit P2PSync(shared_ptr<Solver<Dtype> > root_solver,\n                   P2PSync<Dtype>* parent, const SolverParameter& param);\n  virtual ~P2PSync();\n\n  inline const shared_ptr<Solver<Dtype> >& solver() const {\n    return solver_;\n  }\n\n  void run(const vector<int>& gpus);\n\n protected:\n  void on_start();\n  void on_gradients_ready();\n\n  void InternalThreadEntry();\n\n  P2PSync<Dtype>* parent_;\n  vector<P2PSync<Dtype>*> children_;\n  BlockingQueue<P2PSync<Dtype>*> queue_;\n  const int initial_iter_;\n  Dtype* parent_grads_;\n  shared_ptr<Solver<Dtype> > solver_;\n\n  using Params<Dtype>::size_;\n  using Params<Dtype>::data_;\n  using Params<Dtype>::diff_;\n};\n\n}  // namespace caffe\n\n#endif\n"
  },
  {
    "path": "include/caffe/python_layer.hpp",
    "content": "#ifndef CAFFE_PYTHON_LAYER_HPP_\n#define CAFFE_PYTHON_LAYER_HPP_\n\n#include <boost/python.hpp>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n\nnamespace bp = boost::python;\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nclass PythonLayer : public Layer<Dtype> {\n public:\n  PythonLayer(PyObject* self, const LayerParameter& param)\n      : Layer<Dtype>(param), self_(bp::handle<>(bp::borrowed(self))) { }\n\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n    self_.attr(\"param_str\") = bp::str(\n        this->layer_param_.python_param().param_str());\n    self_.attr(\"setup\")(bottom, top);\n  }\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n    self_.attr(\"reshape\")(bottom, top);\n  }\n\n  virtual inline bool ShareInParallel() const {\n    return this->layer_param_.python_param().share_in_parallel();\n  }\n\n  virtual inline const char* type() const { return \"Python\"; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n    self_.attr(\"forward\")(bottom, top);\n  }\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n    self_.attr(\"backward\")(top, propagate_down, bottom);\n  }\n\n private:\n  bp::object self_;\n};\n\n}  // namespace caffe\n\n#endif\n"
  },
  {
    "path": "include/caffe/solver.hpp",
    "content": "#ifndef CAFFE_OPTIMIZATION_SOLVER_HPP_\n#define CAFFE_OPTIMIZATION_SOLVER_HPP_\n\n#include <string>\n#include <vector>\n\n#include \"caffe/net.hpp\"\n\nnamespace caffe {\n\n/**\n * @brief An interface for classes that perform optimization on Net%s.\n *\n * Requires implementation of ApplyUpdate to compute a parameter update\n * given the current state of the Net parameters.\n */\ntemplate <typename Dtype>\nclass Solver {\n public:\n  explicit Solver(const SolverParameter& param,\n      const Solver* root_solver = NULL);\n  explicit Solver(const string& param_file, const Solver* root_solver = NULL);\n  void Init(const SolverParameter& param);\n  void InitTrainNet();\n  void InitTestNets();\n  // The main entry of the solver function. In default, iter will be zero. Pass\n  // in a non-zero iter number to resume training for a pre-trained net.\n  virtual void Solve(const char* resume_file = NULL);\n  inline void Solve(const string resume_file) { Solve(resume_file.c_str()); }\n  void Step(int iters);\n  // The Restore method simply dispatches to one of the\n  // RestoreSolverStateFrom___ protected methods. You should implement these\n  // methods to restore the state from the appropriate snapshot type.\n  void Restore(const char* resume_file);\n  virtual ~Solver() {}\n  inline const SolverParameter& param() const { return param_; }\n  inline shared_ptr<Net<Dtype> > net() { return net_; }\n  inline const vector<shared_ptr<Net<Dtype> > >& test_nets() {\n    return test_nets_;\n  }\n  int iter() { return iter_; }\n\n  // Invoked at specific points during an iteration\n  class Callback {\n   protected:\n    virtual void on_start() = 0;\n    virtual void on_gradients_ready() = 0;\n\n    template <typename T>\n    friend class Solver;\n  };\n  const vector<Callback*>& callbacks() const { return callbacks_; }\n  void add_callback(Callback* value) {\n    callbacks_.push_back(value);\n  }\n\n protected:\n  // Make and apply the update value for the current iteration.\n  virtual void ApplyUpdate() = 0;\n  // The Solver::Snapshot function implements the basic snapshotting utility\n  // that stores the learned net. You should implement the SnapshotSolverState()\n  // function that produces a SolverState protocol buffer that needs to be\n  // written to disk together with the learned net.\n  void Snapshot();\n  string SnapshotFilename(const string extension);\n  string SnapshotToBinaryProto();\n  string SnapshotToHDF5();\n  // The test routine\n  void TestAll();\n  void Test(const int test_net_id = 0);\n  virtual void SnapshotSolverState(const string& model_filename) = 0;\n  virtual void RestoreSolverStateFromHDF5(const string& state_file) = 0;\n  virtual void RestoreSolverStateFromBinaryProto(const string& state_file) = 0;\n  void DisplayOutputBlobs(const int net_id);\n\n  SolverParameter param_;\n  int iter_;\n  int current_step_;\n  shared_ptr<Net<Dtype> > net_;\n  vector<shared_ptr<Net<Dtype> > > test_nets_;\n  vector<Callback*> callbacks_;\n\n  // The root solver that holds root nets (actually containing shared layers)\n  // in data parallelism\n  const Solver* const root_solver_;\n\n  DISABLE_COPY_AND_ASSIGN(Solver);\n};\n\n/**\n * @brief Solver that only computes gradients, used as worker\n *        for multi-GPU training.\n */\ntemplate <typename Dtype>\nclass WorkerSolver : public Solver<Dtype> {\n public:\n  explicit WorkerSolver(const SolverParameter& param,\n      const Solver<Dtype>* root_solver = NULL)\n      : Solver<Dtype>(param, root_solver) {}\n\n protected:\n  void ApplyUpdate() {}\n  void SnapshotSolverState(const string& model_filename) {\n    LOG(FATAL) << \"Should not be called on worker solver.\";\n  }\n  void RestoreSolverStateFromBinaryProto(const string& state_file) {\n    LOG(FATAL) << \"Should not be called on worker solver.\";\n  }\n  void RestoreSolverStateFromHDF5(const string& state_file) {\n    LOG(FATAL) << \"Should not be called on worker solver.\";\n  }\n};\n\n/**\n * @brief Optimizes the parameters of a Net using\n *        stochastic gradient descent (SGD) with momentum.\n */\ntemplate <typename Dtype>\nclass SGDSolver : public Solver<Dtype> {\n public:\n  explicit SGDSolver(const SolverParameter& param)\n      : Solver<Dtype>(param) { PreSolve(); }\n  explicit SGDSolver(const string& param_file)\n      : Solver<Dtype>(param_file) { PreSolve(); }\n\n  const vector<shared_ptr<Blob<Dtype> > >& history() { return history_; }\n\n protected:\n  void PreSolve();\n  Dtype GetLearningRate();\n  virtual void ApplyUpdate();\n  virtual void Normalize(int param_id);\n  virtual void Regularize(int param_id);\n  virtual void ComputeUpdateValue(int param_id, Dtype rate);\n  virtual void ClipGradients();\n  virtual void SnapshotSolverState(const string& model_filename);\n  virtual void SnapshotSolverStateToBinaryProto(const string& model_filename);\n  virtual void SnapshotSolverStateToHDF5(const string& model_filename);\n  virtual void RestoreSolverStateFromHDF5(const string& state_file);\n  virtual void RestoreSolverStateFromBinaryProto(const string& state_file);\n  // history maintains the historical momentum data.\n  // update maintains update related data and is not needed in snapshots.\n  // temp maintains other information that might be needed in computation\n  //   of gradients/updates and is not needed in snapshots\n  vector<shared_ptr<Blob<Dtype> > > history_, update_, temp_;\n\n  DISABLE_COPY_AND_ASSIGN(SGDSolver);\n};\n\ntemplate <typename Dtype>\nclass NesterovSolver : public SGDSolver<Dtype> {\n public:\n  explicit NesterovSolver(const SolverParameter& param)\n      : SGDSolver<Dtype>(param) {}\n  explicit NesterovSolver(const string& param_file)\n      : SGDSolver<Dtype>(param_file) {}\n\n protected:\n  virtual void ComputeUpdateValue(int param_id, Dtype rate);\n\n  DISABLE_COPY_AND_ASSIGN(NesterovSolver);\n};\n\ntemplate <typename Dtype>\nclass AdaGradSolver : public SGDSolver<Dtype> {\n public:\n  explicit AdaGradSolver(const SolverParameter& param)\n      : SGDSolver<Dtype>(param) { constructor_sanity_check(); }\n  explicit AdaGradSolver(const string& param_file)\n      : SGDSolver<Dtype>(param_file) { constructor_sanity_check(); }\n\n protected:\n  virtual void ComputeUpdateValue(int param_id, Dtype rate);\n  void constructor_sanity_check() {\n    CHECK_EQ(0, this->param_.momentum())\n        << \"Momentum cannot be used with AdaGrad.\";\n  }\n\n  DISABLE_COPY_AND_ASSIGN(AdaGradSolver);\n};\n\n\ntemplate <typename Dtype>\nclass RMSPropSolver : public SGDSolver<Dtype> {\n public:\n  explicit RMSPropSolver(const SolverParameter& param)\n      : SGDSolver<Dtype>(param) { constructor_sanity_check(); }\n  explicit RMSPropSolver(const string& param_file)\n      : SGDSolver<Dtype>(param_file) { constructor_sanity_check(); }\n\n protected:\n  virtual void ComputeUpdateValue(int param_id, Dtype rate);\n  void constructor_sanity_check() {\n    CHECK_EQ(0, this->param_.momentum())\n        << \"Momentum cannot be used with RMSProp.\";\n    CHECK_GE(this->param_.rms_decay(), 0)\n        << \"rms_decay should lie between 0 and 1.\";\n    CHECK_LT(this->param_.rms_decay(), 1)\n        << \"rms_decay should lie between 0 and 1.\";\n  }\n\n  DISABLE_COPY_AND_ASSIGN(RMSPropSolver);\n};\n\ntemplate <typename Dtype>\nclass AdaDeltaSolver : public SGDSolver<Dtype> {\n public:\n  explicit AdaDeltaSolver(const SolverParameter& param)\n      : SGDSolver<Dtype>(param) { AdaDeltaPreSolve(); }\n  explicit AdaDeltaSolver(const string& param_file)\n      : SGDSolver<Dtype>(param_file) { AdaDeltaPreSolve(); }\n\n protected:\n  void AdaDeltaPreSolve();\n  virtual void ComputeUpdateValue(int param_id, Dtype rate);\n\n  DISABLE_COPY_AND_ASSIGN(AdaDeltaSolver);\n};\n\n/**\n * @brief AdamSolver, an algorithm for first-order gradient-based optimization\n *        of stochastic objective functions, based on adaptive estimates of\n *        lower-order moments. Described in [1].\n *\n * [1] D. P. Kingma and J. L. Ba, \"ADAM: A Method for Stochastic Optimization.\"\n *     arXiv preprint arXiv:1412.6980v8 (2014).\n */\ntemplate <typename Dtype>\nclass AdamSolver : public SGDSolver<Dtype> {\n public:\n  explicit AdamSolver(const SolverParameter& param)\n      : SGDSolver<Dtype>(param) { AdamPreSolve();}\n  explicit AdamSolver(const string& param_file)\n      : SGDSolver<Dtype>(param_file) { AdamPreSolve(); }\n\n protected:\n  void AdamPreSolve();\n  virtual void ComputeUpdateValue(int param_id, Dtype rate);\n\n  DISABLE_COPY_AND_ASSIGN(AdamSolver);\n};\n\ntemplate <typename Dtype>\nSolver<Dtype>* GetSolver(const SolverParameter& param) {\n  SolverParameter_SolverType type = param.solver_type();\n\n  switch (type) {\n  case SolverParameter_SolverType_SGD:\n      return new SGDSolver<Dtype>(param);\n  case SolverParameter_SolverType_NESTEROV:\n      return new NesterovSolver<Dtype>(param);\n  case SolverParameter_SolverType_ADAGRAD:\n      return new AdaGradSolver<Dtype>(param);\n  case SolverParameter_SolverType_RMSPROP:\n      return new RMSPropSolver<Dtype>(param);\n  case SolverParameter_SolverType_ADADELTA:\n      return new AdaDeltaSolver<Dtype>(param);\n  case SolverParameter_SolverType_ADAM:\n      return new AdamSolver<Dtype>(param);\n  default:\n      LOG(FATAL) << \"Unknown SolverType: \" << type;\n  }\n  return (Solver<Dtype>*) NULL;\n}\n\n}  // namespace caffe\n\n#endif  // CAFFE_OPTIMIZATION_SOLVER_HPP_\n"
  },
  {
    "path": "include/caffe/syncedmem.hpp",
    "content": "#ifndef CAFFE_SYNCEDMEM_HPP_\n#define CAFFE_SYNCEDMEM_HPP_\n\n#include <cstdlib>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\n// If CUDA is available and in GPU mode, host memory will be allocated pinned,\n// using cudaMallocHost. It avoids dynamic pinning for transfers (DMA).\n// The improvement in performance seems negligible in the single GPU case,\n// but might be more significant for parallel training. Most importantly,\n// it improved stability for large models on many GPUs.\ninline void CaffeMallocHost(void** ptr, size_t size) {\n#ifndef CPU_ONLY\n  if (Caffe::mode() == Caffe::GPU) {\n    CUDA_CHECK(cudaMallocHost(ptr, size));\n    return;\n  }\n#endif\n  *ptr = malloc(size);\n  CHECK(*ptr) << \"host allocation of size \" << size << \" failed\";\n}\n\ninline void CaffeFreeHost(void* ptr) {\n#ifndef CPU_ONLY\n  if (Caffe::mode() == Caffe::GPU) {\n    CUDA_CHECK(cudaFreeHost(ptr));\n    return;\n  }\n#endif\n  free(ptr);\n}\n\n\n/**\n * @brief Manages memory allocation and synchronization between the host (CPU)\n *        and device (GPU).\n *\n * TODO(dox): more thorough description.\n */\nclass SyncedMemory {\n public:\n  SyncedMemory()\n      : cpu_ptr_(NULL), gpu_ptr_(NULL), size_(0), head_(UNINITIALIZED),\n        own_cpu_data_(false), own_gpu_data_(false), gpu_device_(-1) {}\n  explicit SyncedMemory(size_t size)\n      : cpu_ptr_(NULL), gpu_ptr_(NULL), size_(size), head_(UNINITIALIZED),\n        own_cpu_data_(false), own_gpu_data_(false), gpu_device_(-1) {}\n  ~SyncedMemory();\n  const void* cpu_data();\n  void set_cpu_data(void* data);\n  const void* gpu_data();\n  void set_gpu_data(void* data);\n  void* mutable_cpu_data();\n  void* mutable_gpu_data();\n  enum SyncedHead { UNINITIALIZED, HEAD_AT_CPU, HEAD_AT_GPU, SYNCED };\n  SyncedHead head() { return head_; }\n  size_t size() { return size_; }\n\n#ifndef CPU_ONLY\n  void async_gpu_push(const cudaStream_t& stream);\n#endif\n\n private:\n  void to_cpu();\n  void to_gpu();\n  void* cpu_ptr_;\n  void* gpu_ptr_;\n  size_t size_;\n  SyncedHead head_;\n  bool own_cpu_data_;\n  bool own_gpu_data_;\n  int gpu_device_;\n\n  DISABLE_COPY_AND_ASSIGN(SyncedMemory);\n};  // class SyncedMemory\n\n}  // namespace caffe\n\n#endif  // CAFFE_SYNCEDMEM_HPP_\n"
  },
  {
    "path": "include/caffe/test/test_caffe_main.hpp",
    "content": "// The main caffe test code. Your test cpp code should include this hpp\n// to allow a main function to be compiled into the binary.\n#ifndef CAFFE_TEST_TEST_CAFFE_MAIN_HPP_\n#define CAFFE_TEST_TEST_CAFFE_MAIN_HPP_\n\n#include <glog/logging.h>\n#include <gtest/gtest.h>\n\n#include <cstdio>\n#include <cstdlib>\n\n#include \"caffe/common.hpp\"\n\nusing std::cout;\nusing std::endl;\n\n#ifdef CMAKE_BUILD\n  #include \"caffe_config.h\"\n#else\n  #define CUDA_TEST_DEVICE -1\n  #define CMAKE_SOURCE_DIR \"src/\"\n  #define EXAMPLES_SOURCE_DIR \"examples/\"\n  #define CMAKE_EXT \"\"\n#endif\n\nint main(int argc, char** argv);\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass MultiDeviceTest : public ::testing::Test {\n public:\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  MultiDeviceTest() {\n    Caffe::set_mode(TypeParam::device);\n  }\n  virtual ~MultiDeviceTest() {}\n};\n\ntypedef ::testing::Types<float, double> TestDtypes;\n\ntemplate <typename TypeParam>\nstruct CPUDevice {\n  typedef TypeParam Dtype;\n  static const Caffe::Brew device = Caffe::CPU;\n};\n\ntemplate <typename Dtype>\nclass CPUDeviceTest : public MultiDeviceTest<CPUDevice<Dtype> > {\n};\n\n#ifdef CPU_ONLY\n\ntypedef ::testing::Types<CPUDevice<float>,\n                         CPUDevice<double> > TestDtypesAndDevices;\n\n#else\n\ntemplate <typename TypeParam>\nstruct GPUDevice {\n  typedef TypeParam Dtype;\n  static const Caffe::Brew device = Caffe::GPU;\n};\n\ntemplate <typename Dtype>\nclass GPUDeviceTest : public MultiDeviceTest<GPUDevice<Dtype> > {\n};\n\ntypedef ::testing::Types<CPUDevice<float>, CPUDevice<double>,\n                         GPUDevice<float>, GPUDevice<double> >\n                         TestDtypesAndDevices;\n\n#endif\n\n}  // namespace caffe\n\n#endif  // CAFFE_TEST_TEST_CAFFE_MAIN_HPP_\n"
  },
  {
    "path": "include/caffe/test/test_gradient_check_util.hpp",
    "content": "#ifndef CAFFE_TEST_GRADIENT_CHECK_UTIL_H_\n#define CAFFE_TEST_GRADIENT_CHECK_UTIL_H_\n\n#include <glog/logging.h>\n#include <gtest/gtest.h>\n\n#include <algorithm>\n#include <cmath>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/net.hpp\"\n\nnamespace caffe {\n\n// The gradient checker adds a L2 normalization loss function on top of the\n// top blobs, and checks the gradient.\ntemplate <typename Dtype>\nclass GradientChecker {\n public:\n  // kink and kink_range specify an ignored nonsmooth region of the form\n  // kink - kink_range <= |feature value| <= kink + kink_range,\n  // which accounts for all nonsmoothness in use by caffe\n  GradientChecker(const Dtype stepsize, const Dtype threshold,\n      const unsigned int seed = 1701, const Dtype kink = 0.,\n      const Dtype kink_range = -1)\n      : stepsize_(stepsize), threshold_(threshold), seed_(seed),\n        kink_(kink), kink_range_(kink_range) {}\n  // Checks the gradient of a layer, with provided bottom layers and top\n  // layers.\n  // Note that after the gradient check, we do not guarantee that the data\n  // stored in the layer parameters and the blobs are unchanged.\n  void CheckGradient(Layer<Dtype>* layer, const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top, int check_bottom = -1) {\n      layer->SetUp(bottom, top);\n      CheckGradientSingle(layer, bottom, top, check_bottom, -1, -1);\n  }\n  void CheckGradientExhaustive(Layer<Dtype>* layer,\n      const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top,\n      int check_bottom = -1);\n\n  // CheckGradientEltwise can be used to test layers that perform element-wise\n  // computation only (e.g., neuron layers) -- where (d y_i) / (d x_j) = 0 when\n  // i != j.\n  void CheckGradientEltwise(Layer<Dtype>* layer,\n      const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top);\n\n  void CheckGradientSingle(Layer<Dtype>* layer,\n      const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top,\n      int check_bottom, int top_id, int top_data_id, bool element_wise = false);\n\n  // Checks the gradient of a network. This network should not have any data\n  // layers or loss layers, since the function does not explicitly deal with\n  // such cases yet. All input blobs and parameter blobs are going to be\n  // checked, layer-by-layer to avoid numerical problems to accumulate.\n  void CheckGradientNet(const Net<Dtype>& net,\n      const vector<Blob<Dtype>*>& input);\n\n protected:\n  Dtype GetObjAndGradient(const Layer<Dtype>& layer,\n      const vector<Blob<Dtype>*>& top, int top_id = -1, int top_data_id = -1);\n  Dtype stepsize_;\n  Dtype threshold_;\n  unsigned int seed_;\n  Dtype kink_;\n  Dtype kink_range_;\n};\n\n\ntemplate <typename Dtype>\nvoid GradientChecker<Dtype>::CheckGradientSingle(Layer<Dtype>* layer,\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top,\n    int check_bottom, int top_id, int top_data_id, bool element_wise) {\n  if (element_wise) {\n    CHECK_EQ(0, layer->blobs().size());\n    CHECK_LE(0, top_id);\n    CHECK_LE(0, top_data_id);\n    const int top_count = top[top_id]->count();\n    for (int blob_id = 0; blob_id < bottom.size(); ++blob_id) {\n      CHECK_EQ(top_count, bottom[blob_id]->count());\n    }\n  }\n  // First, figure out what blobs we need to check against, and zero init\n  // parameter blobs.\n  vector<Blob<Dtype>*> blobs_to_check;\n  vector<bool> propagate_down(bottom.size(), check_bottom < 0);\n  for (int i = 0; i < layer->blobs().size(); ++i) {\n    Blob<Dtype>* blob = layer->blobs()[i].get();\n    caffe_set(blob->count(), static_cast<Dtype>(0), blob->mutable_cpu_diff());\n    blobs_to_check.push_back(blob);\n  }\n  if (check_bottom < 0) {\n    for (int i = 0; i < bottom.size(); ++i) {\n      blobs_to_check.push_back(bottom[i]);\n    }\n  } else {\n    CHECK_LT(check_bottom, bottom.size());\n    blobs_to_check.push_back(bottom[check_bottom]);\n    propagate_down[check_bottom] = true;\n  }\n  // Compute the gradient analytically using Backward\n  Caffe::set_random_seed(seed_);\n  // Ignore the loss from the layer (it's just the weighted sum of the losses\n  // from the top blobs, whose gradients we may want to test individually).\n  layer->Forward(bottom, top);\n  // Get additional loss from the objective\n  GetObjAndGradient(*layer, top, top_id, top_data_id);\n  layer->Backward(top, propagate_down, bottom);\n  // Store computed gradients for all checked blobs\n  vector<shared_ptr<Blob<Dtype> > >\n      computed_gradient_blobs(blobs_to_check.size());\n  for (int blob_id = 0; blob_id < blobs_to_check.size(); ++blob_id) {\n    Blob<Dtype>* current_blob = blobs_to_check[blob_id];\n    computed_gradient_blobs[blob_id].reset(new Blob<Dtype>());\n    computed_gradient_blobs[blob_id]->ReshapeLike(*current_blob);\n    const int count = blobs_to_check[blob_id]->count();\n    const Dtype* diff = blobs_to_check[blob_id]->cpu_diff();\n    Dtype* computed_gradients =\n        computed_gradient_blobs[blob_id]->mutable_cpu_data();\n    caffe_copy(count, diff, computed_gradients);\n  }\n  // Compute derivative of top w.r.t. each bottom and parameter input using\n  // finite differencing.\n  // LOG(ERROR) << \"Checking \" << blobs_to_check.size() << \" blobs.\";\n  for (int blob_id = 0; blob_id < blobs_to_check.size(); ++blob_id) {\n    Blob<Dtype>* current_blob = blobs_to_check[blob_id];\n    const Dtype* computed_gradients =\n        computed_gradient_blobs[blob_id]->cpu_data();\n    // LOG(ERROR) << \"Blob \" << blob_id << \": checking \"\n    //     << current_blob->count() << \" parameters.\";\n    for (int feat_id = 0; feat_id < current_blob->count(); ++feat_id) {\n      // For an element-wise layer, we only need to do finite differencing to\n      // compute the derivative of top[top_id][top_data_id] w.r.t.\n      // bottom[blob_id][i] only for i == top_data_id.  For any other\n      // i != top_data_id, we know the derivative is 0 by definition, and simply\n      // check that that's true.\n      Dtype estimated_gradient = 0;\n      Dtype positive_objective = 0;\n      Dtype negative_objective = 0;\n      if (!element_wise || (feat_id == top_data_id)) {\n        // Do finite differencing.\n        // Compute loss with stepsize_ added to input.\n        current_blob->mutable_cpu_data()[feat_id] += stepsize_;\n        Caffe::set_random_seed(seed_);\n        layer->Forward(bottom, top);\n        positive_objective =\n            GetObjAndGradient(*layer, top, top_id, top_data_id);\n        // Compute loss with stepsize_ subtracted from input.\n        current_blob->mutable_cpu_data()[feat_id] -= stepsize_ * 2;\n        Caffe::set_random_seed(seed_);\n        layer->Forward(bottom, top);\n        negative_objective =\n            GetObjAndGradient(*layer, top, top_id, top_data_id);\n        // Recover original input value.\n        current_blob->mutable_cpu_data()[feat_id] += stepsize_;\n        estimated_gradient = (positive_objective - negative_objective) /\n            stepsize_ / 2.;\n      }\n      Dtype computed_gradient = computed_gradients[feat_id];\n      Dtype feature = current_blob->cpu_data()[feat_id];\n      // LOG(ERROR) << \"debug: \" << current_blob->cpu_data()[feat_id] << \" \"\n      //     << current_blob->cpu_diff()[feat_id];\n      if (kink_ - kink_range_ > fabs(feature)\n          || fabs(feature) > kink_ + kink_range_) {\n        // We check relative accuracy, but for too small values, we threshold\n        // the scale factor by 1.\n        Dtype scale = std::max(\n            std::max(fabs(computed_gradient), fabs(estimated_gradient)), 1.);\n        EXPECT_NEAR(computed_gradient, estimated_gradient, threshold_ * scale)\n          << \"debug: (top_id, top_data_id, blob_id, feat_id)=\"\n          << top_id << \",\" << top_data_id << \",\" << blob_id << \",\" << feat_id\n          << \"; feat = \" << feature\n          << \"; objective+ = \" << positive_objective\n          << \"; objective- = \" << negative_objective;\n      }\n      // LOG(ERROR) << \"Feature: \" << current_blob->cpu_data()[feat_id];\n      // LOG(ERROR) << \"computed gradient: \" << computed_gradient\n      //    << \" estimated_gradient: \" << estimated_gradient;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid GradientChecker<Dtype>::CheckGradientExhaustive(Layer<Dtype>* layer,\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top,\n    int check_bottom) {\n  layer->SetUp(bottom, top);\n  CHECK_GT(top.size(), 0) << \"Exhaustive mode requires at least one top blob.\";\n  // LOG(ERROR) << \"Exhaustive Mode.\";\n  for (int i = 0; i < top.size(); ++i) {\n    // LOG(ERROR) << \"Exhaustive: blob \" << i << \" size \" << top[i]->count();\n    for (int j = 0; j < top[i]->count(); ++j) {\n      // LOG(ERROR) << \"Exhaustive: blob \" << i << \" data \" << j;\n      CheckGradientSingle(layer, bottom, top, check_bottom, i, j);\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid GradientChecker<Dtype>::CheckGradientEltwise(Layer<Dtype>* layer,\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  layer->SetUp(bottom, top);\n  CHECK_GT(top.size(), 0) << \"Eltwise mode requires at least one top blob.\";\n  const int check_bottom = -1;\n  const bool element_wise = true;\n  for (int i = 0; i < top.size(); ++i) {\n    for (int j = 0; j < top[i]->count(); ++j) {\n      CheckGradientSingle(layer, bottom, top, check_bottom, i, j, element_wise);\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid GradientChecker<Dtype>::CheckGradientNet(\n    const Net<Dtype>& net, const vector<Blob<Dtype>*>& input) {\n  const vector<shared_ptr<Layer<Dtype> > >& layers = net.layers();\n  vector<vector<Blob<Dtype>*> >& bottom_vecs = net.bottom_vecs();\n  vector<vector<Blob<Dtype>*> >& top_vecs = net.top_vecs();\n  for (int i = 0; i < layers.size(); ++i) {\n    net.Forward(input);\n    LOG(ERROR) << \"Checking gradient for \" << layers[i]->layer_param().name();\n    CheckGradientExhaustive(*(layers[i].get()), bottom_vecs[i], top_vecs[i]);\n  }\n}\n\ntemplate <typename Dtype>\nDtype GradientChecker<Dtype>::GetObjAndGradient(const Layer<Dtype>& layer,\n    const vector<Blob<Dtype>*>& top, int top_id, int top_data_id) {\n  Dtype loss = 0;\n  if (top_id < 0) {\n    // the loss will be half of the sum of squares of all outputs\n    for (int i = 0; i < top.size(); ++i) {\n      Blob<Dtype>* top_blob = top[i];\n      const Dtype* top_blob_data = top_blob->cpu_data();\n      Dtype* top_blob_diff = top_blob->mutable_cpu_diff();\n      int count = top_blob->count();\n      for (int j = 0; j < count; ++j) {\n        loss += top_blob_data[j] * top_blob_data[j];\n      }\n      // set the diff: simply the data.\n      caffe_copy(top_blob->count(), top_blob_data, top_blob_diff);\n    }\n    loss /= 2.;\n  } else {\n    // the loss will be the top_data_id-th element in the top_id-th blob.\n    for (int i = 0; i < top.size(); ++i) {\n      Blob<Dtype>* top_blob = top[i];\n      Dtype* top_blob_diff = top_blob->mutable_cpu_diff();\n      caffe_set(top_blob->count(), Dtype(0), top_blob_diff);\n    }\n    const Dtype loss_weight = 2;\n    loss = top[top_id]->cpu_data()[top_data_id] * loss_weight;\n    top[top_id]->mutable_cpu_diff()[top_data_id] = loss_weight;\n  }\n  return loss;\n}\n\n}  // namespace caffe\n\n#endif  // CAFFE_TEST_GRADIENT_CHECK_UTIL_H_\n"
  },
  {
    "path": "include/caffe/util/benchmark.hpp",
    "content": "#ifndef CAFFE_UTIL_BENCHMARK_H_\n#define CAFFE_UTIL_BENCHMARK_H_\n\n#include <boost/date_time/posix_time/posix_time.hpp>\n\n#include \"caffe/util/device_alternate.hpp\"\n\nnamespace caffe {\n\nclass Timer {\n public:\n  Timer();\n  virtual ~Timer();\n  virtual void Start();\n  virtual void Stop();\n  virtual float MilliSeconds();\n  virtual float MicroSeconds();\n  virtual float Seconds();\n\n  inline bool initted() { return initted_; }\n  inline bool running() { return running_; }\n  inline bool has_run_at_least_once() { return has_run_at_least_once_; }\n\n protected:\n  void Init();\n\n  bool initted_;\n  bool running_;\n  bool has_run_at_least_once_;\n#ifndef CPU_ONLY\n  cudaEvent_t start_gpu_;\n  cudaEvent_t stop_gpu_;\n#endif\n  boost::posix_time::ptime start_cpu_;\n  boost::posix_time::ptime stop_cpu_;\n  float elapsed_milliseconds_;\n  float elapsed_microseconds_;\n};\n\nclass CPUTimer : public Timer {\n public:\n  explicit CPUTimer();\n  virtual ~CPUTimer() {}\n  virtual void Start();\n  virtual void Stop();\n  virtual float MilliSeconds();\n  virtual float MicroSeconds();\n};\n\n}  // namespace caffe\n\n#endif   // CAFFE_UTIL_BENCHMARK_H_\n"
  },
  {
    "path": "include/caffe/util/blocking_queue.hpp",
    "content": "#ifndef CAFFE_UTIL_BLOCKING_QUEUE_HPP_\n#define CAFFE_UTIL_BLOCKING_QUEUE_HPP_\n\n#include <queue>\n#include <string>\n\n#include \"caffe/common.hpp\"\n\nnamespace caffe {\n\ntemplate<typename T>\nclass BlockingQueue {\n public:\n  explicit BlockingQueue();\n\n  void push(const T& t);\n\n  bool try_pop(T* t);\n\n  // This logs a message if the threads needs to be blocked\n  // useful for detecting e.g. when data feeding is too slow\n  T pop(const string& log_on_wait = \"\");\n\n  bool try_peek(T* t);\n\n  // Return element without removing it\n  T peek();\n\n  size_t size() const;\n\n protected:\n  /**\n   Move synchronization fields out instead of including boost/thread.hpp\n   to avoid a boost/NVCC issues (#1009, #1010) on OSX. Also fails on\n   Linux CUDA 7.0.18.\n   */\n  class sync;\n\n  std::queue<T> queue_;\n  shared_ptr<sync> sync_;\n\nDISABLE_COPY_AND_ASSIGN(BlockingQueue);\n};\n\n}  // namespace caffe\n\n#endif\n"
  },
  {
    "path": "include/caffe/util/cudnn.hpp",
    "content": "#ifndef CAFFE_UTIL_CUDNN_H_\n#define CAFFE_UTIL_CUDNN_H_\n#ifdef USE_CUDNN\n\n#include <cudnn.h>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\n#define CUDNN_CHECK(condition) \\\n  do { \\\n    cudnnStatus_t status = condition; \\\n    CHECK_EQ(status, CUDNN_STATUS_SUCCESS) << \" \"\\\n      << cudnnGetErrorString(status); \\\n  } while (0)\n\ninline const char* cudnnGetErrorString(cudnnStatus_t status) {\n  switch (status) {\n    case CUDNN_STATUS_SUCCESS:\n      return \"CUDNN_STATUS_SUCCESS\";\n    case CUDNN_STATUS_NOT_INITIALIZED:\n      return \"CUDNN_STATUS_NOT_INITIALIZED\";\n    case CUDNN_STATUS_ALLOC_FAILED:\n      return \"CUDNN_STATUS_ALLOC_FAILED\";\n    case CUDNN_STATUS_BAD_PARAM:\n      return \"CUDNN_STATUS_BAD_PARAM\";\n    case CUDNN_STATUS_INTERNAL_ERROR:\n      return \"CUDNN_STATUS_INTERNAL_ERROR\";\n    case CUDNN_STATUS_INVALID_VALUE:\n      return \"CUDNN_STATUS_INVALID_VALUE\";\n    case CUDNN_STATUS_ARCH_MISMATCH:\n      return \"CUDNN_STATUS_ARCH_MISMATCH\";\n    case CUDNN_STATUS_MAPPING_ERROR:\n      return \"CUDNN_STATUS_MAPPING_ERROR\";\n    case CUDNN_STATUS_EXECUTION_FAILED:\n      return \"CUDNN_STATUS_EXECUTION_FAILED\";\n    case CUDNN_STATUS_NOT_SUPPORTED:\n      return \"CUDNN_STATUS_NOT_SUPPORTED\";\n    case CUDNN_STATUS_LICENSE_ERROR:\n      return \"CUDNN_STATUS_LICENSE_ERROR\";\n  }\n  return \"Unknown cudnn status\";\n}\n\nnamespace caffe {\n\nnamespace cudnn {\n\ntemplate <typename Dtype> class dataType;\ntemplate<> class dataType<float>  {\n public:\n  static const cudnnDataType_t type = CUDNN_DATA_FLOAT;\n  static float oneval, zeroval;\n  static const void *one, *zero;\n};\ntemplate<> class dataType<double> {\n public:\n  static const cudnnDataType_t type = CUDNN_DATA_DOUBLE;\n  static double oneval, zeroval;\n  static const void *one, *zero;\n};\n\ntemplate <typename Dtype>\ninline void createTensor4dDesc(cudnnTensorDescriptor_t* desc) {\n  CUDNN_CHECK(cudnnCreateTensorDescriptor(desc));\n}\n\ntemplate <typename Dtype>\ninline void setTensor4dDesc(cudnnTensorDescriptor_t* desc,\n    int n, int c, int h, int w,\n    int stride_n, int stride_c, int stride_h, int stride_w) {\n  CUDNN_CHECK(cudnnSetTensor4dDescriptorEx(*desc, dataType<Dtype>::type,\n        n, c, h, w, stride_n, stride_c, stride_h, stride_w));\n}\n\ntemplate <typename Dtype>\ninline void setTensor4dDesc(cudnnTensorDescriptor_t* desc,\n    int n, int c, int h, int w) {\n  const int stride_w = 1;\n  const int stride_h = w * stride_w;\n  const int stride_c = h * stride_h;\n  const int stride_n = c * stride_c;\n  setTensor4dDesc<Dtype>(desc, n, c, h, w,\n                         stride_n, stride_c, stride_h, stride_w);\n}\n\ntemplate <typename Dtype>\ninline void createFilterDesc(cudnnFilterDescriptor_t* desc,\n    int n, int c, int h, int w) {\n  CUDNN_CHECK(cudnnCreateFilterDescriptor(desc));\n  CUDNN_CHECK(cudnnSetFilter4dDescriptor(*desc, dataType<Dtype>::type,\n      n, c, h, w));\n}\n\ntemplate <typename Dtype>\ninline void createConvolutionDesc(cudnnConvolutionDescriptor_t* conv) {\n  CUDNN_CHECK(cudnnCreateConvolutionDescriptor(conv));\n}\n\ntemplate <typename Dtype>\ninline void setConvolutionDesc(cudnnConvolutionDescriptor_t* conv,\n    cudnnTensorDescriptor_t bottom, cudnnFilterDescriptor_t filter,\n    int pad_h, int pad_w, int stride_h, int stride_w) {\n  CUDNN_CHECK(cudnnSetConvolution2dDescriptor(*conv,\n      pad_h, pad_w, stride_h, stride_w, 1, 1, CUDNN_CROSS_CORRELATION));\n}\n\ntemplate <typename Dtype>\ninline void createPoolingDesc(cudnnPoolingDescriptor_t* pool_desc,\n    PoolingParameter_PoolMethod poolmethod, cudnnPoolingMode_t* mode,\n    int h, int w, int pad_h, int pad_w, int stride_h, int stride_w) {\n  switch (poolmethod) {\n  case PoolingParameter_PoolMethod_MAX:\n    *mode = CUDNN_POOLING_MAX;\n    break;\n  case PoolingParameter_PoolMethod_AVE:\n    *mode = CUDNN_POOLING_AVERAGE_COUNT_INCLUDE_PADDING;\n    break;\n  default:\n    LOG(FATAL) << \"Unknown pooling method.\";\n  }\n  CUDNN_CHECK(cudnnCreatePoolingDescriptor(pool_desc));\n  CUDNN_CHECK(cudnnSetPooling2dDescriptor(*pool_desc, *mode, h, w,\n        pad_h, pad_w, stride_h, stride_w));\n}\n\n}  // namespace cudnn\n\n}  // namespace caffe\n\n#endif  // USE_CUDNN\n#endif  // CAFFE_UTIL_CUDNN_H_\n"
  },
  {
    "path": "include/caffe/util/db.hpp",
    "content": "#ifndef CAFFE_UTIL_DB_HPP\n#define CAFFE_UTIL_DB_HPP\n\n#include <string>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe { namespace db {\n\nenum Mode { READ, WRITE, NEW };\n\nclass Cursor {\n public:\n  Cursor() { }\n  virtual ~Cursor() { }\n  virtual void SeekToFirst() = 0;\n  virtual void Next() = 0;\n  virtual string key() = 0;\n  virtual string value() = 0;\n  virtual bool valid() = 0;\n\n  DISABLE_COPY_AND_ASSIGN(Cursor);\n};\n\nclass Transaction {\n public:\n  Transaction() { }\n  virtual ~Transaction() { }\n  virtual void Put(const string& key, const string& value) = 0;\n  virtual void Commit() = 0;\n\n  DISABLE_COPY_AND_ASSIGN(Transaction);\n};\n\nclass DB {\n public:\n  DB() { }\n  virtual ~DB() { }\n  virtual void Open(const string& source, Mode mode) = 0;\n  virtual void Close() = 0;\n  virtual Cursor* NewCursor() = 0;\n  virtual Transaction* NewTransaction() = 0;\n\n  DISABLE_COPY_AND_ASSIGN(DB);\n};\n\nDB* GetDB(DataParameter::DB backend);\nDB* GetDB(const string& backend);\n\n}  // namespace db\n}  // namespace caffe\n\n#endif  // CAFFE_UTIL_DB_HPP\n"
  },
  {
    "path": "include/caffe/util/db_leveldb.hpp",
    "content": "#ifndef CAFFE_UTIL_DB_LEVELDB_HPP\n#define CAFFE_UTIL_DB_LEVELDB_HPP\n\n#include <string>\n\n#include \"leveldb/db.h\"\n#include \"leveldb/write_batch.h\"\n\n#include \"caffe/util/db.hpp\"\n\nnamespace caffe { namespace db {\n\nclass LevelDBCursor : public Cursor {\n public:\n  explicit LevelDBCursor(leveldb::Iterator* iter)\n    : iter_(iter) { SeekToFirst(); }\n  ~LevelDBCursor() { delete iter_; }\n  virtual void SeekToFirst() { iter_->SeekToFirst(); }\n  virtual void Next() { iter_->Next(); }\n  virtual string key() { return iter_->key().ToString(); }\n  virtual string value() { return iter_->value().ToString(); }\n  virtual bool valid() { return iter_->Valid(); }\n\n private:\n  leveldb::Iterator* iter_;\n};\n\nclass LevelDBTransaction : public Transaction {\n public:\n  explicit LevelDBTransaction(leveldb::DB* db) : db_(db) { CHECK_NOTNULL(db_); }\n  virtual void Put(const string& key, const string& value) {\n    batch_.Put(key, value);\n  }\n  virtual void Commit() {\n    leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch_);\n    CHECK(status.ok()) << \"Failed to write batch to leveldb \"\n                       << std::endl << status.ToString();\n  }\n\n private:\n  leveldb::DB* db_;\n  leveldb::WriteBatch batch_;\n\n  DISABLE_COPY_AND_ASSIGN(LevelDBTransaction);\n};\n\nclass LevelDB : public DB {\n public:\n  LevelDB() : db_(NULL) { }\n  virtual ~LevelDB() { Close(); }\n  virtual void Open(const string& source, Mode mode);\n  virtual void Close() {\n    if (db_ != NULL) {\n      delete db_;\n      db_ = NULL;\n    }\n  }\n  virtual LevelDBCursor* NewCursor() {\n    return new LevelDBCursor(db_->NewIterator(leveldb::ReadOptions()));\n  }\n  virtual LevelDBTransaction* NewTransaction() {\n    return new LevelDBTransaction(db_);\n  }\n\n private:\n  leveldb::DB* db_;\n};\n\n\n}  // namespace db\n}  // namespace caffe\n\n#endif  // CAFFE_UTIL_DB_LEVELDB_HPP\n"
  },
  {
    "path": "include/caffe/util/db_lmdb.hpp",
    "content": "#ifndef CAFFE_UTIL_DB_LMDB_HPP\n#define CAFFE_UTIL_DB_LMDB_HPP\n\n#include <string>\n\n#include \"lmdb.h\"\n\n#include \"caffe/util/db.hpp\"\n\nnamespace caffe { namespace db {\n\ninline void MDB_CHECK(int mdb_status) {\n  CHECK_EQ(mdb_status, MDB_SUCCESS) << mdb_strerror(mdb_status);\n}\n\nclass LMDBCursor : public Cursor {\n public:\n  explicit LMDBCursor(MDB_txn* mdb_txn, MDB_cursor* mdb_cursor)\n    : mdb_txn_(mdb_txn), mdb_cursor_(mdb_cursor), valid_(false) {\n    SeekToFirst();\n  }\n  virtual ~LMDBCursor() {\n    mdb_cursor_close(mdb_cursor_);\n    mdb_txn_abort(mdb_txn_);\n  }\n  virtual void SeekToFirst() { Seek(MDB_FIRST); }\n  virtual void Next() { Seek(MDB_NEXT); }\n  virtual string key() {\n    return string(static_cast<const char*>(mdb_key_.mv_data), mdb_key_.mv_size);\n  }\n  virtual string value() {\n    return string(static_cast<const char*>(mdb_value_.mv_data),\n        mdb_value_.mv_size);\n  }\n  virtual bool valid() { return valid_; }\n\n private:\n  void Seek(MDB_cursor_op op) {\n    int mdb_status = mdb_cursor_get(mdb_cursor_, &mdb_key_, &mdb_value_, op);\n    if (mdb_status == MDB_NOTFOUND) {\n      valid_ = false;\n    } else {\n      MDB_CHECK(mdb_status);\n      valid_ = true;\n    }\n  }\n\n  MDB_txn* mdb_txn_;\n  MDB_cursor* mdb_cursor_;\n  MDB_val mdb_key_, mdb_value_;\n  bool valid_;\n};\n\nclass LMDBTransaction : public Transaction {\n public:\n  explicit LMDBTransaction(MDB_dbi* mdb_dbi, MDB_txn* mdb_txn)\n    : mdb_dbi_(mdb_dbi), mdb_txn_(mdb_txn) { }\n  virtual void Put(const string& key, const string& value);\n  virtual void Commit() { MDB_CHECK(mdb_txn_commit(mdb_txn_)); }\n\n private:\n  MDB_dbi* mdb_dbi_;\n  MDB_txn* mdb_txn_;\n\n  DISABLE_COPY_AND_ASSIGN(LMDBTransaction);\n};\n\nclass LMDB : public DB {\n public:\n  LMDB() : mdb_env_(NULL) { }\n  virtual ~LMDB() { Close(); }\n  virtual void Open(const string& source, Mode mode);\n  virtual void Close() {\n    if (mdb_env_ != NULL) {\n      mdb_dbi_close(mdb_env_, mdb_dbi_);\n      mdb_env_close(mdb_env_);\n      mdb_env_ = NULL;\n    }\n  }\n  virtual LMDBCursor* NewCursor();\n  virtual LMDBTransaction* NewTransaction();\n\n private:\n  MDB_env* mdb_env_;\n  MDB_dbi mdb_dbi_;\n};\n\n}  // namespace db\n}  // namespace caffe\n\n#endif  // CAFFE_UTIL_DB_LMDB_HPP\n"
  },
  {
    "path": "include/caffe/util/device_alternate.hpp",
    "content": "#ifndef CAFFE_UTIL_DEVICE_ALTERNATE_H_\n#define CAFFE_UTIL_DEVICE_ALTERNATE_H_\n\n#ifdef CPU_ONLY  // CPU-only Caffe.\n\n#include <vector>\n\n// Stub out GPU calls as unavailable.\n\n#define NO_GPU LOG(FATAL) << \"Cannot use GPU in CPU-only Caffe: check mode.\"\n\n#define STUB_GPU(classname) \\\ntemplate <typename Dtype> \\\nvoid classname<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom, \\\n    const vector<Blob<Dtype>*>& top) { NO_GPU; } \\\ntemplate <typename Dtype> \\\nvoid classname<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top, \\\n    const vector<bool>& propagate_down, \\\n    const vector<Blob<Dtype>*>& bottom) { NO_GPU; } \\\n\n#define STUB_GPU_FORWARD(classname, funcname) \\\ntemplate <typename Dtype> \\\nvoid classname<Dtype>::funcname##_##gpu(const vector<Blob<Dtype>*>& bottom, \\\n    const vector<Blob<Dtype>*>& top) { NO_GPU; } \\\n\n#define STUB_GPU_BACKWARD(classname, funcname) \\\ntemplate <typename Dtype> \\\nvoid classname<Dtype>::funcname##_##gpu(const vector<Blob<Dtype>*>& top, \\\n    const vector<bool>& propagate_down, \\\n    const vector<Blob<Dtype>*>& bottom) { NO_GPU; } \\\n\n#else  // Normal GPU + CPU Caffe.\n\n#include <cublas_v2.h>\n#include <cuda.h>\n#include <cuda_runtime.h>\n#include <curand.h>\n#include <driver_types.h>  // cuda driver types\n#ifdef USE_CUDNN  // cuDNN acceleration library.\n#include \"caffe/util/cudnn.hpp\"\n#endif\n\n//\n// CUDA macros\n//\n\n// CUDA: various checks for different function calls.\n#define CUDA_CHECK(condition) \\\n  /* Code block avoids redefinition of cudaError_t error */ \\\n  do { \\\n    cudaError_t error = condition; \\\n    CHECK_EQ(error, cudaSuccess) << \" \" << cudaGetErrorString(error); \\\n  } while (0)\n\n#define CUBLAS_CHECK(condition) \\\n  do { \\\n    cublasStatus_t status = condition; \\\n    CHECK_EQ(status, CUBLAS_STATUS_SUCCESS) << \" \" \\\n      << caffe::cublasGetErrorString(status); \\\n  } while (0)\n\n#define CURAND_CHECK(condition) \\\n  do { \\\n    curandStatus_t status = condition; \\\n    CHECK_EQ(status, CURAND_STATUS_SUCCESS) << \" \" \\\n      << caffe::curandGetErrorString(status); \\\n  } while (0)\n\n// CUDA: grid stride looping\n#define CUDA_KERNEL_LOOP(i, n) \\\n  for (int i = blockIdx.x * blockDim.x + threadIdx.x; \\\n       i < (n); \\\n       i += blockDim.x * gridDim.x)\n\n// CUDA: check for error after kernel execution and exit loudly if there is one.\n#define CUDA_POST_KERNEL_CHECK CUDA_CHECK(cudaPeekAtLastError())\n\nnamespace caffe {\n\n// CUDA: library error reporting.\nconst char* cublasGetErrorString(cublasStatus_t error);\nconst char* curandGetErrorString(curandStatus_t error);\n\n// CUDA: thread number configuration.\n// Use 1024 threads per block, which requires cuda sm_2x or above,\n// or fall back to attempt compatibility (best of luck to you).\n#if __CUDA_ARCH__ >= 200\n    const int CAFFE_CUDA_NUM_THREADS = 1024;\n#else\n    const int CAFFE_CUDA_NUM_THREADS = 512;\n#endif\n\n// CUDA: number of blocks for threads.\ninline int CAFFE_GET_BLOCKS(const int N) {\n  return (N + CAFFE_CUDA_NUM_THREADS - 1) / CAFFE_CUDA_NUM_THREADS;\n}\n\n}  // namespace caffe\n\n#endif  // CPU_ONLY\n\n#endif  // CAFFE_UTIL_DEVICE_ALTERNATE_H_\n"
  },
  {
    "path": "include/caffe/util/hdf5.hpp",
    "content": "#ifndef CAFFE_UTIL_HDF5_H_\n#define CAFFE_UTIL_HDF5_H_\n\n#include <string>\n\n#include \"hdf5.h\"\n#include \"hdf5_hl.h\"\n\n#include \"caffe/blob.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid hdf5_load_nd_dataset_helper(\n    hid_t file_id, const char* dataset_name_, int min_dim, int max_dim,\n    Blob<Dtype>* blob);\n\ntemplate <typename Dtype>\nvoid hdf5_load_nd_dataset(\n    hid_t file_id, const char* dataset_name_, int min_dim, int max_dim,\n    Blob<Dtype>* blob);\n\ntemplate <typename Dtype>\nvoid hdf5_save_nd_dataset(\n    const hid_t file_id, const string& dataset_name, const Blob<Dtype>& blob,\n    bool write_diff = false);\n\nint hdf5_load_int(hid_t loc_id, const string& dataset_name);\nvoid hdf5_save_int(hid_t loc_id, const string& dataset_name, int i);\nstring hdf5_load_string(hid_t loc_id, const string& dataset_name);\nvoid hdf5_save_string(hid_t loc_id, const string& dataset_name,\n                      const string& s);\n\nint hdf5_get_num_links(hid_t loc_id);\nstring hdf5_get_name_by_idx(hid_t loc_id, int idx);\n\n}  // namespace caffe\n\n#endif   // CAFFE_UTIL_HDF5_H_\n"
  },
  {
    "path": "include/caffe/util/im2col.hpp",
    "content": "#ifndef _CAFFE_UTIL_IM2COL_HPP_\n#define _CAFFE_UTIL_IM2COL_HPP_\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid im2col_cpu(const Dtype* data_im, const int channels,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, Dtype* data_col);\n\ntemplate <typename Dtype>\nvoid col2im_cpu(const Dtype* data_col, const int channels,\n    const int height, const int width, const int patch_h, const int patch_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, Dtype* data_im);\n\ntemplate <typename Dtype>\nvoid im2col_gpu(const Dtype* data_im, const int channels,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, Dtype* data_col);\n\ntemplate <typename Dtype>\nvoid col2im_gpu(const Dtype* data_col, const int channels,\n    const int height, const int width, const int patch_h, const int patch_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, Dtype* data_im);\n\n}  // namespace caffe\n\n#endif  // CAFFE_UTIL_IM2COL_HPP_\n"
  },
  {
    "path": "include/caffe/util/insert_splits.hpp",
    "content": "#ifndef _CAFFE_UTIL_INSERT_SPLITS_HPP_\n#define _CAFFE_UTIL_INSERT_SPLITS_HPP_\n\n#include <string>\n\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\n// Copy NetParameters with SplitLayers added to replace any shared bottom\n// blobs with unique bottom blobs provided by the SplitLayer.\nvoid InsertSplits(const NetParameter& param, NetParameter* param_split);\n\nvoid ConfigureSplitLayer(const string& layer_name, const string& blob_name,\n    const int blob_idx, const int split_count, const float loss_weight,\n    LayerParameter* split_layer_param);\n\nstring SplitLayerName(const string& layer_name, const string& blob_name,\n    const int blob_idx);\n\nstring SplitBlobName(const string& layer_name, const string& blob_name,\n    const int blob_idx, const int split_idx);\n\n}  // namespace caffe\n\n#endif  // CAFFE_UTIL_INSERT_SPLITS_HPP_\n"
  },
  {
    "path": "include/caffe/util/io.hpp",
    "content": "#ifndef CAFFE_UTIL_IO_H_\n#define CAFFE_UTIL_IO_H_\n\n#include <unistd.h>\n#include <string>\n\n#include \"google/protobuf/message.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\nusing ::google::protobuf::Message;\n\ninline void MakeTempFilename(string* temp_filename) {\n  temp_filename->clear();\n  *temp_filename = \"/tmp/caffe_test.XXXXXX\";\n  char* temp_filename_cstr = new char[temp_filename->size() + 1];\n  // NOLINT_NEXT_LINE(runtime/printf)\n  strcpy(temp_filename_cstr, temp_filename->c_str());\n  int fd = mkstemp(temp_filename_cstr);\n  CHECK_GE(fd, 0) << \"Failed to open a temporary file at: \" << *temp_filename;\n  close(fd);\n  *temp_filename = temp_filename_cstr;\n  delete[] temp_filename_cstr;\n}\n\ninline void MakeTempDir(string* temp_dirname) {\n  temp_dirname->clear();\n  *temp_dirname = \"/tmp/caffe_test.XXXXXX\";\n  char* temp_dirname_cstr = new char[temp_dirname->size() + 1];\n  // NOLINT_NEXT_LINE(runtime/printf)\n  strcpy(temp_dirname_cstr, temp_dirname->c_str());\n  char* mkdtemp_result = mkdtemp(temp_dirname_cstr);\n  CHECK(mkdtemp_result != NULL)\n      << \"Failed to create a temporary directory at: \" << *temp_dirname;\n  *temp_dirname = temp_dirname_cstr;\n  delete[] temp_dirname_cstr;\n}\n\nbool ReadProtoFromTextFile(const char* filename, Message* proto);\n\ninline bool ReadProtoFromTextFile(const string& filename, Message* proto) {\n  return ReadProtoFromTextFile(filename.c_str(), proto);\n}\n\ninline void ReadProtoFromTextFileOrDie(const char* filename, Message* proto) {\n  CHECK(ReadProtoFromTextFile(filename, proto));\n}\n\ninline void ReadProtoFromTextFileOrDie(const string& filename, Message* proto) {\n  ReadProtoFromTextFileOrDie(filename.c_str(), proto);\n}\n\nvoid WriteProtoToTextFile(const Message& proto, const char* filename);\ninline void WriteProtoToTextFile(const Message& proto, const string& filename) {\n  WriteProtoToTextFile(proto, filename.c_str());\n}\n\nbool ReadProtoFromBinaryFile(const char* filename, Message* proto);\n\ninline bool ReadProtoFromBinaryFile(const string& filename, Message* proto) {\n  return ReadProtoFromBinaryFile(filename.c_str(), proto);\n}\n\ninline void ReadProtoFromBinaryFileOrDie(const char* filename, Message* proto) {\n  CHECK(ReadProtoFromBinaryFile(filename, proto));\n}\n\ninline void ReadProtoFromBinaryFileOrDie(const string& filename,\n                                         Message* proto) {\n  ReadProtoFromBinaryFileOrDie(filename.c_str(), proto);\n}\n\n\nvoid WriteProtoToBinaryFile(const Message& proto, const char* filename);\ninline void WriteProtoToBinaryFile(\n    const Message& proto, const string& filename) {\n  WriteProtoToBinaryFile(proto, filename.c_str());\n}\n\nbool ReadFileToDatum(const string& filename, const int label, Datum* datum);\n\ninline bool ReadFileToDatum(const string& filename, Datum* datum) {\n  return ReadFileToDatum(filename, -1, datum);\n}\n\nbool ReadImageToDatum(const string& filename, const int label,\n    const int height, const int width, const bool is_color,\n    const std::string & encoding, Datum* datum);\n\ninline bool ReadImageToDatum(const string& filename, const int label,\n    const int height, const int width, const bool is_color, Datum* datum) {\n  return ReadImageToDatum(filename, label, height, width, is_color,\n                          \"\", datum);\n}\n\ninline bool ReadImageToDatum(const string& filename, const int label,\n    const int height, const int width, Datum* datum) {\n  return ReadImageToDatum(filename, label, height, width, true, datum);\n}\n\ninline bool ReadImageToDatum(const string& filename, const int label,\n    const bool is_color, Datum* datum) {\n  return ReadImageToDatum(filename, label, 0, 0, is_color, datum);\n}\n\ninline bool ReadImageToDatum(const string& filename, const int label,\n    Datum* datum) {\n  return ReadImageToDatum(filename, label, 0, 0, true, datum);\n}\n\ninline bool ReadImageToDatum(const string& filename, const int label,\n    const std::string & encoding, Datum* datum) {\n  return ReadImageToDatum(filename, label, 0, 0, true, encoding, datum);\n}\n\nbool DecodeDatumNative(Datum* datum);\nbool DecodeDatum(Datum* datum, bool is_color);\n\ncv::Mat ReadImageToCVMat(const string& filename,\n    const int height, const int width, const bool is_color);\n\ncv::Mat ReadImageToCVMat(const string& filename,\n    const int height, const int width);\n\ncv::Mat ReadImageToCVMat(const string& filename,\n    const bool is_color);\n\ncv::Mat ReadImageToCVMat(const string& filename);\n\ncv::Mat DecodeDatumToCVMatNative(const Datum& datum);\ncv::Mat DecodeDatumToCVMat(const Datum& datum, bool is_color);\n\nvoid CVMatToDatum(const cv::Mat& cv_img, Datum* datum);\n\n}  // namespace caffe\n\n#endif   // CAFFE_UTIL_IO_H_\n"
  },
  {
    "path": "include/caffe/util/math_functions.hpp",
    "content": "#ifndef CAFFE_UTIL_MATH_FUNCTIONS_H_\n#define CAFFE_UTIL_MATH_FUNCTIONS_H_\n\n#include <stdint.h>\n#include <cmath>  // for std::fabs and std::signbit\n\n#include \"glog/logging.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/device_alternate.hpp\"\n#include \"caffe/util/mkl_alternate.hpp\"\n\nnamespace caffe {\n\n// Caffe gemm provides a simpler interface to the gemm functions, with the\n// limitation that the data has to be contiguous in memory.\ntemplate <typename Dtype>\nvoid caffe_cpu_gemm(const CBLAS_TRANSPOSE TransA,\n    const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,\n    const Dtype alpha, const Dtype* A, const Dtype* B, const Dtype beta,\n    Dtype* C);\n\ntemplate <typename Dtype>\nvoid caffe_cpu_gemv(const CBLAS_TRANSPOSE TransA, const int M, const int N,\n    const Dtype alpha, const Dtype* A, const Dtype* x, const Dtype beta,\n    Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_axpy(const int N, const Dtype alpha, const Dtype* X,\n    Dtype* Y);\n\ntemplate <typename Dtype>\nvoid caffe_cpu_axpby(const int N, const Dtype alpha, const Dtype* X,\n    const Dtype beta, Dtype* Y);\n\ntemplate <typename Dtype>\nvoid caffe_copy(const int N, const Dtype *X, Dtype *Y);\n\ntemplate <typename Dtype>\nvoid caffe_set(const int N, const Dtype alpha, Dtype *X);\n\ninline void caffe_memset(const size_t N, const int alpha, void* X) {\n  memset(X, alpha, N);  // NOLINT(caffe/alt_fn)\n}\n\ntemplate <typename Dtype>\nvoid caffe_add_scalar(const int N, const Dtype alpha, Dtype *X);\n\ntemplate <typename Dtype>\nvoid caffe_scal(const int N, const Dtype alpha, Dtype *X);\n\ntemplate <typename Dtype>\nvoid caffe_sqr(const int N, const Dtype* a, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_add(const int N, const Dtype* a, const Dtype* b, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_sub(const int N, const Dtype* a, const Dtype* b, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_mul(const int N, const Dtype* a, const Dtype* b, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_div(const int N, const Dtype* a, const Dtype* b, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_powx(const int n, const Dtype* a, const Dtype b, Dtype* y);\n\nunsigned int caffe_rng_rand();\n\ntemplate <typename Dtype>\nDtype caffe_nextafter(const Dtype b);\n\ntemplate <typename Dtype>\nvoid caffe_rng_uniform(const int n, const Dtype a, const Dtype b, Dtype* r);\n\ntemplate <typename Dtype>\nvoid caffe_rng_gaussian(const int n, const Dtype mu, const Dtype sigma,\n                        Dtype* r);\n\ntemplate <typename Dtype>\nvoid caffe_rng_bernoulli(const int n, const Dtype p, int* r);\n\ntemplate <typename Dtype>\nvoid caffe_rng_bernoulli(const int n, const Dtype p, unsigned int* r);\n\ntemplate <typename Dtype>\nvoid caffe_exp(const int n, const Dtype* a, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_log(const int n, const Dtype* a, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_abs(const int n, const Dtype* a, Dtype* y);\n\ntemplate <typename Dtype>\nDtype caffe_cpu_dot(const int n, const Dtype* x, const Dtype* y);\n\ntemplate <typename Dtype>\nDtype caffe_cpu_strided_dot(const int n, const Dtype* x, const int incx,\n    const Dtype* y, const int incy);\n\ntemplate <typename Dtype>\nint caffe_cpu_hamming_distance(const int n, const Dtype* x, const Dtype* y);\n\n// Returns the sum of the absolute values of the elements of vector x\ntemplate <typename Dtype>\nDtype caffe_cpu_asum(const int n, const Dtype* x);\n\n// the branchless, type-safe version from\n// http://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c\ntemplate<typename Dtype>\ninline int8_t caffe_sign(Dtype val) {\n  return (Dtype(0) < val) - (val < Dtype(0));\n}\n\n// The following two macros are modifications of DEFINE_VSL_UNARY_FUNC\n//   in include/caffe/util/mkl_alternate.hpp authored by @Rowland Depp.\n// Please refer to commit 7e8ef25c7 of the boost-eigen branch.\n// Git cherry picking that commit caused a conflict hard to resolve and\n//   copying that file in convenient for code reviewing.\n// So they have to be pasted here temporarily.\n#define DEFINE_CAFFE_CPU_UNARY_FUNC(name, operation) \\\n  template<typename Dtype> \\\n  void caffe_cpu_##name(const int n, const Dtype* x, Dtype* y) { \\\n    CHECK_GT(n, 0); CHECK(x); CHECK(y); \\\n    for (int i = 0; i < n; ++i) { \\\n      operation; \\\n    } \\\n  }\n\n// output is 1 for the positives, 0 for zero, and -1 for the negatives\nDEFINE_CAFFE_CPU_UNARY_FUNC(sign, y[i] = caffe_sign<Dtype>(x[i]));\n\n// This returns a nonzero value if the input has its sign bit set.\n// The name sngbit is meant to avoid conflicts with std::signbit in the macro.\n// The extra parens are needed because CUDA < 6.5 defines signbit as a macro,\n// and we don't want that to expand here when CUDA headers are also included.\nDEFINE_CAFFE_CPU_UNARY_FUNC(sgnbit, \\\n    y[i] = static_cast<bool>((std::signbit)(x[i])));\n\nDEFINE_CAFFE_CPU_UNARY_FUNC(fabs, y[i] = std::fabs(x[i]));\n\ntemplate <typename Dtype>\nvoid caffe_cpu_scale(const int n, const Dtype alpha, const Dtype *x, Dtype* y);\n\n#ifndef CPU_ONLY  // GPU\n\n// Decaf gpu gemm provides an interface that is almost the same as the cpu\n// gemm function - following the c convention and calling the fortran-order\n// gpu code under the hood.\ntemplate <typename Dtype>\nvoid caffe_gpu_gemm(const CBLAS_TRANSPOSE TransA,\n    const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,\n    const Dtype alpha, const Dtype* A, const Dtype* B, const Dtype beta,\n    Dtype* C);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_gemv(const CBLAS_TRANSPOSE TransA, const int M, const int N,\n    const Dtype alpha, const Dtype* A, const Dtype* x, const Dtype beta,\n    Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_axpy(const int N, const Dtype alpha, const Dtype* X,\n    Dtype* Y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_axpby(const int N, const Dtype alpha, const Dtype* X,\n    const Dtype beta, Dtype* Y);\n\nvoid caffe_gpu_memcpy(const size_t N, const void *X, void *Y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_set(const int N, const Dtype alpha, Dtype *X);\n\ninline void caffe_gpu_memset(const size_t N, const int alpha, void* X) {\n#ifndef CPU_ONLY\n  CUDA_CHECK(cudaMemset(X, alpha, N));  // NOLINT(caffe/alt_fn)\n#else\n  NO_GPU;\n#endif\n}\n\ntemplate <typename Dtype>\nvoid caffe_gpu_add_scalar(const int N, const Dtype alpha, Dtype *X);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_scal(const int N, const Dtype alpha, Dtype *X);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_add(const int N, const Dtype* a, const Dtype* b, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_sub(const int N, const Dtype* a, const Dtype* b, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_mul(const int N, const Dtype* a, const Dtype* b, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_div(const int N, const Dtype* a, const Dtype* b, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_abs(const int n, const Dtype* a, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_exp(const int n, const Dtype* a, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_log(const int n, const Dtype* a, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_powx(const int n, const Dtype* a, const Dtype b, Dtype* y);\n\n// caffe_gpu_rng_uniform with two arguments generates integers in the range\n// [0, UINT_MAX].\nvoid caffe_gpu_rng_uniform(const int n, unsigned int* r);\n\n// caffe_gpu_rng_uniform with four arguments generates floats in the range\n// (a, b] (strictly greater than a, less than or equal to b) due to the\n// specification of curandGenerateUniform.  With a = 0, b = 1, just calls\n// curandGenerateUniform; with other limits will shift and scale the outputs\n// appropriately after calling curandGenerateUniform.\ntemplate <typename Dtype>\nvoid caffe_gpu_rng_uniform(const int n, const Dtype a, const Dtype b, Dtype* r);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_rng_gaussian(const int n, const Dtype mu, const Dtype sigma,\n                            Dtype* r);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_rng_bernoulli(const int n, const Dtype p, int* r);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_dot(const int n, const Dtype* x, const Dtype* y, Dtype* out);\n\ntemplate <typename Dtype>\nuint32_t caffe_gpu_hamming_distance(const int n, const Dtype* x,\n                                    const Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_asum(const int n, const Dtype* x, Dtype* y);\n\ntemplate<typename Dtype>\nvoid caffe_gpu_sign(const int n, const Dtype* x, Dtype* y);\n\ntemplate<typename Dtype>\nvoid caffe_gpu_sgnbit(const int n, const Dtype* x, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_fabs(const int n, const Dtype* x, Dtype* y);\n\ntemplate <typename Dtype>\nvoid caffe_gpu_scale(const int n, const Dtype alpha, const Dtype *x, Dtype* y);\n\n#define DEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(name, operation) \\\ntemplate<typename Dtype> \\\n__global__ void name##_kernel(const int n, const Dtype* x, Dtype* y) { \\\n  CUDA_KERNEL_LOOP(index, n) { \\\n    operation; \\\n  } \\\n} \\\ntemplate <> \\\nvoid caffe_gpu_##name<float>(const int n, const float* x, float* y) { \\\n  /* NOLINT_NEXT_LINE(whitespace/operators) */ \\\n  name##_kernel<float><<<CAFFE_GET_BLOCKS(n), CAFFE_CUDA_NUM_THREADS>>>( \\\n      n, x, y); \\\n} \\\ntemplate <> \\\nvoid caffe_gpu_##name<double>(const int n, const double* x, double* y) { \\\n  /* NOLINT_NEXT_LINE(whitespace/operators) */ \\\n  name##_kernel<double><<<CAFFE_GET_BLOCKS(n), CAFFE_CUDA_NUM_THREADS>>>( \\\n      n, x, y); \\\n}\n\n#endif  // !CPU_ONLY\n\n}  // namespace caffe\n\n#endif  // CAFFE_UTIL_MATH_FUNCTIONS_H_\n"
  },
  {
    "path": "include/caffe/util/mkl_alternate.hpp",
    "content": "#ifndef CAFFE_UTIL_MKL_ALTERNATE_H_\n#define CAFFE_UTIL_MKL_ALTERNATE_H_\n\n#ifdef USE_MKL\n\n#include <mkl.h>\n\n#else  // If use MKL, simply include the MKL header\n\nextern \"C\" {\n#include <cblas.h>\n}\n#include <math.h>\n\n// Functions that caffe uses but are not present if MKL is not linked.\n\n// A simple way to define the vsl unary functions. The operation should\n// be in the form e.g. y[i] = sqrt(a[i])\n#define DEFINE_VSL_UNARY_FUNC(name, operation) \\\n  template<typename Dtype> \\\n  void v##name(const int n, const Dtype* a, Dtype* y) { \\\n    CHECK_GT(n, 0); CHECK(a); CHECK(y); \\\n    for (int i = 0; i < n; ++i) { operation; } \\\n  } \\\n  inline void vs##name( \\\n    const int n, const float* a, float* y) { \\\n    v##name<float>(n, a, y); \\\n  } \\\n  inline void vd##name( \\\n      const int n, const double* a, double* y) { \\\n    v##name<double>(n, a, y); \\\n  }\n\nDEFINE_VSL_UNARY_FUNC(Sqr, y[i] = a[i] * a[i]);\nDEFINE_VSL_UNARY_FUNC(Exp, y[i] = exp(a[i]));\nDEFINE_VSL_UNARY_FUNC(Ln, y[i] = log(a[i]));\nDEFINE_VSL_UNARY_FUNC(Abs, y[i] = fabs(a[i]));\n\n// A simple way to define the vsl unary functions with singular parameter b.\n// The operation should be in the form e.g. y[i] = pow(a[i], b)\n#define DEFINE_VSL_UNARY_FUNC_WITH_PARAM(name, operation) \\\n  template<typename Dtype> \\\n  void v##name(const int n, const Dtype* a, const Dtype b, Dtype* y) { \\\n    CHECK_GT(n, 0); CHECK(a); CHECK(y); \\\n    for (int i = 0; i < n; ++i) { operation; } \\\n  } \\\n  inline void vs##name( \\\n    const int n, const float* a, const float b, float* y) { \\\n    v##name<float>(n, a, b, y); \\\n  } \\\n  inline void vd##name( \\\n      const int n, const double* a, const float b, double* y) { \\\n    v##name<double>(n, a, b, y); \\\n  }\n\nDEFINE_VSL_UNARY_FUNC_WITH_PARAM(Powx, y[i] = pow(a[i], b));\n\n// A simple way to define the vsl binary functions. The operation should\n// be in the form e.g. y[i] = a[i] + b[i]\n#define DEFINE_VSL_BINARY_FUNC(name, operation) \\\n  template<typename Dtype> \\\n  void v##name(const int n, const Dtype* a, const Dtype* b, Dtype* y) { \\\n    CHECK_GT(n, 0); CHECK(a); CHECK(b); CHECK(y); \\\n    for (int i = 0; i < n; ++i) { operation; } \\\n  } \\\n  inline void vs##name( \\\n    const int n, const float* a, const float* b, float* y) { \\\n    v##name<float>(n, a, b, y); \\\n  } \\\n  inline void vd##name( \\\n      const int n, const double* a, const double* b, double* y) { \\\n    v##name<double>(n, a, b, y); \\\n  }\n\nDEFINE_VSL_BINARY_FUNC(Add, y[i] = a[i] + b[i]);\nDEFINE_VSL_BINARY_FUNC(Sub, y[i] = a[i] - b[i]);\nDEFINE_VSL_BINARY_FUNC(Mul, y[i] = a[i] * b[i]);\nDEFINE_VSL_BINARY_FUNC(Div, y[i] = a[i] / b[i]);\n\n// In addition, MKL comes with an additional function axpby that is not present\n// in standard blas. We will simply use a two-step (inefficient, of course) way\n// to mimic that.\ninline void cblas_saxpby(const int N, const float alpha, const float* X,\n                         const int incX, const float beta, float* Y,\n                         const int incY) {\n  cblas_sscal(N, beta, Y, incY);\n  cblas_saxpy(N, alpha, X, incX, Y, incY);\n}\ninline void cblas_daxpby(const int N, const double alpha, const double* X,\n                         const int incX, const double beta, double* Y,\n                         const int incY) {\n  cblas_dscal(N, beta, Y, incY);\n  cblas_daxpy(N, alpha, X, incX, Y, incY);\n}\n\n#endif  // USE_MKL\n#endif  // CAFFE_UTIL_MKL_ALTERNATE_H_\n"
  },
  {
    "path": "include/caffe/util/rng.hpp",
    "content": "#ifndef CAFFE_RNG_CPP_HPP_\n#define CAFFE_RNG_CPP_HPP_\n\n#include <algorithm>\n#include <iterator>\n\n#include \"boost/random/mersenne_twister.hpp\"\n#include \"boost/random/uniform_int.hpp\"\n\n#include \"caffe/common.hpp\"\n\nnamespace caffe {\n\ntypedef boost::mt19937 rng_t;\n\ninline rng_t* caffe_rng() {\n  return static_cast<caffe::rng_t*>(Caffe::rng_stream().generator());\n}\n\n// Fisher–Yates algorithm\ntemplate <class RandomAccessIterator, class RandomGenerator>\ninline void shuffle(RandomAccessIterator begin, RandomAccessIterator end,\n                    RandomGenerator* gen) {\n  typedef typename std::iterator_traits<RandomAccessIterator>::difference_type\n      difference_type;\n  typedef typename boost::uniform_int<difference_type> dist_type;\n\n  difference_type length = std::distance(begin, end);\n  if (length <= 0) return;\n\n  for (difference_type i = length - 1; i > 0; --i) {\n    dist_type dist(0, i);\n    std::iter_swap(begin + i, begin + dist(*gen));\n  }\n}\n\ntemplate <class RandomAccessIterator>\ninline void shuffle(RandomAccessIterator begin, RandomAccessIterator end) {\n  shuffle(begin, end, caffe_rng());\n}\n}  // namespace caffe\n\n#endif  // CAFFE_RNG_HPP_\n"
  },
  {
    "path": "include/caffe/util/upgrade_proto.hpp",
    "content": "#ifndef CAFFE_UTIL_UPGRADE_PROTO_H_\n#define CAFFE_UTIL_UPGRADE_PROTO_H_\n\n#include <string>\n\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\n// Return true iff the net is not the current version.\nbool NetNeedsUpgrade(const NetParameter& net_param);\n\n// Return true iff any layer contains parameters specified using\n// deprecated V0LayerParameter.\nbool NetNeedsV0ToV1Upgrade(const NetParameter& net_param);\n\n// Perform all necessary transformations to upgrade a V0NetParameter into a\n// NetParameter (including upgrading padding layers and LayerParameters).\nbool UpgradeV0Net(const NetParameter& v0_net_param, NetParameter* net_param);\n\n// Upgrade NetParameter with padding layers to pad-aware conv layers.\n// For any padding layer, remove it and put its pad parameter in any layers\n// taking its top blob as input.\n// Error if any of these above layers are not-conv layers.\nvoid UpgradeV0PaddingLayers(const NetParameter& param,\n                            NetParameter* param_upgraded_pad);\n\n// Upgrade a single V0LayerConnection to the V1LayerParameter format.\nbool UpgradeV0LayerParameter(const V1LayerParameter& v0_layer_connection,\n                             V1LayerParameter* layer_param);\n\nV1LayerParameter_LayerType UpgradeV0LayerType(const string& type);\n\n// Return true iff any layer contains deprecated data transformation parameters.\nbool NetNeedsDataUpgrade(const NetParameter& net_param);\n\n// Perform all necessary transformations to upgrade old transformation fields\n// into a TransformationParameter.\nvoid UpgradeNetDataTransformation(NetParameter* net_param);\n\n// Return true iff the Net contains any layers specified as V1LayerParameters.\nbool NetNeedsV1ToV2Upgrade(const NetParameter& net_param);\n\n// Perform all necessary transformations to upgrade a NetParameter with\n// deprecated V1LayerParameters.\nbool UpgradeV1Net(const NetParameter& v1_net_param, NetParameter* net_param);\n\nbool UpgradeV1LayerParameter(const V1LayerParameter& v1_layer_param,\n                             LayerParameter* layer_param);\n\nconst char* UpgradeV1LayerType(const V1LayerParameter_LayerType type);\n\n// Check for deprecations and upgrade the NetParameter as needed.\nbool UpgradeNetAsNeeded(const string& param_file, NetParameter* param);\n\n// Read parameters from a file into a NetParameter proto message.\nvoid ReadNetParamsFromTextFileOrDie(const string& param_file,\n                                    NetParameter* param);\nvoid ReadNetParamsFromBinaryFileOrDie(const string& param_file,\n                                      NetParameter* param);\n\n}  // namespace caffe\n\n#endif   // CAFFE_UTIL_UPGRADE_PROTO_H_\n"
  },
  {
    "path": "include/caffe/vision_layers.hpp",
    "content": "#ifndef CAFFE_VISION_LAYERS_HPP_\n#define CAFFE_VISION_LAYERS_HPP_\n\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/common_layers.hpp\"\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/loss_layers.hpp\"\n#include \"caffe/neuron_layers.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\n/**\n * @brief Abstract base class that factors out the BLAS code common to\n *        ConvolutionLayer and DeconvolutionLayer.\n */\ntemplate <typename Dtype>\nclass BaseConvolutionLayer : public Layer<Dtype> {\n public:\n  explicit BaseConvolutionLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline int MinBottomBlobs() const { return 1; }\n  virtual inline int MinTopBlobs() const { return 1; }\n  virtual inline bool EqualNumBottomTopBlobs() const { return true; }\n\n protected:\n  // Helper functions that abstract away the column buffer and gemm arguments.\n  // The last argument in forward_cpu_gemm is so that we can skip the im2col if\n  // we just called weight_cpu_gemm with the same input.\n  void forward_cpu_gemm(const Dtype* input, const Dtype* weights,\n      Dtype* output, bool skip_im2col = false);\n  void forward_cpu_bias(Dtype* output, const Dtype* bias);\n  void backward_cpu_gemm(const Dtype* input, const Dtype* weights,\n      Dtype* output);\n  void weight_cpu_gemm(const Dtype* input, const Dtype* output, Dtype*\n      weights);\n  void backward_cpu_bias(Dtype* bias, const Dtype* input);\n\n#ifndef CPU_ONLY\n  void forward_gpu_gemm(const Dtype* col_input, const Dtype* weights,\n      Dtype* output, bool skip_im2col = false);\n  void forward_gpu_bias(Dtype* output, const Dtype* bias);\n  void backward_gpu_gemm(const Dtype* input, const Dtype* weights,\n      Dtype* col_output);\n  void weight_gpu_gemm(const Dtype* col_input, const Dtype* output, Dtype*\n      weights);\n  void backward_gpu_bias(Dtype* bias, const Dtype* input);\n#endif\n\n  // reverse_dimensions should return true iff we are implementing deconv, so\n  // that conv helpers know which dimensions are which.\n  virtual bool reverse_dimensions() = 0;\n  // Compute height_out_ and width_out_ from other parameters.\n  virtual void compute_output_shape() = 0;\n\n  int kernel_h_, kernel_w_;\n  int stride_h_, stride_w_;\n  int num_;\n  int channels_;\n  int pad_h_, pad_w_;\n  int height_, width_;\n  int group_;\n  int num_output_;\n  int height_out_, width_out_;\n  bool bias_term_;\n  bool is_1x1_;\n\n private:\n  // wrap im2col/col2im so we don't have to remember the (long) argument lists\n  inline void conv_im2col_cpu(const Dtype* data, Dtype* col_buff) {\n    im2col_cpu(data, conv_in_channels_, conv_in_height_, conv_in_width_,\n        kernel_h_, kernel_w_, pad_h_, pad_w_, stride_h_, stride_w_, col_buff);\n  }\n  inline void conv_col2im_cpu(const Dtype* col_buff, Dtype* data) {\n    col2im_cpu(col_buff, conv_in_channels_, conv_in_height_, conv_in_width_,\n        kernel_h_, kernel_w_, pad_h_, pad_w_, stride_h_, stride_w_, data);\n  }\n#ifndef CPU_ONLY\n  inline void conv_im2col_gpu(const Dtype* data, Dtype* col_buff) {\n    im2col_gpu(data, conv_in_channels_, conv_in_height_, conv_in_width_,\n        kernel_h_, kernel_w_, pad_h_, pad_w_, stride_h_, stride_w_, col_buff);\n  }\n  inline void conv_col2im_gpu(const Dtype* col_buff, Dtype* data) {\n    col2im_gpu(col_buff, conv_in_channels_, conv_in_height_, conv_in_width_,\n        kernel_h_, kernel_w_, pad_h_, pad_w_, stride_h_, stride_w_, data);\n  }\n#endif\n\n  int conv_out_channels_;\n  int conv_in_channels_;\n  int conv_out_spatial_dim_;\n  int conv_in_height_;\n  int conv_in_width_;\n  int kernel_dim_;\n  int weight_offset_;\n  int col_offset_;\n  int output_offset_;\n\n  Blob<Dtype> col_buffer_;\n  Blob<Dtype> bias_multiplier_;\n};\n\n/**\n * @brief Convolves the input image with a bank of learned filters,\n *        and (optionally) adds biases.\n *\n *   Caffe convolves by reduction to matrix multiplication. This achieves\n *   high-throughput and generality of input and filter dimensions but comes at\n *   the cost of memory for matrices. This makes use of efficiency in BLAS.\n *\n *   The input is \"im2col\" transformed to a channel K' x H x W data matrix\n *   for multiplication with the N x K' x H x W filter matrix to yield a\n *   N' x H x W output matrix that is then \"col2im\" restored. K' is the\n *   input channel * kernel height * kernel width dimension of the unrolled\n *   inputs so that the im2col matrix has a column for each input region to\n *   be filtered. col2im restores the output spatial structure by rolling up\n *   the output channel N' columns of the output matrix.\n */\ntemplate <typename Dtype>\nclass ConvolutionLayer : public BaseConvolutionLayer<Dtype> {\n public:\n  /**\n   * @param param provides ConvolutionParameter convolution_param,\n   *    with ConvolutionLayer options:\n   *  - num_output. The number of filters.\n   *  - kernel_size / kernel_h / kernel_w. The filter dimensions, given by\n   *  kernel_size for square filters or kernel_h and kernel_w for rectangular\n   *  filters.\n   *  - stride / stride_h / stride_w (\\b optional, default 1). The filter\n   *  stride, given by stride_size for equal dimensions or stride_h and stride_w\n   *  for different strides. By default the convolution is dense with stride 1.\n   *  - pad / pad_h / pad_w (\\b optional, default 0). The zero-padding for\n   *  convolution, given by pad for equal dimensions or pad_h and pad_w for\n   *  different padding. Input padding is computed implicitly instead of\n   *  actually padding.\n   *  - group (\\b optional, default 1). The number of filter groups. Group\n   *  convolution is a method for reducing parameterization by selectively\n   *  connecting input and output channels. The input and output channel dimensions must be divisible\n   *  by the number of groups. For group @f$ \\geq 1 @f$, the\n   *  convolutional filters' input and output channels are separated s.t. each\n   *  group takes 1 / group of the input channels and makes 1 / group of the\n   *  output channels. Concretely 4 input channels, 8 output channels, and\n   *  2 groups separate input channels 1-2 and output channels 1-4 into the\n   *  first group and input channels 3-4 and output channels 5-8 into the second\n   *  group.\n   *  - bias_term (\\b optional, default true). Whether to have a bias.\n   *  - engine: convolution has CAFFE (matrix multiplication) and CUDNN (library\n   *    kernels + stream parallelism) engines.\n   */\n  explicit ConvolutionLayer(const LayerParameter& param)\n      : BaseConvolutionLayer<Dtype>(param) {}\n\n  virtual inline const char* type() const { return \"Convolution\"; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual inline bool reverse_dimensions() { return false; }\n  virtual void compute_output_shape();\n};\n\n/**\n * @brief Convolves the input with a bank of compressed filters, \n *  and (optionally) adds biases.\n */\n\ntemplate <typename Dtype>\nclass CConvolutionLayer : public BaseConvolutionLayer<Dtype> {\n public:\n\n  explicit CConvolutionLayer(const LayerParameter& param)\n      : BaseConvolutionLayer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual inline const char* type() const { return \"CConvolution\"; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual inline bool reverse_dimensions() { return false; }\n  virtual void compute_output_shape();\n  \n private:\n  Blob<Dtype> weight_tmp_;\n  Blob<Dtype> bias_tmp_;   \n  Blob<Dtype> rand_weight_m_;\n  Blob<Dtype> rand_bias_m_;  \n  Dtype gamma,power;\n  Dtype crate; \n  Dtype mu,std;    \n  int iter_stop_;\n};\n\n\n\n/**\n * @brief Convolve the input with a bank of learned filters, and (optionally)\n *        add biases, treating filters and convolution parameters in the\n *        opposite sense as ConvolutionLayer.\n *\n *   ConvolutionLayer computes each output value by dotting an input window with\n *   a filter; DeconvolutionLayer multiplies each input value by a filter\n *   elementwise, and sums over the resulting output windows. In other words,\n *   DeconvolutionLayer is ConvolutionLayer with the forward and backward passes\n *   reversed. DeconvolutionLayer reuses ConvolutionParameter for its\n *   parameters, but they take the opposite sense as in ConvolutionLayer (so\n *   padding is removed from the output rather than added to the input, and\n *   stride results in upsampling rather than downsampling).\n */\ntemplate <typename Dtype>\nclass DeconvolutionLayer : public BaseConvolutionLayer<Dtype> {\n public:\n  explicit DeconvolutionLayer(const LayerParameter& param)\n      : BaseConvolutionLayer<Dtype>(param) {}\n\n  virtual inline const char* type() const { return \"Deconvolution\"; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual inline bool reverse_dimensions() { return true; }\n  virtual void compute_output_shape();\n};\n\n#ifdef USE_CUDNN\n/*\n * @brief cuDNN implementation of ConvolutionLayer.\n *        Fallback to ConvolutionLayer for CPU mode.\n *\n * cuDNN accelerates convolution through forward kernels for filtering and bias\n * plus backward kernels for the gradient w.r.t. the filters, biases, and\n * inputs. Caffe + cuDNN further speeds up the computation through forward\n * parallelism across groups and backward parallelism across gradients.\n *\n * The CUDNN engine does not have memory overhead for matrix buffers. For many\n * input and filter regimes the CUDNN engine is faster than the CAFFE engine,\n * but for fully-convolutional models and large inputs the CAFFE engine can be\n * faster as long as it fits in memory.\n*/\ntemplate <typename Dtype>\nclass CuDNNConvolutionLayer : public ConvolutionLayer<Dtype> {\n public:\n  explicit CuDNNConvolutionLayer(const LayerParameter& param)\n      : ConvolutionLayer<Dtype>(param), handles_setup_(false) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual ~CuDNNConvolutionLayer();\n\n protected:\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  bool handles_setup_;\n  cudnnHandle_t* handle_;\n  cudaStream_t*  stream_;\n  vector<cudnnTensorDescriptor_t> bottom_descs_, top_descs_;\n  cudnnTensorDescriptor_t    bias_desc_;\n  cudnnFilterDescriptor_t      filter_desc_;\n  vector<cudnnConvolutionDescriptor_t> conv_descs_;\n  int bottom_offset_, top_offset_, weight_offset_, bias_offset_;\n  size_t workspaceSizeInBytes;\n  void *workspace;\n};\n#endif\n\n/**\n * @brief A helper for image operations that rearranges image regions into\n *        column vectors.  Used by ConvolutionLayer to perform convolution\n *        by matrix multiplication.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass Im2colLayer : public Layer<Dtype> {\n public:\n  explicit Im2colLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Im2col\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  int kernel_h_, kernel_w_;\n  int stride_h_, stride_w_;\n  int channels_;\n  int height_, width_;\n  int pad_h_, pad_w_;\n};\n\n// Forward declare PoolingLayer and SplitLayer for use in LRNLayer.\ntemplate <typename Dtype> class PoolingLayer;\ntemplate <typename Dtype> class SplitLayer;\n\n/**\n * @brief Normalize the input in a local region across or within feature maps.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass LRNLayer : public Layer<Dtype> {\n public:\n  explicit LRNLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"LRN\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  virtual void CrossChannelForward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void CrossChannelForward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void WithinChannelForward(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void CrossChannelBackward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void CrossChannelBackward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void WithinChannelBackward(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  int size_;\n  int pre_pad_;\n  Dtype alpha_;\n  Dtype beta_;\n  Dtype k_;\n  int num_;\n  int channels_;\n  int height_;\n  int width_;\n\n  // Fields used for normalization ACROSS_CHANNELS\n  // scale_ stores the intermediate summing results\n  Blob<Dtype> scale_;\n\n  // Fields used for normalization WITHIN_CHANNEL\n  shared_ptr<SplitLayer<Dtype> > split_layer_;\n  vector<Blob<Dtype>*> split_top_vec_;\n  shared_ptr<PowerLayer<Dtype> > square_layer_;\n  Blob<Dtype> square_input_;\n  Blob<Dtype> square_output_;\n  vector<Blob<Dtype>*> square_bottom_vec_;\n  vector<Blob<Dtype>*> square_top_vec_;\n  shared_ptr<PoolingLayer<Dtype> > pool_layer_;\n  Blob<Dtype> pool_output_;\n  vector<Blob<Dtype>*> pool_top_vec_;\n  shared_ptr<PowerLayer<Dtype> > power_layer_;\n  Blob<Dtype> power_output_;\n  vector<Blob<Dtype>*> power_top_vec_;\n  shared_ptr<EltwiseLayer<Dtype> > product_layer_;\n  Blob<Dtype> product_input_;\n  vector<Blob<Dtype>*> product_bottom_vec_;\n};\n\n\n/**\n * @brief Pools the input image by taking the max, average, etc. within regions.\n *\n * TODO(dox): thorough documentation for Forward, Backward, and proto params.\n */\ntemplate <typename Dtype>\nclass PoolingLayer : public Layer<Dtype> {\n public:\n  explicit PoolingLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"Pooling\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int MinTopBlobs() const { return 1; }\n  // MAX POOL layers can output an extra top blob for the mask;\n  // others can only output the pooled inputs.\n  virtual inline int MaxTopBlobs() const {\n    return (this->layer_param_.pooling_param().pool() ==\n            PoolingParameter_PoolMethod_MAX) ? 2 : 1;\n  }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  int kernel_h_, kernel_w_;\n  int stride_h_, stride_w_;\n  int pad_h_, pad_w_;\n  int channels_;\n  int height_, width_;\n  int pooled_height_, pooled_width_;\n  bool global_pooling_;\n  Blob<Dtype> rand_idx_;\n  Blob<int> max_idx_;\n};\n\n#ifdef USE_CUDNN\n/*\n * @brief cuDNN implementation of PoolingLayer.\n *        Fallback to PoolingLayer for CPU mode.\n*/\ntemplate <typename Dtype>\nclass CuDNNPoolingLayer : public PoolingLayer<Dtype> {\n public:\n  explicit CuDNNPoolingLayer(const LayerParameter& param)\n      : PoolingLayer<Dtype>(param), handles_setup_(false) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual ~CuDNNPoolingLayer();\n  // Currently, cuDNN does not support the extra top blob.\n  virtual inline int MinTopBlobs() const { return -1; }\n  virtual inline int ExactNumTopBlobs() const { return 1; }\n\n protected:\n  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n\n  bool handles_setup_;\n  cudnnHandle_t             handle_;\n  cudnnTensorDescriptor_t bottom_desc_, top_desc_;\n  cudnnPoolingDescriptor_t  pooling_desc_;\n  cudnnPoolingMode_t        mode_;\n};\n#endif\n\n/**\n * @brief Does spatial pyramid pooling on the input image\n *        by taking the max, average, etc. within regions\n *        so that the result vector of different sized\n *        images are of the same size.\n */\ntemplate <typename Dtype>\nclass SPPLayer : public Layer<Dtype> {\n public:\n  explicit SPPLayer(const LayerParameter& param)\n      : Layer<Dtype>(param) {}\n  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n\n  virtual inline const char* type() const { return \"SPP\"; }\n  virtual inline int ExactNumBottomBlobs() const { return 1; }\n  virtual inline int MinTopBlobs() const { return 1; }\n  // MAX POOL layers can output an extra top blob for the mask;\n  // others can only output the pooled inputs.\n  virtual inline int MaxTopBlobs() const {\n    return (this->layer_param_.pooling_param().pool() ==\n            PoolingParameter_PoolMethod_MAX) ? 2 : 1;\n  }\n\n protected:\n  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top);\n  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);\n  // calculates the kernel and stride dimensions for the pooling layer,\n  // returns a correctly configured LayerParameter for a PoolingLayer\n  virtual LayerParameter GetPoolingParam(const int pyramid_level,\n      const int bottom_h, const int bottom_w, const SPPParameter spp_param);\n\n  int pyramid_height_;\n  int bottom_h_, bottom_w_;\n  int channels_;\n  int kernel_h_, kernel_w_;\n  int pad_h_, pad_w_;\n\n  /// the internal Split layer that feeds the pooling layers\n  shared_ptr<SplitLayer<Dtype> > split_layer_;\n  /// top vector holder used in call to the underlying SplitLayer::Forward\n  vector<Blob<Dtype>*> split_top_vec_;\n  /// bottom vector holder used in call to the underlying PoolingLayer::Forward\n  vector<vector<Blob<Dtype>*>*> pooling_bottom_vecs_;\n  /// the internal Pooling layers of different kernel sizes\n  vector<shared_ptr<PoolingLayer<Dtype> > > pooling_layers_;\n  /// top vector holders used in call to the underlying PoolingLayer::Forward\n  vector<vector<Blob<Dtype>*>*> pooling_top_vecs_;\n  /// pooling_outputs stores the outputs of the PoolingLayers\n  vector<Blob<Dtype>*> pooling_outputs_;\n  /// the internal Flatten layers that the Pooling layers feed into\n  vector<FlattenLayer<Dtype>*> flatten_layers_;\n  /// top vector holders used in call to the underlying FlattenLayer::Forward\n  vector<vector<Blob<Dtype>*>*> flatten_top_vecs_;\n  /// flatten_outputs stores the outputs of the FlattenLayers\n  vector<Blob<Dtype>*> flatten_outputs_;\n  /// bottom vector holder used in call to the underlying ConcatLayer::Forward\n  vector<Blob<Dtype>*> concat_bottom_vec_;\n  /// the internal Concat layers that the Flatten layers feed into\n  shared_ptr<ConcatLayer<Dtype> > concat_layer_;\n};\n\n}  // namespace caffe\n\n#endif  // CAFFE_VISION_LAYERS_HPP_\n"
  },
  {
    "path": "models/lenet300100/lenet300100.prototxt",
    "content": "name: \"LeNet\"\ninput: \"data\"\ninput_dim: 64\ninput_dim: 1\ninput_dim: 28\ninput_dim: 28\nlayer {\n  name: \"ip1\"\n  type: \"InnerProduct\"\n  bottom: \"data\"\n  top: \"ip1\"\n  param {\n    lr_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  inner_product_param {\n    num_output: 300\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"relu1\"\n  type: \"ReLU\"\n  bottom: \"ip1\"\n  top: \"ip1\"\n}\nlayer {\n  name: \"ip2\"\n  type: \"InnerProduct\"\n  bottom: \"ip1\"\n  top: \"ip2\"\n  param {\n    lr_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  inner_product_param {\n    num_output: 100\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"relu2\"\n  type: \"ReLU\"\n  bottom: \"ip2\"\n  top: \"ip2\"\n}\nlayer {\n  name: \"ip3\"\n  type: \"InnerProduct\"\n  bottom: \"ip2\"\n  top: \"ip3\"\n  param {\n    lr_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  inner_product_param {\n    num_output: 10\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"prob\"\n  type: \"Softmax\"\n  bottom: \"ip2\"\n  top: \"prob\"\n}\n"
  },
  {
    "path": "models/lenet5/lenet5.prototxt",
    "content": "name: \"LeNet\"\ninput: \"data\"\ninput_dim: 64\ninput_dim: 1\ninput_dim: 28\ninput_dim: 28\nlayer {\n  name: \"conv1\"\n  type: \"Convolution\"\n  bottom: \"data\"\n  top: \"conv1\"\n  param {\n    lr_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  convolution_param {\n    num_output: 20\n    kernel_size: 5\n    stride: 1\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"pool1\"\n  type: \"Pooling\"\n  bottom: \"conv1\"\n  top: \"pool1\"\n  pooling_param {\n    pool: MAX\n    kernel_size: 2\n    stride: 2\n  }\n}\nlayer {\n  name: \"conv2\"\n  type: \"Convolution\"\n  bottom: \"pool1\"\n  top: \"conv2\"\n  param {\n    lr_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  convolution_param {\n    num_output: 50\n    kernel_size: 5\n    stride: 1\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"pool2\"\n  type: \"Pooling\"\n  bottom: \"conv2\"\n  top: \"pool2\"\n  pooling_param {\n    pool: MAX\n    kernel_size: 2\n    stride: 2\n  }\n}\nlayer {\n  name: \"ip1\"\n  type: \"InnerProduct\"\n  bottom: \"pool2\"\n  top: \"ip1\"\n  param {\n    lr_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  inner_product_param {\n    num_output: 500\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"relu1\"\n  type: \"ReLU\"\n  bottom: \"ip1\"\n  top: \"ip1\"\n}\nlayer {\n  name: \"ip2\"\n  type: \"InnerProduct\"\n  bottom: \"ip1\"\n  top: \"ip2\"\n  param {\n    lr_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  inner_product_param {\n    num_output: 10\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"prob\"\n  type: \"Softmax\"\n  bottom: \"ip2\"\n  top: \"prob\"\n}\n"
  },
  {
    "path": "src/caffe/CMakeLists.txt",
    "content": "# generate protobuf sources\nfile(GLOB proto_files proto/*.proto)\ncaffe_protobuf_generate_cpp_py(${proto_gen_folder} proto_srcs proto_hdrs proto_python ${proto_files})\n\n# include python files either to force generation\nadd_library(proto STATIC ${proto_hdrs} ${proto_srcs} ${proto_python})\nset(Caffe_LINKER_LIBS proto ${Caffe_LINKER_LIBS}) # note, crucial to prepend!\ncaffe_default_properties(proto)\n\n# --[ Caffe library\n\n# creates 'test_srcs', 'srcs', 'test_cuda', 'cuda' lists\ncaffe_pickup_caffe_sources(${PROJECT_SOURCE_DIR})\n\nif(HAVE_CUDA)\n  caffe_cuda_compile(cuda_objs ${cuda})\n  list(APPEND srcs ${cuda_objs} ${cuda})\nendif()\n\nadd_library(caffe ${srcs})\ntarget_link_libraries(caffe proto ${Caffe_LINKER_LIBS})\ncaffe_default_properties(caffe)\n\n# ---[ Tests\n add_subdirectory(test)\n\n# ---[ Install\ninstall(DIRECTORY ${Caffe_INCLUDE_DIR}/caffe DESTINATION include)\ninstall(FILES ${proto_hdrs} DESTINATION include/caffe/proto)\ninstall(TARGETS caffe proto EXPORT CaffeTargets DESTINATION lib)\n\nfile(WRITE ${PROJECT_BINARY_DIR}/__init__.py)\nlist(APPEND proto_python ${PROJECT_BINARY_DIR}/__init__.py)\ninstall(PROGRAMS ${proto_python} DESTINATION python/caffe/proto)\n\n\n"
  },
  {
    "path": "src/caffe/blob.cpp",
    "content": "#include <climits>\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::Reshape(const int num, const int channels, const int height,\n    const int width) {\n  vector<int> shape(4);\n  shape[0] = num;\n  shape[1] = channels;\n  shape[2] = height;\n  shape[3] = width;\n  Reshape(shape);\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::Reshape(const vector<int>& shape) {\n  CHECK_LE(shape.size(), kMaxBlobAxes);\n  count_ = 1;\n  shape_.resize(shape.size());\n  for (int i = 0; i < shape.size(); ++i) {\n    CHECK_GE(shape[i], 0);\n    CHECK_LE(shape[i], INT_MAX / count_) << \"blob size exceeds INT_MAX\";\n    count_ *= shape[i];\n    shape_[i] = shape[i];\n  }\n  if (count_ > capacity_) {\n    capacity_ = count_;\n    data_.reset(new SyncedMemory(capacity_ * sizeof(Dtype)));\n    diff_.reset(new SyncedMemory(capacity_ * sizeof(Dtype)));\n  }\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::Reshape(const BlobShape& shape) {\n  CHECK_LE(shape.dim_size(), kMaxBlobAxes);\n  vector<int> shape_vec(shape.dim_size());\n  for (int i = 0; i < shape.dim_size(); ++i) {\n    shape_vec[i] = shape.dim(i);\n  }\n  Reshape(shape_vec);\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::ReshapeLike(const Blob<Dtype>& other) {\n  Reshape(other.shape());\n}\n\ntemplate <typename Dtype>\nBlob<Dtype>::Blob(const int num, const int channels, const int height,\n    const int width)\n  // capacity_ must be initialized before calling Reshape\n  : capacity_(0) {\n  Reshape(num, channels, height, width);\n}\n\ntemplate <typename Dtype>\nBlob<Dtype>::Blob(const vector<int>& shape)\n  // capacity_ must be initialized before calling Reshape\n  : capacity_(0) {\n  Reshape(shape);\n}\n\ntemplate <typename Dtype>\nconst Dtype* Blob<Dtype>::cpu_data() const {\n  CHECK(data_);\n  return (const Dtype*)data_->cpu_data();\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::set_cpu_data(Dtype* data) {\n  CHECK(data);\n  data_->set_cpu_data(data);\n}\n\ntemplate <typename Dtype>\nconst Dtype* Blob<Dtype>::gpu_data() const {\n  CHECK(data_);\n  return (const Dtype*)data_->gpu_data();\n}\n\ntemplate <typename Dtype>\nconst Dtype* Blob<Dtype>::cpu_diff() const {\n  CHECK(diff_);\n  return (const Dtype*)diff_->cpu_data();\n}\n\ntemplate <typename Dtype>\nconst Dtype* Blob<Dtype>::gpu_diff() const {\n  CHECK(diff_);\n  return (const Dtype*)diff_->gpu_data();\n}\n\ntemplate <typename Dtype>\nDtype* Blob<Dtype>::mutable_cpu_data() {\n  CHECK(data_);\n  return static_cast<Dtype*>(data_->mutable_cpu_data());\n}\n\ntemplate <typename Dtype>\nDtype* Blob<Dtype>::mutable_gpu_data() {\n  CHECK(data_);\n  return static_cast<Dtype*>(data_->mutable_gpu_data());\n}\n\ntemplate <typename Dtype>\nDtype* Blob<Dtype>::mutable_cpu_diff() {\n  CHECK(diff_);\n  return static_cast<Dtype*>(diff_->mutable_cpu_data());\n}\n\ntemplate <typename Dtype>\nDtype* Blob<Dtype>::mutable_gpu_diff() {\n  CHECK(diff_);\n  return static_cast<Dtype*>(diff_->mutable_gpu_data());\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::ShareData(const Blob& other) {\n  CHECK_EQ(count_, other.count());\n  data_ = other.data();\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::ShareDiff(const Blob& other) {\n  CHECK_EQ(count_, other.count());\n  diff_ = other.diff();\n}\n\n// The \"update\" method is used for parameter blobs in a Net, which are stored\n// as Blob<float> or Blob<double> -- hence we do not define it for\n// Blob<int> or Blob<unsigned int>.\ntemplate <> void Blob<unsigned int>::Update() { NOT_IMPLEMENTED; }\ntemplate <> void Blob<int>::Update() { NOT_IMPLEMENTED; }\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::Update() {\n  // We will perform update based on where the data is located.\n  switch (data_->head()) {\n  case SyncedMemory::HEAD_AT_CPU:\n    // perform computation on CPU\n    caffe_axpy<Dtype>(count_, Dtype(-1),\n        static_cast<const Dtype*>(diff_->cpu_data()),\n        static_cast<Dtype*>(data_->mutable_cpu_data()));\n    break;\n  case SyncedMemory::HEAD_AT_GPU:\n  case SyncedMemory::SYNCED:\n#ifndef CPU_ONLY\n    // perform computation on GPU\n    caffe_gpu_axpy<Dtype>(count_, Dtype(-1),\n        static_cast<const Dtype*>(diff_->gpu_data()),\n        static_cast<Dtype*>(data_->mutable_gpu_data()));\n#else\n    NO_GPU;\n#endif\n    break;\n  default:\n    LOG(FATAL) << \"Syncedmem not initialized.\";\n  }\n}\n\ntemplate <> unsigned int Blob<unsigned int>::asum_data() const {\n  NOT_IMPLEMENTED;\n  return 0;\n}\n\ntemplate <> int Blob<int>::asum_data() const {\n  NOT_IMPLEMENTED;\n  return 0;\n}\n\ntemplate <typename Dtype>\nDtype Blob<Dtype>::asum_data() const {\n  if (!data_) { return 0; }\n  switch (data_->head()) {\n  case SyncedMemory::HEAD_AT_CPU:\n    return caffe_cpu_asum(count_, cpu_data());\n  case SyncedMemory::HEAD_AT_GPU:\n  case SyncedMemory::SYNCED:\n#ifndef CPU_ONLY\n  {\n    Dtype asum;\n    caffe_gpu_asum(count_, gpu_data(), &asum);\n    return asum;\n  }\n#else\n    NO_GPU;\n#endif\n  case SyncedMemory::UNINITIALIZED:\n    return 0;\n  default:\n    LOG(FATAL) << \"Unknown SyncedMemory head state: \" << data_->head();\n  }\n  return 0;\n}\n\ntemplate <> unsigned int Blob<unsigned int>::asum_diff() const {\n  NOT_IMPLEMENTED;\n  return 0;\n}\n\ntemplate <> int Blob<int>::asum_diff() const {\n  NOT_IMPLEMENTED;\n  return 0;\n}\n\ntemplate <typename Dtype>\nDtype Blob<Dtype>::asum_diff() const {\n  if (!diff_) { return 0; }\n  switch (diff_->head()) {\n  case SyncedMemory::HEAD_AT_CPU:\n    return caffe_cpu_asum(count_, cpu_diff());\n  case SyncedMemory::HEAD_AT_GPU:\n  case SyncedMemory::SYNCED:\n#ifndef CPU_ONLY\n  {\n    Dtype asum;\n    caffe_gpu_asum(count_, gpu_diff(), &asum);\n    return asum;\n  }\n#else\n    NO_GPU;\n#endif\n  case SyncedMemory::UNINITIALIZED:\n    return 0;\n  default:\n    LOG(FATAL) << \"Unknown SyncedMemory head state: \" << diff_->head();\n  }\n  return 0;\n}\n\ntemplate <> unsigned int Blob<unsigned int>::sumsq_data() const {\n  NOT_IMPLEMENTED;\n  return 0;\n}\n\ntemplate <> int Blob<int>::sumsq_data() const {\n  NOT_IMPLEMENTED;\n  return 0;\n}\n\ntemplate <typename Dtype>\nDtype Blob<Dtype>::sumsq_data() const {\n  Dtype sumsq;\n  const Dtype* data;\n  if (!data_) { return 0; }\n  switch (data_->head()) {\n  case SyncedMemory::HEAD_AT_CPU:\n    data = cpu_data();\n    sumsq = caffe_cpu_dot(count_, data, data);\n    break;\n  case SyncedMemory::HEAD_AT_GPU:\n  case SyncedMemory::SYNCED:\n#ifndef CPU_ONLY\n    data = gpu_data();\n    caffe_gpu_dot(count_, data, data, &sumsq);\n#else\n    NO_GPU;\n#endif\n    break;\n  case SyncedMemory::UNINITIALIZED:\n    return 0;\n  default:\n    LOG(FATAL) << \"Unknown SyncedMemory head state: \" << data_->head();\n  }\n  return sumsq;\n}\n\ntemplate <> unsigned int Blob<unsigned int>::sumsq_diff() const {\n  NOT_IMPLEMENTED;\n  return 0;\n}\n\ntemplate <> int Blob<int>::sumsq_diff() const {\n  NOT_IMPLEMENTED;\n  return 0;\n}\n\ntemplate <typename Dtype>\nDtype Blob<Dtype>::sumsq_diff() const {\n  Dtype sumsq;\n  const Dtype* diff;\n  if (!diff_) { return 0; }\n  switch (diff_->head()) {\n  case SyncedMemory::HEAD_AT_CPU:\n    diff = cpu_diff();\n    sumsq = caffe_cpu_dot(count_, diff, diff);\n    break;\n  case SyncedMemory::HEAD_AT_GPU:\n  case SyncedMemory::SYNCED:\n#ifndef CPU_ONLY\n    diff = gpu_diff();\n    caffe_gpu_dot(count_, diff, diff, &sumsq);\n    break;\n#else\n    NO_GPU;\n#endif\n  case SyncedMemory::UNINITIALIZED:\n    return 0;\n  default:\n    LOG(FATAL) << \"Unknown SyncedMemory head state: \" << data_->head();\n  }\n  return sumsq;\n}\n\ntemplate <> void Blob<unsigned int>::scale_data(unsigned int scale_factor) {\n  NOT_IMPLEMENTED;\n}\n\ntemplate <> void Blob<int>::scale_data(int scale_factor) {\n  NOT_IMPLEMENTED;\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::scale_data(Dtype scale_factor) {\n  Dtype* data;\n  if (!data_) { return; }\n  switch (data_->head()) {\n  case SyncedMemory::HEAD_AT_CPU:\n    data = mutable_cpu_data();\n    caffe_scal(count_, scale_factor, data);\n    return;\n  case SyncedMemory::HEAD_AT_GPU:\n  case SyncedMemory::SYNCED:\n#ifndef CPU_ONLY\n    data = mutable_gpu_data();\n    caffe_gpu_scal(count_, scale_factor, data);\n    return;\n#else\n    NO_GPU;\n#endif\n  case SyncedMemory::UNINITIALIZED:\n    return;\n  default:\n    LOG(FATAL) << \"Unknown SyncedMemory head state: \" << data_->head();\n  }\n}\n\ntemplate <> void Blob<unsigned int>::scale_diff(unsigned int scale_factor) {\n  NOT_IMPLEMENTED;\n}\n\ntemplate <> void Blob<int>::scale_diff(int scale_factor) {\n  NOT_IMPLEMENTED;\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::scale_diff(Dtype scale_factor) {\n  Dtype* diff;\n  if (!diff_) { return; }\n  switch (diff_->head()) {\n  case SyncedMemory::HEAD_AT_CPU:\n    diff = mutable_cpu_diff();\n    caffe_scal(count_, scale_factor, diff);\n    return;\n  case SyncedMemory::HEAD_AT_GPU:\n  case SyncedMemory::SYNCED:\n#ifndef CPU_ONLY\n    diff = mutable_gpu_diff();\n    caffe_gpu_scal(count_, scale_factor, diff);\n    return;\n#else\n    NO_GPU;\n#endif\n  case SyncedMemory::UNINITIALIZED:\n    return;\n  default:\n    LOG(FATAL) << \"Unknown SyncedMemory head state: \" << diff_->head();\n  }\n}\n\ntemplate <typename Dtype>\nbool Blob<Dtype>::ShapeEquals(const BlobProto& other) {\n  if (other.has_num() || other.has_channels() ||\n      other.has_height() || other.has_width()) {\n    // Using deprecated 4D Blob dimensions --\n    // shape is (num, channels, height, width).\n    // Note: we do not use the normal Blob::num(), Blob::channels(), etc.\n    // methods as these index from the beginning of the blob shape, where legacy\n    // parameter blobs were indexed from the end of the blob shape (e.g., bias\n    // Blob shape (1 x 1 x 1 x N), IP layer weight Blob shape (1 x 1 x M x N)).\n    return shape_.size() <= 4 &&\n           LegacyShape(-4) == other.num() &&\n           LegacyShape(-3) == other.channels() &&\n           LegacyShape(-2) == other.height() &&\n           LegacyShape(-1) == other.width();\n  }\n  vector<int> other_shape(other.shape().dim_size());\n  for (int i = 0; i < other.shape().dim_size(); ++i) {\n    other_shape[i] = other.shape().dim(i);\n  }\n  return shape_ == other_shape;\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::CopyFrom(const Blob& source, bool copy_diff, bool reshape) {\n  if (source.count() != count_ || source.shape() != shape_) {\n    if (reshape) {\n      ReshapeLike(source);\n    } else {\n      LOG(FATAL) << \"Trying to copy blobs of different sizes.\";\n    }\n  }\n  switch (Caffe::mode()) {\n  case Caffe::GPU:\n    if (copy_diff) {\n      caffe_copy(count_, source.gpu_diff(),\n          static_cast<Dtype*>(diff_->mutable_gpu_data()));\n    } else {\n      caffe_copy(count_, source.gpu_data(),\n          static_cast<Dtype*>(data_->mutable_gpu_data()));\n    }\n    break;\n  case Caffe::CPU:\n    if (copy_diff) {\n      caffe_copy(count_, source.cpu_diff(),\n          static_cast<Dtype*>(diff_->mutable_cpu_data()));\n    } else {\n      caffe_copy(count_, source.cpu_data(),\n          static_cast<Dtype*>(data_->mutable_cpu_data()));\n    }\n    break;\n  default:\n    LOG(FATAL) << \"Unknown caffe mode.\";\n  }\n}\n\ntemplate <typename Dtype>\nvoid Blob<Dtype>::FromProto(const BlobProto& proto, bool reshape) {\n  if (reshape) {\n    vector<int> shape;\n    if (proto.has_num() || proto.has_channels() ||\n        proto.has_height() || proto.has_width()) {\n      // Using deprecated 4D Blob dimensions --\n      // shape is (num, channels, height, width).\n      shape.resize(4);\n      shape[0] = proto.num();\n      shape[1] = proto.channels();\n      shape[2] = proto.height();\n      shape[3] = proto.width();\n    } else {\n      shape.resize(proto.shape().dim_size());\n      for (int i = 0; i < proto.shape().dim_size(); ++i) {\n        shape[i] = proto.shape().dim(i);\n      }\n    }\n    Reshape(shape);\n  } else {\n    CHECK(ShapeEquals(proto)) << \"shape mismatch (reshape not set)\";\n  }\n  // copy data\n  Dtype* data_vec = mutable_cpu_data();\n  if (proto.double_data_size() > 0) {\n    CHECK_EQ(count_, proto.double_data_size());\n    for (int i = 0; i < count_; ++i) {\n      data_vec[i] = proto.double_data(i);\n    }\n  } else {\n    CHECK_EQ(count_, proto.data_size());\n    for (int i = 0; i < count_; ++i) {\n      data_vec[i] = proto.data(i);\n    }\n  }\n  if (proto.double_diff_size() > 0) {\n    CHECK_EQ(count_, proto.double_diff_size());\n    Dtype* diff_vec = mutable_cpu_diff();\n    for (int i = 0; i < count_; ++i) {\n      diff_vec[i] = proto.double_diff(i);\n    }\n  } else if (proto.diff_size() > 0) {\n    CHECK_EQ(count_, proto.diff_size());\n    Dtype* diff_vec = mutable_cpu_diff();\n    for (int i = 0; i < count_; ++i) {\n      diff_vec[i] = proto.diff(i);\n    }\n  }\n}\n\ntemplate <>\nvoid Blob<double>::ToProto(BlobProto* proto, bool write_diff) const {\n  proto->clear_shape();\n  for (int i = 0; i < shape_.size(); ++i) {\n    proto->mutable_shape()->add_dim(shape_[i]);\n  }\n  proto->clear_double_data();\n  proto->clear_double_diff();\n  const double* data_vec = cpu_data();\n  for (int i = 0; i < count_; ++i) {\n    proto->add_double_data(data_vec[i]);\n  }\n  if (write_diff) {\n    const double* diff_vec = cpu_diff();\n    for (int i = 0; i < count_; ++i) {\n      proto->add_double_diff(diff_vec[i]);\n    }\n  }\n}\n\ntemplate <>\nvoid Blob<float>::ToProto(BlobProto* proto, bool write_diff) const {\n  proto->clear_shape();\n  for (int i = 0; i < shape_.size(); ++i) {\n    proto->mutable_shape()->add_dim(shape_[i]);\n  }\n  proto->clear_data();\n  proto->clear_diff();\n  const float* data_vec = cpu_data();\n  for (int i = 0; i < count_; ++i) {\n    proto->add_data(data_vec[i]);\n  }\n  if (write_diff) {\n    const float* diff_vec = cpu_diff();\n    for (int i = 0; i < count_; ++i) {\n      proto->add_diff(diff_vec[i]);\n    }\n  }\n}\n\nINSTANTIATE_CLASS(Blob);\ntemplate class Blob<int>;\ntemplate class Blob<unsigned int>;\n\n}  // namespace caffe\n\n"
  },
  {
    "path": "src/caffe/common.cpp",
    "content": "#include <boost/thread.hpp>\n#include <glog/logging.h>\n#include <cstdio>\n#include <ctime>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/rng.hpp\"\n\nnamespace caffe {\n\n// Make sure each thread can have different values.\nstatic boost::thread_specific_ptr<Caffe> thread_instance_;\n\nCaffe& Caffe::Get() {\n  if (!thread_instance_.get()) {\n    thread_instance_.reset(new Caffe());\n  }\n  return *(thread_instance_.get());\n}\n\n// random seeding\nint64_t cluster_seedgen(void) {\n  int64_t s, seed, pid;\n  FILE* f = fopen(\"/dev/urandom\", \"rb\");\n  if (f && fread(&seed, 1, sizeof(seed), f) == sizeof(seed)) {\n    fclose(f);\n    return seed;\n  }\n\n  LOG(INFO) << \"System entropy source not available, \"\n              \"using fallback algorithm to generate seed instead.\";\n  if (f)\n    fclose(f);\n\n  pid = getpid();\n  s = time(NULL);\n  seed = abs(((s * 181) * ((pid - 83) * 359)) % 104729);\n  return seed;\n}\n\n\nvoid GlobalInit(int* pargc, char*** pargv) {\n  // Google flags.\n  ::gflags::ParseCommandLineFlags(pargc, pargv, true);\n  // Google logging.\n  ::google::InitGoogleLogging(*(pargv)[0]);\n  // Provide a backtrace on segfault.\n  ::google::InstallFailureSignalHandler();\n}\n\n#ifdef CPU_ONLY  // CPU-only Caffe.\n\nCaffe::Caffe()\n    : random_generator_(), mode_(Caffe::CPU),\n      solver_count_(1), root_solver_(true) { }\n\nCaffe::~Caffe() { }\n\nvoid Caffe::set_random_seed(const unsigned int seed) {\n  // RNG seed\n  Get().random_generator_.reset(new RNG(seed));\n}\n\nvoid Caffe::SetDevice(const int device_id) {\n  NO_GPU;\n}\n\nvoid Caffe::DeviceQuery() {\n  NO_GPU;\n}\n\n\nclass Caffe::RNG::Generator {\n public:\n  Generator() : rng_(new caffe::rng_t(cluster_seedgen())) {}\n  explicit Generator(unsigned int seed) : rng_(new caffe::rng_t(seed)) {}\n  caffe::rng_t* rng() { return rng_.get(); }\n private:\n  shared_ptr<caffe::rng_t> rng_;\n};\n\nCaffe::RNG::RNG() : generator_(new Generator()) { }\n\nCaffe::RNG::RNG(unsigned int seed) : generator_(new Generator(seed)) { }\n\nCaffe::RNG& Caffe::RNG::operator=(const RNG& other) {\n  generator_ = other.generator_;\n  return *this;\n}\n\nvoid* Caffe::RNG::generator() {\n  return static_cast<void*>(generator_->rng());\n}\n\n#else  // Normal GPU + CPU Caffe.\n\nCaffe::Caffe()\n    : cublas_handle_(NULL), curand_generator_(NULL), random_generator_(),\n    mode_(Caffe::CPU), solver_count_(1), root_solver_(true) {\n  // Try to create a cublas handler, and report an error if failed (but we will\n  // keep the program running as one might just want to run CPU code).\n  if (cublasCreate(&cublas_handle_) != CUBLAS_STATUS_SUCCESS) {\n    LOG(ERROR) << \"Cannot create Cublas handle. Cublas won't be available.\";\n  }\n  // Try to create a curand handler.\n  if (curandCreateGenerator(&curand_generator_, CURAND_RNG_PSEUDO_DEFAULT)\n      != CURAND_STATUS_SUCCESS ||\n      curandSetPseudoRandomGeneratorSeed(curand_generator_, cluster_seedgen())\n      != CURAND_STATUS_SUCCESS) {\n    LOG(ERROR) << \"Cannot create Curand generator. Curand won't be available.\";\n  }\n}\n\nCaffe::~Caffe() {\n  if (cublas_handle_) CUBLAS_CHECK(cublasDestroy(cublas_handle_));\n  if (curand_generator_) {\n    CURAND_CHECK(curandDestroyGenerator(curand_generator_));\n  }\n}\n\nvoid Caffe::set_random_seed(const unsigned int seed) {\n  // Curand seed\n  static bool g_curand_availability_logged = false;\n  if (Get().curand_generator_) {\n    CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(curand_generator(),\n        seed));\n    CURAND_CHECK(curandSetGeneratorOffset(curand_generator(), 0));\n  } else {\n    if (!g_curand_availability_logged) {\n        LOG(ERROR) <<\n            \"Curand not available. Skipping setting the curand seed.\";\n        g_curand_availability_logged = true;\n    }\n  }\n  // RNG seed\n  Get().random_generator_.reset(new RNG(seed));\n}\n\nvoid Caffe::SetDevice(const int device_id) {\n  int current_device;\n  CUDA_CHECK(cudaGetDevice(&current_device));\n  if (current_device == device_id) {\n    return;\n  }\n  // The call to cudaSetDevice must come before any calls to Get, which\n  // may perform initialization using the GPU.\n  CUDA_CHECK(cudaSetDevice(device_id));\n  if (Get().cublas_handle_) CUBLAS_CHECK(cublasDestroy(Get().cublas_handle_));\n  if (Get().curand_generator_) {\n    CURAND_CHECK(curandDestroyGenerator(Get().curand_generator_));\n  }\n  CUBLAS_CHECK(cublasCreate(&Get().cublas_handle_));\n  CURAND_CHECK(curandCreateGenerator(&Get().curand_generator_,\n      CURAND_RNG_PSEUDO_DEFAULT));\n  CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(Get().curand_generator_,\n      cluster_seedgen()));\n}\n\nvoid Caffe::DeviceQuery() {\n  cudaDeviceProp prop;\n  int device;\n  if (cudaSuccess != cudaGetDevice(&device)) {\n    printf(\"No cuda device present.\\n\");\n    return;\n  }\n  CUDA_CHECK(cudaGetDeviceProperties(&prop, device));\n  LOG(INFO) << \"Device id:                     \" << device;\n  LOG(INFO) << \"Major revision number:         \" << prop.major;\n  LOG(INFO) << \"Minor revision number:         \" << prop.minor;\n  LOG(INFO) << \"Name:                          \" << prop.name;\n  LOG(INFO) << \"Total global memory:           \" << prop.totalGlobalMem;\n  LOG(INFO) << \"Total shared memory per block: \" << prop.sharedMemPerBlock;\n  LOG(INFO) << \"Total registers per block:     \" << prop.regsPerBlock;\n  LOG(INFO) << \"Warp size:                     \" << prop.warpSize;\n  LOG(INFO) << \"Maximum memory pitch:          \" << prop.memPitch;\n  LOG(INFO) << \"Maximum threads per block:     \" << prop.maxThreadsPerBlock;\n  LOG(INFO) << \"Maximum dimension of block:    \"\n      << prop.maxThreadsDim[0] << \", \" << prop.maxThreadsDim[1] << \", \"\n      << prop.maxThreadsDim[2];\n  LOG(INFO) << \"Maximum dimension of grid:     \"\n      << prop.maxGridSize[0] << \", \" << prop.maxGridSize[1] << \", \"\n      << prop.maxGridSize[2];\n  LOG(INFO) << \"Clock rate:                    \" << prop.clockRate;\n  LOG(INFO) << \"Total constant memory:         \" << prop.totalConstMem;\n  LOG(INFO) << \"Texture alignment:             \" << prop.textureAlignment;\n  LOG(INFO) << \"Concurrent copy and execution: \"\n      << (prop.deviceOverlap ? \"Yes\" : \"No\");\n  LOG(INFO) << \"Number of multiprocessors:     \" << prop.multiProcessorCount;\n  LOG(INFO) << \"Kernel execution timeout:      \"\n      << (prop.kernelExecTimeoutEnabled ? \"Yes\" : \"No\");\n  return;\n}\n\n\nclass Caffe::RNG::Generator {\n public:\n  Generator() : rng_(new caffe::rng_t(cluster_seedgen())) {}\n  explicit Generator(unsigned int seed) : rng_(new caffe::rng_t(seed)) {}\n  caffe::rng_t* rng() { return rng_.get(); }\n private:\n  shared_ptr<caffe::rng_t> rng_;\n};\n\nCaffe::RNG::RNG() : generator_(new Generator()) { }\n\nCaffe::RNG::RNG(unsigned int seed) : generator_(new Generator(seed)) { }\n\nCaffe::RNG& Caffe::RNG::operator=(const RNG& other) {\n  generator_.reset(other.generator_.get());\n  return *this;\n}\n\nvoid* Caffe::RNG::generator() {\n  return static_cast<void*>(generator_->rng());\n}\n\nconst char* cublasGetErrorString(cublasStatus_t error) {\n  switch (error) {\n  case CUBLAS_STATUS_SUCCESS:\n    return \"CUBLAS_STATUS_SUCCESS\";\n  case CUBLAS_STATUS_NOT_INITIALIZED:\n    return \"CUBLAS_STATUS_NOT_INITIALIZED\";\n  case CUBLAS_STATUS_ALLOC_FAILED:\n    return \"CUBLAS_STATUS_ALLOC_FAILED\";\n  case CUBLAS_STATUS_INVALID_VALUE:\n    return \"CUBLAS_STATUS_INVALID_VALUE\";\n  case CUBLAS_STATUS_ARCH_MISMATCH:\n    return \"CUBLAS_STATUS_ARCH_MISMATCH\";\n  case CUBLAS_STATUS_MAPPING_ERROR:\n    return \"CUBLAS_STATUS_MAPPING_ERROR\";\n  case CUBLAS_STATUS_EXECUTION_FAILED:\n    return \"CUBLAS_STATUS_EXECUTION_FAILED\";\n  case CUBLAS_STATUS_INTERNAL_ERROR:\n    return \"CUBLAS_STATUS_INTERNAL_ERROR\";\n#if CUDA_VERSION >= 6000\n  case CUBLAS_STATUS_NOT_SUPPORTED:\n    return \"CUBLAS_STATUS_NOT_SUPPORTED\";\n#endif\n#if CUDA_VERSION >= 6050\n  case CUBLAS_STATUS_LICENSE_ERROR:\n    return \"CUBLAS_STATUS_LICENSE_ERROR\";\n#endif\n  }\n  return \"Unknown cublas status\";\n}\n\nconst char* curandGetErrorString(curandStatus_t error) {\n  switch (error) {\n  case CURAND_STATUS_SUCCESS:\n    return \"CURAND_STATUS_SUCCESS\";\n  case CURAND_STATUS_VERSION_MISMATCH:\n    return \"CURAND_STATUS_VERSION_MISMATCH\";\n  case CURAND_STATUS_NOT_INITIALIZED:\n    return \"CURAND_STATUS_NOT_INITIALIZED\";\n  case CURAND_STATUS_ALLOCATION_FAILED:\n    return \"CURAND_STATUS_ALLOCATION_FAILED\";\n  case CURAND_STATUS_TYPE_ERROR:\n    return \"CURAND_STATUS_TYPE_ERROR\";\n  case CURAND_STATUS_OUT_OF_RANGE:\n    return \"CURAND_STATUS_OUT_OF_RANGE\";\n  case CURAND_STATUS_LENGTH_NOT_MULTIPLE:\n    return \"CURAND_STATUS_LENGTH_NOT_MULTIPLE\";\n  case CURAND_STATUS_DOUBLE_PRECISION_REQUIRED:\n    return \"CURAND_STATUS_DOUBLE_PRECISION_REQUIRED\";\n  case CURAND_STATUS_LAUNCH_FAILURE:\n    return \"CURAND_STATUS_LAUNCH_FAILURE\";\n  case CURAND_STATUS_PREEXISTING_FAILURE:\n    return \"CURAND_STATUS_PREEXISTING_FAILURE\";\n  case CURAND_STATUS_INITIALIZATION_FAILED:\n    return \"CURAND_STATUS_INITIALIZATION_FAILED\";\n  case CURAND_STATUS_ARCH_MISMATCH:\n    return \"CURAND_STATUS_ARCH_MISMATCH\";\n  case CURAND_STATUS_INTERNAL_ERROR:\n    return \"CURAND_STATUS_INTERNAL_ERROR\";\n  }\n  return \"Unknown curand status\";\n}\n\n#endif  // CPU_ONLY\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/data_reader.cpp",
    "content": "#include <boost/thread.hpp>\n#include <map>\n#include <string>\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/data_reader.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n\nnamespace caffe {\n\nusing boost::weak_ptr;\n\nmap<const string, weak_ptr<DataReader::Body> > DataReader::bodies_;\nstatic boost::mutex bodies_mutex_;\n\nDataReader::DataReader(const LayerParameter& param)\n    : queue_pair_(new QueuePair(  //\n        param.data_param().prefetch() * param.data_param().batch_size())) {\n  // Get or create a body\n  boost::mutex::scoped_lock lock(bodies_mutex_);\n  string key = source_key(param);\n  weak_ptr<Body>& weak = bodies_[key];\n  body_ = weak.lock();\n  if (!body_) {\n    body_.reset(new Body(param));\n    bodies_[key] = weak_ptr<Body>(body_);\n  }\n  body_->new_queue_pairs_.push(queue_pair_);\n}\n\nDataReader::~DataReader() {\n  string key = source_key(body_->param_);\n  body_.reset();\n  boost::mutex::scoped_lock lock(bodies_mutex_);\n  if (bodies_[key].expired()) {\n    bodies_.erase(key);\n  }\n}\n\n//\n\nDataReader::QueuePair::QueuePair(int size) {\n  // Initialize the free queue with requested number of datums\n  for (int i = 0; i < size; ++i) {\n    free_.push(new Datum());\n  }\n}\n\nDataReader::QueuePair::~QueuePair() {\n  Datum* datum;\n  while (free_.try_pop(&datum)) {\n    delete datum;\n  }\n  while (full_.try_pop(&datum)) {\n    delete datum;\n  }\n}\n\n//\n\nDataReader::Body::Body(const LayerParameter& param)\n    : param_(param),\n      new_queue_pairs_() {\n  StartInternalThread();\n}\n\nDataReader::Body::~Body() {\n  StopInternalThread();\n}\n\nvoid DataReader::Body::InternalThreadEntry() {\n  shared_ptr<db::DB> db(db::GetDB(param_.data_param().backend()));\n  db->Open(param_.data_param().source(), db::READ);\n  shared_ptr<db::Cursor> cursor(db->NewCursor());\n  vector<shared_ptr<QueuePair> > qps;\n  try {\n    int solver_count = param_.phase() == TRAIN ? Caffe::solver_count() : 1;\n\n    // To ensure deterministic runs, only start running once all solvers\n    // are ready. But solvers need to peek on one item during initialization,\n    // so read one item, then wait for the next solver.\n    for (int i = 0; i < solver_count; ++i) {\n      shared_ptr<QueuePair> qp(new_queue_pairs_.pop());\n      read_one(cursor.get(), qp.get());\n      qps.push_back(qp);\n    }\n    // Main loop\n    while (!must_stop()) {\n      for (int i = 0; i < solver_count; ++i) {\n        read_one(cursor.get(), qps[i].get());\n      }\n      // Check no additional readers have been created. This can happen if\n      // more than one net is trained at a time per process, whether single\n      // or multi solver. It might also happen if two data layers have same\n      // name and same source.\n      CHECK_EQ(new_queue_pairs_.size(), 0);\n    }\n  } catch (boost::thread_interrupted&) {\n    // Interrupted exception is expected on shutdown\n  }\n}\n\nvoid DataReader::Body::read_one(db::Cursor* cursor, QueuePair* qp) {\n  Datum* datum = qp->free_.pop();\n  // TODO deserialize in-place instead of copy?\n  datum->ParseFromString(cursor->value());\n  qp->full_.push(datum);\n\n  // go to the next iter\n  cursor->Next();\n  if (!cursor->valid()) {\n    DLOG(INFO) << \"Restarting data prefetching from start.\";\n    cursor->SeekToFirst();\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/data_transformer.cpp",
    "content": "#include <opencv2/core/core.hpp>\n\n#include <string>\n#include <vector>\n\n#include \"caffe/data_transformer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/util/rng.hpp\"\n\nnamespace caffe {\n\ntemplate<typename Dtype>\nDataTransformer<Dtype>::DataTransformer(const TransformationParameter& param,\n    Phase phase)\n    : param_(param), phase_(phase) {\n  // check if we want to use mean_file\n  if (param_.has_mean_file()) {\n    CHECK_EQ(param_.mean_value_size(), 0) <<\n      \"Cannot specify mean_file and mean_value at the same time\";\n    const string& mean_file = param.mean_file();\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"Loading mean file from: \" << mean_file;\n    }\n    BlobProto blob_proto;\n    ReadProtoFromBinaryFileOrDie(mean_file.c_str(), &blob_proto);\n    data_mean_.FromProto(blob_proto);\n  }\n  // check if we want to use mean_value\n  if (param_.mean_value_size() > 0) {\n    CHECK(param_.has_mean_file() == false) <<\n      \"Cannot specify mean_file and mean_value at the same time\";\n    for (int c = 0; c < param_.mean_value_size(); ++c) {\n      mean_values_.push_back(param_.mean_value(c));\n    }\n  }\n}\n\ntemplate<typename Dtype>\nvoid DataTransformer<Dtype>::Transform(const Datum& datum,\n                                       Dtype* transformed_data) {\n  const string& data = datum.data();\n  const int datum_channels = datum.channels();\n  const int datum_height = datum.height();\n  const int datum_width = datum.width();\n\n  const int crop_size = param_.crop_size();\n  const Dtype scale = param_.scale();\n  const bool do_mirror = param_.mirror() && Rand(2);\n  const bool has_mean_file = param_.has_mean_file();\n  const bool has_uint8 = data.size() > 0;\n  const bool has_mean_values = mean_values_.size() > 0;\n\n  CHECK_GT(datum_channels, 0);\n  CHECK_GE(datum_height, crop_size);\n  CHECK_GE(datum_width, crop_size);\n\n  Dtype* mean = NULL;\n  if (has_mean_file) {\n    CHECK_EQ(datum_channels, data_mean_.channels());\n    CHECK_EQ(datum_height, data_mean_.height());\n    CHECK_EQ(datum_width, data_mean_.width());\n    mean = data_mean_.mutable_cpu_data();\n  }\n  if (has_mean_values) {\n    CHECK(mean_values_.size() == 1 || mean_values_.size() == datum_channels) <<\n     \"Specify either 1 mean_value or as many as channels: \" << datum_channels;\n    if (datum_channels > 1 && mean_values_.size() == 1) {\n      // Replicate the mean_value for simplicity\n      for (int c = 1; c < datum_channels; ++c) {\n        mean_values_.push_back(mean_values_[0]);\n      }\n    }\n  }\n\n  int height = datum_height;\n  int width = datum_width;\n\n  int h_off = 0;\n  int w_off = 0;\n  if (crop_size) {\n    height = crop_size;\n    width = crop_size;\n    // We only do random crop when we do training.\n    if (phase_ == TRAIN) {\n      h_off = Rand(datum_height - crop_size + 1);\n      w_off = Rand(datum_width - crop_size + 1);\n    } else {\n      h_off = (datum_height - crop_size) / 2;\n      w_off = (datum_width - crop_size) / 2;\n    }\n  }\n\n  Dtype datum_element;\n  int top_index, data_index;\n  for (int c = 0; c < datum_channels; ++c) {\n    for (int h = 0; h < height; ++h) {\n      for (int w = 0; w < width; ++w) {\n        data_index = (c * datum_height + h_off + h) * datum_width + w_off + w;\n        if (do_mirror) {\n          top_index = (c * height + h) * width + (width - 1 - w);\n        } else {\n          top_index = (c * height + h) * width + w;\n        }\n        if (has_uint8) {\n          datum_element =\n            static_cast<Dtype>(static_cast<uint8_t>(data[data_index]));\n        } else {\n          datum_element = datum.float_data(data_index);\n        }\n        if (has_mean_file) {\n          transformed_data[top_index] =\n            (datum_element - mean[data_index]) * scale;\n        } else {\n          if (has_mean_values) {\n            transformed_data[top_index] =\n              (datum_element - mean_values_[c]) * scale;\n          } else {\n            transformed_data[top_index] = datum_element * scale;\n          }\n        }\n      }\n    }\n  }\n}\n\ntemplate<typename Dtype>\nvoid DataTransformer<Dtype>::Transform(const Datum& datum,\n                                       Blob<Dtype>* transformed_blob) {\n  // If datum is encoded, decoded and transform the cv::image.\n  if (datum.encoded()) {\n    CHECK(!(param_.force_color() && param_.force_gray()))\n        << \"cannot set both force_color and force_gray\";\n    cv::Mat cv_img;\n    if (param_.force_color() || param_.force_gray()) {\n    // If force_color then decode in color otherwise decode in gray.\n      cv_img = DecodeDatumToCVMat(datum, param_.force_color());\n    } else {\n      cv_img = DecodeDatumToCVMatNative(datum);\n    }\n    // Transform the cv::image into blob.\n    return Transform(cv_img, transformed_blob);\n  } else {\n    if (param_.force_color() || param_.force_gray()) {\n      LOG(ERROR) << \"force_color and force_gray only for encoded datum\";\n    }\n  }\n\n  const int crop_size = param_.crop_size();\n  const int datum_channels = datum.channels();\n  const int datum_height = datum.height();\n  const int datum_width = datum.width();\n\n  // Check dimensions.\n  const int channels = transformed_blob->channels();\n  const int height = transformed_blob->height();\n  const int width = transformed_blob->width();\n  const int num = transformed_blob->num();\n\n  CHECK_EQ(channels, datum_channels);\n  CHECK_LE(height, datum_height);\n  CHECK_LE(width, datum_width);\n  CHECK_GE(num, 1);\n\n  if (crop_size) {\n    CHECK_EQ(crop_size, height);\n    CHECK_EQ(crop_size, width);\n  } else {\n    CHECK_EQ(datum_height, height);\n    CHECK_EQ(datum_width, width);\n  }\n\n  Dtype* transformed_data = transformed_blob->mutable_cpu_data();\n  Transform(datum, transformed_data);\n}\n\ntemplate<typename Dtype>\nvoid DataTransformer<Dtype>::Transform(const vector<Datum> & datum_vector,\n                                       Blob<Dtype>* transformed_blob) {\n  const int datum_num = datum_vector.size();\n  const int num = transformed_blob->num();\n  const int channels = transformed_blob->channels();\n  const int height = transformed_blob->height();\n  const int width = transformed_blob->width();\n\n  CHECK_GT(datum_num, 0) << \"There is no datum to add\";\n  CHECK_LE(datum_num, num) <<\n    \"The size of datum_vector must be no greater than transformed_blob->num()\";\n  Blob<Dtype> uni_blob(1, channels, height, width);\n  for (int item_id = 0; item_id < datum_num; ++item_id) {\n    int offset = transformed_blob->offset(item_id);\n    uni_blob.set_cpu_data(transformed_blob->mutable_cpu_data() + offset);\n    Transform(datum_vector[item_id], &uni_blob);\n  }\n}\n\ntemplate<typename Dtype>\nvoid DataTransformer<Dtype>::Transform(const vector<cv::Mat> & mat_vector,\n                                       Blob<Dtype>* transformed_blob) {\n  const int mat_num = mat_vector.size();\n  const int num = transformed_blob->num();\n  const int channels = transformed_blob->channels();\n  const int height = transformed_blob->height();\n  const int width = transformed_blob->width();\n\n  CHECK_GT(mat_num, 0) << \"There is no MAT to add\";\n  CHECK_EQ(mat_num, num) <<\n    \"The size of mat_vector must be equals to transformed_blob->num()\";\n  Blob<Dtype> uni_blob(1, channels, height, width);\n  for (int item_id = 0; item_id < mat_num; ++item_id) {\n    int offset = transformed_blob->offset(item_id);\n    uni_blob.set_cpu_data(transformed_blob->mutable_cpu_data() + offset);\n    Transform(mat_vector[item_id], &uni_blob);\n  }\n}\n\ntemplate<typename Dtype>\nvoid DataTransformer<Dtype>::Transform(const cv::Mat& cv_img,\n                                       Blob<Dtype>* transformed_blob) {\n  const int crop_size = param_.crop_size();\n  const int img_channels = cv_img.channels();\n  const int img_height = cv_img.rows;\n  const int img_width = cv_img.cols;\n\n  // Check dimensions.\n  const int channels = transformed_blob->channels();\n  const int height = transformed_blob->height();\n  const int width = transformed_blob->width();\n  const int num = transformed_blob->num();\n\n  CHECK_EQ(channels, img_channels);\n  CHECK_LE(height, img_height);\n  CHECK_LE(width, img_width);\n  CHECK_GE(num, 1);\n\n  CHECK(cv_img.depth() == CV_8U) << \"Image data type must be unsigned byte\";\n\n  const Dtype scale = param_.scale();\n  const bool do_mirror = param_.mirror() && Rand(2);\n  const bool has_mean_file = param_.has_mean_file();\n  const bool has_mean_values = mean_values_.size() > 0;\n\n  CHECK_GT(img_channels, 0);\n  CHECK_GE(img_height, crop_size);\n  CHECK_GE(img_width, crop_size);\n\n  Dtype* mean = NULL;\n  if (has_mean_file) {\n    CHECK_EQ(img_channels, data_mean_.channels());\n    CHECK_EQ(img_height, data_mean_.height());\n    CHECK_EQ(img_width, data_mean_.width());\n    mean = data_mean_.mutable_cpu_data();\n  }\n  if (has_mean_values) {\n    CHECK(mean_values_.size() == 1 || mean_values_.size() == img_channels) <<\n     \"Specify either 1 mean_value or as many as channels: \" << img_channels;\n    if (img_channels > 1 && mean_values_.size() == 1) {\n      // Replicate the mean_value for simplicity\n      for (int c = 1; c < img_channels; ++c) {\n        mean_values_.push_back(mean_values_[0]);\n      }\n    }\n  }\n\n  int h_off = 0;\n  int w_off = 0;\n  cv::Mat cv_cropped_img = cv_img;\n  if (crop_size) {\n    CHECK_EQ(crop_size, height);\n    CHECK_EQ(crop_size, width);\n    // We only do random crop when we do training.\n    if (phase_ == TRAIN) {\n      h_off = Rand(img_height - crop_size + 1);\n      w_off = Rand(img_width - crop_size + 1);\n    } else {\n      h_off = (img_height - crop_size) / 2;\n      w_off = (img_width - crop_size) / 2;\n    }\n    cv::Rect roi(w_off, h_off, crop_size, crop_size);\n    cv_cropped_img = cv_img(roi);\n  } else {\n    CHECK_EQ(img_height, height);\n    CHECK_EQ(img_width, width);\n  }\n\n  CHECK(cv_cropped_img.data);\n\n  Dtype* transformed_data = transformed_blob->mutable_cpu_data();\n  int top_index;\n  for (int h = 0; h < height; ++h) {\n    const uchar* ptr = cv_cropped_img.ptr<uchar>(h);\n    int img_index = 0;\n    for (int w = 0; w < width; ++w) {\n      for (int c = 0; c < img_channels; ++c) {\n        if (do_mirror) {\n          top_index = (c * height + h) * width + (width - 1 - w);\n        } else {\n          top_index = (c * height + h) * width + w;\n        }\n        // int top_index = (c * height + h) * width + w;\n        Dtype pixel = static_cast<Dtype>(ptr[img_index++]);\n        if (has_mean_file) {\n          int mean_index = (c * img_height + h_off + h) * img_width + w_off + w;\n          transformed_data[top_index] =\n            (pixel - mean[mean_index]) * scale;\n        } else {\n          if (has_mean_values) {\n            transformed_data[top_index] =\n              (pixel - mean_values_[c]) * scale;\n          } else {\n            transformed_data[top_index] = pixel * scale;\n          }\n        }\n      }\n    }\n  }\n}\n\ntemplate<typename Dtype>\nvoid DataTransformer<Dtype>::Transform(Blob<Dtype>* input_blob,\n                                       Blob<Dtype>* transformed_blob) {\n  const int crop_size = param_.crop_size();\n  const int input_num = input_blob->num();\n  const int input_channels = input_blob->channels();\n  const int input_height = input_blob->height();\n  const int input_width = input_blob->width();\n\n  if (transformed_blob->count() == 0) {\n    // Initialize transformed_blob with the right shape.\n    if (crop_size) {\n      transformed_blob->Reshape(input_num, input_channels,\n                                crop_size, crop_size);\n    } else {\n      transformed_blob->Reshape(input_num, input_channels,\n                                input_height, input_width);\n    }\n  }\n\n  const int num = transformed_blob->num();\n  const int channels = transformed_blob->channels();\n  const int height = transformed_blob->height();\n  const int width = transformed_blob->width();\n  const int size = transformed_blob->count();\n\n  CHECK_LE(input_num, num);\n  CHECK_EQ(input_channels, channels);\n  CHECK_GE(input_height, height);\n  CHECK_GE(input_width, width);\n\n\n  const Dtype scale = param_.scale();\n  const bool do_mirror = param_.mirror() && Rand(2);\n  const bool has_mean_file = param_.has_mean_file();\n  const bool has_mean_values = mean_values_.size() > 0;\n\n  int h_off = 0;\n  int w_off = 0;\n  if (crop_size) {\n    CHECK_EQ(crop_size, height);\n    CHECK_EQ(crop_size, width);\n    // We only do random crop when we do training.\n    if (phase_ == TRAIN) {\n      h_off = Rand(input_height - crop_size + 1);\n      w_off = Rand(input_width - crop_size + 1);\n    } else {\n      h_off = (input_height - crop_size) / 2;\n      w_off = (input_width - crop_size) / 2;\n    }\n  } else {\n    CHECK_EQ(input_height, height);\n    CHECK_EQ(input_width, width);\n  }\n\n  Dtype* input_data = input_blob->mutable_cpu_data();\n  if (has_mean_file) {\n    CHECK_EQ(input_channels, data_mean_.channels());\n    CHECK_EQ(input_height, data_mean_.height());\n    CHECK_EQ(input_width, data_mean_.width());\n    for (int n = 0; n < input_num; ++n) {\n      int offset = input_blob->offset(n);\n      caffe_sub(data_mean_.count(), input_data + offset,\n            data_mean_.cpu_data(), input_data + offset);\n    }\n  }\n\n  if (has_mean_values) {\n    CHECK(mean_values_.size() == 1 || mean_values_.size() == input_channels) <<\n     \"Specify either 1 mean_value or as many as channels: \" << input_channels;\n    if (mean_values_.size() == 1) {\n      caffe_add_scalar(input_blob->count(), -(mean_values_[0]), input_data);\n    } else {\n      for (int n = 0; n < input_num; ++n) {\n        for (int c = 0; c < input_channels; ++c) {\n          int offset = input_blob->offset(n, c);\n          caffe_add_scalar(input_height * input_width, -(mean_values_[c]),\n            input_data + offset);\n        }\n      }\n    }\n  }\n\n  Dtype* transformed_data = transformed_blob->mutable_cpu_data();\n\n  for (int n = 0; n < input_num; ++n) {\n    int top_index_n = n * channels;\n    int data_index_n = n * channels;\n    for (int c = 0; c < channels; ++c) {\n      int top_index_c = (top_index_n + c) * height;\n      int data_index_c = (data_index_n + c) * input_height + h_off;\n      for (int h = 0; h < height; ++h) {\n        int top_index_h = (top_index_c + h) * width;\n        int data_index_h = (data_index_c + h) * input_width + w_off;\n        if (do_mirror) {\n          int top_index_w = top_index_h + width - 1;\n          for (int w = 0; w < width; ++w) {\n            transformed_data[top_index_w-w] = input_data[data_index_h + w];\n          }\n        } else {\n          for (int w = 0; w < width; ++w) {\n            transformed_data[top_index_h + w] = input_data[data_index_h + w];\n          }\n        }\n      }\n    }\n  }\n  if (scale != Dtype(1)) {\n    DLOG(INFO) << \"Scale: \" << scale;\n    caffe_scal(size, scale, transformed_data);\n  }\n}\n\ntemplate<typename Dtype>\nvector<int> DataTransformer<Dtype>::InferBlobShape(const Datum& datum) {\n  if (datum.encoded()) {\n    CHECK(!(param_.force_color() && param_.force_gray()))\n        << \"cannot set both force_color and force_gray\";\n    cv::Mat cv_img;\n    if (param_.force_color() || param_.force_gray()) {\n    // If force_color then decode in color otherwise decode in gray.\n      cv_img = DecodeDatumToCVMat(datum, param_.force_color());\n    } else {\n      cv_img = DecodeDatumToCVMatNative(datum);\n    }\n    // InferBlobShape using the cv::image.\n    return InferBlobShape(cv_img);\n  }\n\n  const int crop_size = param_.crop_size();\n  const int datum_channels = datum.channels();\n  const int datum_height = datum.height();\n  const int datum_width = datum.width();\n  // Check dimensions.\n  CHECK_GT(datum_channels, 0);\n  CHECK_GE(datum_height, crop_size);\n  CHECK_GE(datum_width, crop_size);\n  // Build BlobShape.\n  vector<int> shape(4);\n  shape[0] = 1;\n  shape[1] = datum_channels;\n  shape[2] = (crop_size)? crop_size: datum_height;\n  shape[3] = (crop_size)? crop_size: datum_width;\n  return shape;\n}\n\ntemplate<typename Dtype>\nvector<int> DataTransformer<Dtype>::InferBlobShape(\n    const vector<Datum> & datum_vector) {\n  const int num = datum_vector.size();\n  CHECK_GT(num, 0) << \"There is no datum to in the vector\";\n  // Use first datum in the vector to InferBlobShape.\n  vector<int> shape = InferBlobShape(datum_vector[0]);\n  // Adjust num to the size of the vector.\n  shape[0] = num;\n  return shape;\n}\n\ntemplate<typename Dtype>\nvector<int> DataTransformer<Dtype>::InferBlobShape(const cv::Mat& cv_img) {\n  const int crop_size = param_.crop_size();\n  const int img_channels = cv_img.channels();\n  const int img_height = cv_img.rows;\n  const int img_width = cv_img.cols;\n  // Check dimensions.\n  CHECK_GT(img_channels, 0);\n  CHECK_GE(img_height, crop_size);\n  CHECK_GE(img_width, crop_size);\n  // Build BlobShape.\n  vector<int> shape(4);\n  shape[0] = 1;\n  shape[1] = img_channels;\n  shape[2] = (crop_size)? crop_size: img_height;\n  shape[3] = (crop_size)? crop_size: img_width;\n  return shape;\n}\n\ntemplate<typename Dtype>\nvector<int> DataTransformer<Dtype>::InferBlobShape(\n    const vector<cv::Mat> & mat_vector) {\n  const int num = mat_vector.size();\n  CHECK_GT(num, 0) << \"There is no cv_img to in the vector\";\n  // Use first cv_img in the vector to InferBlobShape.\n  vector<int> shape = InferBlobShape(mat_vector[0]);\n  // Adjust num to the size of the vector.\n  shape[0] = num;\n  return shape;\n}\n\ntemplate <typename Dtype>\nvoid DataTransformer<Dtype>::InitRand() {\n  const bool needs_rand = param_.mirror() ||\n      (phase_ == TRAIN && param_.crop_size());\n  if (needs_rand) {\n    const unsigned int rng_seed = caffe_rng_rand();\n    rng_.reset(new Caffe::RNG(rng_seed));\n  } else {\n    rng_.reset();\n  }\n}\n\ntemplate <typename Dtype>\nint DataTransformer<Dtype>::Rand(int n) {\n  CHECK(rng_);\n  CHECK_GT(n, 0);\n  caffe::rng_t* rng =\n      static_cast<caffe::rng_t*>(rng_->generator());\n  return ((*rng)() % n);\n}\n\nINSTANTIATE_CLASS(DataTransformer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/internal_thread.cpp",
    "content": "#include <boost/thread.hpp>\n#include <exception>\n\n#include \"caffe/internal_thread.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\nInternalThread::~InternalThread() {\n  StopInternalThread();\n}\n\nbool InternalThread::is_started() const {\n  return thread_ && thread_->joinable();\n}\n\nbool InternalThread::must_stop() {\n  return thread_ && thread_->interruption_requested();\n}\n\nvoid InternalThread::StartInternalThread() {\n  CHECK(!is_started()) << \"Threads should persist and not be restarted.\";\n\n  int device = 0;\n#ifndef CPU_ONLY\n  CUDA_CHECK(cudaGetDevice(&device));\n#endif\n  Caffe::Brew mode = Caffe::mode();\n  int rand_seed = caffe_rng_rand();\n  int solver_count = Caffe::solver_count();\n  bool root_solver = Caffe::root_solver();\n\n  try {\n    thread_.reset(new boost::thread(&InternalThread::entry, this, device, mode,\n          rand_seed, solver_count, root_solver));\n  } catch (std::exception& e) {\n    LOG(FATAL) << \"Thread exception: \" << e.what();\n  }\n}\n\nvoid InternalThread::entry(int device, Caffe::Brew mode, int rand_seed,\n    int solver_count, bool root_solver) {\n#ifndef CPU_ONLY\n  CUDA_CHECK(cudaSetDevice(device));\n#endif\n  Caffe::set_mode(mode);\n  Caffe::set_random_seed(rand_seed);\n  Caffe::set_solver_count(solver_count);\n  Caffe::set_root_solver(root_solver);\n\n  InternalThreadEntry();\n}\n\nvoid InternalThread::StopInternalThread() {\n  if (is_started()) {\n    thread_->interrupt();\n    try {\n      thread_->join();\n    } catch (boost::thread_interrupted&) {\n    } catch (std::exception& e) {\n      LOG(FATAL) << \"Thread exception: \" << e.what();\n    }\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layer.cpp",
    "content": "#include <boost/thread.hpp>\n#include \"caffe/layer.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid Layer<Dtype>::InitMutex() {\n  forward_mutex_.reset(new boost::mutex());\n}\n\ntemplate <typename Dtype>\nvoid Layer<Dtype>::Lock() {\n  if (IsShared()) {\n    forward_mutex_->lock();\n  }\n}\n\ntemplate <typename Dtype>\nvoid Layer<Dtype>::Unlock() {\n  if (IsShared()) {\n    forward_mutex_->unlock();\n  }\n}\n\nINSTANTIATE_CLASS(Layer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layer_factory.cpp",
    "content": "// Make sure we include Python.h before any system header\n// to avoid _POSIX_C_SOURCE redefinition\n#ifdef WITH_PYTHON_LAYER\n#include <boost/python.hpp>\n#endif\n#include <string>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/layer_factory.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/vision_layers.hpp\"\n\n#ifdef WITH_PYTHON_LAYER\n#include \"caffe/python_layer.hpp\"\n#endif\n\nnamespace caffe {\n\n// Get convolution layer according to engine.\ntemplate <typename Dtype>\nshared_ptr<Layer<Dtype> > GetConvolutionLayer(\n    const LayerParameter& param) {\n  ConvolutionParameter_Engine engine = param.convolution_param().engine();\n  if (engine == ConvolutionParameter_Engine_DEFAULT) {\n    engine = ConvolutionParameter_Engine_CAFFE;\n#ifdef USE_CUDNN\n    engine = ConvolutionParameter_Engine_CUDNN;\n#endif\n  }\n  if (engine == ConvolutionParameter_Engine_CAFFE) {\n    return shared_ptr<Layer<Dtype> >(new ConvolutionLayer<Dtype>(param));\n#ifdef USE_CUDNN\n  } else if (engine == ConvolutionParameter_Engine_CUDNN) {\n    return shared_ptr<Layer<Dtype> >(new CuDNNConvolutionLayer<Dtype>(param));\n#endif\n  } else {\n    LOG(FATAL) << \"Layer \" << param.name() << \" has unknown engine.\";\n  }\n}\n\nREGISTER_LAYER_CREATOR(Convolution, GetConvolutionLayer);\n\n/************ For dynamic network surgery ***************/\ntemplate <typename Dtype>\nshared_ptr<Layer<Dtype> > GetCConvolutionLayer(\n    const LayerParameter& param) {\n  ConvolutionParameter_Engine engine = param.convolution_param().engine();\n  if (engine == ConvolutionParameter_Engine_DEFAULT) {\n    engine = ConvolutionParameter_Engine_CAFFE;\n#ifdef USE_CUDNN\n    engine = ConvolutionParameter_Engine_CUDNN;\n#endif\n  }\n  if (engine == ConvolutionParameter_Engine_CAFFE) {\n    return shared_ptr<Layer<Dtype> >(new CConvolutionLayer<Dtype>(param));\n#ifdef USE_CUDNN\n  } else if (engine == CConvolutionParameter_Engine_CUDNN) {\n    return shared_ptr<Layer<Dtype> >(new CuDNNConvolutionLayer<Dtype>(param));\n#endif\n  } else {\n    LOG(FATAL) << \"Layer \" << param.name() << \" has unknown engine.\";\n  }\n}\n\n//Comment on this for the error \"Check failed: registry.count(type) == 0 (1 vs. 0) Layer type CConvolution already registered.\"\n//REGISTER_LAYER_CREATOR(CConvolution, GetCConvolutionLayer);\n/********************************************************/\n\n// Get pooling layer according to engine.\ntemplate <typename Dtype>\nshared_ptr<Layer<Dtype> > GetPoolingLayer(const LayerParameter& param) {\n  PoolingParameter_Engine engine = param.pooling_param().engine();\n  if (engine == PoolingParameter_Engine_DEFAULT) {\n    engine = PoolingParameter_Engine_CAFFE;\n#ifdef USE_CUDNN\n    engine = PoolingParameter_Engine_CUDNN;\n#endif\n  }\n  if (engine == PoolingParameter_Engine_CAFFE) {\n    return shared_ptr<Layer<Dtype> >(new PoolingLayer<Dtype>(param));\n#ifdef USE_CUDNN\n  } else if (engine == PoolingParameter_Engine_CUDNN) {\n    PoolingParameter p_param = param.pooling_param();\n    if (p_param.pad() || p_param.pad_h() || p_param.pad_w() ||\n        param.top_size() > 1) {\n      LOG(INFO) << \"CUDNN does not support padding or multiple tops. \"\n                << \"Using Caffe's own pooling layer.\";\n      return shared_ptr<Layer<Dtype> >(new PoolingLayer<Dtype>(param));\n    }\n    return shared_ptr<Layer<Dtype> >(new CuDNNPoolingLayer<Dtype>(param));\n#endif\n  } else {\n    LOG(FATAL) << \"Layer \" << param.name() << \" has unknown engine.\";\n  }\n}\n\nREGISTER_LAYER_CREATOR(Pooling, GetPoolingLayer);\n\n// Get relu layer according to engine.\ntemplate <typename Dtype>\nshared_ptr<Layer<Dtype> > GetReLULayer(const LayerParameter& param) {\n  ReLUParameter_Engine engine = param.relu_param().engine();\n  if (engine == ReLUParameter_Engine_DEFAULT) {\n    engine = ReLUParameter_Engine_CAFFE;\n#ifdef USE_CUDNN\n    engine = ReLUParameter_Engine_CUDNN;\n#endif\n  }\n  if (engine == ReLUParameter_Engine_CAFFE) {\n    return shared_ptr<Layer<Dtype> >(new ReLULayer<Dtype>(param));\n#ifdef USE_CUDNN\n  } else if (engine == ReLUParameter_Engine_CUDNN) {\n    return shared_ptr<Layer<Dtype> >(new CuDNNReLULayer<Dtype>(param));\n#endif\n  } else {\n    LOG(FATAL) << \"Layer \" << param.name() << \" has unknown engine.\";\n  }\n}\n\nREGISTER_LAYER_CREATOR(ReLU, GetReLULayer);\n\n// Get sigmoid layer according to engine.\ntemplate <typename Dtype>\nshared_ptr<Layer<Dtype> > GetSigmoidLayer(const LayerParameter& param) {\n  SigmoidParameter_Engine engine = param.sigmoid_param().engine();\n  if (engine == SigmoidParameter_Engine_DEFAULT) {\n    engine = SigmoidParameter_Engine_CAFFE;\n#ifdef USE_CUDNN\n    engine = SigmoidParameter_Engine_CUDNN;\n#endif\n  }\n  if (engine == SigmoidParameter_Engine_CAFFE) {\n    return shared_ptr<Layer<Dtype> >(new SigmoidLayer<Dtype>(param));\n#ifdef USE_CUDNN\n  } else if (engine == SigmoidParameter_Engine_CUDNN) {\n    return shared_ptr<Layer<Dtype> >(new CuDNNSigmoidLayer<Dtype>(param));\n#endif\n  } else {\n    LOG(FATAL) << \"Layer \" << param.name() << \" has unknown engine.\";\n  }\n}\n\nREGISTER_LAYER_CREATOR(Sigmoid, GetSigmoidLayer);\n\n// Get softmax layer according to engine.\ntemplate <typename Dtype>\nshared_ptr<Layer<Dtype> > GetSoftmaxLayer(const LayerParameter& param) {\n  SoftmaxParameter_Engine engine = param.softmax_param().engine();\n  if (engine == SoftmaxParameter_Engine_DEFAULT) {\n    engine = SoftmaxParameter_Engine_CAFFE;\n#ifdef USE_CUDNN\n    engine = SoftmaxParameter_Engine_CUDNN;\n#endif\n  }\n  if (engine == SoftmaxParameter_Engine_CAFFE) {\n    return shared_ptr<Layer<Dtype> >(new SoftmaxLayer<Dtype>(param));\n#ifdef USE_CUDNN\n  } else if (engine == SoftmaxParameter_Engine_CUDNN) {\n    return shared_ptr<Layer<Dtype> >(new CuDNNSoftmaxLayer<Dtype>(param));\n#endif\n  } else {\n    LOG(FATAL) << \"Layer \" << param.name() << \" has unknown engine.\";\n  }\n}\n\nREGISTER_LAYER_CREATOR(Softmax, GetSoftmaxLayer);\n\n// Get tanh layer according to engine.\ntemplate <typename Dtype>\nshared_ptr<Layer<Dtype> > GetTanHLayer(const LayerParameter& param) {\n  TanHParameter_Engine engine = param.tanh_param().engine();\n  if (engine == TanHParameter_Engine_DEFAULT) {\n    engine = TanHParameter_Engine_CAFFE;\n#ifdef USE_CUDNN\n    engine = TanHParameter_Engine_CUDNN;\n#endif\n  }\n  if (engine == TanHParameter_Engine_CAFFE) {\n    return shared_ptr<Layer<Dtype> >(new TanHLayer<Dtype>(param));\n#ifdef USE_CUDNN\n  } else if (engine == TanHParameter_Engine_CUDNN) {\n    return shared_ptr<Layer<Dtype> >(new CuDNNTanHLayer<Dtype>(param));\n#endif\n  } else {\n    LOG(FATAL) << \"Layer \" << param.name() << \" has unknown engine.\";\n  }\n}\n\nREGISTER_LAYER_CREATOR(TanH, GetTanHLayer);\n\n#ifdef WITH_PYTHON_LAYER\ntemplate <typename Dtype>\nshared_ptr<Layer<Dtype> > GetPythonLayer(const LayerParameter& param) {\n  Py_Initialize();\n  try {\n    bp::object module = bp::import(param.python_param().module().c_str());\n    bp::object layer = module.attr(param.python_param().layer().c_str())(param);\n    return bp::extract<shared_ptr<PythonLayer<Dtype> > >(layer)();\n  } catch (bp::error_already_set) {\n    PyErr_Print();\n    throw;\n  }\n}\n\nREGISTER_LAYER_CREATOR(Python, GetPythonLayer);\n#endif\n\n// Layers that use their constructor as their default creator should be\n// registered in their corresponding cpp files. Do not register them here.\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/absval_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/neuron_layers.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid AbsValLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  NeuronLayer<Dtype>::LayerSetUp(bottom, top);\n  CHECK_NE(top[0], bottom[0]) << this->type() << \" Layer does not \"\n    \"allow in-place computation.\";\n}\n\ntemplate <typename Dtype>\nvoid AbsValLayer<Dtype>::Forward_cpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  const int count = top[0]->count();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  caffe_abs(count, bottom[0]->cpu_data(), top_data);\n}\n\ntemplate <typename Dtype>\nvoid AbsValLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const int count = top[0]->count();\n  const Dtype* top_diff = top[0]->cpu_diff();\n  if (propagate_down[0]) {\n    const Dtype* bottom_data = bottom[0]->cpu_data();\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    caffe_cpu_sign(count, bottom_data, bottom_diff);\n    caffe_mul(count, bottom_diff, top_diff, bottom_diff);\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(AbsValLayer);\n#endif\n\nINSTANTIATE_CLASS(AbsValLayer);\nREGISTER_LAYER_CLASS(AbsVal);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/absval_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid AbsValLayer<Dtype>::Forward_gpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  const int count = top[0]->count();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  caffe_gpu_abs(count, bottom[0]->gpu_data(), top_data);\n}\n\ntemplate <typename Dtype>\nvoid AbsValLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const int count = top[0]->count();\n  const Dtype* top_diff = top[0]->gpu_diff();\n  if (propagate_down[0]) {\n    const Dtype* bottom_data = bottom[0]->gpu_data();\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    caffe_gpu_sign(count, bottom_data, bottom_diff);\n    caffe_gpu_mul(count, bottom_diff, top_diff, bottom_diff);\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(AbsValLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/accuracy_layer.cpp",
    "content": "#include <algorithm>\n#include <functional>\n#include <utility>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid AccuracyLayer<Dtype>::LayerSetUp(\n  const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  top_k_ = this->layer_param_.accuracy_param().top_k();\n\n  has_ignore_label_ =\n    this->layer_param_.accuracy_param().has_ignore_label();\n  if (has_ignore_label_) {\n    ignore_label_ = this->layer_param_.accuracy_param().ignore_label();\n  }\n}\n\ntemplate <typename Dtype>\nvoid AccuracyLayer<Dtype>::Reshape(\n  const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  CHECK_LE(top_k_, bottom[0]->count() / bottom[1]->count())\n      << \"top_k must be less than or equal to the number of classes.\";\n  label_axis_ =\n      bottom[0]->CanonicalAxisIndex(this->layer_param_.accuracy_param().axis());\n  outer_num_ = bottom[0]->count(0, label_axis_);\n  inner_num_ = bottom[0]->count(label_axis_ + 1);\n  CHECK_EQ(outer_num_ * inner_num_, bottom[1]->count())\n      << \"Number of labels must match number of predictions; \"\n      << \"e.g., if label axis == 1 and prediction shape is (N, C, H, W), \"\n      << \"label count (number of labels) must be N*H*W, \"\n      << \"with integer values in {0, 1, ..., C-1}.\";\n  vector<int> top_shape(0);  // Accuracy is a scalar; 0 axes.\n  top[0]->Reshape(top_shape);\n}\n\ntemplate <typename Dtype>\nvoid AccuracyLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  Dtype accuracy = 0;\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  const Dtype* bottom_label = bottom[1]->cpu_data();\n  const int dim = bottom[0]->count() / outer_num_;\n  const int num_labels = bottom[0]->shape(label_axis_);\n  vector<Dtype> maxval(top_k_+1);\n  vector<int> max_id(top_k_+1);\n  int count = 0;\n  for (int i = 0; i < outer_num_; ++i) {\n    for (int j = 0; j < inner_num_; ++j) {\n      const int label_value =\n          static_cast<int>(bottom_label[i * inner_num_ + j]);\n      if (has_ignore_label_ && label_value == ignore_label_) {\n        continue;\n      }\n      DCHECK_GE(label_value, 0);\n      DCHECK_LT(label_value, num_labels);\n      // Top-k accuracy\n      std::vector<std::pair<Dtype, int> > bottom_data_vector;\n      for (int k = 0; k < num_labels; ++k) {\n        bottom_data_vector.push_back(std::make_pair(\n            bottom_data[i * dim + k * inner_num_ + j], k));\n      }\n      std::partial_sort(\n          bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_,\n          bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >());\n      // check if true label is in top k predictions\n      for (int k = 0; k < top_k_; k++) {\n        if (bottom_data_vector[k].second == label_value) {\n          ++accuracy;\n          break;\n        }\n      }\n      ++count;\n    }\n  }\n\n  // LOG(INFO) << \"Accuracy: \" << accuracy;\n  top[0]->mutable_cpu_data()[0] = accuracy / count;\n  // Accuracy layer should not be used as a loss function.\n}\n\nINSTANTIATE_CLASS(AccuracyLayer);\nREGISTER_LAYER_CLASS(Accuracy);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/argmax_layer.cpp",
    "content": "#include <algorithm>\n#include <functional>\n#include <utility>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ArgMaxLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  out_max_val_ = this->layer_param_.argmax_param().out_max_val();\n  top_k_ = this->layer_param_.argmax_param().top_k();\n  CHECK_GE(top_k_, 1) << \" top k must not be less than 1.\";\n  CHECK_LE(top_k_, bottom[0]->count() / bottom[0]->num())\n      << \"top_k must be less than or equal to the number of classes.\";\n}\n\ntemplate <typename Dtype>\nvoid ArgMaxLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  if (out_max_val_) {\n    // Produces max_ind and max_val\n    top[0]->Reshape(bottom[0]->num(), 2, top_k_, 1);\n  } else {\n    // Produces only max_ind\n    top[0]->Reshape(bottom[0]->num(), 1, top_k_, 1);\n  }\n}\n\ntemplate <typename Dtype>\nvoid ArgMaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  int num = bottom[0]->num();\n  int dim = bottom[0]->count() / bottom[0]->num();\n  for (int i = 0; i < num; ++i) {\n    std::vector<std::pair<Dtype, int> > bottom_data_vector;\n    for (int j = 0; j < dim; ++j) {\n      bottom_data_vector.push_back(\n          std::make_pair(bottom_data[i * dim + j], j));\n    }\n    std::partial_sort(\n        bottom_data_vector.begin(), bottom_data_vector.begin() + top_k_,\n        bottom_data_vector.end(), std::greater<std::pair<Dtype, int> >());\n    for (int j = 0; j < top_k_; ++j) {\n      top_data[top[0]->offset(i, 0, j)] = bottom_data_vector[j].second;\n    }\n    if (out_max_val_) {\n      for (int j = 0; j < top_k_; ++j) {\n        top_data[top[0]->offset(i, 1, j)] = bottom_data_vector[j].first;\n      }\n    }\n  }\n}\n\nINSTANTIATE_CLASS(ArgMaxLayer);\nREGISTER_LAYER_CLASS(ArgMax);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/base_conv_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK_EQ(4, bottom[0]->num_axes()) << \"Input must have 4 axes, \"\n      << \"corresponding to (num, channels, height, width)\";\n  // Configure the kernel size, padding, stride, and inputs.\n  ConvolutionParameter conv_param = this->layer_param_.convolution_param();\n  CHECK(!conv_param.has_kernel_size() !=\n      !(conv_param.has_kernel_h() && conv_param.has_kernel_w()))\n      << \"Filter size is kernel_size OR kernel_h and kernel_w; not both\";\n  CHECK(conv_param.has_kernel_size() ||\n      (conv_param.has_kernel_h() && conv_param.has_kernel_w()))\n      << \"For non-square filters both kernel_h and kernel_w are required.\";\n  CHECK((!conv_param.has_pad() && conv_param.has_pad_h()\n      && conv_param.has_pad_w())\n      || (!conv_param.has_pad_h() && !conv_param.has_pad_w()))\n      << \"pad is pad OR pad_h and pad_w are required.\";\n  CHECK((!conv_param.has_stride() && conv_param.has_stride_h()\n      && conv_param.has_stride_w())\n      || (!conv_param.has_stride_h() && !conv_param.has_stride_w()))\n      << \"Stride is stride OR stride_h and stride_w are required.\";\n  if (conv_param.has_kernel_size()) {\n    kernel_h_ = kernel_w_ = conv_param.kernel_size();\n  } else {\n    kernel_h_ = conv_param.kernel_h();\n    kernel_w_ = conv_param.kernel_w();\n  }\n  CHECK_GT(kernel_h_, 0) << \"Filter dimensions cannot be zero.\";\n  CHECK_GT(kernel_w_, 0) << \"Filter dimensions cannot be zero.\";\n  if (!conv_param.has_pad_h()) {\n    pad_h_ = pad_w_ = conv_param.pad();\n  } else {\n    pad_h_ = conv_param.pad_h();\n    pad_w_ = conv_param.pad_w();\n  }\n  if (!conv_param.has_stride_h()) {\n    stride_h_ = stride_w_ = conv_param.stride();\n  } else {\n    stride_h_ = conv_param.stride_h();\n    stride_w_ = conv_param.stride_w();\n  }\n  // Special case: im2col is the identity for 1x1 convolution with stride 1\n  // and no padding, so flag for skipping the buffer and transformation.\n  is_1x1_ = kernel_w_ == 1 && kernel_h_ == 1\n      && stride_h_ == 1 && stride_w_ == 1 && pad_h_ == 0 && pad_w_ == 0;\n  // Configure output channels and groups.\n  channels_ = bottom[0]->channels();\n  num_output_ = this->layer_param_.convolution_param().num_output();\n  CHECK_GT(num_output_, 0);\n  group_ = this->layer_param_.convolution_param().group();\n  CHECK_EQ(channels_ % group_, 0);\n  CHECK_EQ(num_output_ % group_, 0)\n      << \"Number of output should be multiples of group.\";\n  if (reverse_dimensions()) {\n    conv_out_channels_ = channels_;\n    conv_in_channels_ = num_output_;\n  } else {\n    conv_out_channels_ = num_output_;\n    conv_in_channels_ = channels_;\n  }\n  // Handle the parameters: weights and biases.\n  // - blobs_[0] holds the filter weights\n  // - blobs_[1] holds the biases (optional)\n  bias_term_ = this->layer_param_.convolution_param().bias_term();\n  if (this->blobs_.size() > 0) {\n    LOG(INFO) << \"Skipping parameter initialization\";\n  } else {\n    if (bias_term_) {\n      this->blobs_.resize(2);\n    } else {\n      this->blobs_.resize(1);\n    }\n    // Initialize and fill the weights:\n    // output channels x input channels per-group x kernel height x kernel width\n    this->blobs_[0].reset(new Blob<Dtype>(\n        conv_out_channels_, conv_in_channels_ / group_, kernel_h_, kernel_w_));\n    shared_ptr<Filler<Dtype> > weight_filler(GetFiller<Dtype>(\n        this->layer_param_.convolution_param().weight_filler()));\n    weight_filler->Fill(this->blobs_[0].get());\n    // If necessary, initialize and fill the biases.\n    if (bias_term_) {\n      vector<int> bias_shape(1, num_output_);\n      this->blobs_[1].reset(new Blob<Dtype>(bias_shape));\n      shared_ptr<Filler<Dtype> > bias_filler(GetFiller<Dtype>(\n          this->layer_param_.convolution_param().bias_filler()));\n      bias_filler->Fill(this->blobs_[1].get());\n    }\n  }\n  // Propagate gradients to the parameters (as directed by backward pass).\n  this->param_propagate_down_.resize(this->blobs_.size(), true);\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK_EQ(4, bottom[0]->num_axes()) << \"Input must have 4 axes, \"\n      << \"corresponding to (num, channels, height, width)\";\n  num_ = bottom[0]->num();\n  height_ = bottom[0]->height();\n  width_ = bottom[0]->width();\n  CHECK_EQ(bottom[0]->channels(), channels_) << \"Input size incompatible with\"\n    \" convolution kernel.\";\n  // TODO: generalize to handle inputs of different shapes.\n  for (int bottom_id = 1; bottom_id < bottom.size(); ++bottom_id) {\n    CHECK_EQ(num_, bottom[bottom_id]->num()) << \"Inputs must have same num.\";\n    CHECK_EQ(channels_, bottom[bottom_id]->channels())\n        << \"Inputs must have same channels.\";\n    CHECK_EQ(height_, bottom[bottom_id]->height())\n        << \"Inputs must have same height.\";\n    CHECK_EQ(width_, bottom[bottom_id]->width())\n        << \"Inputs must have same width.\";\n  }\n  // Shape the tops.\n  compute_output_shape();\n  for (int top_id = 0; top_id < top.size(); ++top_id) {\n    top[top_id]->Reshape(num_, num_output_, height_out_, width_out_);\n  }\n  if (reverse_dimensions()) {\n    conv_in_height_ = height_out_;\n    conv_in_width_ = width_out_;\n    conv_out_spatial_dim_ = height_ * width_;\n  } else {\n    conv_in_height_ = height_;\n    conv_in_width_ = width_;\n    conv_out_spatial_dim_ = height_out_ * width_out_;\n  }\n  kernel_dim_ = conv_in_channels_ * kernel_h_ * kernel_w_;\n  weight_offset_ = conv_out_channels_ * kernel_dim_ / group_ / group_;\n  col_offset_ = kernel_dim_ * conv_out_spatial_dim_ / group_;\n  output_offset_ = conv_out_channels_ * conv_out_spatial_dim_ / group_;\n  // The im2col result buffer will only hold one image at a time to avoid\n  // overly large memory usage. In the special case of 1x1 convolution\n  // it goes lazily unused to save memory.\n  if (reverse_dimensions()) {\n    col_buffer_.Reshape(1, kernel_dim_, height_, width_);\n  } else {\n    col_buffer_.Reshape(1, kernel_dim_, height_out_, width_out_);\n  }\n  // Set up the all ones \"bias multiplier\" for adding biases by BLAS\n  if (bias_term_) {\n    vector<int> bias_multiplier_shape(1, height_out_ * width_out_);\n    bias_multiplier_.Reshape(bias_multiplier_shape);\n    caffe_set(bias_multiplier_.count(), Dtype(1),\n        bias_multiplier_.mutable_cpu_data());\n  }\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::forward_cpu_gemm(const Dtype* input,\n    const Dtype* weights, Dtype* output, bool skip_im2col) {\n  const Dtype* col_buff = input;\n  if (!is_1x1_) {\n    if (!skip_im2col) {\n      conv_im2col_cpu(input, col_buffer_.mutable_cpu_data());\n    }\n    col_buff = col_buffer_.cpu_data();\n  }\n  for (int g = 0; g < group_; ++g) {\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, conv_out_channels_ /\n        group_, conv_out_spatial_dim_, kernel_dim_ / group_,\n        (Dtype)1., weights + weight_offset_ * g, col_buff + col_offset_ * g,\n        (Dtype)0., output + output_offset_ * g);\n  }\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::forward_cpu_bias(Dtype* output,\n    const Dtype* bias) {\n  caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num_output_,\n      height_out_ * width_out_, 1, (Dtype)1., bias, bias_multiplier_.cpu_data(),\n      (Dtype)1., output);\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::backward_cpu_gemm(const Dtype* output,\n    const Dtype* weights, Dtype* input) {\n  Dtype* col_buff = col_buffer_.mutable_cpu_data();\n  if (is_1x1_) {\n    col_buff = input;\n  }\n  for (int g = 0; g < group_; ++g) {\n    caffe_cpu_gemm<Dtype>(CblasTrans, CblasNoTrans, kernel_dim_ / group_,\n        conv_out_spatial_dim_, conv_out_channels_ / group_,\n        (Dtype)1., weights + weight_offset_ * g, output + output_offset_ * g,\n        (Dtype)0., col_buff + col_offset_ * g);\n  }\n  if (!is_1x1_) {\n    conv_col2im_cpu(col_buff, input);\n  }\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::weight_cpu_gemm(const Dtype* input,\n    const Dtype* output, Dtype* weights) {\n  const Dtype* col_buff = input;\n  if (!is_1x1_) {\n    conv_im2col_cpu(input, col_buffer_.mutable_cpu_data());\n    col_buff = col_buffer_.cpu_data();\n  }\n  for (int g = 0; g < group_; ++g) {\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasTrans, conv_out_channels_ / group_,\n        kernel_dim_ / group_, conv_out_spatial_dim_,\n        (Dtype)1., output + output_offset_ * g, col_buff + col_offset_ * g,\n        (Dtype)1., weights + weight_offset_ * g);\n  }\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::backward_cpu_bias(Dtype* bias,\n    const Dtype* input) {\n  caffe_cpu_gemv<Dtype>(CblasNoTrans, num_output_, height_out_ * width_out_, 1.,\n      input, bias_multiplier_.cpu_data(), 1., bias);\n}\n\n#ifndef CPU_ONLY\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::forward_gpu_gemm(const Dtype* input,\n    const Dtype* weights, Dtype* output, bool skip_im2col) {\n  const Dtype* col_buff = input;\n  if (!is_1x1_) {\n    if (!skip_im2col) {\n      conv_im2col_gpu(input, col_buffer_.mutable_gpu_data());\n    }\n    col_buff = col_buffer_.gpu_data();\n  }\n  for (int g = 0; g < group_; ++g) {\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, conv_out_channels_ /\n        group_, conv_out_spatial_dim_, kernel_dim_ / group_,\n        (Dtype)1., weights + weight_offset_ * g, col_buff + col_offset_ * g,\n        (Dtype)0., output + output_offset_ * g);\n  }\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::forward_gpu_bias(Dtype* output,\n    const Dtype* bias) {\n  caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num_output_,\n      height_out_ * width_out_, 1, (Dtype)1., bias, bias_multiplier_.gpu_data(),\n      (Dtype)1., output);\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::backward_gpu_gemm(const Dtype* output,\n    const Dtype* weights, Dtype* input) {\n  Dtype* col_buff = col_buffer_.mutable_gpu_data();\n  if (is_1x1_) {\n    col_buff = input;\n  }\n  for (int g = 0; g < group_; ++g) {\n    caffe_gpu_gemm<Dtype>(CblasTrans, CblasNoTrans, kernel_dim_ / group_,\n        conv_out_spatial_dim_, conv_out_channels_ / group_,\n        (Dtype)1., weights + weight_offset_ * g, output + output_offset_ * g,\n        (Dtype)0., col_buff + col_offset_ * g);\n  }\n  if (!is_1x1_) {\n    conv_col2im_gpu(col_buff, input);\n  }\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::weight_gpu_gemm(const Dtype* input,\n    const Dtype* output, Dtype* weights) {\n  const Dtype* col_buff = input;\n  if (!is_1x1_) {\n    conv_im2col_gpu(input, col_buffer_.mutable_gpu_data());\n    col_buff = col_buffer_.gpu_data();\n  }\n  for (int g = 0; g < group_; ++g) {\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasTrans, conv_out_channels_ / group_,\n        kernel_dim_ / group_, conv_out_spatial_dim_,\n        (Dtype)1., output + output_offset_ * g, col_buff + col_offset_ * g,\n        (Dtype)1., weights + weight_offset_ * g);\n  }\n}\n\ntemplate <typename Dtype>\nvoid BaseConvolutionLayer<Dtype>::backward_gpu_bias(Dtype* bias,\n    const Dtype* input) {\n  caffe_gpu_gemv<Dtype>(CblasNoTrans, num_output_, height_out_ * width_out_, 1.,\n      input, bias_multiplier_.gpu_data(), 1., bias);\n}\n\n#endif  // !CPU_ONLY\n\nINSTANTIATE_CLASS(BaseConvolutionLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/base_data_layer.cpp",
    "content": "#include <boost/thread.hpp>\n#include <string>\n#include <vector>\n\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/net.hpp\"\n#include \"caffe/util/io.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nBaseDataLayer<Dtype>::BaseDataLayer(const LayerParameter& param)\n    : Layer<Dtype>(param),\n      transform_param_(param.transform_param()) {\n}\n\ntemplate <typename Dtype>\nvoid BaseDataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  if (top.size() == 1) {\n    output_labels_ = false;\n  } else {\n    output_labels_ = true;\n  }\n  data_transformer_.reset(\n      new DataTransformer<Dtype>(transform_param_, this->phase_));\n  data_transformer_->InitRand();\n  // The subclasses should setup the size of bottom and top\n  DataLayerSetUp(bottom, top);\n}\n\ntemplate <typename Dtype>\nBasePrefetchingDataLayer<Dtype>::BasePrefetchingDataLayer(\n    const LayerParameter& param)\n    : BaseDataLayer<Dtype>(param),\n      prefetch_free_(), prefetch_full_() {\n  for (int i = 0; i < PREFETCH_COUNT; ++i) {\n    prefetch_free_.push(&prefetch_[i]);\n  }\n}\n\ntemplate <typename Dtype>\nvoid BasePrefetchingDataLayer<Dtype>::LayerSetUp(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  BaseDataLayer<Dtype>::LayerSetUp(bottom, top);\n  // Before starting the prefetch thread, we make cpu_data and gpu_data\n  // calls so that the prefetch thread does not accidentally make simultaneous\n  // cudaMalloc calls when the main thread is running. In some GPUs this\n  // seems to cause failures if we do not so.\n  for (int i = 0; i < PREFETCH_COUNT; ++i) {\n    prefetch_[i].data_.mutable_cpu_data();\n    if (this->output_labels_) {\n      prefetch_[i].label_.mutable_cpu_data();\n    }\n  }\n#ifndef CPU_ONLY\n  if (Caffe::mode() == Caffe::GPU) {\n    for (int i = 0; i < PREFETCH_COUNT; ++i) {\n      prefetch_[i].data_.mutable_gpu_data();\n      if (this->output_labels_) {\n        prefetch_[i].label_.mutable_gpu_data();\n      }\n    }\n  }\n#endif\n  DLOG(INFO) << \"Initializing prefetch\";\n  this->data_transformer_->InitRand();\n  StartInternalThread();\n  DLOG(INFO) << \"Prefetch initialized.\";\n}\n\ntemplate <typename Dtype>\nvoid BasePrefetchingDataLayer<Dtype>::InternalThreadEntry() {\n#ifndef CPU_ONLY\n  cudaStream_t stream;\n  if (Caffe::mode() == Caffe::GPU) {\n    CUDA_CHECK(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));\n  }\n#endif\n\n  try {\n    while (!must_stop()) {\n      Batch<Dtype>* batch = prefetch_free_.pop();\n      load_batch(batch);\n#ifndef CPU_ONLY\n      if (Caffe::mode() == Caffe::GPU) {\n        batch->data_.data().get()->async_gpu_push(stream);\n        CUDA_CHECK(cudaStreamSynchronize(stream));\n      }\n#endif\n      prefetch_full_.push(batch);\n    }\n  } catch (boost::thread_interrupted&) {\n    // Interrupted exception is expected on shutdown\n  }\n#ifndef CPU_ONLY\n  if (Caffe::mode() == Caffe::GPU) {\n    CUDA_CHECK(cudaStreamDestroy(stream));\n  }\n#endif\n}\n\ntemplate <typename Dtype>\nvoid BasePrefetchingDataLayer<Dtype>::Forward_cpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  Batch<Dtype>* batch = prefetch_full_.pop(\"Data layer prefetch queue empty\");\n  // Reshape to loaded data.\n  top[0]->Reshape(batch->data_.num(), batch->data_.channels(),\n      batch->data_.height(), batch->data_.width());\n  // Copy the data\n  caffe_copy(batch->data_.count(), batch->data_.cpu_data(),\n             top[0]->mutable_cpu_data());\n  DLOG(INFO) << \"Prefetch copied\";\n  if (this->output_labels_) {\n    // Reshape to loaded labels.\n    top[1]->ReshapeLike(batch->label_);\n    // Copy the labels.\n    caffe_copy(batch->label_.count(), batch->label_.cpu_data(),\n        top[1]->mutable_cpu_data());\n  }\n\n  prefetch_free_.push(batch);\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU_FORWARD(BasePrefetchingDataLayer, Forward);\n#endif\n\nINSTANTIATE_CLASS(BaseDataLayer);\nINSTANTIATE_CLASS(BasePrefetchingDataLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/base_data_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/data_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid BasePrefetchingDataLayer<Dtype>::Forward_gpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  Batch<Dtype>* batch = prefetch_full_.pop(\"Data layer prefetch queue empty\");\n  // Reshape to loaded data.\n  top[0]->ReshapeLike(batch->data_);\n  // Copy the data\n  caffe_copy(batch->data_.count(), batch->data_.gpu_data(),\n      top[0]->mutable_gpu_data());\n  if (this->output_labels_) {\n    // Reshape to loaded labels.\n    top[1]->ReshapeLike(batch->label_);\n    // Copy the labels.\n    caffe_copy(batch->label_.count(), batch->label_.gpu_data(),\n        top[1]->mutable_gpu_data());\n  }\n\n  prefetch_free_.push(batch);\n}\n\nINSTANTIATE_LAYER_GPU_FORWARD(BasePrefetchingDataLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/bnll_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\nconst float kBNLL_THRESHOLD = 50.;\n\ntemplate <typename Dtype>\nvoid BNLLLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  const int count = bottom[0]->count();\n  for (int i = 0; i < count; ++i) {\n    top_data[i] = bottom_data[i] > 0 ?\n        bottom_data[i] + log(1. + exp(-bottom_data[i])) :\n        log(1. + exp(bottom_data[i]));\n  }\n}\n\ntemplate <typename Dtype>\nvoid BNLLLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* bottom_data = bottom[0]->cpu_data();\n    const Dtype* top_diff = top[0]->cpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    const int count = bottom[0]->count();\n    Dtype expval;\n    for (int i = 0; i < count; ++i) {\n      expval = exp(std::min(bottom_data[i], Dtype(kBNLL_THRESHOLD)));\n      bottom_diff[i] = top_diff[i] * expval / (expval + 1.);\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(BNLLLayer);\n#endif\n\nINSTANTIATE_CLASS(BNLLLayer);\nREGISTER_LAYER_CLASS(BNLL);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/bnll_layer.cu",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\nconst float kBNLL_THRESHOLD = 50.;\n\ntemplate <typename Dtype>\n__global__ void BNLLForward(const int n, const Dtype* in, Dtype* out) {\n  CUDA_KERNEL_LOOP(index, n) {\n    out[index] = in[index] > 0 ?\n        in[index] + log(1. + exp(-in[index])) :\n        log(1. + exp(in[index]));\n  }\n}\n\ntemplate <typename Dtype>\nvoid BNLLLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  const int count = bottom[0]->count();\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  BNLLForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n      count, bottom_data, top_data);\n  CUDA_POST_KERNEL_CHECK;\n}\n\ntemplate <typename Dtype>\n__global__ void BNLLBackward(const int n, const Dtype* in_diff,\n    const Dtype* in_data, Dtype* out_diff) {\n  CUDA_KERNEL_LOOP(index, n) {\n    Dtype expval = exp(min(in_data[index], Dtype(kBNLL_THRESHOLD)));\n    out_diff[index] = in_diff[index] * expval / (expval + 1.);\n  }\n}\n\ntemplate <typename Dtype>\nvoid BNLLLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* bottom_data = bottom[0]->gpu_data();\n    const Dtype* top_diff = top[0]->gpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    const int count = bottom[0]->count();\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    BNLLBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, top_diff, bottom_data, bottom_diff);\n    CUDA_POST_KERNEL_CHECK;\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(BNLLLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/compress_conv_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n#include <cmath>\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CConvolutionLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  BaseConvolutionLayer <Dtype>::LayerSetUp(bottom, top); \n  \n  /************ For dynamic network surgery ***************/\n\tCConvolutionParameter cconv_param = this->layer_param_.cconvolution_param();\n\t\n  if(this->blobs_.size()==2 && (this->bias_term_)){\n    this->blobs_.resize(4);\n    // Intialize and fill the weightmask & biasmask\n    this->blobs_[2].reset(new Blob<Dtype>(this->blobs_[0]->shape()));\n    shared_ptr<Filler<Dtype> > weight_mask_filler(GetFiller<Dtype>(\n        cconv_param.weight_mask_filler()));\n    weight_mask_filler->Fill(this->blobs_[2].get());\n    this->blobs_[3].reset(new Blob<Dtype>(this->blobs_[1]->shape()));\n    shared_ptr<Filler<Dtype> > bias_mask_filler(GetFiller<Dtype>(\n        cconv_param.bias_mask_filler()));\n    bias_mask_filler->Fill(this->blobs_[3].get());    \n  }  \n  else if(this->blobs_.size()==1 && (!this->bias_term_)){\n    this->blobs_.resize(2);\t  \n    // Intialize and fill the weightmask\n    this->blobs_[1].reset(new Blob<Dtype>(this->blobs_[0]->shape()));\n    shared_ptr<Filler<Dtype> > bias_mask_filler(GetFiller<Dtype>(\n        cconv_param.bias_mask_filler()));\n    bias_mask_filler->Fill(this->blobs_[1].get());      \n  }  \n\t\n  // Intializing the tmp tensor\n  this->weight_tmp_.Reshape(this->blobs_[0]->shape());\n  this->bias_tmp_.Reshape(this->blobs_[1]->shape());  \n\t\n\t// Intialize the hyper-parameters\n  this->std = 0;this->mu = 0;   \n  this->gamma = cconv_param.gamma(); \n  this->power = cconv_param.power();\n  this->crate = cconv_param.c_rate();  \n  this->iter_stop_ = cconv_param.iter_stop();\n  /********************************************************/\n}\n\ntemplate <typename Dtype>\nvoid CConvolutionLayer<Dtype>::compute_output_shape() {\n  this->height_out_ = (this->height_ + 2 * this->pad_h_ - this->kernel_h_)\n      / this->stride_h_ + 1;\n  this->width_out_ = (this->width_ + 2 * this->pad_w_ - this->kernel_w_)\n      / this->stride_w_ + 1;\n}\n\ntemplate <typename Dtype>\nvoid CConvolutionLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {  \n      \n  const Dtype* weight = this->blobs_[0]->mutable_cpu_data();    \n  Dtype* weightMask = this->blobs_[2]->mutable_cpu_data(); \n  Dtype* weightTmp = this->weight_tmp_.mutable_cpu_data(); \n  const Dtype* bias = NULL;\n  Dtype* biasMask = NULL;  \n  Dtype* biasTmp = NULL;\n  if (this->bias_term_) {\n    bias = this->blobs_[1]->mutable_cpu_data(); \n    biasMask = this->blobs_[3]->mutable_cpu_data();\n    biasTmp = this->bias_tmp_.mutable_cpu_data();\n  }\n\n  if (this->phase_ == TRAIN){\n\t\t// Calculate the mean and standard deviation of learnable parameters \n    if (this->std==0 && this->iter_==0){      \n\t\t\tunsigned int ncount = 0;\n\t\t\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\t\t\tthis->mu  += fabs(weightMask[k]*weight[k]);       \n\t\t\t\tthis->std += weightMask[k]*weight[k]*weight[k];\n\t\t\t\tif (weightMask[k]*weight[k]!=0) ncount++;\n\t\t\t}\n\t\t\tif (this->bias_term_) {\n\t\t\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\t\t\tthis->mu  += fabs(biasMask[k]*bias[k]);\n\t\t\t\t\tthis->std += biasMask[k]*bias[k]*bias[k];\n\t\t\t\t\tif (biasMask[k]*bias[k]!=0) ncount++;\n\t\t\t\t}       \n\t\t\t}\n\t\t\tthis->mu /= ncount; this->std -= ncount*mu*mu; \n\t\t\tthis->std /= ncount; this->std = sqrt(std);\n//\t\t\tLOG(INFO)<<mu<<\"  \"<<std<<\"  \"<<ncount<<\"\\n\";     \n\t\t} \n\t\t\n\t\t// Demonstrate the sparsity of compressed convolutional layer\n\t\t/********************************************************/\n\t\t/*if(this->iter_%1000==0){\n\t\t\tunsigned int ncount = 0;\n\t\t\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\t\t\tif (weightMask[k]*weight[k]!=0) ncount++;\n\t\t\t}\n\t\t\tif (this->bias_term_) {\n\t\t\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\t\t\tif (biasMask[k]*bias[k]!=0) ncount++;\n\t\t\t\t}       \n\t\t\t}\n\t\t\tLOG(INFO)<<ncount<<\"\\n\";  \t\t\t\n\t\t}*/\t\n\t\t/********************************************************/\t\t\n\t\t\n\t\t// Calculate the weight mask and bias mask with probability\n\t\tDtype r = static_cast<Dtype>(rand())/static_cast<Dtype>(RAND_MAX);\n\t\tif (pow(1+(this->gamma)*(this->iter_),-(this->power))>r && (this->iter_)<(this->iter_stop_)) { \t\n\t\t\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\t\t\tif (weightMask[k]==1 && fabs(weight[k])<=0.9*std::max(mu+crate*std,Dtype(0))) \n\t\t\t\t\tweightMask[k] = 0;\n\t\t\t\telse if (weightMask[k]==0 && fabs(weight[k])>1.1*std::max(mu+crate*std,Dtype(0)))\n\t\t\t\t\tweightMask[k] = 1;\n\t\t\t}\t\n\t\t\tif (this->bias_term_) {       \n\t\t\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\t\t\tif (biasMask[k]==1 && fabs(bias[k])<=0.9*std::max(mu+crate*std,Dtype(0))) \n\t\t\t\t\t\tbiasMask[k] = 0;\n\t\t\t\t\telse if (biasMask[k]==0 && fabs(bias[k])>1.1*std::max(mu+crate*std,Dtype(0)))\n\t\t\t\t\t\tbiasMask[k] = 1;\n\t\t\t\t}    \n\t\t\t} \n\t\t}\n\t} \n    \n  // Calculate the current (masked) weight and bias\n\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\tweightTmp[k] = weight[k]*weightMask[k];\n\t}\n\tif (this->bias_term_){\n\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\tbiasTmp[k] = bias[k]*biasMask[k];\n\t\t}\n\t}\n  \n\t// Forward calculation with (masked) weight and bias \n  for (int i = 0; i < bottom.size(); ++i) {\n    const Dtype* bottom_data = bottom[i]->cpu_data();\n    Dtype* top_data = top[i]->mutable_cpu_data();\n    for (int n = 0; n < this->num_; ++n) {\n      this->forward_cpu_gemm(bottom_data + bottom[i]->offset(n), weightTmp,\n          top_data + top[i]->offset(n));\n      if (this->bias_term_) {\n        this->forward_cpu_bias(top_data + top[i]->offset(n), biasTmp);\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid CConvolutionLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n\tconst Dtype* weightTmp = this->weight_tmp_.cpu_data();  \n\tconst Dtype* weightMask = this->blobs_[2]->cpu_data();\n\tDtype* weight_diff = this->blobs_[0]->mutable_cpu_diff();\n  for (int i = 0; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->cpu_diff();    \n    // Bias gradient, if necessary.\n    if (this->bias_term_ && this->param_propagate_down_[1]) {\n\t\t\tconst Dtype* biasMask = this->blobs_[3]->cpu_data();\n      Dtype* bias_diff = this->blobs_[1]->mutable_cpu_diff();\t\t\t\n\t\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\t\tbias_diff[k] = bias_diff[k]*biasMask[k];\n\t\t\t}\n      for (int n = 0; n < this->num_; ++n) {\n        this->backward_cpu_bias(bias_diff, top_diff + top[i]->offset(n));\n      }\n    }\n    if (this->param_propagate_down_[0] || propagate_down[i]) {\n\t\t\tconst Dtype* bottom_data = bottom[i]->cpu_data();\n\t\t\tDtype* bottom_diff = bottom[i]->mutable_cpu_diff();\t\n\t\t\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\t\t\tweight_diff[k] = weight_diff[k]*weightMask[k];\n\t\t\t}\n      for (int n = 0; n < this->num_; ++n) {\n        // gradient w.r.t. weight. Note that we will accumulate diffs.\n        if (this->param_propagate_down_[0]) {\n          this->weight_cpu_gemm(bottom_data + bottom[i]->offset(n),\n              top_diff + top[i]->offset(n), weight_diff);\n        }\n        // gradient w.r.t. bottom data, if necessary.\n        if (propagate_down[i]) {\n          this->backward_cpu_gemm(top_diff + top[i]->offset(n), weightTmp,\n              bottom_diff + bottom[i]->offset(n));\n        }\n      }\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(CConvolutionLayer);\n#endif\n\nINSTANTIATE_CLASS(CConvolutionLayer);\nREGISTER_LAYER_CLASS(CConvolution);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/compress_conv_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n#include <cmath>\n\nnamespace caffe {\n\n// The constant NUM_THREADS should be equal to the value in CCMomentCalc\ntemplate <typename Dtype>\n__global__ void CCMomentCollect(const int n, const Dtype* wb, const Dtype* mask,\n    Dtype* mu, Dtype* std, unsigned int* count ) {  \n  const int NUM_THREADS = 512;  \n  __shared__ Dtype param [4*NUM_THREADS]; \n  __shared__ unsigned int tcount [2*NUM_THREADS];   \n  unsigned int t = threadIdx.x; \n  unsigned int s = 2 * blockIdx.x * NUM_THREADS;\n  if (s+t < n){\n    param[t] = fabs(mask[s+t]*wb[s+t]);\n    param[t+2*NUM_THREADS] = mask[s+t]*wb[s+t]*wb[s+t];\n    if(mask[s+t]*wb[s+t]!=0) tcount[t] = 1;\n    else tcount[t] = 0;\n  }\n  else{\n    param[t] = 0;param[t+2*NUM_THREADS] = 0;tcount[t] = 0;\n  }\n  if (s+t+NUM_THREADS < n){\n    param[t+NUM_THREADS] = fabs(mask[s+t+NUM_THREADS]*wb[s+t+NUM_THREADS]);\n    param[t+3*NUM_THREADS] = mask[s+t+NUM_THREADS]*wb[s+t+NUM_THREADS]*wb[s+t+NUM_THREADS];\n    if(mask[s+t+NUM_THREADS]*wb[s+t+NUM_THREADS]!=0) tcount[t+NUM_THREADS] = 1;\n    else tcount[t+NUM_THREADS] = 0;\n  }\n  else{\n    param[t+NUM_THREADS] = 0;param[t+3*NUM_THREADS] = 0;tcount[t+NUM_THREADS] = 0;  \n  }\n  __syncthreads(); \n  for(unsigned int stride = NUM_THREADS; stride >= 1; stride >>= 1) {\n    if (t < stride ){\n      param[t] += param[t+stride]; \n      param[t+2*NUM_THREADS] += param[t+2*NUM_THREADS+stride];\n      tcount[t] += tcount[t+stride];\n    }\n    __syncthreads();  \n  }\n  if (t == 0){\n    mu   [blockIdx.x] = param[0];\n    std  [blockIdx.x] = param[2*NUM_THREADS];\n    count[blockIdx.x] = tcount[0]; \n  }      \n}\n\n// The constant NUM_THREADS should be equal to the value in CCMomentCalc\ntemplate <typename Dtype>\n__global__ void CCNzeroCollect(const int n, const Dtype* mask, unsigned int* count ) {  \n  const int NUM_THREADS = 512;  \n  __shared__ unsigned int tcount [2*NUM_THREADS];   \n  unsigned int t = threadIdx.x; \n  unsigned int s = 2 * blockIdx.x * NUM_THREADS;\n  tcount[t] = 0;\n  if (s+t < n && mask[s+t]!=0){\n    tcount[t] = 1;\n  }\n  tcount[t+NUM_THREADS] = 0;\n  if (s+t+NUM_THREADS < n && mask[s+t+NUM_THREADS]!=0){\n    tcount[t+NUM_THREADS] = 1;\n  }\n  __syncthreads(); \n  for(unsigned int stride = NUM_THREADS; stride >= 1; stride >>= 1) {\n    if (t < stride ){\n      tcount[t] += tcount[t+stride];\n    }\n    __syncthreads();  \n  }\n  if (t == 0){\n    count[blockIdx.x] = tcount[0]; \n  }     \n}\n\ntemplate <typename Dtype>\n__global__ void CCMaskCalc(const int n, const Dtype* wb,\n    Dtype* mask, Dtype mu, Dtype std, Dtype r) {\n  CUDA_KERNEL_LOOP(index, n) {\n    if (mask[index]==1 && fabs(wb[index])<=0.9*max(mu+r*std,Dtype(0))) \n      mask[index] = 0;\n    else if (mask[index]==0 && fabs(wb[index])>1.1*max(mu+r*std,Dtype(0)))\n      mask[index] = 1;\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void CCMaskApply(const int n, const Dtype* wb,\n    const Dtype* mask, Dtype* wb_t) {\n  CUDA_KERNEL_LOOP(index, n) {\n    wb_t[index] = wb[index] * mask[index];    \n  }\n}\n\ntemplate <typename Dtype>\nvoid CCMomentCalc(const int n, const Dtype* wb, const Dtype* mask, Dtype* mu, Dtype* std, unsigned int* ncount){ \n  const unsigned int NUM_THREADS = 512;\n  Dtype* pmu_g; Dtype* pstd_g; unsigned int* pncount_g;\n  Dtype* pmu_c; Dtype* pstd_c; unsigned int* pncount_c;\n  int num_p = (n+(NUM_THREADS<<1)-1)/(NUM_THREADS<<1);  \n  cudaMalloc(&pmu_g, sizeof(Dtype)  * num_p);\n  cudaMalloc(&pstd_g, sizeof(Dtype) * num_p);\n  cudaMalloc(&pncount_g, sizeof(unsigned int) * num_p);\n  pmu_c = (Dtype*) malloc(num_p * sizeof(Dtype));\n  pstd_c = (Dtype*) malloc(num_p * sizeof(Dtype)); \n  pncount_c = (unsigned int*) malloc(num_p * sizeof(unsigned int));      \n  CCMomentCollect<Dtype><<<num_p,NUM_THREADS>>>(n, wb, mask, pmu_g, pstd_g, pncount_g);\n  CUDA_POST_KERNEL_CHECK; \n  cudaMemcpy(pmu_c, pmu_g, sizeof(Dtype) * num_p, cudaMemcpyDeviceToHost);\n  cudaMemcpy(pstd_c, pstd_g, sizeof(Dtype) * num_p, cudaMemcpyDeviceToHost);\n  cudaMemcpy(pncount_c, pncount_g, sizeof(unsigned int) * num_p, cudaMemcpyDeviceToHost);      \n  for (int i = 0; i < num_p; i++) {\n    *mu += pmu_c[i];*std += pstd_c[i];*ncount += pncount_c[i];\n  }       \n  cudaFree(pmu_g);cudaFree(pstd_g);cudaFree(pncount_g);\n  free(pmu_c);free(pstd_c);free(pncount_c);\n}\n\ntemplate <typename Dtype>\nvoid CCNZeroCalc(const int n, const Dtype* mask, unsigned int* ncount ){  \n  const unsigned int NUM_THREADS = 512;\n  unsigned int* pncount_g;\n  unsigned int* pncount_c;\n  int num_p = (n+(NUM_THREADS<<1)-1)/(NUM_THREADS<<1);  \n  cudaMalloc(&pncount_g, sizeof(unsigned int) * num_p);\n  pncount_c = (unsigned int*) malloc(num_p * sizeof(unsigned int));      \n  CCNzeroCollect<Dtype><<<num_p,NUM_THREADS>>>(n, mask, pncount_g);\n  CUDA_POST_KERNEL_CHECK; \n  cudaMemcpy(pncount_c, pncount_g, sizeof(unsigned int) * num_p, cudaMemcpyDeviceToHost);      \n  for (int i = 0; i < num_p; i++) {\n    *ncount += pncount_c[i];\n  }       \n  cudaFree(pncount_g);\n  free(pncount_c);\n}\n\ntemplate <typename Dtype>\nvoid CConvolutionLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {  \n\n  const Dtype* weight = this->blobs_[0]->mutable_gpu_data();  \n  Dtype* weightMask = this->blobs_[2]->mutable_gpu_data();\n  Dtype* weightTmp = this->weight_tmp_.mutable_gpu_data(); \n  const Dtype* bias = NULL;\n  Dtype* biasMask = NULL;\n  Dtype* biasTmp = NULL;   \n  if (this->bias_term_) {  \n    bias = this->blobs_[1]->mutable_gpu_data();   \n    biasMask = this->blobs_[3]->mutable_gpu_data();\n    biasTmp = this->bias_tmp_.mutable_gpu_data();\n  }\n  \n  if (this->phase_ == TRAIN){\n\t\t// Calculate the mean and standard deviation of learnable parameters \t\t\n    if (this->std==0 && this->iter_==0){\n      unsigned int ncount = 0;\n      CCMomentCalc(this->blobs_[0]->count(), weight, weightMask, &mu, &std, &ncount);\n      if (this->bias_term_) {  \n        CCMomentCalc(this->blobs_[1]->count(), bias, biasMask, &mu, &std, &ncount); \n      }     \n      this->mu /= ncount; this->std -= ncount*mu*mu; \n      this->std /= ncount; this->std = sqrt(std);  \n      LOG(INFO)<<mu<<\"  \"<<std<<\"  \"<<ncount<<\"\\n\";                    \n    }\n\t\t\n\t\t// Demonstrate the sparsity of compressed convolutional layer\n\t\t/********************************************************/\n\t\t/*if(this->iter_%1000==0){\n\t\t\tunsigned int ncount = 0;\n\t\t\tCCNZeroCalc(this->blobs_[0]->count(), weightMask, &ncount);\n\t\t\tif (this->bias_term_) {  \n\t\t\t\tCCNZeroCalc(this->blobs_[1]->count(), biasMask, &ncount);   \n\t\t\t}\n\t\t\tLOG(INFO)<<ncount<<\"\\n\";  \t\t\t\n\t\t}*/\t\n\t\t/********************************************************/\n\t\t\n\t\t// Calculate the weight mask and bias mask with probability\n    Dtype r = static_cast<Dtype>(rand())/static_cast<Dtype>(RAND_MAX);\n    if (pow(1+(this->gamma)*(this->iter_),-(this->power))>r && (this->iter_)<(this->iter_stop_)) { \n      CCMaskCalc<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[0]->count()),\n        CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[0]->count(), weight, \n        weightMask, this->mu, this->std, this->crate);\n      CUDA_POST_KERNEL_CHECK;    \n      if (this->bias_term_) {   \n        CCMaskCalc<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[1]->count()),\n          CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[1]->count(), bias, \n          biasMask, this->mu, this->std, this->crate);\n        CUDA_POST_KERNEL_CHECK; \n      }\n    }    \n  }   \n \n  // Calculate the current (masked) weight and bias\n  CCMaskApply<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[0]->count()),\n    CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[0]->count(), weight, weightMask, weightTmp);\n  CUDA_POST_KERNEL_CHECK;\n  if (this->bias_term_) {  \n    CCMaskApply<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[1]->count()),\n      CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[1]->count(), bias, biasMask, biasTmp);\n    CUDA_POST_KERNEL_CHECK;  \n  }\n      \n\t// Forward calculation with (masked) weight and bias \n  for (int i = 0; i < bottom.size(); ++i) {\n    const Dtype* bottom_data = bottom[i]->gpu_data();\n    Dtype* top_data = top[i]->mutable_gpu_data();\n    for (int n = 0; n < this->num_; ++n) {\n      this->forward_gpu_gemm(bottom_data + bottom[i]->offset(n), weightTmp,\n          top_data + top[i]->offset(n));\n      if (this->bias_term_) {\n        this->forward_gpu_bias(top_data + top[i]->offset(n), biasTmp);\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid CConvolutionLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* weightTmp = this->weight_tmp_.gpu_data();  \t\n\tconst Dtype* weightMask = this->blobs_[2]->gpu_data();\n\tDtype* weight_diff = this->blobs_[0]->mutable_gpu_diff();  \t\n  for (int i = 0; i < top.size(); ++i) {    \n    const Dtype* top_diff = top[i]->gpu_diff();\n    // Bias gradient, if necessary.\n    if (this->bias_term_ && this->param_propagate_down_[1]) {\n\t\t\tconst Dtype* biasMask = this->blobs_[3]->gpu_data();\n      Dtype* bias_diff = this->blobs_[1]->mutable_gpu_diff();\t\t\t\n      CCMaskApply<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[3]->count()),\n        CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[3]->count(), bias_diff, biasMask, bias_diff);\n      CUDA_POST_KERNEL_CHECK;  \n      for (int n = 0; n < this->num_; ++n) {\n        this->backward_gpu_bias(bias_diff, top_diff + top[i]->offset(n));\n      }\n    }\n    if (this->param_propagate_down_[0] || propagate_down[i]) {\n      const Dtype* bottom_data = bottom[i]->gpu_data();\n      Dtype* bottom_diff = bottom[i]->mutable_gpu_diff();\n      CCMaskApply<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[2]->count()),\n        CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[2]->count(), weight_diff, weightMask, weight_diff);\n      CUDA_POST_KERNEL_CHECK; \t\t\t\n      for (int n = 0; n < this->num_; ++n) {\n        // gradient w.r.t. weight. Note that we will accumulate diffs.\n        if (this->param_propagate_down_[0]) {\n          this->weight_gpu_gemm(bottom_data + bottom[i]->offset(n),\n              top_diff + top[i]->offset(n), weight_diff);\n        }\n        // gradient w.r.t. bottom data, if necessary.\n        if (propagate_down[i]) {\n          this->backward_gpu_gemm(top_diff + top[i]->offset(n), weightTmp,\n              bottom_diff + bottom[i]->offset(n));\n        }\n      }\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(CConvolutionLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/compress_inner_product_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n#include <cmath>\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CInnerProductLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int num_output = this->layer_param_.inner_product_param().num_output();\n  bias_term_ = this->layer_param_.inner_product_param().bias_term();\n  N_ = num_output;\n  const int axis = bottom[0]->CanonicalAxisIndex(\n      this->layer_param_.inner_product_param().axis());\n  // Dimensions starting from \"axis\" are \"flattened\" into a single\n  // length K_ vector. For example, if bottom[0]'s shape is (N, C, H, W),\n  // and axis == 1, N inner products with dimension CHW are performed.\n  K_ = bottom[0]->count(axis);\n  // Check if we need to set up the weights\n  if (this->blobs_.size() > 0) {\n    LOG(INFO) << \"Skipping parameter initialization\";\n  } else {\n    if (this->bias_term_) {\n      this->blobs_.resize(2);\n    } else {\n      this->blobs_.resize(1);\n    }\n    // Intialize the weight\n    vector<int> weight_shape(2);\n    weight_shape[0] = N_;\n    weight_shape[1] = K_;\n    this->blobs_[0].reset(new Blob<Dtype>(weight_shape));\n    // fill the weights\n    shared_ptr<Filler<Dtype> > weight_filler(GetFiller<Dtype>(\n        this->layer_param_.inner_product_param().weight_filler()));\n    weight_filler->Fill(this->blobs_[0].get());\n    // If necessary, intiialize and fill the bias term\n    if (this->bias_term_) {\n      vector<int> bias_shape(1, N_);\n      this->blobs_[1].reset(new Blob<Dtype>(bias_shape));\n      shared_ptr<Filler<Dtype> > bias_filler(GetFiller<Dtype>(\n          this->layer_param_.inner_product_param().bias_filler()));\n      bias_filler->Fill(this->blobs_[1].get());\n    }\n  }  // parameter initialization\n  this->param_propagate_down_.resize(this->blobs_.size(), true);\n  \n  /************ For dynamic network surgery ***************/\n\tCInnerProductParameter cinner_param = this->layer_param_.cinner_product_param();\n\t\n  if(this->blobs_.size()==2 && (this->bias_term_)){\n    this->blobs_.resize(4);\n    // Intialize and fill the weightmask & biasmask\n    this->blobs_[2].reset(new Blob<Dtype>(this->blobs_[0]->shape()));\n    shared_ptr<Filler<Dtype> > weight_mask_filler(GetFiller<Dtype>(\n        cinner_param.weight_mask_filler()));\n    weight_mask_filler->Fill(this->blobs_[2].get());\n    this->blobs_[3].reset(new Blob<Dtype>(this->blobs_[1]->shape()));\n    shared_ptr<Filler<Dtype> > bias_mask_filler(GetFiller<Dtype>(\n        cinner_param.bias_mask_filler()));\n    bias_mask_filler->Fill(this->blobs_[3].get());    \n  }  \n  else if(this->blobs_.size()==1 && (!this->bias_term_)){\n    this->blobs_.resize(2);\t  \n    // Intialize and fill the weightmask\n    this->blobs_[1].reset(new Blob<Dtype>(this->blobs_[0]->shape()));\n    shared_ptr<Filler<Dtype> > bias_mask_filler(GetFiller<Dtype>(\n        cinner_param.bias_mask_filler()));\n    bias_mask_filler->Fill(this->blobs_[1].get());      \n  }   \n   \n  // Intialize the tmp tensor \n  this->weight_tmp_.Reshape(this->blobs_[0]->shape());\n  this->bias_tmp_.Reshape(this->blobs_[1]->shape());  \n\n  // Intialize the hyper-parameters\n  this->std = 0;this->mu = 0;  \n  this->gamma = cinner_param.gamma(); \n  this->power = cinner_param.power();\n  this->crate = cinner_param.c_rate();  \n  this->iter_stop_ = cinner_param.iter_stop();    \n  /********************************************************/\n}\n\ntemplate <typename Dtype>\nvoid CInnerProductLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  // Figure out the dimensions\n  const int axis = bottom[0]->CanonicalAxisIndex(\n      this->layer_param_.inner_product_param().axis());\n  const int new_K = bottom[0]->count(axis);\n  CHECK_EQ(K_, new_K)\n      << \"Input size incompatible with inner product parameters.\";\n  // The first \"axis\" dimensions are independent inner products; the total\n  // number of these is M_, the product over these dimensions.\n  M_ = bottom[0]->count(0, axis);\n  // The top shape will be the bottom shape with the flattened axes dropped,\n  // and replaced by a single axis with dimension num_output (N_).\n  vector<int> top_shape = bottom[0]->shape();\n  top_shape.resize(axis + 1);\n  top_shape[axis] = N_;\n  top[0]->Reshape(top_shape);\n  // Set up the bias multiplier\n  if (bias_term_) {\n    vector<int> bias_shape(1, M_);\n    bias_multiplier_.Reshape(bias_shape);\n    caffe_set(M_, Dtype(1), bias_multiplier_.mutable_cpu_data());\n  }\n}\n\ntemplate <typename Dtype>\nvoid CInnerProductLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  \n  const Dtype* weight = this->blobs_[0]->mutable_cpu_data();    \n  Dtype* weightMask = this->blobs_[2]->mutable_cpu_data(); \n  Dtype* weightTmp = this->weight_tmp_.mutable_cpu_data(); \n  const Dtype* bias = NULL;\n  Dtype* biasMask = NULL;  \n  Dtype* biasTmp = NULL;\n  if (this->bias_term_) {\n    bias = this->blobs_[1]->mutable_cpu_data(); \n    biasMask = this->blobs_[3]->mutable_cpu_data();\n    biasTmp = this->bias_tmp_.mutable_cpu_data();\n  }\n   \n  if (this->phase_ == TRAIN){\n    // Calculate the mean and standard deviation of learnable parameters \n\t\tif (this->std==0 && this->iter_==0){      \n\t\t\tunsigned int ncount = 0;\n\t\t\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\t\t\tthis->mu  += fabs(weight[k]);       \n\t\t\t\tthis->std += weight[k]*weight[k];\n\t\t\t\tif (weight[k]!=0) ncount++;\n\t\t\t}\n\t\t\tif (this->bias_term_) {\n\t\t\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\t\t\tthis->mu  += fabs(bias[k]);\n\t\t\t\t\tthis->std += bias[k]*bias[k];\n\t\t\t\t\tif (bias[k]!=0) ncount++;\n\t\t\t\t}       \n\t\t\t}\n\t\t\tthis->mu /= ncount; this->std -= ncount*mu*mu; \n\t\t\tthis->std /= ncount; this->std = sqrt(std);\n\t\t\tLOG(INFO)<<mu<<\"  \"<<std<<\"  \"<<ncount<<\"\\n\";        \n\t\t}  \t\t\n\t\t\n\t\t// Demonstrate the sparsity of compressed fully-connected layer\n\t\t/********************************************************/\n\t\t/*if(this->iter_%100==0){\n\t\t\tunsigned int ncount = 0;\n\t\t\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\t\t\tif (weightMask[k]*weight[k]!=0) ncount++;\n\t\t\t}\n\t\t\tif (this->bias_term_) {\n\t\t\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\t\t\tif (biasMask[k]*bias[k]!=0) ncount++;\n\t\t\t\t}       \n\t\t\t}\n\t\t\tLOG(INFO)<<ncount<<\"\\n\";  \t\t\t\n\t\t}*/\t\n\t\t/********************************************************/\t\n\t\t\n\t\t// Calculate the weight mask and bias mask with probability\n\t\tDtype r = static_cast<Dtype>(rand())/static_cast<Dtype>(RAND_MAX);\n\t\tif (pow(1+(this->gamma)*(this->iter_),-(this->power))>r && (this->iter_)<(this->iter_stop_)) { \t\n\t\t\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\t\t\tif (weightMask[k]==1 && fabs(weight[k])<=0.9*std::max(mu+crate*std,Dtype(0)))\n\t\t\t\t\tweightMask[k] = 0;\n\t\t\t\telse if (weightMask[k]==0 && fabs(weight[k])>1.1*std::max(mu+crate*std,Dtype(0)))\n\t\t\t\t\tweightMask[k] = 1;\n\t\t\t}\t\n\t\t\tif (this->bias_term_) {       \n\t\t\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\t\t\tif (biasMask[k]==1 && fabs(bias[k])<=0.9*std::max(mu+crate*std,Dtype(0)))\n\t\t\t\t\t\tbiasMask[k] = 0;\n\t\t\t\t\telse if (biasMask[k]==0 && fabs(bias[k])>1.1*std::max(mu+crate*std,Dtype(0)))\n\t\t\t\t\t\tbiasMask[k] = 1;\n\t\t\t\t}    \n\t\t\t} \n\t\t}\n\t}    \n\t\n  // Calculate the current (masked) weight and bias\n\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\tweightTmp[k] = weight[k]*weightMask[k];\n\t}\n\tif (this->bias_term_){\n\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\tbiasTmp[k] = bias[k]*biasMask[k];\n\t\t}\n\t} \n\t\n\t// Forward calculation with (masked) weight and bias \n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasTrans, M_, N_, K_, (Dtype)1.,\n      bottom_data, weightTmp, (Dtype)0., top_data);\n  if (bias_term_) {\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, N_, 1, (Dtype)1.,\n        bias_multiplier_.cpu_data(), biasTmp, (Dtype)1., top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid CInnerProductLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {  \n\t// Use the masked weight to propagate back\n  const Dtype* top_diff = top[0]->cpu_diff();\n  if (this->param_propagate_down_[0]) {\n\t\tconst Dtype* weightMask = this->blobs_[2]->cpu_data();\n\t\tDtype* weight_diff = this->blobs_[0]->mutable_cpu_diff();\t\t      \n    const Dtype* bottom_data = bottom[0]->cpu_data();    \n    // Gradient with respect to weight\n\t\tfor (unsigned int k = 0;k < this->blobs_[0]->count(); ++k) {\n\t\t\tweight_diff[k] = weight_diff[k]*weightMask[k];\n\t\t}\t\t\n    caffe_cpu_gemm<Dtype>(CblasTrans, CblasNoTrans, N_, K_, M_, (Dtype)1.,\n        top_diff, bottom_data, (Dtype)1., weight_diff);    \n  }\n  if (bias_term_ && this->param_propagate_down_[1]) {\n\t\tconst Dtype* biasMask = this->blobs_[3]->cpu_data();\n    Dtype* bias_diff = this->blobs_[1]->mutable_cpu_diff();\t\t\n    // Gradient with respect to bias\n\t\tfor (unsigned int k = 0;k < this->blobs_[1]->count(); ++k) {\n\t\t\tbias_diff[k] = bias_diff[k]*biasMask[k];\n\t\t}\t\t\n    caffe_cpu_gemv<Dtype>(CblasTrans, M_, N_, (Dtype)1., top_diff,\n        bias_multiplier_.cpu_data(), (Dtype)1., bias_diff);\n  }\n  if (propagate_down[0]) {\n    const\tDtype* weightTmp = this->weight_tmp_.cpu_data();\n    // Gradient with respect to bottom data\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, K_, N_, (Dtype)1.,\n        top_diff, weightTmp, (Dtype)0.,\n        bottom[0]->mutable_cpu_diff());\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(CInnerProductLayer);\n#endif\n\nINSTANTIATE_CLASS(CInnerProductLayer);\nREGISTER_LAYER_CLASS(CInnerProduct);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/compress_inner_product_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n#include <cmath>\n\nnamespace caffe {\n\n// The constant NUM_THREADS should be equal to the value in CCMomentCalc\ntemplate <typename Dtype>\n__global__ void CCMomentCollect(const int n, const Dtype* wb, const Dtype* mask,\n    Dtype* mu, Dtype* std, unsigned int* count ) {  \n  const int NUM_THREADS = 512;  \n  __shared__ Dtype param [4*NUM_THREADS]; \n  __shared__ unsigned int tcount [2*NUM_THREADS];   \n  unsigned int t = threadIdx.x; \n  unsigned int s = 2 * blockIdx.x * NUM_THREADS;\n  if (s+t < n){\n    param[t] = fabs(mask[s+t]*wb[s+t]);\n    param[t+2*NUM_THREADS] = mask[s+t]*wb[s+t]*wb[s+t];\n    if(mask[s+t]*wb[s+t]!=0) tcount[t] = 1;\n    else tcount[t] = 0;\n  }\n  else{\n    param[t] = 0;param[t+2*NUM_THREADS] = 0;tcount[t] = 0;\n  }\n  if (s+t+NUM_THREADS < n){\n    param[t+NUM_THREADS] = fabs(mask[s+t+NUM_THREADS]*wb[s+t+NUM_THREADS]);\n    param[t+3*NUM_THREADS] = mask[s+t+NUM_THREADS]*wb[s+t+NUM_THREADS]*wb[s+t+NUM_THREADS];\n    if(mask[s+t+NUM_THREADS]*wb[s+t+NUM_THREADS]!=0) tcount[t+NUM_THREADS] = 1;\n    else tcount[t+NUM_THREADS] = 0;\n  }\n  else{\n    param[t+NUM_THREADS] = 0;param[t+3*NUM_THREADS] = 0;tcount[t+NUM_THREADS] = 0;  \n  }\n  __syncthreads(); \n  for(unsigned int stride = NUM_THREADS; stride >= 1; stride >>= 1) {\n    if (t < stride ){\n      param[t] += param[t+stride]; \n      param[t+2*NUM_THREADS] += param[t+2*NUM_THREADS+stride];\n      tcount[t] += tcount[t+stride];\n    }\n    __syncthreads();  \n  }\n  if (t == 0){\n    mu   [blockIdx.x] = param[0];\n    std  [blockIdx.x] = param[2*NUM_THREADS];\n    count[blockIdx.x] = tcount[0]; \n  }      \n}\n\n// The constant NUM_THREADS should be equal to the value in CCMomentCalc\ntemplate <typename Dtype>\n__global__ void CCNzeroCollect(const int n, const Dtype* mask, unsigned int* count ) {  \n  const int NUM_THREADS = 512;  \n  __shared__ unsigned int tcount [2*NUM_THREADS];   \n  unsigned int t = threadIdx.x; \n  unsigned int s = 2 * blockIdx.x * NUM_THREADS;\n  tcount[t] = 0;\n  if (s+t < n && mask[s+t]!=0){\n    tcount[t] = 1;\n  }\n  tcount[t+NUM_THREADS] = 0;\n  if (s+t+NUM_THREADS < n && mask[s+t+NUM_THREADS]!=0){\n    tcount[t+NUM_THREADS] = 1;\n  }\n  __syncthreads(); \n  for(unsigned int stride = NUM_THREADS; stride >= 1; stride >>= 1) {\n    if (t < stride ){\n      tcount[t] += tcount[t+stride];\n    }\n    __syncthreads();  \n  }\n  if (t == 0){\n    count[blockIdx.x] = tcount[0]; \n  }     \n}\n\ntemplate <typename Dtype>\n__global__ void CCMaskCalc(const int n, const Dtype* wb,\n    Dtype* mask, Dtype mu, Dtype std, Dtype r) {\n  CUDA_KERNEL_LOOP(index, n) {\n    if (mask[index]==1 && fabs(wb[index])<=0.9*max(mu+r*std,Dtype(0))) \n      mask[index] = 0;\n    else if (mask[index]==0 && fabs(wb[index])>1.1*max(mu+r*std,Dtype(0)))\n      mask[index] = 1;\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void CCMaskApply(const int n, const Dtype* wb,\n    const Dtype* mask, Dtype* wb_t) {\n  CUDA_KERNEL_LOOP(index, n) {\n    wb_t[index] = wb[index] * mask[index];    \n  }\n}\n\ntemplate <typename Dtype>\nvoid CCMomentCalc(const int n, const Dtype* wb, const Dtype* mask, Dtype* mu, Dtype* std, unsigned int* ncount){ \n  const unsigned int NUM_THREADS = 512;\n  Dtype* pmu_g; Dtype* pstd_g; unsigned int* pncount_g;\n  Dtype* pmu_c; Dtype* pstd_c; unsigned int* pncount_c;\n  int num_p = (n+(NUM_THREADS<<1)-1)/(NUM_THREADS<<1);  \n  cudaMalloc(&pmu_g, sizeof(Dtype)  * num_p);\n  cudaMalloc(&pstd_g, sizeof(Dtype) * num_p);\n  cudaMalloc(&pncount_g, sizeof(unsigned int) * num_p);\n  pmu_c = (Dtype*) malloc(num_p * sizeof(Dtype));\n  pstd_c = (Dtype*) malloc(num_p * sizeof(Dtype)); \n  pncount_c = (unsigned int*) malloc(num_p * sizeof(unsigned int));      \n  CCMomentCollect<Dtype><<<num_p,NUM_THREADS>>>(n, wb, mask, pmu_g, pstd_g, pncount_g);\n  CUDA_POST_KERNEL_CHECK; \n  cudaMemcpy(pmu_c, pmu_g, sizeof(Dtype) * num_p, cudaMemcpyDeviceToHost);\n  cudaMemcpy(pstd_c, pstd_g, sizeof(Dtype) * num_p, cudaMemcpyDeviceToHost);\n  cudaMemcpy(pncount_c, pncount_g, sizeof(unsigned int) * num_p, cudaMemcpyDeviceToHost);      \n  for (int i = 0; i < num_p; i++) {\n    *mu += pmu_c[i];*std += pstd_c[i];*ncount += pncount_c[i];\n  }       \n  cudaFree(pmu_g);cudaFree(pstd_g);cudaFree(pncount_g);\n  free(pmu_c);free(pstd_c);free(pncount_c);\n}\n\ntemplate <typename Dtype>\nvoid CCNZeroCalc(const int n, const Dtype* mask, unsigned int* ncount ){   \n  const unsigned int NUM_THREADS = 512;\n  unsigned int* pncount_g;\n  unsigned int* pncount_c;\n  int num_p = (n+(NUM_THREADS<<1)-1)/(NUM_THREADS<<1);  \n  cudaMalloc(&pncount_g, sizeof(unsigned int) * num_p);\n  pncount_c = (unsigned int*) malloc(num_p * sizeof(unsigned int));      \n  CCNzeroCollect<Dtype><<<num_p,NUM_THREADS>>>(n, mask, pncount_g);\n  CUDA_POST_KERNEL_CHECK; \n  cudaMemcpy(pncount_c, pncount_g, sizeof(unsigned int) * num_p, cudaMemcpyDeviceToHost);      \n  for (int i = 0; i < num_p; i++) {\n    *ncount += pncount_c[i];\n  }       \n  cudaFree(pncount_g);\n  free(pncount_c);\n}\n\ntemplate <typename Dtype>\nvoid CInnerProductLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {    \n\n  const Dtype* weight = this->blobs_[0]->mutable_gpu_data();  \n  Dtype* weightMask = this->blobs_[2]->mutable_gpu_data();\n  Dtype* weightTmp = this->weight_tmp_.mutable_gpu_data();  \n  const Dtype* bias = NULL;\n  Dtype* biasMask = NULL;\n  Dtype* biasTmp = NULL;\n  if (this->bias_term_) {  \n    bias = this->blobs_[1]->mutable_gpu_data();   \n    biasMask = this->blobs_[3]->mutable_gpu_data();\n    biasTmp = this->bias_tmp_.mutable_gpu_data();\n  }   \n    \n  if (this->phase_ == TRAIN){\n\t\t// Calculate the mean and standard deviation of learnable parameters \t\t\n    if (this->std==0 && this->iter_==0){\n      unsigned int ncount = 0;\n      CCMomentCalc(this->blobs_[0]->count(), weight, weightMask, &mu, &std, &ncount);\n      if (this->bias_term_) {  \n        CCMomentCalc(this->blobs_[1]->count(), bias, biasMask, &mu, &std, &ncount); \n      }     \n      this->mu /= ncount; this->std -= ncount*mu*mu; \n      this->std /= ncount; this->std = sqrt(std);  \n      LOG(INFO)<<mu<<\"  \"<<std<<\"  \"<<ncount<<\"\\n\";                    \n    }\n\t\t\n\t\t// Demonstrate the sparsity of compressed fully-connected layer\n\t\t/********************************************************/\n\t\t/*if(this->iter_%100==0){\n\t\t\tunsigned int ncount = 0;\n\t\t\tCCNZeroCalc(this->blobs_[0]->count(), weightMask, &ncount);\n\t\t\tif (this->bias_term_) {  \n\t\t\t\tCCNZeroCalc(this->blobs_[1]->count(), biasMask, &ncount);   \n\t\t\t}\n\t\t\tLOG(INFO)<<ncount<<\"\\n\";  \t\t\t\n\t\t}*/\t\n\t\t/********************************************************/\t\t\n\t\t\n\t\t// Calculate the weight mask and bias mask with probability\n    Dtype r = static_cast<Dtype>(rand())/static_cast<Dtype>(RAND_MAX);\n    if (pow(1+(this->gamma)*(this->iter_),-(this->power))>r && (this->iter_)<(this->iter_stop_)) { \n      CCMaskCalc<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[0]->count()),\n        CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[0]->count(), weight, weightMask, this->mu, this->std, this->crate);\n      CUDA_POST_KERNEL_CHECK;    \n      if (this->bias_term_) {  \n        CCMaskCalc<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[1]->count()),\n          CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[1]->count(), bias, biasMask, this->mu, this->std, this->crate);\n        CUDA_POST_KERNEL_CHECK;  \n      }    \n    }\n  }  \n  \n  // Calculate the current (masked) weight and bias\n  CCMaskApply<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[0]->count()),\n    CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[0]->count(), weight, weightMask, weightTmp);\n  CUDA_POST_KERNEL_CHECK;\n  if (this->bias_term_) {  \n    CCMaskApply<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[1]->count()),\n      CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[1]->count(), bias, biasMask, biasTmp);\n    CUDA_POST_KERNEL_CHECK;  \n  } \n   \n\t// Forward calculation with (masked) weight and bias \n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  if (M_ == 1) {\n    caffe_gpu_gemv<Dtype>(CblasNoTrans, N_, K_, (Dtype)1.,\n                         weightTmp, bottom_data, (Dtype)0., top_data);\n    if (this->bias_term_)\n      caffe_gpu_axpy<Dtype>(N_, bias_multiplier_.cpu_data()[0],\n                            biasTmp, top_data);\n  } else {\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasTrans, M_, N_, K_, (Dtype)1.,\n                          bottom_data, weightTmp, (Dtype)0., top_data);\n    if (this->bias_term_)\n      caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, N_, 1, (Dtype)1.,\n                            bias_multiplier_.gpu_data(),\n                            biasTmp, (Dtype)1., top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid CInnerProductLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->gpu_diff();\n  if (this->param_propagate_down_[0]) {\n\t\tconst Dtype* weightMask = this->blobs_[2]->gpu_data();\n    Dtype* weight_diff = this->blobs_[0]->mutable_gpu_diff();\n    const Dtype* bottom_data = bottom[0]->gpu_data();\n    // Gradient with respect to weight\n\t\tCCMaskApply<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[2]->count()),\n      CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[2]->count(), weight_diff, weightMask, weight_diff);\n    CUDA_POST_KERNEL_CHECK; \n    caffe_gpu_gemm<Dtype>(CblasTrans, CblasNoTrans, N_, K_, M_, (Dtype)1.,\n        top_diff, bottom_data, (Dtype)1., weight_diff);\n  }\n  if (bias_term_ && this->param_propagate_down_[1]) {\n\t\tconst Dtype* biasMask = this->blobs_[3]->gpu_data();\n    Dtype* bias_diff = this->blobs_[1]->mutable_gpu_diff();\n    // Gradient with respect to bias\n    CCMaskApply<Dtype><<<CAFFE_GET_BLOCKS(this->blobs_[3]->count()),\n      CAFFE_CUDA_NUM_THREADS>>>( this->blobs_[3]->count(), bias_diff, biasMask, bias_diff);\n    CUDA_POST_KERNEL_CHECK; \t\t\n    caffe_gpu_gemv<Dtype>(CblasTrans, M_, N_, (Dtype)1., top_diff,\n        bias_multiplier_.gpu_data(), (Dtype)1.,bias_diff);\n  }\t\n  if (propagate_down[0]) {\n\t\tconst Dtype* weightTmp = this->weight_tmp_.gpu_data();        \n    // Gradient with respect to bottom data\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, K_, N_, (Dtype)1.,\n        top_diff, weightTmp, (Dtype)0.,\n        bottom[0]->mutable_gpu_diff());\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(CInnerProductLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/concat_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ConcatLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const ConcatParameter& concat_param = this->layer_param_.concat_param();\n  CHECK(!(concat_param.has_axis() && concat_param.has_concat_dim()))\n      << \"Either axis or concat_dim should be specified; not both.\";\n}\n\ntemplate <typename Dtype>\nvoid ConcatLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int num_axes = bottom[0]->num_axes();\n  const ConcatParameter& concat_param = this->layer_param_.concat_param();\n  if (concat_param.has_concat_dim()) {\n    concat_axis_ = static_cast<int>(concat_param.concat_dim());\n    // Don't allow negative indexing for concat_dim, a uint32 -- almost\n    // certainly unintended.\n    CHECK_GE(concat_axis_, 0) << \"casting concat_dim from uint32 to int32 \"\n        << \"produced negative result; concat_dim must satisfy \"\n        << \"0 <= concat_dim < \" << kMaxBlobAxes;\n    CHECK_LT(concat_axis_, num_axes) << \"concat_dim out of range.\";\n  } else {\n    concat_axis_ = bottom[0]->CanonicalAxisIndex(concat_param.axis());\n  }\n  // Initialize with the first blob.\n  vector<int> top_shape = bottom[0]->shape();\n  num_concats_ = bottom[0]->count(0, concat_axis_);\n  concat_input_size_ = bottom[0]->count(concat_axis_ + 1);\n  int bottom_count_sum = bottom[0]->count();\n  for (int i = 1; i < bottom.size(); ++i) {\n    CHECK_EQ(num_axes, bottom[i]->num_axes())\n        << \"All inputs must have the same #axes.\";\n    for (int j = 0; j < num_axes; ++j) {\n      if (j == concat_axis_) { continue; }\n      CHECK_EQ(top_shape[j], bottom[i]->shape(j))\n          << \"All inputs must have the same shape, except at concat_axis.\";\n    }\n    bottom_count_sum += bottom[i]->count();\n    top_shape[concat_axis_] += bottom[i]->shape(concat_axis_);\n  }\n  top[0]->Reshape(top_shape);\n  CHECK_EQ(bottom_count_sum, top[0]->count());\n}\n\ntemplate <typename Dtype>\nvoid ConcatLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  int offset_concat_axis = 0;\n  const int top_concat_axis = top[0]->shape(concat_axis_);\n  for (int i = 0; i < bottom.size(); ++i) {\n    const Dtype* bottom_data = bottom[i]->cpu_data();\n    const int bottom_concat_axis = bottom[i]->shape(concat_axis_);\n    for (int n = 0; n < num_concats_; ++n) {\n      caffe_copy(bottom_concat_axis * concat_input_size_,\n          bottom_data + n * bottom_concat_axis * concat_input_size_,\n          top_data + (n * top_concat_axis + offset_concat_axis)\n              * concat_input_size_);\n    }\n    offset_concat_axis += bottom_concat_axis;\n  }\n}\n\ntemplate <typename Dtype>\nvoid ConcatLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->cpu_diff();\n  int offset_concat_axis = 0;\n  const int top_concat_axis = top[0]->shape(concat_axis_);\n  for (int i = 0; i < bottom.size(); ++i) {\n    if (!propagate_down[i]) { continue; }\n    Dtype* bottom_diff = bottom[i]->mutable_cpu_diff();\n    const int bottom_concat_axis = bottom[i]->shape(concat_axis_);\n    for (int n = 0; n < num_concats_; ++n) {\n      caffe_copy(bottom_concat_axis * concat_input_size_, top_diff +\n          (n * top_concat_axis + offset_concat_axis) * concat_input_size_,\n          bottom_diff + n * bottom_concat_axis * concat_input_size_);\n    }\n    offset_concat_axis += bottom_concat_axis;\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(ConcatLayer);\n#endif\n\nINSTANTIATE_CLASS(ConcatLayer);\nREGISTER_LAYER_CLASS(Concat);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/concat_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void Concat(const int nthreads, const Dtype* in_data,\n    const bool forward, const int num_concats, const int concat_size,\n    const int top_concat_axis, const int bottom_concat_axis,\n    const int offset_concat_axis, Dtype* out_data) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    const int total_concat_size = concat_size * bottom_concat_axis;\n    const int concat_num = index / total_concat_size;\n    const int concat_index = index % total_concat_size;\n    const int top_index = concat_index +\n        (concat_num * top_concat_axis + offset_concat_axis) * concat_size;\n    if (forward) {\n      out_data[top_index] = in_data[index];\n    } else {\n      out_data[index] = in_data[top_index];\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid ConcatLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  int offset_concat_axis = 0;\n  const int top_concat_axis = top[0]->shape(concat_axis_);\n  const bool kForward = true;\n  for (int i = 0; i < bottom.size(); ++i) {\n    const Dtype* bottom_data = bottom[i]->gpu_data();\n    const int bottom_concat_axis = bottom[i]->shape(concat_axis_);\n    const int bottom_concat_size = bottom_concat_axis * concat_input_size_;\n    const int nthreads = bottom_concat_size * num_concats_;\n    Concat<Dtype>  // NOLINT_NEXT_LINE(whitespace/operators)\n        <<<CAFFE_GET_BLOCKS(nthreads), CAFFE_CUDA_NUM_THREADS>>>(\n        nthreads, bottom_data, kForward, num_concats_, concat_input_size_,\n        top_concat_axis, bottom_concat_axis, offset_concat_axis, top_data);\n    offset_concat_axis += bottom_concat_axis;\n  }\n}\n\ntemplate <typename Dtype>\nvoid ConcatLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->gpu_diff();\n  int offset_concat_axis = 0;\n  const int top_concat_axis = top[0]->shape(concat_axis_);\n  const bool kForward = false;\n  for (int i = 0; i < bottom.size(); ++i) {\n    if (!propagate_down[i]) { continue; }\n    Dtype* bottom_diff = bottom[i]->mutable_gpu_diff();\n    const int bottom_concat_axis = bottom[i]->shape(concat_axis_);\n    const int bottom_concat_size = bottom_concat_axis * concat_input_size_;\n    const int nthreads = bottom_concat_size * num_concats_;\n    Concat<Dtype>  // NOLINT_NEXT_LINE(whitespace/operators)\n        <<<CAFFE_GET_BLOCKS(nthreads), CAFFE_CUDA_NUM_THREADS>>>(\n        nthreads, top_diff, kForward, num_concats_, concat_input_size_,\n        top_concat_axis, bottom_concat_axis, offset_concat_axis, bottom_diff);\n    offset_concat_axis += bottom_concat_axis;\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(ConcatLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/contrastive_loss_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/loss_layers.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ContrastiveLossLayer<Dtype>::LayerSetUp(\n  const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  LossLayer<Dtype>::LayerSetUp(bottom, top);\n  CHECK_EQ(bottom[0]->channels(), bottom[1]->channels());\n  CHECK_EQ(bottom[0]->height(), 1);\n  CHECK_EQ(bottom[0]->width(), 1);\n  CHECK_EQ(bottom[1]->height(), 1);\n  CHECK_EQ(bottom[1]->width(), 1);\n  CHECK_EQ(bottom[2]->channels(), 1);\n  CHECK_EQ(bottom[2]->height(), 1);\n  CHECK_EQ(bottom[2]->width(), 1);\n  diff_.Reshape(bottom[0]->num(), bottom[0]->channels(), 1, 1);\n  diff_sq_.Reshape(bottom[0]->num(), bottom[0]->channels(), 1, 1);\n  dist_sq_.Reshape(bottom[0]->num(), 1, 1, 1);\n  // vector of ones used to sum along channels\n  summer_vec_.Reshape(bottom[0]->channels(), 1, 1, 1);\n  for (int i = 0; i < bottom[0]->channels(); ++i)\n    summer_vec_.mutable_cpu_data()[i] = Dtype(1);\n}\n\ntemplate <typename Dtype>\nvoid ContrastiveLossLayer<Dtype>::Forward_cpu(\n    const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  int count = bottom[0]->count();\n  caffe_sub(\n      count,\n      bottom[0]->cpu_data(),  // a\n      bottom[1]->cpu_data(),  // b\n      diff_.mutable_cpu_data());  // a_i-b_i\n  const int channels = bottom[0]->channels();\n  Dtype margin = this->layer_param_.contrastive_loss_param().margin();\n  bool legacy_version =\n      this->layer_param_.contrastive_loss_param().legacy_version();\n  Dtype loss(0.0);\n  for (int i = 0; i < bottom[0]->num(); ++i) {\n    dist_sq_.mutable_cpu_data()[i] = caffe_cpu_dot(channels,\n        diff_.cpu_data() + (i*channels), diff_.cpu_data() + (i*channels));\n    if (static_cast<int>(bottom[2]->cpu_data()[i])) {  // similar pairs\n      loss += dist_sq_.cpu_data()[i];\n    } else {  // dissimilar pairs\n      if (legacy_version) {\n        loss += std::max(margin - dist_sq_.cpu_data()[i], Dtype(0.0));\n      } else {\n        Dtype dist = std::max(margin - sqrt(dist_sq_.cpu_data()[i]), 0.0);\n        loss += dist*dist;\n      }\n    }\n  }\n  loss = loss / static_cast<Dtype>(bottom[0]->num()) / Dtype(2);\n  top[0]->mutable_cpu_data()[0] = loss;\n}\n\ntemplate <typename Dtype>\nvoid ContrastiveLossLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  Dtype margin = this->layer_param_.contrastive_loss_param().margin();\n  bool legacy_version =\n      this->layer_param_.contrastive_loss_param().legacy_version();\n  for (int i = 0; i < 2; ++i) {\n    if (propagate_down[i]) {\n      const Dtype sign = (i == 0) ? 1 : -1;\n      const Dtype alpha = sign * top[0]->cpu_diff()[0] /\n          static_cast<Dtype>(bottom[i]->num());\n      int num = bottom[i]->num();\n      int channels = bottom[i]->channels();\n      for (int j = 0; j < num; ++j) {\n        Dtype* bout = bottom[i]->mutable_cpu_diff();\n        if (static_cast<int>(bottom[2]->cpu_data()[j])) {  // similar pairs\n          caffe_cpu_axpby(\n              channels,\n              alpha,\n              diff_.cpu_data() + (j*channels),\n              Dtype(0.0),\n              bout + (j*channels));\n        } else {  // dissimilar pairs\n          Dtype mdist(0.0);\n          Dtype beta(0.0);\n          if (legacy_version) {\n            mdist = margin - dist_sq_.cpu_data()[j];\n            beta = -alpha;\n          } else {\n            Dtype dist = sqrt(dist_sq_.cpu_data()[j]);\n            mdist = margin - dist;\n            beta = -alpha * mdist / (dist + Dtype(1e-4));\n          }\n          if (mdist > Dtype(0.0)) {\n            caffe_cpu_axpby(\n                channels,\n                beta,\n                diff_.cpu_data() + (j*channels),\n                Dtype(0.0),\n                bout + (j*channels));\n          } else {\n            caffe_set(channels, Dtype(0), bout + (j*channels));\n          }\n        }\n      }\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(ContrastiveLossLayer);\n#endif\n\nINSTANTIATE_CLASS(ContrastiveLossLayer);\nREGISTER_LAYER_CLASS(ContrastiveLoss);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/contrastive_loss_layer.cu",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ContrastiveLossLayer<Dtype>::Forward_gpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  const int count = bottom[0]->count();\n  caffe_gpu_sub(\n      count,\n      bottom[0]->gpu_data(),  // a\n      bottom[1]->gpu_data(),  // b\n      diff_.mutable_gpu_data());  // a_i-b_i\n  caffe_gpu_powx(\n      count,\n      diff_.mutable_gpu_data(),  // a_i-b_i\n      Dtype(2),\n      diff_sq_.mutable_gpu_data());  // (a_i-b_i)^2\n  caffe_gpu_gemv(\n      CblasNoTrans,\n      bottom[0]->num(),\n      bottom[0]->channels(),\n      Dtype(1.0),\n      diff_sq_.gpu_data(),  // (a_i-b_i)^2\n      summer_vec_.gpu_data(),\n      Dtype(0.0),\n      dist_sq_.mutable_gpu_data());  // \\Sum (a_i-b_i)^2\n  Dtype margin = this->layer_param_.contrastive_loss_param().margin();\n  bool legacy_version =\n      this->layer_param_.contrastive_loss_param().legacy_version();\n  Dtype loss(0.0);\n  for (int i = 0; i < bottom[0]->num(); ++i) {\n    if (static_cast<int>(bottom[2]->cpu_data()[i])) {  // similar pairs\n      loss += dist_sq_.cpu_data()[i];\n    } else {  // dissimilar pairs\n      if (legacy_version) {\n        loss += std::max(margin - dist_sq_.cpu_data()[i], Dtype(0.0));\n      } else {\n        Dtype dist = std::max(margin - sqrt(dist_sq_.cpu_data()[i]),\n                              Dtype(0.0));\n        loss += dist*dist;\n      }\n    }\n  }\n  loss = loss / static_cast<Dtype>(bottom[0]->num()) / Dtype(2);\n  top[0]->mutable_cpu_data()[0] = loss;\n}\n\ntemplate <typename Dtype>\n__global__ void CLLBackward(const int count, const int channels,\n    const Dtype margin, const bool legacy_version, const Dtype alpha,\n    const Dtype* y, const Dtype* diff, const Dtype* dist_sq,\n    Dtype *bottom_diff) {\n  CUDA_KERNEL_LOOP(i, count) {\n    int n = i / channels;  // the num index, to access y and dist_sq\n    if (static_cast<int>(y[n])) {  // similar pairs\n      bottom_diff[i] = alpha * diff[i];\n    } else {  // dissimilar pairs\n      Dtype mdist(0.0);\n      Dtype beta(0.0);\n      if (legacy_version) {\n        mdist = (margin - dist_sq[n]);\n        beta = -alpha;\n      } else {\n        Dtype dist = sqrt(dist_sq[n]);\n        mdist = (margin - dist);\n        beta = -alpha * mdist / (dist + Dtype(1e-4)) * diff[i];\n      }\n      if (mdist > 0.0) {\n        bottom_diff[i] = beta;\n      } else {\n        bottom_diff[i] = 0;\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid ContrastiveLossLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  for (int i = 0; i < 2; ++i) {\n    if (propagate_down[i]) {\n      const int count = bottom[0]->count();\n      const int channels = bottom[0]->channels();\n      Dtype margin = this->layer_param_.contrastive_loss_param().margin();\n      const bool legacy_version =\n          this->layer_param_.contrastive_loss_param().legacy_version();\n      const Dtype sign = (i == 0) ? 1 : -1;\n      const Dtype alpha = sign * top[0]->cpu_diff()[0] /\n          static_cast<Dtype>(bottom[0]->num());\n      // NOLINT_NEXT_LINE(whitespace/operators)\n      CLLBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n          count, channels, margin, legacy_version, alpha,\n          bottom[2]->gpu_data(),  // pair similarity 0 or 1\n          diff_.gpu_data(),  // the cached eltwise difference between a and b\n          dist_sq_.gpu_data(),  // the cached square distance between a and b\n          bottom[i]->mutable_gpu_diff());\n      CUDA_POST_KERNEL_CHECK;\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(ContrastiveLossLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/conv_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ConvolutionLayer<Dtype>::compute_output_shape() {\n  this->height_out_ = (this->height_ + 2 * this->pad_h_ - this->kernel_h_)\n      / this->stride_h_ + 1;\n  this->width_out_ = (this->width_ + 2 * this->pad_w_ - this->kernel_w_)\n      / this->stride_w_ + 1;\n}\n\ntemplate <typename Dtype>\nvoid ConvolutionLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const Dtype* weight = this->blobs_[0]->cpu_data();\n  for (int i = 0; i < bottom.size(); ++i) {\n    const Dtype* bottom_data = bottom[i]->cpu_data();\n    Dtype* top_data = top[i]->mutable_cpu_data();\n    for (int n = 0; n < this->num_; ++n) {\n      this->forward_cpu_gemm(bottom_data + bottom[i]->offset(n), weight,\n          top_data + top[i]->offset(n));\n      if (this->bias_term_) {\n        const Dtype* bias = this->blobs_[1]->cpu_data();\n        this->forward_cpu_bias(top_data + top[i]->offset(n), bias);\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid ConvolutionLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* weight = this->blobs_[0]->cpu_data();\n  Dtype* weight_diff = this->blobs_[0]->mutable_cpu_diff();\n  for (int i = 0; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->cpu_diff();\n    const Dtype* bottom_data = bottom[i]->cpu_data();\n    Dtype* bottom_diff = bottom[i]->mutable_cpu_diff();\n    // Bias gradient, if necessary.\n    if (this->bias_term_ && this->param_propagate_down_[1]) {\n      Dtype* bias_diff = this->blobs_[1]->mutable_cpu_diff();\n      for (int n = 0; n < this->num_; ++n) {\n        this->backward_cpu_bias(bias_diff, top_diff + top[i]->offset(n));\n      }\n    }\n    if (this->param_propagate_down_[0] || propagate_down[i]) {\n      for (int n = 0; n < this->num_; ++n) {\n        // gradient w.r.t. weight. Note that we will accumulate diffs.\n        if (this->param_propagate_down_[0]) {\n          this->weight_cpu_gemm(bottom_data + bottom[i]->offset(n),\n              top_diff + top[i]->offset(n), weight_diff);\n        }\n        // gradient w.r.t. bottom data, if necessary.\n        if (propagate_down[i]) {\n          this->backward_cpu_gemm(top_diff + top[i]->offset(n), weight,\n              bottom_diff + bottom[i]->offset(n));\n        }\n      }\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(ConvolutionLayer);\n#endif\n\nINSTANTIATE_CLASS(ConvolutionLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/conv_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ConvolutionLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const Dtype* weight = this->blobs_[0]->gpu_data();\n  for (int i = 0; i < bottom.size(); ++i) {\n    const Dtype* bottom_data = bottom[i]->gpu_data();\n    Dtype* top_data = top[i]->mutable_gpu_data();\n    for (int n = 0; n < this->num_; ++n) {\n      this->forward_gpu_gemm(bottom_data + bottom[i]->offset(n), weight,\n          top_data + top[i]->offset(n));\n      if (this->bias_term_) {\n        const Dtype* bias = this->blobs_[1]->gpu_data();\n        this->forward_gpu_bias(top_data + top[i]->offset(n), bias);\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid ConvolutionLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* weight = this->blobs_[0]->gpu_data();\n  Dtype* weight_diff = this->blobs_[0]->mutable_gpu_diff();\n  for (int i = 0; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->gpu_diff();\n    // Bias gradient, if necessary.\n    if (this->bias_term_ && this->param_propagate_down_[1]) {\n      Dtype* bias_diff = this->blobs_[1]->mutable_gpu_diff();\n      for (int n = 0; n < this->num_; ++n) {\n        this->backward_gpu_bias(bias_diff, top_diff + top[i]->offset(n));\n      }\n    }\n    if (this->param_propagate_down_[0] || propagate_down[i]) {\n      const Dtype* bottom_data = bottom[i]->gpu_data();\n      Dtype* bottom_diff = bottom[i]->mutable_gpu_diff();\n      for (int n = 0; n < this->num_; ++n) {\n        // gradient w.r.t. weight. Note that we will accumulate diffs.\n        if (this->param_propagate_down_[0]) {\n          this->weight_gpu_gemm(bottom_data + bottom[i]->offset(n),\n              top_diff + top[i]->offset(n), weight_diff);\n        }\n        // gradient w.r.t. bottom data, if necessary.\n        if (propagate_down[i]) {\n          this->backward_gpu_gemm(top_diff + top[i]->offset(n), weight,\n              bottom_diff + bottom[i]->offset(n));\n        }\n      }\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(ConvolutionLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/cudnn_conv_layer.cpp",
    "content": "#ifdef USE_CUDNN\n#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\n// Set to three for the benefit of the backward pass, which\n// can use separate streams for calculating the gradient w.r.t.\n// bias, filter weights, and bottom data for each group independently\n#define CUDNN_STREAMS_PER_GROUP 3\n\n/**\n * TODO(dox) explain cuDNN interface\n */\ntemplate <typename Dtype>\nvoid CuDNNConvolutionLayer<Dtype>::LayerSetUp(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  ConvolutionLayer<Dtype>::LayerSetUp(bottom, top);\n  // Initialize CUDA streams and cuDNN.\n  stream_         = new cudaStream_t[this->group_ * CUDNN_STREAMS_PER_GROUP];\n  handle_         = new cudnnHandle_t[this->group_ * CUDNN_STREAMS_PER_GROUP];\n  workspaceSizeInBytes = 0;\n  workspace = NULL;\n\n  for (int g = 0; g < this->group_ * CUDNN_STREAMS_PER_GROUP; g++) {\n    CUDA_CHECK(cudaStreamCreate(&stream_[g]));\n    CUDNN_CHECK(cudnnCreate(&handle_[g]));\n    CUDNN_CHECK(cudnnSetStream(handle_[g], stream_[g]));\n  }\n\n  // Set the indexing parameters.\n  weight_offset_ = (this->num_output_ / this->group_)\n      * (this->channels_ / this->group_) * this->kernel_h_ * this->kernel_w_;\n  bias_offset_ = (this->num_output_ / this->group_);\n\n  // Create filter descriptor.\n  cudnn::createFilterDesc<Dtype>(&filter_desc_,\n      this->num_output_ / this->group_, this->channels_ / this->group_,\n      this->kernel_h_, this->kernel_w_);\n\n  // Create tensor descriptor(s) for data and corresponding convolution(s).\n  for (int i = 0; i < bottom.size(); i++) {\n    cudnnTensorDescriptor_t bottom_desc;\n    cudnn::createTensor4dDesc<Dtype>(&bottom_desc);\n    bottom_descs_.push_back(bottom_desc);\n    cudnnTensorDescriptor_t top_desc;\n    cudnn::createTensor4dDesc<Dtype>(&top_desc);\n    top_descs_.push_back(top_desc);\n    cudnnConvolutionDescriptor_t conv_desc;\n    cudnn::createConvolutionDesc<Dtype>(&conv_desc);\n    conv_descs_.push_back(conv_desc);\n  }\n\n  // Tensor descriptor for bias.\n  if (this->bias_term_) {\n    cudnn::createTensor4dDesc<Dtype>(&bias_desc_);\n  }\n\n  handles_setup_ = true;\n}\n\ntemplate <typename Dtype>\nvoid CuDNNConvolutionLayer<Dtype>::Reshape(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  ConvolutionLayer<Dtype>::Reshape(bottom, top);\n  bottom_offset_ = (this->channels_ / this->group_)\n      * this->height_ * this->width_;\n  top_offset_ = (this->num_output_ / this->group_)\n      * this->height_out_ * this->width_out_;\n\n  for (int i = 0; i < bottom.size(); i++) {\n    cudnn::setTensor4dDesc<Dtype>(&bottom_descs_[i],\n        this->num_,\n        this->channels_ / this->group_,\n        this->height_, this->width_,\n        this->channels_ * this->height_ * this->width_,\n        this->height_ * this->width_,\n        this->width_, 1);\n    cudnn::setTensor4dDesc<Dtype>(&top_descs_[i],\n        this->num_,\n        this->num_output_ / this->group_,\n        this->height_out_, this->width_out_,\n        this->num_output_ * this->height_out_ * this->width_out_,\n        this->height_out_ * this->width_out_,\n        this->width_out_, 1);\n    cudnn::setConvolutionDesc<Dtype>(&conv_descs_[i], bottom_descs_[i],\n        filter_desc_, this->pad_h_, this->pad_w_,\n        this->stride_h_, this->stride_w_);\n  }\n\n  // Tensor descriptor for bias.\n  if (this->bias_term_) {\n    cudnn::setTensor4dDesc<Dtype>(&bias_desc_,\n        1, this->num_output_ / this->group_, 1, 1);\n  }\n}\n\ntemplate <typename Dtype>\nCuDNNConvolutionLayer<Dtype>::~CuDNNConvolutionLayer() {\n  // Check that handles have been setup before destroying.\n  if (!handles_setup_) { return; }\n\n  for (int i = 0; i < bottom_descs_.size(); i++) {\n    cudnnDestroyTensorDescriptor(bottom_descs_[i]);\n    cudnnDestroyTensorDescriptor(top_descs_[i]);\n    cudnnDestroyConvolutionDescriptor(conv_descs_[i]);\n  }\n  if (this->bias_term_) {\n    cudnnDestroyTensorDescriptor(bias_desc_);\n  }\n  cudnnDestroyFilterDescriptor(filter_desc_);\n\n  for (int g = 0; g < this->group_ * CUDNN_STREAMS_PER_GROUP; g++) {\n    cudaStreamDestroy(stream_[g]);\n    cudnnDestroy(handle_[g]);\n  }\n\n  delete [] stream_;\n  delete [] handle_;\n}\n\nINSTANTIATE_CLASS(CuDNNConvolutionLayer);\n\n}   // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_conv_layer.cu",
    "content": "#ifdef USE_CUDNN\n#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\n__global__ void sync_conv_groups() { }\n\ntemplate <typename Dtype>\nvoid CuDNNConvolutionLayer<Dtype>::Forward_gpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  for (int i = 0; i < bottom.size(); ++i) {\n    const Dtype* bottom_data = bottom[i]->gpu_data();\n    Dtype* top_data = top[i]->mutable_gpu_data();\n    const Dtype* weight = this->blobs_[0]->gpu_data();\n\n    size_t workspace_limit_bytes = this->kernel_h_ *\n                                   this->kernel_w_ *\n                                   this->channels_ *\n                                   sizeof(int) + 1;\n\n    // Forward through cuDNN in parallel over groups.\n    for (int g = 0; g < this->group_; g++) {\n      cudnnConvolutionFwdAlgo_t algo;\n\n      // pick the convolution algorithm\n      // TODO(shelhamer) this should be done during reshape\n      // TODO(shelhamer) the choice of automatic or manual algorithm picking\n      // should be exposed in proto\n      CUDNN_CHECK(cudnnGetConvolutionForwardAlgorithm(handle_[g],\n        bottom_descs_[i],\n        filter_desc_,\n        conv_descs_[i],\n        top_descs_[i],\n        CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT,\n        workspace_limit_bytes,  // memoryLimitInBytes,\n        &algo));\n\n      // get minimum size of the workspace needed for the desired algorithm\n      size_t workspaceSizeInBytes_temp = 0;\n\n      CUDNN_CHECK(cudnnGetConvolutionForwardWorkspaceSize(handle_[g],\n        bottom_descs_[i],\n        filter_desc_,\n        conv_descs_[i],\n        top_descs_[i],\n        algo,\n        &workspaceSizeInBytes_temp));\n\n      if (workspaceSizeInBytes_temp > workspaceSizeInBytes) {\n        workspaceSizeInBytes = workspaceSizeInBytes_temp;\n        // free the existing workspace and allocate a new (larger) one\n        cudaFree(this->workspace);\n        cudaError_t err = cudaMalloc(&(this->workspace), workspaceSizeInBytes);\n        if (err != cudaSuccess) {\n          // force zero memory path\n          algo = CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_GEMM;\n          workspace = NULL;\n          workspaceSizeInBytes = 0;\n        }\n      }\n\n      // Filters.\n      CUDNN_CHECK(cudnnConvolutionForward(handle_[g],\n            cudnn::dataType<Dtype>::one,\n            bottom_descs_[i], bottom_data + bottom_offset_ * g,\n            filter_desc_, weight + weight_offset_ * g,\n            conv_descs_[i],\n            algo, workspace, workspaceSizeInBytes,\n            cudnn::dataType<Dtype>::zero,\n            top_descs_[i], top_data + top_offset_ * g));\n\n      // Bias.\n      if (this->bias_term_) {\n        const Dtype* bias_data = this->blobs_[1]->gpu_data();\n        CUDNN_CHECK(cudnnAddTensor(handle_[g], CUDNN_ADD_SAME_C,\n              cudnn::dataType<Dtype>::one,\n              bias_desc_, bias_data + bias_offset_ * g,\n              cudnn::dataType<Dtype>::one,\n              top_descs_[i], top_data + top_offset_ * g));\n      }\n    }\n\n    // Synchronize the work across groups, each of which went into its own\n    // stream, by launching an empty kernel into the default (null) stream.\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    sync_conv_groups<<<1, 1>>>();\n  }\n}\n\ntemplate <typename Dtype>\nvoid CuDNNConvolutionLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* weight = NULL;\n  Dtype* weight_diff = NULL;\n  if (this->param_propagate_down_[0]) {\n    weight = this->blobs_[0]->gpu_data();\n    weight_diff = this->blobs_[0]->mutable_gpu_diff();\n  }\n  Dtype* bias_diff = NULL;\n  if (this->bias_term_ && this->param_propagate_down_[1]) {\n    bias_diff = this->blobs_[1]->mutable_gpu_diff();\n  }\n  for (int i = 0; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->gpu_diff();\n    // Backward through cuDNN in parallel over groups and gradients.\n    for (int g = 0; g < this->group_; g++) {\n      // Gradient w.r.t. bias.\n      if (this->bias_term_ && this->param_propagate_down_[1]) {\n        CUDNN_CHECK(cudnnConvolutionBackwardBias(handle_[0*this->group_ + g],\n              cudnn::dataType<Dtype>::one,\n              top_descs_[i],  top_diff + top_offset_ * g,\n              cudnn::dataType<Dtype>::one,\n              bias_desc_, bias_diff + bias_offset_ * g));\n      }\n\n      // Gradient w.r.t. weights.\n      if (this->param_propagate_down_[0]) {\n        const Dtype* bottom_data = bottom[i]->gpu_data();\n        CUDNN_CHECK(cudnnConvolutionBackwardFilter(handle_[1*this->group_ + g],\n              cudnn::dataType<Dtype>::one,\n              bottom_descs_[i], bottom_data + bottom_offset_ * g,\n              top_descs_[i],    top_diff + top_offset_ * g,\n              conv_descs_[i],\n              cudnn::dataType<Dtype>::one,\n              filter_desc_, weight_diff + weight_offset_ * g));\n      }\n\n      // Gradient w.r.t. bottom data.\n      if (propagate_down[i]) {\n        if (weight == NULL) {\n          weight = this->blobs_[0]->gpu_data();\n        }\n        Dtype* bottom_diff = bottom[i]->mutable_gpu_diff();\n        CUDNN_CHECK(cudnnConvolutionBackwardData(handle_[2*this->group_ + g],\n              cudnn::dataType<Dtype>::one,\n              filter_desc_, weight + weight_offset_ * g,\n              top_descs_[i], top_diff + top_offset_ * g,\n              conv_descs_[i],\n              cudnn::dataType<Dtype>::zero,\n              bottom_descs_[i], bottom_diff + bottom_offset_ * g));\n      }\n    }\n\n    // Synchronize the work across groups, each of which went into its own\n    // stream, by launching an empty kernel into the default (null) stream.\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    sync_conv_groups<<<1, 1>>>();\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(CuDNNConvolutionLayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_pooling_layer.cpp",
    "content": "#ifdef USE_CUDNN\n#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNPoolingLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  PoolingLayer<Dtype>::LayerSetUp(bottom, top);\n  CUDNN_CHECK(cudnnCreate(&handle_));\n  cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);\n  cudnn::createTensor4dDesc<Dtype>(&top_desc_);\n  cudnn::createPoolingDesc<Dtype>(&pooling_desc_,\n      this->layer_param_.pooling_param().pool(), &mode_,\n      this->kernel_h_, this->kernel_w_, this->pad_h_, this->pad_w_,\n      this->stride_h_, this->stride_w_);\n  handles_setup_ = true;\n}\n\ntemplate <typename Dtype>\nvoid CuDNNPoolingLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  PoolingLayer<Dtype>::Reshape(bottom, top);\n  cudnn::setTensor4dDesc<Dtype>(&bottom_desc_, bottom[0]->num(),\n      this->channels_, this->height_, this->width_);\n  cudnn::setTensor4dDesc<Dtype>(&top_desc_, bottom[0]->num(),\n      this->channels_, this->pooled_height_, this->pooled_width_);\n}\n\ntemplate <typename Dtype>\nCuDNNPoolingLayer<Dtype>::~CuDNNPoolingLayer() {\n  // Check that handles have been setup before destroying.\n  if (!handles_setup_) { return; }\n\n  cudnnDestroyTensorDescriptor(bottom_desc_);\n  cudnnDestroyTensorDescriptor(top_desc_);\n  cudnnDestroyPoolingDescriptor(pooling_desc_);\n  cudnnDestroy(handle_);\n}\n\nINSTANTIATE_CLASS(CuDNNPoolingLayer);\n\n}   // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_pooling_layer.cu",
    "content": "#ifdef USE_CUDNN\n#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNPoolingLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  CUDNN_CHECK(cudnnPoolingForward(handle_, pooling_desc_,\n        cudnn::dataType<Dtype>::one,\n        bottom_desc_, bottom_data,\n        cudnn::dataType<Dtype>::zero,\n        top_desc_, top_data));\n}\n\ntemplate <typename Dtype>\nvoid CuDNNPoolingLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) {\n    return;\n  }\n  const Dtype* top_diff = top[0]->gpu_diff();\n  const Dtype* top_data = top[0]->gpu_data();\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n  CUDNN_CHECK(cudnnPoolingBackward(handle_, pooling_desc_,\n        cudnn::dataType<Dtype>::one,\n        top_desc_, top_data, top_desc_, top_diff,\n        bottom_desc_, bottom_data,\n        cudnn::dataType<Dtype>::zero,\n        bottom_desc_, bottom_diff));\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(CuDNNPoolingLayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_relu_layer.cpp",
    "content": "#ifdef USE_CUDNN\n#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNReLULayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  ReLULayer<Dtype>::LayerSetUp(bottom, top);\n  // initialize cuDNN\n  CUDNN_CHECK(cudnnCreate(&handle_));\n  cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);\n  cudnn::createTensor4dDesc<Dtype>(&top_desc_);\n  handles_setup_ = true;\n}\n\ntemplate <typename Dtype>\nvoid CuDNNReLULayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  ReLULayer<Dtype>::Reshape(bottom, top);\n  const int N = bottom[0]->num();\n  const int K = bottom[0]->channels();\n  const int H = bottom[0]->height();\n  const int W = bottom[0]->width();\n  cudnn::setTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);\n  cudnn::setTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);\n}\n\ntemplate <typename Dtype>\nCuDNNReLULayer<Dtype>::~CuDNNReLULayer() {\n  // Check that handles have been setup before destroying.\n  if (!handles_setup_) { return; }\n\n  cudnnDestroyTensorDescriptor(this->bottom_desc_);\n  cudnnDestroyTensorDescriptor(this->top_desc_);\n  cudnnDestroy(this->handle_);\n}\n\nINSTANTIATE_CLASS(CuDNNReLULayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_relu_layer.cu",
    "content": "#ifdef USE_CUDNN\n#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNReLULayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  // Fallback to standard Caffe for leaky ReLU.\n  if (ReLULayer<Dtype>::layer_param_.relu_param().negative_slope() != 0) {\n    return ReLULayer<Dtype>::Forward_gpu(bottom, top);\n  }\n\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  CUDNN_CHECK(cudnnActivationForward(this->handle_,\n        CUDNN_ACTIVATION_RELU,\n        cudnn::dataType<Dtype>::one,\n        this->bottom_desc_, bottom_data,\n        cudnn::dataType<Dtype>::zero,\n        this->top_desc_, top_data));\n}\n\ntemplate <typename Dtype>\nvoid CuDNNReLULayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) {\n    return;\n  }\n\n  // Fallback to standard Caffe for leaky ReLU.\n  if (ReLULayer<Dtype>::layer_param_.relu_param().negative_slope() != 0) {\n    return ReLULayer<Dtype>::Backward_gpu(top, propagate_down, bottom);\n  }\n\n  const Dtype* top_data = top[0]->gpu_data();\n  const Dtype* top_diff = top[0]->gpu_diff();\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n  CUDNN_CHECK(cudnnActivationBackward(this->handle_,\n        CUDNN_ACTIVATION_RELU,\n        cudnn::dataType<Dtype>::one,\n        this->top_desc_, top_data, this->top_desc_, top_diff,\n        this->bottom_desc_, bottom_data,\n        cudnn::dataType<Dtype>::zero,\n        this->bottom_desc_, bottom_diff));\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(CuDNNReLULayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_sigmoid_layer.cpp",
    "content": "#ifdef USE_CUDNN\n#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNSigmoidLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  SigmoidLayer<Dtype>::LayerSetUp(bottom, top);\n  // initialize cuDNN\n  CUDNN_CHECK(cudnnCreate(&handle_));\n  cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);\n  cudnn::createTensor4dDesc<Dtype>(&top_desc_);\n  handles_setup_ = true;\n}\n\ntemplate <typename Dtype>\nvoid CuDNNSigmoidLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  SigmoidLayer<Dtype>::Reshape(bottom, top);\n  const int N = bottom[0]->num();\n  const int K = bottom[0]->channels();\n  const int H = bottom[0]->height();\n  const int W = bottom[0]->width();\n  cudnn::setTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);\n  cudnn::setTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);\n}\n\ntemplate <typename Dtype>\nCuDNNSigmoidLayer<Dtype>::~CuDNNSigmoidLayer() {\n  // Check that handles have been setup before destroying.\n  if (!handles_setup_) { return; }\n\n  cudnnDestroyTensorDescriptor(this->bottom_desc_);\n  cudnnDestroyTensorDescriptor(this->top_desc_);\n  cudnnDestroy(this->handle_);\n}\n\nINSTANTIATE_CLASS(CuDNNSigmoidLayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_sigmoid_layer.cu",
    "content": "#ifdef USE_CUDNN\n#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNSigmoidLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  CUDNN_CHECK(cudnnActivationForward(this->handle_,\n        CUDNN_ACTIVATION_SIGMOID,\n        cudnn::dataType<Dtype>::one,\n        this->bottom_desc_, bottom_data,\n        cudnn::dataType<Dtype>::zero,\n        this->top_desc_, top_data));\n}\n\ntemplate <typename Dtype>\nvoid CuDNNSigmoidLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) {\n    return;\n  }\n\n  const Dtype* top_data = top[0]->gpu_data();\n  const Dtype* top_diff = top[0]->gpu_diff();\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n  CUDNN_CHECK(cudnnActivationBackward(this->handle_,\n        CUDNN_ACTIVATION_SIGMOID,\n        cudnn::dataType<Dtype>::one,\n        this->top_desc_, top_data, this->top_desc_, top_diff,\n        this->bottom_desc_, bottom_data,\n        cudnn::dataType<Dtype>::zero,\n        this->bottom_desc_, bottom_diff));\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(CuDNNSigmoidLayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_softmax_layer.cpp",
    "content": "#ifdef USE_CUDNN\n#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"thrust/device_vector.h\"\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNSoftmaxLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  SoftmaxLayer<Dtype>::LayerSetUp(bottom, top);\n  // Initialize CUDNN.\n  CUDNN_CHECK(cudnnCreate(&handle_));\n  cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);\n  cudnn::createTensor4dDesc<Dtype>(&top_desc_);\n  handles_setup_ = true;\n}\n\ntemplate <typename Dtype>\nvoid CuDNNSoftmaxLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  SoftmaxLayer<Dtype>::Reshape(bottom, top);\n  int N = this->outer_num_;\n  int K = bottom[0]->shape(this->softmax_axis_);\n  int H = this->inner_num_;\n  int W = 1;\n  cudnn::setTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);\n  cudnn::setTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);\n}\n\ntemplate <typename Dtype>\nCuDNNSoftmaxLayer<Dtype>::~CuDNNSoftmaxLayer() {\n  // Check that handles have been setup before destroying.\n  if (!handles_setup_) { return; }\n\n  cudnnDestroyTensorDescriptor(bottom_desc_);\n  cudnnDestroyTensorDescriptor(top_desc_);\n  cudnnDestroy(handle_);\n}\n\nINSTANTIATE_CLASS(CuDNNSoftmaxLayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_softmax_layer.cu",
    "content": "#ifdef USE_CUDNN\n#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"thrust/device_vector.h\"\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNSoftmaxLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  CUDNN_CHECK(cudnnSoftmaxForward(handle_, CUDNN_SOFTMAX_ACCURATE,\n        CUDNN_SOFTMAX_MODE_CHANNEL,\n        cudnn::dataType<Dtype>::one,\n        bottom_desc_, bottom_data,\n        cudnn::dataType<Dtype>::zero,\n        top_desc_, top_data));\n}\n\ntemplate <typename Dtype>\nvoid CuDNNSoftmaxLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* top_data = top[0]->gpu_data();\n    const Dtype* top_diff = top[0]->gpu_diff();\n    const Dtype* bottom_data = bottom[0]->gpu_data();\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n\n    CUDNN_CHECK(cudnnSoftmaxBackward(handle_, CUDNN_SOFTMAX_ACCURATE,\n          CUDNN_SOFTMAX_MODE_CHANNEL,\n          cudnn::dataType<Dtype>::one,\n          top_desc_, top_data, top_desc_, top_diff,\n          cudnn::dataType<Dtype>::zero,\n          bottom_desc_, bottom_diff));\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(CuDNNSoftmaxLayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_tanh_layer.cpp",
    "content": "#ifdef USE_CUDNN\n#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNTanHLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  TanHLayer<Dtype>::LayerSetUp(bottom, top);\n  // initialize cuDNN\n  CUDNN_CHECK(cudnnCreate(&handle_));\n  cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);\n  cudnn::createTensor4dDesc<Dtype>(&top_desc_);\n  handles_setup_ = true;\n}\n\ntemplate <typename Dtype>\nvoid CuDNNTanHLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  TanHLayer<Dtype>::Reshape(bottom, top);\n  const int N = bottom[0]->num();\n  const int K = bottom[0]->channels();\n  const int H = bottom[0]->height();\n  const int W = bottom[0]->width();\n  cudnn::setTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);\n  cudnn::setTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);\n}\n\ntemplate <typename Dtype>\nCuDNNTanHLayer<Dtype>::~CuDNNTanHLayer() {\n  // Check that handles have been setup before destroying.\n  if (!handles_setup_) { return; }\n\n  cudnnDestroyTensorDescriptor(this->bottom_desc_);\n  cudnnDestroyTensorDescriptor(this->top_desc_);\n  cudnnDestroy(this->handle_);\n}\n\nINSTANTIATE_CLASS(CuDNNTanHLayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/cudnn_tanh_layer.cu",
    "content": "#ifdef USE_CUDNN\n#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid CuDNNTanHLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  CUDNN_CHECK(cudnnActivationForward(this->handle_,\n        CUDNN_ACTIVATION_TANH,\n        cudnn::dataType<Dtype>::one,\n        this->bottom_desc_, bottom_data,\n        cudnn::dataType<Dtype>::zero,\n        this->top_desc_, top_data));\n}\n\ntemplate <typename Dtype>\nvoid CuDNNTanHLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) {\n    return;\n  }\n\n  const Dtype* top_data = top[0]->gpu_data();\n  const Dtype* top_diff = top[0]->gpu_diff();\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n\n  CUDNN_CHECK(cudnnActivationBackward(this->handle_,\n        CUDNN_ACTIVATION_TANH,\n        cudnn::dataType<Dtype>::one,\n        this->top_desc_, top_data, this->top_desc_, top_diff,\n        this->bottom_desc_, bottom_data,\n        cudnn::dataType<Dtype>::zero,\n        this->bottom_desc_, bottom_diff));\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(CuDNNTanHLayer);\n\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/layers/data_layer.cpp",
    "content": "#include <opencv2/core/core.hpp>\n\n#include <stdint.h>\n\n#include <string>\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/benchmark.hpp\"\n#include \"caffe/util/io.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nDataLayer<Dtype>::DataLayer(const LayerParameter& param)\n  : BasePrefetchingDataLayer<Dtype>(param),\n    reader_(param) {\n}\n\ntemplate <typename Dtype>\nDataLayer<Dtype>::~DataLayer() {\n  this->StopInternalThread();\n}\n\ntemplate <typename Dtype>\nvoid DataLayer<Dtype>::DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int batch_size = this->layer_param_.data_param().batch_size();\n  // Read a data point, and use it to initialize the top blob.\n  Datum& datum = *(reader_.full().peek());\n\n  // Use data_transformer to infer the expected blob shape from datum.\n  vector<int> top_shape = this->data_transformer_->InferBlobShape(datum);\n  this->transformed_data_.Reshape(top_shape);\n  // Reshape top[0] and prefetch_data according to the batch_size.\n  top_shape[0] = batch_size;\n  top[0]->Reshape(top_shape);\n  for (int i = 0; i < this->PREFETCH_COUNT; ++i) {\n    this->prefetch_[i].data_.Reshape(top_shape);\n  }\n  LOG(INFO) << \"output data size: \" << top[0]->num() << \",\"\n      << top[0]->channels() << \",\" << top[0]->height() << \",\"\n      << top[0]->width();\n  // label\n  if (this->output_labels_) {\n    vector<int> label_shape(1, batch_size);\n    top[1]->Reshape(label_shape);\n    for (int i = 0; i < this->PREFETCH_COUNT; ++i) {\n      this->prefetch_[i].label_.Reshape(label_shape);\n    }\n  }\n}\n\n// This function is called on prefetch thread\ntemplate<typename Dtype>\nvoid DataLayer<Dtype>::load_batch(Batch<Dtype>* batch) {\n  CPUTimer batch_timer;\n  batch_timer.Start();\n  double read_time = 0;\n  double trans_time = 0;\n  CPUTimer timer;\n  CHECK(batch->data_.count());\n  CHECK(this->transformed_data_.count());\n\n  // Reshape according to the first datum of each batch\n  // on single input batches allows for inputs of varying dimension.\n  const int batch_size = this->layer_param_.data_param().batch_size();\n  Datum& datum = *(reader_.full().peek());\n  // Use data_transformer to infer the expected blob shape from datum.\n  vector<int> top_shape = this->data_transformer_->InferBlobShape(datum);\n  this->transformed_data_.Reshape(top_shape);\n  // Reshape batch according to the batch_size.\n  top_shape[0] = batch_size;\n  batch->data_.Reshape(top_shape);\n\n  Dtype* top_data = batch->data_.mutable_cpu_data();\n  Dtype* top_label = NULL;  // suppress warnings about uninitialized variables\n\n  if (this->output_labels_) {\n    top_label = batch->label_.mutable_cpu_data();\n  }\n  for (int item_id = 0; item_id < batch_size; ++item_id) {\n    timer.Start();\n    // get a datum\n    Datum& datum = *(reader_.full().pop(\"Waiting for data\"));\n    read_time += timer.MicroSeconds();\n    timer.Start();\n    // Apply data transformations (mirror, scale, crop...)\n    int offset = batch->data_.offset(item_id);\n    this->transformed_data_.set_cpu_data(top_data + offset);\n    this->data_transformer_->Transform(datum, &(this->transformed_data_));\n    // Copy label.\n    if (this->output_labels_) {\n      top_label[item_id] = datum.label();\n    }\n    trans_time += timer.MicroSeconds();\n\n    reader_.free().push(const_cast<Datum*>(&datum));\n  }\n  timer.Stop();\n  batch_timer.Stop();\n  DLOG(INFO) << \"Prefetch batch: \" << batch_timer.MilliSeconds() << \" ms.\";\n  DLOG(INFO) << \"     Read time: \" << read_time / 1000 << \" ms.\";\n  DLOG(INFO) << \"Transform time: \" << trans_time / 1000 << \" ms.\";\n}\n\nINSTANTIATE_CLASS(DataLayer);\nREGISTER_LAYER_CLASS(Data);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/deconv_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid DeconvolutionLayer<Dtype>::compute_output_shape() {\n  this->height_out_ = this->stride_h_ * (this->height_ - 1) + this->kernel_h_\n      - 2 * this->pad_h_;\n  this->width_out_ = this->stride_w_ * (this->width_ - 1) + this->kernel_w_\n      - 2 * this->pad_w_;\n}\n\ntemplate <typename Dtype>\nvoid DeconvolutionLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const Dtype* weight = this->blobs_[0]->cpu_data();\n  for (int i = 0; i < bottom.size(); ++i) {\n    const Dtype* bottom_data = bottom[i]->cpu_data();\n    Dtype* top_data = top[i]->mutable_cpu_data();\n    for (int n = 0; n < this->num_; ++n) {\n      this->backward_cpu_gemm(bottom_data + bottom[i]->offset(n), weight,\n          top_data + top[i]->offset(n));\n      if (this->bias_term_) {\n        const Dtype* bias = this->blobs_[1]->cpu_data();\n        this->forward_cpu_bias(top_data + top[i]->offset(n), bias);\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid DeconvolutionLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* weight = this->blobs_[0]->cpu_data();\n  Dtype* weight_diff = this->blobs_[0]->mutable_cpu_diff();\n  for (int i = 0; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->cpu_diff();\n    const Dtype* bottom_data = bottom[i]->cpu_data();\n    Dtype* bottom_diff = bottom[i]->mutable_cpu_diff();\n    // Bias gradient, if necessary.\n    if (this->bias_term_ && this->param_propagate_down_[1]) {\n      Dtype* bias_diff = this->blobs_[1]->mutable_cpu_diff();\n      for (int n = 0; n < this->num_; ++n) {\n        this->backward_cpu_bias(bias_diff, top_diff + top[i]->offset(n));\n      }\n    }\n    if (this->param_propagate_down_[0] || propagate_down[i]) {\n      for (int n = 0; n < this->num_; ++n) {\n        // Gradient w.r.t. weight. Note that we will accumulate diffs.\n        if (this->param_propagate_down_[0]) {\n          this->weight_cpu_gemm(top_diff + top[i]->offset(n),\n              bottom_data + bottom[i]->offset(n), weight_diff);\n        }\n        // Gradient w.r.t. bottom data, if necessary, reusing the column buffer\n        // we might have just computed above.\n        if (propagate_down[i]) {\n          this->forward_cpu_gemm(top_diff + top[i]->offset(n), weight,\n              bottom_diff + bottom[i]->offset(n),\n              this->param_propagate_down_[0]);\n        }\n      }\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(DeconvolutionLayer);\n#endif\n\nINSTANTIATE_CLASS(DeconvolutionLayer);\nREGISTER_LAYER_CLASS(Deconvolution);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/deconv_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid DeconvolutionLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const Dtype* weight = this->blobs_[0]->gpu_data();\n  for (int i = 0; i < bottom.size(); ++i) {\n    const Dtype* bottom_data = bottom[i]->gpu_data();\n    Dtype* top_data = top[i]->mutable_gpu_data();\n    for (int n = 0; n < this->num_; ++n) {\n      this->backward_gpu_gemm(bottom_data + bottom[i]->offset(n), weight,\n          top_data + top[i]->offset(n));\n      if (this->bias_term_) {\n        const Dtype* bias = this->blobs_[1]->gpu_data();\n        this->forward_gpu_bias(top_data + top[i]->offset(n), bias);\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid DeconvolutionLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* weight = this->blobs_[0]->gpu_data();\n  Dtype* weight_diff = this->blobs_[0]->mutable_gpu_diff();\n  for (int i = 0; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->gpu_diff();\n    const Dtype* bottom_data = bottom[i]->gpu_data();\n    Dtype* bottom_diff = bottom[i]->mutable_gpu_diff();\n    // Bias gradient, if necessary.\n    if (this->bias_term_ && this->param_propagate_down_[1]) {\n      Dtype* bias_diff = this->blobs_[1]->mutable_gpu_diff();\n      for (int n = 0; n < this->num_; ++n) {\n        this->backward_gpu_bias(bias_diff, top_diff + top[i]->offset(n));\n      }\n    }\n    if (this->param_propagate_down_[0] || propagate_down[i]) {\n      for (int n = 0; n < this->num_; ++n) {\n        // gradient w.r.t. weight. Note that we will accumulate diffs.\n        if (this->param_propagate_down_[0]) {\n          this->weight_gpu_gemm(top_diff + top[i]->offset(n),\n              bottom_data + bottom[i]->offset(n), weight_diff);\n        }\n        // gradient w.r.t. bottom data, if necessary.\n        if (propagate_down[i]) {\n          this->forward_gpu_gemm(top_diff + top[i]->offset(n), weight,\n              bottom_diff + bottom[i]->offset(n));\n        }\n      }\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(DeconvolutionLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/dropout_layer.cpp",
    "content": "// TODO (sergeyk): effect should not be dependent on phase. wasted memcpy.\n\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid DropoutLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  NeuronLayer<Dtype>::LayerSetUp(bottom, top);\n  threshold_ = this->layer_param_.dropout_param().dropout_ratio();\n  DCHECK(threshold_ > 0.);\n  DCHECK(threshold_ < 1.);\n  scale_ = 1. / (1. - threshold_);\n  uint_thres_ = static_cast<unsigned int>(UINT_MAX * threshold_);\n}\n\ntemplate <typename Dtype>\nvoid DropoutLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  NeuronLayer<Dtype>::Reshape(bottom, top);\n  // Set up the cache for random number generation\n  rand_vec_.Reshape(bottom[0]->num(), bottom[0]->channels(),\n      bottom[0]->height(), bottom[0]->width());\n}\n\ntemplate <typename Dtype>\nvoid DropoutLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  unsigned int* mask = rand_vec_.mutable_cpu_data();\n  const int count = bottom[0]->count();\n  if (this->phase_ == TRAIN) {\n    // Create random numbers\n    caffe_rng_bernoulli(count, 1. - threshold_, mask);\n    for (int i = 0; i < count; ++i) {\n      top_data[i] = bottom_data[i] * mask[i] * scale_;\n    }\n  } else {\n    caffe_copy(bottom[0]->count(), bottom_data, top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid DropoutLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* top_diff = top[0]->cpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    if (this->phase_ == TRAIN) {\n      const unsigned int* mask = rand_vec_.cpu_data();\n      const int count = bottom[0]->count();\n      for (int i = 0; i < count; ++i) {\n        bottom_diff[i] = top_diff[i] * mask[i] * scale_;\n      }\n    } else {\n      caffe_copy(top[0]->count(), top_diff, bottom_diff);\n    }\n  }\n}\n\n\n#ifdef CPU_ONLY\nSTUB_GPU(DropoutLayer);\n#endif\n\nINSTANTIATE_CLASS(DropoutLayer);\nREGISTER_LAYER_CLASS(Dropout);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/dropout_layer.cu",
    "content": "#include <algorithm>\n#include <limits>\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\n\ntemplate <typename Dtype>\n__global__ void DropoutForward(const int n, const Dtype* in,\n    const unsigned int* mask, const unsigned int threshold, const float scale,\n    Dtype* out) {\n  CUDA_KERNEL_LOOP(index, n) {\n    out[index] = in[index] * (mask[index] > threshold) * scale;\n  }\n}\n\ntemplate <typename Dtype>\nvoid DropoutLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  const int count = bottom[0]->count();\n  if (this->phase_ == TRAIN) {\n    unsigned int* mask =\n        static_cast<unsigned int*>(rand_vec_.mutable_gpu_data());\n    caffe_gpu_rng_uniform(count, mask);\n    // set thresholds\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    DropoutForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, bottom_data, mask, uint_thres_, scale_, top_data);\n    CUDA_POST_KERNEL_CHECK;\n  } else {\n    caffe_copy(count, bottom_data, top_data);\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void DropoutBackward(const int n, const Dtype* in_diff,\n    const unsigned int* mask, const unsigned int threshold, const float scale,\n    Dtype* out_diff) {\n  CUDA_KERNEL_LOOP(index, n) {\n    out_diff[index] = in_diff[index] * scale * (mask[index] > threshold);\n  }\n}\n\ntemplate <typename Dtype>\nvoid DropoutLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* top_diff = top[0]->gpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    if (this->phase_ == TRAIN) {\n      const unsigned int* mask =\n          static_cast<const unsigned int*>(rand_vec_.gpu_data());\n      const int count = bottom[0]->count();\n      // NOLINT_NEXT_LINE(whitespace/operators)\n      DropoutBackward<Dtype><<<CAFFE_GET_BLOCKS(count),\n        CAFFE_CUDA_NUM_THREADS>>>(\n          count, top_diff, mask, uint_thres_, scale_, bottom_diff);\n      CUDA_POST_KERNEL_CHECK;\n    } else {\n      caffe_copy(top[0]->count(), top_diff, bottom_diff);\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(DropoutLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/dummy_data_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid DummyDataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int num_top = top.size();\n  const DummyDataParameter& param = this->layer_param_.dummy_data_param();\n  const int num_data_filler = param.data_filler_size();\n  CHECK(num_data_filler == 0 || num_data_filler == 1 ||\n        num_data_filler == num_top)\n      << \"Number of data fillers must be 0, 1 or equal to the number of tops: \"\n      << num_top << \"; you specified \" << num_data_filler << \" data fillers.\";\n\n  const bool legacy_dims = param.num_size() || param.channels_size() ||\n                           param.height_size() || param.width_size();\n  if (legacy_dims) {\n    CHECK_EQ(0, param.shape_size())\n        << \"Both shape and legacy fields were specified\";\n    // Using deprecated 4D output dim specifiers.\n    CHECK(param.num_size() == 1 || param.num_size() == num_top)\n        << \"Must specify 'num' once, or once per top blob \"\n        << \"(\" << num_top << \"); specified \" << param.num_size() << \".\";\n    CHECK(param.channels_size() == 1 || param.channels_size() == num_top)\n        << \"Must specify 'channels' once, or once per top blob \"\n        << \"(\" << num_top << \"); specified \" << param.channels_size() << \".\";\n    CHECK(param.height_size() == 1 || param.height_size() == num_top)\n        << \"Must specify 'height' once, or once per top blob \"\n        << \"(\" << num_top << \"); specified \" << param.height_size() << \".\";\n    CHECK(param.width_size() == 1 || param.width_size() == num_top)\n        << \"Must specify 'width' once, or once per top blob \"\n        << \"(\" << num_top << \"); specified \" << param.width_size() << \".\";\n  } else {\n    CHECK(param.shape_size() == 1 || param.shape_size() == num_top)\n        << \"Must specify 'shape' once, or once per top blob \"\n        << \"(\" << num_top << \"); specified \" << param.shape_size() << \".\";\n  }\n  // refill_[i] tells Forward i whether or not to actually refill top Blob i.\n  // If refill_[i] is false, Forward does nothing for Blob i. We use this to\n  // avoid wastefully refilling \"constant\" Blobs in every forward pass.\n  // We first fill refill_ in with the INVERSE of its final values.\n  // The first time we run Forward from the LayerSetUp method, we'll fill only\n  // Blobs for which refill_ is normally false.  These Blobs will never be\n  // filled again.\n  refill_.clear();\n  fillers_.clear();\n  if (num_data_filler <= 1) {\n    FillerParameter filler_param;\n    if (num_data_filler == 0) {\n      filler_param.set_type(\"constant\");\n      filler_param.set_value(0);\n    } else {\n      filler_param.CopyFrom(param.data_filler(0));\n    }\n    // Refill on each iteration iff not using a constant filler,\n    // but use the inverse of this rule for the first run.\n    refill_.resize(1);\n    refill_[0] = (strcmp(filler_param.type().c_str(), \"constant\") == 0);\n    fillers_.resize(1);\n    fillers_[0].reset(GetFiller<Dtype>(filler_param));\n  } else {\n    refill_.resize(num_top);\n    fillers_.resize(num_top);\n    for (int i = 0; i < num_top; ++i) {\n      fillers_[i].reset(GetFiller<Dtype>(param.data_filler(i)));\n      // Refill on each iteration iff not using a constant filler,\n      // but use the inverse of this rule for the first run.\n      refill_[i] =\n          (strcmp(param.data_filler(i).type().c_str(), \"constant\") == 0);\n    }\n  }\n  for (int i = 0; i < num_top; ++i) {\n    if (legacy_dims) {\n      const int num = (param.num_size() == 1) ? param.num(0) : param.num(i);\n      const int channels =\n          (param.channels_size() == 1) ? param.channels(0) : param.channels(i);\n      const int height =\n          (param.height_size() == 1) ? param.height(0) : param.height(i);\n      const int width =\n          (param.width_size() == 1) ? param.width(0) : param.width(i);\n      top[i]->Reshape(num, channels, height, width);\n    } else {\n      const int shape_index = (param.shape_size() == 1) ? 0 : i;\n      top[i]->Reshape(param.shape(shape_index));\n    }\n  }\n  // Run Forward once, with refill_ inverted, to fill the constant Blobs.\n  this->Forward(bottom, top);\n  // Invert the inverted refill_ values to refill the desired (non-constant)\n  // Blobs in every usual forward pass.\n  for (int i = 0; i < refill_.size(); ++i) {\n    refill_[i] = !refill_[i];\n  }\n}\n\ntemplate <typename Dtype>\nvoid DummyDataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  for (int i = 0; i < top.size(); ++i) {\n    const int filler_id = (fillers_.size() > 1) ? i : 0;\n    if (refill_[filler_id]) {\n      fillers_[filler_id]->Fill(top[i]);\n    }\n  }\n}\n\nINSTANTIATE_CLASS(DummyDataLayer);\nREGISTER_LAYER_CLASS(DummyData);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/eltwise_layer.cpp",
    "content": "#include <cfloat>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid EltwiseLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK(this->layer_param().eltwise_param().coeff_size() == 0\n      || this->layer_param().eltwise_param().coeff_size() == bottom.size()) <<\n      \"Eltwise Layer takes one coefficient per bottom blob.\";\n  CHECK(!(this->layer_param().eltwise_param().operation()\n      == EltwiseParameter_EltwiseOp_PROD\n      && this->layer_param().eltwise_param().coeff_size())) <<\n      \"Eltwise layer only takes coefficients for summation.\";\n  op_ = this->layer_param_.eltwise_param().operation();\n  // Blob-wise coefficients for the elementwise operation.\n  coeffs_ = vector<Dtype>(bottom.size(), 1);\n  if (this->layer_param().eltwise_param().coeff_size()) {\n    for (int i = 0; i < bottom.size(); ++i) {\n      coeffs_[i] = this->layer_param().eltwise_param().coeff(i);\n    }\n  }\n  stable_prod_grad_ = this->layer_param_.eltwise_param().stable_prod_grad();\n}\n\ntemplate <typename Dtype>\nvoid EltwiseLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  for (int i = 1; i < bottom.size(); ++i) {\n    CHECK(bottom[i]->shape() == bottom[0]->shape());\n  }\n  top[0]->ReshapeLike(*bottom[0]);\n  // If max operation, we will initialize the vector index part.\n  if (this->layer_param_.eltwise_param().operation() ==\n      EltwiseParameter_EltwiseOp_MAX && top.size() == 1) {\n    max_idx_.Reshape(bottom[0]->shape());\n  }\n}\n\ntemplate <typename Dtype>\nvoid EltwiseLayer<Dtype>::Forward_cpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  int* mask = NULL;\n  const Dtype* bottom_data_a = NULL;\n  const Dtype* bottom_data_b = NULL;\n  const int count = top[0]->count();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  switch (op_) {\n  case EltwiseParameter_EltwiseOp_PROD:\n    caffe_mul(count, bottom[0]->cpu_data(), bottom[1]->cpu_data(), top_data);\n    for (int i = 2; i < bottom.size(); ++i) {\n      caffe_mul(count, top_data, bottom[i]->cpu_data(), top_data);\n    }\n    break;\n  case EltwiseParameter_EltwiseOp_SUM:\n    caffe_set(count, Dtype(0), top_data);\n    // TODO(shelhamer) does BLAS optimize to sum for coeff = 1?\n    for (int i = 0; i < bottom.size(); ++i) {\n      caffe_axpy(count, coeffs_[i], bottom[i]->cpu_data(), top_data);\n    }\n    break;\n  case EltwiseParameter_EltwiseOp_MAX:\n    // Initialize\n    mask = max_idx_.mutable_cpu_data();\n    caffe_set(count, -1, mask);\n    caffe_set(count, Dtype(-FLT_MAX), top_data);\n    // bottom 0 & 1\n    bottom_data_a = bottom[0]->cpu_data();\n    bottom_data_b = bottom[1]->cpu_data();\n    for (int idx = 0; idx < count; ++idx) {\n      if (bottom_data_a[idx] > bottom_data_b[idx]) {\n        top_data[idx] = bottom_data_a[idx];  // maxval\n        mask[idx] = 0;  // maxid\n      } else {\n        top_data[idx] = bottom_data_b[idx];  // maxval\n        mask[idx] = 1;  // maxid\n      }\n    }\n    // bottom 2++\n    for (int blob_idx = 2; blob_idx < bottom.size(); ++blob_idx) {\n      bottom_data_b = bottom[blob_idx]->cpu_data();\n      for (int idx = 0; idx < count; ++idx) {\n        if (bottom_data_b[idx] > top_data[idx]) {\n          top_data[idx] = bottom_data_b[idx];  // maxval\n          mask[idx] = blob_idx;  // maxid\n        }\n      }\n    }\n    break;\n  default:\n    LOG(FATAL) << \"Unknown elementwise operation.\";\n  }\n}\n\ntemplate <typename Dtype>\nvoid EltwiseLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const int* mask = NULL;\n  const int count = top[0]->count();\n  const Dtype* top_data = top[0]->cpu_data();\n  const Dtype* top_diff = top[0]->cpu_diff();\n  for (int i = 0; i < bottom.size(); ++i) {\n    if (propagate_down[i]) {\n      const Dtype* bottom_data = bottom[i]->cpu_data();\n      Dtype* bottom_diff = bottom[i]->mutable_cpu_diff();\n      switch (op_) {\n      case EltwiseParameter_EltwiseOp_PROD:\n        if (stable_prod_grad_) {\n          bool initialized = false;\n          for (int j = 0; j < bottom.size(); ++j) {\n            if (i == j) { continue; }\n            if (!initialized) {\n              caffe_copy(count, bottom[j]->cpu_data(), bottom_diff);\n              initialized = true;\n            } else {\n              caffe_mul(count, bottom[j]->cpu_data(), bottom_diff,\n                        bottom_diff);\n            }\n          }\n        } else {\n          caffe_div(count, top_data, bottom_data, bottom_diff);\n        }\n        caffe_mul(count, bottom_diff, top_diff, bottom_diff);\n        break;\n      case EltwiseParameter_EltwiseOp_SUM:\n        if (coeffs_[i] == Dtype(1)) {\n          caffe_copy(count, top_diff, bottom_diff);\n        } else {\n          caffe_cpu_scale(count, coeffs_[i], top_diff, bottom_diff);\n        }\n        break;\n      case EltwiseParameter_EltwiseOp_MAX:\n        mask = max_idx_.cpu_data();\n        for (int index = 0; index < count; ++index) {\n          Dtype gradient = 0;\n          if (mask[index] == i) {\n            gradient += top_diff[index];\n          }\n          bottom_diff[index] = gradient;\n        }\n        break;\n      default:\n        LOG(FATAL) << \"Unknown elementwise operation.\";\n      }\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(EltwiseLayer);\n#endif\n\nINSTANTIATE_CLASS(EltwiseLayer);\nREGISTER_LAYER_CLASS(Eltwise);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/eltwise_layer.cu",
    "content": "#include <cfloat>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void MaxForward(const int nthreads, const Dtype* bottom_data_a,\n    const Dtype* bottom_data_b, const int blob_idx, Dtype* top_data,\n    int* mask) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    Dtype maxval = -FLT_MAX;\n    int maxidx = -1;\n    if (bottom_data_a[index] > bottom_data_b[index]) {\n      // only update for very first bottom_data blob (blob_idx == 0)\n      if (blob_idx == 0) {\n        maxval = bottom_data_a[index];\n        top_data[index] = maxval;\n        maxidx = blob_idx;\n        mask[index] = maxidx;\n      }\n    } else {\n      maxval = bottom_data_b[index];\n      top_data[index] = maxval;\n      maxidx = blob_idx + 1;\n      mask[index] = maxidx;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid EltwiseLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  int* mask = NULL;\n  const int count = top[0]->count();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  switch (op_) {\n  case EltwiseParameter_EltwiseOp_PROD:\n    caffe_gpu_mul(count, bottom[0]->gpu_data(), bottom[1]->gpu_data(),\n        top_data);\n    for (int i = 2; i < bottom.size(); ++i) {\n      caffe_gpu_mul(count, top_data, bottom[i]->gpu_data(), top_data);\n    }\n    break;\n  case EltwiseParameter_EltwiseOp_SUM:\n    caffe_gpu_set(count, Dtype(0.), top_data);\n    // TODO(shelhamer) does cuBLAS optimize to sum for coeff = 1?\n    for (int i = 0; i < bottom.size(); ++i) {\n      caffe_gpu_axpy(count, coeffs_[i], bottom[i]->gpu_data(), top_data);\n    }\n    break;\n  case EltwiseParameter_EltwiseOp_MAX:\n    mask = max_idx_.mutable_gpu_data();\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    MaxForward<Dtype> <<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, bottom[0]->gpu_data(), bottom[1]->gpu_data(), 0, top_data, mask);\n    for (int i = 2; i < bottom.size(); ++i) {\n      // NOLINT_NEXT_LINE(whitespace/operators)\n      MaxForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n          count, top_data, bottom[i]->gpu_data(), i-1, top_data, mask);\n    }\n    break;\n  default:\n    LOG(FATAL) << \"Unknown elementwise operation.\";\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void MaxBackward(const int nthreads, const Dtype* top_diff,\n    const int blob_idx, const int* mask, Dtype* bottom_diff) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    Dtype gradient = 0;\n    if (mask[index] == blob_idx) {\n      gradient += top_diff[index];\n    }\n    bottom_diff[index] = gradient;\n  }\n}\n\ntemplate <typename Dtype>\nvoid EltwiseLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const int* mask = NULL;\n  const int count = top[0]->count();\n  const Dtype* top_data = top[0]->gpu_data();\n  const Dtype* top_diff = top[0]->gpu_diff();\n  for (int i = 0; i < bottom.size(); ++i) {\n    if (propagate_down[i]) {\n      const Dtype* bottom_data = bottom[i]->gpu_data();\n      Dtype* bottom_diff = bottom[i]->mutable_gpu_diff();\n      switch (op_) {\n      case EltwiseParameter_EltwiseOp_PROD:\n        if (stable_prod_grad_) {\n          bool initialized = false;\n          for (int j = 0; j < bottom.size(); ++j) {\n            if (i == j) { continue; }\n            if (!initialized) {\n              caffe_copy(count, bottom[j]->gpu_data(), bottom_diff);\n              initialized = true;\n            } else {\n              caffe_gpu_mul(count, bottom[j]->gpu_data(), bottom_diff,\n                            bottom_diff);\n            }\n          }\n        } else {\n          caffe_gpu_div(count, top_data, bottom_data, bottom_diff);\n        }\n        caffe_gpu_mul(count, bottom_diff, top_diff, bottom_diff);\n        break;\n      case EltwiseParameter_EltwiseOp_SUM:\n        if (coeffs_[i] == Dtype(1.)) {\n          caffe_copy(count, top_diff, bottom_diff);\n        } else {\n          caffe_gpu_scale(count, coeffs_[i], top_diff, bottom_diff);\n        }\n        break;\n      case EltwiseParameter_EltwiseOp_MAX:\n        mask = max_idx_.gpu_data();\n        MaxBackward<Dtype>  // NOLINT_NEXT_LINE(whitespace/operators)\n            <<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n            count, top_diff, i, mask, bottom_diff);\n        break;\n      default:\n        LOG(FATAL) << \"Unknown elementwise operation.\";\n      }\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(EltwiseLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/euclidean_loss_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid EuclideanLossLayer<Dtype>::Reshape(\n  const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  LossLayer<Dtype>::Reshape(bottom, top);\n  CHECK_EQ(bottom[0]->count(1), bottom[1]->count(1))\n      << \"Inputs must have the same dimension.\";\n  diff_.ReshapeLike(*bottom[0]);\n}\n\ntemplate <typename Dtype>\nvoid EuclideanLossLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  int count = bottom[0]->count();\n  caffe_sub(\n      count,\n      bottom[0]->cpu_data(),\n      bottom[1]->cpu_data(),\n      diff_.mutable_cpu_data());\n  Dtype dot = caffe_cpu_dot(count, diff_.cpu_data(), diff_.cpu_data());\n  Dtype loss = dot / bottom[0]->num() / Dtype(2);\n  top[0]->mutable_cpu_data()[0] = loss;\n}\n\ntemplate <typename Dtype>\nvoid EuclideanLossLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  for (int i = 0; i < 2; ++i) {\n    if (propagate_down[i]) {\n      const Dtype sign = (i == 0) ? 1 : -1;\n      const Dtype alpha = sign * top[0]->cpu_diff()[0] / bottom[i]->num();\n      caffe_cpu_axpby(\n          bottom[i]->count(),              // count\n          alpha,                              // alpha\n          diff_.cpu_data(),                   // a\n          Dtype(0),                           // beta\n          bottom[i]->mutable_cpu_diff());  // b\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(EuclideanLossLayer);\n#endif\n\nINSTANTIATE_CLASS(EuclideanLossLayer);\nREGISTER_LAYER_CLASS(EuclideanLoss);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/euclidean_loss_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid EuclideanLossLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  int count = bottom[0]->count();\n  caffe_gpu_sub(\n      count,\n      bottom[0]->gpu_data(),\n      bottom[1]->gpu_data(),\n      diff_.mutable_gpu_data());\n  Dtype dot;\n  caffe_gpu_dot(count, diff_.gpu_data(), diff_.gpu_data(), &dot);\n  Dtype loss = dot / bottom[0]->num() / Dtype(2);\n  top[0]->mutable_cpu_data()[0] = loss;\n}\n\ntemplate <typename Dtype>\nvoid EuclideanLossLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  for (int i = 0; i < 2; ++i) {\n    if (propagate_down[i]) {\n      const Dtype sign = (i == 0) ? 1 : -1;\n      const Dtype alpha = sign * top[0]->cpu_diff()[0] / bottom[i]->num();\n      caffe_gpu_axpby(\n          bottom[i]->count(),              // count\n          alpha,                              // alpha\n          diff_.gpu_data(),                   // a\n          Dtype(0),                           // beta\n          bottom[i]->mutable_gpu_diff());  // b\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(EuclideanLossLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/exp_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ExpLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  NeuronLayer<Dtype>::LayerSetUp(bottom, top);\n  const Dtype base = this->layer_param_.exp_param().base();\n  if (base != Dtype(-1)) {\n    CHECK_GT(base, 0) << \"base must be strictly positive.\";\n  }\n  // If base == -1, interpret the base as e and set log_base = 1 exactly.\n  // Otherwise, calculate its log explicitly.\n  const Dtype log_base = (base == Dtype(-1)) ? Dtype(1) : log(base);\n  CHECK(!isnan(log_base))\n      << \"NaN result: log(base) = log(\" << base << \") = \" << log_base;\n  CHECK(!isinf(log_base))\n      << \"Inf result: log(base) = log(\" << base << \") = \" << log_base;\n  const Dtype input_scale = this->layer_param_.exp_param().scale();\n  const Dtype input_shift = this->layer_param_.exp_param().shift();\n  inner_scale_ = log_base * input_scale;\n  outer_scale_ = (input_shift == Dtype(0)) ? Dtype(1) : pow(base, input_shift);\n}\n\ntemplate <typename Dtype>\nvoid ExpLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const int count = bottom[0]->count();\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  if (inner_scale_ == Dtype(1)) {\n    caffe_exp(count, bottom_data, top_data);\n  } else {\n    caffe_cpu_scale(count, inner_scale_, bottom_data, top_data);\n    caffe_exp(count, top_data, top_data);\n  }\n  if (outer_scale_ != Dtype(1)) {\n    caffe_scal(count, outer_scale_, top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid ExpLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) { return; }\n  const int count = bottom[0]->count();\n  const Dtype* top_data = top[0]->cpu_data();\n  const Dtype* top_diff = top[0]->cpu_diff();\n  Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n  caffe_mul(count, top_data, top_diff, bottom_diff);\n  if (inner_scale_ != Dtype(1)) {\n    caffe_scal(count, inner_scale_, bottom_diff);\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(ExpLayer);\n#endif\n\nINSTANTIATE_CLASS(ExpLayer);\nREGISTER_LAYER_CLASS(Exp);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/exp_layer.cu",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ExpLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const int count = bottom[0]->count();\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  if (inner_scale_ == Dtype(1)) {\n    caffe_gpu_exp(count, bottom_data, top_data);\n  } else {\n    caffe_gpu_scale(count, inner_scale_, bottom_data, top_data);\n    caffe_gpu_exp(count, top_data, top_data);\n  }\n  if (outer_scale_ != Dtype(1)) {\n    caffe_gpu_scal(count, outer_scale_, top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid ExpLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) { return; }\n  const int count = bottom[0]->count();\n  const Dtype* top_data = top[0]->gpu_data();\n  const Dtype* top_diff = top[0]->gpu_diff();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n  caffe_gpu_mul(count, top_data, top_diff, bottom_diff);\n  if (inner_scale_ != Dtype(1)) {\n    caffe_gpu_scal(count, inner_scale_, bottom_diff);\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(ExpLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/filter_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid FilterLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK_EQ(top.size(), bottom.size() - 1);\n  first_reshape_ = true;\n}\n\ntemplate <typename Dtype>\nvoid FilterLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  // bottom[0...k-1] are the blobs to filter\n  // bottom[last] is the \"selector_blob\"\n  int selector_index = bottom.size() - 1;\n  for (int i = 1; i < bottom[selector_index]->num_axes(); ++i) {\n    CHECK_EQ(bottom[selector_index]->shape(i), 1)\n        << \"Selector blob dimensions must be singletons (1), except the first\";\n  }\n  for (int i = 0; i < bottom.size() - 1; ++i) {\n    CHECK_EQ(bottom[selector_index]->shape(0), bottom[i]->shape(0)) <<\n        \"Each bottom should have the same 0th dimension as the selector blob\";\n  }\n\n  const Dtype* bottom_data_selector = bottom[selector_index]->cpu_data();\n  indices_to_forward_.clear();\n\n  // look for non-zero elements in bottom[0]. Items of each bottom that\n  // have the same index as the items in bottom[0] with value == non-zero\n  // will be forwarded\n  for (int item_id = 0; item_id < bottom[selector_index]->shape(0); ++item_id) {\n    // we don't need an offset because item size == 1\n    const Dtype* tmp_data_selector = bottom_data_selector + item_id;\n    if (*tmp_data_selector) {\n      indices_to_forward_.push_back(item_id);\n    }\n  }\n  // only filtered items will be forwarded\n  int new_tops_num = indices_to_forward_.size();\n  // init\n  if (first_reshape_) {\n    new_tops_num = bottom[0]->shape(0);\n    first_reshape_ = false;\n  }\n  for (int t = 0; t < top.size(); ++t) {\n    int num_axes = bottom[t]->num_axes();\n    vector<int> shape_top(num_axes);\n    shape_top[0] = new_tops_num;\n    for (int ts = 1; ts < num_axes; ++ts)\n      shape_top[ts] = bottom[t]->shape(ts);\n    top[t]->Reshape(shape_top);\n  }\n}\n\ntemplate <typename Dtype>\nvoid FilterLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  int new_tops_num = indices_to_forward_.size();\n  // forward all filtered items for all bottoms but the Selector (bottom[last])\n  for (int t = 0; t < top.size(); ++t) {\n    const Dtype* bottom_data = bottom[t]->cpu_data();\n    Dtype* top_data = top[t]->mutable_cpu_data();\n    int dim = bottom[t]->count() / bottom[t]->shape(0);\n    for (int n = 0; n < new_tops_num; ++n) {\n      int data_offset_top = n * dim;\n      int data_offset_bottom = indices_to_forward_[n] * bottom[t]->count(1);\n      caffe_copy(dim, bottom_data + data_offset_bottom,\n          top_data + data_offset_top);\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid FilterLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[bottom.size() - 1]) {\n    LOG(FATAL) << this->type()\n               << \"Layer cannot backpropagate to filter index inputs\";\n  }\n  for (int i = 0; i < top.size(); i++) {\n    // bottom[last] is the selector and never needs backpropagation\n    // so we can iterate over top vector because top.size() == bottom.size() -1\n    if (propagate_down[i]) {\n      const int dim = top[i]->count() / top[i]->shape(0);\n      int next_to_backward_offset = 0;\n      int batch_offset = 0;\n      int data_offset_bottom = 0;\n      int data_offset_top = 0;\n      for (int n = 0; n < bottom[i]->shape(0); n++) {\n        data_offset_bottom = n * dim;\n        if (next_to_backward_offset >= indices_to_forward_.size()) {\n          // we already visited all items that were been forwarded, so\n          // just set to zero remaining ones\n          caffe_set(dim, Dtype(0),\n              bottom[i]->mutable_cpu_diff() + data_offset_bottom);\n        } else {\n          batch_offset = indices_to_forward_[next_to_backward_offset];\n          if (n != batch_offset) {  // this data was not been forwarded\n            caffe_set(dim, Dtype(0),\n                bottom[i]->mutable_cpu_diff() + data_offset_bottom);\n          } else {  // this data was been forwarded\n            data_offset_top = next_to_backward_offset * dim;\n            next_to_backward_offset++;  // point to next forwarded item index\n            caffe_copy(dim, top[i]->mutable_cpu_diff() + data_offset_top,\n                bottom[i]->mutable_cpu_diff() + data_offset_bottom);\n          }\n        }\n      }\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(FilterLayer);\n#endif\n\nINSTANTIATE_CLASS(FilterLayer);\nREGISTER_LAYER_CLASS(Filter);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/filter_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid FilterLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  int new_tops_num = indices_to_forward_.size();\n  // forward all filtered items for all bottoms but the Selector (bottom[last])\n  for (int t = 0; t < top.size(); ++t) {\n    const Dtype* bottom_data = bottom[t]->gpu_data();\n    Dtype* top_data = top[t]->mutable_gpu_data();\n    int dim = bottom[t]->count() / bottom[t]->shape(0);\n    for (int n = 0; n < new_tops_num; ++n) {\n      int data_offset_top = n * dim;\n      int data_offset_bottom = indices_to_forward_[n] * dim;\n      caffe_copy(dim, bottom_data + data_offset_bottom,\n          top_data + data_offset_top);\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid FilterLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[bottom.size() - 1]) {\n    LOG(FATAL) << this->type()\n               << \"Layer cannot backpropagate to filter index inputs\";\n  }\n  for (int i = 0; i < top.size(); ++i) {\n    // bottom[last] is the selector and never needs backpropagation\n    // so we can iterate over top vector because top.size() == bottom.size() -1\n    if (propagate_down[i]) {\n      const int dim = top[i]->count() / top[i]->shape(0);\n      int next_to_backward_offset = 0;\n      int batch_offset = 0;\n      int data_offset_bottom = 0;\n      int data_offset_top = 0;\n      for (int n = 0; n < bottom[i]->shape(0); ++n) {\n        if (next_to_backward_offset >= indices_to_forward_.size()) {\n          // we already visited all items that were been forwarded, so\n          // just set to zero remaining ones\n          data_offset_bottom = n * dim;\n          caffe_gpu_set(dim, Dtype(0),\n              bottom[i]->mutable_gpu_diff() + data_offset_bottom);\n        } else {\n          batch_offset = indices_to_forward_[next_to_backward_offset];\n          data_offset_bottom = n * dim;\n          if (n != batch_offset) {  // this data was not been forwarded\n            caffe_gpu_set(dim, Dtype(0),\n                bottom[i]->mutable_gpu_diff() + data_offset_bottom);\n          } else {  // this data was been forwarded\n            data_offset_top = next_to_backward_offset * dim;\n            ++next_to_backward_offset;  // point to next forwarded item index\n            caffe_copy(dim, top[i]->mutable_gpu_diff() + data_offset_top,\n                bottom[i]->mutable_gpu_diff() + data_offset_bottom);\n          }\n        }\n      }\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(FilterLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/flatten_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid FlattenLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int start_axis = bottom[0]->CanonicalAxisIndex(\n      this->layer_param_.flatten_param().axis());\n  const int end_axis = bottom[0]->CanonicalAxisIndex(\n      this->layer_param_.flatten_param().end_axis());\n  vector<int> top_shape;\n  for (int i = 0; i < start_axis; ++i) {\n    top_shape.push_back(bottom[0]->shape(i));\n  }\n  const int flattened_dim = bottom[0]->count(start_axis, end_axis + 1);\n  top_shape.push_back(flattened_dim);\n  for (int i = end_axis + 1; i < bottom[0]->num_axes(); ++i) {\n    top_shape.push_back(bottom[0]->shape(i));\n  }\n  top[0]->Reshape(top_shape);\n  CHECK_EQ(top[0]->count(), bottom[0]->count());\n}\n\ntemplate <typename Dtype>\nvoid FlattenLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  top[0]->ShareData(*bottom[0]);\n}\n\ntemplate <typename Dtype>\nvoid FlattenLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  bottom[0]->ShareDiff(*top[0]);\n}\n\nINSTANTIATE_CLASS(FlattenLayer);\nREGISTER_LAYER_CLASS(Flatten);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/hdf5_data_layer.cpp",
    "content": "/*\nTODO:\n- load file in a separate thread (\"prefetch\")\n- can be smarter about the memcpy call instead of doing it row-by-row\n  :: use util functions caffe_copy, and Blob->offset()\n  :: don't forget to update hdf5_daa_layer.cu accordingly\n- add ability to shuffle filenames if flag is set\n*/\n#include <fstream>  // NOLINT(readability/streams)\n#include <string>\n#include <vector>\n\n#include \"hdf5.h\"\n#include \"hdf5_hl.h\"\n#include \"stdint.h\"\n\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/hdf5.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nHDF5DataLayer<Dtype>::~HDF5DataLayer<Dtype>() { }\n\n// Load data and label from HDF5 filename into the class property blobs.\ntemplate <typename Dtype>\nvoid HDF5DataLayer<Dtype>::LoadHDF5FileData(const char* filename) {\n  DLOG(INFO) << \"Loading HDF5 file: \" << filename;\n  hid_t file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);\n  if (file_id < 0) {\n    LOG(FATAL) << \"Failed opening HDF5 file: \" << filename;\n  }\n\n  int top_size = this->layer_param_.top_size();\n  hdf_blobs_.resize(top_size);\n\n  const int MIN_DATA_DIM = 1;\n  const int MAX_DATA_DIM = INT_MAX;\n\n  for (int i = 0; i < top_size; ++i) {\n    hdf_blobs_[i] = shared_ptr<Blob<Dtype> >(new Blob<Dtype>());\n    hdf5_load_nd_dataset(file_id, this->layer_param_.top(i).c_str(),\n        MIN_DATA_DIM, MAX_DATA_DIM, hdf_blobs_[i].get());\n  }\n\n  herr_t status = H5Fclose(file_id);\n  CHECK_GE(status, 0) << \"Failed to close HDF5 file: \" << filename;\n\n  // MinTopBlobs==1 guarantees at least one top blob\n  CHECK_GE(hdf_blobs_[0]->num_axes(), 1) << \"Input must have at least 1 axis.\";\n  const int num = hdf_blobs_[0]->shape(0);\n  for (int i = 1; i < top_size; ++i) {\n    CHECK_EQ(hdf_blobs_[i]->shape(0), num);\n  }\n  // Default to identity permutation.\n  data_permutation_.clear();\n  data_permutation_.resize(hdf_blobs_[0]->shape(0));\n  for (int i = 0; i < hdf_blobs_[0]->shape(0); i++)\n    data_permutation_[i] = i;\n\n  // Shuffle if needed.\n  if (this->layer_param_.hdf5_data_param().shuffle()) {\n    std::random_shuffle(data_permutation_.begin(), data_permutation_.end());\n    DLOG(INFO) << \"Successully loaded \" << hdf_blobs_[0]->shape(0)\n               << \" rows (shuffled)\";\n  } else {\n    DLOG(INFO) << \"Successully loaded \" << hdf_blobs_[0]->shape(0) << \" rows\";\n  }\n}\n\ntemplate <typename Dtype>\nvoid HDF5DataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  // Refuse transformation parameters since HDF5 is totally generic.\n  CHECK(!this->layer_param_.has_transform_param()) <<\n      this->type() << \" does not transform data.\";\n  // Read the source to parse the filenames.\n  const string& source = this->layer_param_.hdf5_data_param().source();\n  LOG(INFO) << \"Loading list of HDF5 filenames from: \" << source;\n  hdf_filenames_.clear();\n  std::ifstream source_file(source.c_str());\n  if (source_file.is_open()) {\n    std::string line;\n    while (source_file >> line) {\n      hdf_filenames_.push_back(line);\n    }\n  } else {\n    LOG(FATAL) << \"Failed to open source file: \" << source;\n  }\n  source_file.close();\n  num_files_ = hdf_filenames_.size();\n  current_file_ = 0;\n  LOG(INFO) << \"Number of HDF5 files: \" << num_files_;\n  CHECK_GE(num_files_, 1) << \"Must have at least 1 HDF5 filename listed in \"\n    << source;\n\n  file_permutation_.clear();\n  file_permutation_.resize(num_files_);\n  // Default to identity permutation.\n  for (int i = 0; i < num_files_; i++) {\n    file_permutation_[i] = i;\n  }\n\n  // Shuffle if needed.\n  if (this->layer_param_.hdf5_data_param().shuffle()) {\n    std::random_shuffle(file_permutation_.begin(), file_permutation_.end());\n  }\n\n  // Load the first HDF5 file and initialize the line counter.\n  LoadHDF5FileData(hdf_filenames_[file_permutation_[current_file_]].c_str());\n  current_row_ = 0;\n\n  // Reshape blobs.\n  const int batch_size = this->layer_param_.hdf5_data_param().batch_size();\n  const int top_size = this->layer_param_.top_size();\n  vector<int> top_shape;\n  for (int i = 0; i < top_size; ++i) {\n    top_shape.resize(hdf_blobs_[i]->num_axes());\n    top_shape[0] = batch_size;\n    for (int j = 1; j < top_shape.size(); ++j) {\n      top_shape[j] = hdf_blobs_[i]->shape(j);\n    }\n    top[i]->Reshape(top_shape);\n  }\n}\n\ntemplate <typename Dtype>\nvoid HDF5DataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int batch_size = this->layer_param_.hdf5_data_param().batch_size();\n  for (int i = 0; i < batch_size; ++i, ++current_row_) {\n    if (current_row_ == hdf_blobs_[0]->shape(0)) {\n      if (num_files_ > 1) {\n        ++current_file_;\n        if (current_file_ == num_files_) {\n          current_file_ = 0;\n          if (this->layer_param_.hdf5_data_param().shuffle()) {\n            std::random_shuffle(file_permutation_.begin(),\n                                file_permutation_.end());\n          }\n          DLOG(INFO) << \"Looping around to first file.\";\n        }\n        LoadHDF5FileData(\n            hdf_filenames_[file_permutation_[current_file_]].c_str());\n      }\n      current_row_ = 0;\n      if (this->layer_param_.hdf5_data_param().shuffle())\n        std::random_shuffle(data_permutation_.begin(), data_permutation_.end());\n    }\n    for (int j = 0; j < this->layer_param_.top_size(); ++j) {\n      int data_dim = top[j]->count() / top[j]->shape(0);\n      caffe_copy(data_dim,\n          &hdf_blobs_[j]->cpu_data()[data_permutation_[current_row_]\n            * data_dim], &top[j]->mutable_cpu_data()[i * data_dim]);\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU_FORWARD(HDF5DataLayer, Forward);\n#endif\n\nINSTANTIATE_CLASS(HDF5DataLayer);\nREGISTER_LAYER_CLASS(HDF5Data);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/hdf5_data_layer.cu",
    "content": "/*\nTODO:\n- only load parts of the file, in accordance with a prototxt param \"max_mem\"\n*/\n\n#include <stdint.h>\n#include <string>\n#include <vector>\n\n#include \"hdf5.h\"\n#include \"hdf5_hl.h\"\n\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid HDF5DataLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int batch_size = this->layer_param_.hdf5_data_param().batch_size();\n  for (int i = 0; i < batch_size; ++i, ++current_row_) {\n    if (current_row_ == hdf_blobs_[0]->shape(0)) {\n      if (num_files_ > 1) {\n        current_file_ += 1;\n        if (current_file_ == num_files_) {\n          current_file_ = 0;\n          if (this->layer_param_.hdf5_data_param().shuffle()) {\n            std::random_shuffle(file_permutation_.begin(),\n                                file_permutation_.end());\n          }\n          DLOG(INFO) << \"Looping around to first file.\";\n        }\n        LoadHDF5FileData(\n            hdf_filenames_[file_permutation_[current_file_]].c_str());\n      }\n      current_row_ = 0;\n      if (this->layer_param_.hdf5_data_param().shuffle())\n        std::random_shuffle(data_permutation_.begin(), data_permutation_.end());\n    }\n    for (int j = 0; j < this->layer_param_.top_size(); ++j) {\n      int data_dim = top[j]->count() / top[j]->shape(0);\n      caffe_copy(data_dim,\n          &hdf_blobs_[j]->cpu_data()[data_permutation_[current_row_]\n            * data_dim], &top[j]->mutable_gpu_data()[i * data_dim]);\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(HDF5DataLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/hdf5_output_layer.cpp",
    "content": "#include <vector>\n\n#include \"hdf5.h\"\n#include \"hdf5_hl.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/hdf5.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid HDF5OutputLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  file_name_ = this->layer_param_.hdf5_output_param().file_name();\n  file_id_ = H5Fcreate(file_name_.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,\n                       H5P_DEFAULT);\n  CHECK_GE(file_id_, 0) << \"Failed to open HDF5 file\" << file_name_;\n  file_opened_ = true;\n}\n\ntemplate <typename Dtype>\nHDF5OutputLayer<Dtype>::~HDF5OutputLayer<Dtype>() {\n  if (file_opened_) {\n    herr_t status = H5Fclose(file_id_);\n    CHECK_GE(status, 0) << \"Failed to close HDF5 file \" << file_name_;\n  }\n}\n\ntemplate <typename Dtype>\nvoid HDF5OutputLayer<Dtype>::SaveBlobs() {\n  // TODO: no limit on the number of blobs\n  LOG(INFO) << \"Saving HDF5 file \" << file_name_;\n  CHECK_EQ(data_blob_.num(), label_blob_.num()) <<\n      \"data blob and label blob must have the same batch size\";\n  hdf5_save_nd_dataset(file_id_, HDF5_DATA_DATASET_NAME, data_blob_);\n  hdf5_save_nd_dataset(file_id_, HDF5_DATA_LABEL_NAME, label_blob_);\n  LOG(INFO) << \"Successfully saved \" << data_blob_.num() << \" rows\";\n}\n\ntemplate <typename Dtype>\nvoid HDF5OutputLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK_GE(bottom.size(), 2);\n  CHECK_EQ(bottom[0]->num(), bottom[1]->num());\n  data_blob_.Reshape(bottom[0]->num(), bottom[0]->channels(),\n                     bottom[0]->height(), bottom[0]->width());\n  label_blob_.Reshape(bottom[1]->num(), bottom[1]->channels(),\n                     bottom[1]->height(), bottom[1]->width());\n  const int data_datum_dim = bottom[0]->count() / bottom[0]->num();\n  const int label_datum_dim = bottom[1]->count() / bottom[1]->num();\n\n  for (int i = 0; i < bottom[0]->num(); ++i) {\n    caffe_copy(data_datum_dim, &bottom[0]->cpu_data()[i * data_datum_dim],\n        &data_blob_.mutable_cpu_data()[i * data_datum_dim]);\n    caffe_copy(label_datum_dim, &bottom[1]->cpu_data()[i * label_datum_dim],\n        &label_blob_.mutable_cpu_data()[i * label_datum_dim]);\n  }\n  SaveBlobs();\n}\n\ntemplate <typename Dtype>\nvoid HDF5OutputLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  return;\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(HDF5OutputLayer);\n#endif\n\nINSTANTIATE_CLASS(HDF5OutputLayer);\nREGISTER_LAYER_CLASS(HDF5Output);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/hdf5_output_layer.cu",
    "content": "#include <vector>\n\n#include \"hdf5.h\"\n#include \"hdf5_hl.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid HDF5OutputLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK_GE(bottom.size(), 2);\n  CHECK_EQ(bottom[0]->num(), bottom[1]->num());\n  data_blob_.Reshape(bottom[0]->num(), bottom[0]->channels(),\n                     bottom[0]->height(), bottom[0]->width());\n  label_blob_.Reshape(bottom[1]->num(), bottom[1]->channels(),\n                     bottom[1]->height(), bottom[1]->width());\n  const int data_datum_dim = bottom[0]->count() / bottom[0]->num();\n  const int label_datum_dim = bottom[1]->count() / bottom[1]->num();\n\n  for (int i = 0; i < bottom[0]->num(); ++i) {\n    caffe_copy(data_datum_dim, &bottom[0]->gpu_data()[i * data_datum_dim],\n        &data_blob_.mutable_cpu_data()[i * data_datum_dim]);\n    caffe_copy(label_datum_dim, &bottom[1]->gpu_data()[i * label_datum_dim],\n        &label_blob_.mutable_cpu_data()[i * label_datum_dim]);\n  }\n  SaveBlobs();\n}\n\ntemplate <typename Dtype>\nvoid HDF5OutputLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  return;\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(HDF5OutputLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/hinge_loss_layer.cpp",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <cmath>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid HingeLossLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n  const Dtype* label = bottom[1]->cpu_data();\n  int num = bottom[0]->num();\n  int count = bottom[0]->count();\n  int dim = count / num;\n\n  caffe_copy(count, bottom_data, bottom_diff);\n  for (int i = 0; i < num; ++i) {\n    bottom_diff[i * dim + static_cast<int>(label[i])] *= -1;\n  }\n  for (int i = 0; i < num; ++i) {\n    for (int j = 0; j < dim; ++j) {\n      bottom_diff[i * dim + j] = std::max(\n        Dtype(0), 1 + bottom_diff[i * dim + j]);\n    }\n  }\n  Dtype* loss = top[0]->mutable_cpu_data();\n  switch (this->layer_param_.hinge_loss_param().norm()) {\n  case HingeLossParameter_Norm_L1:\n    loss[0] = caffe_cpu_asum(count, bottom_diff) / num;\n    break;\n  case HingeLossParameter_Norm_L2:\n    loss[0] = caffe_cpu_dot(count, bottom_diff, bottom_diff) / num;\n    break;\n  default:\n    LOG(FATAL) << \"Unknown Norm\";\n  }\n}\n\ntemplate <typename Dtype>\nvoid HingeLossLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[1]) {\n    LOG(FATAL) << this->type()\n               << \" Layer cannot backpropagate to label inputs.\";\n  }\n  if (propagate_down[0]) {\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    const Dtype* label = bottom[1]->cpu_data();\n    int num = bottom[0]->num();\n    int count = bottom[0]->count();\n    int dim = count / num;\n\n    for (int i = 0; i < num; ++i) {\n      bottom_diff[i * dim + static_cast<int>(label[i])] *= -1;\n    }\n\n    const Dtype loss_weight = top[0]->cpu_diff()[0];\n    switch (this->layer_param_.hinge_loss_param().norm()) {\n    case HingeLossParameter_Norm_L1:\n      caffe_cpu_sign(count, bottom_diff, bottom_diff);\n      caffe_scal(count, loss_weight / num, bottom_diff);\n      break;\n    case HingeLossParameter_Norm_L2:\n      caffe_scal(count, loss_weight * 2 / num, bottom_diff);\n      break;\n    default:\n      LOG(FATAL) << \"Unknown Norm\";\n    }\n  }\n}\n\nINSTANTIATE_CLASS(HingeLossLayer);\nREGISTER_LAYER_CLASS(HingeLoss);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/im2col_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid Im2colLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  ConvolutionParameter conv_param = this->layer_param_.convolution_param();\n  CHECK(!conv_param.has_kernel_size() !=\n      !(conv_param.has_kernel_h() && conv_param.has_kernel_w()))\n      << \"Filter size is kernel_size OR kernel_h and kernel_w; not both\";\n  CHECK(conv_param.has_kernel_size() ||\n      (conv_param.has_kernel_h() && conv_param.has_kernel_w()))\n      << \"For non-square filters both kernel_h and kernel_w are required.\";\n  CHECK((!conv_param.has_pad() && conv_param.has_pad_h()\n      && conv_param.has_pad_w())\n      || (!conv_param.has_pad_h() && !conv_param.has_pad_w()))\n      << \"pad is pad OR pad_h and pad_w are required.\";\n  CHECK((!conv_param.has_stride() && conv_param.has_stride_h()\n      && conv_param.has_stride_w())\n      || (!conv_param.has_stride_h() && !conv_param.has_stride_w()))\n      << \"Stride is stride OR stride_h and stride_w are required.\";\n  if (conv_param.has_kernel_size()) {\n    kernel_h_ = kernel_w_ = conv_param.kernel_size();\n  } else {\n    kernel_h_ = conv_param.kernel_h();\n    kernel_w_ = conv_param.kernel_w();\n  }\n  CHECK_GT(kernel_h_, 0) << \"Filter dimensions cannot be zero.\";\n  CHECK_GT(kernel_w_, 0) << \"Filter dimensions cannot be zero.\";\n  if (!conv_param.has_pad_h()) {\n    pad_h_ = pad_w_ = conv_param.pad();\n  } else {\n    pad_h_ = conv_param.pad_h();\n    pad_w_ = conv_param.pad_w();\n  }\n  if (!conv_param.has_stride_h()) {\n    stride_h_ = stride_w_ = conv_param.stride();\n  } else {\n    stride_h_ = conv_param.stride_h();\n    stride_w_ = conv_param.stride_w();\n  }\n}\n\ntemplate <typename Dtype>\nvoid Im2colLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK_EQ(4, bottom[0]->num_axes()) << \"Input must have 4 axes, \"\n      << \"corresponding to (num, channels, height, width)\";\n  channels_ = bottom[0]->channels();\n  height_ = bottom[0]->height();\n  width_ = bottom[0]->width();\n  top[0]->Reshape(\n      bottom[0]->num(), channels_ * kernel_h_ * kernel_w_,\n      (height_ + 2 * pad_h_ - kernel_h_) / stride_h_ + 1,\n      (width_ + 2 * pad_w_ - kernel_w_) / stride_w_ + 1);\n}\n\ntemplate <typename Dtype>\nvoid Im2colLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  for (int n = 0; n < bottom[0]->num(); ++n) {\n    im2col_cpu(bottom_data + bottom[0]->offset(n), channels_, height_,\n        width_, kernel_h_, kernel_w_, pad_h_, pad_w_,\n        stride_h_, stride_w_, top_data + top[0]->offset(n));\n  }\n}\n\ntemplate <typename Dtype>\nvoid Im2colLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->cpu_diff();\n  Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n  for (int n = 0; n < top[0]->num(); ++n) {\n    col2im_cpu(top_diff + top[0]->offset(n), channels_, height_, width_,\n        kernel_h_, kernel_w_, pad_h_, pad_w_,\n        stride_h_, stride_w_, bottom_diff + bottom[0]->offset(n));\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(Im2colLayer);\n#endif\n\nINSTANTIATE_CLASS(Im2colLayer);\nREGISTER_LAYER_CLASS(Im2col);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/im2col_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid Im2colLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  for (int n = 0; n < bottom[0]->num(); ++n) {\n    im2col_gpu(bottom_data + bottom[0]->offset(n), channels_, height_,\n        width_, kernel_h_, kernel_w_, pad_h_, pad_w_,\n        stride_h_, stride_w_, top_data + top[0]->offset(n));\n  }\n}\n\ntemplate <typename Dtype>\nvoid Im2colLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->gpu_diff();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n  for (int n = 0; n < top[0]->num(); ++n) {\n    col2im_gpu(top_diff + top[0]->offset(n), channels_, height_, width_,\n        kernel_h_, kernel_w_, pad_h_, pad_w_,\n        stride_h_, stride_w_, bottom_diff + bottom[0]->offset(n));\n  }\n}\n\n\nINSTANTIATE_LAYER_GPU_FUNCS(Im2colLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/image_data_layer.cpp",
    "content": "#include <opencv2/core/core.hpp>\n\n#include <fstream>  // NOLINT(readability/streams)\n#include <iostream>  // NOLINT(readability/streams)\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/benchmark.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/util/rng.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nImageDataLayer<Dtype>::~ImageDataLayer<Dtype>() {\n  this->StopInternalThread();\n}\n\ntemplate <typename Dtype>\nvoid ImageDataLayer<Dtype>::DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int new_height = this->layer_param_.image_data_param().new_height();\n  const int new_width  = this->layer_param_.image_data_param().new_width();\n  const bool is_color  = this->layer_param_.image_data_param().is_color();\n  string root_folder = this->layer_param_.image_data_param().root_folder();\n\n  CHECK((new_height == 0 && new_width == 0) ||\n      (new_height > 0 && new_width > 0)) << \"Current implementation requires \"\n      \"new_height and new_width to be set at the same time.\";\n  // Read the file with filenames and labels\n  const string& source = this->layer_param_.image_data_param().source();\n  LOG(INFO) << \"Opening file \" << source;\n  std::ifstream infile(source.c_str());\n  string filename;\n  int label;\n  while (infile >> filename >> label) {\n    lines_.push_back(std::make_pair(filename, label));\n  }\n\n  if (this->layer_param_.image_data_param().shuffle()) {\n    // randomly shuffle data\n    LOG(INFO) << \"Shuffling data\";\n    const unsigned int prefetch_rng_seed = caffe_rng_rand();\n    prefetch_rng_.reset(new Caffe::RNG(prefetch_rng_seed));\n    ShuffleImages();\n  }\n  LOG(INFO) << \"A total of \" << lines_.size() << \" images.\";\n\n  lines_id_ = 0;\n  // Check if we would need to randomly skip a few data points\n  if (this->layer_param_.image_data_param().rand_skip()) {\n    unsigned int skip = caffe_rng_rand() %\n        this->layer_param_.image_data_param().rand_skip();\n    LOG(INFO) << \"Skipping first \" << skip << \" data points.\";\n    CHECK_GT(lines_.size(), skip) << \"Not enough points to skip\";\n    lines_id_ = skip;\n  }\n  // Read an image, and use it to initialize the top blob.\n  cv::Mat cv_img = ReadImageToCVMat(root_folder + lines_[lines_id_].first,\n                                    new_height, new_width, is_color);\n  CHECK(cv_img.data) << \"Could not load \" << lines_[lines_id_].first;\n  // Use data_transformer to infer the expected blob shape from a cv_image.\n  vector<int> top_shape = this->data_transformer_->InferBlobShape(cv_img);\n  this->transformed_data_.Reshape(top_shape);\n  // Reshape prefetch_data and top[0] according to the batch_size.\n  const int batch_size = this->layer_param_.image_data_param().batch_size();\n  CHECK_GT(batch_size, 0) << \"Positive batch size required\";\n  top_shape[0] = batch_size;\n  for (int i = 0; i < this->PREFETCH_COUNT; ++i) {\n    this->prefetch_[i].data_.Reshape(top_shape);\n  }\n  top[0]->Reshape(top_shape);\n\n  LOG(INFO) << \"output data size: \" << top[0]->num() << \",\"\n      << top[0]->channels() << \",\" << top[0]->height() << \",\"\n      << top[0]->width();\n  // label\n  vector<int> label_shape(1, batch_size);\n  top[1]->Reshape(label_shape);\n  for (int i = 0; i < this->PREFETCH_COUNT; ++i) {\n    this->prefetch_[i].label_.Reshape(label_shape);\n  }\n}\n\ntemplate <typename Dtype>\nvoid ImageDataLayer<Dtype>::ShuffleImages() {\n  caffe::rng_t* prefetch_rng =\n      static_cast<caffe::rng_t*>(prefetch_rng_->generator());\n  shuffle(lines_.begin(), lines_.end(), prefetch_rng);\n}\n\n// This function is called on prefetch thread\ntemplate <typename Dtype>\nvoid ImageDataLayer<Dtype>::load_batch(Batch<Dtype>* batch) {\n  CPUTimer batch_timer;\n  batch_timer.Start();\n  double read_time = 0;\n  double trans_time = 0;\n  CPUTimer timer;\n  CHECK(batch->data_.count());\n  CHECK(this->transformed_data_.count());\n  ImageDataParameter image_data_param = this->layer_param_.image_data_param();\n  const int batch_size = image_data_param.batch_size();\n  const int new_height = image_data_param.new_height();\n  const int new_width = image_data_param.new_width();\n  const bool is_color = image_data_param.is_color();\n  string root_folder = image_data_param.root_folder();\n\n  // Reshape according to the first image of each batch\n  // on single input batches allows for inputs of varying dimension.\n  cv::Mat cv_img = ReadImageToCVMat(root_folder + lines_[lines_id_].first,\n      new_height, new_width, is_color);\n  CHECK(cv_img.data) << \"Could not load \" << lines_[lines_id_].first;\n  // Use data_transformer to infer the expected blob shape from a cv_img.\n  vector<int> top_shape = this->data_transformer_->InferBlobShape(cv_img);\n  this->transformed_data_.Reshape(top_shape);\n  // Reshape batch according to the batch_size.\n  top_shape[0] = batch_size;\n  batch->data_.Reshape(top_shape);\n\n  Dtype* prefetch_data = batch->data_.mutable_cpu_data();\n  Dtype* prefetch_label = batch->label_.mutable_cpu_data();\n\n  // datum scales\n  const int lines_size = lines_.size();\n  for (int item_id = 0; item_id < batch_size; ++item_id) {\n    // get a blob\n    timer.Start();\n    CHECK_GT(lines_size, lines_id_);\n    cv::Mat cv_img = ReadImageToCVMat(root_folder + lines_[lines_id_].first,\n        new_height, new_width, is_color);\n    CHECK(cv_img.data) << \"Could not load \" << lines_[lines_id_].first;\n    read_time += timer.MicroSeconds();\n    timer.Start();\n    // Apply transformations (mirror, crop...) to the image\n    int offset = batch->data_.offset(item_id);\n    this->transformed_data_.set_cpu_data(prefetch_data + offset);\n    this->data_transformer_->Transform(cv_img, &(this->transformed_data_));\n    trans_time += timer.MicroSeconds();\n\n    prefetch_label[item_id] = lines_[lines_id_].second;\n    // go to the next iter\n    lines_id_++;\n    if (lines_id_ >= lines_size) {\n      // We have reached the end. Restart from the first.\n      DLOG(INFO) << \"Restarting data prefetching from start.\";\n      lines_id_ = 0;\n      if (this->layer_param_.image_data_param().shuffle()) {\n        ShuffleImages();\n      }\n    }\n  }\n  batch_timer.Stop();\n  DLOG(INFO) << \"Prefetch batch: \" << batch_timer.MilliSeconds() << \" ms.\";\n  DLOG(INFO) << \"     Read time: \" << read_time / 1000 << \" ms.\";\n  DLOG(INFO) << \"Transform time: \" << trans_time / 1000 << \" ms.\";\n}\n\nINSTANTIATE_CLASS(ImageDataLayer);\nREGISTER_LAYER_CLASS(ImageData);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/infogain_loss_layer.cpp",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <cmath>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid InfogainLossLayer<Dtype>::LayerSetUp(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  LossLayer<Dtype>::LayerSetUp(bottom, top);\n  if (bottom.size() < 3) {\n    CHECK(this->layer_param_.infogain_loss_param().has_source())\n        << \"Infogain matrix source must be specified.\";\n    BlobProto blob_proto;\n    ReadProtoFromBinaryFile(\n      this->layer_param_.infogain_loss_param().source(), &blob_proto);\n    infogain_.FromProto(blob_proto);\n  }\n}\n\ntemplate <typename Dtype>\nvoid InfogainLossLayer<Dtype>::Reshape(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  LossLayer<Dtype>::Reshape(bottom, top);\n  Blob<Dtype>* infogain = NULL;\n  if (bottom.size() < 3) {\n    infogain = &infogain_;\n  } else {\n    infogain = bottom[2];\n  }\n  CHECK_EQ(bottom[1]->channels(), 1);\n  CHECK_EQ(bottom[1]->height(), 1);\n  CHECK_EQ(bottom[1]->width(), 1);\n  const int num = bottom[0]->num();\n  const int dim = bottom[0]->count() / num;\n  CHECK_EQ(infogain->num(), 1);\n  CHECK_EQ(infogain->channels(), 1);\n  CHECK_EQ(infogain->height(), dim);\n  CHECK_EQ(infogain->width(), dim);\n}\n\n\ntemplate <typename Dtype>\nvoid InfogainLossLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  const Dtype* bottom_label = bottom[1]->cpu_data();\n  const Dtype* infogain_mat = NULL;\n  if (bottom.size() < 3) {\n    infogain_mat = infogain_.cpu_data();\n  } else {\n    infogain_mat = bottom[2]->cpu_data();\n  }\n  int num = bottom[0]->num();\n  int dim = bottom[0]->count() / bottom[0]->num();\n  Dtype loss = 0;\n  for (int i = 0; i < num; ++i) {\n    int label = static_cast<int>(bottom_label[i]);\n    for (int j = 0; j < dim; ++j) {\n      Dtype prob = std::max(bottom_data[i * dim + j], Dtype(kLOG_THRESHOLD));\n      loss -= infogain_mat[label * dim + j] * log(prob);\n    }\n  }\n  top[0]->mutable_cpu_data()[0] = loss / num;\n}\n\ntemplate <typename Dtype>\nvoid InfogainLossLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[1]) {\n    LOG(FATAL) << this->type()\n               << \" Layer cannot backpropagate to label inputs.\";\n  }\n  if (propagate_down.size() > 2 && propagate_down[2]) {\n    LOG(FATAL) << this->type()\n               << \" Layer cannot backpropagate to infogain inputs.\";\n  }\n  if (propagate_down[0]) {\n    const Dtype* bottom_data = bottom[0]->cpu_data();\n    const Dtype* bottom_label = bottom[1]->cpu_data();\n    const Dtype* infogain_mat = NULL;\n    if (bottom.size() < 3) {\n      infogain_mat = infogain_.cpu_data();\n    } else {\n      infogain_mat = bottom[2]->cpu_data();\n    }\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    int num = bottom[0]->num();\n    int dim = bottom[0]->count() / bottom[0]->num();\n    const Dtype scale = - top[0]->cpu_diff()[0] / num;\n    for (int i = 0; i < num; ++i) {\n      const int label = static_cast<int>(bottom_label[i]);\n      for (int j = 0; j < dim; ++j) {\n        Dtype prob = std::max(bottom_data[i * dim + j], Dtype(kLOG_THRESHOLD));\n        bottom_diff[i * dim + j] = scale * infogain_mat[label * dim + j] / prob;\n      }\n    }\n  }\n}\n\nINSTANTIATE_CLASS(InfogainLossLayer);\nREGISTER_LAYER_CLASS(InfogainLoss);\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/inner_product_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid InnerProductLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int num_output = this->layer_param_.inner_product_param().num_output();\n  bias_term_ = this->layer_param_.inner_product_param().bias_term();\n  N_ = num_output;\n  const int axis = bottom[0]->CanonicalAxisIndex(\n      this->layer_param_.inner_product_param().axis());\n  // Dimensions starting from \"axis\" are \"flattened\" into a single\n  // length K_ vector. For example, if bottom[0]'s shape is (N, C, H, W),\n  // and axis == 1, N inner products with dimension CHW are performed.\n  K_ = bottom[0]->count(axis);\n  // Check if we need to set up the weights\n  if (this->blobs_.size() > 0) {\n    LOG(INFO) << \"Skipping parameter initialization\";\n  } else {\n    if (bias_term_) {\n      this->blobs_.resize(2);\n    } else {\n      this->blobs_.resize(1);\n    }\n    // Intialize the weight\n    vector<int> weight_shape(2);\n    weight_shape[0] = N_;\n    weight_shape[1] = K_;\n    this->blobs_[0].reset(new Blob<Dtype>(weight_shape));\n    // fill the weights\n    shared_ptr<Filler<Dtype> > weight_filler(GetFiller<Dtype>(\n        this->layer_param_.inner_product_param().weight_filler()));\n    weight_filler->Fill(this->blobs_[0].get());\n    // If necessary, intiialize and fill the bias term\n    if (bias_term_) {\n      vector<int> bias_shape(1, N_);\n      this->blobs_[1].reset(new Blob<Dtype>(bias_shape));\n      shared_ptr<Filler<Dtype> > bias_filler(GetFiller<Dtype>(\n          this->layer_param_.inner_product_param().bias_filler()));\n      bias_filler->Fill(this->blobs_[1].get());\n    }\n  }  // parameter initialization\n  this->param_propagate_down_.resize(this->blobs_.size(), true);\n}\n\ntemplate <typename Dtype>\nvoid InnerProductLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  // Figure out the dimensions\n  const int axis = bottom[0]->CanonicalAxisIndex(\n      this->layer_param_.inner_product_param().axis());\n  const int new_K = bottom[0]->count(axis);\n  CHECK_EQ(K_, new_K)\n      << \"Input size incompatible with inner product parameters.\";\n  // The first \"axis\" dimensions are independent inner products; the total\n  // number of these is M_, the product over these dimensions.\n  M_ = bottom[0]->count(0, axis);\n  // The top shape will be the bottom shape with the flattened axes dropped,\n  // and replaced by a single axis with dimension num_output (N_).\n  vector<int> top_shape = bottom[0]->shape();\n  top_shape.resize(axis + 1);\n  top_shape[axis] = N_;\n  top[0]->Reshape(top_shape);\n  // Set up the bias multiplier\n  if (bias_term_) {\n    vector<int> bias_shape(1, M_);\n    bias_multiplier_.Reshape(bias_shape);\n    caffe_set(M_, Dtype(1), bias_multiplier_.mutable_cpu_data());\n  }\n}\n\ntemplate <typename Dtype>\nvoid InnerProductLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  const Dtype* weight = this->blobs_[0]->cpu_data();\n  caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasTrans, M_, N_, K_, (Dtype)1.,\n      bottom_data, weight, (Dtype)0., top_data);\n  if (bias_term_) {\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, N_, 1, (Dtype)1.,\n        bias_multiplier_.cpu_data(),\n        this->blobs_[1]->cpu_data(), (Dtype)1., top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid InnerProductLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (this->param_propagate_down_[0]) {\n    const Dtype* top_diff = top[0]->cpu_diff();\n    const Dtype* bottom_data = bottom[0]->cpu_data();\n    // Gradient with respect to weight\n    caffe_cpu_gemm<Dtype>(CblasTrans, CblasNoTrans, N_, K_, M_, (Dtype)1.,\n        top_diff, bottom_data, (Dtype)1., this->blobs_[0]->mutable_cpu_diff());\n  }\n  if (bias_term_ && this->param_propagate_down_[1]) {\n    const Dtype* top_diff = top[0]->cpu_diff();\n    // Gradient with respect to bias\n    caffe_cpu_gemv<Dtype>(CblasTrans, M_, N_, (Dtype)1., top_diff,\n        bias_multiplier_.cpu_data(), (Dtype)1.,\n        this->blobs_[1]->mutable_cpu_diff());\n  }\n  if (propagate_down[0]) {\n    const Dtype* top_diff = top[0]->cpu_diff();\n    // Gradient with respect to bottom data\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, K_, N_, (Dtype)1.,\n        top_diff, this->blobs_[0]->cpu_data(), (Dtype)0.,\n        bottom[0]->mutable_cpu_diff());\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(InnerProductLayer);\n#endif\n\nINSTANTIATE_CLASS(InnerProductLayer);\nREGISTER_LAYER_CLASS(InnerProduct);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/inner_product_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid InnerProductLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  const Dtype* weight = this->blobs_[0]->gpu_data();\n  if (M_ == 1) {\n    caffe_gpu_gemv<Dtype>(CblasNoTrans, N_, K_, (Dtype)1.,\n                         weight, bottom_data, (Dtype)0., top_data);\n    if (bias_term_)\n      caffe_gpu_axpy<Dtype>(N_, bias_multiplier_.cpu_data()[0],\n                            this->blobs_[1]->gpu_data(), top_data);\n  } else {\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasTrans, M_, N_, K_, (Dtype)1.,\n                          bottom_data, weight, (Dtype)0., top_data);\n    if (bias_term_)\n      caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, N_, 1, (Dtype)1.,\n                            bias_multiplier_.gpu_data(),\n                            this->blobs_[1]->gpu_data(), (Dtype)1., top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid InnerProductLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (this->param_propagate_down_[0]) {\n    const Dtype* top_diff = top[0]->gpu_diff();\n    const Dtype* bottom_data = bottom[0]->gpu_data();\n    // Gradient with respect to weight\n    caffe_gpu_gemm<Dtype>(CblasTrans, CblasNoTrans, N_, K_, M_, (Dtype)1.,\n        top_diff, bottom_data, (Dtype)1., this->blobs_[0]->mutable_gpu_diff());\n  }\n  if (bias_term_ && this->param_propagate_down_[1]) {\n    const Dtype* top_diff = top[0]->gpu_diff();\n    // Gradient with respect to bias\n    caffe_gpu_gemv<Dtype>(CblasTrans, M_, N_, (Dtype)1., top_diff,\n        bias_multiplier_.gpu_data(), (Dtype)1.,\n        this->blobs_[1]->mutable_gpu_diff());\n  }\n  if (propagate_down[0]) {\n    const Dtype* top_diff = top[0]->gpu_diff();\n    // Gradient with respect to bottom data\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, K_, N_, (Dtype)1.,\n        top_diff, this->blobs_[0]->gpu_data(), (Dtype)0.,\n        bottom[0]->mutable_gpu_diff());\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(InnerProductLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/loss_layer.cpp",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <cmath>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid LossLayer<Dtype>::LayerSetUp(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  // LossLayers have a non-zero (1) loss by default.\n  if (this->layer_param_.loss_weight_size() == 0) {\n    this->layer_param_.add_loss_weight(Dtype(1));\n  }\n}\n\ntemplate <typename Dtype>\nvoid LossLayer<Dtype>::Reshape(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  CHECK_EQ(bottom[0]->num(), bottom[1]->num())\n      << \"The data and label should have the same number.\";\n  vector<int> loss_shape(0);  // Loss layers output a scalar; 0 axes.\n  top[0]->Reshape(loss_shape);\n}\n\nINSTANTIATE_CLASS(LossLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/lrn_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  size_ = this->layer_param_.lrn_param().local_size();\n  CHECK_EQ(size_ % 2, 1) << \"LRN only supports odd values for local_size\";\n  pre_pad_ = (size_ - 1) / 2;\n  alpha_ = this->layer_param_.lrn_param().alpha();\n  beta_ = this->layer_param_.lrn_param().beta();\n  k_ = this->layer_param_.lrn_param().k();\n  if (this->layer_param_.lrn_param().norm_region() ==\n      LRNParameter_NormRegion_WITHIN_CHANNEL) {\n    // Set up split_layer_ to use inputs in the numerator and denominator.\n    split_top_vec_.clear();\n    split_top_vec_.push_back(&product_input_);\n    split_top_vec_.push_back(&square_input_);\n    LayerParameter split_param;\n    split_layer_.reset(new SplitLayer<Dtype>(split_param));\n    split_layer_->SetUp(bottom, split_top_vec_);\n    // Set up square_layer_ to square the inputs.\n    square_bottom_vec_.clear();\n    square_top_vec_.clear();\n    square_bottom_vec_.push_back(&square_input_);\n    square_top_vec_.push_back(&square_output_);\n    LayerParameter square_param;\n    square_param.mutable_power_param()->set_power(Dtype(2));\n    square_layer_.reset(new PowerLayer<Dtype>(square_param));\n    square_layer_->SetUp(square_bottom_vec_, square_top_vec_);\n    // Set up pool_layer_ to sum over square neighborhoods of the input.\n    pool_top_vec_.clear();\n    pool_top_vec_.push_back(&pool_output_);\n    LayerParameter pool_param;\n    pool_param.mutable_pooling_param()->set_pool(\n        PoolingParameter_PoolMethod_AVE);\n    pool_param.mutable_pooling_param()->set_pad(pre_pad_);\n    pool_param.mutable_pooling_param()->set_kernel_size(size_);\n    pool_layer_.reset(new PoolingLayer<Dtype>(pool_param));\n    pool_layer_->SetUp(square_top_vec_, pool_top_vec_);\n    // Set up power_layer_ to compute (1 + alpha_/N^2 s)^-beta_, where s is\n    // the sum of a squared neighborhood (the output of pool_layer_).\n    power_top_vec_.clear();\n    power_top_vec_.push_back(&power_output_);\n    LayerParameter power_param;\n    power_param.mutable_power_param()->set_power(-beta_);\n    power_param.mutable_power_param()->set_scale(alpha_);\n    power_param.mutable_power_param()->set_shift(Dtype(1));\n    power_layer_.reset(new PowerLayer<Dtype>(power_param));\n    power_layer_->SetUp(pool_top_vec_, power_top_vec_);\n    // Set up a product_layer_ to compute outputs by multiplying inputs by the\n    // inverse demoninator computed by the power layer.\n    product_bottom_vec_.clear();\n    product_bottom_vec_.push_back(&product_input_);\n    product_bottom_vec_.push_back(&power_output_);\n    LayerParameter product_param;\n    EltwiseParameter* eltwise_param = product_param.mutable_eltwise_param();\n    eltwise_param->set_operation(EltwiseParameter_EltwiseOp_PROD);\n    product_layer_.reset(new EltwiseLayer<Dtype>(product_param));\n    product_layer_->SetUp(product_bottom_vec_, top);\n  }\n}\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK_EQ(4, bottom[0]->num_axes()) << \"Input must have 4 axes, \"\n      << \"corresponding to (num, channels, height, width)\";\n  num_ = bottom[0]->num();\n  channels_ = bottom[0]->channels();\n  height_ = bottom[0]->height();\n  width_ = bottom[0]->width();\n  switch (this->layer_param_.lrn_param().norm_region()) {\n  case LRNParameter_NormRegion_ACROSS_CHANNELS:\n    top[0]->Reshape(num_, channels_, height_, width_);\n    scale_.Reshape(num_, channels_, height_, width_);\n    break;\n  case LRNParameter_NormRegion_WITHIN_CHANNEL:\n    split_layer_->Reshape(bottom, split_top_vec_);\n    square_layer_->Reshape(square_bottom_vec_, square_top_vec_);\n    pool_layer_->Reshape(square_top_vec_, pool_top_vec_);\n    power_layer_->Reshape(pool_top_vec_, power_top_vec_);\n    product_layer_->Reshape(product_bottom_vec_, top);\n    break;\n  }\n}\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  switch (this->layer_param_.lrn_param().norm_region()) {\n  case LRNParameter_NormRegion_ACROSS_CHANNELS:\n    CrossChannelForward_cpu(bottom, top);\n    break;\n  case LRNParameter_NormRegion_WITHIN_CHANNEL:\n    WithinChannelForward(bottom, top);\n    break;\n  default:\n    LOG(FATAL) << \"Unknown normalization region.\";\n  }\n}\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::CrossChannelForward_cpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  Dtype* scale_data = scale_.mutable_cpu_data();\n  // start with the constant value\n  for (int i = 0; i < scale_.count(); ++i) {\n    scale_data[i] = k_;\n  }\n  Blob<Dtype> padded_square(1, channels_ + size_ - 1, height_, width_);\n  Dtype* padded_square_data = padded_square.mutable_cpu_data();\n  caffe_set(padded_square.count(), Dtype(0), padded_square_data);\n  Dtype alpha_over_size = alpha_ / size_;\n  // go through the images\n  for (int n = 0; n < num_; ++n) {\n    // compute the padded square\n    caffe_sqr(channels_ * height_ * width_,\n        bottom_data + bottom[0]->offset(n),\n        padded_square_data + padded_square.offset(0, pre_pad_));\n    // Create the first channel scale\n    for (int c = 0; c < size_; ++c) {\n      caffe_axpy<Dtype>(height_ * width_, alpha_over_size,\n          padded_square_data + padded_square.offset(0, c),\n          scale_data + scale_.offset(n, 0));\n    }\n    for (int c = 1; c < channels_; ++c) {\n      // copy previous scale\n      caffe_copy<Dtype>(height_ * width_,\n          scale_data + scale_.offset(n, c - 1),\n          scale_data + scale_.offset(n, c));\n      // add head\n      caffe_axpy<Dtype>(height_ * width_, alpha_over_size,\n          padded_square_data + padded_square.offset(0, c + size_ - 1),\n          scale_data + scale_.offset(n, c));\n      // subtract tail\n      caffe_axpy<Dtype>(height_ * width_, -alpha_over_size,\n          padded_square_data + padded_square.offset(0, c - 1),\n          scale_data + scale_.offset(n, c));\n    }\n  }\n\n  // In the end, compute output\n  caffe_powx<Dtype>(scale_.count(), scale_data, -beta_, top_data);\n  caffe_mul<Dtype>(scale_.count(), top_data, bottom_data, top_data);\n}\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::WithinChannelForward(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  split_layer_->Forward(bottom, split_top_vec_);\n  square_layer_->Forward(square_bottom_vec_, square_top_vec_);\n  pool_layer_->Forward(square_top_vec_, pool_top_vec_);\n  power_layer_->Forward(pool_top_vec_, power_top_vec_);\n  product_layer_->Forward(product_bottom_vec_, top);\n}\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  switch (this->layer_param_.lrn_param().norm_region()) {\n  case LRNParameter_NormRegion_ACROSS_CHANNELS:\n    CrossChannelBackward_cpu(top, propagate_down, bottom);\n    break;\n  case LRNParameter_NormRegion_WITHIN_CHANNEL:\n    WithinChannelBackward(top, propagate_down, bottom);\n    break;\n  default:\n    LOG(FATAL) << \"Unknown normalization region.\";\n  }\n}\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::CrossChannelBackward_cpu(\n    const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->cpu_diff();\n  const Dtype* top_data = top[0]->cpu_data();\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  const Dtype* scale_data = scale_.cpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n  Blob<Dtype> padded_ratio(1, channels_ + size_ - 1, height_, width_);\n  Blob<Dtype> accum_ratio(1, 1, height_, width_);\n  Dtype* padded_ratio_data = padded_ratio.mutable_cpu_data();\n  Dtype* accum_ratio_data = accum_ratio.mutable_cpu_data();\n  // We hack a little bit by using the diff() to store an additional result\n  Dtype* accum_ratio_times_bottom = accum_ratio.mutable_cpu_diff();\n  caffe_set(padded_ratio.count(), Dtype(0), padded_ratio_data);\n  Dtype cache_ratio_value = 2. * alpha_ * beta_ / size_;\n\n  caffe_powx<Dtype>(scale_.count(), scale_data, -beta_, bottom_diff);\n  caffe_mul<Dtype>(scale_.count(), top_diff, bottom_diff, bottom_diff);\n\n  // go through individual data\n  int inverse_pre_pad = size_ - (size_ + 1) / 2;\n  for (int n = 0; n < num_; ++n) {\n    int block_offset = scale_.offset(n);\n    // first, compute diff_i * y_i / s_i\n    caffe_mul<Dtype>(channels_ * height_ * width_,\n        top_diff + block_offset, top_data + block_offset,\n        padded_ratio_data + padded_ratio.offset(0, inverse_pre_pad));\n    caffe_div<Dtype>(channels_ * height_ * width_,\n        padded_ratio_data + padded_ratio.offset(0, inverse_pre_pad),\n        scale_data + block_offset,\n        padded_ratio_data + padded_ratio.offset(0, inverse_pre_pad));\n    // Now, compute the accumulated ratios and the bottom diff\n    caffe_set(accum_ratio.count(), Dtype(0), accum_ratio_data);\n    for (int c = 0; c < size_ - 1; ++c) {\n      caffe_axpy<Dtype>(height_ * width_, 1.,\n          padded_ratio_data + padded_ratio.offset(0, c), accum_ratio_data);\n    }\n    for (int c = 0; c < channels_; ++c) {\n      caffe_axpy<Dtype>(height_ * width_, 1.,\n          padded_ratio_data + padded_ratio.offset(0, c + size_ - 1),\n          accum_ratio_data);\n      // compute bottom diff\n      caffe_mul<Dtype>(height_ * width_,\n          bottom_data + top[0]->offset(n, c),\n          accum_ratio_data, accum_ratio_times_bottom);\n      caffe_axpy<Dtype>(height_ * width_, -cache_ratio_value,\n          accum_ratio_times_bottom, bottom_diff + top[0]->offset(n, c));\n      caffe_axpy<Dtype>(height_ * width_, -1.,\n          padded_ratio_data + padded_ratio.offset(0, c), accum_ratio_data);\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::WithinChannelBackward(\n    const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    vector<bool> product_propagate_down(2, true);\n    product_layer_->Backward(top, product_propagate_down, product_bottom_vec_);\n    power_layer_->Backward(power_top_vec_, propagate_down, pool_top_vec_);\n    pool_layer_->Backward(pool_top_vec_, propagate_down, square_top_vec_);\n    square_layer_->Backward(square_top_vec_, propagate_down,\n                            square_bottom_vec_);\n    split_layer_->Backward(split_top_vec_, propagate_down, bottom);\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(LRNLayer);\nSTUB_GPU_FORWARD(LRNLayer, CrossChannelForward);\nSTUB_GPU_BACKWARD(LRNLayer, CrossChannelBackward);\n#endif\n\nINSTANTIATE_CLASS(LRNLayer);\nREGISTER_LAYER_CLASS(LRN);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/lrn_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void LRNFillScale(const int nthreads, const Dtype* const in,\n    const int num, const int channels, const int height,\n    const int width, const int size, const Dtype alpha_over_size,\n    const Dtype k, Dtype* const scale) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    // find out the local offset\n    const int w = index % width;\n    const int h = (index / width) % height;\n    const int n = index / width / height;\n    const int offset = (n * channels * height + h) * width + w;\n    const int step = height * width;\n    const Dtype* const in_off = in + offset;\n    Dtype* const scale_off = scale + offset;\n    int head = 0;\n    const int pre_pad = (size - 1) / 2;\n    const int post_pad = size - pre_pad - 1;\n    Dtype accum_scale = 0;\n    // fill the scale at [n, :, h, w]\n    // accumulate values\n    while (head < post_pad && head < channels) {\n      accum_scale += in_off[head * step] * in_off[head * step];\n      ++head;\n    }\n    // both add and subtract\n    while (head < channels) {\n      accum_scale += in_off[head * step] * in_off[head * step];\n      if (head - size >= 0) {\n        accum_scale -= in_off[(head - size) * step]\n                       * in_off[(head - size) * step];\n      }\n      scale_off[(head - post_pad) * step] = k + accum_scale * alpha_over_size;\n      ++head;\n    }\n    // subtract only\n    while (head < channels + post_pad) {\n      if (head - size >= 0) {\n        accum_scale -= in_off[(head - size) * step]\n                       * in_off[(head - size) * step];\n      }\n      scale_off[(head - post_pad) * step] = k + accum_scale * alpha_over_size;\n      ++head;\n    }\n  }\n}\n\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  switch (this->layer_param_.lrn_param().norm_region()) {\n  case LRNParameter_NormRegion_ACROSS_CHANNELS:\n    CrossChannelForward_gpu(bottom, top);\n    break;\n  case LRNParameter_NormRegion_WITHIN_CHANNEL:\n    WithinChannelForward(bottom, top);\n    break;\n  default:\n    LOG(FATAL) << \"Unknown normalization region.\";\n  }\n}\n\n// TODO: check if it would be faster to just put it into the previous kernel.\ntemplate <typename Dtype>\n__global__ void LRNComputeOutput(const int nthreads, const Dtype* const in,\n    const Dtype* const scale, const Dtype negative_beta, Dtype* const out) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    out[index] = in[index] * pow(scale[index], negative_beta);\n  }\n}\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::CrossChannelForward_gpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  // First, compute scale\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  Dtype* scale_data = scale_.mutable_gpu_data();\n  // We will launch one kernel for each pixel location, and have the kernel\n  // go through all the channels.\n  int n_threads = num_ * height_ * width_;\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  LRNFillScale<<<CAFFE_GET_BLOCKS(n_threads), CAFFE_CUDA_NUM_THREADS>>>(\n      n_threads, bottom_data, num_, channels_, height_, width_, size_,\n      alpha_ / size_, k_, scale_data);\n  CUDA_POST_KERNEL_CHECK;\n  n_threads = bottom[0]->count();\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  LRNComputeOutput<<<CAFFE_GET_BLOCKS(n_threads), CAFFE_CUDA_NUM_THREADS>>>(\n      n_threads, bottom_data, scale_data, -beta_, top_data);\n  CUDA_POST_KERNEL_CHECK;\n}\ntemplate void LRNLayer<float>::CrossChannelForward_gpu(\n    const vector<Blob<float>*>& bottom, const vector<Blob<float>*>& top);\ntemplate void LRNLayer<double>::CrossChannelForward_gpu(\n    const vector<Blob<double>*>& bottom, const vector<Blob<double>*>& top);\n\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  switch (this->layer_param_.lrn_param().norm_region()) {\n  case LRNParameter_NormRegion_ACROSS_CHANNELS:\n    CrossChannelBackward_gpu(top, propagate_down, bottom);\n    break;\n  case LRNParameter_NormRegion_WITHIN_CHANNEL:\n    WithinChannelBackward(top, propagate_down, bottom);\n    break;\n  default:\n    LOG(FATAL) << \"Unknown normalization region.\";\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void LRNComputeDiff(const int nthreads,\n    const Dtype* const bottom_data, const Dtype* const top_data,\n    const Dtype* const scale, const Dtype* const top_diff,\n    const int num, const int channels, const int height,\n    const int width, const int size, const Dtype negative_beta,\n    const Dtype cache_ratio, Dtype* const bottom_diff) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    // find out the local offset\n    const int w = index % width;\n    const int h = (index / width) % height;\n    const int n = index / width / height;\n    const int offset = (n * channels * height + h) * width + w;\n    const int step = height * width;\n    const Dtype* const bottom_off = bottom_data + offset;\n    const Dtype* const top_off = top_data + offset;\n    const Dtype* const scale_off = scale + offset;\n    const Dtype* const top_diff_off = top_diff + offset;\n    Dtype* const bottom_diff_off = bottom_diff + offset;\n    int head = 0;\n    const int pre_pad = size - (size + 1) / 2;\n    const int post_pad = size - pre_pad - 1;\n    Dtype accum_ratio = 0;\n    // accumulate values\n    while (head < post_pad && head < channels) {\n      accum_ratio += top_diff_off[head * step] * top_off[head * step] /\n          scale_off[head * step];\n      ++head;\n    }\n    // both add and subtract\n    while (head < channels) {\n      accum_ratio += top_diff_off[head * step] * top_off[head * step] /\n          scale_off[head * step];\n      if (head - size >= 0) {\n        accum_ratio -= top_diff_off[(head - size) * step] *\n            top_off[(head - size) * step] / scale_off[(head - size) * step];\n      }\n      bottom_diff_off[(head - post_pad) * step] =\n          top_diff_off[(head - post_pad) * step]\n            * pow(scale_off[(head - post_pad) * step], negative_beta)\n          - cache_ratio * bottom_off[(head - post_pad) * step] * accum_ratio;\n      ++head;\n    }\n    // subtract only\n    while (head < channels + post_pad) {\n      if (head - size >= 0) {\n        accum_ratio -= top_diff_off[(head - size) * step] *\n            top_off[(head - size) * step] / scale_off[(head - size) * step];\n      }\n      bottom_diff_off[(head - post_pad) * step] =\n          top_diff_off[(head - post_pad) * step]\n            * pow(scale_off[(head - post_pad) * step], negative_beta)\n          - cache_ratio * bottom_off[(head - post_pad) * step] * accum_ratio;\n      ++head;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid LRNLayer<Dtype>::CrossChannelBackward_gpu(\n    const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  int n_threads = num_ * height_ * width_;\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  LRNComputeDiff<<<CAFFE_GET_BLOCKS(n_threads), CAFFE_CUDA_NUM_THREADS>>>(\n      n_threads, bottom[0]->gpu_data(), top[0]->gpu_data(),\n      scale_.gpu_data(), top[0]->gpu_diff(), num_, channels_, height_, width_,\n      size_, -beta_, Dtype(2. * alpha_ * beta_ / size_),\n      bottom[0]->mutable_gpu_diff());\n}\ntemplate void LRNLayer<float>::CrossChannelBackward_gpu(\n    const vector<Blob<float>*>& top, const vector<bool>& propagate_down,\n    const vector<Blob<float>*>& bottom);\ntemplate void LRNLayer<double>::CrossChannelBackward_gpu(\n    const vector<Blob<double>*>& top, const vector<bool>& propagate_down,\n    const vector<Blob<double>*>& bottom);\n\n\n\nINSTANTIATE_LAYER_GPU_FUNCS(LRNLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/memory_data_layer.cpp",
    "content": "#include <opencv2/core/core.hpp>\n\n#include <vector>\n\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid MemoryDataLayer<Dtype>::DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,\n     const vector<Blob<Dtype>*>& top) {\n  batch_size_ = this->layer_param_.memory_data_param().batch_size();\n  channels_ = this->layer_param_.memory_data_param().channels();\n  height_ = this->layer_param_.memory_data_param().height();\n  width_ = this->layer_param_.memory_data_param().width();\n  size_ = channels_ * height_ * width_;\n  CHECK_GT(batch_size_ * size_, 0) <<\n      \"batch_size, channels, height, and width must be specified and\"\n      \" positive in memory_data_param\";\n  vector<int> label_shape(1, batch_size_);\n  top[0]->Reshape(batch_size_, channels_, height_, width_);\n  top[1]->Reshape(label_shape);\n  added_data_.Reshape(batch_size_, channels_, height_, width_);\n  added_label_.Reshape(label_shape);\n  data_ = NULL;\n  labels_ = NULL;\n  added_data_.cpu_data();\n  added_label_.cpu_data();\n}\n\ntemplate <typename Dtype>\nvoid MemoryDataLayer<Dtype>::AddDatumVector(const vector<Datum>& datum_vector) {\n  CHECK(!has_new_data_) <<\n      \"Can't add data until current data has been consumed.\";\n  size_t num = datum_vector.size();\n  CHECK_GT(num, 0) << \"There is no datum to add.\";\n  CHECK_EQ(num % batch_size_, 0) <<\n      \"The added data must be a multiple of the batch size.\";\n  added_data_.Reshape(num, channels_, height_, width_);\n  added_label_.Reshape(num, 1, 1, 1);\n  // Apply data transformations (mirror, scale, crop...)\n  this->data_transformer_->Transform(datum_vector, &added_data_);\n  // Copy Labels\n  Dtype* top_label = added_label_.mutable_cpu_data();\n  for (int item_id = 0; item_id < num; ++item_id) {\n    top_label[item_id] = datum_vector[item_id].label();\n  }\n  // num_images == batch_size_\n  Dtype* top_data = added_data_.mutable_cpu_data();\n  Reset(top_data, top_label, num);\n  has_new_data_ = true;\n}\n\ntemplate <typename Dtype>\nvoid MemoryDataLayer<Dtype>::AddMatVector(const vector<cv::Mat>& mat_vector,\n    const vector<int>& labels) {\n  size_t num = mat_vector.size();\n  CHECK(!has_new_data_) <<\n      \"Can't add mat until current data has been consumed.\";\n  CHECK_GT(num, 0) << \"There is no mat to add\";\n  CHECK_EQ(num % batch_size_, 0) <<\n      \"The added data must be a multiple of the batch size.\";\n  added_data_.Reshape(num, channels_, height_, width_);\n  added_label_.Reshape(num, 1, 1, 1);\n  // Apply data transformations (mirror, scale, crop...)\n  this->data_transformer_->Transform(mat_vector, &added_data_);\n  // Copy Labels\n  Dtype* top_label = added_label_.mutable_cpu_data();\n  for (int item_id = 0; item_id < num; ++item_id) {\n    top_label[item_id] = labels[item_id];\n  }\n  // num_images == batch_size_\n  Dtype* top_data = added_data_.mutable_cpu_data();\n  Reset(top_data, top_label, num);\n  has_new_data_ = true;\n}\n\ntemplate <typename Dtype>\nvoid MemoryDataLayer<Dtype>::Reset(Dtype* data, Dtype* labels, int n) {\n  CHECK(data);\n  CHECK(labels);\n  CHECK_EQ(n % batch_size_, 0) << \"n must be a multiple of batch size\";\n  // Warn with transformation parameters since a memory array is meant to\n  // be generic and no transformations are done with Reset().\n  if (this->layer_param_.has_transform_param()) {\n    LOG(WARNING) << this->type() << \" does not transform array data on Reset()\";\n  }\n  data_ = data;\n  labels_ = labels;\n  n_ = n;\n  pos_ = 0;\n}\n\ntemplate <typename Dtype>\nvoid MemoryDataLayer<Dtype>::set_batch_size(int new_size) {\n  CHECK(!has_new_data_) <<\n      \"Can't change batch_size until current data has been consumed.\";\n  batch_size_ = new_size;\n  added_data_.Reshape(batch_size_, channels_, height_, width_);\n  added_label_.Reshape(batch_size_, 1, 1, 1);\n}\n\ntemplate <typename Dtype>\nvoid MemoryDataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK(data_) << \"MemoryDataLayer needs to be initalized by calling Reset\";\n  top[0]->Reshape(batch_size_, channels_, height_, width_);\n  top[1]->Reshape(batch_size_, 1, 1, 1);\n  top[0]->set_cpu_data(data_ + pos_ * size_);\n  top[1]->set_cpu_data(labels_ + pos_);\n  pos_ = (pos_ + batch_size_) % n_;\n  if (pos_ == 0)\n    has_new_data_ = false;\n}\n\nINSTANTIATE_CLASS(MemoryDataLayer);\nREGISTER_LAYER_CLASS(MemoryData);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/multinomial_logistic_loss_layer.cpp",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <cmath>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid MultinomialLogisticLossLayer<Dtype>::Reshape(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  LossLayer<Dtype>::Reshape(bottom, top);\n  CHECK_EQ(bottom[1]->channels(), 1);\n  CHECK_EQ(bottom[1]->height(), 1);\n  CHECK_EQ(bottom[1]->width(), 1);\n}\n\ntemplate <typename Dtype>\nvoid MultinomialLogisticLossLayer<Dtype>::Forward_cpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  const Dtype* bottom_label = bottom[1]->cpu_data();\n  int num = bottom[0]->num();\n  int dim = bottom[0]->count() / bottom[0]->num();\n  Dtype loss = 0;\n  for (int i = 0; i < num; ++i) {\n    int label = static_cast<int>(bottom_label[i]);\n    Dtype prob = std::max(\n        bottom_data[i * dim + label], Dtype(kLOG_THRESHOLD));\n    loss -= log(prob);\n  }\n  top[0]->mutable_cpu_data()[0] = loss / num;\n}\n\ntemplate <typename Dtype>\nvoid MultinomialLogisticLossLayer<Dtype>::Backward_cpu(\n    const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[1]) {\n    LOG(FATAL) << this->type()\n               << \" Layer cannot backpropagate to label inputs.\";\n  }\n  if (propagate_down[0]) {\n    const Dtype* bottom_data = bottom[0]->cpu_data();\n    const Dtype* bottom_label = bottom[1]->cpu_data();\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    int num = bottom[0]->num();\n    int dim = bottom[0]->count() / bottom[0]->num();\n    caffe_set(bottom[0]->count(), Dtype(0), bottom_diff);\n    const Dtype scale = - top[0]->cpu_diff()[0] / num;\n    for (int i = 0; i < num; ++i) {\n      int label = static_cast<int>(bottom_label[i]);\n      Dtype prob = std::max(\n          bottom_data[i * dim + label], Dtype(kLOG_THRESHOLD));\n      bottom_diff[i * dim + label] = scale / prob;\n    }\n  }\n}\n\nINSTANTIATE_CLASS(MultinomialLogisticLossLayer);\nREGISTER_LAYER_CLASS(MultinomialLogisticLoss);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/mvn_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/common_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid MVNLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  top[0]->Reshape(bottom[0]->num(), bottom[0]->channels(),\n      bottom[0]->height(), bottom[0]->width());\n  mean_.Reshape(bottom[0]->num(), bottom[0]->channels(),\n      1, 1);\n  variance_.Reshape(bottom[0]->num(), bottom[0]->channels(),\n      1, 1);\n  temp_.Reshape(bottom[0]->num(), bottom[0]->channels(),\n      bottom[0]->height(), bottom[0]->width());\n  sum_multiplier_.Reshape(1, 1,\n      bottom[0]->height(), bottom[0]->width());\n  Dtype* multiplier_data = sum_multiplier_.mutable_cpu_data();\n  caffe_set(sum_multiplier_.count(), Dtype(1), multiplier_data);\n  eps_ = this->layer_param_.mvn_param().eps();\n}\n\ntemplate <typename Dtype>\nvoid MVNLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  int num;\n  if (this->layer_param_.mvn_param().across_channels())\n    num = bottom[0]->num();\n  else\n    num = bottom[0]->num() * bottom[0]->channels();\n\n  int dim = bottom[0]->count() / num;\n\n  if (this->layer_param_.mvn_param().normalize_variance()) {\n    // put the squares of bottom into temp_\n    caffe_powx(bottom[0]->count(), bottom_data, Dtype(2),\n        temp_.mutable_cpu_data());\n\n    // computes variance using var(X) = E(X^2) - (EX)^2\n    caffe_cpu_gemv<Dtype>(CblasNoTrans, num, dim, 1. / dim, bottom_data,\n        sum_multiplier_.cpu_data(), 0., mean_.mutable_cpu_data());  // EX\n    caffe_cpu_gemv<Dtype>(CblasNoTrans, num, dim, 1. / dim, temp_.cpu_data(),\n        sum_multiplier_.cpu_data(), 0.,\n        variance_.mutable_cpu_data());  // E(X^2)\n    caffe_powx(mean_.count(), mean_.cpu_data(), Dtype(2),\n        temp_.mutable_cpu_data());  // (EX)^2\n    caffe_sub(mean_.count(), variance_.cpu_data(), temp_.cpu_data(),\n        variance_.mutable_cpu_data());  // variance\n\n    // do mean and variance normalization\n    // subtract mean\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, -1.,\n            mean_.cpu_data(), sum_multiplier_.cpu_data(), 0.,\n            temp_.mutable_cpu_data());\n\n    caffe_add(temp_.count(), bottom_data, temp_.cpu_data(), top_data);\n\n    // normalize variance\n    caffe_powx(variance_.count(), variance_.cpu_data(), Dtype(0.5),\n          variance_.mutable_cpu_data());\n\n    caffe_add_scalar(variance_.count(), eps_, variance_.mutable_cpu_data());\n\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,\n          variance_.cpu_data(), sum_multiplier_.cpu_data(), 0.,\n          temp_.mutable_cpu_data());\n\n    caffe_div(temp_.count(), top_data, temp_.cpu_data(), top_data);\n  } else {\n    caffe_cpu_gemv<Dtype>(CblasNoTrans, num, dim, 1. / dim, bottom_data,\n            sum_multiplier_.cpu_data(), 0., mean_.mutable_cpu_data());  // EX\n\n    // subtract mean\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, -1.,\n            mean_.cpu_data(), sum_multiplier_.cpu_data(), 0.,\n            temp_.mutable_cpu_data());\n\n    caffe_add(temp_.count(), bottom_data, temp_.cpu_data(), top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid MVNLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->cpu_diff();\n  const Dtype* top_data = top[0]->cpu_data();\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n\n  int num;\n  if (this->layer_param_.mvn_param().across_channels())\n    num = bottom[0]->num();\n  else\n    num = bottom[0]->num() * bottom[0]->channels();\n\n  int dim = bottom[0]->count() / num;\n\n  if (this->layer_param_.mvn_param().normalize_variance()) {\n    caffe_mul(temp_.count(), top_data, top_diff, bottom_diff);\n    caffe_cpu_gemv<Dtype>(CblasNoTrans, num, dim, 1., bottom_diff,\n          sum_multiplier_.cpu_data(), 0., mean_.mutable_cpu_data());\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,\n          mean_.cpu_data(), sum_multiplier_.cpu_data(), 0.,\n          bottom_diff);\n    caffe_mul(temp_.count(), top_data, bottom_diff, bottom_diff);\n\n    caffe_cpu_gemv<Dtype>(CblasNoTrans, num, dim, 1., top_diff,\n            sum_multiplier_.cpu_data(), 0., mean_.mutable_cpu_data());\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,\n            mean_.cpu_data(), sum_multiplier_.cpu_data(), 1.,\n            bottom_diff);\n\n    caffe_cpu_axpby(temp_.count(), Dtype(1), top_diff, Dtype(-1. / dim),\n        bottom_diff);\n\n    // put the squares of bottom into temp_\n    caffe_powx(temp_.count(), bottom_data, Dtype(2),\n        temp_.mutable_cpu_data());\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,\n        variance_.cpu_data(), sum_multiplier_.cpu_data(), 0.,\n        temp_.mutable_cpu_data());\n\n    caffe_div(temp_.count(), bottom_diff, temp_.cpu_data(), bottom_diff);\n  } else {\n    caffe_copy(temp_.count(), top_diff, bottom_diff);\n  }\n}\n\n\n#ifdef CPU_ONLY\nSTUB_GPU(MVNLayer);\n#endif\n\nINSTANTIATE_CLASS(MVNLayer);\nREGISTER_LAYER_CLASS(MVN);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/mvn_layer.cu",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/common_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid MVNLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  int num;\n  if (this->layer_param_.mvn_param().across_channels())\n    num = bottom[0]->num();\n  else\n    num = bottom[0]->num() * bottom[0]->channels();\n\n  int dim = bottom[0]->count() / num;\n\n  if (this->layer_param_.mvn_param().normalize_variance()) {\n    // put the squares of bottom into temp_\n    caffe_gpu_powx(bottom[0]->count(), bottom_data, Dtype(2),\n        temp_.mutable_gpu_data());\n\n    // computes variance using var(X) = E(X^2) - (EX)^2\n    caffe_gpu_gemv<Dtype>(CblasNoTrans, num, dim, 1. / dim, bottom_data,\n        sum_multiplier_.gpu_data(), 0., mean_.mutable_gpu_data());  // EX\n    caffe_gpu_gemv<Dtype>(CblasNoTrans, num, dim, 1. / dim, temp_.gpu_data(),\n        sum_multiplier_.gpu_data(), 0.,\n        variance_.mutable_gpu_data());  // E(X^2)\n    caffe_gpu_powx(mean_.count(), mean_.gpu_data(), Dtype(2),\n        temp_.mutable_gpu_data());  // (EX)^2\n    caffe_gpu_sub(mean_.count(), variance_.gpu_data(), temp_.gpu_data(),\n        variance_.mutable_gpu_data());  // variance\n\n    // do mean and variance normalization\n    // subtract mean\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, -1.,\n            mean_.gpu_data(), sum_multiplier_.gpu_data(), 0.,\n            temp_.mutable_gpu_data());\n\n    caffe_gpu_add(temp_.count(), bottom_data, temp_.gpu_data(), top_data);\n\n    // normalize variance\n    caffe_gpu_powx(variance_.count(), variance_.gpu_data(), Dtype(0.5),\n          variance_.mutable_gpu_data());\n\n    caffe_gpu_add_scalar(variance_.count(), eps_, variance_.mutable_gpu_data());\n\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,\n          variance_.gpu_data(), sum_multiplier_.gpu_data(), 0.,\n          temp_.mutable_gpu_data());\n\n    caffe_gpu_div(temp_.count(), top_data, temp_.gpu_data(), top_data);\n  } else {\n    caffe_gpu_gemv<Dtype>(CblasNoTrans, num, dim, 1. / dim, bottom_data,\n            sum_multiplier_.gpu_data(), 0., mean_.mutable_gpu_data());  // EX\n\n    // subtract mean\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, -1.,\n            mean_.gpu_data(), sum_multiplier_.gpu_data(), 0.,\n            temp_.mutable_gpu_data());\n\n    caffe_gpu_add(temp_.count(), bottom_data, temp_.gpu_data(), top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid MVNLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->gpu_diff();\n  const Dtype* top_data = top[0]->gpu_data();\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n\n  int num;\n  if (this->layer_param_.mvn_param().across_channels())\n    num = bottom[0]->num();\n  else\n    num = bottom[0]->num() * bottom[0]->channels();\n\n  int dim = bottom[0]->count() / num;\n\n  if (this->layer_param_.mvn_param().normalize_variance()) {\n    caffe_gpu_mul(temp_.count(), top_data, top_diff, bottom_diff);\n    caffe_gpu_gemv<Dtype>(CblasNoTrans, num, dim, 1., bottom_diff,\n          sum_multiplier_.gpu_data(), 0., mean_.mutable_gpu_data());\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,\n          mean_.gpu_data(), sum_multiplier_.gpu_data(), 0.,\n          bottom_diff);\n    caffe_gpu_mul(temp_.count(), top_data, bottom_diff, bottom_diff);\n\n    caffe_gpu_gemv<Dtype>(CblasNoTrans, num, dim, 1., top_diff,\n            sum_multiplier_.gpu_data(), 0., mean_.mutable_gpu_data());\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,\n            mean_.gpu_data(), sum_multiplier_.gpu_data(), 1.,\n            bottom_diff);\n\n    caffe_gpu_axpby(temp_.count(), Dtype(1), top_diff, Dtype(-1. / dim),\n        bottom_diff);\n\n    // put the squares of bottom into temp_\n    caffe_gpu_powx(temp_.count(), bottom_data, Dtype(2),\n        temp_.mutable_gpu_data());\n\n    caffe_gpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, num, dim, 1, 1.,\n        variance_.gpu_data(), sum_multiplier_.gpu_data(), 0.,\n        temp_.mutable_gpu_data());\n\n    caffe_gpu_div(temp_.count(), bottom_diff, temp_.gpu_data(), bottom_diff);\n  } else {\n    caffe_copy(temp_.count(), top_diff, bottom_diff);\n  }\n}\n\n\nINSTANTIATE_LAYER_GPU_FUNCS(MVNLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/neuron_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid NeuronLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  top[0]->ReshapeLike(*bottom[0]);\n}\n\nINSTANTIATE_CLASS(NeuronLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/pooling_layer.cpp",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\nusing std::min;\nusing std::max;\n\ntemplate <typename Dtype>\nvoid PoolingLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  PoolingParameter pool_param = this->layer_param_.pooling_param();\n  if (pool_param.global_pooling()) {\n    CHECK(!(pool_param.has_kernel_size() ||\n      pool_param.has_kernel_h() || pool_param.has_kernel_w()))\n      << \"With Global_pooling: true Filter size cannot specified\";\n  } else {\n    CHECK(!pool_param.has_kernel_size() !=\n      !(pool_param.has_kernel_h() && pool_param.has_kernel_w()))\n      << \"Filter size is kernel_size OR kernel_h and kernel_w; not both\";\n    CHECK(pool_param.has_kernel_size() ||\n      (pool_param.has_kernel_h() && pool_param.has_kernel_w()))\n      << \"For non-square filters both kernel_h and kernel_w are required.\";\n  }\n  CHECK((!pool_param.has_pad() && pool_param.has_pad_h()\n      && pool_param.has_pad_w())\n      || (!pool_param.has_pad_h() && !pool_param.has_pad_w()))\n      << \"pad is pad OR pad_h and pad_w are required.\";\n  CHECK((!pool_param.has_stride() && pool_param.has_stride_h()\n      && pool_param.has_stride_w())\n      || (!pool_param.has_stride_h() && !pool_param.has_stride_w()))\n      << \"Stride is stride OR stride_h and stride_w are required.\";\n  global_pooling_ = pool_param.global_pooling();\n  if (global_pooling_) {\n    kernel_h_ = bottom[0]->height();\n    kernel_w_ = bottom[0]->width();\n  } else {\n    if (pool_param.has_kernel_size()) {\n      kernel_h_ = kernel_w_ = pool_param.kernel_size();\n    } else {\n      kernel_h_ = pool_param.kernel_h();\n      kernel_w_ = pool_param.kernel_w();\n    }\n  }\n  CHECK_GT(kernel_h_, 0) << \"Filter dimensions cannot be zero.\";\n  CHECK_GT(kernel_w_, 0) << \"Filter dimensions cannot be zero.\";\n  if (!pool_param.has_pad_h()) {\n    pad_h_ = pad_w_ = pool_param.pad();\n  } else {\n    pad_h_ = pool_param.pad_h();\n    pad_w_ = pool_param.pad_w();\n  }\n  if (!pool_param.has_stride_h()) {\n    stride_h_ = stride_w_ = pool_param.stride();\n  } else {\n    stride_h_ = pool_param.stride_h();\n    stride_w_ = pool_param.stride_w();\n  }\n  if (global_pooling_) {\n    CHECK(pad_h_ == 0 && pad_w_ == 0 && stride_h_ == 1 && stride_w_ == 1)\n      << \"With Global_pooling: true; only pad = 0 and stride = 1\";\n  }\n  if (pad_h_ != 0 || pad_w_ != 0) {\n    CHECK(this->layer_param_.pooling_param().pool()\n        == PoolingParameter_PoolMethod_AVE\n        || this->layer_param_.pooling_param().pool()\n        == PoolingParameter_PoolMethod_MAX)\n        << \"Padding implemented only for average and max pooling.\";\n    CHECK_LT(pad_h_, kernel_h_);\n    CHECK_LT(pad_w_, kernel_w_);\n  }\n}\n\ntemplate <typename Dtype>\nvoid PoolingLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK_EQ(4, bottom[0]->num_axes()) << \"Input must have 4 axes, \"\n      << \"corresponding to (num, channels, height, width)\";\n  channels_ = bottom[0]->channels();\n  height_ = bottom[0]->height();\n  width_ = bottom[0]->width();\n  if (global_pooling_) {\n    kernel_h_ = bottom[0]->height();\n    kernel_w_ = bottom[0]->width();\n  }\n  pooled_height_ = static_cast<int>(ceil(static_cast<float>(\n      height_ + 2 * pad_h_ - kernel_h_) / stride_h_)) + 1;\n  pooled_width_ = static_cast<int>(ceil(static_cast<float>(\n      width_ + 2 * pad_w_ - kernel_w_) / stride_w_)) + 1;\n  if (pad_h_ || pad_w_) {\n    // If we have padding, ensure that the last pooling starts strictly\n    // inside the image (instead of at the padding); otherwise clip the last.\n    if ((pooled_height_ - 1) * stride_h_ >= height_ + pad_h_) {\n      --pooled_height_;\n    }\n    if ((pooled_width_ - 1) * stride_w_ >= width_ + pad_w_) {\n      --pooled_width_;\n    }\n    CHECK_LT((pooled_height_ - 1) * stride_h_, height_ + pad_h_);\n    CHECK_LT((pooled_width_ - 1) * stride_w_, width_ + pad_w_);\n  }\n  top[0]->Reshape(bottom[0]->num(), channels_, pooled_height_,\n      pooled_width_);\n  if (top.size() > 1) {\n    top[1]->ReshapeLike(*top[0]);\n  }\n  // If max pooling, we will initialize the vector index part.\n  if (this->layer_param_.pooling_param().pool() ==\n      PoolingParameter_PoolMethod_MAX && top.size() == 1) {\n    max_idx_.Reshape(bottom[0]->num(), channels_, pooled_height_,\n        pooled_width_);\n  }\n  // If stochastic pooling, we will initialize the random index part.\n  if (this->layer_param_.pooling_param().pool() ==\n      PoolingParameter_PoolMethod_STOCHASTIC) {\n    rand_idx_.Reshape(bottom[0]->num(), channels_, pooled_height_,\n      pooled_width_);\n  }\n}\n\n// TODO(Yangqing): Is there a faster way to do pooling in the channel-first\n// case?\ntemplate <typename Dtype>\nvoid PoolingLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  const int top_count = top[0]->count();\n  // We'll output the mask to top[1] if it's of size >1.\n  const bool use_top_mask = top.size() > 1;\n  int* mask = NULL;  // suppress warnings about uninitalized variables\n  Dtype* top_mask = NULL;\n  // Different pooling methods. We explicitly do the switch outside the for\n  // loop to save time, although this results in more code.\n  switch (this->layer_param_.pooling_param().pool()) {\n  case PoolingParameter_PoolMethod_MAX:\n    // Initialize\n    if (use_top_mask) {\n      top_mask = top[1]->mutable_cpu_data();\n      caffe_set(top_count, Dtype(-1), top_mask);\n    } else {\n      mask = max_idx_.mutable_cpu_data();\n      caffe_set(top_count, -1, mask);\n    }\n    caffe_set(top_count, Dtype(-FLT_MAX), top_data);\n    // The main loop\n    for (int n = 0; n < bottom[0]->num(); ++n) {\n      for (int c = 0; c < channels_; ++c) {\n        for (int ph = 0; ph < pooled_height_; ++ph) {\n          for (int pw = 0; pw < pooled_width_; ++pw) {\n            int hstart = ph * stride_h_ - pad_h_;\n            int wstart = pw * stride_w_ - pad_w_;\n            int hend = min(hstart + kernel_h_, height_);\n            int wend = min(wstart + kernel_w_, width_);\n            hstart = max(hstart, 0);\n            wstart = max(wstart, 0);\n            const int pool_index = ph * pooled_width_ + pw;\n            for (int h = hstart; h < hend; ++h) {\n              for (int w = wstart; w < wend; ++w) {\n                const int index = h * width_ + w;\n                if (bottom_data[index] > top_data[pool_index]) {\n                  top_data[pool_index] = bottom_data[index];\n                  if (use_top_mask) {\n                    top_mask[pool_index] = static_cast<Dtype>(index);\n                  } else {\n                    mask[pool_index] = index;\n                  }\n                }\n              }\n            }\n          }\n        }\n        // compute offset\n        bottom_data += bottom[0]->offset(0, 1);\n        top_data += top[0]->offset(0, 1);\n        if (use_top_mask) {\n          top_mask += top[0]->offset(0, 1);\n        } else {\n          mask += top[0]->offset(0, 1);\n        }\n      }\n    }\n    break;\n  case PoolingParameter_PoolMethod_AVE:\n    for (int i = 0; i < top_count; ++i) {\n      top_data[i] = 0;\n    }\n    // The main loop\n    for (int n = 0; n < bottom[0]->num(); ++n) {\n      for (int c = 0; c < channels_; ++c) {\n        for (int ph = 0; ph < pooled_height_; ++ph) {\n          for (int pw = 0; pw < pooled_width_; ++pw) {\n            int hstart = ph * stride_h_ - pad_h_;\n            int wstart = pw * stride_w_ - pad_w_;\n            int hend = min(hstart + kernel_h_, height_ + pad_h_);\n            int wend = min(wstart + kernel_w_, width_ + pad_w_);\n            int pool_size = (hend - hstart) * (wend - wstart);\n            hstart = max(hstart, 0);\n            wstart = max(wstart, 0);\n            hend = min(hend, height_);\n            wend = min(wend, width_);\n            for (int h = hstart; h < hend; ++h) {\n              for (int w = wstart; w < wend; ++w) {\n                top_data[ph * pooled_width_ + pw] +=\n                    bottom_data[h * width_ + w];\n              }\n            }\n            top_data[ph * pooled_width_ + pw] /= pool_size;\n          }\n        }\n        // compute offset\n        bottom_data += bottom[0]->offset(0, 1);\n        top_data += top[0]->offset(0, 1);\n      }\n    }\n    break;\n  case PoolingParameter_PoolMethod_STOCHASTIC:\n    NOT_IMPLEMENTED;\n    break;\n  default:\n    LOG(FATAL) << \"Unknown pooling method.\";\n  }\n}\n\ntemplate <typename Dtype>\nvoid PoolingLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) {\n    return;\n  }\n  const Dtype* top_diff = top[0]->cpu_diff();\n  Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n  // Different pooling methods. We explicitly do the switch outside the for\n  // loop to save time, although this results in more codes.\n  caffe_set(bottom[0]->count(), Dtype(0), bottom_diff);\n  // We'll output the mask to top[1] if it's of size >1.\n  const bool use_top_mask = top.size() > 1;\n  const int* mask = NULL;  // suppress warnings about uninitialized variables\n  const Dtype* top_mask = NULL;\n  switch (this->layer_param_.pooling_param().pool()) {\n  case PoolingParameter_PoolMethod_MAX:\n    // The main loop\n    if (use_top_mask) {\n      top_mask = top[1]->cpu_data();\n    } else {\n      mask = max_idx_.cpu_data();\n    }\n    for (int n = 0; n < top[0]->num(); ++n) {\n      for (int c = 0; c < channels_; ++c) {\n        for (int ph = 0; ph < pooled_height_; ++ph) {\n          for (int pw = 0; pw < pooled_width_; ++pw) {\n            const int index = ph * pooled_width_ + pw;\n            const int bottom_index =\n                use_top_mask ? top_mask[index] : mask[index];\n            bottom_diff[bottom_index] += top_diff[index];\n          }\n        }\n        bottom_diff += bottom[0]->offset(0, 1);\n        top_diff += top[0]->offset(0, 1);\n        if (use_top_mask) {\n          top_mask += top[0]->offset(0, 1);\n        } else {\n          mask += top[0]->offset(0, 1);\n        }\n      }\n    }\n    break;\n  case PoolingParameter_PoolMethod_AVE:\n    // The main loop\n    for (int n = 0; n < top[0]->num(); ++n) {\n      for (int c = 0; c < channels_; ++c) {\n        for (int ph = 0; ph < pooled_height_; ++ph) {\n          for (int pw = 0; pw < pooled_width_; ++pw) {\n            int hstart = ph * stride_h_ - pad_h_;\n            int wstart = pw * stride_w_ - pad_w_;\n            int hend = min(hstart + kernel_h_, height_ + pad_h_);\n            int wend = min(wstart + kernel_w_, width_ + pad_w_);\n            int pool_size = (hend - hstart) * (wend - wstart);\n            hstart = max(hstart, 0);\n            wstart = max(wstart, 0);\n            hend = min(hend, height_);\n            wend = min(wend, width_);\n            for (int h = hstart; h < hend; ++h) {\n              for (int w = wstart; w < wend; ++w) {\n                bottom_diff[h * width_ + w] +=\n                  top_diff[ph * pooled_width_ + pw] / pool_size;\n              }\n            }\n          }\n        }\n        // offset\n        bottom_diff += bottom[0]->offset(0, 1);\n        top_diff += top[0]->offset(0, 1);\n      }\n    }\n    break;\n  case PoolingParameter_PoolMethod_STOCHASTIC:\n    NOT_IMPLEMENTED;\n    break;\n  default:\n    LOG(FATAL) << \"Unknown pooling method.\";\n  }\n}\n\n\n#ifdef CPU_ONLY\nSTUB_GPU(PoolingLayer);\n#endif\n\nINSTANTIATE_CLASS(PoolingLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/pooling_layer.cu",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void MaxPoolForward(const int nthreads,\n    const Dtype* const bottom_data, const int num, const int channels,\n    const int height, const int width, const int pooled_height,\n    const int pooled_width, const int kernel_h, const int kernel_w,\n    const int stride_h, const int stride_w, const int pad_h, const int pad_w,\n    Dtype* const top_data, int* mask, Dtype* top_mask) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    const int pw = index % pooled_width;\n    const int ph = (index / pooled_width) % pooled_height;\n    const int c = (index / pooled_width / pooled_height) % channels;\n    const int n = index / pooled_width / pooled_height / channels;\n    int hstart = ph * stride_h - pad_h;\n    int wstart = pw * stride_w - pad_w;\n    const int hend = min(hstart + kernel_h, height);\n    const int wend = min(wstart + kernel_w, width);\n    hstart = max(hstart, 0);\n    wstart = max(wstart, 0);\n    Dtype maxval = -FLT_MAX;\n    int maxidx = -1;\n    const Dtype* const bottom_slice =\n        bottom_data + (n * channels + c) * height * width;\n    for (int h = hstart; h < hend; ++h) {\n      for (int w = wstart; w < wend; ++w) {\n        if (bottom_slice[h * width + w] > maxval) {\n          maxidx = h * width + w;\n          maxval = bottom_slice[maxidx];\n        }\n      }\n    }\n    top_data[index] = maxval;\n    if (mask) {\n      mask[index] = maxidx;\n    } else {\n      top_mask[index] = maxidx;\n    }\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void AvePoolForward(const int nthreads,\n    const Dtype* const bottom_data, const int num, const int channels,\n    const int height, const int width, const int pooled_height,\n    const int pooled_width, const int kernel_h, const int kernel_w,\n    const int stride_h, const int stride_w, const int pad_h, const int pad_w,\n    Dtype* const top_data) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    const int pw = index % pooled_width;\n    const int ph = (index / pooled_width) % pooled_height;\n    const int c = (index / pooled_width / pooled_height) % channels;\n    const int n = index / pooled_width / pooled_height / channels;\n    int hstart = ph * stride_h - pad_h;\n    int wstart = pw * stride_w - pad_w;\n    int hend = min(hstart + kernel_h, height + pad_h);\n    int wend = min(wstart + kernel_w, width + pad_w);\n    const int pool_size = (hend - hstart) * (wend - wstart);\n    hstart = max(hstart, 0);\n    wstart = max(wstart, 0);\n    hend = min(hend, height);\n    wend = min(wend, width);\n    Dtype aveval = 0;\n    const Dtype* const bottom_slice =\n        bottom_data + (n * channels + c) * height * width;\n    for (int h = hstart; h < hend; ++h) {\n      for (int w = wstart; w < wend; ++w) {\n        aveval += bottom_slice[h * width + w];\n      }\n    }\n    top_data[index] = aveval / pool_size;\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void StoPoolForwardTrain(const int nthreads,\n    const Dtype* const bottom_data,\n    const int num, const int channels, const int height,\n    const int width, const int pooled_height, const int pooled_width,\n    const int kernel_h, const int kernel_w, const int stride_h,\n    const int stride_w, Dtype* const rand_idx, Dtype* const top_data) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    const int pw = index % pooled_width;\n    const int ph = (index / pooled_width) % pooled_height;\n    const int c = (index / pooled_width / pooled_height) % channels;\n    const int n = index / pooled_width / pooled_height / channels;\n    const int hstart = ph * stride_h;\n    const int hend = min(hstart + kernel_h, height);\n    const int wstart = pw * stride_w;\n    const int wend = min(wstart + kernel_w, width);\n    Dtype cumsum = 0.;\n    const Dtype* const bottom_slice =\n        bottom_data + (n * channels + c) * height * width;\n    // First pass: get sum\n    for (int h = hstart; h < hend; ++h) {\n      for (int w = wstart; w < wend; ++w) {\n        cumsum += bottom_slice[h * width + w];\n      }\n    }\n    const float thres = rand_idx[index] * cumsum;\n    // Second pass: get value, and set index.\n    cumsum = 0;\n    for (int h = hstart; h < hend; ++h) {\n      for (int w = wstart; w < wend; ++w) {\n        cumsum += bottom_slice[h * width + w];\n        if (cumsum >= thres) {\n          rand_idx[index] = ((n * channels + c) * height + h) * width + w;\n          top_data[index] = bottom_slice[h * width + w];\n          return;\n        }\n      }\n    }\n  }\n}\n\n\ntemplate <typename Dtype>\n__global__ void StoPoolForwardTest(const int nthreads,\n    const Dtype* const bottom_data,\n    const int num, const int channels, const int height,\n    const int width, const int pooled_height, const int pooled_width,\n    const int kernel_h, const int kernel_w, const int stride_h,\n    const int stride_w, Dtype* const top_data) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    const int pw = index % pooled_width;\n    const int ph = (index / pooled_width) % pooled_height;\n    const int c = (index / pooled_width / pooled_height) % channels;\n    const int n = index / pooled_width / pooled_height / channels;\n    const int hstart = ph * stride_h;\n    const int hend = min(hstart + kernel_h, height);\n    const int wstart = pw * stride_w;\n    const int wend = min(wstart + kernel_w, width);\n    // We set cumsum to be 0 to avoid divide-by-zero problems\n    Dtype cumsum = FLT_MIN;\n    Dtype cumvalues = 0.;\n    const Dtype* const bottom_slice =\n        bottom_data + (n * channels + c) * height * width;\n    // First pass: get sum\n    for (int h = hstart; h < hend; ++h) {\n      for (int w = wstart; w < wend; ++w) {\n        cumsum += bottom_slice[h * width + w];\n        cumvalues += bottom_slice[h * width + w] * bottom_slice[h * width + w];\n      }\n    }\n    top_data[index] = cumvalues / cumsum;\n  }\n}\n\n\ntemplate <typename Dtype>\nvoid PoolingLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  int count = top[0]->count();\n  // We'll output the mask to top[1] if it's of size >1.\n  const bool use_top_mask = top.size() > 1;\n  int* mask = NULL;\n  Dtype* top_mask = NULL;\n  switch (this->layer_param_.pooling_param().pool()) {\n  case PoolingParameter_PoolMethod_MAX:\n    if (use_top_mask) {\n      top_mask = top[1]->mutable_gpu_data();\n    } else {\n      mask = max_idx_.mutable_gpu_data();\n    }\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    MaxPoolForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, bottom_data, bottom[0]->num(), channels_,\n        height_, width_, pooled_height_, pooled_width_, kernel_h_,\n        kernel_w_, stride_h_, stride_w_, pad_h_, pad_w_, top_data,\n        mask, top_mask);\n    break;\n  case PoolingParameter_PoolMethod_AVE:\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    AvePoolForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, bottom_data, bottom[0]->num(), channels_,\n        height_, width_, pooled_height_, pooled_width_, kernel_h_,\n        kernel_w_, stride_h_, stride_w_, pad_h_, pad_w_, top_data);\n    break;\n  case PoolingParameter_PoolMethod_STOCHASTIC:\n    if (this->phase_ == TRAIN) {\n      // We need to create the random index as well.\n      caffe_gpu_rng_uniform(count, Dtype(0), Dtype(1),\n                            rand_idx_.mutable_gpu_data());\n      // NOLINT_NEXT_LINE(whitespace/operators)\n      StoPoolForwardTrain<Dtype><<<CAFFE_GET_BLOCKS(count),\n                                   CAFFE_CUDA_NUM_THREADS>>>(\n          count, bottom_data, bottom[0]->num(), channels_,\n          height_, width_, pooled_height_, pooled_width_, kernel_h_,\n          kernel_w_, stride_h_, stride_w_,\n          rand_idx_.mutable_gpu_data(), top_data);\n    } else {\n      // NOLINT_NEXT_LINE(whitespace/operators)\n      StoPoolForwardTest<Dtype><<<CAFFE_GET_BLOCKS(count),\n                                  CAFFE_CUDA_NUM_THREADS>>>(\n          count, bottom_data, bottom[0]->num(), channels_,\n          height_, width_, pooled_height_, pooled_width_, kernel_h_,\n          kernel_w_, stride_h_, stride_w_, top_data);\n    }\n    break;\n  default:\n    LOG(FATAL) << \"Unknown pooling method.\";\n  }\n  CUDA_POST_KERNEL_CHECK;\n}\n\n\ntemplate <typename Dtype>\n__global__ void MaxPoolBackward(const int nthreads, const Dtype* const top_diff,\n    const int* const mask, const Dtype* const top_mask, const int num,\n    const int channels, const int height, const int width,\n    const int pooled_height, const int pooled_width, const int kernel_h,\n    const int kernel_w, const int stride_h, const int stride_w, const int pad_h,\n    const int pad_w, Dtype* const bottom_diff) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    // find out the local index\n    // find out the local offset\n    const int w = index % width;\n    const int h = (index / width) % height;\n    const int c = (index / width / height) % channels;\n    const int n = index / width / height / channels;\n    const int phstart =\n         (h + pad_h < kernel_h) ? 0 : (h + pad_h - kernel_h) / stride_h + 1;\n    const int phend = min((h + pad_h) / stride_h + 1, pooled_height);\n    const int pwstart =\n         (w + pad_w < kernel_w) ? 0 : (w + pad_w - kernel_w) / stride_w + 1;\n    const int pwend = min((w + pad_w) / stride_w + 1, pooled_width);\n    Dtype gradient = 0;\n    const int offset = (n * channels + c) * pooled_height * pooled_width;\n    const Dtype* const top_diff_slice = top_diff + offset;\n    if (mask) {\n      const int* const mask_slice = mask + offset;\n      for (int ph = phstart; ph < phend; ++ph) {\n        for (int pw = pwstart; pw < pwend; ++pw) {\n          if (mask_slice[ph * pooled_width + pw] == h * width + w) {\n            gradient += top_diff_slice[ph * pooled_width + pw];\n          }\n        }\n      }\n    } else {\n      const Dtype* const top_mask_slice = top_mask + offset;\n      for (int ph = phstart; ph < phend; ++ph) {\n        for (int pw = pwstart; pw < pwend; ++pw) {\n          if (top_mask_slice[ph * pooled_width + pw] == h * width + w) {\n            gradient += top_diff_slice[ph * pooled_width + pw];\n          }\n        }\n      }\n    }\n    bottom_diff[index] = gradient;\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void AvePoolBackward(const int nthreads, const Dtype* const top_diff,\n    const int num, const int channels, const int height,\n    const int width, const int pooled_height, const int pooled_width,\n    const int kernel_h, const int kernel_w, const int stride_h,\n    const int stride_w, const int pad_h, const int pad_w,\n    Dtype* const bottom_diff) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    // find out the local index\n    // find out the local offset\n    const int w = index % width + pad_w;\n    const int h = (index / width) % height + pad_h;\n    const int c = (index / width / height) % channels;\n    const int n = index / width / height / channels;\n    const int phstart = (h < kernel_h) ? 0 : (h - kernel_h) / stride_h + 1;\n    const int phend = min(h / stride_h + 1, pooled_height);\n    const int pwstart = (w < kernel_w) ? 0 : (w - kernel_w) / stride_w + 1;\n    const int pwend = min(w / stride_w + 1, pooled_width);\n    Dtype gradient = 0;\n    const Dtype* const top_diff_slice =\n        top_diff + (n * channels + c) * pooled_height * pooled_width;\n    for (int ph = phstart; ph < phend; ++ph) {\n      for (int pw = pwstart; pw < pwend; ++pw) {\n        // figure out the pooling size\n        int hstart = ph * stride_h - pad_h;\n        int wstart = pw * stride_w - pad_w;\n        int hend = min(hstart + kernel_h, height + pad_h);\n        int wend = min(wstart + kernel_w, width + pad_w);\n        int pool_size = (hend - hstart) * (wend - wstart);\n        gradient += top_diff_slice[ph * pooled_width + pw] / pool_size;\n      }\n    }\n    bottom_diff[index] = gradient;\n  }\n}\n\n\ntemplate <typename Dtype>\n__global__ void StoPoolBackward(const int nthreads,\n    const Dtype* const rand_idx, const Dtype* const top_diff,\n    const int num, const int channels, const int height,\n    const int width, const int pooled_height, const int pooled_width,\n    const int kernel_h, const int kernel_w, const int stride_h,\n    const int stride_w, Dtype* const bottom_diff) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    // find out the local index\n    // find out the local offset\n    const int w = index % width;\n    const int h = (index / width) % height;\n    const int c = (index / width / height) % channels;\n    const int n = index / width / height / channels;\n    const int phstart = (h < kernel_h) ? 0 : (h - kernel_h) / stride_h + 1;\n    const int phend = min(h / stride_h + 1, pooled_height);\n    const int pwstart = (w < kernel_w) ? 0 : (w - kernel_w) / stride_w + 1;\n    const int pwend = min(w / stride_w + 1, pooled_width);\n    Dtype gradient = 0;\n    const Dtype* const rand_idx_slice =\n        rand_idx + (n * channels + c) * pooled_height * pooled_width;\n    const Dtype* const top_diff_slice =\n        top_diff + (n * channels + c) * pooled_height * pooled_width;\n    for (int ph = phstart; ph < phend; ++ph) {\n      for (int pw = pwstart; pw < pwend; ++pw) {\n        gradient += top_diff_slice[ph * pooled_width + pw] *\n            (index == static_cast<int>(rand_idx_slice[ph * pooled_width + pw]));\n      }\n    }\n    bottom_diff[index] = gradient;\n  }\n}\n\n\ntemplate <typename Dtype>\nvoid PoolingLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) {\n    return;\n  }\n  const Dtype* top_diff = top[0]->gpu_diff();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n  const int count = bottom[0]->count();\n  caffe_gpu_set(count, Dtype(0.), bottom_diff);\n  // We'll output the mask to top[1] if it's of size >1.\n  const bool use_top_mask = top.size() > 1;\n  const int* mask = NULL;\n  const Dtype* top_mask = NULL;\n  switch (this->layer_param_.pooling_param().pool()) {\n  case PoolingParameter_PoolMethod_MAX:\n    if (use_top_mask) {\n      top_mask = top[1]->gpu_data();\n    } else {\n      mask = max_idx_.gpu_data();\n    }\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    MaxPoolBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, top_diff, mask, top_mask, top[0]->num(), channels_,\n        height_, width_, pooled_height_, pooled_width_,\n        kernel_h_, kernel_w_, stride_h_, stride_w_, pad_h_, pad_w_,\n        bottom_diff);\n    break;\n  case PoolingParameter_PoolMethod_AVE:\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    AvePoolBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, top_diff, top[0]->num(), channels_,\n        height_, width_, pooled_height_, pooled_width_, kernel_h_,\n        kernel_w_, stride_h_, stride_w_, pad_h_, pad_w_, bottom_diff);\n    break;\n  case PoolingParameter_PoolMethod_STOCHASTIC:\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    StoPoolBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, rand_idx_.gpu_data(), top_diff,\n        top[0]->num(), channels_, height_, width_, pooled_height_,\n        pooled_width_, kernel_h_, kernel_w_, stride_h_, stride_w_,\n        bottom_diff);\n    break;\n  default:\n    LOG(FATAL) << \"Unknown pooling method.\";\n  }\n  CUDA_POST_KERNEL_CHECK;\n}\n\n\nINSTANTIATE_LAYER_GPU_FUNCS(PoolingLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/power_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid PowerLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  NeuronLayer<Dtype>::LayerSetUp(bottom, top);\n  power_ = this->layer_param_.power_param().power();\n  scale_ = this->layer_param_.power_param().scale();\n  shift_ = this->layer_param_.power_param().shift();\n  diff_scale_ = power_  * scale_;\n}\n\n// Compute y = (shift + scale * x)^power\ntemplate <typename Dtype>\nvoid PowerLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  const int count = bottom[0]->count();\n  // Special case where we can ignore the input: scale or power is 0.\n  if (diff_scale_ == Dtype(0)) {\n    Dtype value = (power_ == 0) ? Dtype(1) : pow(shift_, power_);\n    caffe_set(count, value, top_data);\n    return;\n  }\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  caffe_copy(count, bottom_data, top_data);\n  if (scale_ != Dtype(1)) {\n    caffe_scal(count, scale_, top_data);\n  }\n  if (shift_ != Dtype(0)) {\n    caffe_add_scalar(count, shift_, top_data);\n  }\n  if (power_ != Dtype(1)) {\n    caffe_powx(count, top_data, power_, top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid PowerLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    const int count = bottom[0]->count();\n    const Dtype* top_diff = top[0]->cpu_diff();\n    if (diff_scale_ == Dtype(0) || power_ == Dtype(1)) {\n      caffe_set(count, diff_scale_, bottom_diff);\n    } else {\n      const Dtype* bottom_data = bottom[0]->cpu_data();\n      // Compute dy/dx = scale * power * (shift + scale * x)^(power - 1)\n      //               = diff_scale * y / (shift + scale * x)\n      if (power_ == Dtype(2)) {\n        // Special case for y = (shift + scale * x)^2\n        //     -> dy/dx = 2 * scale * (shift + scale * x)\n        //              = diff_scale * shift + diff_scale * scale * x\n        caffe_cpu_axpby(count, diff_scale_ * scale_, bottom_data,\n            Dtype(0), bottom_diff);\n        if (shift_ != Dtype(0)) {\n          caffe_add_scalar(count, diff_scale_ * shift_, bottom_diff);\n        }\n      } else if (shift_ == Dtype(0)) {\n        // Special case for y = (scale * x)^power\n        //     -> dy/dx = scale * power * (scale * x)^(power - 1)\n        //              = scale * power * (scale * x)^power * (scale * x)^(-1)\n        //              = power * y / x\n        const Dtype* top_data = top[0]->cpu_data();\n        caffe_div(count, top_data, bottom_data, bottom_diff);\n        caffe_scal(count, power_, bottom_diff);\n      } else {\n        caffe_copy(count, bottom_data, bottom_diff);\n        if (scale_ != Dtype(1)) {\n          caffe_scal(count, scale_, bottom_diff);\n        }\n        if (shift_ != Dtype(0)) {\n          caffe_add_scalar(count, shift_, bottom_diff);\n        }\n        const Dtype* top_data = top[0]->cpu_data();\n        caffe_div<Dtype>(count, top_data, bottom_diff, bottom_diff);\n        if (diff_scale_ != Dtype(1)) {\n          caffe_scal(count, diff_scale_, bottom_diff);\n        }\n      }\n    }\n    if (diff_scale_ != Dtype(0)) {\n      caffe_mul(count, top_diff, bottom_diff, bottom_diff);\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(PowerLayer);\n#endif\n\nINSTANTIATE_CLASS(PowerLayer);\nREGISTER_LAYER_CLASS(Power);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/power_layer.cu",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid PowerLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  const int count = bottom[0]->count();\n  // Special case where we can ignore the input: scale or power is 0.\n  if (diff_scale_ == Dtype(0)) {\n    Dtype value = (power_ == 0) ? Dtype(1) : pow(shift_, power_);\n    caffe_gpu_set(count, value, top_data);\n    return;\n  }\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  caffe_copy(count, bottom_data, top_data);\n  if (scale_ != Dtype(1)) {\n    caffe_gpu_scal(count, scale_, top_data);\n  }\n  if (shift_ != Dtype(0)) {\n    caffe_gpu_add_scalar(count, shift_, top_data);\n  }\n  if (power_ != Dtype(1)) {\n    caffe_gpu_powx(count, top_data, power_, top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid PowerLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    const int count = bottom[0]->count();\n    const Dtype* top_diff = top[0]->gpu_diff();\n    if (diff_scale_ == Dtype(0) || power_ == Dtype(1)) {\n      caffe_gpu_set(count, diff_scale_, bottom_diff);\n    } else {\n      const Dtype* bottom_data = bottom[0]->gpu_data();\n      // Compute dy/dx = scale * power * (shift + scale * x)^(power - 1)\n      //               = diff_scale * y / (shift + scale * x)\n      if (power_ == Dtype(2)) {\n        // Special case for y = (shift + scale * x)^2\n        //     -> dy/dx = 2 * scale * (shift + scale * x)\n        //              = diff_scale * shift + diff_scale * scale * x\n        caffe_gpu_axpby(count, diff_scale_ * scale_, bottom_data,\n            Dtype(0), bottom_diff);\n        if (shift_ != Dtype(0)) {\n          caffe_gpu_add_scalar(count, diff_scale_ * shift_, bottom_diff);\n        }\n      } else if (shift_ == Dtype(0)) {\n        // Special case for y = (scale * x)^power\n        //     -> dy/dx = scale * power * (scale * x)^(power - 1)\n        //              = scale * power * (scale * x)^power * (scale * x)^(-1)\n        //              = power * y / x\n        const Dtype* top_data = top[0]->gpu_data();\n        caffe_gpu_div(count, top_data, bottom_data, bottom_diff);\n        caffe_gpu_scal(count, power_, bottom_diff);\n      } else {\n        caffe_copy(count, bottom_data, bottom_diff);\n        if (scale_ != Dtype(1)) {\n          caffe_gpu_scal(count, scale_, bottom_diff);\n        }\n        if (shift_ != Dtype(0)) {\n          caffe_gpu_add_scalar(count, shift_, bottom_diff);\n        }\n        const Dtype* top_data = top[0]->gpu_data();\n        caffe_gpu_div<Dtype>(count, top_data, bottom_diff, bottom_diff);\n        if (diff_scale_ != Dtype(1)) {\n          caffe_gpu_scal(count, diff_scale_, bottom_diff);\n        }\n      }\n    }\n    caffe_gpu_mul(count, top_diff, bottom_diff, bottom_diff);\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(PowerLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/prelu_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/filler.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid PReLULayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  CHECK_GE(bottom[0]->num_axes(), 2)\n      << \"Number of axes of bottom blob must be >=2.\";\n  PReLUParameter prelu_param = this->layer_param().prelu_param();\n  int channels = bottom[0]->channels();\n  channel_shared_ = prelu_param.channel_shared();\n  if (this->blobs_.size() > 0) {\n    LOG(INFO) << \"Skipping parameter initialization\";\n  } else {\n    this->blobs_.resize(1);\n    if (channel_shared_) {\n      this->blobs_[0].reset(new Blob<Dtype>(vector<int>(0)));\n    } else {\n      this->blobs_[0].reset(new Blob<Dtype>(vector<int>(1, channels)));\n    }\n    shared_ptr<Filler<Dtype> > filler;\n    if (prelu_param.has_filler()) {\n      filler.reset(GetFiller<Dtype>(prelu_param.filler()));\n    } else {\n      FillerParameter filler_param;\n      filler_param.set_type(\"constant\");\n      filler_param.set_value(0.25);\n      filler.reset(GetFiller<Dtype>(filler_param));\n    }\n    filler->Fill(this->blobs_[0].get());\n  }\n  if (channel_shared_) {\n    CHECK_EQ(this->blobs_[0]->count(), 1)\n        << \"Negative slope size is inconsistent with prototxt config\";\n  } else {\n    CHECK_EQ(this->blobs_[0]->count(), channels)\n        << \"Negative slope size is inconsistent with prototxt config\";\n  }\n\n  // Propagate gradients to the parameters (as directed by backward pass).\n  this->param_propagate_down_.resize(this->blobs_.size(), true);\n  multiplier_.Reshape(vector<int>(1, bottom[0]->count(1)));\n  backward_buff_.Reshape(vector<int>(1, bottom[0]->count(1)));\n  caffe_set(multiplier_.count(), Dtype(1), multiplier_.mutable_cpu_data());\n}\n\ntemplate <typename Dtype>\nvoid PReLULayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  CHECK_GE(bottom[0]->num_axes(), 2)\n      << \"Number of axes of bottom blob must be >=2.\";\n  top[0]->ReshapeLike(*bottom[0]);\n  if (bottom[0] == top[0]) {\n    // For in-place computation\n    bottom_memory_.ReshapeLike(*bottom[0]);\n  }\n}\n\ntemplate <typename Dtype>\nvoid PReLULayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  const int count = bottom[0]->count();\n  const int dim = bottom[0]->count(2);\n  const int channels = bottom[0]->channels();\n  const Dtype* slope_data = this->blobs_[0]->cpu_data();\n\n  // For in-place computation\n  if (bottom[0] == top[0]) {\n    caffe_copy(count, bottom_data, bottom_memory_.mutable_cpu_data());\n  }\n\n  // if channel_shared, channel index in the following computation becomes\n  // always zero.\n  const int div_factor = channel_shared_ ? channels : 1;\n  for (int i = 0; i < count; ++i) {\n    int c = (i / dim) % channels / div_factor;\n    top_data[i] = std::max(bottom_data[i], Dtype(0))\n        + slope_data[c] * std::min(bottom_data[i], Dtype(0));\n  }\n}\n\ntemplate <typename Dtype>\nvoid PReLULayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  const Dtype* slope_data = this->blobs_[0]->cpu_data();\n  const Dtype* top_diff = top[0]->cpu_diff();\n  const int count = bottom[0]->count();\n  const int dim = bottom[0]->count(2);\n  const int channels = bottom[0]->channels();\n\n  // For in-place computation\n  if (top[0] == bottom[0]) {\n    bottom_data = bottom_memory_.cpu_data();\n  }\n\n  // if channel_shared, channel index in the following computation becomes\n  // always zero.\n  const int div_factor = channel_shared_ ? channels : 1;\n\n  // Propagte to param\n  // Since to write bottom diff will affect top diff if top and bottom blobs\n  // are identical (in-place computaion), we first compute param backward to\n  // keep top_diff unchanged.\n  if (this->param_propagate_down_[0]) {\n    Dtype* slope_diff = this->blobs_[0]->mutable_cpu_diff();\n    for (int i = 0; i < count; ++i) {\n      int c = (i / dim) % channels / div_factor;\n      slope_diff[c] += top_diff[i] * bottom_data[i] * (bottom_data[i] <= 0);\n    }\n  }\n  // Propagate to bottom\n  if (propagate_down[0]) {\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    for (int i = 0; i < count; ++i) {\n      int c = (i / dim) % channels / div_factor;\n      bottom_diff[i] = top_diff[i] * ((bottom_data[i] > 0)\n          + slope_data[c] * (bottom_data[i] <= 0));\n    }\n  }\n}\n\n\n#ifdef CPU_ONLY\nSTUB_GPU(PReLULayer);\n#endif\n\nINSTANTIATE_CLASS(PReLULayer);\nREGISTER_LAYER_CLASS(PReLU);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/prelu_layer.cu",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\n// CUDA kernele for forward\ntemplate <typename Dtype>\n__global__ void PReLUForward(const int n, const int channels, const int dim,\n    const Dtype* in, Dtype* out, const Dtype* slope_data,\n    const int div_factor) {\n  CUDA_KERNEL_LOOP(index, n) {\n    int c = (index / dim) % channels / div_factor;\n    out[index] = in[index] > 0 ? in[index] : in[index] * slope_data[c];\n  }\n}\n\n// CUDA kernel for bottom backward\ntemplate <typename Dtype>\n__global__ void PReLUBackward(const int n, const int channels, const int dim,\n    const Dtype* in_diff, const Dtype* in_data, Dtype* out_diff,\n    const Dtype* slope_data, const int div_factor) {\n  CUDA_KERNEL_LOOP(index, n) {\n    int c = (index / dim) % channels / div_factor;\n    out_diff[index] = in_diff[index] * ((in_data[index] > 0)\n        + (in_data[index] <= 0) * slope_data[c]);\n  }\n}\n\n// CUDA kernel for element-wise parameter backward\ntemplate <typename Dtype>\n__global__ void PReLUParamBackward(const int n, const Dtype* in_diff,\n    const Dtype* in_data, Dtype* out_diff) {\n  CUDA_KERNEL_LOOP(index, n) {\n    out_diff[index] = in_diff[index] * in_data[index] * (in_data[index] <= 0);\n  }\n}\n\ntemplate <typename Dtype>\nvoid PReLULayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  const int count = bottom[0]->count();\n  const int dim = bottom[0]->count(2);\n  const int channels = bottom[0]->channels();\n  const Dtype* slope_data = this->blobs_[0]->gpu_data();\n  const int div_factor = channel_shared_ ? channels : 1;\n\n  // For in-place computation\n  if (top[0] == bottom[0]) {\n    caffe_copy(count, bottom_data, bottom_memory_.mutable_gpu_data());\n  }\n\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  PReLUForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n      count, channels, dim, bottom_data, top_data, slope_data, div_factor);\n  CUDA_POST_KERNEL_CHECK;\n}\n\ntemplate <typename Dtype>\nvoid PReLULayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  const Dtype* top_diff = top[0]->gpu_diff();\n  const int count = bottom[0]->count();\n  const int dim = bottom[0]->count(2);\n  const int channels = bottom[0]->channels();\n\n  // For in-place computation\n  if (top[0] == bottom[0]) {\n    bottom_data = bottom_memory_.gpu_data();\n  }\n\n  // Propagate to param\n  // Since to write bottom diff will affect top diff if top and bottom blobs\n  // are identical (in-place computaion), we first compute param backward to\n  // keep top_diff unchanged.\n  if (this->param_propagate_down_[0]) {\n    Dtype* slope_diff = this->blobs_[0]->mutable_gpu_diff();\n    int cdim = channels * dim;\n    Dtype dsum = 0.;\n    for (int n = 0; n < bottom[0]->num(); ++n) {\n      // compute element-wise diff\n      // NOLINT_NEXT_LINE(whitespace/operators)\n      PReLUParamBackward<Dtype><<<CAFFE_GET_BLOCKS(cdim),\n          CAFFE_CUDA_NUM_THREADS>>>(\n          cdim, top_diff + top[0]->offset(n),\n          bottom_data + bottom[0]->offset(n),\n          backward_buff_.mutable_gpu_diff());\n      CUDA_POST_KERNEL_CHECK;\n      if (channel_shared_) {\n        Dtype d;\n        caffe_gpu_dot<Dtype>(channels * dim, backward_buff_.gpu_diff(),\n            multiplier_.gpu_data(), &d);\n        dsum += d;\n      } else {\n        caffe_gpu_gemv<Dtype>(CblasNoTrans, channels, dim, 1.,\n            backward_buff_.gpu_diff(), multiplier_.gpu_data(), 1.,\n            slope_diff);\n      }\n    }\n    if (channel_shared_) {\n      caffe_gpu_add_scalar(this->blobs_[0]->count(), Dtype(dsum), slope_diff);\n    }\n  }\n  // Propagate to bottom\n  if (propagate_down[0]) {\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    const Dtype* slope_data = this->blobs_[0]->gpu_data();\n    int div_factor = channel_shared_ ? channels : 1;\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    PReLUBackward<Dtype><<<CAFFE_GET_BLOCKS(count),\n        CAFFE_CUDA_NUM_THREADS>>>(\n        count, channels, dim, top_diff, bottom_data, bottom_diff, slope_data,\n        div_factor);\n    CUDA_POST_KERNEL_CHECK;\n  }\n}\n\n\nINSTANTIATE_LAYER_GPU_FUNCS(PReLULayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/reduction_layer.cpp",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ReductionLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  op_ = this->layer_param_.reduction_param().operation();\n}\n\ntemplate <typename Dtype>\nvoid ReductionLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  axis_ = bottom[0]->CanonicalAxisIndex(\n      this->layer_param_.reduction_param().axis());\n  // In the output, we'll keep all axes up to the reduction axis, but\n  // throw away any after that.\n  // Note: currently reducing along non-tail axes is not supported; otherwise,\n  // we'd need to also copy any axes following an \"end_axis\".\n  vector<int> top_shape(bottom[0]->shape().begin(),\n                        bottom[0]->shape().begin() + axis_);\n  top[0]->Reshape(top_shape);\n  num_ = bottom[0]->count(0, axis_);\n  dim_ = bottom[0]->count(axis_);\n  CHECK_EQ(num_, top[0]->count());\n  if (op_ == ReductionParameter_ReductionOp_SUM ||\n      op_ == ReductionParameter_ReductionOp_MEAN) {\n    vector<int> sum_mult_shape(1, dim_);\n    sum_multiplier_.Reshape(sum_mult_shape);\n    caffe_set(dim_, Dtype(1), sum_multiplier_.mutable_cpu_data());\n  }\n  coeff_ = this->layer_param().reduction_param().coeff();\n  if (op_ == ReductionParameter_ReductionOp_MEAN) {\n    coeff_ /= dim_;\n  }\n}\n\ntemplate <typename Dtype>\nvoid ReductionLayer<Dtype>::Forward_cpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  const Dtype* mult_data = NULL;\n  if (sum_multiplier_.count() > 0) {\n    mult_data = sum_multiplier_.cpu_data();\n  }\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  for (int i = 0; i < num_; ++i) {\n    switch (op_) {\n    case ReductionParameter_ReductionOp_SUM:\n    case ReductionParameter_ReductionOp_MEAN:\n      *top_data = caffe_cpu_dot(dim_, mult_data, bottom_data);\n      break;\n    case ReductionParameter_ReductionOp_ASUM:\n      *top_data = caffe_cpu_asum(dim_, bottom_data);\n      break;\n    case ReductionParameter_ReductionOp_SUMSQ:\n      *top_data = caffe_cpu_dot(dim_, bottom_data, bottom_data);\n      break;\n    default:\n      LOG(FATAL) << \"Unknown reduction op: \"\n          << ReductionParameter_ReductionOp_Name(op_);\n    }\n    bottom_data += dim_;\n    ++top_data;\n  }\n  if (coeff_ != Dtype(1)) {\n    // Reset the top_data pointer.\n    top_data = top[0]->mutable_cpu_data();\n    caffe_scal(num_, coeff_, top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid ReductionLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) { return; }\n  // Get bottom_data, if needed.\n  const Dtype* bottom_data = NULL;\n  switch (op_) {\n  // Operations that don't need bottom_data\n  case ReductionParameter_ReductionOp_SUM:\n  case ReductionParameter_ReductionOp_MEAN:\n    break;\n  // Operations that need bottom_data\n  case ReductionParameter_ReductionOp_ASUM:\n  case ReductionParameter_ReductionOp_SUMSQ:\n    bottom_data = bottom[0]->cpu_data();\n    break;\n  default:\n    LOG(FATAL) << \"Unknown reduction op: \"\n        << ReductionParameter_ReductionOp_Name(op_);\n  }\n  const Dtype* top_diff = top[0]->cpu_diff();\n  Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n  for (int i = 0; i < num_; ++i) {\n    const Dtype bottom_coeff = (*top_diff) * coeff_;\n    switch (op_) {\n    case ReductionParameter_ReductionOp_SUM:\n    case ReductionParameter_ReductionOp_MEAN:\n      caffe_set(dim_, bottom_coeff, bottom_diff);\n      break;\n    case ReductionParameter_ReductionOp_ASUM:\n      caffe_cpu_sign(dim_, bottom_data, bottom_diff);\n      caffe_scal(dim_, bottom_coeff, bottom_diff);\n      break;\n    case ReductionParameter_ReductionOp_SUMSQ:\n      caffe_cpu_scale(dim_, 2 * bottom_coeff, bottom_data, bottom_diff);\n      break;\n    default:\n      LOG(FATAL) << \"Unknown reduction op: \"\n          << ReductionParameter_ReductionOp_Name(op_);\n    }\n    bottom_data += dim_;\n    bottom_diff += dim_;\n    ++top_diff;\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(ReductionLayer);\n#endif\n\nINSTANTIATE_CLASS(ReductionLayer);\nREGISTER_LAYER_CLASS(Reduction);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/reduction_layer.cu",
    "content": "#include <cfloat>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ReductionLayer<Dtype>::Forward_gpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  const Dtype* mult_data = NULL;\n  if (sum_multiplier_.count() > 0) {\n    mult_data = sum_multiplier_.gpu_data();\n  }\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  for (int i = 0; i < num_; ++i) {\n    switch (op_) {\n    case ReductionParameter_ReductionOp_SUM:\n    case ReductionParameter_ReductionOp_MEAN:\n      caffe_gpu_dot(dim_, mult_data, bottom_data, top_data);\n      break;\n    case ReductionParameter_ReductionOp_ASUM:\n      caffe_gpu_asum(dim_, bottom_data, top_data);\n      break;\n    case ReductionParameter_ReductionOp_SUMSQ:\n      caffe_gpu_dot(dim_, bottom_data, bottom_data, top_data);\n      break;\n    default:\n      LOG(FATAL) << \"Unknown reduction op: \"\n          << ReductionParameter_ReductionOp_Name(op_);\n    }\n    bottom_data += dim_;\n    ++top_data;\n  }\n  if (coeff_ != Dtype(1)) {\n    // Reset the top_data pointer.\n    top_data = top[0]->mutable_gpu_data();\n    caffe_gpu_scal(num_, coeff_, top_data);\n  }\n}\n\ntemplate <typename Dtype>\nvoid ReductionLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) { return; }\n  // Get bottom_data, if needed.\n  const Dtype* bottom_data = NULL;\n  switch (op_) {\n  // Operations that don't need bottom_data\n  case ReductionParameter_ReductionOp_SUM:\n  case ReductionParameter_ReductionOp_MEAN:\n    break;\n  // Operations that need bottom_data\n  case ReductionParameter_ReductionOp_ASUM:\n  case ReductionParameter_ReductionOp_SUMSQ:\n    bottom_data = bottom[0]->gpu_data();\n    break;\n  default:\n    LOG(FATAL) << \"Unknown reduction op: \"\n        << ReductionParameter_ReductionOp_Name(op_);\n  }\n  const Dtype* top_diff = top[0]->cpu_diff();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n  for (int i = 0; i < num_; ++i) {\n    const Dtype bottom_coeff = (*top_diff) * coeff_;\n    switch (op_) {\n    case ReductionParameter_ReductionOp_SUM:\n    case ReductionParameter_ReductionOp_MEAN:\n      caffe_gpu_set(dim_, bottom_coeff, bottom_diff);\n      break;\n    case ReductionParameter_ReductionOp_ASUM:\n      caffe_gpu_sign(dim_, bottom_data, bottom_diff);\n      caffe_gpu_scal(dim_, bottom_coeff, bottom_diff);\n      break;\n    case ReductionParameter_ReductionOp_SUMSQ:\n      caffe_gpu_scale(dim_, 2 * bottom_coeff, bottom_data, bottom_diff);\n      break;\n    default:\n      LOG(FATAL) << \"Unknown reduction op: \"\n          << ReductionParameter_ReductionOp_Name(op_);\n    }\n    bottom_data += dim_;\n    bottom_diff += dim_;\n    ++top_diff;\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(ReductionLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/relu_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ReLULayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  const int count = bottom[0]->count();\n  Dtype negative_slope = this->layer_param_.relu_param().negative_slope();\n  for (int i = 0; i < count; ++i) {\n    top_data[i] = std::max(bottom_data[i], Dtype(0))\n        + negative_slope * std::min(bottom_data[i], Dtype(0));\n  }\n}\n\ntemplate <typename Dtype>\nvoid ReLULayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* bottom_data = bottom[0]->cpu_data();\n    const Dtype* top_diff = top[0]->cpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    const int count = bottom[0]->count();\n    Dtype negative_slope = this->layer_param_.relu_param().negative_slope();\n    for (int i = 0; i < count; ++i) {\n      bottom_diff[i] = top_diff[i] * ((bottom_data[i] > 0)\n          + negative_slope * (bottom_data[i] <= 0));\n    }\n  }\n}\n\n\n#ifdef CPU_ONLY\nSTUB_GPU(ReLULayer);\n#endif\n\nINSTANTIATE_CLASS(ReLULayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/relu_layer.cu",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void ReLUForward(const int n, const Dtype* in, Dtype* out,\n    Dtype negative_slope) {\n  CUDA_KERNEL_LOOP(index, n) {\n    out[index] = in[index] > 0 ? in[index] : in[index] * negative_slope;\n  }\n}\n\ntemplate <typename Dtype>\nvoid ReLULayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  const int count = bottom[0]->count();\n  Dtype negative_slope = this->layer_param_.relu_param().negative_slope();\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  ReLUForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n      count, bottom_data, top_data, negative_slope);\n  CUDA_POST_KERNEL_CHECK;\n  // << \" count: \" << count << \" bottom_data: \"\n  //     << (unsigned long)bottom_data\n  //     << \" top_data: \" << (unsigned long)top_data\n  //     << \" blocks: \" << CAFFE_GET_BLOCKS(count)\n  //     << \" threads: \" << CAFFE_CUDA_NUM_THREADS;\n}\n\ntemplate <typename Dtype>\n__global__ void ReLUBackward(const int n, const Dtype* in_diff,\n    const Dtype* in_data, Dtype* out_diff, Dtype negative_slope) {\n  CUDA_KERNEL_LOOP(index, n) {\n    out_diff[index] = in_diff[index] * ((in_data[index] > 0)\n        + (in_data[index] <= 0) * negative_slope);\n  }\n}\n\ntemplate <typename Dtype>\nvoid ReLULayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* bottom_data = bottom[0]->gpu_data();\n    const Dtype* top_diff = top[0]->gpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    const int count = bottom[0]->count();\n    Dtype negative_slope = this->layer_param_.relu_param().negative_slope();\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    ReLUBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, top_diff, bottom_data, bottom_diff, negative_slope);\n    CUDA_POST_KERNEL_CHECK;\n  }\n}\n\n\nINSTANTIATE_LAYER_GPU_FUNCS(ReLULayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/reshape_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/common_layers.hpp\"\n#include \"caffe/layer.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ReshapeLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  inferred_axis_ = -1;\n  copy_axes_.clear();\n  const BlobShape& top_blob_shape = this->layer_param_.reshape_param().shape();\n  const int top_num_axes = top_blob_shape.dim_size();\n  constant_count_ = 1;\n  for (int i = 0; i < top_num_axes; ++i) {\n    const int top_dim = top_blob_shape.dim(i);\n    if (top_dim == 0) {\n      copy_axes_.push_back(i);\n    } else if (top_dim == -1) {\n      CHECK_EQ(inferred_axis_, -1) << \"new shape contains multiple \"\n          << \"-1 dims; at most a single (1) value of -1 may be specified\";\n      inferred_axis_ = i;\n    } else {\n      constant_count_ *= top_dim;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid ReshapeLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const int input_start_axis = this->layer_param_.reshape_param().axis();\n  const int start_axis = (input_start_axis >= 0) ? input_start_axis :\n      bottom[0]->num_axes() + input_start_axis + 1;\n  CHECK_GE(start_axis, 0) << \"axis \" << input_start_axis << \" out of range\";\n  CHECK_LE(start_axis, bottom[0]->num_axes()) << \"axis \" << input_start_axis\n      << \" out of range for \" << bottom[0]->num_axes() << \"-D input blob\";\n  const int num_axes = this->layer_param_.reshape_param().num_axes();\n  CHECK_GE(num_axes, -1) << \"num_axes must be >= 0, or -1 for all\";\n  const int end_axis =\n      (num_axes == -1) ? bottom[0]->num_axes() : (start_axis + num_axes);\n  CHECK_LE(end_axis, bottom[0]->num_axes())\n      << \"end_axis = axis + num_axes is out of range\";\n  const int num_axes_replaced = end_axis - start_axis;\n  const int num_axes_retained = bottom[0]->num_axes() - num_axes_replaced;\n  const BlobShape& top_blob_shape = this->layer_param_.reshape_param().shape();\n  const int num_new_axes = top_blob_shape.dim_size();\n  vector<int> top_shape(num_axes_retained + num_new_axes);\n  int top_shape_index = 0;\n  for (int i = 0; i < start_axis; ++i) {\n    top_shape[top_shape_index++] = bottom[0]->shape(i);\n  }\n  for (int i = 0; i < num_new_axes; ++i) {\n    top_shape[top_shape_index++] = top_blob_shape.dim(i);\n  }\n  for (int i = end_axis; i < bottom[0]->num_axes(); ++i) {\n    top_shape[top_shape_index++] = bottom[0]->shape(i);\n  }\n  CHECK_EQ(top_shape_index, top_shape.size());\n  for (int i = 0; i < copy_axes_.size(); ++i) {\n    const int copy_axis_index = copy_axes_[i];\n    CHECK_GT(bottom[0]->num_axes(), start_axis + copy_axis_index)\n        << \"new shape contains a 0, but there was no corresponding bottom axis \"\n        << \"to copy\";\n    top_shape[start_axis + copy_axis_index] =\n        bottom[0]->shape(start_axis + copy_axis_index);\n  }\n  if (inferred_axis_ >= 0) {\n    // A -1 dim was specified; infer the correct dimension by computing the\n    // product of the other dimensions.\n    int explicit_count = constant_count_;\n    explicit_count *= bottom[0]->count(0, start_axis);\n    explicit_count *= bottom[0]->count(end_axis);\n    for (int i = 0; i < copy_axes_.size(); ++i) {\n      const int copy_axis_index = copy_axes_[i];\n      explicit_count *= top_shape[start_axis + copy_axis_index];\n    }\n    CHECK_EQ(0, bottom[0]->count() % explicit_count) << \"bottom count (\"\n        << bottom[0]->count() << \") must be divisible by the product of \"\n        << \"the specified dimensions (\" << explicit_count << \")\";\n    const int inferred_dim = bottom[0]->count() / explicit_count;\n    top_shape[start_axis + inferred_axis_] = inferred_dim;\n  }\n  top[0]->Reshape(top_shape);\n  CHECK_EQ(top[0]->count(), bottom[0]->count())\n      << \"output count must match input count\";\n  top[0]->ShareData(*bottom[0]);\n  top[0]->ShareDiff(*bottom[0]);\n}\n\nINSTANTIATE_CLASS(ReshapeLayer);\nREGISTER_LAYER_CLASS(Reshape);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/sigmoid_cross_entropy_loss_layer.cpp",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid SigmoidCrossEntropyLossLayer<Dtype>::LayerSetUp(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  LossLayer<Dtype>::LayerSetUp(bottom, top);\n  sigmoid_bottom_vec_.clear();\n  sigmoid_bottom_vec_.push_back(bottom[0]);\n  sigmoid_top_vec_.clear();\n  sigmoid_top_vec_.push_back(sigmoid_output_.get());\n  sigmoid_layer_->SetUp(sigmoid_bottom_vec_, sigmoid_top_vec_);\n}\n\ntemplate <typename Dtype>\nvoid SigmoidCrossEntropyLossLayer<Dtype>::Reshape(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  LossLayer<Dtype>::Reshape(bottom, top);\n  CHECK_EQ(bottom[0]->count(), bottom[1]->count()) <<\n      \"SIGMOID_CROSS_ENTROPY_LOSS layer inputs must have the same count.\";\n  sigmoid_layer_->Reshape(sigmoid_bottom_vec_, sigmoid_top_vec_);\n}\n\ntemplate <typename Dtype>\nvoid SigmoidCrossEntropyLossLayer<Dtype>::Forward_cpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  // The forward pass computes the sigmoid outputs.\n  sigmoid_bottom_vec_[0] = bottom[0];\n  sigmoid_layer_->Forward(sigmoid_bottom_vec_, sigmoid_top_vec_);\n  // Compute the loss (negative log likelihood)\n  const int count = bottom[0]->count();\n  const int num = bottom[0]->num();\n  // Stable version of loss computation from input data\n  const Dtype* input_data = bottom[0]->cpu_data();\n  const Dtype* target = bottom[1]->cpu_data();\n  Dtype loss = 0;\n  for (int i = 0; i < count; ++i) {\n    loss -= input_data[i] * (target[i] - (input_data[i] >= 0)) -\n        log(1 + exp(input_data[i] - 2 * input_data[i] * (input_data[i] >= 0)));\n  }\n  top[0]->mutable_cpu_data()[0] = loss / num;\n}\n\ntemplate <typename Dtype>\nvoid SigmoidCrossEntropyLossLayer<Dtype>::Backward_cpu(\n    const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[1]) {\n    LOG(FATAL) << this->type()\n               << \" Layer cannot backpropagate to label inputs.\";\n  }\n  if (propagate_down[0]) {\n    // First, compute the diff\n    const int count = bottom[0]->count();\n    const int num = bottom[0]->num();\n    const Dtype* sigmoid_output_data = sigmoid_output_->cpu_data();\n    const Dtype* target = bottom[1]->cpu_data();\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    caffe_sub(count, sigmoid_output_data, target, bottom_diff);\n    // Scale down gradient\n    const Dtype loss_weight = top[0]->cpu_diff()[0];\n    caffe_scal(count, loss_weight / num, bottom_diff);\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU_BACKWARD(SigmoidCrossEntropyLossLayer, Backward);\n#endif\n\nINSTANTIATE_CLASS(SigmoidCrossEntropyLossLayer);\nREGISTER_LAYER_CLASS(SigmoidCrossEntropyLoss);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/sigmoid_cross_entropy_loss_layer.cu",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid SigmoidCrossEntropyLossLayer<Dtype>::Backward_gpu(\n    const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[1]) {\n    LOG(FATAL) << this->type()\n               << \" Layer cannot backpropagate to label inputs.\";\n  }\n  if (propagate_down[0]) {\n    // First, compute the diff\n    const int count = bottom[0]->count();\n    const int num = bottom[0]->num();\n    const Dtype* sigmoid_output_data = sigmoid_output_->gpu_data();\n    const Dtype* target = bottom[1]->gpu_data();\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    caffe_copy(count, sigmoid_output_data, bottom_diff);\n    caffe_gpu_axpy(count, Dtype(-1), target, bottom_diff);\n    // Scale down gradient\n    const Dtype loss_weight = top[0]->cpu_diff()[0];\n    caffe_gpu_scal(count, loss_weight / num, bottom_diff);\n  }\n}\n\nINSTANTIATE_LAYER_GPU_BACKWARD(SigmoidCrossEntropyLossLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/sigmoid_layer.cpp",
    "content": "#include <algorithm>\n#include <cmath>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\ninline Dtype sigmoid(Dtype x) {\n  return 1. / (1. + exp(-x));\n}\n\ntemplate <typename Dtype>\nvoid SigmoidLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  const int count = bottom[0]->count();\n  for (int i = 0; i < count; ++i) {\n    top_data[i] = sigmoid(bottom_data[i]);\n  }\n}\n\ntemplate <typename Dtype>\nvoid SigmoidLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* top_data = top[0]->cpu_data();\n    const Dtype* top_diff = top[0]->cpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    const int count = bottom[0]->count();\n    for (int i = 0; i < count; ++i) {\n      const Dtype sigmoid_x = top_data[i];\n      bottom_diff[i] = top_diff[i] * sigmoid_x * (1. - sigmoid_x);\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(SigmoidLayer);\n#endif\n\nINSTANTIATE_CLASS(SigmoidLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/sigmoid_layer.cu",
    "content": "#include <algorithm>\n#include <cmath>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void SigmoidForward(const int n, const Dtype* in, Dtype* out) {\n  CUDA_KERNEL_LOOP(index, n) {\n    out[index] = 1. / (1. + exp(-in[index]));\n  }\n}\n\ntemplate <typename Dtype>\nvoid SigmoidLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  const int count = bottom[0]->count();\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  SigmoidForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n      count, bottom_data, top_data);\n  CUDA_POST_KERNEL_CHECK;\n  // << \" count: \" << count << \" bottom_data: \"\n  //     << (unsigned long)bottom_data\n  //     << \" top_data: \" << (unsigned long)top_data\n  //     << \" blocks: \" << CAFFE_GET_BLOCKS(count)\n  //     << \" threads: \" << CAFFE_CUDA_NUM_THREADS;\n}\n\ntemplate <typename Dtype>\n__global__ void SigmoidBackward(const int n, const Dtype* in_diff,\n    const Dtype* out_data, Dtype* out_diff) {\n  CUDA_KERNEL_LOOP(index, n) {\n    const Dtype sigmoid_x = out_data[index];\n    out_diff[index] = in_diff[index] * sigmoid_x * (1 - sigmoid_x);\n  }\n}\n\ntemplate <typename Dtype>\nvoid SigmoidLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* top_data = top[0]->gpu_data();\n    const Dtype* top_diff = top[0]->gpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    const int count = bottom[0]->count();\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    SigmoidBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, top_diff, top_data, bottom_diff);\n    CUDA_POST_KERNEL_CHECK;\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(SigmoidLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/silence_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/common_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid SilenceLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  for (int i = 0; i < bottom.size(); ++i) {\n    if (propagate_down[i]) {\n      caffe_set(bottom[i]->count(), Dtype(0),\n                bottom[i]->mutable_cpu_data());\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(SilenceLayer);\n#endif\n\nINSTANTIATE_CLASS(SilenceLayer);\nREGISTER_LAYER_CLASS(Silence);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/silence_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/common_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid SilenceLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  // Do nothing.\n}\n\ntemplate <typename Dtype>\nvoid SilenceLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  for (int i = 0; i < bottom.size(); ++i) {\n    if (propagate_down[i]) {\n      caffe_gpu_set(bottom[i]->count(), Dtype(0),\n                    bottom[i]->mutable_gpu_data());\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(SilenceLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/slice_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid SliceLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const SliceParameter& slice_param = this->layer_param_.slice_param();\n  CHECK(!(slice_param.has_axis() && slice_param.has_slice_dim()))\n      << \"Either axis or slice_dim should be specified; not both.\";\n  slice_point_.clear();\n  std::copy(slice_param.slice_point().begin(),\n      slice_param.slice_point().end(),\n      std::back_inserter(slice_point_));\n}\n\ntemplate <typename Dtype>\nvoid SliceLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  const int num_axes = bottom[0]->num_axes();\n  const SliceParameter& slice_param = this->layer_param_.slice_param();\n  if (slice_param.has_slice_dim()) {\n    slice_axis_ = static_cast<int>(slice_param.slice_dim());\n    // Don't allow negative indexing for slice_dim, a uint32 -- almost\n    // certainly unintended.\n    CHECK_GE(slice_axis_, 0) << \"casting slice_dim from uint32 to int32 \"\n        << \"produced negative result; slice_dim must satisfy \"\n        << \"0 <= slice_dim < \" << kMaxBlobAxes;\n    CHECK_LT(slice_axis_, num_axes) << \"slice_dim out of range.\";\n  } else {\n    slice_axis_ = bottom[0]->CanonicalAxisIndex(slice_param.axis());\n  }\n  vector<int> top_shape = bottom[0]->shape();\n  const int bottom_slice_axis = bottom[0]->shape(slice_axis_);\n  num_slices_ = bottom[0]->count(0, slice_axis_);\n  slice_size_ = bottom[0]->count(slice_axis_ + 1);\n  int count = 0;\n  if (slice_point_.size() != 0) {\n    CHECK_EQ(slice_point_.size(), top.size() - 1);\n    CHECK_LE(top.size(), bottom_slice_axis);\n    int prev = 0;\n    vector<int> slices;\n    for (int i = 0; i < slice_point_.size(); ++i) {\n      CHECK_GT(slice_point_[i], prev);\n      slices.push_back(slice_point_[i] - prev);\n      prev = slice_point_[i];\n    }\n    slices.push_back(bottom_slice_axis - prev);\n    for (int i = 0; i < top.size(); ++i) {\n      top_shape[slice_axis_] = slices[i];\n      top[i]->Reshape(top_shape);\n      count += top[i]->count();\n    }\n  } else {\n    CHECK_EQ(bottom_slice_axis % top.size(), 0)\n        << \"Number of top blobs (\" << top.size() << \") should evenly \"\n        << \"divide input slice axis (\" << bottom_slice_axis << \")\";\n    top_shape[slice_axis_] = bottom_slice_axis / top.size();\n    for (int i = 0; i < top.size(); ++i) {\n      top[i]->Reshape(top_shape);\n      count += top[i]->count();\n    }\n  }\n  CHECK_EQ(count, bottom[0]->count());\n}\n\ntemplate <typename Dtype>\nvoid SliceLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  int offset_slice_axis = 0;\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  const int bottom_slice_axis = bottom[0]->shape(slice_axis_);\n  for (int i = 0; i < top.size(); ++i) {\n    Dtype* top_data = top[i]->mutable_cpu_data();\n    const int top_slice_axis = top[i]->shape(slice_axis_);\n    for (int n = 0; n < num_slices_; ++n) {\n      const int top_offset = n * top_slice_axis * slice_size_;\n      const int bottom_offset =\n          (n * bottom_slice_axis + offset_slice_axis) * slice_size_;\n      caffe_copy(top_slice_axis * slice_size_,\n          bottom_data + bottom_offset, top_data + top_offset);\n    }\n    offset_slice_axis += top_slice_axis;\n  }\n}\n\ntemplate <typename Dtype>\nvoid SliceLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) { return; }\n  int offset_slice_axis = 0;\n  Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n  const int bottom_slice_axis = bottom[0]->shape(slice_axis_);\n  for (int i = 0; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->cpu_diff();\n    const int top_slice_axis = top[i]->shape(slice_axis_);\n    for (int n = 0; n < num_slices_; ++n) {\n      const int top_offset = n * top_slice_axis * slice_size_;\n      const int bottom_offset =\n          (n * bottom_slice_axis + offset_slice_axis) * slice_size_;\n      caffe_copy(top_slice_axis * slice_size_,\n          top_diff + top_offset, bottom_diff + bottom_offset);\n    }\n    offset_slice_axis += top_slice_axis;\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(SliceLayer);\n#endif\n\nINSTANTIATE_CLASS(SliceLayer);\nREGISTER_LAYER_CLASS(Slice);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/slice_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void Slice(const int nthreads, const Dtype* in_data,\n    const bool forward, const int num_slices, const int slice_size,\n    const int bottom_slice_axis, const int top_slice_axis,\n    const int offset_slice_axis, Dtype* out_data) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    const int total_slice_size = slice_size * top_slice_axis;\n    const int slice_num = index / total_slice_size;\n    const int slice_index = index % total_slice_size;\n    const int bottom_index = slice_index +\n        (slice_num * bottom_slice_axis + offset_slice_axis) * slice_size;\n    if (forward) {\n      out_data[index] = in_data[bottom_index];\n    } else {\n      out_data[bottom_index] = in_data[index];\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid SliceLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  int offset_slice_axis = 0;\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  const int bottom_slice_axis = bottom[0]->shape(slice_axis_);\n  const bool kForward = true;\n  for (int i = 0; i < top.size(); ++i) {\n    Dtype* top_data = top[i]->mutable_gpu_data();\n    const int top_slice_axis = top[i]->shape(slice_axis_);\n    const int top_slice_size = top_slice_axis * slice_size_;\n    const int nthreads = top_slice_size * num_slices_;\n    Slice<Dtype>  // NOLINT_NEXT_LINE(whitespace/operators)\n        <<<CAFFE_GET_BLOCKS(nthreads), CAFFE_CUDA_NUM_THREADS>>>(\n        nthreads, bottom_data, kForward, num_slices_, slice_size_,\n        bottom_slice_axis, top_slice_axis, offset_slice_axis, top_data);\n    offset_slice_axis += top_slice_axis;\n  }\n}\n\ntemplate <typename Dtype>\nvoid SliceLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) { return; }\n  int offset_slice_axis = 0;\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n  const int bottom_slice_axis = bottom[0]->shape(slice_axis_);\n  const bool kForward = false;\n  for (int i = 0; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->gpu_diff();\n    const int top_slice_axis = top[i]->shape(slice_axis_);\n    const int top_slice_size = top_slice_axis * slice_size_;\n    const int nthreads = top_slice_size * num_slices_;\n    Slice<Dtype>  // NOLINT_NEXT_LINE(whitespace/operators)\n        <<<CAFFE_GET_BLOCKS(nthreads), CAFFE_CUDA_NUM_THREADS>>>(\n        nthreads, top_diff, kForward, num_slices_, slice_size_,\n        bottom_slice_axis, top_slice_axis, offset_slice_axis, bottom_diff);\n    offset_slice_axis += top_slice_axis;\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(SliceLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/softmax_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid SoftmaxLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  softmax_axis_ =\n      bottom[0]->CanonicalAxisIndex(this->layer_param_.softmax_param().axis());\n  top[0]->ReshapeLike(*bottom[0]);\n  vector<int> mult_dims(1, bottom[0]->shape(softmax_axis_));\n  sum_multiplier_.Reshape(mult_dims);\n  Dtype* multiplier_data = sum_multiplier_.mutable_cpu_data();\n  caffe_set(sum_multiplier_.count(), Dtype(1), multiplier_data);\n  outer_num_ = bottom[0]->count(0, softmax_axis_);\n  inner_num_ = bottom[0]->count(softmax_axis_ + 1);\n  vector<int> scale_dims = bottom[0]->shape();\n  scale_dims[softmax_axis_] = 1;\n  scale_.Reshape(scale_dims);\n}\n\ntemplate <typename Dtype>\nvoid SoftmaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  Dtype* scale_data = scale_.mutable_cpu_data();\n  int channels = bottom[0]->shape(softmax_axis_);\n  int dim = bottom[0]->count() / outer_num_;\n  caffe_copy(bottom[0]->count(), bottom_data, top_data);\n  // We need to subtract the max to avoid numerical issues, compute the exp,\n  // and then normalize.\n  for (int i = 0; i < outer_num_; ++i) {\n    // initialize scale_data to the first plane\n    caffe_copy(inner_num_, bottom_data + i * dim, scale_data);\n    for (int j = 0; j < channels; j++) {\n      for (int k = 0; k < inner_num_; k++) {\n        scale_data[k] = std::max(scale_data[k],\n            bottom_data[i * dim + j * inner_num_ + k]);\n      }\n    }\n    // subtraction\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, channels, inner_num_,\n        1, -1., sum_multiplier_.cpu_data(), scale_data, 1., top_data);\n    // exponentiation\n    caffe_exp<Dtype>(dim, top_data, top_data);\n    // sum after exp\n    caffe_cpu_gemv<Dtype>(CblasTrans, channels, inner_num_, 1.,\n        top_data, sum_multiplier_.cpu_data(), 0., scale_data);\n    // division\n    for (int j = 0; j < channels; j++) {\n      caffe_div(inner_num_, top_data, scale_data, top_data);\n      top_data += inner_num_;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid SoftmaxLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->cpu_diff();\n  const Dtype* top_data = top[0]->cpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n  Dtype* scale_data = scale_.mutable_cpu_data();\n  int channels = top[0]->shape(softmax_axis_);\n  int dim = top[0]->count() / outer_num_;\n  caffe_copy(top[0]->count(), top_diff, bottom_diff);\n  for (int i = 0; i < outer_num_; ++i) {\n    // compute dot(top_diff, top_data) and subtract them from the bottom diff\n    for (int k = 0; k < inner_num_; ++k) {\n      scale_data[k] = caffe_cpu_strided_dot<Dtype>(channels,\n          bottom_diff + i * dim + k, inner_num_,\n          top_data + i * dim + k, inner_num_);\n    }\n    // subtraction\n    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, channels, inner_num_, 1,\n        -1., sum_multiplier_.cpu_data(), scale_data, 1., bottom_diff + i * dim);\n  }\n  // elementwise multiplication\n  caffe_mul(top[0]->count(), bottom_diff, top_data, bottom_diff);\n}\n\n\n#ifdef CPU_ONLY\nSTUB_GPU(SoftmaxLayer);\n#endif\n\nINSTANTIATE_CLASS(SoftmaxLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/softmax_layer.cu",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"thrust/device_vector.h\"\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void kernel_channel_max(const int num, const int channels,\n    const int spatial_dim, const Dtype* data, Dtype* out) {\n  CUDA_KERNEL_LOOP(index, num * spatial_dim) {\n    int n = index / spatial_dim;\n    int s = index % spatial_dim;\n    Dtype maxval = -FLT_MAX;\n    for (int c = 0; c < channels; ++c) {\n      maxval = max(data[(n * channels + c) * spatial_dim + s], maxval);\n    }\n    out[index] = maxval;\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void kernel_channel_subtract(const int count,\n    const int num, const int channels,\n    const int spatial_dim, const Dtype* channel_max, Dtype* data) {\n  CUDA_KERNEL_LOOP(index, count) {\n    int n = index / channels / spatial_dim;\n    int s = index % spatial_dim;\n    data[index] -= channel_max[n * spatial_dim + s];\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void kernel_exp(const int count, const Dtype* data, Dtype* out) {\n  CUDA_KERNEL_LOOP(index, count) {\n    out[index] = exp(data[index]);\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void kernel_channel_sum(const int num, const int channels,\n    const int spatial_dim, const Dtype* data, Dtype* channel_sum) {\n  CUDA_KERNEL_LOOP(index, num * spatial_dim) {\n    int n = index / spatial_dim;\n    int s = index % spatial_dim;\n    Dtype sum = 0;\n    for (int c = 0; c < channels; ++c) {\n      sum += data[(n * channels + c) * spatial_dim + s];\n    }\n    channel_sum[index] = sum;\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void kernel_channel_div(const int count,\n    const int num, const int channels,\n    const int spatial_dim, const Dtype* channel_sum, Dtype* data) {\n  CUDA_KERNEL_LOOP(index, count) {\n    int n = index / channels / spatial_dim;\n    int s = index % spatial_dim;\n    data[index] /= channel_sum[n * spatial_dim + s];\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void kernel_channel_dot(const int num, const int channels,\n    const int spatial_dim, const Dtype* data_1, const Dtype* data_2,\n    Dtype* channel_dot) {\n  CUDA_KERNEL_LOOP(index, num * spatial_dim) {\n    int n = index / spatial_dim;\n    int s = index % spatial_dim;\n    Dtype dot = 0;\n    for (int c = 0; c < channels; ++c) {\n      dot += (data_1[(n * channels + c) * spatial_dim + s]\n          * data_2[(n * channels + c) * spatial_dim + s]);\n    }\n    channel_dot[index] = dot;\n  }\n}\n\ntemplate <typename Dtype>\nvoid SoftmaxLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  Dtype* scale_data = scale_.mutable_gpu_data();\n  int count = bottom[0]->count();\n  int channels = top[0]->shape(softmax_axis_);\n  caffe_copy(count, bottom_data, top_data);\n  // We need to subtract the max to avoid numerical issues, compute the exp,\n  // and then normalize.\n  // compute max\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  kernel_channel_max<Dtype><<<CAFFE_GET_BLOCKS(outer_num_ * inner_num_),\n      CAFFE_CUDA_NUM_THREADS>>>(outer_num_, channels, inner_num_, top_data,\n      scale_data);\n  // subtract\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  kernel_channel_subtract<Dtype><<<CAFFE_GET_BLOCKS(count),\n      CAFFE_CUDA_NUM_THREADS>>>(count, outer_num_, channels, inner_num_,\n      scale_data, top_data);\n  // exponentiate\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  kernel_exp<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n      count, top_data, top_data);\n  // sum after exp\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  kernel_channel_sum<Dtype><<<CAFFE_GET_BLOCKS(outer_num_ * inner_num_),\n      CAFFE_CUDA_NUM_THREADS>>>(outer_num_, channels, inner_num_, top_data,\n      scale_data);\n  // divide\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  kernel_channel_div<Dtype><<<CAFFE_GET_BLOCKS(count),\n      CAFFE_CUDA_NUM_THREADS>>>(count, outer_num_, channels, inner_num_,\n      scale_data, top_data);\n}\n\ntemplate <typename Dtype>\nvoid SoftmaxLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  const Dtype* top_diff = top[0]->gpu_diff();\n  const Dtype* top_data = top[0]->gpu_data();\n  Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n  Dtype* scale_data = scale_.mutable_gpu_data();\n  int count = top[0]->count();\n  int channels = top[0]->shape(softmax_axis_);\n  caffe_copy(count, top_diff, bottom_diff);\n  // Compute inner1d(top_diff, top_data) and subtract them from the bottom diff.\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  kernel_channel_dot<Dtype><<<CAFFE_GET_BLOCKS(outer_num_ * inner_num_),\n      CAFFE_CUDA_NUM_THREADS>>>(outer_num_, channels, inner_num_,\n      top_diff, top_data, scale_data);\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  kernel_channel_subtract<Dtype><<<CAFFE_GET_BLOCKS(count),\n      CAFFE_CUDA_NUM_THREADS>>>(count, outer_num_, channels, inner_num_,\n      scale_data, bottom_diff);\n  // elementwise multiplication\n  caffe_gpu_mul<Dtype>(top[0]->count(), bottom_diff, top_data, bottom_diff);\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(SoftmaxLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/softmax_loss_layer.cpp",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/layer_factory.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid SoftmaxWithLossLayer<Dtype>::LayerSetUp(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  LossLayer<Dtype>::LayerSetUp(bottom, top);\n  LayerParameter softmax_param(this->layer_param_);\n  softmax_param.set_type(\"Softmax\");\n  softmax_layer_ = LayerRegistry<Dtype>::CreateLayer(softmax_param);\n  softmax_bottom_vec_.clear();\n  softmax_bottom_vec_.push_back(bottom[0]);\n  softmax_top_vec_.clear();\n  softmax_top_vec_.push_back(&prob_);\n  softmax_layer_->SetUp(softmax_bottom_vec_, softmax_top_vec_);\n\n  has_ignore_label_ =\n    this->layer_param_.loss_param().has_ignore_label();\n  if (has_ignore_label_) {\n    ignore_label_ = this->layer_param_.loss_param().ignore_label();\n  }\n  normalize_ = this->layer_param_.loss_param().normalize();\n}\n\ntemplate <typename Dtype>\nvoid SoftmaxWithLossLayer<Dtype>::Reshape(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  LossLayer<Dtype>::Reshape(bottom, top);\n  softmax_layer_->Reshape(softmax_bottom_vec_, softmax_top_vec_);\n  softmax_axis_ =\n      bottom[0]->CanonicalAxisIndex(this->layer_param_.softmax_param().axis());\n  outer_num_ = bottom[0]->count(0, softmax_axis_);\n  inner_num_ = bottom[0]->count(softmax_axis_ + 1);\n  CHECK_EQ(outer_num_ * inner_num_, bottom[1]->count())\n      << \"Number of labels must match number of predictions; \"\n      << \"e.g., if softmax axis == 1 and prediction shape is (N, C, H, W), \"\n      << \"label count (number of labels) must be N*H*W, \"\n      << \"with integer values in {0, 1, ..., C-1}.\";\n  if (top.size() >= 2) {\n    // softmax output\n    top[1]->ReshapeLike(*bottom[0]);\n  }\n}\n\ntemplate <typename Dtype>\nvoid SoftmaxWithLossLayer<Dtype>::Forward_cpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  // The forward pass computes the softmax prob values.\n  softmax_layer_->Forward(softmax_bottom_vec_, softmax_top_vec_);\n  const Dtype* prob_data = prob_.cpu_data();\n  const Dtype* label = bottom[1]->cpu_data();\n  int dim = prob_.count() / outer_num_;\n  int count = 0;\n  Dtype loss = 0;\n  for (int i = 0; i < outer_num_; ++i) {\n    for (int j = 0; j < inner_num_; j++) {\n      const int label_value = static_cast<int>(label[i * inner_num_ + j]);\n      if (has_ignore_label_ && label_value == ignore_label_) {\n        continue;\n      }\n      DCHECK_GE(label_value, 0);\n      DCHECK_LT(label_value, prob_.shape(softmax_axis_));\n      loss -= log(std::max(prob_data[i * dim + label_value * inner_num_ + j],\n                           Dtype(FLT_MIN)));\n      ++count;\n    }\n  }\n  if (normalize_) {\n    top[0]->mutable_cpu_data()[0] = loss / count;\n  } else {\n    top[0]->mutable_cpu_data()[0] = loss / outer_num_;\n  }\n  if (top.size() == 2) {\n    top[1]->ShareData(prob_);\n  }\n}\n\ntemplate <typename Dtype>\nvoid SoftmaxWithLossLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[1]) {\n    LOG(FATAL) << this->type()\n               << \" Layer cannot backpropagate to label inputs.\";\n  }\n  if (propagate_down[0]) {\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    const Dtype* prob_data = prob_.cpu_data();\n    caffe_copy(prob_.count(), prob_data, bottom_diff);\n    const Dtype* label = bottom[1]->cpu_data();\n    int dim = prob_.count() / outer_num_;\n    int count = 0;\n    for (int i = 0; i < outer_num_; ++i) {\n      for (int j = 0; j < inner_num_; ++j) {\n        const int label_value = static_cast<int>(label[i * inner_num_ + j]);\n        if (has_ignore_label_ && label_value == ignore_label_) {\n          for (int c = 0; c < bottom[0]->shape(softmax_axis_); ++c) {\n            bottom_diff[i * dim + c * inner_num_ + j] = 0;\n          }\n        } else {\n          bottom_diff[i * dim + label_value * inner_num_ + j] -= 1;\n          ++count;\n        }\n      }\n    }\n    // Scale gradient\n    const Dtype loss_weight = top[0]->cpu_diff()[0];\n    if (normalize_) {\n      caffe_scal(prob_.count(), loss_weight / count, bottom_diff);\n    } else {\n      caffe_scal(prob_.count(), loss_weight / outer_num_, bottom_diff);\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(SoftmaxWithLossLayer);\n#endif\n\nINSTANTIATE_CLASS(SoftmaxWithLossLayer);\nREGISTER_LAYER_CLASS(SoftmaxWithLoss);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/softmax_loss_layer.cu",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void SoftmaxLossForwardGPU(const int nthreads,\n          const Dtype* prob_data, const Dtype* label, Dtype* loss,\n          const int num, const int dim, const int spatial_dim,\n          const bool has_ignore_label_, const int ignore_label_,\n          Dtype* counts) {\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    const int n = index / spatial_dim;\n    const int s = index % spatial_dim;\n    const int label_value = static_cast<int>(label[n * spatial_dim + s]);\n    if (has_ignore_label_ && label_value == ignore_label_) {\n      loss[index] = 0;\n      counts[index] = 0;\n    } else {\n      loss[index] = -log(max(prob_data[n * dim + label_value * spatial_dim + s],\n                      Dtype(FLT_MIN)));\n      counts[index] = 1;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid SoftmaxWithLossLayer<Dtype>::Forward_gpu(\n    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {\n  softmax_layer_->Forward(softmax_bottom_vec_, softmax_top_vec_);\n  const Dtype* prob_data = prob_.gpu_data();\n  const Dtype* label = bottom[1]->gpu_data();\n  const int dim = prob_.count() / outer_num_;\n  const int nthreads = outer_num_ * inner_num_;\n  // Since this memory is not used for anything until it is overwritten\n  // on the backward pass, we use it here to avoid having to allocate new GPU\n  // memory to accumulate intermediate results in the kernel.\n  Dtype* loss_data = bottom[0]->mutable_gpu_diff();\n  // Similarly, this memory is never used elsewhere, and thus we can use it\n  // to avoid having to allocate additional GPU memory.\n  Dtype* counts = prob_.mutable_gpu_diff();\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  SoftmaxLossForwardGPU<Dtype><<<CAFFE_GET_BLOCKS(nthreads),\n      CAFFE_CUDA_NUM_THREADS>>>(nthreads, prob_data, label, loss_data,\n      outer_num_, dim, inner_num_, has_ignore_label_, ignore_label_, counts);\n  Dtype loss;\n  caffe_gpu_asum(nthreads, loss_data, &loss);\n  if (normalize_) {\n    Dtype count;\n    caffe_gpu_asum(nthreads, counts, &count);\n    loss /= count;\n  } else {\n    loss /= outer_num_;\n  }\n  top[0]->mutable_cpu_data()[0] = loss;\n  if (top.size() == 2) {\n    top[1]->ShareData(prob_);\n  }\n}\n\ntemplate <typename Dtype>\n__global__ void SoftmaxLossBackwardGPU(const int nthreads, const Dtype* top,\n          const Dtype* label, Dtype* bottom_diff, const int num, const int dim,\n          const int spatial_dim, const bool has_ignore_label_,\n          const int ignore_label_, Dtype* counts) {\n  const int channels = dim / spatial_dim;\n\n  CUDA_KERNEL_LOOP(index, nthreads) {\n    const int n = index / spatial_dim;\n    const int s = index % spatial_dim;\n    const int label_value = static_cast<int>(label[n * spatial_dim + s]);\n\n    if (has_ignore_label_ && label_value == ignore_label_) {\n      for (int c = 0; c < channels; ++c) {\n        bottom_diff[n * dim + c * spatial_dim + s] = 0;\n      }\n      counts[index] = 0;\n    } else {\n      bottom_diff[n * dim + label_value * spatial_dim + s] -= 1;\n      counts[index] = 1;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid SoftmaxWithLossLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[1]) {\n    LOG(FATAL) << this->type()\n               << \" Layer cannot backpropagate to label inputs.\";\n  }\n  if (propagate_down[0]) {\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    const Dtype* prob_data = prob_.gpu_data();\n    const Dtype* top_data = top[0]->gpu_data();\n    caffe_gpu_memcpy(prob_.count() * sizeof(Dtype), prob_data, bottom_diff);\n    const Dtype* label = bottom[1]->gpu_data();\n    const int dim = prob_.count() / outer_num_;\n    const int nthreads = outer_num_ * inner_num_;\n    // Since this memory is never used for anything else,\n    // we use to to avoid allocating new GPU memory.\n    Dtype* counts = prob_.mutable_gpu_diff();\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    SoftmaxLossBackwardGPU<Dtype><<<CAFFE_GET_BLOCKS(nthreads),\n        CAFFE_CUDA_NUM_THREADS>>>(nthreads, top_data, label, bottom_diff,\n        outer_num_, dim, inner_num_, has_ignore_label_, ignore_label_, counts);\n    const Dtype loss_weight = top[0]->cpu_diff()[0];\n    if (normalize_) {\n      Dtype count;\n      caffe_gpu_asum(nthreads, counts, &count);\n      caffe_gpu_scal(prob_.count(), loss_weight / count, bottom_diff);\n    } else {\n      caffe_gpu_scal(prob_.count(), loss_weight / outer_num_, bottom_diff);\n    }\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(SoftmaxWithLossLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/split_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid SplitLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  count_ = bottom[0]->count();\n  for (int i = 0; i < top.size(); ++i) {\n    // Do not allow in-place computation in the SplitLayer.  Instead, share data\n    // by reference in the forward pass, and keep separate diff allocations in\n    // the backward pass.  (Technically, it should be possible to share the diff\n    // blob of the first split output with the input, but this seems to cause\n    // some strange effects in practice...)\n    CHECK_NE(top[i], bottom[0]) << this->type() << \" Layer does not \"\n        \"allow in-place computation.\";\n    top[i]->ReshapeLike(*bottom[0]);\n    CHECK_EQ(count_, top[i]->count());\n  }\n}\n\ntemplate <typename Dtype>\nvoid SplitLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  for (int i = 0; i < top.size(); ++i) {\n    top[i]->ShareData(*bottom[0]);\n  }\n}\n\ntemplate <typename Dtype>\nvoid SplitLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) { return; }\n  if (top.size() == 1) {\n    caffe_copy(count_, top[0]->cpu_diff(), bottom[0]->mutable_cpu_diff());\n    return;\n  }\n  caffe_add(count_, top[0]->cpu_diff(), top[1]->cpu_diff(),\n            bottom[0]->mutable_cpu_diff());\n  // Add remaining top blob diffs.\n  for (int i = 2; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->cpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    caffe_axpy(count_, Dtype(1.), top_diff, bottom_diff);\n  }\n}\n\n\n#ifdef CPU_ONLY\nSTUB_GPU(SplitLayer);\n#endif\n\nINSTANTIATE_CLASS(SplitLayer);\nREGISTER_LAYER_CLASS(Split);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/split_layer.cu",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid SplitLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  for (int i = 0; i < top.size(); ++i) {\n    top[i]->ShareData(*bottom[0]);\n  }\n}\n\ntemplate <typename Dtype>\nvoid SplitLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) { return; }\n  if (top.size() == 1) {\n    caffe_copy(count_, top[0]->gpu_diff(), bottom[0]->mutable_gpu_diff());\n    return;\n  }\n  caffe_gpu_add(count_, top[0]->gpu_diff(), top[1]->gpu_diff(),\n                bottom[0]->mutable_gpu_diff());\n  // Add remaining top blob diffs.\n  for (int i = 2; i < top.size(); ++i) {\n    const Dtype* top_diff = top[i]->gpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    caffe_gpu_axpy(count_, Dtype(1.), top_diff, bottom_diff);\n  }\n}\n\n\nINSTANTIATE_LAYER_GPU_FUNCS(SplitLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/spp_layer.cpp",
    "content": "#include <algorithm>\n#include <cfloat>\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\nusing std::min;\nusing std::max;\n\ntemplate <typename Dtype>\nLayerParameter SPPLayer<Dtype>::GetPoolingParam(const int pyramid_level,\n      const int bottom_h, const int bottom_w, const SPPParameter spp_param) {\n  LayerParameter pooling_param;\n  int num_bins = pow(2, pyramid_level);\n\n  // find padding and kernel size so that the pooling is\n  // performed across the entire image\n  int kernel_h = ceil(bottom_h / static_cast<double>(num_bins));\n  // remainder_h is the min number of pixels that need to be padded before\n  // entire image height is pooled over with the chosen kernel dimension\n  int remainder_h = kernel_h * num_bins - bottom_h;\n  // pooling layer pads (2 * pad_h) pixels on the top and bottom of the\n  // image.\n  int pad_h = (remainder_h + 1) / 2;\n\n  // similar logic for width\n  int kernel_w = ceil(bottom_w / static_cast<double>(num_bins));\n  int remainder_w = kernel_w * num_bins - bottom_w;\n  int pad_w = (remainder_w + 1) / 2;\n\n  pooling_param.mutable_pooling_param()->set_pad_h(pad_h);\n  pooling_param.mutable_pooling_param()->set_pad_w(pad_w);\n  pooling_param.mutable_pooling_param()->set_kernel_h(kernel_h);\n  pooling_param.mutable_pooling_param()->set_kernel_w(kernel_w);\n  pooling_param.mutable_pooling_param()->set_stride_h(kernel_h);\n  pooling_param.mutable_pooling_param()->set_stride_w(kernel_w);\n\n  switch (spp_param.pool()) {\n  case SPPParameter_PoolMethod_MAX:\n    pooling_param.mutable_pooling_param()->set_pool(\n        PoolingParameter_PoolMethod_MAX);\n    break;\n  case SPPParameter_PoolMethod_AVE:\n    pooling_param.mutable_pooling_param()->set_pool(\n        PoolingParameter_PoolMethod_AVE);\n    break;\n  case SPPParameter_PoolMethod_STOCHASTIC:\n    pooling_param.mutable_pooling_param()->set_pool(\n        PoolingParameter_PoolMethod_STOCHASTIC);\n    break;\n  default:\n    LOG(FATAL) << \"Unknown pooling method.\";\n  }\n\n  return pooling_param;\n}\n\ntemplate <typename Dtype>\nvoid SPPLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  SPPParameter spp_param = this->layer_param_.spp_param();\n\n  bottom_h_ = bottom[0]->height();\n  bottom_w_ = bottom[0]->width();\n  CHECK_GT(bottom_h_, 0) << \"Input dimensions cannot be zero.\";\n  CHECK_GT(bottom_w_, 0) << \"Input dimensions cannot be zero.\";\n\n  pyramid_height_ = spp_param.pyramid_height();\n  split_top_vec_.clear();\n  pooling_bottom_vecs_.clear();\n  pooling_layers_.clear();\n  pooling_top_vecs_.clear();\n  pooling_outputs_.clear();\n  flatten_layers_.clear();\n  flatten_top_vecs_.clear();\n  flatten_outputs_.clear();\n  concat_bottom_vec_.clear();\n\n  // split layer output holders setup\n  for (int i = 0; i < pyramid_height_; i++) {\n    split_top_vec_.push_back(new Blob<Dtype>());\n  }\n\n  // split layer setup\n  LayerParameter split_param;\n  split_layer_.reset(new SplitLayer<Dtype>(split_param));\n  split_layer_->SetUp(bottom, split_top_vec_);\n\n  for (int i = 0; i < pyramid_height_; i++) {\n    // pooling layer input holders setup\n    pooling_bottom_vecs_.push_back(new vector<Blob<Dtype>*>);\n    pooling_bottom_vecs_[i]->push_back(split_top_vec_[i]);\n\n    // pooling layer output holders setup\n    pooling_outputs_.push_back(new Blob<Dtype>());\n    pooling_top_vecs_.push_back(new vector<Blob<Dtype>*>);\n    pooling_top_vecs_[i]->push_back(pooling_outputs_[i]);\n\n    // pooling layer setup\n    LayerParameter pooling_param = GetPoolingParam(\n        i, bottom_h_, bottom_w_, spp_param);\n\n    pooling_layers_.push_back(shared_ptr<PoolingLayer<Dtype> > (\n        new PoolingLayer<Dtype>(pooling_param)));\n    pooling_layers_[i]->SetUp(*pooling_bottom_vecs_[i], *pooling_top_vecs_[i]);\n\n    // flatten layer output holders setup\n    flatten_outputs_.push_back(new Blob<Dtype>());\n    flatten_top_vecs_.push_back(new vector<Blob<Dtype>*>);\n    flatten_top_vecs_[i]->push_back(flatten_outputs_[i]);\n\n    // flatten layer setup\n    LayerParameter flatten_param;\n    flatten_layers_.push_back(new FlattenLayer<Dtype>(flatten_param));\n    flatten_layers_[i]->SetUp(*pooling_top_vecs_[i], *flatten_top_vecs_[i]);\n\n    // concat layer input holders setup\n    concat_bottom_vec_.push_back(flatten_outputs_[i]);\n  }\n\n  // concat layer setup\n  LayerParameter concat_param;\n  concat_layer_.reset(new ConcatLayer<Dtype>(concat_param));\n  concat_layer_->SetUp(concat_bottom_vec_, top);\n}\n\ntemplate <typename Dtype>\nvoid SPPLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  CHECK_EQ(4, bottom[0]->num_axes()) << \"Input must have 4 axes, \"\n      << \"corresponding to (num, channels, height, width)\";\n  channels_ = bottom[0]->channels();\n  bottom_h_ = bottom[0]->height();\n  bottom_w_ = bottom[0]->width();\n  SPPParameter spp_param = this->layer_param_.spp_param();\n  split_layer_->Reshape(bottom, split_top_vec_);\n  for (int i = 0; i < pyramid_height_; i++) {\n    LayerParameter pooling_param = GetPoolingParam(\n        i, bottom_h_, bottom_w_, spp_param);\n\n    pooling_layers_[i].reset(\n        new PoolingLayer<Dtype>(pooling_param));\n    pooling_layers_[i]->SetUp(\n        *pooling_bottom_vecs_[i], *pooling_top_vecs_[i]);\n    pooling_layers_[i]->Reshape(\n        *pooling_bottom_vecs_[i], *pooling_top_vecs_[i]);\n    flatten_layers_[i]->Reshape(\n        *pooling_top_vecs_[i], *flatten_top_vecs_[i]);\n  }\n  concat_layer_->Reshape(concat_bottom_vec_, top);\n}\n\ntemplate <typename Dtype>\nvoid SPPLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  split_layer_->Forward(bottom, split_top_vec_);\n  for (int i = 0; i < pyramid_height_; i++) {\n    pooling_layers_[i]->Forward(\n        *pooling_bottom_vecs_[i], *pooling_top_vecs_[i]);\n    flatten_layers_[i]->Forward(\n        *pooling_top_vecs_[i], *flatten_top_vecs_[i]);\n  }\n  concat_layer_->Forward(concat_bottom_vec_, top);\n}\n\ntemplate <typename Dtype>\nvoid SPPLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {\n  if (!propagate_down[0]) {\n    return;\n  }\n  vector<bool> concat_propagate_down(pyramid_height_, true);\n  concat_layer_->Backward(top, concat_propagate_down, concat_bottom_vec_);\n  for (int i = 0; i < pyramid_height_; i++) {\n    flatten_layers_[i]->Backward(\n        *flatten_top_vecs_[i], propagate_down, *pooling_top_vecs_[i]);\n    pooling_layers_[i]->Backward(\n        *pooling_top_vecs_[i], propagate_down, *pooling_bottom_vecs_[i]);\n  }\n  split_layer_->Backward(split_top_vec_, propagate_down, bottom);\n}\n\n\nINSTANTIATE_CLASS(SPPLayer);\nREGISTER_LAYER_CLASS(SPP);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/tanh_layer.cpp",
    "content": "// TanH neuron activation function layer.\n// Adapted from ReLU layer code written by Yangqing Jia\n\n#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid TanHLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  const int count = bottom[0]->count();\n  for (int i = 0; i < count; ++i) {\n    top_data[i] = tanh(bottom_data[i]);\n  }\n}\n\ntemplate <typename Dtype>\nvoid TanHLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* top_data = top[0]->cpu_data();\n    const Dtype* top_diff = top[0]->cpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();\n    const int count = bottom[0]->count();\n    Dtype tanhx;\n    for (int i = 0; i < count; ++i) {\n      tanhx = top_data[i];\n      bottom_diff[i] = top_diff[i] * (1 - tanhx * tanhx);\n    }\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU(TanHLayer);\n#endif\n\nINSTANTIATE_CLASS(TanHLayer);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/tanh_layer.cu",
    "content": "// TanH neuron activation function layer.\n// Adapted from ReLU layer code written by Yangqing Jia\n\n#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void TanHForward(const int n, const Dtype* in, Dtype* out) {\n  CUDA_KERNEL_LOOP(index, n) {\n    out[index] = tanh(in[index]);\n  }\n}\n\ntemplate <typename Dtype>\nvoid TanHLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  const int count = bottom[0]->count();\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  TanHForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n      count, bottom_data, top_data);\n  CUDA_POST_KERNEL_CHECK;\n}\n\ntemplate <typename Dtype>\n__global__ void TanHBackward(const int n, const Dtype* in_diff,\n    const Dtype* out_data, Dtype* out_diff) {\n  CUDA_KERNEL_LOOP(index, n) {\n    Dtype tanhx = out_data[index];\n    out_diff[index] = in_diff[index] * (1 - tanhx * tanhx);\n  }\n}\n\ntemplate <typename Dtype>\nvoid TanHLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,\n    const vector<bool>& propagate_down,\n    const vector<Blob<Dtype>*>& bottom) {\n  if (propagate_down[0]) {\n    const Dtype* top_data = top[0]->gpu_data();\n    const Dtype* top_diff = top[0]->gpu_diff();\n    Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();\n    const int count = bottom[0]->count();\n    // NOLINT_NEXT_LINE(whitespace/operators)\n    TanHBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n        count, top_diff, top_data, bottom_diff);\n    CUDA_POST_KERNEL_CHECK;\n  }\n}\n\nINSTANTIATE_LAYER_GPU_FUNCS(TanHLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/threshold_layer.cpp",
    "content": "#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid ThresholdLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  NeuronLayer<Dtype>::LayerSetUp(bottom, top);\n  threshold_ = this->layer_param_.threshold_param().threshold();\n}\n\ntemplate <typename Dtype>\nvoid ThresholdLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->cpu_data();\n  Dtype* top_data = top[0]->mutable_cpu_data();\n  const int count = bottom[0]->count();\n  for (int i = 0; i < count; ++i) {\n    top_data[i] = (bottom_data[i] > threshold_) ? Dtype(1) : Dtype(0);\n  }\n}\n\n#ifdef CPU_ONLY\nSTUB_GPU_FORWARD(ThresholdLayer, Forward);\n#endif\n\nINSTANTIATE_CLASS(ThresholdLayer);\nREGISTER_LAYER_CLASS(Threshold);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/threshold_layer.cu",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"caffe/layer.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void ThresholdForward(const int n, const Dtype threshold,\n    const Dtype* in, Dtype* out) {\n  CUDA_KERNEL_LOOP(index, n) {\n    out[index] = in[index] > threshold ? 1 : 0;\n  }\n}\n\ntemplate <typename Dtype>\nvoid ThresholdLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,\n    const vector<Blob<Dtype>*>& top) {\n  const Dtype* bottom_data = bottom[0]->gpu_data();\n  Dtype* top_data = top[0]->mutable_gpu_data();\n  const int count = bottom[0]->count();\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  ThresholdForward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(\n      count, threshold_, bottom_data, top_data);\n  CUDA_POST_KERNEL_CHECK;\n}\n\n\nINSTANTIATE_LAYER_GPU_FORWARD(ThresholdLayer);\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/layers/window_data_layer.cpp",
    "content": "#include <opencv2/highgui/highgui_c.h>\n#include <stdint.h>\n\n#include <algorithm>\n#include <map>\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"opencv2/core/core.hpp\"\n#include \"opencv2/highgui/highgui.hpp\"\n#include \"opencv2/imgproc/imgproc.hpp\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/benchmark.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/util/rng.hpp\"\n\n// caffe.proto > LayerParameter > WindowDataParameter\n//   'source' field specifies the window_file\n//   'crop_size' indicates the desired warped size\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nWindowDataLayer<Dtype>::~WindowDataLayer<Dtype>() {\n  this->StopInternalThread();\n}\n\ntemplate <typename Dtype>\nvoid WindowDataLayer<Dtype>::DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,\n      const vector<Blob<Dtype>*>& top) {\n  // LayerSetUp runs through the window_file and creates two structures\n  // that hold windows: one for foreground (object) windows and one\n  // for background (non-object) windows. We use an overlap threshold\n  // to decide which is which.\n\n  // window_file format\n  // repeated:\n  //    # image_index\n  //    img_path (abs path)\n  //    channels\n  //    height\n  //    width\n  //    num_windows\n  //    class_index overlap x1 y1 x2 y2\n\n  LOG(INFO) << \"Window data layer:\" << std::endl\n      << \"  foreground (object) overlap threshold: \"\n      << this->layer_param_.window_data_param().fg_threshold() << std::endl\n      << \"  background (non-object) overlap threshold: \"\n      << this->layer_param_.window_data_param().bg_threshold() << std::endl\n      << \"  foreground sampling fraction: \"\n      << this->layer_param_.window_data_param().fg_fraction() << std::endl\n      << \"  cache_images: \"\n      << this->layer_param_.window_data_param().cache_images() << std::endl\n      << \"  root_folder: \"\n      << this->layer_param_.window_data_param().root_folder();\n\n  cache_images_ = this->layer_param_.window_data_param().cache_images();\n  string root_folder = this->layer_param_.window_data_param().root_folder();\n\n  const bool prefetch_needs_rand =\n      this->transform_param_.mirror() ||\n      this->transform_param_.crop_size();\n  if (prefetch_needs_rand) {\n    const unsigned int prefetch_rng_seed = caffe_rng_rand();\n    prefetch_rng_.reset(new Caffe::RNG(prefetch_rng_seed));\n  } else {\n    prefetch_rng_.reset();\n  }\n\n  std::ifstream infile(this->layer_param_.window_data_param().source().c_str());\n  CHECK(infile.good()) << \"Failed to open window file \"\n      << this->layer_param_.window_data_param().source() << std::endl;\n\n  map<int, int> label_hist;\n  label_hist.insert(std::make_pair(0, 0));\n\n  string hashtag;\n  int image_index, channels;\n  if (!(infile >> hashtag >> image_index)) {\n    LOG(FATAL) << \"Window file is empty\";\n  }\n  do {\n    CHECK_EQ(hashtag, \"#\");\n    // read image path\n    string image_path;\n    infile >> image_path;\n    image_path = root_folder + image_path;\n    // read image dimensions\n    vector<int> image_size(3);\n    infile >> image_size[0] >> image_size[1] >> image_size[2];\n    channels = image_size[0];\n    image_database_.push_back(std::make_pair(image_path, image_size));\n\n    if (cache_images_) {\n      Datum datum;\n      if (!ReadFileToDatum(image_path, &datum)) {\n        LOG(ERROR) << \"Could not open or find file \" << image_path;\n        return;\n      }\n      image_database_cache_.push_back(std::make_pair(image_path, datum));\n    }\n    // read each box\n    int num_windows;\n    infile >> num_windows;\n    const float fg_threshold =\n        this->layer_param_.window_data_param().fg_threshold();\n    const float bg_threshold =\n        this->layer_param_.window_data_param().bg_threshold();\n    for (int i = 0; i < num_windows; ++i) {\n      int label, x1, y1, x2, y2;\n      float overlap;\n      infile >> label >> overlap >> x1 >> y1 >> x2 >> y2;\n\n      vector<float> window(WindowDataLayer::NUM);\n      window[WindowDataLayer::IMAGE_INDEX] = image_index;\n      window[WindowDataLayer::LABEL] = label;\n      window[WindowDataLayer::OVERLAP] = overlap;\n      window[WindowDataLayer::X1] = x1;\n      window[WindowDataLayer::Y1] = y1;\n      window[WindowDataLayer::X2] = x2;\n      window[WindowDataLayer::Y2] = y2;\n\n      // add window to foreground list or background list\n      if (overlap >= fg_threshold) {\n        int label = window[WindowDataLayer::LABEL];\n        CHECK_GT(label, 0);\n        fg_windows_.push_back(window);\n        label_hist.insert(std::make_pair(label, 0));\n        label_hist[label]++;\n      } else if (overlap < bg_threshold) {\n        // background window, force label and overlap to 0\n        window[WindowDataLayer::LABEL] = 0;\n        window[WindowDataLayer::OVERLAP] = 0;\n        bg_windows_.push_back(window);\n        label_hist[0]++;\n      }\n    }\n\n    if (image_index % 100 == 0) {\n      LOG(INFO) << \"num: \" << image_index << \" \"\n          << image_path << \" \"\n          << image_size[0] << \" \"\n          << image_size[1] << \" \"\n          << image_size[2] << \" \"\n          << \"windows to process: \" << num_windows;\n    }\n  } while (infile >> hashtag >> image_index);\n\n  LOG(INFO) << \"Number of images: \" << image_index+1;\n\n  for (map<int, int>::iterator it = label_hist.begin();\n      it != label_hist.end(); ++it) {\n    LOG(INFO) << \"class \" << it->first << \" has \" << label_hist[it->first]\n              << \" samples\";\n  }\n\n  LOG(INFO) << \"Amount of context padding: \"\n      << this->layer_param_.window_data_param().context_pad();\n\n  LOG(INFO) << \"Crop mode: \"\n      << this->layer_param_.window_data_param().crop_mode();\n\n  // image\n  const int crop_size = this->transform_param_.crop_size();\n  CHECK_GT(crop_size, 0);\n  const int batch_size = this->layer_param_.window_data_param().batch_size();\n  top[0]->Reshape(batch_size, channels, crop_size, crop_size);\n  for (int i = 0; i < this->PREFETCH_COUNT; ++i)\n    this->prefetch_[i].data_.Reshape(\n        batch_size, channels, crop_size, crop_size);\n\n  LOG(INFO) << \"output data size: \" << top[0]->num() << \",\"\n      << top[0]->channels() << \",\" << top[0]->height() << \",\"\n      << top[0]->width();\n  // label\n  vector<int> label_shape(1, batch_size);\n  top[1]->Reshape(label_shape);\n  for (int i = 0; i < this->PREFETCH_COUNT; ++i) {\n    this->prefetch_[i].label_.Reshape(label_shape);\n  }\n\n  // data mean\n  has_mean_file_ = this->transform_param_.has_mean_file();\n  has_mean_values_ = this->transform_param_.mean_value_size() > 0;\n  if (has_mean_file_) {\n    const string& mean_file =\n          this->transform_param_.mean_file();\n    LOG(INFO) << \"Loading mean file from: \" << mean_file;\n    BlobProto blob_proto;\n    ReadProtoFromBinaryFileOrDie(mean_file.c_str(), &blob_proto);\n    data_mean_.FromProto(blob_proto);\n  }\n  if (has_mean_values_) {\n    CHECK(has_mean_file_ == false) <<\n      \"Cannot specify mean_file and mean_value at the same time\";\n    for (int c = 0; c < this->transform_param_.mean_value_size(); ++c) {\n      mean_values_.push_back(this->transform_param_.mean_value(c));\n    }\n    CHECK(mean_values_.size() == 1 || mean_values_.size() == channels) <<\n     \"Specify either 1 mean_value or as many as channels: \" << channels;\n    if (channels > 1 && mean_values_.size() == 1) {\n      // Replicate the mean_value for simplicity\n      for (int c = 1; c < channels; ++c) {\n        mean_values_.push_back(mean_values_[0]);\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nunsigned int WindowDataLayer<Dtype>::PrefetchRand() {\n  CHECK(prefetch_rng_);\n  caffe::rng_t* prefetch_rng =\n      static_cast<caffe::rng_t*>(prefetch_rng_->generator());\n  return (*prefetch_rng)();\n}\n\n// This function is called on prefetch thread\ntemplate <typename Dtype>\nvoid WindowDataLayer<Dtype>::load_batch(Batch<Dtype>* batch) {\n  // At each iteration, sample N windows where N*p are foreground (object)\n  // windows and N*(1-p) are background (non-object) windows\n  CPUTimer batch_timer;\n  batch_timer.Start();\n  double read_time = 0;\n  double trans_time = 0;\n  CPUTimer timer;\n  Dtype* top_data = batch->data_.mutable_cpu_data();\n  Dtype* top_label = batch->label_.mutable_cpu_data();\n  const Dtype scale = this->layer_param_.window_data_param().scale();\n  const int batch_size = this->layer_param_.window_data_param().batch_size();\n  const int context_pad = this->layer_param_.window_data_param().context_pad();\n  const int crop_size = this->transform_param_.crop_size();\n  const bool mirror = this->transform_param_.mirror();\n  const float fg_fraction =\n      this->layer_param_.window_data_param().fg_fraction();\n  Dtype* mean = NULL;\n  int mean_off = 0;\n  int mean_width = 0;\n  int mean_height = 0;\n  if (this->has_mean_file_) {\n    mean = this->data_mean_.mutable_cpu_data();\n    mean_off = (this->data_mean_.width() - crop_size) / 2;\n    mean_width = this->data_mean_.width();\n    mean_height = this->data_mean_.height();\n  }\n  cv::Size cv_crop_size(crop_size, crop_size);\n  const string& crop_mode = this->layer_param_.window_data_param().crop_mode();\n\n  bool use_square = (crop_mode == \"square\") ? true : false;\n\n  // zero out batch\n  caffe_set(batch->data_.count(), Dtype(0), top_data);\n\n  const int num_fg = static_cast<int>(static_cast<float>(batch_size)\n      * fg_fraction);\n  const int num_samples[2] = { batch_size - num_fg, num_fg };\n\n  int item_id = 0;\n  // sample from bg set then fg set\n  for (int is_fg = 0; is_fg < 2; ++is_fg) {\n    for (int dummy = 0; dummy < num_samples[is_fg]; ++dummy) {\n      // sample a window\n      timer.Start();\n      const unsigned int rand_index = PrefetchRand();\n      vector<float> window = (is_fg) ?\n          fg_windows_[rand_index % fg_windows_.size()] :\n          bg_windows_[rand_index % bg_windows_.size()];\n\n      bool do_mirror = mirror && PrefetchRand() % 2;\n\n      // load the image containing the window\n      pair<std::string, vector<int> > image =\n          image_database_[window[WindowDataLayer<Dtype>::IMAGE_INDEX]];\n\n      cv::Mat cv_img;\n      if (this->cache_images_) {\n        pair<std::string, Datum> image_cached =\n          image_database_cache_[window[WindowDataLayer<Dtype>::IMAGE_INDEX]];\n        cv_img = DecodeDatumToCVMat(image_cached.second, true);\n      } else {\n        cv_img = cv::imread(image.first, CV_LOAD_IMAGE_COLOR);\n        if (!cv_img.data) {\n          LOG(ERROR) << \"Could not open or find file \" << image.first;\n          return;\n        }\n      }\n      read_time += timer.MicroSeconds();\n      timer.Start();\n      const int channels = cv_img.channels();\n\n      // crop window out of image and warp it\n      int x1 = window[WindowDataLayer<Dtype>::X1];\n      int y1 = window[WindowDataLayer<Dtype>::Y1];\n      int x2 = window[WindowDataLayer<Dtype>::X2];\n      int y2 = window[WindowDataLayer<Dtype>::Y2];\n\n      int pad_w = 0;\n      int pad_h = 0;\n      if (context_pad > 0 || use_square) {\n        // scale factor by which to expand the original region\n        // such that after warping the expanded region to crop_size x crop_size\n        // there's exactly context_pad amount of padding on each side\n        Dtype context_scale = static_cast<Dtype>(crop_size) /\n            static_cast<Dtype>(crop_size - 2*context_pad);\n\n        // compute the expanded region\n        Dtype half_height = static_cast<Dtype>(y2-y1+1)/2.0;\n        Dtype half_width = static_cast<Dtype>(x2-x1+1)/2.0;\n        Dtype center_x = static_cast<Dtype>(x1) + half_width;\n        Dtype center_y = static_cast<Dtype>(y1) + half_height;\n        if (use_square) {\n          if (half_height > half_width) {\n            half_width = half_height;\n          } else {\n            half_height = half_width;\n          }\n        }\n        x1 = static_cast<int>(round(center_x - half_width*context_scale));\n        x2 = static_cast<int>(round(center_x + half_width*context_scale));\n        y1 = static_cast<int>(round(center_y - half_height*context_scale));\n        y2 = static_cast<int>(round(center_y + half_height*context_scale));\n\n        // the expanded region may go outside of the image\n        // so we compute the clipped (expanded) region and keep track of\n        // the extent beyond the image\n        int unclipped_height = y2-y1+1;\n        int unclipped_width = x2-x1+1;\n        int pad_x1 = std::max(0, -x1);\n        int pad_y1 = std::max(0, -y1);\n        int pad_x2 = std::max(0, x2 - cv_img.cols + 1);\n        int pad_y2 = std::max(0, y2 - cv_img.rows + 1);\n        // clip bounds\n        x1 = x1 + pad_x1;\n        x2 = x2 - pad_x2;\n        y1 = y1 + pad_y1;\n        y2 = y2 - pad_y2;\n        CHECK_GT(x1, -1);\n        CHECK_GT(y1, -1);\n        CHECK_LT(x2, cv_img.cols);\n        CHECK_LT(y2, cv_img.rows);\n\n        int clipped_height = y2-y1+1;\n        int clipped_width = x2-x1+1;\n\n        // scale factors that would be used to warp the unclipped\n        // expanded region\n        Dtype scale_x =\n            static_cast<Dtype>(crop_size)/static_cast<Dtype>(unclipped_width);\n        Dtype scale_y =\n            static_cast<Dtype>(crop_size)/static_cast<Dtype>(unclipped_height);\n\n        // size to warp the clipped expanded region to\n        cv_crop_size.width =\n            static_cast<int>(round(static_cast<Dtype>(clipped_width)*scale_x));\n        cv_crop_size.height =\n            static_cast<int>(round(static_cast<Dtype>(clipped_height)*scale_y));\n        pad_x1 = static_cast<int>(round(static_cast<Dtype>(pad_x1)*scale_x));\n        pad_x2 = static_cast<int>(round(static_cast<Dtype>(pad_x2)*scale_x));\n        pad_y1 = static_cast<int>(round(static_cast<Dtype>(pad_y1)*scale_y));\n        pad_y2 = static_cast<int>(round(static_cast<Dtype>(pad_y2)*scale_y));\n\n        pad_h = pad_y1;\n        // if we're mirroring, we mirror the padding too (to be pedantic)\n        if (do_mirror) {\n          pad_w = pad_x2;\n        } else {\n          pad_w = pad_x1;\n        }\n\n        // ensure that the warped, clipped region plus the padding fits in the\n        // crop_size x crop_size image (it might not due to rounding)\n        if (pad_h + cv_crop_size.height > crop_size) {\n          cv_crop_size.height = crop_size - pad_h;\n        }\n        if (pad_w + cv_crop_size.width > crop_size) {\n          cv_crop_size.width = crop_size - pad_w;\n        }\n      }\n\n      cv::Rect roi(x1, y1, x2-x1+1, y2-y1+1);\n      cv::Mat cv_cropped_img = cv_img(roi);\n      cv::resize(cv_cropped_img, cv_cropped_img,\n          cv_crop_size, 0, 0, cv::INTER_LINEAR);\n\n      // horizontal flip at random\n      if (do_mirror) {\n        cv::flip(cv_cropped_img, cv_cropped_img, 1);\n      }\n\n      // copy the warped window into top_data\n      for (int h = 0; h < cv_cropped_img.rows; ++h) {\n        const uchar* ptr = cv_cropped_img.ptr<uchar>(h);\n        int img_index = 0;\n        for (int w = 0; w < cv_cropped_img.cols; ++w) {\n          for (int c = 0; c < channels; ++c) {\n            int top_index = ((item_id * channels + c) * crop_size + h + pad_h)\n                     * crop_size + w + pad_w;\n            // int top_index = (c * height + h) * width + w;\n            Dtype pixel = static_cast<Dtype>(ptr[img_index++]);\n            if (this->has_mean_file_) {\n              int mean_index = (c * mean_height + h + mean_off + pad_h)\n                           * mean_width + w + mean_off + pad_w;\n              top_data[top_index] = (pixel - mean[mean_index]) * scale;\n            } else {\n              if (this->has_mean_values_) {\n                top_data[top_index] = (pixel - this->mean_values_[c]) * scale;\n              } else {\n                top_data[top_index] = pixel * scale;\n              }\n            }\n          }\n        }\n      }\n      trans_time += timer.MicroSeconds();\n      // get window label\n      top_label[item_id] = window[WindowDataLayer<Dtype>::LABEL];\n\n      #if 0\n      // useful debugging code for dumping transformed windows to disk\n      string file_id;\n      std::stringstream ss;\n      ss << PrefetchRand();\n      ss >> file_id;\n      std::ofstream inf((string(\"dump/\") + file_id +\n          string(\"_info.txt\")).c_str(), std::ofstream::out);\n      inf << image.first << std::endl\n          << window[WindowDataLayer<Dtype>::X1]+1 << std::endl\n          << window[WindowDataLayer<Dtype>::Y1]+1 << std::endl\n          << window[WindowDataLayer<Dtype>::X2]+1 << std::endl\n          << window[WindowDataLayer<Dtype>::Y2]+1 << std::endl\n          << do_mirror << std::endl\n          << top_label[item_id] << std::endl\n          << is_fg << std::endl;\n      inf.close();\n      std::ofstream top_data_file((string(\"dump/\") + file_id +\n          string(\"_data.txt\")).c_str(),\n          std::ofstream::out | std::ofstream::binary);\n      for (int c = 0; c < channels; ++c) {\n        for (int h = 0; h < crop_size; ++h) {\n          for (int w = 0; w < crop_size; ++w) {\n            top_data_file.write(reinterpret_cast<char*>(\n                &top_data[((item_id * channels + c) * crop_size + h)\n                          * crop_size + w]),\n                sizeof(Dtype));\n          }\n        }\n      }\n      top_data_file.close();\n      #endif\n\n      item_id++;\n    }\n  }\n  batch_timer.Stop();\n  DLOG(INFO) << \"Prefetch batch: \" << batch_timer.MilliSeconds() << \" ms.\";\n  DLOG(INFO) << \"     Read time: \" << read_time / 1000 << \" ms.\";\n  DLOG(INFO) << \"Transform time: \" << trans_time / 1000 << \" ms.\";\n}\n\nINSTANTIATE_CLASS(WindowDataLayer);\nREGISTER_LAYER_CLASS(WindowData);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/net.cpp",
    "content": "#include <algorithm>\n#include <map>\n#include <set>\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"hdf5.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/net.hpp\"\n#include \"caffe/parallel.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/hdf5.hpp\"\n#include \"caffe/util/insert_splits.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/util/upgrade_proto.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nNet<Dtype>::Net(const NetParameter& param, const Net* root_net)\n    : root_net_(root_net) {\n  Init(param);\n}\n\ntemplate <typename Dtype>\nNet<Dtype>::Net(const string& param_file, Phase phase, const Net* root_net)\n    : root_net_(root_net) {\n  NetParameter param;\n  ReadNetParamsFromTextFileOrDie(param_file, &param);\n  param.mutable_state()->set_phase(phase);\n  Init(param);\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::Init(const NetParameter& in_param) {\n  CHECK(Caffe::root_solver() || root_net_)\n      << \"root_net_ needs to be set for all non-root solvers\";\n  // Set phase from the state.\n  phase_ = in_param.state().phase();\n  // Filter layers based on their include/exclude rules and\n  // the current NetState.\n  NetParameter filtered_param;\n  FilterNet(in_param, &filtered_param);\n  if (Caffe::root_solver()) {\n    LOG(INFO) << \"Initializing net from parameters: \" << std::endl\n              << filtered_param.DebugString();\n  }\n  // Create a copy of filtered_param with splits added where necessary.\n  NetParameter param;\n  InsertSplits(filtered_param, &param);\n  // Basically, build all the layers and set up their connections.\n  name_ = param.name();\n  map<string, int> blob_name_to_idx;\n  set<string> available_blobs;\n  CHECK(param.input_dim_size() == 0 || param.input_shape_size() == 0)\n      << \"Must specify either input_shape OR deprecated input_dim, not both.\";\n  if (param.input_dim_size() > 0) {\n    // Deprecated 4D dimensions.\n    CHECK_EQ(param.input_size() * 4, param.input_dim_size())\n        << \"Incorrect input blob dimension specifications.\";\n  } else {\n    CHECK_EQ(param.input_size(), param.input_shape_size())\n        << \"Exactly one input_shape must be specified per input.\";\n  }\n  memory_used_ = 0;\n  // set the input blobs\n  for (int input_id = 0; input_id < param.input_size(); ++input_id) {\n    const int layer_id = -1;  // inputs have fake layer ID -1\n    AppendTop(param, layer_id, input_id, &available_blobs, &blob_name_to_idx);\n  }\n  DLOG_IF(INFO, Caffe::root_solver())\n      << \"Memory required for data: \" << memory_used_ * sizeof(Dtype);\n  // For each layer, set up its input and output\n  bottom_vecs_.resize(param.layer_size());\n  top_vecs_.resize(param.layer_size());\n  bottom_id_vecs_.resize(param.layer_size());\n  param_id_vecs_.resize(param.layer_size());\n  top_id_vecs_.resize(param.layer_size());\n  bottom_need_backward_.resize(param.layer_size());\n  for (int layer_id = 0; layer_id < param.layer_size(); ++layer_id) {\n    // For non-root solvers, whether this layer is shared from root_net_.\n    bool share_from_root = !Caffe::root_solver()\n        && root_net_->layers_[layer_id]->ShareInParallel();\n    // Inherit phase from net if unset.\n    if (!param.layer(layer_id).has_phase()) {\n      param.mutable_layer(layer_id)->set_phase(phase_);\n    }\n    // Setup layer.\n    const LayerParameter& layer_param = param.layer(layer_id);\n    if (layer_param.propagate_down_size() > 0) {\n      CHECK_EQ(layer_param.propagate_down_size(),\n          layer_param.bottom_size())\n          << \"propagate_down param must be specified \"\n          << \"either 0 or bottom_size times \";\n    }\n    if (share_from_root) {\n      LOG(INFO) << \"Sharing layer \" << layer_param.name() << \" from root net\";\n      layers_.push_back(root_net_->layers_[layer_id]);\n      layers_[layer_id]->SetShared(true);\n    } else {\n      layers_.push_back(LayerRegistry<Dtype>::CreateLayer(layer_param));\n    }\n    layer_names_.push_back(layer_param.name());\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"Creating Layer \" << layer_param.name();\n    }\n    bool need_backward = false;\n\n    // Figure out this layer's input and output\n    for (int bottom_id = 0; bottom_id < layer_param.bottom_size();\n         ++bottom_id) {\n      const int blob_id = AppendBottom(param, layer_id, bottom_id,\n                                       &available_blobs, &blob_name_to_idx);\n      // If a blob needs backward, this layer should provide it.\n      need_backward |= blob_need_backward_[blob_id];\n    }\n    int num_top = layer_param.top_size();\n    for (int top_id = 0; top_id < num_top; ++top_id) {\n      AppendTop(param, layer_id, top_id, &available_blobs, &blob_name_to_idx);\n    }\n    // If the layer specifies that AutoTopBlobs() -> true and the LayerParameter\n    // specified fewer than the required number (as specified by\n    // ExactNumTopBlobs() or MinTopBlobs()), allocate them here.\n    Layer<Dtype>* layer = layers_[layer_id].get();\n    if (layer->AutoTopBlobs()) {\n      const int needed_num_top =\n          std::max(layer->MinTopBlobs(), layer->ExactNumTopBlobs());\n      for (; num_top < needed_num_top; ++num_top) {\n        // Add \"anonymous\" top blobs -- do not modify available_blobs or\n        // blob_name_to_idx as we don't want these blobs to be usable as input\n        // to other layers.\n        AppendTop(param, layer_id, num_top, NULL, NULL);\n      }\n    }\n    // After this layer is connected, set it up.\n    if (share_from_root) {\n      // Set up size of top blobs using root_net_\n      const vector<Blob<Dtype>*>& base_top = root_net_->top_vecs_[layer_id];\n      const vector<Blob<Dtype>*>& this_top = this->top_vecs_[layer_id];\n      for (int top_id = 0; top_id < base_top.size(); ++top_id) {\n        this_top[top_id]->ReshapeLike(*base_top[top_id]);\n        LOG(INFO) << \"Created top blob \" << top_id << \" (shape: \"\n            << this_top[top_id]->shape_string() <<  \") for shared layer \"\n            << layer_param.name();\n      }\n    } else {\n      layers_[layer_id]->SetUp(bottom_vecs_[layer_id], top_vecs_[layer_id]);\n    }\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"Setting up \" << layer_names_[layer_id];\n    }\n    for (int top_id = 0; top_id < top_vecs_[layer_id].size(); ++top_id) {\n      if (blob_loss_weights_.size() <= top_id_vecs_[layer_id][top_id]) {\n        blob_loss_weights_.resize(top_id_vecs_[layer_id][top_id] + 1, Dtype(0));\n      }\n      blob_loss_weights_[top_id_vecs_[layer_id][top_id]] = layer->loss(top_id);\n      if (Caffe::root_solver()) {\n        LOG(INFO) << \"Top shape: \"\n                  << top_vecs_[layer_id][top_id]->shape_string();\n      }\n      if (layer->loss(top_id)) {\n        if (Caffe::root_solver()) {\n          LOG(INFO) << \"    with loss weight \" << layer->loss(top_id);\n        }\n      }\n      memory_used_ += top_vecs_[layer_id][top_id]->count();\n    }\n    if (Caffe::root_solver()) {\n      DLOG(INFO) << \"Memory required for data: \"\n                 << memory_used_ * sizeof(Dtype);\n    }\n    const int param_size = layer_param.param_size();\n    const int num_param_blobs = layers_[layer_id]->blobs().size();\n    CHECK_LE(param_size, num_param_blobs)\n        << \"Too many params specified for layer \" << layer_param.name();\n    ParamSpec default_param_spec;\n    for (int param_id = 0; param_id < num_param_blobs; ++param_id) {\n      const ParamSpec* param_spec = (param_id < param_size) ?\n          &layer_param.param(param_id) : &default_param_spec;\n      const bool param_need_backward = param_spec->lr_mult() > 0;\n      need_backward |= param_need_backward;\n      layers_[layer_id]->set_param_propagate_down(param_id,\n                                                  param_need_backward);\n    }\n    for (int param_id = 0; param_id < num_param_blobs; ++param_id) {\n      AppendParam(param, layer_id, param_id);\n    }\n    // Finally, set the backward flag\n    layer_need_backward_.push_back(need_backward);\n    if (need_backward) {\n      for (int top_id = 0; top_id < top_id_vecs_[layer_id].size(); ++top_id) {\n        blob_need_backward_[top_id_vecs_[layer_id][top_id]] = true;\n      }\n    }\n  }\n  // Go through the net backwards to determine which blobs contribute to the\n  // loss.  We can skip backward computation for blobs that don't contribute\n  // to the loss.\n  // Also checks if all bottom blobs don't need backward computation (possible\n  // because the skip_propagate_down param) and so we can skip bacward\n  // computation for the entire layer\n  set<string> blobs_under_loss;\n  set<string> blobs_skip_backp;\n  for (int layer_id = layers_.size() - 1; layer_id >= 0; --layer_id) {\n    bool layer_contributes_loss = false;\n    bool layer_skip_propagate_down = true;\n    for (int top_id = 0; top_id < top_vecs_[layer_id].size(); ++top_id) {\n      const string& blob_name = blob_names_[top_id_vecs_[layer_id][top_id]];\n      if (layers_[layer_id]->loss(top_id) ||\n          (blobs_under_loss.find(blob_name) != blobs_under_loss.end())) {\n        layer_contributes_loss = true;\n      }\n      if (blobs_skip_backp.find(blob_name) == blobs_skip_backp.end()) {\n        layer_skip_propagate_down = false;\n      }\n      if (layer_contributes_loss && !layer_skip_propagate_down)\n        break;\n    }\n    // If this layer can skip backward computation, also all his bottom blobs\n    // don't need backpropagation\n    if (layer_need_backward_[layer_id] && layer_skip_propagate_down) {\n      layer_need_backward_[layer_id] = false;\n      for (int bottom_id = 0; bottom_id < bottom_vecs_[layer_id].size();\n               ++bottom_id) {\n        bottom_need_backward_[layer_id][bottom_id] = false;\n      }\n    }\n    if (!layer_contributes_loss) { layer_need_backward_[layer_id] = false; }\n    if (layer_need_backward_[layer_id]) {\n      if (Caffe::root_solver()) {\n        LOG(INFO) << layer_names_[layer_id] << \" needs backward computation.\";\n      }\n    } else {\n      if (Caffe::root_solver()) {\n        LOG(INFO) << layer_names_[layer_id]\n                  << \" does not need backward computation.\";\n      }\n    }\n    for (int bottom_id = 0; bottom_id < bottom_vecs_[layer_id].size();\n         ++bottom_id) {\n      if (layer_contributes_loss) {\n        const string& blob_name =\n            blob_names_[bottom_id_vecs_[layer_id][bottom_id]];\n        blobs_under_loss.insert(blob_name);\n      } else {\n        bottom_need_backward_[layer_id][bottom_id] = false;\n      }\n      if (!bottom_need_backward_[layer_id][bottom_id]) {\n        const string& blob_name =\n                   blob_names_[bottom_id_vecs_[layer_id][bottom_id]];\n        blobs_skip_backp.insert(blob_name);\n      }\n    }\n  }\n  // Handle force_backward if needed.\n  if (param.force_backward()) {\n    for (int layer_id = 0; layer_id < layers_.size(); ++layer_id) {\n      layer_need_backward_[layer_id] = true;\n      for (int bottom_id = 0;\n           bottom_id < bottom_need_backward_[layer_id].size(); ++bottom_id) {\n        bottom_need_backward_[layer_id][bottom_id] =\n            bottom_need_backward_[layer_id][bottom_id] ||\n            layers_[layer_id]->AllowForceBackward(bottom_id);\n        blob_need_backward_[bottom_id_vecs_[layer_id][bottom_id]] =\n            blob_need_backward_[bottom_id_vecs_[layer_id][bottom_id]] ||\n            bottom_need_backward_[layer_id][bottom_id];\n      }\n      for (int param_id = 0; param_id < layers_[layer_id]->blobs().size();\n           ++param_id) {\n        layers_[layer_id]->set_param_propagate_down(param_id, true);\n      }\n    }\n  }\n  // In the end, all remaining blobs are considered output blobs.\n  for (set<string>::iterator it = available_blobs.begin();\n      it != available_blobs.end(); ++it) {\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"This network produces output \" << *it;\n    }\n    net_output_blobs_.push_back(blobs_[blob_name_to_idx[*it]].get());\n    net_output_blob_indices_.push_back(blob_name_to_idx[*it]);\n  }\n  for (size_t blob_id = 0; blob_id < blob_names_.size(); ++blob_id) {\n    blob_names_index_[blob_names_[blob_id]] = blob_id;\n  }\n  for (size_t layer_id = 0; layer_id < layer_names_.size(); ++layer_id) {\n    layer_names_index_[layer_names_[layer_id]] = layer_id;\n  }\n  ShareWeights();\n  debug_info_ = param.debug_info();\n  if (Caffe::root_solver()) {\n    LOG(INFO) << \"Network initialization done.\";\n    LOG(INFO) << \"Memory required for data: \" << memory_used_ * sizeof(Dtype);\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::FilterNet(const NetParameter& param,\n    NetParameter* param_filtered) {\n  NetState net_state(param.state());\n  param_filtered->CopyFrom(param);\n  param_filtered->clear_layer();\n  for (int i = 0; i < param.layer_size(); ++i) {\n    const LayerParameter& layer_param = param.layer(i);\n    const string& layer_name = layer_param.name();\n    CHECK(layer_param.include_size() == 0 || layer_param.exclude_size() == 0)\n          << \"Specify either include rules or exclude rules; not both.\";\n    // If no include rules are specified, the layer is included by default and\n    // only excluded if it meets one of the exclude rules.\n    bool layer_included = (layer_param.include_size() == 0);\n    for (int j = 0; layer_included && j < layer_param.exclude_size(); ++j) {\n      if (StateMeetsRule(net_state, layer_param.exclude(j), layer_name)) {\n        layer_included = false;\n      }\n    }\n    for (int j = 0; !layer_included && j < layer_param.include_size(); ++j) {\n      if (StateMeetsRule(net_state, layer_param.include(j), layer_name)) {\n        layer_included = true;\n      }\n    }\n    if (layer_included) {\n      param_filtered->add_layer()->CopyFrom(layer_param);\n    }\n  }\n}\n\ntemplate <typename Dtype>\nbool Net<Dtype>::StateMeetsRule(const NetState& state,\n    const NetStateRule& rule, const string& layer_name) {\n  // Check whether the rule is broken due to phase.\n  if (rule.has_phase()) {\n      if (rule.phase() != state.phase()) {\n        if (Caffe::root_solver()) {\n          LOG(INFO) << \"The NetState phase (\" << state.phase()\n                    << \") differed from the phase (\" << rule.phase()\n                    << \") specified by a rule in layer \" << layer_name;\n        }\n        return false;\n      }\n  }\n  // Check whether the rule is broken due to min level.\n  if (rule.has_min_level()) {\n    if (state.level() < rule.min_level()) {\n      if (Caffe::root_solver()) {\n        LOG(INFO) << \"The NetState level (\" << state.level()\n                  << \") is above the min_level (\" << rule.min_level()\n                  << \") specified by a rule in layer \" << layer_name;\n      }\n      return false;\n    }\n  }\n  // Check whether the rule is broken due to max level.\n  if (rule.has_max_level()) {\n    if (state.level() > rule.max_level()) {\n      if (Caffe::root_solver()) {\n        LOG(INFO) << \"The NetState level (\" << state.level()\n                  << \") is above the max_level (\" << rule.max_level()\n                  << \") specified by a rule in layer \" << layer_name;\n      }\n      return false;\n    }\n  }\n  // Check whether the rule is broken due to stage. The NetState must\n  // contain ALL of the rule's stages to meet it.\n  for (int i = 0; i < rule.stage_size(); ++i) {\n    // Check that the NetState contains the rule's ith stage.\n    bool has_stage = false;\n    for (int j = 0; !has_stage && j < state.stage_size(); ++j) {\n      if (rule.stage(i) == state.stage(j)) { has_stage = true; }\n    }\n    if (!has_stage) {\n      if (Caffe::root_solver()) {\n        LOG(INFO) << \"The NetState did not contain stage '\" << rule.stage(i)\n                  << \"' specified by a rule in layer \" << layer_name;\n      }\n      return false;\n    }\n  }\n  // Check whether the rule is broken due to not_stage. The NetState must\n  // contain NONE of the rule's not_stages to meet it.\n  for (int i = 0; i < rule.not_stage_size(); ++i) {\n    // Check that the NetState contains the rule's ith not_stage.\n    bool has_stage = false;\n    for (int j = 0; !has_stage && j < state.stage_size(); ++j) {\n      if (rule.not_stage(i) == state.stage(j)) { has_stage = true; }\n    }\n    if (has_stage) {\n      if (Caffe::root_solver()) {\n        LOG(INFO) << \"The NetState contained a not_stage '\" << rule.not_stage(i)\n                  << \"' specified by a rule in layer \" << layer_name;\n      }\n      return false;\n    }\n  }\n  return true;\n}\n\n// Helper for Net::Init: add a new input or top blob to the net.  (Inputs have\n// layer_id == -1, tops have layer_id >= 0.)\ntemplate <typename Dtype>\nvoid Net<Dtype>::AppendTop(const NetParameter& param, const int layer_id,\n                           const int top_id, set<string>* available_blobs,\n                           map<string, int>* blob_name_to_idx) {\n  shared_ptr<LayerParameter> layer_param((layer_id >= 0) ?\n    (new LayerParameter(param.layer(layer_id))) : NULL);\n  const string& blob_name = layer_param ?\n      (layer_param->top_size() > top_id ?\n          layer_param->top(top_id) : \"(automatic)\") : param.input(top_id);\n  // Check if we are doing in-place computation\n  if (blob_name_to_idx && layer_param && layer_param->bottom_size() > top_id &&\n      blob_name == layer_param->bottom(top_id)) {\n    // In-place computation\n    if (Caffe::root_solver()) {\n      LOG(INFO) << layer_param->name() << \" -> \" << blob_name << \" (in-place)\";\n    }\n    top_vecs_[layer_id].push_back(blobs_[(*blob_name_to_idx)[blob_name]].get());\n    top_id_vecs_[layer_id].push_back((*blob_name_to_idx)[blob_name]);\n  } else if (blob_name_to_idx &&\n             blob_name_to_idx->find(blob_name) != blob_name_to_idx->end()) {\n    // If we are not doing in-place computation but have duplicated blobs,\n    // raise an error.\n    LOG(FATAL) << \"Duplicate blobs produced by multiple sources.\";\n  } else {\n    // Normal output.\n    if (Caffe::root_solver()) {\n      if (layer_param) {\n        LOG(INFO) << layer_param->name() << \" -> \" << blob_name;\n      } else {\n        LOG(INFO) << \"Input \" << top_id << \" -> \" << blob_name;\n      }\n    }\n    shared_ptr<Blob<Dtype> > blob_pointer(new Blob<Dtype>());\n    const int blob_id = blobs_.size();\n    blobs_.push_back(blob_pointer);\n    blob_names_.push_back(blob_name);\n    blob_need_backward_.push_back(false);\n    if (blob_name_to_idx) { (*blob_name_to_idx)[blob_name] = blob_id; }\n    if (layer_id == -1) {\n      // Set the (explicitly specified) dimensions of the input blob.\n      if (param.input_dim_size() > 0) {\n        blob_pointer->Reshape(param.input_dim(top_id * 4),\n                              param.input_dim(top_id * 4 + 1),\n                              param.input_dim(top_id * 4 + 2),\n                              param.input_dim(top_id * 4 + 3));\n      } else {\n        blob_pointer->Reshape(param.input_shape(top_id));\n      }\n      net_input_blob_indices_.push_back(blob_id);\n      net_input_blobs_.push_back(blob_pointer.get());\n    } else {\n      top_id_vecs_[layer_id].push_back(blob_id);\n      top_vecs_[layer_id].push_back(blob_pointer.get());\n    }\n  }\n  if (available_blobs) { available_blobs->insert(blob_name); }\n}\n\n// Helper for Net::Init: add a new bottom blob to the net.\ntemplate <typename Dtype>\nint Net<Dtype>::AppendBottom(const NetParameter& param, const int layer_id,\n    const int bottom_id, set<string>* available_blobs,\n    map<string, int>* blob_name_to_idx) {\n  const LayerParameter& layer_param = param.layer(layer_id);\n  const string& blob_name = layer_param.bottom(bottom_id);\n  if (available_blobs->find(blob_name) == available_blobs->end()) {\n    LOG(FATAL) << \"Unknown blob input \" << blob_name\n               << \" (at index \" << bottom_id << \") to layer \" << layer_id;\n  }\n  const int blob_id = (*blob_name_to_idx)[blob_name];\n  if (Caffe::root_solver()) {\n    LOG(INFO) << layer_names_[layer_id] << \" <- \" << blob_name;\n  }\n  bottom_vecs_[layer_id].push_back(blobs_[blob_id].get());\n  bottom_id_vecs_[layer_id].push_back(blob_id);\n  available_blobs->erase(blob_name);\n  bool propagate_down = true;\n  // Check if the backpropagation on bottom_id should be skipped\n  if (layer_param.propagate_down_size() > 0)\n    propagate_down = layer_param.propagate_down(bottom_id);\n  const bool need_backward = blob_need_backward_[blob_id] &&\n                          propagate_down;\n  bottom_need_backward_[layer_id].push_back(need_backward);\n  return blob_id;\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::AppendParam(const NetParameter& param, const int layer_id,\n                             const int param_id) {\n  const LayerParameter& layer_param = layers_[layer_id]->layer_param();\n  const int param_size = layer_param.param_size();\n  string param_name =\n      (param_size > param_id) ? layer_param.param(param_id).name() : \"\";\n  if (param_name.size()) {\n    param_display_names_.push_back(param_name);\n  } else {\n    ostringstream param_display_name;\n    param_display_name << param_id;\n    param_display_names_.push_back(param_display_name.str());\n  }\n  const int net_param_id = params_.size();\n  params_.push_back(layers_[layer_id]->blobs()[param_id]);\n  param_id_vecs_[layer_id].push_back(net_param_id);\n  param_layer_indices_.push_back(make_pair(layer_id, param_id));\n  ParamSpec default_param_spec;\n  const ParamSpec* param_spec = (layer_param.param_size() > param_id) ?\n      &layer_param.param(param_id) : &default_param_spec;\n  if (!param_size || !param_name.size() || (param_name.size() &&\n      param_names_index_.find(param_name) == param_names_index_.end())) {\n    // This layer \"owns\" this parameter blob -- it is either anonymous\n    // (i.e., not given a param_name) or explicitly given a name that we\n    // haven't already seen.\n    param_owners_.push_back(-1);\n    if (param_name.size()) {\n      param_names_index_[param_name] = net_param_id;\n    }\n    const int learnable_param_id = learnable_params_.size();\n    learnable_params_.push_back(params_[net_param_id].get());\n    learnable_param_ids_.push_back(learnable_param_id);\n    /************ For dynamic network surgery ***************/\n    if(param_id>=2) {\n      mask_param_ids_.push_back(learnable_param_id);\n    }    \n    /********************************************************/\n    has_params_lr_.push_back(param_spec->has_lr_mult());\n    has_params_decay_.push_back(param_spec->has_decay_mult());\n    params_lr_.push_back(param_spec->lr_mult());\n    params_weight_decay_.push_back(param_spec->decay_mult());\n  } else {\n    // Named param blob with name we've seen before: share params\n    const int owner_net_param_id = param_names_index_[param_name];\n    param_owners_.push_back(owner_net_param_id);\n    const pair<int, int>& owner_index =\n        param_layer_indices_[owner_net_param_id];\n    const int owner_layer_id = owner_index.first;\n    const int owner_param_id = owner_index.second;\n    LOG_IF(INFO, Caffe::root_solver()) << \"Sharing parameters '\" << param_name\n        << \"' owned by \"\n        << \"layer '\" << layer_names_[owner_layer_id] << \"', param \"\n        << \"index \" << owner_param_id;\n    Blob<Dtype>* this_blob = layers_[layer_id]->blobs()[param_id].get();\n    Blob<Dtype>* owner_blob =\n        layers_[owner_layer_id]->blobs()[owner_param_id].get();\n    const int param_size = layer_param.param_size();\n    if (param_size > param_id && (layer_param.param(param_id).share_mode() ==\n                                  ParamSpec_DimCheckMode_PERMISSIVE)) {\n      // Permissive dimension checking -- only check counts are the same.\n      CHECK_EQ(this_blob->count(), owner_blob->count())\n          << \"Shared parameter blobs must have the same count.\";\n    } else {\n      // Strict dimension checking -- all dims must be the same.\n      CHECK(this_blob->shape() == owner_blob->shape());\n    }\n    const int learnable_param_id = learnable_param_ids_[owner_net_param_id];\n    learnable_param_ids_.push_back(learnable_param_id);\n    /************ For dynamic network surgery ***************/\n    if(param_id>=2) {\n      mask_param_ids_.push_back(learnable_param_id);\n    }  \n    /********************************************************/  \n    if (param_spec->has_lr_mult()) {\n      if (has_params_lr_[learnable_param_id]) {\n        CHECK_EQ(param_spec->lr_mult(), params_lr_[learnable_param_id])\n            << \"Shared param '\" << param_name << \"' has mismatched lr_mult.\";\n      } else {\n        has_params_lr_[learnable_param_id] = true;\n        params_lr_[learnable_param_id] = param_spec->lr_mult();\n      }\n    }\n    if (param_spec->has_decay_mult()) {\n      if (has_params_decay_[learnable_param_id]) {\n        CHECK_EQ(param_spec->decay_mult(),\n                 params_weight_decay_[learnable_param_id])\n            << \"Shared param '\" << param_name << \"' has mismatched decay_mult.\";\n      } else {\n        has_params_decay_[learnable_param_id] = true;\n        params_weight_decay_[learnable_param_id] = param_spec->decay_mult();\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nDtype Net<Dtype>::ForwardFromTo(int start, int end) {\n  CHECK_GE(start, 0);\n  CHECK_LT(end, layers_.size());\n  Dtype loss = 0;\n  if (debug_info_) {\n    for (int i = 0; i < net_input_blobs_.size(); ++i) {\n      InputDebugInfo(i);\n    }\n  }\n  for (int i = start; i <= end; ++i) {\n    // LOG(ERROR) << \"Forwarding \" << layer_names_[i];\n    Dtype layer_loss = layers_[i]->Forward(bottom_vecs_[i], top_vecs_[i]);\n    loss += layer_loss;\n    if (debug_info_) { ForwardDebugInfo(i); }\n  }\n  return loss;\n}\n\ntemplate <typename Dtype>\nDtype Net<Dtype>::ForwardFrom(int start) {\n  return ForwardFromTo(start, layers_.size() - 1);\n}\n\ntemplate <typename Dtype>\nDtype Net<Dtype>::ForwardTo(int end) {\n  return ForwardFromTo(0, end);\n}\n\ntemplate <typename Dtype>\nconst vector<Blob<Dtype>*>& Net<Dtype>::ForwardPrefilled(Dtype* loss) {\n  if (loss != NULL) {\n    *loss = ForwardFromTo(0, layers_.size() - 1);\n  } else {\n    ForwardFromTo(0, layers_.size() - 1);\n  }\n  return net_output_blobs_;\n}\n\ntemplate <typename Dtype>\nconst vector<Blob<Dtype>*>& Net<Dtype>::Forward(\n    const vector<Blob<Dtype>*> & bottom, Dtype* loss) {\n  // Copy bottom to internal bottom\n  for (int i = 0; i < bottom.size(); ++i) {\n    net_input_blobs_[i]->CopyFrom(*bottom[i]);\n  }\n  return ForwardPrefilled(loss);\n}\n\ntemplate <typename Dtype>\nstring Net<Dtype>::Forward(const string& input_blob_protos, Dtype* loss) {\n  BlobProtoVector blob_proto_vec;\n  if (net_input_blobs_.size()) {\n    blob_proto_vec.ParseFromString(input_blob_protos);\n    CHECK_EQ(blob_proto_vec.blobs_size(), net_input_blobs_.size())\n        << \"Incorrect input size.\";\n    for (int i = 0; i < blob_proto_vec.blobs_size(); ++i) {\n      net_input_blobs_[i]->FromProto(blob_proto_vec.blobs(i));\n    }\n  }\n  ForwardPrefilled(loss);\n  blob_proto_vec.Clear();\n  for (int i = 0; i < net_output_blobs_.size(); ++i) {\n    net_output_blobs_[i]->ToProto(blob_proto_vec.add_blobs());\n  }\n  string output;\n  blob_proto_vec.SerializeToString(&output);\n  return output;\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::BackwardFromTo(int start, int end) {\n  CHECK_GE(end, 0);\n  CHECK_LT(start, layers_.size());\n  for (int i = start; i >= end; --i) {\n    if (layer_need_backward_[i]) {\n      layers_[i]->Backward(\n          top_vecs_[i], bottom_need_backward_[i], bottom_vecs_[i]);\n      if (debug_info_) { BackwardDebugInfo(i); }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::InputDebugInfo(const int input_id) {\n  const Blob<Dtype>& blob = *net_input_blobs_[input_id];\n  const string& blob_name = blob_names_[net_input_blob_indices_[input_id]];\n  const Dtype data_abs_val_mean = blob.asum_data() / blob.count();\n  if (Caffe::root_solver()) {\n    LOG(INFO) << \"    [Forward] \"\n              << \"Input \" << blob_name << \" data: \" << data_abs_val_mean;\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::ForwardDebugInfo(const int layer_id) {\n  for (int top_id = 0; top_id < top_vecs_[layer_id].size(); ++top_id) {\n    const Blob<Dtype>& blob = *top_vecs_[layer_id][top_id];\n    const string& blob_name = blob_names_[top_id_vecs_[layer_id][top_id]];\n    const Dtype data_abs_val_mean = blob.asum_data() / blob.count();\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"    [Forward] \"\n                << \"Layer \" << layer_names_[layer_id]\n                << \", top blob \" << blob_name\n                << \" data: \" << data_abs_val_mean;\n    }\n  }\n  for (int param_id = 0; param_id < layers_[layer_id]->blobs().size();\n       ++param_id) {\n    const Blob<Dtype>& blob = *layers_[layer_id]->blobs()[param_id];\n    const int net_param_id = param_id_vecs_[layer_id][param_id];\n    const string& blob_name = param_display_names_[net_param_id];\n    const Dtype data_abs_val_mean = blob.asum_data() / blob.count();\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"    [Forward] \"\n                << \"Layer \" << layer_names_[layer_id]\n                << \", param blob \" << blob_name\n                << \" data: \" << data_abs_val_mean;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::BackwardDebugInfo(const int layer_id) {\n  const vector<Blob<Dtype>*>& bottom_vec = bottom_vecs_[layer_id];\n  for (int bottom_id = 0; bottom_id < bottom_vec.size(); ++bottom_id) {\n    if (!bottom_need_backward_[layer_id][bottom_id]) { continue; }\n    const Blob<Dtype>& blob = *bottom_vec[bottom_id];\n    const string& blob_name = blob_names_[bottom_id_vecs_[layer_id][bottom_id]];\n    const Dtype diff_abs_val_mean = blob.asum_diff() / blob.count();\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"    [Backward] \"\n                << \"Layer \" << layer_names_[layer_id]\n                << \", bottom blob \" << blob_name\n                << \" diff: \" << diff_abs_val_mean;\n    }\n  }\n  for (int param_id = 0; param_id < layers_[layer_id]->blobs().size();\n       ++param_id) {\n    if (!layers_[layer_id]->param_propagate_down(param_id)) { continue; }\n    const Blob<Dtype>& blob = *layers_[layer_id]->blobs()[param_id];\n    const Dtype diff_abs_val_mean = blob.asum_diff() / blob.count();\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"    [Backward] \"\n                << \"Layer \" << layer_names_[layer_id]\n                << \", param blob \" << param_id\n                << \" diff: \" << diff_abs_val_mean;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::UpdateDebugInfo(const int param_id) {\n  const Blob<Dtype>& blob = *params_[param_id];\n  const int param_owner = param_owners_[param_id];\n  const string& layer_name = layer_names_[param_layer_indices_[param_id].first];\n  const string& param_display_name = param_display_names_[param_id];\n  const Dtype diff_abs_val_mean = blob.asum_diff() / blob.count();\n  if (param_owner < 0) {\n    const Dtype data_abs_val_mean = blob.asum_data() / blob.count();\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"    [Update] Layer \" << layer_name\n                << \", param \" << param_display_name\n                << \" data: \" << data_abs_val_mean\n                << \"; diff: \" << diff_abs_val_mean;\n    }\n  } else {\n    const string& owner_layer_name =\n        layer_names_[param_layer_indices_[param_owner].first];\n    if (Caffe::root_solver()) {\n      LOG(INFO) << \"    [Update] Layer \" << layer_name\n                << \", param blob \" << param_display_name\n                << \" (owned by layer \" << owner_layer_name << \", \" << \"param \"\n                << param_display_names_[param_owners_[param_id]] << \")\"\n                << \" diff: \" << diff_abs_val_mean;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::ShareTrainedLayersWith(const Net* other) {\n  int num_source_layers = other->layers().size();\n  for (int i = 0; i < num_source_layers; ++i) {\n    Layer<Dtype>* source_layer = other->layers()[i].get();\n    const string& source_layer_name = other->layer_names()[i];\n    int target_layer_id = 0;\n    while (target_layer_id != layer_names_.size() &&\n        layer_names_[target_layer_id] != source_layer_name) {\n      ++target_layer_id;\n    }\n    if (target_layer_id == layer_names_.size()) {\n      DLOG(INFO) << \"Ignoring source layer \" << source_layer_name;\n      continue;\n    }\n    DLOG(INFO) << \"Copying source layer \" << source_layer_name;\n    vector<shared_ptr<Blob<Dtype> > >& target_blobs =\n        layers_[target_layer_id]->blobs();\n    CHECK_EQ(target_blobs.size(), source_layer->blobs().size())\n        << \"Incompatible number of blobs for layer \" << source_layer_name;\n    for (int j = 0; j < target_blobs.size(); ++j) {\n      Blob<Dtype>* source_blob = source_layer->blobs()[j].get();\n      CHECK(target_blobs[j]->shape() == source_blob->shape());\n      target_blobs[j]->ShareData(*source_blob);\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::BackwardFrom(int start) {\n  BackwardFromTo(start, 0);\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::BackwardTo(int end) {\n  BackwardFromTo(layers_.size() - 1, end);\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::Backward() {\n  BackwardFromTo(layers_.size() - 1, 0);\n  if (debug_info_) {\n    Dtype asum_data = 0, asum_diff = 0, sumsq_data = 0, sumsq_diff = 0;\n    for (int i = 0; i < params_.size(); ++i) {\n      if (param_owners_[i] >= 0) { continue; }\n      asum_data += params_[i]->asum_data();\n      asum_diff += params_[i]->asum_diff();\n      sumsq_data += params_[i]->sumsq_data();\n      sumsq_diff += params_[i]->sumsq_diff();\n    }\n    const Dtype l2norm_data = std::sqrt(sumsq_data);\n    const Dtype l2norm_diff = std::sqrt(sumsq_diff);\n    LOG(ERROR) << \"    [Backward] All net params (data, diff): \"\n               << \"L1 norm = (\" << asum_data << \", \" << asum_diff << \"); \"\n               << \"L2 norm = (\" << l2norm_data << \", \" << l2norm_diff << \")\";\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::Reshape() {\n  for (int i = 0; i < layers_.size(); ++i) {\n    layers_[i]->Reshape(bottom_vecs_[i], top_vecs_[i]);\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::CopyTrainedLayersFrom(const NetParameter& param) {\n  int num_source_layers = param.layer_size();\n  for (int i = 0; i < num_source_layers; ++i) {\n    const LayerParameter& source_layer = param.layer(i);\n    const string& source_layer_name = source_layer.name();\n    int target_layer_id = 0;\n    while (target_layer_id != layer_names_.size() &&\n        layer_names_[target_layer_id] != source_layer_name) {\n      ++target_layer_id;\n    }\n    if (target_layer_id == layer_names_.size()) {\n      DLOG(INFO) << \"Ignoring source layer \" << source_layer_name;\n      continue;\n    }\n    DLOG(INFO) << \"Copying source layer \" << source_layer_name;\n    vector<shared_ptr<Blob<Dtype> > >& target_blobs =\n        layers_[target_layer_id]->blobs();\n        \n    /************ For dynamic network surgery ***************/\n    if (strcmp(layers_[target_layer_id]->type(),\"CInnerProduct\")==0 || strcmp(layers_[target_layer_id]->type(),\"CConvolution\" )==0 ) {\n      if(target_blobs.size() > source_layer.blobs_size()) {\n        for (int j = 0; j < source_layer.blobs_size(); ++j) {\n          const bool kReshape = false;\n          target_blobs[j]->FromProto(source_layer.blobs(j), kReshape);\n        }\n        continue;\n      }\n    }     \n    /********************************************************/    \n    CHECK_EQ(target_blobs.size(), source_layer.blobs_size())\n        << \"Incompatible number of blobs for layer \" << source_layer_name;\n    for (int j = 0; j < target_blobs.size(); ++j) {\n      const bool kReshape = false;\n      target_blobs[j]->FromProto(source_layer.blobs(j), kReshape);\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::CopyTrainedLayersFrom(const string trained_filename) {\n  if (trained_filename.size() >= 3 &&\n      trained_filename.compare(trained_filename.size() - 3, 3, \".h5\") == 0) {\n    CopyTrainedLayersFromHDF5(trained_filename);\n  } else {\n    CopyTrainedLayersFromBinaryProto(trained_filename);\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::CopyTrainedLayersFromBinaryProto(\n    const string trained_filename) {\n  NetParameter param;\n  ReadNetParamsFromBinaryFileOrDie(trained_filename, &param);\n  CopyTrainedLayersFrom(param);\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::CopyTrainedLayersFromHDF5(const string trained_filename) {\n  hid_t file_hid = H5Fopen(trained_filename.c_str(), H5F_ACC_RDONLY,\n                           H5P_DEFAULT);\n  CHECK_GE(file_hid, 0) << \"Couldn't open \" << trained_filename;\n  hid_t data_hid = H5Gopen2(file_hid, \"data\", H5P_DEFAULT);\n  CHECK_GE(data_hid, 0) << \"Error reading weights from \" << trained_filename;\n  int num_layers = hdf5_get_num_links(data_hid);\n  for (int i = 0; i < num_layers; ++i) {\n    string source_layer_name = hdf5_get_name_by_idx(data_hid, i);\n    if (!layer_names_index_.count(source_layer_name)) {\n      DLOG(INFO) << \"Ignoring source layer \" << source_layer_name;\n      continue;\n    }\n    int target_layer_id = layer_names_index_[source_layer_name];\n    DLOG(INFO) << \"Copying source layer \" << source_layer_name;\n    vector<shared_ptr<Blob<Dtype> > >& target_blobs =\n        layers_[target_layer_id]->blobs();\n    hid_t layer_hid = H5Gopen2(data_hid, source_layer_name.c_str(),\n        H5P_DEFAULT);\n    CHECK_GE(layer_hid, 0)\n        << \"Error reading weights from \" << trained_filename;\n    // Check that source layer doesn't have more params than target layer\n    int num_source_params = hdf5_get_num_links(layer_hid);\n    CHECK_LE(num_source_params, target_blobs.size())\n        << \"Incompatible number of blobs for layer \" << source_layer_name;\n    for (int j = 0; j < target_blobs.size(); ++j) {\n      ostringstream oss;\n      oss << j;\n      string dataset_name = oss.str();\n      int target_net_param_id = param_id_vecs_[target_layer_id][j];\n      if (!H5Lexists(layer_hid, dataset_name.c_str(), H5P_DEFAULT)) {\n        // Target param doesn't exist in source weights...\n        if (param_owners_[target_net_param_id] != -1) {\n          // ...but it's weight-shared in target, so that's fine.\n          continue;\n        } else {\n          LOG(FATAL) << \"Incompatible number of blobs for layer \"\n              << source_layer_name;\n        }\n      }\n      hdf5_load_nd_dataset(layer_hid, dataset_name.c_str(), 0, kMaxBlobAxes,\n          target_blobs[j].get());\n    }\n    H5Gclose(layer_hid);\n  }\n  H5Gclose(data_hid);\n  H5Fclose(file_hid);\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::ToProto(NetParameter* param, bool write_diff) const {\n  param->Clear();\n  param->set_name(name_);\n  // Add bottom and top\n  for (int i = 0; i < net_input_blob_indices_.size(); ++i) {\n    param->add_input(blob_names_[net_input_blob_indices_[i]]);\n  }\n  DLOG(INFO) << \"Serializing \" << layers_.size() << \" layers\";\n  for (int i = 0; i < layers_.size(); ++i) {\n    LayerParameter* layer_param = param->add_layer();\n    for (int j = 0; j < bottom_id_vecs_[i].size(); ++j) {\n      layer_param->add_bottom(blob_names_[bottom_id_vecs_[i][j]]);\n    }\n    for (int j = 0; j < top_id_vecs_[i].size(); ++j) {\n      layer_param->add_top(blob_names_[top_id_vecs_[i][j]]);\n    }\n    layers_[i]->ToProto(layer_param, write_diff);\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::ToHDF5(const string& filename, bool write_diff) const {\n  hid_t file_hid = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,\n      H5P_DEFAULT);\n  CHECK_GE(file_hid, 0)\n      << \"Couldn't open \" << filename << \" to save weights.\";\n  hid_t data_hid = H5Gcreate2(file_hid, \"data\", H5P_DEFAULT, H5P_DEFAULT,\n      H5P_DEFAULT);\n  CHECK_GE(data_hid, 0) << \"Error saving weights to \" << filename << \".\";\n  hid_t diff_hid = -1;\n  if (write_diff) {\n    diff_hid = H5Gcreate2(file_hid, \"diff\", H5P_DEFAULT, H5P_DEFAULT,\n        H5P_DEFAULT);\n    CHECK_GE(diff_hid, 0) << \"Error saving weights to \" << filename << \".\";\n  }\n  for (int layer_id = 0; layer_id < layers_.size(); ++layer_id) {\n    const LayerParameter& layer_param = layers_[layer_id]->layer_param();\n    string layer_name = layer_param.name();\n    hid_t layer_data_hid = H5Gcreate2(data_hid, layer_name.c_str(),\n        H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);\n    CHECK_GE(layer_data_hid, 0)\n        << \"Error saving weights to \" << filename << \".\";\n    hid_t layer_diff_hid = -1;\n    if (write_diff) {\n      layer_diff_hid = H5Gcreate2(diff_hid, layer_name.c_str(),\n          H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);\n      CHECK_GE(layer_diff_hid, 0)\n          << \"Error saving weights to \" << filename << \".\";\n    }\n    int num_params = layers_[layer_id]->blobs().size();\n    for (int param_id = 0; param_id < num_params; ++param_id) {\n      ostringstream dataset_name;\n      dataset_name << param_id;\n      const int net_param_id = param_id_vecs_[layer_id][param_id];\n      if (param_owners_[net_param_id] == -1) {\n        // Only save params that own themselves\n        hdf5_save_nd_dataset<Dtype>(layer_data_hid, dataset_name.str(),\n            *params_[net_param_id]);\n      }\n      if (write_diff) {\n        // Write diffs regardless of weight-sharing\n        hdf5_save_nd_dataset<Dtype>(layer_diff_hid, dataset_name.str(),\n            *params_[net_param_id], true);\n      }\n    }\n    H5Gclose(layer_data_hid);\n    if (write_diff) {\n      H5Gclose(layer_diff_hid);\n    }\n  }\n  H5Gclose(data_hid);\n  if (write_diff) {\n    H5Gclose(diff_hid);\n  }\n  H5Fclose(file_hid);\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::Update() {\n  for (int i = 0; i < learnable_params_.size(); ++i) {\n  \t/************ For dynamic network surgery ***************/\n    if (std::find(mask_param_ids_.begin(), mask_param_ids_.end(),\n\t\t\t\t\t\t\t\t\tlearnable_param_ids_[i]) != mask_param_ids_.end())\n      continue; \n    /********************************************************/         \n    learnable_params_[i]->Update();\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::ClearParamDiffs() {\n  for (int i = 0; i < learnable_params_.size(); ++i) {\n    Blob<Dtype>* blob = learnable_params_[i];\n    switch (Caffe::mode()) {\n    case Caffe::CPU:\n      caffe_set(blob->count(), static_cast<Dtype>(0),\n                blob->mutable_cpu_diff());\n      break;\n    case Caffe::GPU:\n#ifndef CPU_ONLY\n      caffe_gpu_set(blob->count(), static_cast<Dtype>(0),\n                    blob->mutable_gpu_diff());\n#else\n      NO_GPU;\n#endif\n      break;\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid Net<Dtype>::ShareWeights() {\n  for (int i = 0; i < params_.size(); ++i) {\n    if (param_owners_[i] < 0) { continue; }\n    params_[i]->ShareData(*params_[param_owners_[i]]);\n    params_[i]->ShareDiff(*params_[param_owners_[i]]);\n  }\n}\n\ntemplate <typename Dtype>\nbool Net<Dtype>::has_blob(const string& blob_name) const {\n  return blob_names_index_.find(blob_name) != blob_names_index_.end();\n}\n\ntemplate <typename Dtype>\nconst shared_ptr<Blob<Dtype> > Net<Dtype>::blob_by_name(\n    const string& blob_name) const {\n  shared_ptr<Blob<Dtype> > blob_ptr;\n  if (has_blob(blob_name)) {\n    blob_ptr = blobs_[blob_names_index_.find(blob_name)->second];\n  } else {\n    blob_ptr.reset((Blob<Dtype>*)(NULL));\n    LOG(WARNING) << \"Unknown blob name \" << blob_name;\n  }\n  return blob_ptr;\n}\n\ntemplate <typename Dtype>\nbool Net<Dtype>::has_layer(const string& layer_name) const {\n  return layer_names_index_.find(layer_name) != layer_names_index_.end();\n}\n\ntemplate <typename Dtype>\nconst shared_ptr<Layer<Dtype> > Net<Dtype>::layer_by_name(\n    const string& layer_name) const {\n  shared_ptr<Layer<Dtype> > layer_ptr;\n  if (has_layer(layer_name)) {\n    layer_ptr = layers_[layer_names_index_.find(layer_name)->second];\n  } else {\n    layer_ptr.reset((Layer<Dtype>*)(NULL));\n    LOG(WARNING) << \"Unknown layer name \" << layer_name;\n  }\n  return layer_ptr;\n}\n\nINSTANTIATE_CLASS(Net);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/parallel.cpp",
    "content": "#ifndef CPU_ONLY\n#include <cuda_runtime.h>\n#endif\n#include <glog/logging.h>\n#include <stdio.h>\n#include <sys/ioctl.h>\n#include <sys/mman.h>\n#include <sys/stat.h>\n\n#include <cstdlib>\n#include <sstream>\n#include <string>\n#include <vector>\n\n#include \"boost/thread.hpp\"\n#include \"caffe/caffe.hpp\"\n#include \"caffe/parallel.hpp\"\n\nnamespace caffe {\n\nenum Op {\n  copy,\n  replace_cpu,\n  replace_gpu,\n  replace_cpu_diff,\n  replace_gpu_diff\n};\n\ntemplate<typename Dtype>\nstatic void apply_buffers(const vector<Blob<Dtype>*>& blobs,\n                          Dtype* buffer, size_t total_size, Op op) {\n  Dtype* ptr = buffer;\n  for (int i = 0; i < blobs.size(); ++i) {\n    int size = blobs[i]->count();\n    switch (op) {\n      case copy: {\n        // Init buffer to current values of blobs\n        caffe_copy(size,\n                   reinterpret_cast<const Dtype*>(blobs[i]->data()->cpu_data()),\n                   ptr);\n        break;\n      }\n      case replace_cpu:\n        blobs[i]->data()->set_cpu_data(ptr);\n        break;\n      case replace_gpu:\n        blobs[i]->data()->set_gpu_data(ptr);\n        break;\n      case replace_cpu_diff:\n        blobs[i]->diff()->set_cpu_data(ptr);\n        break;\n      case replace_gpu_diff:\n        blobs[i]->diff()->set_gpu_data(ptr);\n        break;\n    }\n    ptr += size;\n  }\n  // total_size is at least one byte\n  CHECK_EQ(total_size, (ptr == buffer ? 1 : ptr - buffer));\n}\n\n// Buffer size necessary to store given blobs\ntemplate<typename Dtype>\nstatic size_t total_size(const vector<Blob<Dtype>*>& params) {\n  size_t size = 0;\n  for (int i = 0; i < params.size(); ++i)\n    size += params[i]->count();\n  // Size have at least one byte, otherwise cudaMalloc fails if net has no\n  // learnable parameters.\n  return (size > 0) ? size : 1;\n}\n\ntemplate<typename Dtype>\nParams<Dtype>::Params(shared_ptr<Solver<Dtype> > root_solver)\n    : size_(total_size<Dtype>(root_solver->net()->learnable_params())),\n      data_(),\n      diff_() {\n}\n\ntemplate<typename Dtype>\nGPUParams<Dtype>::GPUParams(shared_ptr<Solver<Dtype> > root_solver, int device)\n    : Params<Dtype>(root_solver) {\n#ifndef CPU_ONLY\n  int initial_device;\n  CUDA_CHECK(cudaGetDevice(&initial_device));\n\n  // Allocate device buffers\n  CUDA_CHECK(cudaSetDevice(device));\n  CUDA_CHECK(cudaMalloc(&data_, size_ * sizeof(Dtype)));\n\n  // Copy blob values\n  const vector<Blob<Dtype>*>& net =\n      root_solver->net()->learnable_params();\n  apply_buffers(net, data_, size_, copy);\n\n  CUDA_CHECK(cudaMalloc(&diff_, size_ * sizeof(Dtype)));\n  caffe_gpu_set(size_, Dtype(0), diff_);\n\n  CUDA_CHECK(cudaSetDevice(initial_device));\n#else\n  NO_GPU;\n#endif\n}\n\ntemplate<typename Dtype>\nGPUParams<Dtype>::~GPUParams() {\n#ifndef CPU_ONLY\n  CUDA_CHECK(cudaFree(data_));\n  CUDA_CHECK(cudaFree(diff_));\n#endif\n}\n\ntemplate<typename Dtype>\nvoid GPUParams<Dtype>::configure(Solver<Dtype>* solver) const {\n  const vector<Blob<Dtype>*>& net =\n      solver->net()->learnable_params();\n  apply_buffers(net, data_, size_, replace_gpu);\n  apply_buffers(net, diff_, size_, replace_gpu_diff);\n}\n\nvoid DevicePair::compute(const vector<int> devices, vector<DevicePair>* pairs) {\n#ifndef CPU_ONLY\n  vector<int> remaining(devices);\n\n  // Depth for reduction tree\n  int remaining_depth = static_cast<int>(ceil(log2(remaining.size())));\n\n  // Group GPUs by board\n  for (int d = 0; d < remaining_depth; ++d) {\n    for (int i = 0; i < remaining.size(); ++i) {\n      for (int j = i + 1; j < remaining.size(); ++j) {\n        cudaDeviceProp a, b;\n        CUDA_CHECK(cudaGetDeviceProperties(&a, remaining[i]));\n        CUDA_CHECK(cudaGetDeviceProperties(&b, remaining[j]));\n        if (a.isMultiGpuBoard && b.isMultiGpuBoard) {\n          if (a.multiGpuBoardGroupID == b.multiGpuBoardGroupID) {\n            pairs->push_back(DevicePair(remaining[i], remaining[j]));\n            DLOG(INFO) << \"GPU board: \" << remaining[i] << \":\" << remaining[j];\n            remaining.erase(remaining.begin() + j);\n            break;\n          }\n        }\n      }\n    }\n  }\n  ostringstream s;\n  for (int i = 0; i < remaining.size(); ++i) {\n    s << (i ? \", \" : \"\") << remaining[i];\n  }\n  DLOG(INFO) << \"GPUs paired by boards, remaining: \" << s.str();\n\n  // Group by P2P accessibility\n  remaining_depth = ceil(log2(remaining.size()));\n  for (int d = 0; d < remaining_depth; ++d) {\n    for (int i = 0; i < remaining.size(); ++i) {\n      for (int j = i + 1; j < remaining.size(); ++j) {\n        int access;\n        CUDA_CHECK(\n            cudaDeviceCanAccessPeer(&access, remaining[i], remaining[j]));\n        if (access) {\n          pairs->push_back(DevicePair(remaining[i], remaining[j]));\n          DLOG(INFO) << \"P2P pair: \" << remaining[i] << \":\" << remaining[j];\n          remaining.erase(remaining.begin() + j);\n          break;\n        }\n      }\n    }\n  }\n  s.str(\"\");\n  for (int i = 0; i < remaining.size(); ++i) {\n    s << (i ? \", \" : \"\") << remaining[i];\n  }\n  DLOG(INFO) << \"GPUs paired by P2P access, remaining: \" << s.str();\n\n  // Group remaining\n  remaining_depth = ceil(log2(remaining.size()));\n  for (int d = 0; d < remaining_depth; ++d) {\n    for (int i = 0; i < remaining.size(); ++i) {\n      pairs->push_back(DevicePair(remaining[i], remaining[i + 1]));\n      DLOG(INFO) << \"Remaining pair: \" << remaining[i] << \":\"\n                 << remaining[i + 1];\n      remaining.erase(remaining.begin() + i + 1);\n    }\n  }\n\n  // Should only be the parent node remaining\n  CHECK_EQ(remaining.size(), 1);\n\n  pairs->insert(pairs->begin(), DevicePair(-1, remaining[0]));\n\n  CHECK(pairs->size() == devices.size());\n  for (int i = 0; i < pairs->size(); ++i) {\n    CHECK((*pairs)[i].parent() != (*pairs)[i].device());\n    for (int j = i + 1; j < pairs->size(); ++j) {\n      CHECK((*pairs)[i].device() != (*pairs)[j].device());\n    }\n  }\n#else\n  NO_GPU;\n#endif\n}\n\n//\n\ntemplate<typename Dtype>\nP2PSync<Dtype>::P2PSync(shared_ptr<Solver<Dtype> > root_solver,\n                        P2PSync<Dtype>* parent, const SolverParameter& param)\n    : GPUParams<Dtype>(root_solver, param.device_id()),\n      parent_(parent),\n      children_(),\n      queue_(),\n      initial_iter_(root_solver->iter()),\n      solver_() {\n#ifndef CPU_ONLY\n  int initial_device;\n  CUDA_CHECK(cudaGetDevice(&initial_device));\n  const int self = param.device_id();\n  CUDA_CHECK(cudaSetDevice(self));\n\n  if (parent == NULL) {\n    solver_ = root_solver;\n  } else {\n    Caffe::set_root_solver(false);\n    solver_.reset(new WorkerSolver<Dtype>(param, root_solver.get()));\n    Caffe::set_root_solver(true);\n  }\n  this->configure(solver_.get());\n  solver_->add_callback(this);\n\n  if (parent) {\n    // Enable p2p access between devices\n    const int peer = parent->solver_->param().device_id();\n    int access;\n    CUDA_CHECK(cudaDeviceCanAccessPeer(&access, self, peer));\n    if (access) {\n      CUDA_CHECK(cudaDeviceEnablePeerAccess(peer, 0));\n    } else {\n      LOG(INFO)<< \"GPU \" << self << \" does not have p2p access to GPU \" << peer;\n    }\n    // Allocate receiving buffer on parent\n    CUDA_CHECK(cudaSetDevice(peer));\n    CUDA_CHECK(cudaMalloc(&parent_grads_, size_ * sizeof(Dtype)));\n    CUDA_CHECK(cudaSetDevice(self));\n  }\n\n  CUDA_CHECK(cudaSetDevice(initial_device));\n#else\n  NO_GPU;\n#endif\n}\n\ntemplate<typename Dtype>\nP2PSync<Dtype>::~P2PSync() {\n#ifndef CPU_ONLY\n  int initial_device;\n  CUDA_CHECK(cudaGetDevice(&initial_device));\n  const int self = solver_->param().device_id();\n  CUDA_CHECK(cudaSetDevice(self));\n\n  if (parent_) {\n    CUDA_CHECK(cudaFree(parent_grads_));\n    const int peer = parent_->solver_->param().device_id();\n    int access;\n    CUDA_CHECK(cudaDeviceCanAccessPeer(&access, self, peer));\n    if (access) {\n      CUDA_CHECK(cudaDeviceDisablePeerAccess(peer));\n    }\n  }\n\n  CUDA_CHECK(cudaSetDevice(initial_device));\n#endif\n}\n\ntemplate<typename Dtype>\nvoid P2PSync<Dtype>::InternalThreadEntry() {\n  Caffe::SetDevice(solver_->param().device_id());\n  CHECK(Caffe::root_solver());\n  Caffe::set_root_solver(false);\n  // See if there is a defined seed and reset random state if so\n  if (solver_->param().random_seed() >= 0) {\n    // Fetch random seed and modulate by device ID to make sure\n    // everyone doesn't have the same seed.  We seem to have some\n    // solver instability if we have everyone with the same seed\n    Caffe::set_random_seed(\n        solver_->param().random_seed() + solver_->param().device_id());\n  }\n  solver_->Step(solver_->param().max_iter() - initial_iter_);\n}\n\ntemplate<typename Dtype>\nvoid P2PSync<Dtype>::on_start() {\n#ifndef CPU_ONLY\n#ifdef DEBUG\n  int device;\n  CUDA_CHECK(cudaGetDevice(&device));\n  CHECK(device == solver_->param().device_id());\n#else\n//  CHECK(false);\n#endif\n\n  // Wait for update from parent\n  if (parent_) {\n    P2PSync<Dtype> *parent = queue_.pop();\n    CHECK(parent == parent_);\n  }\n\n  // Update children\n  for (int i = children_.size() - 1; i >= 0; i--) {\n    Dtype* src = data_;\n    Dtype* dst = children_[i]->data_;\n\n#ifdef DEBUG\n    cudaPointerAttributes attributes;\n    CUDA_CHECK(cudaPointerGetAttributes(&attributes, src));\n    CHECK(attributes.device == device);\n    CUDA_CHECK(cudaPointerGetAttributes(&attributes, dst));\n    CHECK(attributes.device == children_[i]->solver_->param().device_id());\n#endif\n\n    CUDA_CHECK(cudaMemcpyAsync(dst, src, size_ * sizeof(Dtype),\n        cudaMemcpyDeviceToDevice, cudaStreamDefault));\n    CUDA_CHECK(cudaStreamSynchronize(cudaStreamDefault));\n    children_[i]->queue_.push(this);\n  }\n#endif\n}\n\ntemplate<typename Dtype>\nvoid P2PSync<Dtype>::on_gradients_ready() {\n#ifndef CPU_ONLY\n#ifdef DEBUG\n  int device;\n  CUDA_CHECK(cudaGetDevice(&device));\n  CHECK(device == solver_->param().device_id());\n#endif\n\n  // Sum children gradients as they appear in the queue\n  for (int i = 0; i < children_.size(); ++i) {\n    P2PSync<Dtype> *child = queue_.pop();\n    Dtype* src = child->parent_grads_;\n    Dtype* dst = diff_;\n\n#ifdef DEBUG\n    bool ok = false;\n    for (int j = 0; j < children_.size(); ++j) {\n      if (child == children_[j]) {\n        ok = true;\n      }\n    }\n    CHECK(ok);\n    cudaPointerAttributes attributes;\n    CUDA_CHECK(cudaPointerGetAttributes(&attributes, src));\n    CHECK(attributes.device == device);\n    CUDA_CHECK(cudaPointerGetAttributes(&attributes, dst));\n    CHECK(attributes.device == device);\n#endif\n\n    caffe_gpu_add(size_, src, dst, dst);\n  }\n\n  // Send gradients to parent\n  if (parent_) {\n    Dtype* src = diff_;\n    Dtype* dst = parent_grads_;\n\n#ifdef DEBUG\n    cudaPointerAttributes attributes;\n    CUDA_CHECK(cudaPointerGetAttributes(&attributes, src));\n    CHECK(attributes.device == device);\n    CUDA_CHECK(cudaPointerGetAttributes(&attributes, dst));\n    CHECK(attributes.device == parent_->solver_->param().device_id());\n#endif\n\n    CUDA_CHECK(cudaMemcpyAsync(dst, src, size_ * sizeof(Dtype),  //\n        cudaMemcpyDeviceToDevice, cudaStreamDefault));\n    CUDA_CHECK(cudaStreamSynchronize(cudaStreamDefault));\n    parent_->queue_.push(this);\n  } else {\n    // Loss functions divide gradients by the batch size, so to compensate\n    // for split batch, the root solver divides by number of solvers.\n    caffe_gpu_scal(size_, Dtype(1.0 / Caffe::solver_count()), diff_);\n  }\n#endif\n}\n\ntemplate<typename Dtype>\nvoid P2PSync<Dtype>::run(const vector<int>& gpus) {\n  // Pair devices for map-reduce synchronization\n  vector<DevicePair> pairs;\n  DevicePair::compute(gpus, &pairs);\n  ostringstream s;\n  for (int i = 1; i < pairs.size(); ++i) {\n    s << (i == 1 ? \"\" : \", \") << pairs[i].parent() << \":\" << pairs[i].device();\n  }\n  LOG(INFO)<< \"GPUs pairs \" << s.str();\n\n  SolverParameter param(solver_->param());\n  vector<shared_ptr<P2PSync<Dtype> > > syncs(gpus.size());\n\n  // Build the GPU tree by finding the parent for each solver\n  for (int attempts = 0; attempts < pairs.size(); ++attempts) {\n    for (int i = 1; i < pairs.size(); ++i) {\n      if (!syncs[i].get()) {\n        P2PSync<Dtype>* parent = NULL;\n        for (int j = 0; j < syncs.size(); ++j) {\n          P2PSync<Dtype>* sync = j == 0 ? this : syncs[j].get();\n          if (sync) {\n            const SolverParameter& p = sync->solver()->param();\n            if (p.device_id() == pairs[i].parent()) {\n              parent = sync;\n            }\n          }\n        }\n        if (parent) {\n          param.set_device_id(pairs[i].device());\n          syncs[i].reset(new P2PSync<Dtype>(solver_, parent, param));\n          parent->children_.push_back((P2PSync<Dtype>*) syncs[i].get());\n        }\n      }\n    }\n  }\n\n  LOG(INFO)<< \"Starting Optimization\";\n\n  for (int i = 1; i < syncs.size(); ++i) {\n    syncs[i]->StartInternalThread();\n  }\n\n  // Run root solver on current thread\n  solver_->Solve();\n\n  for (int i = 1; i < syncs.size(); ++i) {\n    syncs[i]->StopInternalThread();\n  }\n}\n\nINSTANTIATE_CLASS(Params);\nINSTANTIATE_CLASS(GPUParams);\nINSTANTIATE_CLASS(P2PSync);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/proto/caffe.proto",
    "content": "syntax = \"proto2\";\n\npackage caffe;\n\n// Specifies the shape (dimensions) of a Blob.\nmessage BlobShape {\n  repeated int64 dim = 1 [packed = true];\n}\n\nmessage BlobProto {\n  optional BlobShape shape = 7;\n  repeated float data = 5 [packed = true];\n  repeated float diff = 6 [packed = true];\n  repeated double double_data = 8 [packed = true];\n  repeated double double_diff = 9 [packed = true];\n\n  // 4D dimensions -- deprecated.  Use \"shape\" instead.\n  optional int32 num = 1 [default = 0];\n  optional int32 channels = 2 [default = 0];\n  optional int32 height = 3 [default = 0];\n  optional int32 width = 4 [default = 0];\n}\n\n// The BlobProtoVector is simply a way to pass multiple blobproto instances\n// around.\nmessage BlobProtoVector {\n  repeated BlobProto blobs = 1;\n}\n\nmessage Datum {\n  optional int32 channels = 1;\n  optional int32 height = 2;\n  optional int32 width = 3;\n  // the actual image data, in bytes\n  optional bytes data = 4;\n  optional int32 label = 5;\n  // Optionally, the datum could also hold float data.\n  repeated float float_data = 6;\n  // If true data contains an encoded image that need to be decoded\n  optional bool encoded = 7 [default = false];\n}\n\nmessage FillerParameter {\n  // The filler type.\n  optional string type = 1 [default = 'constant'];\n  optional float value = 2 [default = 0]; // the value in constant filler\n  optional float min = 3 [default = 0]; // the min value in uniform filler\n  optional float max = 4 [default = 1]; // the max value in uniform filler\n  optional float mean = 5 [default = 0]; // the mean value in Gaussian filler\n  optional float std = 6 [default = 1]; // the std value in Gaussian filler\n  // The expected number of non-zero output weights for a given input in\n  // Gaussian filler -- the default -1 means don't perform sparsification.\n  optional int32 sparse = 7 [default = -1];\n  // Normalize the filler variance by fan_in, fan_out, or their average.\n  // Applies to 'xavier' and 'msra' fillers.\n  enum VarianceNorm {\n    FAN_IN = 0;\n    FAN_OUT = 1;\n    AVERAGE = 2;\n  }\n  optional VarianceNorm variance_norm = 8 [default = FAN_IN];\n}\n\nmessage NetParameter {\n  optional string name = 1; // consider giving the network a name\n  // The input blobs to the network.\n  repeated string input = 3;\n  // The shape of the input blobs.\n  repeated BlobShape input_shape = 8;\n\n  // 4D input dimensions -- deprecated.  Use \"shape\" instead.\n  // If specified, for each input blob there should be four\n  // values specifying the num, channels, height and width of the input blob.\n  // Thus, there should be a total of (4 * #input) numbers.\n  repeated int32 input_dim = 4;\n\n  // Whether the network will force every layer to carry out backward operation.\n  // If set False, then whether to carry out backward is determined\n  // automatically according to the net structure and learning rates.\n  optional bool force_backward = 5 [default = false];\n  // The current \"state\" of the network, including the phase, level, and stage.\n  // Some layers may be included/excluded depending on this state and the states\n  // specified in the layers' include and exclude fields.\n  optional NetState state = 6;\n\n  // Print debugging information about results while running Net::Forward,\n  // Net::Backward, and Net::Update.\n  optional bool debug_info = 7 [default = false];\n\n  // The layers that make up the net.  Each of their configurations, including\n  // connectivity and behavior, is specified as a LayerParameter.\n  repeated LayerParameter layer = 100;  // ID 100 so layers are printed last.\n\n  // DEPRECATED: use 'layer' instead.\n  repeated V1LayerParameter layers = 2;\n}\n\n// NOTE\n// Update the next available ID when you add a new SolverParameter field.\n//\n// SolverParameter next available ID: 40 (last added: momentum2)\nmessage SolverParameter {\n  //////////////////////////////////////////////////////////////////////////////\n  // Specifying the train and test networks\n  //\n  // Exactly one train net must be specified using one of the following fields:\n  //     train_net_param, train_net, net_param, net\n  // One or more test nets may be specified using any of the following fields:\n  //     test_net_param, test_net, net_param, net\n  // If more than one test net field is specified (e.g., both net and\n  // test_net are specified), they will be evaluated in the field order given\n  // above: (1) test_net_param, (2) test_net, (3) net_param/net.\n  // A test_iter must be specified for each test_net.\n  // A test_level and/or a test_stage may also be specified for each test_net.\n  //////////////////////////////////////////////////////////////////////////////\n\n  // Proto filename for the train net, possibly combined with one or more\n  // test nets.\n  optional string net = 24;\n  // Inline train net param, possibly combined with one or more test nets.\n  optional NetParameter net_param = 25;\n\n  optional string train_net = 1; // Proto filename for the train net.\n  repeated string test_net = 2; // Proto filenames for the test nets.\n  optional NetParameter train_net_param = 21; // Inline train net params.\n  repeated NetParameter test_net_param = 22; // Inline test net params.\n\n  // The states for the train/test nets. Must be unspecified or\n  // specified once per net.\n  //\n  // By default, all states will have solver = true;\n  // train_state will have phase = TRAIN,\n  // and all test_state's will have phase = TEST.\n  // Other defaults are set according to the NetState defaults.\n  optional NetState train_state = 26;\n  repeated NetState test_state = 27;\n\n  // The number of iterations for each test net.\n  repeated int32 test_iter = 3;\n\n  // The number of iterations between two testing phases.\n  optional int32 test_interval = 4 [default = 0];\n  optional bool test_compute_loss = 19 [default = false];\n  // If true, run an initial test pass before the first iteration,\n  // ensuring memory availability and printing the starting value of the loss.\n  optional bool test_initialization = 32 [default = true];\n  optional float base_lr = 5; // The base learning rate\n  // the number of iterations between displaying info. If display = 0, no info\n  // will be displayed.\n  optional int32 display = 6;\n  // Display the loss averaged over the last average_loss iterations\n  optional int32 average_loss = 33 [default = 1];\n  optional int32 max_iter = 7; // the maximum number of iterations\n  // accumulate gradients over `iter_size` x `batch_size` instances\n  optional int32 iter_size = 36 [default = 1];\n\n  // The learning rate decay policy. The currently implemented learning rate\n  // policies are as follows:\n  //    - fixed: always return base_lr.\n  //    - step: return base_lr * gamma ^ (floor(iter / step))\n  //    - exp: return base_lr * gamma ^ iter\n  //    - inv: return base_lr * (1 + gamma * iter) ^ (- power)\n  //    - multistep: similar to step but it allows non uniform steps defined by\n  //      stepvalue\n  //    - poly: the effective learning rate follows a polynomial decay, to be\n  //      zero by the max_iter. return base_lr (1 - iter/max_iter) ^ (power)\n  //    - sigmoid: the effective learning rate follows a sigmod decay\n  //      return base_lr ( 1/(1 + exp(-gamma * (iter - stepsize))))\n  //\n  // where base_lr, max_iter, gamma, step, stepvalue and power are defined\n  // in the solver parameter protocol buffer, and iter is the current iteration.\n  optional string lr_policy = 8;\n  optional float gamma = 9; // The parameter to compute the learning rate.\n  optional float power = 10; // The parameter to compute the learning rate.\n  optional float momentum = 11; // The momentum value.\n  optional float weight_decay = 12; // The weight decay.\n  // regularization types supported: L1 and L2\n  // controlled by weight_decay\n  optional string regularization_type = 29 [default = \"L2\"];\n  // the stepsize for learning rate policy \"step\"\n  optional int32 stepsize = 13;\n  // the stepsize for learning rate policy \"multistep\"\n  repeated int32 stepvalue = 34;\n\n  // Set clip_gradients to >= 0 to clip parameter gradients to that L2 norm,\n  // whenever their actual L2 norm is larger.\n  optional float clip_gradients = 35 [default = -1];\n\n  optional int32 snapshot = 14 [default = 0]; // The snapshot interval\n  optional string snapshot_prefix = 15; // The prefix for the snapshot.\n  // whether to snapshot diff in the results or not. Snapshotting diff will help\n  // debugging but the final protocol buffer size will be much larger.\n  optional bool snapshot_diff = 16 [default = false];\n  enum SnapshotFormat {\n    HDF5 = 0;\n    BINARYPROTO = 1;\n  }\n  optional SnapshotFormat snapshot_format = 37 [default = BINARYPROTO];\n  // the mode solver will use: 0 for CPU and 1 for GPU. Use GPU in default.\n  enum SolverMode {\n    CPU = 0;\n    GPU = 1;\n  }\n  optional SolverMode solver_mode = 17 [default = GPU];\n  // the device_id will that be used in GPU mode. Use device_id = 0 in default.\n  optional int32 device_id = 18 [default = 0];\n  // If non-negative, the seed with which the Solver will initialize the Caffe\n  // random number generator -- useful for reproducible results. Otherwise,\n  // (and by default) initialize using a seed derived from the system clock.\n  optional int64 random_seed = 20 [default = -1];\n\n  // Solver type\n  enum SolverType {\n    SGD = 0;\n    NESTEROV = 1;\n    ADAGRAD = 2;\n    RMSPROP = 3;\n    ADADELTA = 4;\n    ADAM = 5;\n  }\n  optional SolverType solver_type = 30 [default = SGD];\n  // numerical stability for RMSProp, AdaGrad and AdaDelta and Adam\n  optional float delta = 31 [default = 1e-8];\n  // parameters for the Adam solver\n  optional float momentum2 = 39 [default = 0.999];\n\n  // RMSProp decay value\n  // MeanSquare(t) = rms_decay*MeanSquare(t-1) + (1-rms_decay)*SquareGradient(t)\n  optional float rms_decay = 38;\n\n  // If true, print information about the state of the net that may help with\n  // debugging learning problems.\n  optional bool debug_info = 23 [default = false];\n\n  // If false, don't save a snapshot after training finishes.\n  optional bool snapshot_after_train = 28 [default = true];\n}\n\n// A message that stores the solver snapshots\nmessage SolverState {\n  optional int32 iter = 1; // The current iteration\n  optional string learned_net = 2; // The file that stores the learned net.\n  repeated BlobProto history = 3; // The history for sgd solvers\n  optional int32 current_step = 4 [default = 0]; // The current step for learning rate\n}\n\nenum Phase {\n   TRAIN = 0;\n   TEST = 1;\n}\n\nmessage NetState {\n  optional Phase phase = 1 [default = TEST];\n  optional int32 level = 2 [default = 0];\n  repeated string stage = 3;\n}\n\nmessage NetStateRule {\n  // Set phase to require the NetState have a particular phase (TRAIN or TEST)\n  // to meet this rule.\n  optional Phase phase = 1;\n\n  // Set the minimum and/or maximum levels in which the layer should be used.\n  // Leave undefined to meet the rule regardless of level.\n  optional int32 min_level = 2;\n  optional int32 max_level = 3;\n\n  // Customizable sets of stages to include or exclude.\n  // The net must have ALL of the specified stages and NONE of the specified\n  // \"not_stage\"s to meet the rule.\n  // (Use multiple NetStateRules to specify conjunctions of stages.)\n  repeated string stage = 4;\n  repeated string not_stage = 5;\n}\n\n// Specifies training parameters (multipliers on global learning constants,\n// and the name and other settings used for weight sharing).\nmessage ParamSpec {\n  // The names of the parameter blobs -- useful for sharing parameters among\n  // layers, but never required otherwise.  To share a parameter between two\n  // layers, give it a (non-empty) name.\n  optional string name = 1;\n\n  // Whether to require shared weights to have the same shape, or just the same\n  // count -- defaults to STRICT if unspecified.\n  optional DimCheckMode share_mode = 2;\n  enum DimCheckMode {\n    // STRICT (default) requires that num, channels, height, width each match.\n    STRICT = 0;\n    // PERMISSIVE requires only the count (num*channels*height*width) to match.\n    PERMISSIVE = 1;\n  }\n\n  // The multiplier on the global learning rate for this parameter.\n  optional float lr_mult = 3 [default = 1.0];\n\n  // The multiplier on the global weight decay for this parameter.\n  optional float decay_mult = 4 [default = 1.0];\n}\n\n// NOTE\n// Update the next available ID when you add a new LayerParameter field.\n//\n// LayerParameter next available layer-specific ID: 137 (last added: reduction_param)\nmessage LayerParameter {\n  optional string name = 1; // the layer name\n  optional string type = 2; // the layer type\n  repeated string bottom = 3; // the name of each bottom blob\n  repeated string top = 4; // the name of each top blob\n\n  // The train / test phase for computation.\n  optional Phase phase = 10;\n\n  // The amount of weight to assign each top blob in the objective.\n  // Each layer assigns a default value, usually of either 0 or 1,\n  // to each top blob.\n  repeated float loss_weight = 5;\n\n  // Specifies training parameters (multipliers on global learning constants,\n  // and the name and other settings used for weight sharing).\n  repeated ParamSpec param = 6;\n\n  // The blobs containing the numeric parameters of the layer.\n  repeated BlobProto blobs = 7;\n\n  // Specifies on which bottoms the backpropagation should be skipped.\n  // The size must be either 0 or equal to the number of bottoms.\n  repeated bool propagate_down = 11;\n\n  // Rules controlling whether and when a layer is included in the network,\n  // based on the current NetState.  You may specify a non-zero number of rules\n  // to include OR exclude, but not both.  If no include or exclude rules are\n  // specified, the layer is always included.  If the current NetState meets\n  // ANY (i.e., one or more) of the specified rules, the layer is\n  // included/excluded.\n  repeated NetStateRule include = 8;\n  repeated NetStateRule exclude = 9;\n\n  // Parameters for data pre-processing.\n  optional TransformationParameter transform_param = 100;\n\n  // Parameters shared by loss layers.\n  optional LossParameter loss_param = 101;\n\n  // Layer type-specific parameters.\n  //\n  // Note: certain layers may have more than one computational engine\n  // for their implementation. These layers include an Engine type and\n  // engine parameter for selecting the implementation.\n  // The default for the engine is set by the ENGINE switch at compile-time.\n  optional AccuracyParameter accuracy_param = 102;\n  optional ArgMaxParameter argmax_param = 103;\n  optional ConcatParameter concat_param = 104;\n  optional ContrastiveLossParameter contrastive_loss_param = 105;\n  optional ConvolutionParameter convolution_param = 106;\n  optional DataParameter data_param = 107;\n  optional DropoutParameter dropout_param = 108;\n  optional DummyDataParameter dummy_data_param = 109;\n  optional EltwiseParameter eltwise_param = 110;\n  optional ExpParameter exp_param = 111;\n  optional FlattenParameter flatten_param = 135;\n  optional HDF5DataParameter hdf5_data_param = 112;\n  optional HDF5OutputParameter hdf5_output_param = 113;\n  optional HingeLossParameter hinge_loss_param = 114;\n  optional ImageDataParameter image_data_param = 115;\n  optional InfogainLossParameter infogain_loss_param = 116;\n  optional InnerProductParameter inner_product_param = 117;\n  optional LogParameter log_param = 134;\n  optional LRNParameter lrn_param = 118;\n  optional MemoryDataParameter memory_data_param = 119;\n  optional MVNParameter mvn_param = 120;\n  optional PoolingParameter pooling_param = 121;\n  optional PowerParameter power_param = 122;\n  optional PReLUParameter prelu_param = 131;\n  optional PythonParameter python_param = 130;\n  optional ReductionParameter reduction_param = 136;\n  optional ReLUParameter relu_param = 123;\n  optional ReshapeParameter reshape_param = 133;\n  optional SigmoidParameter sigmoid_param = 124;\n  optional SoftmaxParameter softmax_param = 125;\n  optional SPPParameter spp_param = 132;\n  optional SliceParameter slice_param = 126;\n  optional TanHParameter tanh_param = 127;\n  optional ThresholdParameter threshold_param = 128;\n  optional WindowDataParameter window_data_param = 129;\n  optional CConvolutionParameter cconvolution_param = 140;\n  optional CInnerProductParameter cinner_product_param = 141;  \n}\n\n// Message that stores parameters used to apply transformation\n// to the data layer's data\nmessage TransformationParameter {\n  // For data pre-processing, we can do simple scaling and subtracting the\n  // data mean, if provided. Note that the mean subtraction is always carried\n  // out before scaling.\n  optional float scale = 1 [default = 1];\n  // Specify if we want to randomly mirror data.\n  optional bool mirror = 2 [default = false];\n  // Specify if we would like to randomly crop an image.\n  optional uint32 crop_size = 3 [default = 0];\n  // mean_file and mean_value cannot be specified at the same time\n  optional string mean_file = 4;\n  // if specified can be repeated once (would substract it from all the channels)\n  // or can be repeated the same number of times as channels\n  // (would subtract them from the corresponding channel)\n  repeated float mean_value = 5;\n  // Force the decoded image to have 3 color channels.\n  optional bool force_color = 6 [default = false];\n  // Force the decoded image to have 1 color channels.\n  optional bool force_gray = 7 [default = false];\n}\n\n// Message that stores parameters shared by loss layers\nmessage LossParameter {\n  // If specified, ignore instances with the given label.\n  optional int32 ignore_label = 1;\n  // If true, normalize each batch across all instances (including spatial\n  // dimesions, but not ignored instances); else, divide by batch size only.\n  optional bool normalize = 2 [default = true];\n}\n\n// Messages that store parameters used by individual layer types follow, in\n// alphabetical order.\n\nmessage AccuracyParameter {\n  // When computing accuracy, count as correct by comparing the true label to\n  // the top k scoring classes.  By default, only compare to the top scoring\n  // class (i.e. argmax).\n  optional uint32 top_k = 1 [default = 1];\n\n  // The \"label\" axis of the prediction blob, whose argmax corresponds to the\n  // predicted label -- may be negative to index from the end (e.g., -1 for the\n  // last axis).  For example, if axis == 1 and the predictions are\n  // (N x C x H x W), the label blob is expected to contain N*H*W ground truth\n  // labels with integer values in {0, 1, ..., C-1}.\n  optional int32 axis = 2 [default = 1];\n\n  // If specified, ignore instances with the given label.\n  optional int32 ignore_label = 3;\n}\n\nmessage ArgMaxParameter {\n  // If true produce pairs (argmax, maxval)\n  optional bool out_max_val = 1 [default = false];\n  optional uint32 top_k = 2 [default = 1];\n}\n\nmessage ConcatParameter {\n  // The axis along which to concatenate -- may be negative to index from the\n  // end (e.g., -1 for the last axis).  Other axes must have the\n  // same dimension for all the bottom blobs.\n  // By default, ConcatLayer concatenates blobs along the \"channels\" axis (1).\n  optional int32 axis = 2 [default = 1];\n\n  // DEPRECATED: alias for \"axis\" -- does not support negative indexing.\n  optional uint32 concat_dim = 1 [default = 1];\n}\n\nmessage ContrastiveLossParameter {\n  // margin for dissimilar pair\n  optional float margin = 1 [default = 1.0];\n  // The first implementation of this cost did not exactly match the cost of\n  // Hadsell et al 2006 -- using (margin - d^2) instead of (margin - d)^2.\n  // legacy_version = false (the default) uses (margin - d)^2 as proposed in the\n  // Hadsell paper. New models should probably use this version.\n  // legacy_version = true uses (margin - d^2). This is kept to support /\n  // reproduce existing models and results\n  optional bool legacy_version = 2 [default = false];\n}\n\nmessage ConvolutionParameter {\n  optional uint32 num_output = 1; // The number of outputs for the layer\n  optional bool bias_term = 2 [default = true]; // whether to have bias terms\n  // Pad, kernel size, and stride are all given as a single value for equal\n  // dimensions in height and width or as Y, X pairs.\n  optional uint32 pad = 3 [default = 0]; // The padding size (equal in Y, X)\n  optional uint32 pad_h = 9 [default = 0]; // The padding height\n  optional uint32 pad_w = 10 [default = 0]; // The padding width\n  optional uint32 kernel_size = 4; // The kernel size (square)\n  optional uint32 kernel_h = 11; // The kernel height\n  optional uint32 kernel_w = 12; // The kernel width\n  optional uint32 group = 5 [default = 1]; // The group size for group conv\n  optional uint32 stride = 6 [default = 1]; // The stride (equal in Y, X)\n  optional uint32 stride_h = 13; // The stride height\n  optional uint32 stride_w = 14; // The stride width\n  optional FillerParameter weight_filler = 7; // The filler for the weight\n  optional FillerParameter bias_filler = 8; // The filler for the bias\n  enum Engine {\n    DEFAULT = 0;\n    CAFFE = 1;\n    CUDNN = 2;\n  }\n  optional Engine engine = 15 [default = DEFAULT];\n}\n\nmessage CConvolutionParameter {\n  optional float gamma = 1 [default = 0.001]; // The compress parameter of current layer\n  optional float power = 2 [default = 1];\n  optional float iter_stop = 3 [default = 10000];  \n  optional float c_rate = 4 [default = 3];    \n  optional FillerParameter weight_mask_filler = 5; // The filler for the weight\n  optional FillerParameter bias_mask_filler = 6;   // The filler for the bias  \n}\n\nmessage DataParameter {\n  enum DB {\n    LEVELDB = 0;\n    LMDB = 1;\n  }\n  // Specify the data source.\n  optional string source = 1;\n  // Specify the batch size.\n  optional uint32 batch_size = 4;\n  // The rand_skip variable is for the data layer to skip a few data points\n  // to avoid all asynchronous sgd clients to start at the same point. The skip\n  // point would be set as rand_skip * rand(0,1). Note that rand_skip should not\n  // be larger than the number of keys in the database.\n  // DEPRECATED. Each solver accesses a different subset of the database.\n  optional uint32 rand_skip = 7 [default = 0];\n  optional DB backend = 8 [default = LEVELDB];\n  // DEPRECATED. See TransformationParameter. For data pre-processing, we can do\n  // simple scaling and subtracting the data mean, if provided. Note that the\n  // mean subtraction is always carried out before scaling.\n  optional float scale = 2 [default = 1];\n  optional string mean_file = 3;\n  // DEPRECATED. See TransformationParameter. Specify if we would like to randomly\n  // crop an image.\n  optional uint32 crop_size = 5 [default = 0];\n  // DEPRECATED. See TransformationParameter. Specify if we want to randomly mirror\n  // data.\n  optional bool mirror = 6 [default = false];\n  // Force the encoded image to have 3 color channels\n  optional bool force_encoded_color = 9 [default = false];\n  // Prefetch queue (Number of batches to prefetch to host memory, increase if\n  // data access bandwidth varies).\n  optional uint32 prefetch = 10 [default = 4];\n}\n\nmessage DropoutParameter {\n  optional float dropout_ratio = 1 [default = 0.5]; // dropout ratio\n}\n\n// DummyDataLayer fills any number of arbitrarily shaped blobs with random\n// (or constant) data generated by \"Fillers\" (see \"message FillerParameter\").\nmessage DummyDataParameter {\n  // This layer produces N >= 1 top blobs.  DummyDataParameter must specify 1 or N\n  // shape fields, and 0, 1 or N data_fillers.\n  //\n  // If 0 data_fillers are specified, ConstantFiller with a value of 0 is used.\n  // If 1 data_filler is specified, it is applied to all top blobs.  If N are\n  // specified, the ith is applied to the ith top blob.\n  repeated FillerParameter data_filler = 1;\n  repeated BlobShape shape = 6;\n\n  // 4D dimensions -- deprecated.  Use \"shape\" instead.\n  repeated uint32 num = 2;\n  repeated uint32 channels = 3;\n  repeated uint32 height = 4;\n  repeated uint32 width = 5;\n}\n\nmessage EltwiseParameter {\n  enum EltwiseOp {\n    PROD = 0;\n    SUM = 1;\n    MAX = 2;\n  }\n  optional EltwiseOp operation = 1 [default = SUM]; // element-wise operation\n  repeated float coeff = 2; // blob-wise coefficient for SUM operation\n\n  // Whether to use an asymptotically slower (for >2 inputs) but stabler method\n  // of computing the gradient for the PROD operation. (No effect for SUM op.)\n  optional bool stable_prod_grad = 3 [default = true];\n}\n\nmessage ExpParameter {\n  // ExpLayer computes outputs y = base ^ (shift + scale * x), for base > 0.\n  // Or if base is set to the default (-1), base is set to e,\n  // so y = exp(shift + scale * x).\n  optional float base = 1 [default = -1.0];\n  optional float scale = 2 [default = 1.0];\n  optional float shift = 3 [default = 0.0];\n}\n\n/// Message that stores parameters used by FlattenLayer\nmessage FlattenParameter {\n  // The first axis to flatten: all preceding axes are retained in the output.\n  // May be negative to index from the end (e.g., -1 for the last axis).\n  optional int32 axis = 1 [default = 1];\n\n  // The last axis to flatten: all following axes are retained in the output.\n  // May be negative to index from the end (e.g., the default -1 for the last\n  // axis).\n  optional int32 end_axis = 2 [default = -1];\n}\n\n// Message that stores parameters used by HDF5DataLayer\nmessage HDF5DataParameter {\n  // Specify the data source.\n  optional string source = 1;\n  // Specify the batch size.\n  optional uint32 batch_size = 2;\n\n  // Specify whether to shuffle the data.\n  // If shuffle == true, the ordering of the HDF5 files is shuffled,\n  // and the ordering of data within any given HDF5 file is shuffled,\n  // but data between different files are not interleaved; all of a file's\n  // data are output (in a random order) before moving onto another file.\n  optional bool shuffle = 3 [default = false];\n}\n\nmessage HDF5OutputParameter {\n  optional string file_name = 1;\n}\n\nmessage HingeLossParameter {\n  enum Norm {\n    L1 = 1;\n    L2 = 2;\n  }\n  // Specify the Norm to use L1 or L2\n  optional Norm norm = 1 [default = L1];\n}\n\nmessage ImageDataParameter {\n  // Specify the data source.\n  optional string source = 1;\n  // Specify the batch size.\n  optional uint32 batch_size = 4 [default = 1];\n  // The rand_skip variable is for the data layer to skip a few data points\n  // to avoid all asynchronous sgd clients to start at the same point. The skip\n  // point would be set as rand_skip * rand(0,1). Note that rand_skip should not\n  // be larger than the number of keys in the database.\n  optional uint32 rand_skip = 7 [default = 0];\n  // Whether or not ImageLayer should shuffle the list of files at every epoch.\n  optional bool shuffle = 8 [default = false];\n  // It will also resize images if new_height or new_width are not zero.\n  optional uint32 new_height = 9 [default = 0];\n  optional uint32 new_width = 10 [default = 0];\n  // Specify if the images are color or gray\n  optional bool is_color = 11 [default = true];\n  // DEPRECATED. See TransformationParameter. For data pre-processing, we can do\n  // simple scaling and subtracting the data mean, if provided. Note that the\n  // mean subtraction is always carried out before scaling.\n  optional float scale = 2 [default = 1];\n  optional string mean_file = 3;\n  // DEPRECATED. See TransformationParameter. Specify if we would like to randomly\n  // crop an image.\n  optional uint32 crop_size = 5 [default = 0];\n  // DEPRECATED. See TransformationParameter. Specify if we want to randomly mirror\n  // data.\n  optional bool mirror = 6 [default = false];\n  optional string root_folder = 12 [default = \"\"];\n}\n\nmessage InfogainLossParameter {\n  // Specify the infogain matrix source.\n  optional string source = 1;\n}\n\nmessage InnerProductParameter {\n  optional uint32 num_output = 1; // The number of outputs for the layer\n  optional bool bias_term = 2 [default = true]; // whether to have bias terms\n  optional FillerParameter weight_filler = 3; // The filler for the weight\n  optional FillerParameter bias_filler = 4; // The filler for the bias\n\n  // The first axis to be lumped into a single inner product computation;\n  // all preceding axes are retained in the output.\n  // May be negative to index from the end (e.g., -1 for the last axis).\n  optional int32 axis = 5 [default = 1];\n}\n\nmessage CInnerProductParameter {\n  optional float gamma = 1 [default = 0.001]; // The compress parameter of current layer\n  optional float power = 2 [default = 1];\n  optional float iter_stop = 3 [default = 8000];\n  optional float c_rate = 4 [default = 3];  \n  optional FillerParameter weight_mask_filler = 5; // The filler for the weight\n  optional FillerParameter bias_mask_filler = 6;   // The filler for the bias  \n}\n\n// Message that stores parameters used by LogLayer\nmessage LogParameter {\n  // LogLayer computes outputs y = log_base(shift + scale * x), for base > 0.\n  // Or if base is set to the default (-1), base is set to e,\n  // so y = ln(shift + scale * x) = log_e(shift + scale * x)\n  optional float base = 1 [default = -1.0];\n  optional float scale = 2 [default = 1.0];\n  optional float shift = 3 [default = 0.0];\n}\n\n// Message that stores parameters used by LRNLayer\nmessage LRNParameter {\n  optional uint32 local_size = 1 [default = 5];\n  optional float alpha = 2 [default = 1.];\n  optional float beta = 3 [default = 0.75];\n  enum NormRegion {\n    ACROSS_CHANNELS = 0;\n    WITHIN_CHANNEL = 1;\n  }\n  optional NormRegion norm_region = 4 [default = ACROSS_CHANNELS];\n  optional float k = 5 [default = 1.];\n}\n\nmessage MemoryDataParameter {\n  optional uint32 batch_size = 1;\n  optional uint32 channels = 2;\n  optional uint32 height = 3;\n  optional uint32 width = 4;\n}\n\nmessage MVNParameter {\n  // This parameter can be set to false to normalize mean only\n  optional bool normalize_variance = 1 [default = true];\n\n  // This parameter can be set to true to perform DNN-like MVN\n  optional bool across_channels = 2 [default = false];\n\n  // Epsilon for not dividing by zero while normalizing variance\n  optional float eps = 3 [default = 1e-9];\n}\n\nmessage PoolingParameter {\n  enum PoolMethod {\n    MAX = 0;\n    AVE = 1;\n    STOCHASTIC = 2;\n  }\n  optional PoolMethod pool = 1 [default = MAX]; // The pooling method\n  // Pad, kernel size, and stride are all given as a single value for equal\n  // dimensions in height and width or as Y, X pairs.\n  optional uint32 pad = 4 [default = 0]; // The padding size (equal in Y, X)\n  optional uint32 pad_h = 9 [default = 0]; // The padding height\n  optional uint32 pad_w = 10 [default = 0]; // The padding width\n  optional uint32 kernel_size = 2; // The kernel size (square)\n  optional uint32 kernel_h = 5; // The kernel height\n  optional uint32 kernel_w = 6; // The kernel width\n  optional uint32 stride = 3 [default = 1]; // The stride (equal in Y, X)\n  optional uint32 stride_h = 7; // The stride height\n  optional uint32 stride_w = 8; // The stride width\n  enum Engine {\n    DEFAULT = 0;\n    CAFFE = 1;\n    CUDNN = 2;\n  }\n  optional Engine engine = 11 [default = DEFAULT];\n  // If global_pooling then it will pool over the size of the bottom by doing\n  // kernel_h = bottom->height and kernel_w = bottom->width\n  optional bool global_pooling = 12 [default = false];\n}\n\nmessage PowerParameter {\n  // PowerLayer computes outputs y = (shift + scale * x) ^ power.\n  optional float power = 1 [default = 1.0];\n  optional float scale = 2 [default = 1.0];\n  optional float shift = 3 [default = 0.0];\n}\n\nmessage PythonParameter {\n  optional string module = 1;\n  optional string layer = 2;\n  // This value is set to the attribute `param_str` of the `PythonLayer` object\n  // in Python before calling the `setup()` method. This could be a number,\n  // string, dictionary in Python dict format, JSON, etc. You may parse this\n  // string in `setup` method and use it in `forward` and `backward`.\n  optional string param_str = 3 [default = ''];\n  // Whether this PythonLayer is shared among worker solvers during data parallelism.\n  // If true, each worker solver sequentially run forward from this layer.\n  // This value should be set true if you are using it as a data layer.\n  optional bool share_in_parallel = 4 [default = false];\n}\n\n// Message that stores parameters used by ReductionLayer\nmessage ReductionParameter {\n  enum ReductionOp {\n    SUM = 1;\n    ASUM = 2;\n    SUMSQ = 3;\n    MEAN = 4;\n  }\n\n  optional ReductionOp operation = 1 [default = SUM]; // reduction operation\n\n  // The first axis to reduce to a scalar -- may be negative to index from the\n  // end (e.g., -1 for the last axis).\n  // (Currently, only reduction along ALL \"tail\" axes is supported; reduction\n  // of axis M through N, where N < num_axes - 1, is unsupported.)\n  // Suppose we have an n-axis bottom Blob with shape:\n  //     (d0, d1, d2, ..., d(m-1), dm, d(m+1), ..., d(n-1)).\n  // If axis == m, the output Blob will have shape\n  //     (d0, d1, d2, ..., d(m-1)),\n  // and the ReductionOp operation is performed (d0 * d1 * d2 * ... * d(m-1))\n  // times, each including (dm * d(m+1) * ... * d(n-1)) individual data.\n  // If axis == 0 (the default), the output Blob always has the empty shape\n  // (count 1), performing reduction across the entire input --\n  // often useful for creating new loss functions.\n  optional int32 axis = 2 [default = 0];\n\n  optional float coeff = 3 [default = 1.0]; // coefficient for output\n}\n\n// Message that stores parameters used by ReLULayer\nmessage ReLUParameter {\n  // Allow non-zero slope for negative inputs to speed up optimization\n  // Described in:\n  // Maas, A. L., Hannun, A. Y., & Ng, A. Y. (2013). Rectifier nonlinearities\n  // improve neural network acoustic models. In ICML Workshop on Deep Learning\n  // for Audio, Speech, and Language Processing.\n  optional float negative_slope = 1 [default = 0];\n  enum Engine {\n    DEFAULT = 0;\n    CAFFE = 1;\n    CUDNN = 2;\n  }\n  optional Engine engine = 2 [default = DEFAULT];\n}\n\nmessage ReshapeParameter {\n  // Specify the output dimensions. If some of the dimensions are set to 0,\n  // the corresponding dimension from the bottom layer is used (unchanged).\n  // Exactly one dimension may be set to -1, in which case its value is\n  // inferred from the count of the bottom blob and the remaining dimensions.\n  // For example, suppose we want to reshape a 2D blob \"input\" with shape 2 x 8:\n  //\n  //   layer {\n  //     type: \"Reshape\" bottom: \"input\" top: \"output\"\n  //     reshape_param { ... }\n  //   }\n  //\n  // If \"input\" is 2D with shape 2 x 8, then the following reshape_param\n  // specifications are all equivalent, producing a 3D blob \"output\" with shape\n  // 2 x 2 x 4:\n  //\n  //   reshape_param { shape { dim:  2  dim: 2  dim:  4 } }\n  //   reshape_param { shape { dim:  0  dim: 2  dim:  4 } }\n  //   reshape_param { shape { dim:  0  dim: 2  dim: -1 } }\n  //   reshape_param { shape { dim: -1  dim: 0  dim:  2 } }\n  //\n  optional BlobShape shape = 1;\n\n  // axis and num_axes control the portion of the bottom blob's shape that are\n  // replaced by (included in) the reshape. By default (axis == 0 and\n  // num_axes == -1), the entire bottom blob shape is included in the reshape,\n  // and hence the shape field must specify the entire output shape.\n  //\n  // axis may be non-zero to retain some portion of the beginning of the input\n  // shape (and may be negative to index from the end; e.g., -1 to begin the\n  // reshape after the last axis, including nothing in the reshape,\n  // -2 to include only the last axis, etc.).\n  //\n  // For example, suppose \"input\" is a 2D blob with shape 2 x 8.\n  // Then the following ReshapeLayer specifications are all equivalent,\n  // producing a blob \"output\" with shape 2 x 2 x 4:\n  //\n  //   reshape_param { shape { dim: 2  dim: 2  dim: 4 } }\n  //   reshape_param { shape { dim: 2  dim: 4 } axis:  1 }\n  //   reshape_param { shape { dim: 2  dim: 4 } axis: -3 }\n  //\n  // num_axes specifies the extent of the reshape.\n  // If num_axes >= 0 (and axis >= 0), the reshape will be performed only on\n  // input axes in the range [axis, axis+num_axes].\n  // num_axes may also be -1, the default, to include all remaining axes\n  // (starting from axis).\n  //\n  // For example, suppose \"input\" is a 2D blob with shape 2 x 8.\n  // Then the following ReshapeLayer specifications are equivalent,\n  // producing a blob \"output\" with shape 1 x 2 x 8.\n  //\n  //   reshape_param { shape { dim:  1  dim: 2  dim:  8 } }\n  //   reshape_param { shape { dim:  1  dim: 2  }  num_axes: 1 }\n  //   reshape_param { shape { dim:  1  }  num_axes: 0 }\n  //\n  // On the other hand, these would produce output blob shape 2 x 1 x 8:\n  //\n  //   reshape_param { shape { dim: 2  dim: 1  dim: 8  }  }\n  //   reshape_param { shape { dim: 1 }  axis: 1  num_axes: 0 }\n  //\n  optional int32 axis = 2 [default = 0];\n  optional int32 num_axes = 3 [default = -1];\n}\n\nmessage SigmoidParameter {\n  enum Engine {\n    DEFAULT = 0;\n    CAFFE = 1;\n    CUDNN = 2;\n  }\n  optional Engine engine = 1 [default = DEFAULT];\n}\n\nmessage SliceParameter {\n  // The axis along which to slice -- may be negative to index from the end\n  // (e.g., -1 for the last axis).\n  // By default, SliceLayer concatenates blobs along the \"channels\" axis (1).\n  optional int32 axis = 3 [default = 1];\n  repeated uint32 slice_point = 2;\n\n  // DEPRECATED: alias for \"axis\" -- does not support negative indexing.\n  optional uint32 slice_dim = 1 [default = 1];\n}\n\n// Message that stores parameters used by SoftmaxLayer, SoftmaxWithLossLayer\nmessage SoftmaxParameter {\n  enum Engine {\n    DEFAULT = 0;\n    CAFFE = 1;\n    CUDNN = 2;\n  }\n  optional Engine engine = 1 [default = DEFAULT];\n\n  // The axis along which to perform the softmax -- may be negative to index\n  // from the end (e.g., -1 for the last axis).\n  // Any other axes will be evaluated as independent softmaxes.\n  optional int32 axis = 2 [default = 1];\n}\n\nmessage TanHParameter {\n  enum Engine {\n    DEFAULT = 0;\n    CAFFE = 1;\n    CUDNN = 2;\n  }\n  optional Engine engine = 1 [default = DEFAULT];\n}\n\nmessage ThresholdParameter {\n  optional float threshold = 1 [default = 0]; // Strictly positive values\n}\n\nmessage WindowDataParameter {\n  // Specify the data source.\n  optional string source = 1;\n  // For data pre-processing, we can do simple scaling and subtracting the\n  // data mean, if provided. Note that the mean subtraction is always carried\n  // out before scaling.\n  optional float scale = 2 [default = 1];\n  optional string mean_file = 3;\n  // Specify the batch size.\n  optional uint32 batch_size = 4;\n  // Specify if we would like to randomly crop an image.\n  optional uint32 crop_size = 5 [default = 0];\n  // Specify if we want to randomly mirror data.\n  optional bool mirror = 6 [default = false];\n  // Foreground (object) overlap threshold\n  optional float fg_threshold = 7 [default = 0.5];\n  // Background (non-object) overlap threshold\n  optional float bg_threshold = 8 [default = 0.5];\n  // Fraction of batch that should be foreground objects\n  optional float fg_fraction = 9 [default = 0.25];\n  // Amount of contextual padding to add around a window\n  // (used only by the window_data_layer)\n  optional uint32 context_pad = 10 [default = 0];\n  // Mode for cropping out a detection window\n  // warp: cropped window is warped to a fixed size and aspect ratio\n  // square: the tightest square around the window is cropped\n  optional string crop_mode = 11 [default = \"warp\"];\n  // cache_images: will load all images in memory for faster access\n  optional bool cache_images = 12 [default = false];\n  // append root_folder to locate images\n  optional string root_folder = 13 [default = \"\"];\n}\n\nmessage SPPParameter {\n  enum PoolMethod {\n    MAX = 0;\n    AVE = 1;\n    STOCHASTIC = 2;\n  }\n  optional uint32 pyramid_height = 1;\n  optional PoolMethod pool = 2 [default = MAX]; // The pooling method\n  enum Engine {\n    DEFAULT = 0;\n    CAFFE = 1;\n    CUDNN = 2;\n  }\n  optional Engine engine = 6 [default = DEFAULT];\n}\n\n// DEPRECATED: use LayerParameter.\nmessage V1LayerParameter {\n  repeated string bottom = 2;\n  repeated string top = 3;\n  optional string name = 4;\n  repeated NetStateRule include = 32;\n  repeated NetStateRule exclude = 33;\n  enum LayerType {\n    NONE = 0;\n    ABSVAL = 35;\n    ACCURACY = 1;\n    ARGMAX = 30;\n    BNLL = 2;\n    CONCAT = 3;\n    CONTRASTIVE_LOSS = 37;\n    CONVOLUTION = 4;\n    DATA = 5;\n    DECONVOLUTION = 39;\n    DROPOUT = 6;\n    DUMMY_DATA = 32;\n    EUCLIDEAN_LOSS = 7;\n    ELTWISE = 25;\n    EXP = 38;\n    FLATTEN = 8;\n    HDF5_DATA = 9;\n    HDF5_OUTPUT = 10;\n    HINGE_LOSS = 28;\n    IM2COL = 11;\n    IMAGE_DATA = 12;\n    INFOGAIN_LOSS = 13;\n    INNER_PRODUCT = 14;\n    LRN = 15;\n    MEMORY_DATA = 29;\n    MULTINOMIAL_LOGISTIC_LOSS = 16;\n    MVN = 34;\n    POOLING = 17;\n    POWER = 26;\n    RELU = 18;\n    SIGMOID = 19;\n    SIGMOID_CROSS_ENTROPY_LOSS = 27;\n    SILENCE = 36;\n    SOFTMAX = 20;\n    SOFTMAX_LOSS = 21;\n    SPLIT = 22;\n    SLICE = 33;\n    TANH = 23;\n    WINDOW_DATA = 24;\n    THRESHOLD = 31;\n  }\n  optional LayerType type = 5;\n  repeated BlobProto blobs = 6;\n  repeated string param = 1001;\n  repeated DimCheckMode blob_share_mode = 1002;\n  enum DimCheckMode {\n    STRICT = 0;\n    PERMISSIVE = 1;\n  }\n  repeated float blobs_lr = 7;\n  repeated float weight_decay = 8;\n  repeated float loss_weight = 35;\n  optional AccuracyParameter accuracy_param = 27;\n  optional ArgMaxParameter argmax_param = 23;\n  optional ConcatParameter concat_param = 9;\n  optional ContrastiveLossParameter contrastive_loss_param = 40;\n  optional ConvolutionParameter convolution_param = 10;\n  optional DataParameter data_param = 11;\n  optional DropoutParameter dropout_param = 12;\n  optional DummyDataParameter dummy_data_param = 26;\n  optional EltwiseParameter eltwise_param = 24;\n  optional ExpParameter exp_param = 41;\n  optional HDF5DataParameter hdf5_data_param = 13;\n  optional HDF5OutputParameter hdf5_output_param = 14;\n  optional HingeLossParameter hinge_loss_param = 29;\n  optional ImageDataParameter image_data_param = 15;\n  optional InfogainLossParameter infogain_loss_param = 16;\n  optional InnerProductParameter inner_product_param = 17;\n  optional LRNParameter lrn_param = 18;\n  optional MemoryDataParameter memory_data_param = 22;\n  optional MVNParameter mvn_param = 34;\n  optional PoolingParameter pooling_param = 19;\n  optional PowerParameter power_param = 21;\n  optional ReLUParameter relu_param = 30;\n  optional SigmoidParameter sigmoid_param = 38;\n  optional SoftmaxParameter softmax_param = 39;\n  optional SliceParameter slice_param = 31;\n  optional TanHParameter tanh_param = 37;\n  optional ThresholdParameter threshold_param = 25;\n  optional WindowDataParameter window_data_param = 20;\n  optional TransformationParameter transform_param = 36;\n  optional LossParameter loss_param = 42;\n  optional V0LayerParameter layer = 1;\n}\n\n// DEPRECATED: V0LayerParameter is the old way of specifying layer parameters\n// in Caffe.  We keep this message type around for legacy support.\nmessage V0LayerParameter {\n  optional string name = 1; // the layer name\n  optional string type = 2; // the string to specify the layer type\n\n  // Parameters to specify layers with inner products.\n  optional uint32 num_output = 3; // The number of outputs for the layer\n  optional bool biasterm = 4 [default = true]; // whether to have bias terms\n  optional FillerParameter weight_filler = 5; // The filler for the weight\n  optional FillerParameter bias_filler = 6; // The filler for the bias\n\n  optional uint32 pad = 7 [default = 0]; // The padding size\n  optional uint32 kernelsize = 8; // The kernel size\n  optional uint32 group = 9 [default = 1]; // The group size for group conv\n  optional uint32 stride = 10 [default = 1]; // The stride\n  enum PoolMethod {\n    MAX = 0;\n    AVE = 1;\n    STOCHASTIC = 2;\n  }\n  optional PoolMethod pool = 11 [default = MAX]; // The pooling method\n  optional float dropout_ratio = 12 [default = 0.5]; // dropout ratio\n\n  optional uint32 local_size = 13 [default = 5]; // for local response norm\n  optional float alpha = 14 [default = 1.]; // for local response norm\n  optional float beta = 15 [default = 0.75]; // for local response norm\n  optional float k = 22 [default = 1.];\n\n  // For data layers, specify the data source\n  optional string source = 16;\n  // For data pre-processing, we can do simple scaling and subtracting the\n  // data mean, if provided. Note that the mean subtraction is always carried\n  // out before scaling.\n  optional float scale = 17 [default = 1];\n  optional string meanfile = 18;\n  // For data layers, specify the batch size.\n  optional uint32 batchsize = 19;\n  // For data layers, specify if we would like to randomly crop an image.\n  optional uint32 cropsize = 20 [default = 0];\n  // For data layers, specify if we want to randomly mirror data.\n  optional bool mirror = 21 [default = false];\n\n  // The blobs containing the numeric parameters of the layer\n  repeated BlobProto blobs = 50;\n  // The ratio that is multiplied on the global learning rate. If you want to\n  // set the learning ratio for one blob, you need to set it for all blobs.\n  repeated float blobs_lr = 51;\n  // The weight decay that is multiplied on the global weight decay.\n  repeated float weight_decay = 52;\n\n  // The rand_skip variable is for the data layer to skip a few data points\n  // to avoid all asynchronous sgd clients to start at the same point. The skip\n  // point would be set as rand_skip * rand(0,1). Note that rand_skip should not\n  // be larger than the number of keys in the database.\n  optional uint32 rand_skip = 53 [default = 0];\n\n  // Fields related to detection (det_*)\n  // foreground (object) overlap threshold\n  optional float det_fg_threshold = 54 [default = 0.5];\n  // background (non-object) overlap threshold\n  optional float det_bg_threshold = 55 [default = 0.5];\n  // Fraction of batch that should be foreground objects\n  optional float det_fg_fraction = 56 [default = 0.25];\n\n  // optional bool OBSOLETE_can_clobber = 57 [default = true];\n\n  // Amount of contextual padding to add around a window\n  // (used only by the window_data_layer)\n  optional uint32 det_context_pad = 58 [default = 0];\n\n  // Mode for cropping out a detection window\n  // warp: cropped window is warped to a fixed size and aspect ratio\n  // square: the tightest square around the window is cropped\n  optional string det_crop_mode = 59 [default = \"warp\"];\n\n  // For ReshapeLayer, one needs to specify the new dimensions.\n  optional int32 new_num = 60 [default = 0];\n  optional int32 new_channels = 61 [default = 0];\n  optional int32 new_height = 62 [default = 0];\n  optional int32 new_width = 63 [default = 0];\n\n  // Whether or not ImageLayer should shuffle the list of files at every epoch.\n  // It will also resize images if new_height or new_width are not zero.\n  optional bool shuffle_images = 64 [default = false];\n\n  // For ConcatLayer, one needs to specify the dimension for concatenation, and\n  // the other dimensions must be the same for all the bottom blobs.\n  // By default it will concatenate blobs along the channels dimension.\n  optional uint32 concat_dim = 65 [default = 1];\n\n  optional HDF5OutputParameter hdf5_output_param = 1001;\n}\n\nmessage PReLUParameter {\n  // Parametric ReLU described in K. He et al, Delving Deep into Rectifiers:\n  // Surpassing Human-Level Performance on ImageNet Classification, 2015.\n\n  // Initial value of a_i. Default is a_i=0.25 for all i.\n  optional FillerParameter filler = 1;\n  // Whether or not slope paramters are shared across channels.\n  optional bool channel_shared = 2 [default = false];\n}\n\n"
  },
  {
    "path": "src/caffe/solver.cpp",
    "content": "#include <cstdio>\n\n#include <algorithm>\n#include <string>\n#include <vector>\n\n#include \"hdf5.h\"\n#include \"hdf5_hl.h\"\n\n#include \"caffe/net.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/solver.hpp\"\n#include \"caffe/util/hdf5.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/util/upgrade_proto.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nSolver<Dtype>::Solver(const SolverParameter& param, const Solver* root_solver)\n    : net_(), callbacks_(), root_solver_(root_solver) {\n  Init(param);\n}\n\ntemplate <typename Dtype>\nSolver<Dtype>::Solver(const string& param_file, const Solver* root_solver)\n    : net_(), callbacks_(), root_solver_(root_solver) {\n  SolverParameter param;\n  ReadProtoFromTextFileOrDie(param_file, &param);\n  Init(param);\n}\n\ntemplate <typename Dtype>\nvoid Solver<Dtype>::Init(const SolverParameter& param) {\n  CHECK(Caffe::root_solver() || root_solver_)\n      << \"root_solver_ needs to be set for all non-root solvers\";\n  LOG_IF(INFO, Caffe::root_solver()) << \"Initializing solver from parameters: \"\n    << std::endl << param.DebugString();\n  param_ = param;\n  CHECK_GE(param_.average_loss(), 1) << \"average_loss should be non-negative.\";\n  if (Caffe::root_solver() && param_.random_seed() >= 0) {\n    Caffe::set_random_seed(param_.random_seed());\n  }\n  // Scaffolding code\n  InitTrainNet();\n  if (Caffe::root_solver()) {\n    InitTestNets();\n    LOG(INFO) << \"Solver scaffolding done.\";\n  }\n  iter_ = 0;\n  current_step_ = 0;\n}\n\ntemplate <typename Dtype>\nvoid Solver<Dtype>::InitTrainNet() {\n  const int num_train_nets = param_.has_net() + param_.has_net_param() +\n      param_.has_train_net() + param_.has_train_net_param();\n  const string& field_names = \"net, net_param, train_net, train_net_param\";\n  CHECK_GE(num_train_nets, 1) << \"SolverParameter must specify a train net \"\n      << \"using one of these fields: \" << field_names;\n  CHECK_LE(num_train_nets, 1) << \"SolverParameter must not contain more than \"\n      << \"one of these fields specifying a train_net: \" << field_names;\n  NetParameter net_param;\n  if (param_.has_train_net_param()) {\n    LOG_IF(INFO, Caffe::root_solver())\n        << \"Creating training net specified in train_net_param.\";\n    net_param.CopyFrom(param_.train_net_param());\n  } else if (param_.has_train_net()) {\n    LOG_IF(INFO, Caffe::root_solver())\n        << \"Creating training net from train_net file: \" << param_.train_net();\n    ReadNetParamsFromTextFileOrDie(param_.train_net(), &net_param);\n  }\n  if (param_.has_net_param()) {\n    LOG_IF(INFO, Caffe::root_solver())\n        << \"Creating training net specified in net_param.\";\n    net_param.CopyFrom(param_.net_param());\n  }\n  if (param_.has_net()) {\n    LOG_IF(INFO, Caffe::root_solver())\n        << \"Creating training net from net file: \" << param_.net();\n    ReadNetParamsFromTextFileOrDie(param_.net(), &net_param);\n  }\n  // Set the correct NetState.  We start with the solver defaults (lowest\n  // precedence); then, merge in any NetState specified by the net_param itself;\n  // finally, merge in any NetState specified by the train_state (highest\n  // precedence).\n  NetState net_state;\n  net_state.set_phase(TRAIN);\n  net_state.MergeFrom(net_param.state());\n  net_state.MergeFrom(param_.train_state());\n  net_param.mutable_state()->CopyFrom(net_state);\n  if (Caffe::root_solver()) {\n    net_.reset(new Net<Dtype>(net_param));\n  } else {\n    net_.reset(new Net<Dtype>(net_param, root_solver_->net_.get()));\n  }\n}\n\ntemplate <typename Dtype>\nvoid Solver<Dtype>::InitTestNets() {\n  CHECK(Caffe::root_solver());\n  const bool has_net_param = param_.has_net_param();\n  const bool has_net_file = param_.has_net();\n  const int num_generic_nets = has_net_param + has_net_file;\n  CHECK_LE(num_generic_nets, 1)\n      << \"Both net_param and net_file may not be specified.\";\n  const int num_test_net_params = param_.test_net_param_size();\n  const int num_test_net_files = param_.test_net_size();\n  const int num_test_nets = num_test_net_params + num_test_net_files;\n  if (num_generic_nets) {\n      CHECK_GE(param_.test_iter_size(), num_test_nets)\n          << \"test_iter must be specified for each test network.\";\n  } else {\n      CHECK_EQ(param_.test_iter_size(), num_test_nets)\n          << \"test_iter must be specified for each test network.\";\n  }\n  // If we have a generic net (specified by net or net_param, rather than\n  // test_net or test_net_param), we may have an unlimited number of actual\n  // test networks -- the actual number is given by the number of remaining\n  // test_iters after any test nets specified by test_net_param and/or test_net\n  // are evaluated.\n  const int num_generic_net_instances = param_.test_iter_size() - num_test_nets;\n  const int num_test_net_instances = num_test_nets + num_generic_net_instances;\n  if (param_.test_state_size()) {\n    CHECK_EQ(param_.test_state_size(), num_test_net_instances)\n        << \"test_state must be unspecified or specified once per test net.\";\n  }\n  if (num_test_net_instances) {\n    CHECK_GT(param_.test_interval(), 0);\n  }\n  int test_net_id = 0;\n  vector<string> sources(num_test_net_instances);\n  vector<NetParameter> net_params(num_test_net_instances);\n  for (int i = 0; i < num_test_net_params; ++i, ++test_net_id) {\n      sources[test_net_id] = \"test_net_param\";\n      net_params[test_net_id].CopyFrom(param_.test_net_param(i));\n  }\n  for (int i = 0; i < num_test_net_files; ++i, ++test_net_id) {\n      sources[test_net_id] = \"test_net file: \" + param_.test_net(i);\n      ReadNetParamsFromTextFileOrDie(param_.test_net(i),\n          &net_params[test_net_id]);\n  }\n  const int remaining_test_nets = param_.test_iter_size() - test_net_id;\n  if (has_net_param) {\n    for (int i = 0; i < remaining_test_nets; ++i, ++test_net_id) {\n      sources[test_net_id] = \"net_param\";\n      net_params[test_net_id].CopyFrom(param_.net_param());\n    }\n  }\n  if (has_net_file) {\n    for (int i = 0; i < remaining_test_nets; ++i, ++test_net_id) {\n      sources[test_net_id] = \"net file: \" + param_.net();\n      ReadNetParamsFromTextFileOrDie(param_.net(), &net_params[test_net_id]);\n    }\n  }\n  test_nets_.resize(num_test_net_instances);\n  for (int i = 0; i < num_test_net_instances; ++i) {\n    // Set the correct NetState.  We start with the solver defaults (lowest\n    // precedence); then, merge in any NetState specified by the net_param\n    // itself; finally, merge in any NetState specified by the test_state\n    // (highest precedence).\n    NetState net_state;\n    net_state.set_phase(TEST);\n    net_state.MergeFrom(net_params[i].state());\n    if (param_.test_state_size()) {\n      net_state.MergeFrom(param_.test_state(i));\n    }\n    net_params[i].mutable_state()->CopyFrom(net_state);\n    LOG(INFO)\n        << \"Creating test net (#\" << i << \") specified by \" << sources[i];\n    if (Caffe::root_solver()) {\n      test_nets_[i].reset(new Net<Dtype>(net_params[i]));\n    } else {\n      test_nets_[i].reset(new Net<Dtype>(net_params[i],\n          root_solver_->test_nets_[i].get()));\n    }\n    test_nets_[i]->set_debug_info(param_.debug_info());\n  }\n}\n\ntemplate <typename Dtype>\nvoid Solver<Dtype>::Step(int iters) {\n  vector<Blob<Dtype>*> bottom_vec;\n  const int start_iter = iter_;\n  const int stop_iter = iter_ + iters;\n  int average_loss = this->param_.average_loss();\n  vector<Dtype> losses;\n  Dtype smoothed_loss = 0;\n\n  while (iter_ < stop_iter) {\n    // zero-init the params\n    net_->ClearParamDiffs();\n    if (param_.test_interval() && iter_ % param_.test_interval() == 0\n        && (iter_ > 0 || param_.test_initialization())\n        && Caffe::root_solver()) {\n      TestAll();\n    }\n\n    for (int i = 0; i < callbacks_.size(); ++i) {\n      callbacks_[i]->on_start();\n    }\n    const bool display = param_.display() && iter_ % param_.display() == 0;\n    net_->set_debug_info(display && param_.debug_info());\n\t\n    // Set current iteration number for dynamic network surgery\n    net_->set_current_iter_num(iter_);\n\t\n    // accumulate the loss and gradient\n    Dtype loss = 0;    \n    for (int i = 0; i < param_.iter_size(); ++i) {\n      loss += net_->ForwardBackward(bottom_vec);\n    }\n    loss /= param_.iter_size();\n    // average the loss across iterations for smoothed reporting\n    if (losses.size() < average_loss) {\n      losses.push_back(loss);\n      int size = losses.size();\n      smoothed_loss = (smoothed_loss * (size - 1) + loss) / size;\n    } else {\n      int idx = (iter_ - start_iter) % average_loss;\n      smoothed_loss += (loss - losses[idx]) / average_loss;\n      losses[idx] = loss;\n    }\n    if (display) {\n      LOG_IF(INFO, Caffe::root_solver()) << \"Iteration \" << iter_\n          << \", loss = \" << smoothed_loss;\n      const vector<Blob<Dtype>*>& result = net_->output_blobs();\n      int score_index = 0;\n      for (int j = 0; j < result.size(); ++j) {\n        const Dtype* result_vec = result[j]->cpu_data();\n        const string& output_name =\n            net_->blob_names()[net_->output_blob_indices()[j]];\n        const Dtype loss_weight =\n            net_->blob_loss_weights()[net_->output_blob_indices()[j]];\n        for (int k = 0; k < result[j]->count(); ++k) {\n          ostringstream loss_msg_stream;\n          if (loss_weight) {\n            loss_msg_stream << \" (* \" << loss_weight\n                            << \" = \" << loss_weight * result_vec[k] << \" loss)\";\n          }\n          LOG_IF(INFO, Caffe::root_solver()) << \"    Train net output #\"\n              << score_index++ << \": \" << output_name << \" = \"\n              << result_vec[k] << loss_msg_stream.str();\n        }\n      }\n    }\n    for (int i = 0; i < callbacks_.size(); ++i) {\n      callbacks_[i]->on_gradients_ready();\n    }\n    ApplyUpdate();\n\n    // Increment the internal iter_ counter -- its value should always indicate\n    // the number of times the weights have been updated.\n    ++iter_;\n\n    // Save a snapshot if needed.\n    if (param_.snapshot()\n        && iter_ % param_.snapshot() == 0\n        && Caffe::root_solver()) {\n      Snapshot();\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid Solver<Dtype>::Solve(const char* resume_file) {\n  CHECK(Caffe::root_solver());\n  LOG(INFO) << \"Solving \" << net_->name();\n  LOG(INFO) << \"Learning Rate Policy: \" << param_.lr_policy();\n\n  if (resume_file) {\n    LOG(INFO) << \"Restoring previous solver status from \" << resume_file;\n    Restore(resume_file);\n  }\n\n  // For a network that is trained by the solver, no bottom or top vecs\n  // should be given, and we will just provide dummy vecs.\n  Step(param_.max_iter() - iter_);\n  // If we haven't already, save a snapshot after optimization, unless\n  // overridden by setting snapshot_after_train := false\n  if (param_.snapshot_after_train()\n      && (!param_.snapshot() || iter_ % param_.snapshot() != 0)) {\n    Snapshot();\n  }\n  // After the optimization is done, run an additional train and test pass to\n  // display the train and test loss/outputs if appropriate (based on the\n  // display and test_interval settings, respectively).  Unlike in the rest of\n  // training, for the train net we only run a forward pass as we've already\n  // updated the parameters \"max_iter\" times -- this final pass is only done to\n  // display the loss, which is computed in the forward pass.\n  if (param_.display() && iter_ % param_.display() == 0) {\n    Dtype loss;\n    net_->ForwardPrefilled(&loss);\n    LOG(INFO) << \"Iteration \" << iter_ << \", loss = \" << loss;\n  }\n  if (param_.test_interval() && iter_ % param_.test_interval() == 0) {\n    TestAll();\n  }\n  LOG(INFO) << \"Optimization Done.\";\n}\n\n\ntemplate <typename Dtype>\nvoid Solver<Dtype>::TestAll() {\n  for (int test_net_id = 0; test_net_id < test_nets_.size(); ++test_net_id) {\n    Test(test_net_id);\n  }\n}\n\ntemplate <typename Dtype>\nvoid Solver<Dtype>::Test(const int test_net_id) {\n  CHECK(Caffe::root_solver());\n  LOG(INFO) << \"Iteration \" << iter_\n            << \", Testing net (#\" << test_net_id << \")\";\n  CHECK_NOTNULL(test_nets_[test_net_id].get())->\n      ShareTrainedLayersWith(net_.get());\n  vector<Dtype> test_score;\n  vector<int> test_score_output_id;\n  vector<Blob<Dtype>*> bottom_vec;\n  const shared_ptr<Net<Dtype> >& test_net = test_nets_[test_net_id];\n  Dtype loss = 0;\n  for (int i = 0; i < param_.test_iter(test_net_id); ++i) {\n    Dtype iter_loss;\n    const vector<Blob<Dtype>*>& result =\n        test_net->Forward(bottom_vec, &iter_loss);\n    if (param_.test_compute_loss()) {\n      loss += iter_loss;\n    }\n    if (i == 0) {\n      for (int j = 0; j < result.size(); ++j) {\n        const Dtype* result_vec = result[j]->cpu_data();\n        for (int k = 0; k < result[j]->count(); ++k) {\n          test_score.push_back(result_vec[k]);\n          test_score_output_id.push_back(j);\n        }\n      }\n    } else {\n      int idx = 0;\n      for (int j = 0; j < result.size(); ++j) {\n        const Dtype* result_vec = result[j]->cpu_data();\n        for (int k = 0; k < result[j]->count(); ++k) {\n          test_score[idx++] += result_vec[k];\n        }\n      }\n    }\n  }\n  if (param_.test_compute_loss()) {\n    loss /= param_.test_iter(test_net_id);\n    LOG(INFO) << \"Test loss: \" << loss;\n  }\n  for (int i = 0; i < test_score.size(); ++i) {\n    const int output_blob_index =\n        test_net->output_blob_indices()[test_score_output_id[i]];\n    const string& output_name = test_net->blob_names()[output_blob_index];\n    const Dtype loss_weight = test_net->blob_loss_weights()[output_blob_index];\n    ostringstream loss_msg_stream;\n    const Dtype mean_score = test_score[i] / param_.test_iter(test_net_id);\n    if (loss_weight) {\n      loss_msg_stream << \" (* \" << loss_weight\n                      << \" = \" << loss_weight * mean_score << \" loss)\";\n    }\n    LOG(INFO) << \"    Test net output #\" << i << \": \" << output_name << \" = \"\n              << mean_score << loss_msg_stream.str();\n  }\n}\n\n\ntemplate <typename Dtype>\nvoid Solver<Dtype>::Snapshot() {\n  CHECK(Caffe::root_solver());\n  string model_filename;\n  switch (param_.snapshot_format()) {\n    case caffe::SolverParameter_SnapshotFormat_BINARYPROTO:\n      model_filename = SnapshotToBinaryProto();\n      break;\n    case caffe::SolverParameter_SnapshotFormat_HDF5:\n      model_filename = SnapshotToHDF5();\n      break;\n    default:\n      LOG(FATAL) << \"Unsupported snapshot format.\";\n  }\n\n  SnapshotSolverState(model_filename);\n}\n\ntemplate <typename Dtype>\nstring Solver<Dtype>::SnapshotFilename(const string extension) {\n  string filename(param_.snapshot_prefix());\n  const int kBufferSize = 20;\n  char iter_str_buffer[kBufferSize];\n  snprintf(iter_str_buffer, kBufferSize, \"_iter_%d\", iter_);\n  return filename + iter_str_buffer + extension;\n}\n\ntemplate <typename Dtype>\nstring Solver<Dtype>::SnapshotToBinaryProto() {\n  string model_filename = SnapshotFilename(\".caffemodel\");\n  LOG(INFO) << \"Snapshotting to binary proto file \" << model_filename;\n  NetParameter net_param;\n  net_->ToProto(&net_param, param_.snapshot_diff());\n  WriteProtoToBinaryFile(net_param, model_filename);\n  return model_filename;\n}\n\ntemplate <typename Dtype>\nstring Solver<Dtype>::SnapshotToHDF5() {\n  string model_filename = SnapshotFilename(\".caffemodel.h5\");\n  LOG(INFO) << \"Snapshotting to HDF5 file \" << model_filename;\n  net_->ToHDF5(model_filename, param_.snapshot_diff());\n  return model_filename;\n}\n\ntemplate <typename Dtype>\nvoid Solver<Dtype>::Restore(const char* state_file) {\n  CHECK(Caffe::root_solver());\n  string state_filename(state_file);\n  if (state_filename.size() >= 3 &&\n      state_filename.compare(state_filename.size() - 3, 3, \".h5\") == 0) {\n    RestoreSolverStateFromHDF5(state_filename);\n  } else {\n    RestoreSolverStateFromBinaryProto(state_filename);\n  }\n}\n\n// Return the current learning rate. The currently implemented learning rate\n// policies are as follows:\n//    - fixed: always return base_lr.\n//    - step: return base_lr * gamma ^ (floor(iter / step))\n//    - exp: return base_lr * gamma ^ iter\n//    - inv: return base_lr * (1 + gamma * iter) ^ (- power)\n//    - multistep: similar to step but it allows non uniform steps defined by\n//      stepvalue\n//    - poly: the effective learning rate follows a polynomial decay, to be\n//      zero by the max_iter. return base_lr (1 - iter/max_iter) ^ (power)\n//    - sigmoid: the effective learning rate follows a sigmod decay\n//      return base_lr ( 1/(1 + exp(-gamma * (iter - stepsize))))\n//\n// where base_lr, max_iter, gamma, step, stepvalue and power are defined\n// in the solver parameter protocol buffer, and iter is the current iteration.\ntemplate <typename Dtype>\nDtype SGDSolver<Dtype>::GetLearningRate() {\n  Dtype rate;\n  const string& lr_policy = this->param_.lr_policy();\n  if (lr_policy == \"fixed\") {\n    rate = this->param_.base_lr();\n  } else if (lr_policy == \"step\") {\n    this->current_step_ = this->iter_ / this->param_.stepsize();\n    rate = this->param_.base_lr() *\n        pow(this->param_.gamma(), this->current_step_);\n  } else if (lr_policy == \"exp\") {\n    rate = this->param_.base_lr() * pow(this->param_.gamma(), this->iter_);\n  } else if (lr_policy == \"inv\") {\n    rate = this->param_.base_lr() *\n        pow(Dtype(1) + this->param_.gamma() * this->iter_,\n            - this->param_.power());\n  } else if (lr_policy == \"multistep\") {\n    if (this->current_step_ < this->param_.stepvalue_size() &&\n          this->iter_ >= this->param_.stepvalue(this->current_step_)) {\n      this->current_step_++;\n      LOG(INFO) << \"MultiStep Status: Iteration \" <<\n      this->iter_ << \", step = \" << this->current_step_;\n    }\n    rate = this->param_.base_lr() *\n        pow(this->param_.gamma(), this->current_step_);\n  } else if (lr_policy == \"poly\") {\n    rate = this->param_.base_lr() * pow(Dtype(1.) -\n        (Dtype(this->iter_) / Dtype(this->param_.max_iter())),\n        this->param_.power());\n  } else if (lr_policy == \"sigmoid\") {\n    rate = this->param_.base_lr() * (Dtype(1.) /\n        (Dtype(1.) + exp(-this->param_.gamma() * (Dtype(this->iter_) -\n          Dtype(this->param_.stepsize())))));\n  } else {\n    LOG(FATAL) << \"Unknown learning rate policy: \" << lr_policy;\n  }\n  return rate;\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::PreSolve() {\n  // Initialize the history\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  history_.clear();\n  update_.clear();\n  temp_.clear();\n  for (int i = 0; i < net_params.size(); ++i) {\n    const vector<int>& shape = net_params[i]->shape();\n    history_.push_back(shared_ptr<Blob<Dtype> >(new Blob<Dtype>(shape)));\n    update_.push_back(shared_ptr<Blob<Dtype> >(new Blob<Dtype>(shape)));\n    temp_.push_back(shared_ptr<Blob<Dtype> >(new Blob<Dtype>(shape)));\n  }\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::ClipGradients() {\n  const Dtype clip_gradients = this->param_.clip_gradients();\n  if (clip_gradients < 0) { return; }\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  Dtype sumsq_diff = 0;\n  for (int i = 0; i < net_params.size(); ++i) {\n    sumsq_diff += net_params[i]->sumsq_diff();\n  }\n  const Dtype l2norm_diff = std::sqrt(sumsq_diff);\n  if (l2norm_diff > clip_gradients) {\n    Dtype scale_factor = clip_gradients / l2norm_diff;\n    LOG(INFO) << \"Gradient clipping: scaling down gradients (L2 norm \"\n        << l2norm_diff << \" > \" << clip_gradients << \") \"\n        << \"by scale factor \" << scale_factor;\n    for (int i = 0; i < net_params.size(); ++i) {\n      net_params[i]->scale_diff(scale_factor);\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::ApplyUpdate() {\n  CHECK(Caffe::root_solver());\n  Dtype rate = GetLearningRate();\n  if (this->param_.display() && this->iter_ % this->param_.display() == 0) {\n    LOG(INFO) << \"Iteration \" << this->iter_ << \", lr = \" << rate;\n  }\n  ClipGradients();\n  for (int param_id = 0; param_id < this->net_->learnable_params().size();\n       ++param_id) {\n    Normalize(param_id);\n    Regularize(param_id);\n    ComputeUpdateValue(param_id, rate);\n  }\n  this->net_->Update();\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::Normalize(int param_id) {\n  if (this->param_.iter_size() == 1) { return; }\n  // Scale gradient to counterbalance accumulation.\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  const Dtype accum_normalization = Dtype(1.) / this->param_.iter_size();\n  switch (Caffe::mode()) {\n  case Caffe::CPU: {\n    caffe_scal(net_params[param_id]->count(), accum_normalization,\n        net_params[param_id]->mutable_cpu_diff());\n    break;\n  }\n  case Caffe::GPU: {\n#ifndef CPU_ONLY\n    caffe_gpu_scal(net_params[param_id]->count(), accum_normalization,\n        net_params[param_id]->mutable_gpu_diff());\n#else\n    NO_GPU;\n#endif\n    break;\n  }\n  default:\n    LOG(FATAL) << \"Unknown caffe mode: \" << Caffe::mode();\n  }\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::Regularize(int param_id) {\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  const vector<float>& net_params_weight_decay =\n      this->net_->params_weight_decay();\n  Dtype weight_decay = this->param_.weight_decay();\n  string regularization_type = this->param_.regularization_type();\n  Dtype local_decay = weight_decay * net_params_weight_decay[param_id];\n  switch (Caffe::mode()) {\n  case Caffe::CPU: {\n    if (local_decay) {\n      if (regularization_type == \"L2\") {\n        // add weight decay\n        caffe_axpy(net_params[param_id]->count(),\n            local_decay,\n            net_params[param_id]->cpu_data(),\n            net_params[param_id]->mutable_cpu_diff());\n      } else if (regularization_type == \"L1\") {\n        caffe_cpu_sign(net_params[param_id]->count(),\n            net_params[param_id]->cpu_data(),\n            temp_[param_id]->mutable_cpu_data());\n        caffe_axpy(net_params[param_id]->count(),\n            local_decay,\n            temp_[param_id]->cpu_data(),\n            net_params[param_id]->mutable_cpu_diff());\n      } else {\n        LOG(FATAL) << \"Unknown regularization type: \" << regularization_type;\n      }\n    }\n    break;\n  }\n  case Caffe::GPU: {\n#ifndef CPU_ONLY\n    if (local_decay) {\n      if (regularization_type == \"L2\") {\n        // add weight decay\n        caffe_gpu_axpy(net_params[param_id]->count(),\n            local_decay,\n            net_params[param_id]->gpu_data(),\n            net_params[param_id]->mutable_gpu_diff());\n      } else if (regularization_type == \"L1\") {\n        caffe_gpu_sign(net_params[param_id]->count(),\n            net_params[param_id]->gpu_data(),\n            temp_[param_id]->mutable_gpu_data());\n        caffe_gpu_axpy(net_params[param_id]->count(),\n            local_decay,\n            temp_[param_id]->gpu_data(),\n            net_params[param_id]->mutable_gpu_diff());\n      } else {\n        LOG(FATAL) << \"Unknown regularization type: \" << regularization_type;\n      }\n    }\n#else\n    NO_GPU;\n#endif\n    break;\n  }\n  default:\n    LOG(FATAL) << \"Unknown caffe mode: \" << Caffe::mode();\n  }\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  const vector<float>& net_params_lr = this->net_->params_lr();\n  Dtype momentum = this->param_.momentum();\n  Dtype local_rate = rate * net_params_lr[param_id];\n  // Compute the update to history, then copy it to the parameter diff.\n  switch (Caffe::mode()) {\n  case Caffe::CPU: {\n    caffe_cpu_axpby(net_params[param_id]->count(), local_rate,\n              net_params[param_id]->cpu_diff(), momentum,\n              history_[param_id]->mutable_cpu_data());\n    caffe_copy(net_params[param_id]->count(),\n        history_[param_id]->cpu_data(),\n        net_params[param_id]->mutable_cpu_diff());\n    break;\n  }\n  case Caffe::GPU: {\n#ifndef CPU_ONLY\n    caffe_gpu_axpby(net_params[param_id]->count(), local_rate,\n              net_params[param_id]->gpu_diff(), momentum,\n              history_[param_id]->mutable_gpu_data());\n    caffe_copy(net_params[param_id]->count(),\n        history_[param_id]->gpu_data(),\n        net_params[param_id]->mutable_gpu_diff());\n#else\n    NO_GPU;\n#endif\n    break;\n  }\n  default:\n    LOG(FATAL) << \"Unknown caffe mode: \" << Caffe::mode();\n  }\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::SnapshotSolverState(const string& model_filename) {\n  switch (this->param_.snapshot_format()) {\n    case caffe::SolverParameter_SnapshotFormat_BINARYPROTO:\n      SnapshotSolverStateToBinaryProto(model_filename);\n      break;\n    case caffe::SolverParameter_SnapshotFormat_HDF5:\n      SnapshotSolverStateToHDF5(model_filename);\n      break;\n    default:\n      LOG(FATAL) << \"Unsupported snapshot format.\";\n  }\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::SnapshotSolverStateToBinaryProto(\n    const string& model_filename) {\n  SolverState state;\n  state.set_iter(this->iter_);\n  state.set_learned_net(model_filename);\n  state.set_current_step(this->current_step_);\n  state.clear_history();\n  for (int i = 0; i < history_.size(); ++i) {\n    // Add history\n    BlobProto* history_blob = state.add_history();\n    history_[i]->ToProto(history_blob);\n  }\n  string snapshot_filename = Solver<Dtype>::SnapshotFilename(\".solverstate\");\n  LOG(INFO)\n    << \"Snapshotting solver state to binary proto file\" << snapshot_filename;\n  WriteProtoToBinaryFile(state, snapshot_filename.c_str());\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::SnapshotSolverStateToHDF5(\n    const string& model_filename) {\n  string snapshot_filename =\n      Solver<Dtype>::SnapshotFilename(\".solverstate.h5\");\n  LOG(INFO) << \"Snapshotting solver state to HDF5 file \" << snapshot_filename;\n  hid_t file_hid = H5Fcreate(snapshot_filename.c_str(), H5F_ACC_TRUNC,\n      H5P_DEFAULT, H5P_DEFAULT);\n  CHECK_GE(file_hid, 0)\n      << \"Couldn't open \" << snapshot_filename << \" to save solver state.\";\n  hdf5_save_int(file_hid, \"iter\", this->iter_);\n  hdf5_save_string(file_hid, \"learned_net\", model_filename);\n  hdf5_save_int(file_hid, \"current_step\", this->current_step_);\n  hid_t history_hid = H5Gcreate2(file_hid, \"history\", H5P_DEFAULT, H5P_DEFAULT,\n      H5P_DEFAULT);\n  CHECK_GE(history_hid, 0)\n      << \"Error saving solver state to \" << snapshot_filename << \".\";\n  for (int i = 0; i < history_.size(); ++i) {\n    ostringstream oss;\n    oss << i;\n    hdf5_save_nd_dataset<Dtype>(history_hid, oss.str(), *history_[i]);\n  }\n  H5Gclose(history_hid);\n  H5Fclose(file_hid);\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::RestoreSolverStateFromBinaryProto(\n    const string& state_file) {\n  SolverState state;\n  ReadProtoFromBinaryFile(state_file, &state);\n  this->iter_ = state.iter();\n  if (state.has_learned_net()) {\n    NetParameter net_param;\n    ReadNetParamsFromBinaryFileOrDie(state.learned_net().c_str(), &net_param);\n    this->net_->CopyTrainedLayersFrom(net_param);\n  }\n  this->current_step_ = state.current_step();\n  CHECK_EQ(state.history_size(), history_.size())\n      << \"Incorrect length of history blobs.\";\n  LOG(INFO) << \"SGDSolver: restoring history\";\n  for (int i = 0; i < history_.size(); ++i) {\n    history_[i]->FromProto(state.history(i));\n  }\n}\n\ntemplate <typename Dtype>\nvoid SGDSolver<Dtype>::RestoreSolverStateFromHDF5(const string& state_file) {\n  hid_t file_hid = H5Fopen(state_file.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);\n  CHECK_GE(file_hid, 0) << \"Couldn't open solver state file \" << state_file;\n  this->iter_ = hdf5_load_int(file_hid, \"iter\");\n  if (H5LTfind_dataset(file_hid, \"learned_net\")) {\n    string learned_net = hdf5_load_string(file_hid, \"learned_net\");\n    this->net_->CopyTrainedLayersFrom(learned_net);\n  }\n  this->current_step_ = hdf5_load_int(file_hid, \"current_step\");\n  hid_t history_hid = H5Gopen2(file_hid, \"history\", H5P_DEFAULT);\n  CHECK_GE(history_hid, 0) << \"Error reading history from \" << state_file;\n  int state_history_size = hdf5_get_num_links(history_hid);\n  CHECK_EQ(state_history_size, history_.size())\n      << \"Incorrect length of history blobs.\";\n  for (int i = 0; i < history_.size(); ++i) {\n    ostringstream oss;\n    oss << i;\n    hdf5_load_nd_dataset<Dtype>(history_hid, oss.str().c_str(), 0,\n                                kMaxBlobAxes, history_[i].get());\n  }\n  H5Gclose(history_hid);\n  H5Fclose(file_hid);\n}\n\ntemplate <typename Dtype>\nvoid NesterovSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {\n  CHECK(Caffe::root_solver());\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  const vector<float>& net_params_lr = this->net_->params_lr();\n  Dtype momentum = this->param_.momentum();\n  Dtype local_rate = rate * net_params_lr[param_id];\n  switch (Caffe::mode()) {\n  case Caffe::CPU: {\n    // save history momentum for stepping back\n    caffe_copy(net_params[param_id]->count(),\n        this->history_[param_id]->cpu_data(),\n        this->update_[param_id]->mutable_cpu_data());\n\n    // update history\n    caffe_cpu_axpby(net_params[param_id]->count(), local_rate,\n              net_params[param_id]->cpu_diff(), momentum,\n              this->history_[param_id]->mutable_cpu_data());\n\n    // compute update: step back then over step\n    caffe_cpu_axpby(net_params[param_id]->count(), Dtype(1) + momentum,\n        this->history_[param_id]->cpu_data(), -momentum,\n        this->update_[param_id]->mutable_cpu_data());\n\n    // copy\n    caffe_copy(net_params[param_id]->count(),\n        this->update_[param_id]->cpu_data(),\n        net_params[param_id]->mutable_cpu_diff());\n    break;\n  }\n  case Caffe::GPU: {\n#ifndef CPU_ONLY\n    // save history momentum for stepping back\n    caffe_copy(net_params[param_id]->count(),\n        this->history_[param_id]->gpu_data(),\n        this->update_[param_id]->mutable_gpu_data());\n\n    // update history\n    caffe_gpu_axpby(net_params[param_id]->count(), local_rate,\n              net_params[param_id]->gpu_diff(), momentum,\n              this->history_[param_id]->mutable_gpu_data());\n\n    // compute update: step back then over step\n    caffe_gpu_axpby(net_params[param_id]->count(), Dtype(1) + momentum,\n        this->history_[param_id]->gpu_data(), -momentum,\n        this->update_[param_id]->mutable_gpu_data());\n\n    // copy\n    caffe_copy(net_params[param_id]->count(),\n        this->update_[param_id]->gpu_data(),\n        net_params[param_id]->mutable_gpu_diff());\n#else\n    NO_GPU;\n#endif\n    break;\n  }\n  default:\n    LOG(FATAL) << \"Unknown caffe mode: \" << Caffe::mode();\n  }\n}\n\ntemplate <typename Dtype>\nvoid AdaGradSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {\n  CHECK(Caffe::root_solver());\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  const vector<float>& net_params_lr = this->net_->params_lr();\n  Dtype delta = this->param_.delta();\n  Dtype local_rate = rate * net_params_lr[param_id];\n  switch (Caffe::mode()) {\n  case Caffe::CPU: {\n    // compute square of gradient in update\n    caffe_powx(net_params[param_id]->count(),\n        net_params[param_id]->cpu_diff(), Dtype(2),\n        this->update_[param_id]->mutable_cpu_data());\n\n    // update history\n    caffe_add(net_params[param_id]->count(),\n        this->update_[param_id]->cpu_data(),\n        this->history_[param_id]->cpu_data(),\n        this->history_[param_id]->mutable_cpu_data());\n\n    // prepare update\n    caffe_powx(net_params[param_id]->count(),\n              this->history_[param_id]->cpu_data(), Dtype(0.5),\n              this->update_[param_id]->mutable_cpu_data());\n\n    caffe_add_scalar(net_params[param_id]->count(),\n              delta, this->update_[param_id]->mutable_cpu_data());\n\n    caffe_div(net_params[param_id]->count(),\n              net_params[param_id]->cpu_diff(),\n              this->update_[param_id]->cpu_data(),\n              this->update_[param_id]->mutable_cpu_data());\n\n    // scale and copy\n    caffe_cpu_axpby(net_params[param_id]->count(), local_rate,\n        this->update_[param_id]->cpu_data(), Dtype(0),\n        net_params[param_id]->mutable_cpu_diff());\n    break;\n  }\n  case Caffe::GPU: {\n#ifndef CPU_ONLY\n    // compute square of gradient in update\n    caffe_gpu_powx(net_params[param_id]->count(),\n        net_params[param_id]->gpu_diff(), Dtype(2),\n        this->update_[param_id]->mutable_gpu_data());\n\n    // update history\n    caffe_gpu_add(net_params[param_id]->count(),\n        this->update_[param_id]->gpu_data(),\n        this->history_[param_id]->gpu_data(),\n        this->history_[param_id]->mutable_gpu_data());\n\n    // prepare update\n    caffe_gpu_powx(net_params[param_id]->count(),\n              this->history_[param_id]->gpu_data(), Dtype(0.5),\n              this->update_[param_id]->mutable_gpu_data());\n\n    caffe_gpu_add_scalar(net_params[param_id]->count(),\n              delta, this->update_[param_id]->mutable_gpu_data());\n\n    caffe_gpu_div(net_params[param_id]->count(),\n              net_params[param_id]->gpu_diff(),\n              this->update_[param_id]->gpu_data(),\n              this->update_[param_id]->mutable_gpu_data());\n\n    // scale and copy\n    caffe_gpu_axpby(net_params[param_id]->count(), local_rate,\n        this->update_[param_id]->gpu_data(), Dtype(0),\n        net_params[param_id]->mutable_gpu_diff());\n#else\n    NO_GPU;\n#endif\n    break;\n  }\n  default:\n    LOG(FATAL) << \"Unknown caffe mode: \" << Caffe::mode();\n  }\n}\n\ntemplate <typename Dtype>\nvoid RMSPropSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  const vector<float>& net_params_lr = this->net_->params_lr();\n\n  // get the learning rate\n  Dtype delta = this->param_.delta();\n  Dtype rms_decay = this->param_.rms_decay();\n  Dtype local_rate = rate * net_params_lr[param_id];\n\n  switch (Caffe::mode()) {\n  case Caffe::CPU:\n    // compute square of gradient in update\n    caffe_powx(net_params[param_id]->count(),\n        net_params[param_id]->cpu_diff(), Dtype(2),\n        this->update_[param_id]->mutable_cpu_data());\n\n    // update history\n    caffe_cpu_axpby(net_params[param_id] -> count(),\n        Dtype(1-rms_decay), this->update_[param_id]->cpu_data(),\n        rms_decay, this->history_[param_id]-> mutable_cpu_data());\n\n    // prepare update\n    caffe_powx(net_params[param_id]->count(),\n        this->history_[param_id]->cpu_data(), Dtype(0.5),\n        this->update_[param_id]->mutable_cpu_data());\n\n    caffe_add_scalar(net_params[param_id]->count(),\n        delta, this->update_[param_id]->mutable_cpu_data());\n\n    caffe_div(net_params[param_id]->count(),\n        net_params[param_id]->cpu_diff(), this->update_[param_id]->cpu_data(),\n        this->update_[param_id]->mutable_cpu_data());\n\n    // scale and copy\n    caffe_cpu_axpby(net_params[param_id]->count(), local_rate,\n        this->update_[param_id]->cpu_data(), Dtype(0),\n        net_params[param_id]->mutable_cpu_diff());\n    break;\n  case Caffe::GPU:\n#ifndef CPU_ONLY\n    // compute square of gradient in update\n    caffe_gpu_powx(net_params[param_id]->count(),\n        net_params[param_id]->gpu_diff(), Dtype(2),\n        this->update_[param_id]->mutable_gpu_data());\n\n    // update history\n    caffe_gpu_axpby(net_params[param_id] -> count(),\n        Dtype(1-rms_decay), this->update_[param_id]->gpu_data(),\n        rms_decay, this->history_[param_id]-> mutable_gpu_data());\n\n    // prepare update\n    caffe_gpu_powx(net_params[param_id]->count(),\n        this->history_[param_id]->gpu_data(), Dtype(0.5),\n        this->update_[param_id]->mutable_gpu_data());\n\n    caffe_gpu_add_scalar(net_params[param_id]->count(),\n        delta, this->update_[param_id]->mutable_gpu_data());\n\n    caffe_gpu_div(net_params[param_id]->count(),\n        net_params[param_id]->gpu_diff(), this->update_[param_id]->gpu_data(),\n        this->update_[param_id]->mutable_gpu_data());\n\n    caffe_gpu_axpby(net_params[param_id]->count(), local_rate,\n        this->update_[param_id]->gpu_data(), Dtype(0),\n        net_params[param_id]->mutable_gpu_diff());\n#else\n    NO_GPU;\n#endif\n    break;\n  default:\n    LOG(FATAL) << \"Unknown caffe mode: \" << Caffe::mode();\n  }\n}\n\ntemplate <typename Dtype>\nvoid AdaDeltaSolver<Dtype>::AdaDeltaPreSolve() {\n  // Add the extra history entries for AdaDelta after those from\n  // SGDSolver::PreSolve\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  for (int i = 0; i < net_params.size(); ++i) {\n        const vector<int>& shape = net_params[i]->shape();\n        this->history_.push_back(\n                shared_ptr<Blob<Dtype> >(new Blob<Dtype>(shape)));\n  }\n}\n\ntemplate <typename Dtype>\nvoid AdaDeltaSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  const vector<float>& net_params_lr = this->net_->params_lr();\n  Dtype delta = this->param_.delta();\n  Dtype momentum = this->param_.momentum();\n  Dtype local_rate = rate * net_params_lr[param_id];\n  size_t update_history_offset = net_params.size();\n  switch (Caffe::mode()) {\n  case Caffe::CPU: {\n    // compute square of gradient in update\n    caffe_powx(net_params[param_id]->count(),\n        net_params[param_id]->cpu_diff(), Dtype(2),\n        this->update_[param_id]->mutable_cpu_data());\n\n    // update history of gradients\n    caffe_cpu_axpby(net_params[param_id]->count(), Dtype(1) - momentum,\n        this->update_[param_id]->cpu_data(), momentum,\n        this->history_[param_id]->mutable_cpu_data());\n\n    // add delta to history to guard against dividing by zero later\n    caffe_set(net_params[param_id]->count(), delta,\n        this->temp_[param_id]->mutable_cpu_data());\n\n    caffe_add(net_params[param_id]->count(),\n        this->temp_[param_id]->cpu_data(),\n        this->history_[update_history_offset + param_id]->cpu_data(),\n        this->update_[param_id]->mutable_cpu_data());\n\n    caffe_add(net_params[param_id]->count(),\n        this->temp_[param_id]->cpu_data(),\n        this->history_[param_id]->cpu_data(),\n        this->temp_[param_id]->mutable_cpu_data());\n\n    // divide history of updates by history of gradients\n    caffe_div(net_params[param_id]->count(),\n        this->update_[param_id]->cpu_data(),\n        this->temp_[param_id]->cpu_data(),\n        this->update_[param_id]->mutable_cpu_data());\n\n    // jointly compute the RMS of both for update and gradient history\n    caffe_powx(net_params[param_id]->count(),\n        this->update_[param_id]->cpu_data(), Dtype(0.5),\n        this->update_[param_id]->mutable_cpu_data());\n\n    // compute the update\n    caffe_mul(net_params[param_id]->count(),\n        net_params[param_id]->cpu_diff(),\n        this->update_[param_id]->cpu_data(),\n        net_params[param_id]->mutable_cpu_diff());\n\n    // compute square of update\n    caffe_powx(net_params[param_id]->count(),\n        net_params[param_id]->cpu_diff(), Dtype(2),\n        this->update_[param_id]->mutable_cpu_data());\n\n    // update history of updates\n    caffe_cpu_axpby(net_params[param_id]->count(), Dtype(1) - momentum,\n        this->update_[param_id]->cpu_data(), momentum,\n        this->history_[update_history_offset + param_id]->mutable_cpu_data());\n\n    // apply learning rate\n    caffe_cpu_scale(net_params[param_id]->count(), local_rate,\n        net_params[param_id]->cpu_diff(),\n        net_params[param_id]->mutable_cpu_diff());\n    break;\n  }\n  case Caffe::GPU: {\n#ifndef CPU_ONLY\n    // compute square of gradient in update\n    caffe_gpu_powx(net_params[param_id]->count(),\n        net_params[param_id]->gpu_diff(), Dtype(2),\n        this->update_[param_id]->mutable_gpu_data());\n\n    // update history of gradients\n    caffe_gpu_axpby(net_params[param_id]->count(), Dtype(1) - momentum,\n        this->update_[param_id]->gpu_data(), momentum,\n        this->history_[param_id]->mutable_gpu_data());\n\n    // add delta to history to guard against dividing by zero later\n    caffe_gpu_set(net_params[param_id]->count(), delta,\n        this->temp_[param_id]->mutable_gpu_data());\n\n    caffe_gpu_add(net_params[param_id]->count(),\n        this->temp_[param_id]->gpu_data(),\n        this->history_[update_history_offset + param_id]->gpu_data(),\n        this->update_[param_id]->mutable_gpu_data());\n\n    caffe_gpu_add(net_params[param_id]->count(),\n        this->temp_[param_id]->gpu_data(),\n        this->history_[param_id]->gpu_data(),\n        this->temp_[param_id]->mutable_gpu_data());\n\n    // divide history of updates by history of gradients\n    caffe_gpu_div(net_params[param_id]->count(),\n        this->update_[param_id]->gpu_data(),\n        this->temp_[param_id]->gpu_data(),\n        this->update_[param_id]->mutable_gpu_data());\n\n    // jointly compute the RMS of both for update and gradient history\n    caffe_gpu_powx(net_params[param_id]->count(),\n        this->update_[param_id]->gpu_data(), Dtype(0.5),\n        this->update_[param_id]->mutable_gpu_data());\n\n    // compute the update and copy to net_diff\n    caffe_gpu_mul(net_params[param_id]->count(),\n        net_params[param_id]->gpu_diff(),\n        this->update_[param_id]->gpu_data(),\n        net_params[param_id]->mutable_gpu_diff());\n\n    // compute square of update\n    caffe_gpu_powx(net_params[param_id]->count(),\n        net_params[param_id]->gpu_diff(), Dtype(2),\n        this->update_[param_id]->mutable_gpu_data());\n\n    // update history of updates\n    caffe_gpu_axpby(net_params[param_id]->count(), Dtype(1) - momentum,\n        this->update_[param_id]->gpu_data(), momentum,\n        this->history_[update_history_offset + param_id]->mutable_gpu_data());\n\n    // apply learning rate\n    caffe_gpu_scale(net_params[param_id]->count(), local_rate,\n        net_params[param_id]->gpu_diff(),\n        net_params[param_id]->mutable_gpu_diff());\n#else\n    NO_GPU;\n#endif\n    break;\n  }\n  default:\n    LOG(FATAL) << \"Unknown caffe mode: \" << Caffe::mode();\n  }\n}\n\ntemplate <typename Dtype>\nvoid AdamSolver<Dtype>::AdamPreSolve() {\n  // Add the extra history entries for Adam after those from\n  // SGDSolver::PreSolve\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  for (int i = 0; i < net_params.size(); ++i) {\n    const vector<int>& shape = net_params[i]->shape();\n    this->history_.push_back(\n            shared_ptr<Blob<Dtype> >(new Blob<Dtype>(shape)));\n  }\n}\n\ntemplate <typename Dtype>\nvoid AdamSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {\n  const vector<Blob<Dtype>*>& net_params = this->net_->learnable_params();\n  const vector<float>& net_params_lr = this->net_->params_lr();\n  Dtype local_rate = rate * net_params_lr[param_id];\n  const Dtype beta1 = this->param_.momentum();\n  const Dtype beta2 = this->param_.momentum2();\n\n  // we create aliases for convenience\n  size_t update_history_offset = net_params.size();\n  Blob<Dtype>* val_m = this->history_[param_id].get();\n  Blob<Dtype>* val_v = this->history_[param_id + update_history_offset].get();\n  Blob<Dtype>* val_t = this->temp_[param_id].get();\n\n  const int t = this->iter_  + 1;\n  const Dtype correction = std::sqrt(Dtype(1) - pow(beta2, t)) /\n      (Dtype(1.) - pow(beta1, t));\n  const int N = net_params[param_id]->count();\n  const Dtype eps_hat = this->param_.delta();\n\n  switch (Caffe::mode()) {\n    case Caffe::CPU: {\n    // update m <- \\beta_1 m_{t-1} + (1-\\beta_1)g_t\n    caffe_cpu_axpby(N, Dtype(1)-beta1,\n        net_params[param_id]->cpu_diff(), beta1,\n        val_m->mutable_cpu_data());\n\n    // update v <- \\beta_2 m_{t-1} + (1-\\beta_2)g_t^2\n    caffe_mul(N,\n        net_params[param_id]->cpu_diff(),\n        net_params[param_id]->cpu_diff(),\n    val_t->mutable_cpu_data());\n    caffe_cpu_axpby(N, Dtype(1)-beta2,\n        val_t->cpu_data(), beta2,\n        val_v->mutable_cpu_data());\n\n    // set update\n    caffe_powx(N,\n        val_v->cpu_data(), Dtype(0.5),\n        val_t->mutable_cpu_data());\n    caffe_add_scalar(N, eps_hat, val_t->mutable_cpu_data());\n    caffe_div(N,\n        val_m->cpu_data(),\n        val_t->cpu_data(),\n        val_t->mutable_cpu_data());\n\n    caffe_cpu_scale(N, local_rate*correction,\n        val_t->cpu_data(),\n        net_params[param_id]->mutable_cpu_diff());\n    break;\n  }\n  case Caffe::GPU: {\n#ifndef CPU_ONLY\n    // update m <- \\beta_1 m_{t-1} + (1-\\beta_1)g_t\n    caffe_gpu_axpby(N, Dtype(1)-beta1,\n        net_params[param_id]->gpu_diff(), beta1,\n        val_m->mutable_gpu_data());\n\n    // update v <- \\beta_2 m_{t-1} + (1-\\beta_2)g_t^2\n    caffe_gpu_mul(N,\n        net_params[param_id]->gpu_diff(),\n        net_params[param_id]->gpu_diff(),\n        val_t->mutable_gpu_data());\n    caffe_gpu_axpby(N, Dtype(1)-beta2,\n        val_t->gpu_data(), beta2,\n        val_v->mutable_gpu_data());\n\n    // set update\n    caffe_gpu_powx(N,\n        val_v->gpu_data(), Dtype(0.5),\n        val_t->mutable_gpu_data());\n    caffe_gpu_add_scalar(N, eps_hat,\n        val_t->mutable_gpu_data());\n    caffe_gpu_div(N,\n        val_m->gpu_data(),\n        val_t->gpu_data(),\n        val_t->mutable_gpu_data());\n\n    caffe_gpu_scale(N, local_rate*correction,\n        val_t->gpu_data(),\n        net_params[param_id]->mutable_gpu_diff());\n#else\n    NO_GPU;\n#endif\n    break;\n  }\n  default:\n    LOG(FATAL) << \"Unknown caffe mode: \" << Caffe::mode();\n  }\n}\n\nINSTANTIATE_CLASS(Solver);\nINSTANTIATE_CLASS(SGDSolver);\nINSTANTIATE_CLASS(NesterovSolver);\nINSTANTIATE_CLASS(AdaGradSolver);\nINSTANTIATE_CLASS(RMSPropSolver);\nINSTANTIATE_CLASS(AdaDeltaSolver);\nINSTANTIATE_CLASS(AdamSolver);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/syncedmem.cpp",
    "content": "#include <cstring>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\nSyncedMemory::~SyncedMemory() {\n  if (cpu_ptr_ && own_cpu_data_) {\n    CaffeFreeHost(cpu_ptr_);\n  }\n\n#ifndef CPU_ONLY\n  if (gpu_ptr_ && own_gpu_data_) {\n    int initial_device;\n    cudaGetDevice(&initial_device);\n    if (gpu_device_ != -1) {\n      CUDA_CHECK(cudaSetDevice(gpu_device_));\n    }\n    CUDA_CHECK(cudaFree(gpu_ptr_));\n    cudaSetDevice(initial_device);\n  }\n#endif  // CPU_ONLY\n}\n\ninline void SyncedMemory::to_cpu() {\n  switch (head_) {\n  case UNINITIALIZED:\n    CaffeMallocHost(&cpu_ptr_, size_);\n    caffe_memset(size_, 0, cpu_ptr_);\n    head_ = HEAD_AT_CPU;\n    own_cpu_data_ = true;\n    break;\n  case HEAD_AT_GPU:\n#ifndef CPU_ONLY\n    if (cpu_ptr_ == NULL) {\n      CaffeMallocHost(&cpu_ptr_, size_);\n      own_cpu_data_ = true;\n    }\n    caffe_gpu_memcpy(size_, gpu_ptr_, cpu_ptr_);\n    head_ = SYNCED;\n#else\n    NO_GPU;\n#endif\n    break;\n  case HEAD_AT_CPU:\n  case SYNCED:\n    break;\n  }\n}\n\ninline void SyncedMemory::to_gpu() {\n#ifndef CPU_ONLY\n  switch (head_) {\n  case UNINITIALIZED:\n    CUDA_CHECK(cudaGetDevice(&gpu_device_));\n    CUDA_CHECK(cudaMalloc(&gpu_ptr_, size_));\n    caffe_gpu_memset(size_, 0, gpu_ptr_);\n    head_ = HEAD_AT_GPU;\n    own_gpu_data_ = true;\n    break;\n  case HEAD_AT_CPU:\n    if (gpu_ptr_ == NULL) {\n      CUDA_CHECK(cudaGetDevice(&gpu_device_));\n      CUDA_CHECK(cudaMalloc(&gpu_ptr_, size_));\n      own_gpu_data_ = true;\n    }\n    caffe_gpu_memcpy(size_, cpu_ptr_, gpu_ptr_);\n    head_ = SYNCED;\n    break;\n  case HEAD_AT_GPU:\n  case SYNCED:\n    break;\n  }\n#else\n  NO_GPU;\n#endif\n}\n\nconst void* SyncedMemory::cpu_data() {\n  to_cpu();\n  return (const void*)cpu_ptr_;\n}\n\nvoid SyncedMemory::set_cpu_data(void* data) {\n  CHECK(data);\n  if (own_cpu_data_) {\n    CaffeFreeHost(cpu_ptr_);\n  }\n  cpu_ptr_ = data;\n  head_ = HEAD_AT_CPU;\n  own_cpu_data_ = false;\n}\n\nconst void* SyncedMemory::gpu_data() {\n#ifndef CPU_ONLY\n  to_gpu();\n  return (const void*)gpu_ptr_;\n#else\n  NO_GPU;\n#endif\n}\n\nvoid SyncedMemory::set_gpu_data(void* data) {\n#ifndef CPU_ONLY\n  CHECK(data);\n  if (own_gpu_data_) {\n    int initial_device;\n    cudaGetDevice(&initial_device);\n    if (gpu_device_ != -1) {\n      CUDA_CHECK(cudaSetDevice(gpu_device_));\n    }\n    CUDA_CHECK(cudaFree(gpu_ptr_));\n    cudaSetDevice(initial_device);\n  }\n  gpu_ptr_ = data;\n  head_ = HEAD_AT_GPU;\n  own_gpu_data_ = false;\n#else\n  NO_GPU;\n#endif\n}\n\nvoid* SyncedMemory::mutable_cpu_data() {\n  to_cpu();\n  head_ = HEAD_AT_CPU;\n  return cpu_ptr_;\n}\n\nvoid* SyncedMemory::mutable_gpu_data() {\n#ifndef CPU_ONLY\n  to_gpu();\n  head_ = HEAD_AT_GPU;\n  return gpu_ptr_;\n#else\n  NO_GPU;\n#endif\n}\n\n#ifndef CPU_ONLY\nvoid SyncedMemory::async_gpu_push(const cudaStream_t& stream) {\n  CHECK(head_ == HEAD_AT_CPU);\n  if (gpu_ptr_ == NULL) {\n    CUDA_CHECK(cudaGetDevice(&gpu_device_));\n    CUDA_CHECK(cudaMalloc(&gpu_ptr_, size_));\n    own_gpu_data_ = true;\n  }\n  const cudaMemcpyKind put = cudaMemcpyHostToDevice;\n  CUDA_CHECK(cudaMemcpyAsync(gpu_ptr_, cpu_ptr_, size_, put, stream));\n  // Assume caller will synchronize on the stream before use\n  head_ = SYNCED;\n}\n#endif\n\n}  // namespace caffe\n\n"
  },
  {
    "path": "src/caffe/test/CMakeLists.txt",
    "content": "# The option allows to include in build only selected test files and exclude all others\n# Usage example:\n#  cmake -DBUILD_only_tests=\"common,net,blob,im2col_kernel\"\nset(BUILD_only_tests \"\" CACHE STRING \"Blank or comma-separated list of test files to build without 'test_' prefix and extention\")\ncaffe_leave_only_selected_tests(test_srcs ${BUILD_only_tests})\ncaffe_leave_only_selected_tests(test_cuda ${BUILD_only_tests})\n\n# For 'make runtest' target we don't need to embed test data paths to\n# source files, because test target is executed in source directory\n# That's why the lines below are commented. TODO: remove them\n\n# definition needed to include CMake generated files\n#add_definitions(-DCMAKE_BUILD)\n\n# generates test_data/sample_data_list.txt.gen.cmake\n#caffe_configure_testdatafile(test_data/sample_data_list.txt)\n\nset(the_target test.testbin)\nset(test_args --gtest_shuffle)\n\nif(HAVE_CUDA)\n  caffe_cuda_compile(test_cuda_objs ${test_cuda})\n  list(APPEND test_srcs ${test_cuda_objs} ${test_cuda})\nelse()\n  list(APPEND test_args --gtest_filter=\"-*GPU*\")\nendif()\n\n# ---[ Adding test target\nadd_executable(${the_target} EXCLUDE_FROM_ALL ${test_srcs})\ntarget_link_libraries(${the_target} gtest ${Caffe_LINK})\ncaffe_default_properties(${the_target})\ncaffe_set_runtime_directory(${the_target} \"${PROJECT_BINARY_DIR}/test\")\n\n# ---[ Adding runtest\nadd_custom_target(runtest COMMAND ${the_target} ${test_args}\n                          WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})\n"
  },
  {
    "path": "src/caffe/test/test_accuracy_layer.cpp",
    "content": "#include <cfloat>\n#include <cmath>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/util/rng.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nclass AccuracyLayerTest : public CPUDeviceTest<Dtype> {\n protected:\n  AccuracyLayerTest()\n      : blob_bottom_data_(new Blob<Dtype>()),\n        blob_bottom_label_(new Blob<Dtype>()),\n        blob_top_(new Blob<Dtype>()),\n        top_k_(3) {\n    vector<int> shape(2);\n    shape[0] = 100;\n    shape[1] = 10;\n    blob_bottom_data_->Reshape(shape);\n    shape.resize(1);\n    blob_bottom_label_->Reshape(shape);\n    FillBottoms();\n\n    blob_bottom_vec_.push_back(blob_bottom_data_);\n    blob_bottom_vec_.push_back(blob_bottom_label_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n\n  virtual void FillBottoms() {\n    // fill the probability values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_data_);\n\n    const unsigned int prefetch_rng_seed = caffe_rng_rand();\n    shared_ptr<Caffe::RNG> rng(new Caffe::RNG(prefetch_rng_seed));\n    caffe::rng_t* prefetch_rng =\n          static_cast<caffe::rng_t*>(rng->generator());\n    Dtype* label_data = blob_bottom_label_->mutable_cpu_data();\n    for (int i = 0; i < blob_bottom_label_->count(); ++i) {\n      label_data[i] = (*prefetch_rng)() % 10;\n    }\n  }\n\n  virtual ~AccuracyLayerTest() {\n    delete blob_bottom_data_;\n    delete blob_bottom_label_;\n    delete blob_top_;\n  }\n  Blob<Dtype>* const blob_bottom_data_;\n  Blob<Dtype>* const blob_bottom_label_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n  int top_k_;\n};\n\nTYPED_TEST_CASE(AccuracyLayerTest, TestDtypes);\n\nTYPED_TEST(AccuracyLayerTest, TestSetup) {\n  LayerParameter layer_param;\n  AccuracyLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 1);\n  EXPECT_EQ(this->blob_top_->channels(), 1);\n  EXPECT_EQ(this->blob_top_->height(), 1);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n}\n\nTYPED_TEST(AccuracyLayerTest, TestSetupTopK) {\n  LayerParameter layer_param;\n  AccuracyParameter* accuracy_param =\n      layer_param.mutable_accuracy_param();\n  accuracy_param->set_top_k(5);\n  AccuracyLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 1);\n  EXPECT_EQ(this->blob_top_->channels(), 1);\n  EXPECT_EQ(this->blob_top_->height(), 1);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n}\n\nTYPED_TEST(AccuracyLayerTest, TestForwardCPU) {\n  LayerParameter layer_param;\n  AccuracyLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  TypeParam max_value;\n  int max_id;\n  int num_correct_labels = 0;\n  for (int i = 0; i < 100; ++i) {\n    max_value = -FLT_MAX;\n    max_id = 0;\n    for (int j = 0; j < 10; ++j) {\n      if (this->blob_bottom_data_->data_at(i, j, 0, 0) > max_value) {\n        max_value = this->blob_bottom_data_->data_at(i, j, 0, 0);\n        max_id = j;\n      }\n    }\n    if (max_id == this->blob_bottom_label_->data_at(i, 0, 0, 0)) {\n      ++num_correct_labels;\n    }\n  }\n  EXPECT_NEAR(this->blob_top_->data_at(0, 0, 0, 0),\n              num_correct_labels / 100.0, 1e-4);\n}\n\nTYPED_TEST(AccuracyLayerTest, TestForwardWithSpatialAxes) {\n  this->blob_bottom_data_->Reshape(2, 10, 4, 5);\n  vector<int> label_shape(3);\n  label_shape[0] = 2; label_shape[1] = 4; label_shape[2] = 5;\n  this->blob_bottom_label_->Reshape(label_shape);\n  this->FillBottoms();\n  LayerParameter layer_param;\n  layer_param.mutable_accuracy_param()->set_axis(1);\n  AccuracyLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  TypeParam max_value;\n  const int num_labels = this->blob_bottom_label_->count();\n  int max_id;\n  int num_correct_labels = 0;\n  vector<int> label_offset(3);\n  for (int n = 0; n < this->blob_bottom_data_->num(); ++n) {\n    for (int h = 0; h < this->blob_bottom_data_->height(); ++h) {\n      for (int w = 0; w < this->blob_bottom_data_->width(); ++w) {\n        max_value = -FLT_MAX;\n        max_id = 0;\n        for (int c = 0; c < this->blob_bottom_data_->channels(); ++c) {\n          const TypeParam pred_value =\n              this->blob_bottom_data_->data_at(n, c, h, w);\n          if (pred_value > max_value) {\n            max_value = pred_value;\n            max_id = c;\n          }\n        }\n        label_offset[0] = n; label_offset[1] = h; label_offset[2] = w;\n        const int correct_label =\n            static_cast<int>(this->blob_bottom_label_->data_at(label_offset));\n        if (max_id == correct_label) {\n          ++num_correct_labels;\n        }\n      }\n    }\n  }\n  EXPECT_NEAR(this->blob_top_->data_at(0, 0, 0, 0),\n              num_correct_labels / TypeParam(num_labels), 1e-4);\n}\n\nTYPED_TEST(AccuracyLayerTest, TestForwardIgnoreLabel) {\n  LayerParameter layer_param;\n  const TypeParam kIgnoreLabelValue = -1;\n  layer_param.mutable_accuracy_param()->set_ignore_label(kIgnoreLabelValue);\n  AccuracyLayer<TypeParam> layer(layer_param);\n  // Manually set some labels to the ignore label value (-1).\n  this->blob_bottom_label_->mutable_cpu_data()[2] = kIgnoreLabelValue;\n  this->blob_bottom_label_->mutable_cpu_data()[5] = kIgnoreLabelValue;\n  this->blob_bottom_label_->mutable_cpu_data()[32] = kIgnoreLabelValue;\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  TypeParam max_value;\n  int max_id;\n  int num_correct_labels = 0;\n  int count = 0;\n  for (int i = 0; i < 100; ++i) {\n    if (kIgnoreLabelValue == this->blob_bottom_label_->data_at(i, 0, 0, 0)) {\n      continue;\n    }\n    ++count;\n    max_value = -FLT_MAX;\n    max_id = 0;\n    for (int j = 0; j < 10; ++j) {\n      if (this->blob_bottom_data_->data_at(i, j, 0, 0) > max_value) {\n        max_value = this->blob_bottom_data_->data_at(i, j, 0, 0);\n        max_id = j;\n      }\n    }\n    if (max_id == this->blob_bottom_label_->data_at(i, 0, 0, 0)) {\n      ++num_correct_labels;\n    }\n  }\n  EXPECT_EQ(count, 97);  // We set 3 out of 100 labels to kIgnoreLabelValue.\n  EXPECT_NEAR(this->blob_top_->data_at(0, 0, 0, 0),\n              num_correct_labels / TypeParam(count), 1e-4);\n}\n\nTYPED_TEST(AccuracyLayerTest, TestForwardCPUTopK) {\n  LayerParameter layer_param;\n  AccuracyParameter* accuracy_param = layer_param.mutable_accuracy_param();\n  accuracy_param->set_top_k(this->top_k_);\n  AccuracyLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  TypeParam current_value;\n  int current_rank;\n  int num_correct_labels = 0;\n  for (int i = 0; i < 100; ++i) {\n    for (int j = 0; j < 10; ++j) {\n      current_value = this->blob_bottom_data_->data_at(i, j, 0, 0);\n      current_rank = 0;\n      for (int k = 0; k < 10; ++k) {\n        if (this->blob_bottom_data_->data_at(i, k, 0, 0) > current_value) {\n          ++current_rank;\n        }\n      }\n      if (current_rank < this->top_k_ &&\n          j == this->blob_bottom_label_->data_at(i, 0, 0, 0)) {\n        ++num_correct_labels;\n      }\n    }\n  }\n\n  EXPECT_NEAR(this->blob_top_->data_at(0, 0, 0, 0),\n              num_correct_labels / 100.0, 1e-4);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_argmax_layer.cpp",
    "content": "#include <utility>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nclass ArgMaxLayerTest : public CPUDeviceTest<Dtype> {\n protected:\n  ArgMaxLayerTest()\n      : blob_bottom_(new Blob<Dtype>(10, 20, 1, 1)),\n        blob_top_(new Blob<Dtype>()),\n        top_k_(5) {\n    Caffe::set_random_seed(1701);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~ArgMaxLayerTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n  size_t top_k_;\n};\n\nTYPED_TEST_CASE(ArgMaxLayerTest, TestDtypes);\n\nTYPED_TEST(ArgMaxLayerTest, TestSetup) {\n  LayerParameter layer_param;\n  ArgMaxLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), 1);\n}\n\nTYPED_TEST(ArgMaxLayerTest, TestSetupMaxVal) {\n  LayerParameter layer_param;\n  ArgMaxParameter* argmax_param = layer_param.mutable_argmax_param();\n  argmax_param->set_out_max_val(true);\n  ArgMaxLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), 2);\n}\n\nTYPED_TEST(ArgMaxLayerTest, TestCPU) {\n  LayerParameter layer_param;\n  ArgMaxLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const TypeParam* bottom_data = this->blob_bottom_->cpu_data();\n  const TypeParam* top_data = this->blob_top_->cpu_data();\n  int max_ind;\n  TypeParam max_val;\n  int num = this->blob_bottom_->num();\n  int dim = this->blob_bottom_->count() / num;\n  for (int i = 0; i < num; ++i) {\n    EXPECT_GE(top_data[i], 0);\n    EXPECT_LE(top_data[i], dim);\n    max_ind = top_data[i];\n    max_val = bottom_data[i * dim + max_ind];\n    for (int j = 0; j < dim; ++j) {\n      EXPECT_LE(bottom_data[i * dim + j], max_val);\n    }\n  }\n}\n\nTYPED_TEST(ArgMaxLayerTest, TestCPUMaxVal) {\n  LayerParameter layer_param;\n  ArgMaxParameter* argmax_param = layer_param.mutable_argmax_param();\n  argmax_param->set_out_max_val(true);\n  ArgMaxLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const TypeParam* bottom_data = this->blob_bottom_->cpu_data();\n  const TypeParam* top_data = this->blob_top_->cpu_data();\n  int max_ind;\n  TypeParam max_val;\n  int num = this->blob_bottom_->num();\n  int dim = this->blob_bottom_->count() / num;\n  for (int i = 0; i < num; ++i) {\n    EXPECT_GE(top_data[i], 0);\n    EXPECT_LE(top_data[i], dim);\n    max_ind = top_data[i * 2];\n    max_val = top_data[i * 2 + 1];\n    EXPECT_EQ(bottom_data[i * dim + max_ind], max_val);\n    for (int j = 0; j < dim; ++j) {\n      EXPECT_LE(bottom_data[i * dim + j], max_val);\n    }\n  }\n}\n\nTYPED_TEST(ArgMaxLayerTest, TestCPUTopK) {\n  LayerParameter layer_param;\n  ArgMaxParameter* argmax_param = layer_param.mutable_argmax_param();\n  argmax_param->set_top_k(this->top_k_);\n  ArgMaxLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  int max_ind;\n  TypeParam max_val;\n  int num = this->blob_bottom_->num();\n  int dim = this->blob_bottom_->count() / num;\n  for (int i = 0; i < num; ++i) {\n    EXPECT_GE(this->blob_top_->data_at(i, 0, 0, 0), 0);\n    EXPECT_LE(this->blob_top_->data_at(i, 0, 0, 0), dim);\n    for (int j = 0; j < this->top_k_; ++j) {\n      max_ind = this->blob_top_->data_at(i, 0, j, 0);\n      max_val = this->blob_bottom_->data_at(i, max_ind, 0, 0);\n      int count = 0;\n      for (int k = 0; k < dim; ++k) {\n        if (this->blob_bottom_->data_at(i, k, 0, 0) > max_val) {\n          ++count;\n        }\n      }\n      EXPECT_EQ(j, count);\n    }\n  }\n}\n\nTYPED_TEST(ArgMaxLayerTest, TestCPUMaxValTopK) {\n  LayerParameter layer_param;\n  ArgMaxParameter* argmax_param = layer_param.mutable_argmax_param();\n  argmax_param->set_out_max_val(true);\n  argmax_param->set_top_k(this->top_k_);\n  ArgMaxLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  int max_ind;\n  TypeParam max_val;\n  int num = this->blob_bottom_->num();\n  int dim = this->blob_bottom_->count() / num;\n  for (int i = 0; i < num; ++i) {\n    EXPECT_GE(this->blob_top_->data_at(i, 0, 0, 0), 0);\n    EXPECT_LE(this->blob_top_->data_at(i, 0, 0, 0), dim);\n    for (int j = 0; j < this->top_k_; ++j) {\n      max_ind = this->blob_top_->data_at(i, 0, j, 0);\n      max_val = this->blob_top_->data_at(i, 1, j, 0);\n      EXPECT_EQ(this->blob_bottom_->data_at(i, max_ind, 0, 0), max_val);\n      int count = 0;\n      for (int k = 0; k < dim; ++k) {\n        if (this->blob_bottom_->data_at(i, k, 0, 0) > max_val) {\n          ++count;\n        }\n      }\n      EXPECT_EQ(j, count);\n    }\n  }\n}\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_benchmark.cpp",
    "content": "#include <unistd.h>  // for usleep\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/benchmark.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nconst float kMillisecondsThreshold = 30;\n\ntemplate <typename TypeParam>\nclass BenchmarkTest : public MultiDeviceTest<TypeParam> {};\n\nTYPED_TEST_CASE(BenchmarkTest, TestDtypesAndDevices);\n\nTYPED_TEST(BenchmarkTest, TestTimerConstructor) {\n  Timer timer;\n  EXPECT_TRUE(timer.initted());\n  EXPECT_FALSE(timer.running());\n  EXPECT_FALSE(timer.has_run_at_least_once());\n}\n\nTYPED_TEST(BenchmarkTest, TestTimerStart) {\n  Timer timer;\n  timer.Start();\n  EXPECT_TRUE(timer.initted());\n  EXPECT_TRUE(timer.running());\n  EXPECT_TRUE(timer.has_run_at_least_once());\n  timer.Start();\n  EXPECT_TRUE(timer.initted());\n  EXPECT_TRUE(timer.running());\n  EXPECT_TRUE(timer.has_run_at_least_once());\n  timer.Stop();\n  timer.Start();\n  EXPECT_TRUE(timer.initted());\n  EXPECT_TRUE(timer.running());\n  EXPECT_TRUE(timer.has_run_at_least_once());\n}\n\nTYPED_TEST(BenchmarkTest, TestTimerStop) {\n  Timer timer;\n  timer.Stop();\n  EXPECT_TRUE(timer.initted());\n  EXPECT_FALSE(timer.running());\n  EXPECT_FALSE(timer.has_run_at_least_once());\n  timer.Start();\n  timer.Stop();\n  EXPECT_TRUE(timer.initted());\n  EXPECT_FALSE(timer.running());\n  EXPECT_TRUE(timer.has_run_at_least_once());\n  timer.Stop();\n  EXPECT_TRUE(timer.initted());\n  EXPECT_FALSE(timer.running());\n  EXPECT_TRUE(timer.has_run_at_least_once());\n}\n\nTYPED_TEST(BenchmarkTest, TestTimerMilliSeconds) {\n  Timer timer;\n  EXPECT_EQ(timer.MilliSeconds(), 0);\n  EXPECT_TRUE(timer.initted());\n  EXPECT_FALSE(timer.running());\n  EXPECT_FALSE(timer.has_run_at_least_once());\n  timer.Start();\n  usleep(300 * 1000);\n  EXPECT_GE(timer.MilliSeconds(), 300 - kMillisecondsThreshold);\n  EXPECT_LE(timer.MilliSeconds(), 300 + kMillisecondsThreshold);\n  EXPECT_TRUE(timer.initted());\n  EXPECT_FALSE(timer.running());\n  EXPECT_TRUE(timer.has_run_at_least_once());\n}\n\nTYPED_TEST(BenchmarkTest, TestTimerSeconds) {\n  Timer timer;\n  EXPECT_EQ(timer.Seconds(), 0);\n  EXPECT_TRUE(timer.initted());\n  EXPECT_FALSE(timer.running());\n  EXPECT_FALSE(timer.has_run_at_least_once());\n  timer.Start();\n  usleep(300 * 1000);\n  EXPECT_GE(timer.Seconds(), 0.3 - kMillisecondsThreshold / 1000.);\n  EXPECT_LE(timer.Seconds(), 0.3 + kMillisecondsThreshold / 1000.);\n  EXPECT_TRUE(timer.initted());\n  EXPECT_FALSE(timer.running());\n  EXPECT_TRUE(timer.has_run_at_least_once());\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_blob.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nclass BlobSimpleTest : public ::testing::Test {\n protected:\n  BlobSimpleTest()\n      : blob_(new Blob<Dtype>()),\n        blob_preshaped_(new Blob<Dtype>(2, 3, 4, 5)) {}\n  virtual ~BlobSimpleTest() { delete blob_; delete blob_preshaped_; }\n  Blob<Dtype>* const blob_;\n  Blob<Dtype>* const blob_preshaped_;\n};\n\nTYPED_TEST_CASE(BlobSimpleTest, TestDtypes);\n\nTYPED_TEST(BlobSimpleTest, TestInitialization) {\n  EXPECT_TRUE(this->blob_);\n  EXPECT_TRUE(this->blob_preshaped_);\n  EXPECT_EQ(this->blob_preshaped_->num(), 2);\n  EXPECT_EQ(this->blob_preshaped_->channels(), 3);\n  EXPECT_EQ(this->blob_preshaped_->height(), 4);\n  EXPECT_EQ(this->blob_preshaped_->width(), 5);\n  EXPECT_EQ(this->blob_preshaped_->count(), 120);\n  EXPECT_EQ(this->blob_->num_axes(), 0);\n  EXPECT_EQ(this->blob_->count(), 0);\n}\n\nTYPED_TEST(BlobSimpleTest, TestPointersCPUGPU) {\n  EXPECT_TRUE(this->blob_preshaped_->gpu_data());\n  EXPECT_TRUE(this->blob_preshaped_->cpu_data());\n  EXPECT_TRUE(this->blob_preshaped_->mutable_gpu_data());\n  EXPECT_TRUE(this->blob_preshaped_->mutable_cpu_data());\n}\n\nTYPED_TEST(BlobSimpleTest, TestReshape) {\n  this->blob_->Reshape(2, 3, 4, 5);\n  EXPECT_EQ(this->blob_->num(), 2);\n  EXPECT_EQ(this->blob_->channels(), 3);\n  EXPECT_EQ(this->blob_->height(), 4);\n  EXPECT_EQ(this->blob_->width(), 5);\n  EXPECT_EQ(this->blob_->count(), 120);\n}\n\nTYPED_TEST(BlobSimpleTest, TestLegacyBlobProtoShapeEquals) {\n  BlobProto blob_proto;\n\n  // Reshape to (3 x 2).\n  vector<int> shape(2);\n  shape[0] = 3;\n  shape[1] = 2;\n  this->blob_->Reshape(shape);\n\n  // (3 x 2) blob == (1 x 1 x 3 x 2) legacy blob\n  blob_proto.set_num(1);\n  blob_proto.set_channels(1);\n  blob_proto.set_height(3);\n  blob_proto.set_width(2);\n  EXPECT_TRUE(this->blob_->ShapeEquals(blob_proto));\n\n  // (3 x 2) blob != (0 x 1 x 3 x 2) legacy blob\n  blob_proto.set_num(0);\n  blob_proto.set_channels(1);\n  blob_proto.set_height(3);\n  blob_proto.set_width(2);\n  EXPECT_FALSE(this->blob_->ShapeEquals(blob_proto));\n\n  // (3 x 2) blob != (3 x 1 x 3 x 2) legacy blob\n  blob_proto.set_num(3);\n  blob_proto.set_channels(1);\n  blob_proto.set_height(3);\n  blob_proto.set_width(2);\n  EXPECT_FALSE(this->blob_->ShapeEquals(blob_proto));\n\n  // Reshape to (1 x 3 x 2).\n  shape.insert(shape.begin(), 1);\n  this->blob_->Reshape(shape);\n\n  // (1 x 3 x 2) blob == (1 x 1 x 3 x 2) legacy blob\n  blob_proto.set_num(1);\n  blob_proto.set_channels(1);\n  blob_proto.set_height(3);\n  blob_proto.set_width(2);\n  EXPECT_TRUE(this->blob_->ShapeEquals(blob_proto));\n\n  // Reshape to (2 x 3 x 2).\n  shape[0] = 2;\n  this->blob_->Reshape(shape);\n\n  // (2 x 3 x 2) blob != (1 x 1 x 3 x 2) legacy blob\n  blob_proto.set_num(1);\n  blob_proto.set_channels(1);\n  blob_proto.set_height(3);\n  blob_proto.set_width(2);\n  EXPECT_FALSE(this->blob_->ShapeEquals(blob_proto));\n}\n\ntemplate <typename TypeParam>\nclass BlobMathTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  BlobMathTest()\n      : blob_(new Blob<Dtype>(2, 3, 4, 5)),\n        epsilon_(1e-6) {}\n\n  virtual ~BlobMathTest() { delete blob_; }\n  Blob<Dtype>* const blob_;\n  Dtype epsilon_;\n};\n\nTYPED_TEST_CASE(BlobMathTest, TestDtypesAndDevices);\n\nTYPED_TEST(BlobMathTest, TestSumOfSquares) {\n  typedef typename TypeParam::Dtype Dtype;\n\n  // Uninitialized Blob should have sum of squares == 0.\n  EXPECT_EQ(0, this->blob_->sumsq_data());\n  EXPECT_EQ(0, this->blob_->sumsq_diff());\n  FillerParameter filler_param;\n  filler_param.set_min(-3);\n  filler_param.set_max(3);\n  UniformFiller<Dtype> filler(filler_param);\n  filler.Fill(this->blob_);\n  Dtype expected_sumsq = 0;\n  const Dtype* data = this->blob_->cpu_data();\n  for (int i = 0; i < this->blob_->count(); ++i) {\n    expected_sumsq += data[i] * data[i];\n  }\n  // Do a mutable access on the current device,\n  // so that the sumsq computation is done on that device.\n  // (Otherwise, this would only check the CPU sumsq implementation.)\n  switch (TypeParam::device) {\n  case Caffe::CPU:\n    this->blob_->mutable_cpu_data();\n    break;\n  case Caffe::GPU:\n    this->blob_->mutable_gpu_data();\n    break;\n  default:\n    LOG(FATAL) << \"Unknown device: \" << TypeParam::device;\n  }\n  EXPECT_NEAR(expected_sumsq, this->blob_->sumsq_data(),\n              this->epsilon_ * expected_sumsq);\n  EXPECT_EQ(0, this->blob_->sumsq_diff());\n\n  // Check sumsq_diff too.\n  const Dtype kDiffScaleFactor = 7;\n  caffe_cpu_scale(this->blob_->count(), kDiffScaleFactor, data,\n                  this->blob_->mutable_cpu_diff());\n  switch (TypeParam::device) {\n  case Caffe::CPU:\n    this->blob_->mutable_cpu_diff();\n    break;\n  case Caffe::GPU:\n    this->blob_->mutable_gpu_diff();\n    break;\n  default:\n    LOG(FATAL) << \"Unknown device: \" << TypeParam::device;\n  }\n  EXPECT_NEAR(expected_sumsq, this->blob_->sumsq_data(),\n              this->epsilon_ * expected_sumsq);\n  const Dtype expected_sumsq_diff =\n      expected_sumsq * kDiffScaleFactor * kDiffScaleFactor;\n  EXPECT_NEAR(expected_sumsq_diff, this->blob_->sumsq_diff(),\n              this->epsilon_ * expected_sumsq_diff);\n}\n\nTYPED_TEST(BlobMathTest, TestAsum) {\n  typedef typename TypeParam::Dtype Dtype;\n\n  // Uninitialized Blob should have asum == 0.\n  EXPECT_EQ(0, this->blob_->asum_data());\n  EXPECT_EQ(0, this->blob_->asum_diff());\n  FillerParameter filler_param;\n  filler_param.set_min(-3);\n  filler_param.set_max(3);\n  UniformFiller<Dtype> filler(filler_param);\n  filler.Fill(this->blob_);\n  Dtype expected_asum = 0;\n  const Dtype* data = this->blob_->cpu_data();\n  for (int i = 0; i < this->blob_->count(); ++i) {\n    expected_asum += std::fabs(data[i]);\n  }\n  // Do a mutable access on the current device,\n  // so that the asum computation is done on that device.\n  // (Otherwise, this would only check the CPU asum implementation.)\n  switch (TypeParam::device) {\n  case Caffe::CPU:\n    this->blob_->mutable_cpu_data();\n    break;\n  case Caffe::GPU:\n    this->blob_->mutable_gpu_data();\n    break;\n  default:\n    LOG(FATAL) << \"Unknown device: \" << TypeParam::device;\n  }\n  EXPECT_NEAR(expected_asum, this->blob_->asum_data(),\n              this->epsilon_ * expected_asum);\n  EXPECT_EQ(0, this->blob_->asum_diff());\n\n  // Check asum_diff too.\n  const Dtype kDiffScaleFactor = 7;\n  caffe_cpu_scale(this->blob_->count(), kDiffScaleFactor, data,\n                  this->blob_->mutable_cpu_diff());\n  switch (TypeParam::device) {\n  case Caffe::CPU:\n    this->blob_->mutable_cpu_diff();\n    break;\n  case Caffe::GPU:\n    this->blob_->mutable_gpu_diff();\n    break;\n  default:\n    LOG(FATAL) << \"Unknown device: \" << TypeParam::device;\n  }\n  EXPECT_NEAR(expected_asum, this->blob_->asum_data(),\n              this->epsilon_ * expected_asum);\n  const Dtype expected_diff_asum = expected_asum * kDiffScaleFactor;\n  EXPECT_NEAR(expected_diff_asum, this->blob_->asum_diff(),\n              this->epsilon_ * expected_diff_asum);\n}\n\nTYPED_TEST(BlobMathTest, TestScaleData) {\n  typedef typename TypeParam::Dtype Dtype;\n\n  EXPECT_EQ(0, this->blob_->asum_data());\n  EXPECT_EQ(0, this->blob_->asum_diff());\n  FillerParameter filler_param;\n  filler_param.set_min(-3);\n  filler_param.set_max(3);\n  UniformFiller<Dtype> filler(filler_param);\n  filler.Fill(this->blob_);\n  const Dtype asum_before_scale = this->blob_->asum_data();\n  // Do a mutable access on the current device,\n  // so that the asum computation is done on that device.\n  // (Otherwise, this would only check the CPU asum implementation.)\n  switch (TypeParam::device) {\n  case Caffe::CPU:\n    this->blob_->mutable_cpu_data();\n    break;\n  case Caffe::GPU:\n    this->blob_->mutable_gpu_data();\n    break;\n  default:\n    LOG(FATAL) << \"Unknown device: \" << TypeParam::device;\n  }\n  const Dtype kDataScaleFactor = 3;\n  this->blob_->scale_data(kDataScaleFactor);\n  EXPECT_NEAR(asum_before_scale * kDataScaleFactor, this->blob_->asum_data(),\n              this->epsilon_ * asum_before_scale * kDataScaleFactor);\n  EXPECT_EQ(0, this->blob_->asum_diff());\n\n  // Check scale_diff too.\n  const Dtype kDataToDiffScaleFactor = 7;\n  const Dtype* data = this->blob_->cpu_data();\n  caffe_cpu_scale(this->blob_->count(), kDataToDiffScaleFactor, data,\n                  this->blob_->mutable_cpu_diff());\n  const Dtype expected_asum_before_scale = asum_before_scale * kDataScaleFactor;\n  EXPECT_NEAR(expected_asum_before_scale, this->blob_->asum_data(),\n              this->epsilon_ * expected_asum_before_scale);\n  const Dtype expected_diff_asum_before_scale =\n      asum_before_scale * kDataScaleFactor * kDataToDiffScaleFactor;\n  EXPECT_NEAR(expected_diff_asum_before_scale, this->blob_->asum_diff(),\n              this->epsilon_ * expected_diff_asum_before_scale);\n  switch (TypeParam::device) {\n  case Caffe::CPU:\n    this->blob_->mutable_cpu_diff();\n    break;\n  case Caffe::GPU:\n    this->blob_->mutable_gpu_diff();\n    break;\n  default:\n    LOG(FATAL) << \"Unknown device: \" << TypeParam::device;\n  }\n  const Dtype kDiffScaleFactor = 3;\n  this->blob_->scale_diff(kDiffScaleFactor);\n  EXPECT_NEAR(asum_before_scale * kDataScaleFactor, this->blob_->asum_data(),\n              this->epsilon_ * asum_before_scale * kDataScaleFactor);\n  const Dtype expected_diff_asum =\n      expected_diff_asum_before_scale * kDiffScaleFactor;\n  EXPECT_NEAR(expected_diff_asum, this->blob_->asum_diff(),\n              this->epsilon_ * expected_diff_asum);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_caffe_main.cpp",
    "content": "// The main caffe test code. Your test cpp code should include this hpp\n// to allow a main function to be compiled into the binary.\n\n#include \"caffe/caffe.hpp\"\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n#ifndef CPU_ONLY\n  cudaDeviceProp CAFFE_TEST_CUDA_PROP;\n#endif\n}\n\n#ifndef CPU_ONLY\nusing caffe::CAFFE_TEST_CUDA_PROP;\n#endif\n\nint main(int argc, char** argv) {\n  ::testing::InitGoogleTest(&argc, argv);\n  caffe::GlobalInit(&argc, &argv);\n#ifndef CPU_ONLY\n  // Before starting testing, let's first print out a few cuda defice info.\n  int device;\n  cudaGetDeviceCount(&device);\n  cout << \"Cuda number of devices: \" << device << endl;\n  if (argc > 1) {\n    // Use the given device\n    device = atoi(argv[1]);\n    cudaSetDevice(device);\n    cout << \"Setting to use device \" << device << endl;\n  } else if (CUDA_TEST_DEVICE >= 0) {\n    // Use the device assigned in build configuration; but with a lower priority\n    device = CUDA_TEST_DEVICE;\n  }\n  cudaGetDevice(&device);\n  cout << \"Current device id: \" << device << endl;\n  cudaGetDeviceProperties(&CAFFE_TEST_CUDA_PROP, device);\n#endif\n  // invoke the test.\n  return RUN_ALL_TESTS();\n}\n"
  },
  {
    "path": "src/caffe/test/test_common.cpp",
    "content": "#include <cstring>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nclass CommonTest : public ::testing::Test {};\n\n#ifndef CPU_ONLY  // GPU Caffe singleton test.\n\nTEST_F(CommonTest, TestCublasHandlerGPU) {\n  int cuda_device_id;\n  CUDA_CHECK(cudaGetDevice(&cuda_device_id));\n  EXPECT_TRUE(Caffe::cublas_handle());\n}\n\n#endif\n\nTEST_F(CommonTest, TestBrewMode) {\n  Caffe::set_mode(Caffe::CPU);\n  EXPECT_EQ(Caffe::mode(), Caffe::CPU);\n  Caffe::set_mode(Caffe::GPU);\n  EXPECT_EQ(Caffe::mode(), Caffe::GPU);\n}\n\nTEST_F(CommonTest, TestRandSeedCPU) {\n  SyncedMemory data_a(10 * sizeof(int));\n  SyncedMemory data_b(10 * sizeof(int));\n  Caffe::set_random_seed(1701);\n  caffe_rng_bernoulli(10, 0.5, static_cast<int*>(data_a.mutable_cpu_data()));\n\n  Caffe::set_random_seed(1701);\n  caffe_rng_bernoulli(10, 0.5, static_cast<int*>(data_b.mutable_cpu_data()));\n\n  for (int i = 0; i < 10; ++i) {\n    EXPECT_EQ(static_cast<const int*>(data_a.cpu_data())[i],\n        static_cast<const int*>(data_b.cpu_data())[i]);\n  }\n}\n\n#ifndef CPU_ONLY  // GPU Caffe singleton test.\n\nTEST_F(CommonTest, TestRandSeedGPU) {\n  SyncedMemory data_a(10 * sizeof(unsigned int));\n  SyncedMemory data_b(10 * sizeof(unsigned int));\n  Caffe::set_random_seed(1701);\n  CURAND_CHECK(curandGenerate(Caffe::curand_generator(),\n        static_cast<unsigned int*>(data_a.mutable_gpu_data()), 10));\n  Caffe::set_random_seed(1701);\n  CURAND_CHECK(curandGenerate(Caffe::curand_generator(),\n        static_cast<unsigned int*>(data_b.mutable_gpu_data()), 10));\n  for (int i = 0; i < 10; ++i) {\n    EXPECT_EQ(((const unsigned int*)(data_a.cpu_data()))[i],\n        ((const unsigned int*)(data_b.cpu_data()))[i]);\n  }\n}\n\n#endif\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_concat_layer.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass ConcatLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  ConcatLayerTest()\n      : blob_bottom_0_(new Blob<Dtype>(2, 3, 6, 5)),\n        blob_bottom_1_(new Blob<Dtype>(2, 5, 6, 5)),\n        blob_bottom_2_(new Blob<Dtype>(5, 3, 6, 5)),\n        blob_top_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    // fill the values\n    shared_ptr<ConstantFiller<Dtype> > filler;\n    FillerParameter filler_param;\n    filler_param.set_value(1.);\n    filler.reset(new ConstantFiller<Dtype>(filler_param));\n    filler->Fill(this->blob_bottom_0_);\n    filler_param.set_value(2.);\n    filler.reset(new ConstantFiller<Dtype>(filler_param));\n    filler->Fill(this->blob_bottom_1_);\n    filler_param.set_value(3.);\n    filler.reset(new ConstantFiller<Dtype>(filler_param));\n    filler->Fill(this->blob_bottom_2_);\n    blob_bottom_vec_0_.push_back(blob_bottom_0_);\n    blob_bottom_vec_0_.push_back(blob_bottom_1_);\n    blob_bottom_vec_1_.push_back(blob_bottom_0_);\n    blob_bottom_vec_1_.push_back(blob_bottom_2_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n\n  virtual ~ConcatLayerTest() {\n    delete blob_bottom_0_; delete blob_bottom_1_;\n    delete blob_bottom_2_; delete blob_top_;\n  }\n\n  Blob<Dtype>* const blob_bottom_0_;\n  Blob<Dtype>* const blob_bottom_1_;\n  Blob<Dtype>* const blob_bottom_2_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_0_, blob_bottom_vec_1_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(ConcatLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(ConcatLayerTest, TestSetupNum) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_concat_param()->set_axis(0);\n  ConcatLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_1_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(),\n      this->blob_bottom_0_->num() + this->blob_bottom_2_->num());\n  EXPECT_EQ(this->blob_top_->channels(), this->blob_bottom_0_->channels());\n  EXPECT_EQ(this->blob_top_->height(), this->blob_bottom_0_->height());\n  EXPECT_EQ(this->blob_top_->width(), this->blob_bottom_0_->width());\n}\n\nTYPED_TEST(ConcatLayerTest, TestSetupChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConcatLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_0_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_0_->num());\n  EXPECT_EQ(this->blob_top_->channels(),\n      this->blob_bottom_0_->channels() + this->blob_bottom_1_->channels());\n  EXPECT_EQ(this->blob_top_->height(), this->blob_bottom_0_->height());\n  EXPECT_EQ(this->blob_top_->width(), this->blob_bottom_0_->width());\n}\n\nTYPED_TEST(ConcatLayerTest, TestSetupChannelsNegativeIndexing) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConcatLayer<Dtype> layer(layer_param);\n  // \"channels\" index is the third one from the end -- test negative indexing\n  // by setting axis to -3 and checking that we get the same results as above in\n  // TestSetupChannels.\n  layer_param.mutable_concat_param()->set_axis(-3);\n  layer.SetUp(this->blob_bottom_vec_0_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_0_->num());\n  EXPECT_EQ(this->blob_top_->channels(),\n      this->blob_bottom_0_->channels() + this->blob_bottom_1_->channels());\n  EXPECT_EQ(this->blob_top_->height(), this->blob_bottom_0_->height());\n  EXPECT_EQ(this->blob_top_->width(), this->blob_bottom_0_->width());\n}\n\nTYPED_TEST(ConcatLayerTest, TestForwardNum) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_concat_param()->set_axis(0);\n  ConcatLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_1_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_1_, this->blob_top_vec_);\n  for (int n = 0; n < this->blob_bottom_vec_1_[0]->num(); ++n) {\n    for (int c = 0; c < this->blob_top_->channels(); ++c) {\n      for (int h = 0; h < this->blob_top_->height(); ++h) {\n        for (int w = 0; w < this->blob_top_->width(); ++w) {\n          EXPECT_EQ(this->blob_top_->data_at(n, c, h, w),\n              this->blob_bottom_vec_1_[0]->data_at(n, c, h, w));\n        }\n      }\n    }\n  }\n  for (int n = 0; n < this->blob_bottom_vec_1_[1]->num(); ++n) {\n    for (int c = 0; c < this->blob_top_->channels(); ++c) {\n      for (int h = 0; h < this->blob_top_->height(); ++h) {\n        for (int w = 0; w < this->blob_top_->width(); ++w) {\n          EXPECT_EQ(this->blob_top_->data_at(n + 2, c, h, w),\n              this->blob_bottom_vec_1_[1]->data_at(n, c, h, w));\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(ConcatLayerTest, TestForwardChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConcatLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_0_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_0_, this->blob_top_vec_);\n  for (int n = 0; n < this->blob_top_->num(); ++n) {\n    for (int c = 0; c < this->blob_bottom_0_->channels(); ++c) {\n      for (int h = 0; h < this->blob_top_->height(); ++h) {\n        for (int w = 0; w < this->blob_top_->width(); ++w) {\n          EXPECT_EQ(this->blob_top_->data_at(n, c, h, w),\n              this->blob_bottom_vec_0_[0]->data_at(n, c, h, w));\n        }\n      }\n    }\n    for (int c = 0; c < this->blob_bottom_1_->channels(); ++c) {\n      for (int h = 0; h < this->blob_top_->height(); ++h) {\n        for (int w = 0; w < this->blob_top_->width(); ++w) {\n          EXPECT_EQ(this->blob_top_->data_at(n, c + 3, h, w),\n              this->blob_bottom_vec_0_[1]->data_at(n, c, h, w));\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(ConcatLayerTest, TestGradientNum) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_concat_param()->set_axis(0);\n  ConcatLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  checker.CheckGradient(&layer, this->blob_bottom_vec_1_,\n    this->blob_top_vec_);\n}\n\nTYPED_TEST(ConcatLayerTest, TestGradientChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConcatLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  checker.CheckGradient(&layer, this->blob_bottom_vec_0_,\n    this->blob_top_vec_);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_contrastive_loss_layer.cpp",
    "content": "#include <algorithm>\n#include <cmath>\n#include <cstdlib>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass ContrastiveLossLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  ContrastiveLossLayerTest()\n      : blob_bottom_data_i_(new Blob<Dtype>(512, 2, 1, 1)),\n        blob_bottom_data_j_(new Blob<Dtype>(512, 2, 1, 1)),\n        blob_bottom_y_(new Blob<Dtype>(512, 1, 1, 1)),\n        blob_top_loss_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    filler_param.set_min(-1.0);\n    filler_param.set_max(1.0);  // distances~=1.0 to test both sides of margin\n    UniformFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_data_i_);\n    blob_bottom_vec_.push_back(blob_bottom_data_i_);\n    filler.Fill(this->blob_bottom_data_j_);\n    blob_bottom_vec_.push_back(blob_bottom_data_j_);\n    for (int i = 0; i < blob_bottom_y_->count(); ++i) {\n      blob_bottom_y_->mutable_cpu_data()[i] = caffe_rng_rand() % 2;  // 0 or 1\n    }\n    blob_bottom_vec_.push_back(blob_bottom_y_);\n    blob_top_vec_.push_back(blob_top_loss_);\n  }\n  virtual ~ContrastiveLossLayerTest() {\n    delete blob_bottom_data_i_;\n    delete blob_bottom_data_j_;\n    delete blob_bottom_y_;\n    delete blob_top_loss_;\n  }\n\n  Blob<Dtype>* const blob_bottom_data_i_;\n  Blob<Dtype>* const blob_bottom_data_j_;\n  Blob<Dtype>* const blob_bottom_y_;\n  Blob<Dtype>* const blob_top_loss_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(ContrastiveLossLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(ContrastiveLossLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ContrastiveLossLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // manually compute to compare\n  const Dtype margin = layer_param.contrastive_loss_param().margin();\n  const int num = this->blob_bottom_data_i_->num();\n  const int channels = this->blob_bottom_data_i_->channels();\n  Dtype loss(0);\n  for (int i = 0; i < num; ++i) {\n    Dtype dist_sq(0);\n    for (int j = 0; j < channels; ++j) {\n      Dtype diff = this->blob_bottom_data_i_->cpu_data()[i*channels+j] -\n          this->blob_bottom_data_j_->cpu_data()[i*channels+j];\n      dist_sq += diff*diff;\n    }\n    if (this->blob_bottom_y_->cpu_data()[i]) {  // similar pairs\n      loss += dist_sq;\n    } else {\n      Dtype dist = std::max(margin - sqrt(dist_sq), 0.0);\n      loss += dist*dist;\n    }\n  }\n  loss /= static_cast<Dtype>(num) * Dtype(2);\n  EXPECT_NEAR(this->blob_top_loss_->cpu_data()[0], loss, 1e-6);\n}\n\nTYPED_TEST(ContrastiveLossLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ContrastiveLossLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);\n  // check the gradient for the first two bottom layers\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 1);\n}\n\nTYPED_TEST(ContrastiveLossLayerTest, TestForwardLegacy) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_contrastive_loss_param()->set_legacy_version(true);\n  ContrastiveLossLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // manually compute to compare\n  const Dtype margin = layer_param.contrastive_loss_param().margin();\n  const int num = this->blob_bottom_data_i_->num();\n  const int channels = this->blob_bottom_data_i_->channels();\n  Dtype loss(0);\n  for (int i = 0; i < num; ++i) {\n    Dtype dist_sq(0);\n    for (int j = 0; j < channels; ++j) {\n      Dtype diff = this->blob_bottom_data_i_->cpu_data()[i*channels+j] -\n          this->blob_bottom_data_j_->cpu_data()[i*channels+j];\n      dist_sq += diff*diff;\n    }\n    if (this->blob_bottom_y_->cpu_data()[i]) {  // similar pairs\n      loss += dist_sq;\n    } else {\n      loss += std::max(margin - dist_sq, Dtype(0.0));\n    }\n  }\n  loss /= static_cast<Dtype>(num) * Dtype(2);\n  EXPECT_NEAR(this->blob_top_loss_->cpu_data()[0], loss, 1e-6);\n}\n\nTYPED_TEST(ContrastiveLossLayerTest, TestGradientLegacy) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_contrastive_loss_param()->set_legacy_version(true);\n  ContrastiveLossLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);\n  // check the gradient for the first two bottom layers\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 1);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_convolution_layer.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\n// Reference convolution for checking results:\n// accumulate through explicit loops over input, output, and filters.\ntemplate <typename Dtype>\nvoid caffe_conv(const Blob<Dtype>* in, ConvolutionParameter* conv_param,\n    const vector<shared_ptr<Blob<Dtype> > >& weights,\n    Blob<Dtype>* out) {\n  // Kernel size, stride, and pad\n  int kernel_h, kernel_w;\n  if (conv_param->has_kernel_size()) {\n    kernel_h = kernel_w = conv_param->kernel_size();\n  } else {\n    kernel_h = conv_param->kernel_h();\n    kernel_w = conv_param->kernel_w();\n  }\n  int pad_h, pad_w;\n  if (!conv_param->has_pad_h()) {\n    pad_h = pad_w = conv_param->pad();\n  } else {\n    pad_h = conv_param->pad_h();\n    pad_w = conv_param->pad_w();\n  }\n  int stride_h, stride_w;\n  if (!conv_param->has_stride_h()) {\n    stride_h = stride_w = conv_param->stride();\n  } else {\n    stride_h = conv_param->stride_h();\n    stride_w = conv_param->stride_w();\n  }\n  // Groups\n  int groups = conv_param->group();\n  int o_g = out->channels() / groups;\n  int k_g = in->channels() / groups;\n  int o_head, k_head;\n  // Convolution\n  const Dtype* in_data = in->cpu_data();\n  const Dtype* weight_data = weights[0]->cpu_data();\n  Dtype* out_data = out->mutable_cpu_data();\n  for (int n = 0; n < out->num(); n++) {\n    for (int g = 0; g < groups; g++) {\n      o_head = o_g * g;\n      k_head = k_g * g;\n      for (int o = 0; o < o_g; o++) {\n        for (int k = 0; k < k_g; k++) {\n          for (int y = 0; y < out->height(); y++) {\n            for (int x = 0; x < out->width(); x++) {\n              for (int p = 0; p < kernel_h; p++) {\n                for (int q = 0; q < kernel_w; q++) {\n                  int in_y = y * stride_h - pad_h + p;\n                  int in_x = x * stride_w - pad_w + q;\n                  if (in_y >= 0 && in_y < in->height()\n                    && in_x >= 0 && in_x < in->width()) {\n                    out_data[out->offset(n, o + o_head, y, x)] +=\n                        in_data[in->offset(n, k + k_head, in_y, in_x)]\n                        * weight_data[weights[0]->offset(o + o_head, k, p, q)];\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n  // Bias\n  if (conv_param->bias_term()) {\n    const Dtype* bias_data = weights[1]->cpu_data();\n    for (int n = 0; n < out->num(); n++) {\n      for (int o = 0; o < out->channels(); o++) {\n        for (int y = 0; y < out->height(); y++) {\n          for (int x = 0; x < out->width(); x++) {\n            out_data[out->offset(n, o, y, x)] += bias_data[o];\n          }\n        }\n      }\n    }\n  }\n}\n\ntemplate void caffe_conv(const Blob<float>* in,\n    ConvolutionParameter* conv_param,\n    const vector<shared_ptr<Blob<float> > >& weights,\n    Blob<float>* out);\ntemplate void caffe_conv(const Blob<double>* in,\n    ConvolutionParameter* conv_param,\n    const vector<shared_ptr<Blob<double> > >& weights,\n    Blob<double>* out);\n\ntemplate <typename TypeParam>\nclass ConvolutionLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  ConvolutionLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 6, 4)),\n        blob_bottom_2_(new Blob<Dtype>(2, 3, 6, 4)),\n        blob_top_(new Blob<Dtype>()),\n        blob_top_2_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    // fill the values\n    FillerParameter filler_param;\n    filler_param.set_value(1.);\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    filler.Fill(this->blob_bottom_2_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n\n  virtual ~ConvolutionLayerTest() {\n    delete blob_bottom_;\n    delete blob_bottom_2_;\n    delete blob_top_;\n    delete blob_top_2_;\n  }\n\n  virtual Blob<Dtype>* MakeReferenceTop(Blob<Dtype>* top) {\n    this->ref_blob_top_.reset(new Blob<Dtype>());\n    this->ref_blob_top_->ReshapeLike(*top);\n    return this->ref_blob_top_.get();\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_bottom_2_;\n  Blob<Dtype>* const blob_top_;\n  Blob<Dtype>* const blob_top_2_;\n  shared_ptr<Blob<Dtype> > ref_blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(ConvolutionLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(ConvolutionLayerTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(4);\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  shared_ptr<Layer<Dtype> > layer(\n      new ConvolutionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 4);\n  EXPECT_EQ(this->blob_top_->height(), 2);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n  EXPECT_EQ(this->blob_top_2_->num(), 2);\n  EXPECT_EQ(this->blob_top_2_->channels(), 4);\n  EXPECT_EQ(this->blob_top_2_->height(), 2);\n  EXPECT_EQ(this->blob_top_2_->width(), 1);\n  // setting group should not change the shape\n  convolution_param->set_num_output(3);\n  convolution_param->set_group(3);\n  layer.reset(new ConvolutionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 3);\n  EXPECT_EQ(this->blob_top_->height(), 2);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n  EXPECT_EQ(this->blob_top_2_->num(), 2);\n  EXPECT_EQ(this->blob_top_2_->channels(), 3);\n  EXPECT_EQ(this->blob_top_2_->height(), 2);\n  EXPECT_EQ(this->blob_top_2_->width(), 1);\n}\n\nTYPED_TEST(ConvolutionLayerTest, TestSimpleConvolution) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(4);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"constant\");\n  convolution_param->mutable_bias_filler()->set_value(0.1);\n  shared_ptr<Layer<Dtype> > layer(\n      new ConvolutionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Check against reference convolution.\n  const Dtype* top_data;\n  const Dtype* ref_top_data;\n  caffe_conv(this->blob_bottom_, convolution_param, layer->blobs(),\n      this->MakeReferenceTop(this->blob_top_));\n  top_data = this->blob_top_->cpu_data();\n  ref_top_data = this->ref_blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    EXPECT_NEAR(top_data[i], ref_top_data[i], 1e-4);\n  }\n  caffe_conv(this->blob_bottom_2_, convolution_param, layer->blobs(),\n      this->MakeReferenceTop(this->blob_top_2_));\n  top_data = this->blob_top_2_->cpu_data();\n  ref_top_data = this->ref_blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    EXPECT_NEAR(top_data[i], ref_top_data[i], 1e-4);\n  }\n}\n\nTYPED_TEST(ConvolutionLayerTest, Test1x1Convolution) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(1);\n  convolution_param->set_stride(1);\n  convolution_param->set_num_output(4);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"constant\");\n  convolution_param->mutable_bias_filler()->set_value(0.1);\n  shared_ptr<Layer<Dtype> > layer(\n      new ConvolutionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Check against reference convolution.\n  const Dtype* top_data;\n  const Dtype* ref_top_data;\n  caffe_conv(this->blob_bottom_, convolution_param, layer->blobs(),\n      this->MakeReferenceTop(this->blob_top_));\n  top_data = this->blob_top_->cpu_data();\n  ref_top_data = this->ref_blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    EXPECT_NEAR(top_data[i], ref_top_data[i], 1e-4);\n  }\n}\n\nTYPED_TEST(ConvolutionLayerTest, TestSimpleConvolutionGroup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(3);\n  convolution_param->set_group(3);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"constant\");\n  convolution_param->mutable_bias_filler()->set_value(0.1);\n  shared_ptr<Layer<Dtype> > layer(\n      new ConvolutionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Check against reference convolution.\n  const Dtype* top_data;\n  const Dtype* ref_top_data;\n  caffe_conv(this->blob_bottom_, convolution_param, layer->blobs(),\n      this->MakeReferenceTop(this->blob_top_));\n  top_data = this->blob_top_->cpu_data();\n  ref_top_data = this->ref_blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    EXPECT_NEAR(top_data[i], ref_top_data[i], 1e-4);\n  }\n}\n\nTYPED_TEST(ConvolutionLayerTest, TestSobelConvolution) {\n  // Test separable convolution by computing the Sobel operator\n  // as a single filter then comparing the result\n  // as the convolution of two rectangular filters.\n  typedef typename TypeParam::Dtype Dtype;\n  // Fill bottoms with identical Gaussian noise.\n  shared_ptr<GaussianFiller<Dtype> > filler;\n  FillerParameter filler_param;\n  filler_param.set_value(1.);\n  filler.reset(new GaussianFiller<Dtype>(filler_param));\n  filler->Fill(this->blob_bottom_);\n  this->blob_bottom_2_->CopyFrom(*this->blob_bottom_);\n  // Compute Sobel G_x operator as 3 x 3 convolution.\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(1);\n  convolution_param->set_bias_term(false);\n  shared_ptr<Layer<Dtype> > layer(\n      new ConvolutionLayer<Dtype>(layer_param));\n  layer->blobs().resize(1);\n  layer->blobs()[0].reset(new Blob<Dtype>(1, 3, 3, 3));\n  Dtype* weights = layer->blobs()[0]->mutable_cpu_data();\n  for (int c = 0; c < 3; ++c) {\n    int i = c * 9;  // 3 x 3 filter\n    weights[i +  0] = -1;\n    weights[i +  1] =  0;\n    weights[i +  2] =  1;\n    weights[i +  3] = -2;\n    weights[i +  4] =  0;\n    weights[i +  5] =  2;\n    weights[i +  6] = -1;\n    weights[i +  7] =  0;\n    weights[i +  8] =  1;\n  }\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Compute Sobel G_x operator as separable 3 x 1 and 1 x 3 convolutions.\n  // (1) the [1 2 1] column filter\n  vector<Blob<Dtype>*> sep_blob_bottom_vec;\n  vector<Blob<Dtype>*> sep_blob_top_vec;\n  shared_ptr<Blob<Dtype> > blob_sep(new Blob<Dtype>());\n  sep_blob_bottom_vec.push_back(this->blob_bottom_2_);\n  sep_blob_top_vec.push_back(this->blob_top_2_);\n  convolution_param->clear_kernel_size();\n  convolution_param->clear_stride();\n  convolution_param->set_kernel_h(3);\n  convolution_param->set_kernel_w(1);\n  convolution_param->set_stride_h(2);\n  convolution_param->set_stride_w(1);\n  convolution_param->set_num_output(1);\n  convolution_param->set_bias_term(false);\n  layer.reset(new ConvolutionLayer<Dtype>(layer_param));\n  layer->blobs().resize(1);\n  layer->blobs()[0].reset(new Blob<Dtype>(1, 3, 3, 1));\n  Dtype* weights_1 = layer->blobs()[0]->mutable_cpu_data();\n  for (int c = 0; c < 3; ++c) {\n    int i = c * 3;  // 3 x 1 filter\n    weights_1[i +  0] = 1;\n    weights_1[i +  1] = 2;\n    weights_1[i +  2] = 1;\n  }\n  layer->SetUp(sep_blob_bottom_vec, sep_blob_top_vec);\n  layer->Forward(sep_blob_bottom_vec, sep_blob_top_vec);\n  // (2) the [-1 0 1] row filter\n  blob_sep->CopyFrom(*this->blob_top_2_, false, true);\n  sep_blob_bottom_vec.clear();\n  sep_blob_bottom_vec.push_back(blob_sep.get());\n  convolution_param->set_kernel_h(1);\n  convolution_param->set_kernel_w(3);\n  convolution_param->set_stride_h(1);\n  convolution_param->set_stride_w(2);\n  convolution_param->set_num_output(1);\n  convolution_param->set_bias_term(false);\n  layer.reset(new ConvolutionLayer<Dtype>(layer_param));\n  layer->blobs().resize(1);\n  layer->blobs()[0].reset(new Blob<Dtype>(1, 3, 1, 3));\n  Dtype* weights_2 = layer->blobs()[0]->mutable_cpu_data();\n  for (int c = 0; c < 3; ++c) {\n    int i = c * 3;  // 1 x 3 filter\n    weights_2[i +  0] = -1;\n    weights_2[i +  1] =  0;\n    weights_2[i +  2] =  1;\n  }\n  layer->SetUp(sep_blob_bottom_vec, sep_blob_top_vec);\n  layer->Forward(sep_blob_bottom_vec, sep_blob_top_vec);\n  // Test equivalence of full and separable filters.\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  const Dtype* sep_top_data = this->blob_top_2_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    EXPECT_NEAR(top_data[i], sep_top_data[i], 1e-4);\n  }\n}\n\nTYPED_TEST(ConvolutionLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(2);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"gaussian\");\n  ConvolutionLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(ConvolutionLayerTest, Test1x1Gradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  convolution_param->set_kernel_size(1);\n  convolution_param->set_stride(1);\n  convolution_param->set_num_output(2);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"gaussian\");\n  ConvolutionLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(ConvolutionLayerTest, TestGradientGroup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(3);\n  convolution_param->set_group(3);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"gaussian\");\n  ConvolutionLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n#ifdef USE_CUDNN\n\ntemplate <typename Dtype>\nclass CuDNNConvolutionLayerTest : public GPUDeviceTest<Dtype> {\n protected:\n  CuDNNConvolutionLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 6, 4)),\n        blob_bottom_2_(new Blob<Dtype>(2, 3, 6, 4)),\n        blob_top_(new Blob<Dtype>()),\n        blob_top_2_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    // fill the values\n    FillerParameter filler_param;\n    filler_param.set_value(1.);\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    filler.Fill(this->blob_bottom_2_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n\n  virtual ~CuDNNConvolutionLayerTest() {\n    delete blob_bottom_;\n    delete blob_bottom_2_;\n    delete blob_top_;\n    delete blob_top_2_;\n  }\n\n  virtual Blob<Dtype>* MakeReferenceTop(Blob<Dtype>* top) {\n    this->ref_blob_top_.reset(new Blob<Dtype>());\n    this->ref_blob_top_->ReshapeLike(*top);\n    return this->ref_blob_top_.get();\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_bottom_2_;\n  Blob<Dtype>* const blob_top_;\n  Blob<Dtype>* const blob_top_2_;\n  shared_ptr<Blob<Dtype> > ref_blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(CuDNNConvolutionLayerTest, TestDtypes);\n\nTYPED_TEST(CuDNNConvolutionLayerTest, TestSetupCuDNN) {\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(4);\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  shared_ptr<Layer<TypeParam> > layer(\n      new CuDNNConvolutionLayer<TypeParam>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 4);\n  EXPECT_EQ(this->blob_top_->height(), 2);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n  EXPECT_EQ(this->blob_top_2_->num(), 2);\n  EXPECT_EQ(this->blob_top_2_->channels(), 4);\n  EXPECT_EQ(this->blob_top_2_->height(), 2);\n  EXPECT_EQ(this->blob_top_2_->width(), 1);\n  // setting group should not change the shape\n  convolution_param->set_num_output(3);\n  convolution_param->set_group(3);\n  layer.reset(new CuDNNConvolutionLayer<TypeParam>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 3);\n  EXPECT_EQ(this->blob_top_->height(), 2);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n  EXPECT_EQ(this->blob_top_2_->num(), 2);\n  EXPECT_EQ(this->blob_top_2_->channels(), 3);\n  EXPECT_EQ(this->blob_top_2_->height(), 2);\n  EXPECT_EQ(this->blob_top_2_->width(), 1);\n}\n\nTYPED_TEST(CuDNNConvolutionLayerTest, TestSimpleConvolutionCuDNN) {\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(4);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"constant\");\n  convolution_param->mutable_bias_filler()->set_value(0.1);\n  shared_ptr<Layer<TypeParam> > layer(\n      new CuDNNConvolutionLayer<TypeParam>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Check against reference convolution.\n  const TypeParam* top_data;\n  const TypeParam* ref_top_data;\n  caffe_conv(this->blob_bottom_, convolution_param, layer->blobs(),\n      this->MakeReferenceTop(this->blob_top_));\n  top_data = this->blob_top_->cpu_data();\n  ref_top_data = this->ref_blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    EXPECT_NEAR(top_data[i], ref_top_data[i], 1e-4);\n  }\n  caffe_conv(this->blob_bottom_2_, convolution_param, layer->blobs(),\n      this->MakeReferenceTop(this->blob_top_2_));\n  top_data = this->blob_top_2_->cpu_data();\n  ref_top_data = this->ref_blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    EXPECT_NEAR(top_data[i], ref_top_data[i], 1e-4);\n  }\n}\n\nTYPED_TEST(CuDNNConvolutionLayerTest, TestSimpleConvolutionGroupCuDNN) {\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(3);\n  convolution_param->set_group(3);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"constant\");\n  convolution_param->mutable_bias_filler()->set_value(0.1);\n  shared_ptr<Layer<TypeParam> > layer(\n      new CuDNNConvolutionLayer<TypeParam>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Check against reference convolution.\n  const TypeParam* top_data;\n  const TypeParam* ref_top_data;\n  caffe_conv(this->blob_bottom_, convolution_param, layer->blobs(),\n      this->MakeReferenceTop(this->blob_top_));\n  top_data = this->blob_top_->cpu_data();\n  ref_top_data = this->ref_blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    EXPECT_NEAR(top_data[i], ref_top_data[i], 1e-4);\n  }\n}\n\nTYPED_TEST(CuDNNConvolutionLayerTest, TestSobelConvolutionCuDNN) {\n  // Test separable convolution by computing the Sobel operator\n  // as a single filter then comparing the result\n  // as the convolution of two rectangular filters.\n\n  // Fill bottoms with identical Gaussian noise.\n  shared_ptr<GaussianFiller<TypeParam> > filler;\n  FillerParameter filler_param;\n  filler_param.set_value(1.);\n  filler.reset(new GaussianFiller<TypeParam>(filler_param));\n  filler->Fill(this->blob_bottom_);\n  this->blob_bottom_2_->CopyFrom(*this->blob_bottom_);\n  // Compute Sobel G_x operator as 3 x 3 convolution.\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(1);\n  convolution_param->set_bias_term(false);\n  shared_ptr<Layer<TypeParam> > layer(\n      new CuDNNConvolutionLayer<TypeParam>(layer_param));\n  layer->blobs().resize(1);\n  layer->blobs()[0].reset(new Blob<TypeParam>(1, 3, 3, 3));\n  TypeParam* weights = layer->blobs()[0]->mutable_cpu_data();\n  for (int c = 0; c < 3; ++c) {\n    int i = c * 9;  // 3 x 3 filter\n    weights[i +  0] = -1;\n    weights[i +  1] =  0;\n    weights[i +  2] =  1;\n    weights[i +  3] = -2;\n    weights[i +  4] =  0;\n    weights[i +  5] =  2;\n    weights[i +  6] = -1;\n    weights[i +  7] =  0;\n    weights[i +  8] =  1;\n  }\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Compute Sobel G_x operator as separable 3 x 1 and 1 x 3 convolutions.\n  // (1) the [1 2 1] column filter\n  vector<Blob<TypeParam>*> sep_blob_bottom_vec;\n  vector<Blob<TypeParam>*> sep_blob_top_vec;\n  shared_ptr<Blob<TypeParam> > blob_sep(new Blob<TypeParam>());\n  sep_blob_bottom_vec.push_back(this->blob_bottom_2_);\n  sep_blob_top_vec.push_back(this->blob_top_2_);\n  convolution_param->clear_kernel_size();\n  convolution_param->clear_stride();\n  convolution_param->set_kernel_h(3);\n  convolution_param->set_kernel_w(1);\n  convolution_param->set_stride_h(2);\n  convolution_param->set_stride_w(1);\n  convolution_param->set_num_output(1);\n  convolution_param->set_bias_term(false);\n  layer.reset(new CuDNNConvolutionLayer<TypeParam>(layer_param));\n  layer->blobs().resize(1);\n  layer->blobs()[0].reset(new Blob<TypeParam>(1, 3, 3, 1));\n  TypeParam* weights_1 = layer->blobs()[0]->mutable_cpu_data();\n  for (int c = 0; c < 3; ++c) {\n    int i = c * 3;  // 3 x 1 filter\n    weights_1[i +  0] = 1;\n    weights_1[i +  1] = 2;\n    weights_1[i +  2] = 1;\n  }\n  layer->SetUp(sep_blob_bottom_vec, sep_blob_top_vec);\n  layer->Forward(sep_blob_bottom_vec, sep_blob_top_vec);\n  // (2) the [-1 0 1] row filter\n  blob_sep->CopyFrom(*this->blob_top_2_, false, true);\n  sep_blob_bottom_vec.clear();\n  sep_blob_bottom_vec.push_back(blob_sep.get());\n  convolution_param->set_kernel_h(1);\n  convolution_param->set_kernel_w(3);\n  convolution_param->set_stride_h(1);\n  convolution_param->set_stride_w(2);\n  convolution_param->set_num_output(1);\n  convolution_param->set_bias_term(false);\n  layer.reset(new CuDNNConvolutionLayer<TypeParam>(layer_param));\n  layer->blobs().resize(1);\n  layer->blobs()[0].reset(new Blob<TypeParam>(1, 3, 1, 3));\n  TypeParam* weights_2 = layer->blobs()[0]->mutable_cpu_data();\n  for (int c = 0; c < 3; ++c) {\n    int i = c * 3;  // 1 x 3 filter\n    weights_2[i +  0] = -1;\n    weights_2[i +  1] =  0;\n    weights_2[i +  2] =  1;\n  }\n  layer->SetUp(sep_blob_bottom_vec, sep_blob_top_vec);\n  layer->Forward(sep_blob_bottom_vec, sep_blob_top_vec);\n  // Test equivalence of full and separable filters.\n  const TypeParam* top_data = this->blob_top_->cpu_data();\n  const TypeParam* sep_top_data = this->blob_top_2_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    EXPECT_NEAR(top_data[i], sep_top_data[i], 1e-4);\n  }\n}\n\nTYPED_TEST(CuDNNConvolutionLayerTest, TestGradientCuDNN) {\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(2);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"gaussian\");\n  CuDNNConvolutionLayer<TypeParam> layer(layer_param);\n  GradientChecker<TypeParam> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(CuDNNConvolutionLayerTest, TestGradientGroupCuDNN) {\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(3);\n  convolution_param->set_group(3);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"gaussian\");\n  CuDNNConvolutionLayer<TypeParam> layer(layer_param);\n  GradientChecker<TypeParam> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n#endif\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_data/generate_sample_data.py",
    "content": "\"\"\"\nGenerate data used in the HDF5DataLayer and GradientBasedSolver tests.\n\"\"\"\nimport os\nimport numpy as np\nimport h5py\n\nscript_dir = os.path.dirname(os.path.abspath(__file__))\n\n# Generate HDF5DataLayer sample_data.h5\n\nnum_cols = 8\nnum_rows = 10\nheight = 6\nwidth = 5\ntotal_size = num_cols * num_rows * height * width\n\ndata = np.arange(total_size)\ndata = data.reshape(num_rows, num_cols, height, width)\ndata = data.astype('float32')\n\n# We had a bug where data was copied into label, but the tests weren't\n# catching it, so let's make label 1-indexed.\nlabel = 1 + np.arange(num_rows)[:, np.newaxis]\nlabel = label.astype('float32')\n\n# We add an extra label2 dataset to test HDF5 layer's ability\n# to handle arbitrary number of output (\"top\") Blobs.\nlabel2 = label + 1\n\nprint data\nprint label\n\nwith h5py.File(script_dir + '/sample_data.h5', 'w') as f:\n    f['data'] = data\n    f['label'] = label\n    f['label2'] = label2\n\nwith h5py.File(script_dir + '/sample_data_2_gzip.h5', 'w') as f:\n    f.create_dataset(\n        'data', data=data + total_size,\n        compression='gzip', compression_opts=1\n    )\n    f.create_dataset(\n        'label', data=label,\n        compression='gzip', compression_opts=1\n    )\n    f.create_dataset(\n        'label2', data=label2,\n        compression='gzip', compression_opts=1\n    )\n\nwith open(script_dir + '/sample_data_list.txt', 'w') as f:\n    f.write(script_dir + '/sample_data.h5\\n')\n    f.write(script_dir + '/sample_data_2_gzip.h5\\n')\n\n# Generate GradientBasedSolver solver_data.h5\n\nnum_cols = 3\nnum_rows = 8\nheight = 10\nwidth = 10\n\ndata = np.random.randn(num_rows, num_cols, height, width)\ndata = data.reshape(num_rows, num_cols, height, width)\ndata = data.astype('float32')\n\ntargets = np.random.randn(num_rows, 1)\ntargets = targets.astype('float32')\n\nprint data\nprint targets\n\nwith h5py.File(script_dir + '/solver_data.h5', 'w') as f:\n    f['data'] = data\n    f['targets'] = targets\n\nwith open(script_dir + '/solver_data_list.txt', 'w') as f:\n    f.write(script_dir + '/solver_data.h5\\n')\n"
  },
  {
    "path": "src/caffe/test/test_data/sample_data_list.txt",
    "content": "src/caffe/test/test_data/sample_data.h5\nsrc/caffe/test/test_data/sample_data_2_gzip.h5\n"
  },
  {
    "path": "src/caffe/test/test_data/solver_data_list.txt",
    "content": "src/caffe/test/test_data/solver_data.h5\n"
  },
  {
    "path": "src/caffe/test/test_data_layer.cpp",
    "content": "#include <string>\n#include <vector>\n\n#include \"boost/scoped_ptr.hpp\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/db.hpp\"\n#include \"caffe/util/io.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nusing boost::scoped_ptr;\n\ntemplate <typename TypeParam>\nclass DataLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  DataLayerTest()\n      : backend_(DataParameter_DB_LEVELDB),\n        blob_top_data_(new Blob<Dtype>()),\n        blob_top_label_(new Blob<Dtype>()),\n        seed_(1701) {}\n  virtual void SetUp() {\n    filename_.reset(new string());\n    MakeTempDir(filename_.get());\n    *filename_ += \"/db\";\n    blob_top_vec_.push_back(blob_top_data_);\n    blob_top_vec_.push_back(blob_top_label_);\n  }\n\n  // Fill the DB with data: if unique_pixels, each pixel is unique but\n  // all images are the same; else each image is unique but all pixels within\n  // an image are the same.\n  void Fill(const bool unique_pixels, DataParameter_DB backend) {\n    backend_ = backend;\n    LOG(INFO) << \"Using temporary dataset \" << *filename_;\n    scoped_ptr<db::DB> db(db::GetDB(backend));\n    db->Open(*filename_, db::NEW);\n    scoped_ptr<db::Transaction> txn(db->NewTransaction());\n    for (int i = 0; i < 5; ++i) {\n      Datum datum;\n      datum.set_label(i);\n      datum.set_channels(2);\n      datum.set_height(3);\n      datum.set_width(4);\n      std::string* data = datum.mutable_data();\n      for (int j = 0; j < 24; ++j) {\n        int datum = unique_pixels ? j : i;\n        data->push_back(static_cast<uint8_t>(datum));\n      }\n      stringstream ss;\n      ss << i;\n      string out;\n      CHECK(datum.SerializeToString(&out));\n      txn->Put(ss.str(), out);\n    }\n    txn->Commit();\n    db->Close();\n  }\n\n  void TestRead() {\n    const Dtype scale = 3;\n    LayerParameter param;\n    param.set_phase(TRAIN);\n    DataParameter* data_param = param.mutable_data_param();\n    data_param->set_batch_size(5);\n    data_param->set_source(filename_->c_str());\n    data_param->set_backend(backend_);\n\n    TransformationParameter* transform_param =\n        param.mutable_transform_param();\n    transform_param->set_scale(scale);\n\n    DataLayer<Dtype> layer(param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    EXPECT_EQ(blob_top_data_->num(), 5);\n    EXPECT_EQ(blob_top_data_->channels(), 2);\n    EXPECT_EQ(blob_top_data_->height(), 3);\n    EXPECT_EQ(blob_top_data_->width(), 4);\n    EXPECT_EQ(blob_top_label_->num(), 5);\n    EXPECT_EQ(blob_top_label_->channels(), 1);\n    EXPECT_EQ(blob_top_label_->height(), 1);\n    EXPECT_EQ(blob_top_label_->width(), 1);\n\n    for (int iter = 0; iter < 100; ++iter) {\n      layer.Forward(blob_bottom_vec_, blob_top_vec_);\n      for (int i = 0; i < 5; ++i) {\n        EXPECT_EQ(i, blob_top_label_->cpu_data()[i]);\n      }\n      for (int i = 0; i < 5; ++i) {\n        for (int j = 0; j < 24; ++j) {\n          EXPECT_EQ(scale * i, blob_top_data_->cpu_data()[i * 24 + j])\n              << \"debug: iter \" << iter << \" i \" << i << \" j \" << j;\n        }\n      }\n    }\n  }\n\n  void TestReshape(DataParameter_DB backend) {\n    const int num_inputs = 5;\n    // Save data of varying shapes.\n    LOG(INFO) << \"Using temporary dataset \" << *filename_;\n    scoped_ptr<db::DB> db(db::GetDB(backend));\n    db->Open(*filename_, db::NEW);\n    scoped_ptr<db::Transaction> txn(db->NewTransaction());\n    for (int i = 0; i < num_inputs; ++i) {\n      Datum datum;\n      datum.set_label(i);\n      datum.set_channels(2);\n      datum.set_height(i % 2 + 1);\n      datum.set_width(i % 4 + 1);\n      std::string* data = datum.mutable_data();\n      const int data_size = datum.channels() * datum.height() * datum.width();\n      for (int j = 0; j < data_size; ++j) {\n        data->push_back(static_cast<uint8_t>(j));\n      }\n      stringstream ss;\n      ss << i;\n      string out;\n      CHECK(datum.SerializeToString(&out));\n      txn->Put(ss.str(), out);\n    }\n    txn->Commit();\n    db->Close();\n\n    // Load and check data of various shapes.\n    LayerParameter param;\n    param.set_phase(TEST);\n    DataParameter* data_param = param.mutable_data_param();\n    data_param->set_batch_size(1);\n    data_param->set_source(filename_->c_str());\n    data_param->set_backend(backend);\n\n    DataLayer<Dtype> layer(param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    EXPECT_EQ(blob_top_data_->num(), 1);\n    EXPECT_EQ(blob_top_data_->channels(), 2);\n    EXPECT_EQ(blob_top_label_->num(), 1);\n    EXPECT_EQ(blob_top_label_->channels(), 1);\n    EXPECT_EQ(blob_top_label_->height(), 1);\n    EXPECT_EQ(blob_top_label_->width(), 1);\n\n    for (int iter = 0; iter < num_inputs; ++iter) {\n      layer.Forward(blob_bottom_vec_, blob_top_vec_);\n      EXPECT_EQ(blob_top_data_->height(), iter % 2 + 1);\n      EXPECT_EQ(blob_top_data_->width(), iter % 4 + 1);\n      EXPECT_EQ(iter, blob_top_label_->cpu_data()[0]);\n      const int channels = blob_top_data_->channels();\n      const int height = blob_top_data_->height();\n      const int width = blob_top_data_->width();\n      for (int c = 0; c < channels; ++c) {\n        for (int h = 0; h < height; ++h) {\n          for (int w = 0; w < width; ++w) {\n            const int idx = (c * height + h) * width + w;\n            EXPECT_EQ(idx, static_cast<int>(blob_top_data_->cpu_data()[idx]))\n                << \"debug: iter \" << iter << \" c \" << c\n                << \" h \" << h << \" w \" << w;\n          }\n        }\n      }\n    }\n  }\n\n  void TestReadCrop(Phase phase) {\n    const Dtype scale = 3;\n    LayerParameter param;\n    param.set_phase(phase);\n    Caffe::set_random_seed(1701);\n\n    DataParameter* data_param = param.mutable_data_param();\n    data_param->set_batch_size(5);\n    data_param->set_source(filename_->c_str());\n    data_param->set_backend(backend_);\n\n    TransformationParameter* transform_param =\n        param.mutable_transform_param();\n    transform_param->set_scale(scale);\n    transform_param->set_crop_size(1);\n\n    DataLayer<Dtype> layer(param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    EXPECT_EQ(blob_top_data_->num(), 5);\n    EXPECT_EQ(blob_top_data_->channels(), 2);\n    EXPECT_EQ(blob_top_data_->height(), 1);\n    EXPECT_EQ(blob_top_data_->width(), 1);\n    EXPECT_EQ(blob_top_label_->num(), 5);\n    EXPECT_EQ(blob_top_label_->channels(), 1);\n    EXPECT_EQ(blob_top_label_->height(), 1);\n    EXPECT_EQ(blob_top_label_->width(), 1);\n\n    for (int iter = 0; iter < 2; ++iter) {\n      layer.Forward(blob_bottom_vec_, blob_top_vec_);\n      for (int i = 0; i < 5; ++i) {\n        EXPECT_EQ(i, blob_top_label_->cpu_data()[i]);\n      }\n      int num_with_center_value = 0;\n      for (int i = 0; i < 5; ++i) {\n        for (int j = 0; j < 2; ++j) {\n          const Dtype center_value = scale * (j ? 17 : 5);\n          num_with_center_value +=\n              (center_value == blob_top_data_->cpu_data()[i * 2 + j]);\n          // At TEST time, check that we always get center value.\n          if (phase == caffe::TEST) {\n            EXPECT_EQ(center_value, this->blob_top_data_->cpu_data()[i * 2 + j])\n                << \"debug: iter \" << iter << \" i \" << i << \" j \" << j;\n          }\n        }\n      }\n      // At TRAIN time, check that we did not get the center crop all 10 times.\n      // (This check fails with probability 1-1/12^10 in a correct\n      // implementation, so we call set_random_seed.)\n      if (phase == caffe::TRAIN) {\n        EXPECT_LT(num_with_center_value, 10);\n      }\n    }\n  }\n\n  void TestReadCropTrainSequenceSeeded() {\n    LayerParameter param;\n    param.set_phase(TRAIN);\n    DataParameter* data_param = param.mutable_data_param();\n    data_param->set_batch_size(5);\n    data_param->set_source(filename_->c_str());\n    data_param->set_backend(backend_);\n\n    TransformationParameter* transform_param =\n        param.mutable_transform_param();\n    transform_param->set_crop_size(1);\n    transform_param->set_mirror(true);\n\n    // Get crop sequence with Caffe seed 1701.\n    Caffe::set_random_seed(seed_);\n    vector<vector<Dtype> > crop_sequence;\n    {\n      DataLayer<Dtype> layer1(param);\n      layer1.SetUp(blob_bottom_vec_, blob_top_vec_);\n      for (int iter = 0; iter < 2; ++iter) {\n        layer1.Forward(blob_bottom_vec_, blob_top_vec_);\n        for (int i = 0; i < 5; ++i) {\n          EXPECT_EQ(i, blob_top_label_->cpu_data()[i]);\n        }\n        vector<Dtype> iter_crop_sequence;\n        for (int i = 0; i < 5; ++i) {\n          for (int j = 0; j < 2; ++j) {\n            iter_crop_sequence.push_back(\n                blob_top_data_->cpu_data()[i * 2 + j]);\n          }\n        }\n        crop_sequence.push_back(iter_crop_sequence);\n      }\n    }  // destroy 1st data layer and unlock the db\n\n    // Get crop sequence after reseeding Caffe with 1701.\n    // Check that the sequence is the same as the original.\n    Caffe::set_random_seed(seed_);\n    DataLayer<Dtype> layer2(param);\n    layer2.SetUp(blob_bottom_vec_, blob_top_vec_);\n    for (int iter = 0; iter < 2; ++iter) {\n      layer2.Forward(blob_bottom_vec_, blob_top_vec_);\n      for (int i = 0; i < 5; ++i) {\n        EXPECT_EQ(i, blob_top_label_->cpu_data()[i]);\n      }\n      for (int i = 0; i < 5; ++i) {\n        for (int j = 0; j < 2; ++j) {\n          EXPECT_EQ(crop_sequence[iter][i * 2 + j],\n                    blob_top_data_->cpu_data()[i * 2 + j])\n              << \"debug: iter \" << iter << \" i \" << i << \" j \" << j;\n        }\n      }\n    }\n  }\n\n  void TestReadCropTrainSequenceUnseeded() {\n    LayerParameter param;\n    param.set_phase(TRAIN);\n    DataParameter* data_param = param.mutable_data_param();\n    data_param->set_batch_size(5);\n    data_param->set_source(filename_->c_str());\n    data_param->set_backend(backend_);\n\n    TransformationParameter* transform_param =\n        param.mutable_transform_param();\n    transform_param->set_crop_size(1);\n    transform_param->set_mirror(true);\n\n    // Get crop sequence with Caffe seed 1701, srand seed 1701.\n    Caffe::set_random_seed(seed_);\n    srand(seed_);\n    vector<vector<Dtype> > crop_sequence;\n    {\n      DataLayer<Dtype> layer1(param);\n      layer1.SetUp(blob_bottom_vec_, blob_top_vec_);\n      for (int iter = 0; iter < 2; ++iter) {\n        layer1.Forward(blob_bottom_vec_, blob_top_vec_);\n        for (int i = 0; i < 5; ++i) {\n          EXPECT_EQ(i, blob_top_label_->cpu_data()[i]);\n        }\n        vector<Dtype> iter_crop_sequence;\n        for (int i = 0; i < 5; ++i) {\n          for (int j = 0; j < 2; ++j) {\n            iter_crop_sequence.push_back(\n                blob_top_data_->cpu_data()[i * 2 + j]);\n          }\n        }\n        crop_sequence.push_back(iter_crop_sequence);\n      }\n    }  // destroy 1st data layer and unlock the db\n\n    // Get crop sequence continuing from previous Caffe RNG state; reseed\n    // srand with 1701. Check that the sequence differs from the original.\n    srand(seed_);\n    DataLayer<Dtype> layer2(param);\n    layer2.SetUp(blob_bottom_vec_, blob_top_vec_);\n    for (int iter = 0; iter < 2; ++iter) {\n      layer2.Forward(blob_bottom_vec_, blob_top_vec_);\n      for (int i = 0; i < 5; ++i) {\n        EXPECT_EQ(i, blob_top_label_->cpu_data()[i]);\n      }\n      int num_sequence_matches = 0;\n      for (int i = 0; i < 5; ++i) {\n        for (int j = 0; j < 2; ++j) {\n          num_sequence_matches += (crop_sequence[iter][i * 2 + j] ==\n                                   blob_top_data_->cpu_data()[i * 2 + j]);\n        }\n      }\n      EXPECT_LT(num_sequence_matches, 10);\n    }\n  }\n\n  virtual ~DataLayerTest() { delete blob_top_data_; delete blob_top_label_; }\n\n  DataParameter_DB backend_;\n  shared_ptr<string> filename_;\n  Blob<Dtype>* const blob_top_data_;\n  Blob<Dtype>* const blob_top_label_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n  int seed_;\n};\n\nTYPED_TEST_CASE(DataLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(DataLayerTest, TestReadLevelDB) {\n  const bool unique_pixels = false;  // all pixels the same; images different\n  this->Fill(unique_pixels, DataParameter_DB_LEVELDB);\n  this->TestRead();\n}\n\nTYPED_TEST(DataLayerTest, TestReshapeLevelDB) {\n  this->TestReshape(DataParameter_DB_LEVELDB);\n}\n\nTYPED_TEST(DataLayerTest, TestReadCropTrainLevelDB) {\n  const bool unique_pixels = true;  // all images the same; pixels different\n  this->Fill(unique_pixels, DataParameter_DB_LEVELDB);\n  this->TestReadCrop(TRAIN);\n}\n\n// Test that the sequence of random crops is consistent when using\n// Caffe::set_random_seed.\nTYPED_TEST(DataLayerTest, TestReadCropTrainSequenceSeededLevelDB) {\n  const bool unique_pixels = true;  // all images the same; pixels different\n  this->Fill(unique_pixels, DataParameter_DB_LEVELDB);\n  this->TestReadCropTrainSequenceSeeded();\n}\n\n// Test that the sequence of random crops differs across iterations when\n// Caffe::set_random_seed isn't called (and seeds from srand are ignored).\nTYPED_TEST(DataLayerTest, TestReadCropTrainSequenceUnseededLevelDB) {\n  const bool unique_pixels = true;  // all images the same; pixels different\n  this->Fill(unique_pixels, DataParameter_DB_LEVELDB);\n  this->TestReadCropTrainSequenceUnseeded();\n}\n\nTYPED_TEST(DataLayerTest, TestReadCropTestLevelDB) {\n  const bool unique_pixels = true;  // all images the same; pixels different\n  this->Fill(unique_pixels, DataParameter_DB_LEVELDB);\n  this->TestReadCrop(TEST);\n}\n\nTYPED_TEST(DataLayerTest, TestReadLMDB) {\n  const bool unique_pixels = false;  // all pixels the same; images different\n  this->Fill(unique_pixels, DataParameter_DB_LMDB);\n  this->TestRead();\n}\n\nTYPED_TEST(DataLayerTest, TestReshapeLMDB) {\n  this->TestReshape(DataParameter_DB_LMDB);\n}\n\nTYPED_TEST(DataLayerTest, TestReadCropTrainLMDB) {\n  const bool unique_pixels = true;  // all images the same; pixels different\n  this->Fill(unique_pixels, DataParameter_DB_LMDB);\n  this->TestReadCrop(TRAIN);\n}\n\n// Test that the sequence of random crops is consistent when using\n// Caffe::set_random_seed.\nTYPED_TEST(DataLayerTest, TestReadCropTrainSequenceSeededLMDB) {\n  const bool unique_pixels = true;  // all images the same; pixels different\n  this->Fill(unique_pixels, DataParameter_DB_LMDB);\n  this->TestReadCropTrainSequenceSeeded();\n}\n\n// Test that the sequence of random crops differs across iterations when\n// Caffe::set_random_seed isn't called (and seeds from srand are ignored).\nTYPED_TEST(DataLayerTest, TestReadCropTrainSequenceUnseededLMDB) {\n  const bool unique_pixels = true;  // all images the same; pixels different\n  this->Fill(unique_pixels, DataParameter_DB_LMDB);\n  this->TestReadCropTrainSequenceUnseeded();\n}\n\nTYPED_TEST(DataLayerTest, TestReadCropTestLMDB) {\n  const bool unique_pixels = true;  // all images the same; pixels different\n  this->Fill(unique_pixels, DataParameter_DB_LMDB);\n  this->TestReadCrop(TEST);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_data_transformer.cpp",
    "content": "#include <string>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n#include \"leveldb/db.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/data_transformer.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/io.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nvoid FillDatum(const int label, const int channels, const int height,\n  const int width, const bool unique_pixels, Datum * datum) {\n  datum->set_label(label);\n  datum->set_channels(channels);\n  datum->set_height(height);\n  datum->set_width(width);\n  int size = channels * height * width;\n  std::string* data = datum->mutable_data();\n  for (int j = 0; j < size; ++j) {\n    int datum = unique_pixels ? j : label;\n    data->push_back(static_cast<uint8_t>(datum));\n  }\n}\n\ntemplate <typename Dtype>\nclass DataTransformTest : public ::testing::Test {\n protected:\n  DataTransformTest()\n      : seed_(1701),\n      num_iter_(10) {}\n\n  int NumSequenceMatches(const TransformationParameter transform_param,\n      const Datum& datum, Phase phase) {\n    // Get crop sequence with Caffe seed 1701.\n    DataTransformer<Dtype>* transformer =\n        new DataTransformer<Dtype>(transform_param, phase);\n    const int crop_size = transform_param.crop_size();\n    Caffe::set_random_seed(seed_);\n    transformer->InitRand();\n    Blob<Dtype>* blob =\n        new Blob<Dtype>(1, datum.channels(), datum.height(), datum.width());\n    if (transform_param.crop_size() > 0) {\n      blob->Reshape(1, datum.channels(), crop_size, crop_size);\n    }\n\n    vector<vector<Dtype> > crop_sequence;\n    for (int iter = 0; iter < this->num_iter_; ++iter) {\n      vector<Dtype> iter_crop_sequence;\n      transformer->Transform(datum, blob);\n      for (int j = 0; j < blob->count(); ++j) {\n        iter_crop_sequence.push_back(blob->cpu_data()[j]);\n      }\n      crop_sequence.push_back(iter_crop_sequence);\n    }\n    // Check if the sequence differs from the previous\n    int num_sequence_matches = 0;\n    for (int iter = 0; iter < this->num_iter_; ++iter) {\n      vector<Dtype> iter_crop_sequence = crop_sequence[iter];\n      transformer->Transform(datum, blob);\n      for (int j = 0; j < blob->count(); ++j) {\n        num_sequence_matches +=\n            (crop_sequence[iter][j] == blob->cpu_data()[j]);\n      }\n    }\n    return num_sequence_matches;\n  }\n\n  virtual ~DataTransformTest() { }\n\n  int seed_;\n  int num_iter_;\n};\n\nTYPED_TEST_CASE(DataTransformTest, TestDtypes);\n\nTYPED_TEST(DataTransformTest, TestEmptyTransform) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = false;  // all pixels the same equal to label\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  Blob<TypeParam>* blob = new Blob<TypeParam>(1, channels, height, width);\n  DataTransformer<TypeParam>* transformer =\n      new DataTransformer<TypeParam>(transform_param, TEST);\n  transformer->InitRand();\n  transformer->Transform(datum, blob);\n  EXPECT_EQ(blob->num(), 1);\n  EXPECT_EQ(blob->channels(), datum.channels());\n  EXPECT_EQ(blob->height(), datum.height());\n  EXPECT_EQ(blob->width(), datum.width());\n  for (int j = 0; j < blob->count(); ++j) {\n    EXPECT_EQ(blob->cpu_data()[j], label);\n  }\n}\n\nTYPED_TEST(DataTransformTest, TestEmptyTransformUniquePixels) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = true;  // pixels are consecutive ints [0,size]\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  Blob<TypeParam>* blob = new Blob<TypeParam>(1, 3, 4, 5);\n  DataTransformer<TypeParam>* transformer =\n      new DataTransformer<TypeParam>(transform_param, TEST);\n  transformer->InitRand();\n  transformer->Transform(datum, blob);\n  EXPECT_EQ(blob->num(), 1);\n  EXPECT_EQ(blob->channels(), datum.channels());\n  EXPECT_EQ(blob->height(), datum.height());\n  EXPECT_EQ(blob->width(), datum.width());\n  for (int j = 0; j < blob->count(); ++j) {\n    EXPECT_EQ(blob->cpu_data()[j], j);\n  }\n}\n\nTYPED_TEST(DataTransformTest, TestCropSize) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = false;  // all pixels the same equal to label\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n  const int crop_size = 2;\n\n  transform_param.set_crop_size(crop_size);\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  DataTransformer<TypeParam>* transformer =\n      new DataTransformer<TypeParam>(transform_param, TEST);\n  transformer->InitRand();\n  Blob<TypeParam>* blob =\n      new Blob<TypeParam>(1, channels, crop_size, crop_size);\n  for (int iter = 0; iter < this->num_iter_; ++iter) {\n    transformer->Transform(datum, blob);\n    EXPECT_EQ(blob->num(), 1);\n    EXPECT_EQ(blob->channels(), datum.channels());\n    EXPECT_EQ(blob->height(), crop_size);\n    EXPECT_EQ(blob->width(), crop_size);\n    for (int j = 0; j < blob->count(); ++j) {\n      EXPECT_EQ(blob->cpu_data()[j], label);\n    }\n  }\n}\n\nTYPED_TEST(DataTransformTest, TestCropTrain) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = true;  // pixels are consecutive ints [0,size]\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n  const int crop_size = 2;\n  const int size = channels * crop_size * crop_size;\n\n  transform_param.set_crop_size(crop_size);\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  int num_matches = this->NumSequenceMatches(transform_param, datum, TRAIN);\n  EXPECT_LT(num_matches, size * this->num_iter_);\n}\n\nTYPED_TEST(DataTransformTest, TestCropTest) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = true;  // pixels are consecutive ints [0,size]\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n  const int crop_size = 2;\n  const int size = channels * crop_size * crop_size;\n\n  transform_param.set_crop_size(crop_size);\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  int num_matches = this->NumSequenceMatches(transform_param, datum, TEST);\n  EXPECT_EQ(num_matches, size * this->num_iter_);\n}\n\nTYPED_TEST(DataTransformTest, TestMirrorTrain) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = true;  // pixels are consecutive ints [0,size]\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n  const int size = channels * height * width;\n\n  transform_param.set_mirror(true);\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  int num_matches = this->NumSequenceMatches(transform_param, datum, TRAIN);\n  EXPECT_LT(num_matches, size * this->num_iter_);\n}\n\nTYPED_TEST(DataTransformTest, TestMirrorTest) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = true;  // pixels are consecutive ints [0,size]\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n  const int size = channels * height * width;\n\n  transform_param.set_mirror(true);\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  int num_matches = this->NumSequenceMatches(transform_param, datum, TEST);\n  EXPECT_LT(num_matches, size * this->num_iter_);\n}\n\nTYPED_TEST(DataTransformTest, TestCropMirrorTrain) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = true;  // pixels are consecutive ints [0,size]\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n  const int crop_size = 2;\n\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  transform_param.set_crop_size(crop_size);\n  int num_matches_crop = this->NumSequenceMatches(\n      transform_param, datum, TRAIN);\n\n  transform_param.set_mirror(true);\n  int num_matches_crop_mirror =\n      this->NumSequenceMatches(transform_param, datum, TRAIN);\n  // When doing crop and mirror we expect less num_matches than just crop\n  EXPECT_LE(num_matches_crop_mirror, num_matches_crop);\n}\n\nTYPED_TEST(DataTransformTest, TestCropMirrorTest) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = true;  // pixels are consecutive ints [0,size]\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n  const int crop_size = 2;\n\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  transform_param.set_crop_size(crop_size);\n  int num_matches_crop = this->NumSequenceMatches(transform_param, datum, TEST);\n\n  transform_param.set_mirror(true);\n  int num_matches_crop_mirror =\n      this->NumSequenceMatches(transform_param, datum, TEST);\n  // When doing crop and mirror we expect less num_matches than just crop\n  EXPECT_LT(num_matches_crop_mirror, num_matches_crop);\n}\n\n\nTYPED_TEST(DataTransformTest, TestMeanValue) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = false;  // pixels are equal to label\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n  const int mean_value = 2;\n\n  transform_param.add_mean_value(mean_value);\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  Blob<TypeParam>* blob = new Blob<TypeParam>(1, channels, height, width);\n  DataTransformer<TypeParam>* transformer =\n      new DataTransformer<TypeParam>(transform_param, TEST);\n  transformer->InitRand();\n  transformer->Transform(datum, blob);\n  for (int j = 0; j < blob->count(); ++j) {\n    EXPECT_EQ(blob->cpu_data()[j], label - mean_value);\n  }\n}\n\nTYPED_TEST(DataTransformTest, TestMeanValues) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = false;  // pixels are equal to label\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n\n  transform_param.add_mean_value(0);\n  transform_param.add_mean_value(1);\n  transform_param.add_mean_value(2);\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  Blob<TypeParam>* blob = new Blob<TypeParam>(1, channels, height, width);\n  DataTransformer<TypeParam>* transformer =\n      new DataTransformer<TypeParam>(transform_param, TEST);\n  transformer->InitRand();\n  transformer->Transform(datum, blob);\n  for (int c = 0; c < channels; ++c) {\n    for (int j = 0; j < height * width; ++j) {\n      EXPECT_EQ(blob->cpu_data()[blob->offset(0, c) + j], label - c);\n    }\n  }\n}\n\nTYPED_TEST(DataTransformTest, TestMeanFile) {\n  TransformationParameter transform_param;\n  const bool unique_pixels = true;  // pixels are consecutive ints [0,size]\n  const int label = 0;\n  const int channels = 3;\n  const int height = 4;\n  const int width = 5;\n  const int size = channels * height * width;\n\n  // Create a mean file\n  string* mean_file = new string();\n  MakeTempFilename(mean_file);\n  BlobProto blob_mean;\n  blob_mean.set_num(1);\n  blob_mean.set_channels(channels);\n  blob_mean.set_height(height);\n  blob_mean.set_width(width);\n\n  for (int j = 0; j < size; ++j) {\n      blob_mean.add_data(j);\n  }\n\n  LOG(INFO) << \"Using temporary mean_file \" << *mean_file;\n  WriteProtoToBinaryFile(blob_mean, *mean_file);\n\n  transform_param.set_mean_file(*mean_file);\n  Datum datum;\n  FillDatum(label, channels, height, width, unique_pixels, &datum);\n  Blob<TypeParam>* blob = new Blob<TypeParam>(1, channels, height, width);\n  DataTransformer<TypeParam>* transformer =\n      new DataTransformer<TypeParam>(transform_param, TEST);\n  transformer->InitRand();\n  transformer->Transform(datum, blob);\n  for (int j = 0; j < blob->count(); ++j) {\n      EXPECT_EQ(blob->cpu_data()[j], 0);\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_db.cpp",
    "content": "#include <string>\n\n#include \"boost/scoped_ptr.hpp\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/db.hpp\"\n#include \"caffe/util/io.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nusing boost::scoped_ptr;\n\ntemplate <typename TypeParam>\nclass DBTest : public ::testing::Test {\n protected:\n  DBTest()\n      : backend_(TypeParam::backend),\n      root_images_(string(EXAMPLES_SOURCE_DIR) + string(\"images/\")) {}\n\n  virtual void SetUp() {\n    MakeTempDir(&source_);\n    source_ += \"/db\";\n    string keys[] = {\"cat.jpg\", \"fish-bike.jpg\"};\n    LOG(INFO) << \"Using temporary db \" << source_;\n    scoped_ptr<db::DB> db(db::GetDB(TypeParam::backend));\n    db->Open(this->source_, db::NEW);\n    scoped_ptr<db::Transaction> txn(db->NewTransaction());\n    for (int i = 0; i < 2; ++i) {\n      Datum datum;\n      ReadImageToDatum(root_images_ + keys[i], i, &datum);\n      string out;\n      CHECK(datum.SerializeToString(&out));\n      txn->Put(keys[i], out);\n    }\n    txn->Commit();\n  }\n\n  virtual ~DBTest() { }\n\n  DataParameter_DB backend_;\n  string source_;\n  string root_images_;\n};\n\nstruct TypeLevelDB {\n  static DataParameter_DB backend;\n};\nDataParameter_DB TypeLevelDB::backend = DataParameter_DB_LEVELDB;\n\nstruct TypeLMDB {\n  static DataParameter_DB backend;\n};\nDataParameter_DB TypeLMDB::backend = DataParameter_DB_LMDB;\n\n// typedef ::testing::Types<TypeLmdb> TestTypes;\ntypedef ::testing::Types<TypeLevelDB, TypeLMDB> TestTypes;\n\nTYPED_TEST_CASE(DBTest, TestTypes);\n\nTYPED_TEST(DBTest, TestGetDB) {\n  scoped_ptr<db::DB> db(db::GetDB(TypeParam::backend));\n}\n\nTYPED_TEST(DBTest, TestNext) {\n  scoped_ptr<db::DB> db(db::GetDB(TypeParam::backend));\n  db->Open(this->source_, db::READ);\n  scoped_ptr<db::Cursor> cursor(db->NewCursor());\n  EXPECT_TRUE(cursor->valid());\n  cursor->Next();\n  EXPECT_TRUE(cursor->valid());\n  cursor->Next();\n  EXPECT_FALSE(cursor->valid());\n}\n\nTYPED_TEST(DBTest, TestSeekToFirst) {\n  scoped_ptr<db::DB> db(db::GetDB(TypeParam::backend));\n  db->Open(this->source_, db::READ);\n  scoped_ptr<db::Cursor> cursor(db->NewCursor());\n  cursor->Next();\n  cursor->SeekToFirst();\n  EXPECT_TRUE(cursor->valid());\n  string key = cursor->key();\n  Datum datum;\n  datum.ParseFromString(cursor->value());\n  EXPECT_EQ(key, \"cat.jpg\");\n  EXPECT_EQ(datum.channels(), 3);\n  EXPECT_EQ(datum.height(), 360);\n  EXPECT_EQ(datum.width(), 480);\n}\n\nTYPED_TEST(DBTest, TestKeyValue) {\n  scoped_ptr<db::DB> db(db::GetDB(TypeParam::backend));\n  db->Open(this->source_, db::READ);\n  scoped_ptr<db::Cursor> cursor(db->NewCursor());\n  EXPECT_TRUE(cursor->valid());\n  string key = cursor->key();\n  Datum datum;\n  datum.ParseFromString(cursor->value());\n  EXPECT_EQ(key, \"cat.jpg\");\n  EXPECT_EQ(datum.channels(), 3);\n  EXPECT_EQ(datum.height(), 360);\n  EXPECT_EQ(datum.width(), 480);\n  cursor->Next();\n  EXPECT_TRUE(cursor->valid());\n  key = cursor->key();\n  datum.ParseFromString(cursor->value());\n  EXPECT_EQ(key, \"fish-bike.jpg\");\n  EXPECT_EQ(datum.channels(), 3);\n  EXPECT_EQ(datum.height(), 323);\n  EXPECT_EQ(datum.width(), 481);\n  cursor->Next();\n  EXPECT_FALSE(cursor->valid());\n}\n\nTYPED_TEST(DBTest, TestWrite) {\n  scoped_ptr<db::DB> db(db::GetDB(TypeParam::backend));\n  db->Open(this->source_, db::WRITE);\n  scoped_ptr<db::Transaction> txn(db->NewTransaction());\n  Datum datum;\n  ReadFileToDatum(this->root_images_ + \"cat.jpg\", 0, &datum);\n  string out;\n  CHECK(datum.SerializeToString(&out));\n  txn->Put(\"cat.jpg\", out);\n  ReadFileToDatum(this->root_images_ + \"fish-bike.jpg\", 1, &datum);\n  CHECK(datum.SerializeToString(&out));\n  txn->Put(\"fish-bike.jpg\", out);\n  txn->Commit();\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_deconvolution_layer.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\n// Since ConvolutionLayerTest checks the shared conv/deconv code in detail,\n// we'll just do a simple forward test and a gradient check.\ntemplate <typename TypeParam>\nclass DeconvolutionLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  DeconvolutionLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 6, 4)),\n        blob_bottom_2_(new Blob<Dtype>(2, 3, 6, 4)),\n        blob_top_(new Blob<Dtype>()),\n        blob_top_2_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    // fill the values\n    FillerParameter filler_param;\n    filler_param.set_value(1.);\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    filler.Fill(this->blob_bottom_2_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n\n  virtual ~DeconvolutionLayerTest() {\n    delete blob_bottom_;\n    delete blob_bottom_2_;\n    delete blob_top_;\n    delete blob_top_2_;\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_bottom_2_;\n  Blob<Dtype>* const blob_top_;\n  Blob<Dtype>* const blob_top_2_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(DeconvolutionLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(DeconvolutionLayerTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(4);\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  shared_ptr<Layer<Dtype> > layer(\n      new DeconvolutionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 4);\n  EXPECT_EQ(this->blob_top_->height(), 13);\n  EXPECT_EQ(this->blob_top_->width(), 9);\n  EXPECT_EQ(this->blob_top_2_->num(), 2);\n  EXPECT_EQ(this->blob_top_2_->channels(), 4);\n  EXPECT_EQ(this->blob_top_2_->height(), 13);\n  EXPECT_EQ(this->blob_top_2_->width(), 9);\n  // setting group should not change the shape\n  convolution_param->set_num_output(3);\n  convolution_param->set_group(3);\n  layer.reset(new DeconvolutionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 3);\n  EXPECT_EQ(this->blob_top_->height(), 13);\n  EXPECT_EQ(this->blob_top_->width(), 9);\n  EXPECT_EQ(this->blob_top_2_->num(), 2);\n  EXPECT_EQ(this->blob_top_2_->channels(), 3);\n  EXPECT_EQ(this->blob_top_2_->height(), 13);\n  EXPECT_EQ(this->blob_top_2_->width(), 9);\n}\n\nTYPED_TEST(DeconvolutionLayerTest, TestSimpleDeconvolution) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  convolution_param->set_num_output(4);\n  convolution_param->mutable_weight_filler()->set_type(\"constant\");\n  convolution_param->mutable_weight_filler()->set_value(1);\n  convolution_param->mutable_bias_filler()->set_type(\"constant\");\n  convolution_param->mutable_bias_filler()->set_value(0.1);\n  shared_ptr<Layer<Dtype> > layer(\n      new DeconvolutionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  // constant-fill the bottom blobs\n  FillerParameter filler_param;\n  filler_param.set_value(1.);\n  ConstantFiller<Dtype> filler(filler_param);\n  filler.Fill(this->blob_bottom_);\n  filler.Fill(this->blob_bottom_2_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // simply check that accumulation works with overlapping filters\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  for (int n = 0; n < this->blob_top_->num(); ++n) {\n    for (int c = 0; c < this->blob_top_->channels(); ++c) {\n      for (int h = 0; h < this->blob_top_->height(); ++h) {\n        for (int w = 0; w < this->blob_top_->width(); ++w) {\n          Dtype expected = 3.1;\n          bool h_overlap = h % 2 == 0 && h > 0\n            && h < this->blob_top_->height() - 1;\n          bool w_overlap = w % 2 == 0 && w > 0\n            && w < this->blob_top_->width() - 1;\n          if (h_overlap && w_overlap) {\n            expected += 9;\n          } else if (h_overlap || w_overlap) {\n            expected += 3;\n          }\n          EXPECT_NEAR(top_data[this->blob_top_->offset(n, c, h, w)],\n              expected, 1e-4);\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(DeconvolutionLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  this->blob_bottom_vec_.push_back(this->blob_bottom_2_);\n  this->blob_top_vec_.push_back(this->blob_top_2_);\n  convolution_param->set_kernel_size(2);\n  convolution_param->set_stride(1);\n  convolution_param->set_num_output(1);\n  convolution_param->mutable_weight_filler()->set_type(\"gaussian\");\n  convolution_param->mutable_bias_filler()->set_type(\"gaussian\");\n  DeconvolutionLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_dummy_data_layer.cpp",
    "content": "#include <string>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nclass DummyDataLayerTest : public CPUDeviceTest<Dtype> {\n protected:\n  DummyDataLayerTest()\n      : blob_top_a_(new Blob<Dtype>()),\n        blob_top_b_(new Blob<Dtype>()),\n        blob_top_c_(new Blob<Dtype>()) {}\n\n  virtual void SetUp() {\n    blob_bottom_vec_.clear();\n    blob_top_vec_.clear();\n    blob_top_vec_.push_back(blob_top_a_);\n    blob_top_vec_.push_back(blob_top_b_);\n    blob_top_vec_.push_back(blob_top_c_);\n  }\n\n  virtual ~DummyDataLayerTest() {\n    delete blob_top_a_;\n    delete blob_top_b_;\n    delete blob_top_c_;\n  }\n\n  Blob<Dtype>* const blob_top_a_;\n  Blob<Dtype>* const blob_top_b_;\n  Blob<Dtype>* const blob_top_c_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(DummyDataLayerTest, TestDtypes);\n\nTYPED_TEST(DummyDataLayerTest, TestOneTopConstant) {\n  LayerParameter param;\n  DummyDataParameter* dummy_data_param = param.mutable_dummy_data_param();\n  dummy_data_param->add_num(5);\n  dummy_data_param->add_channels(3);\n  dummy_data_param->add_height(2);\n  dummy_data_param->add_width(4);\n  this->blob_top_vec_.resize(1);\n  DummyDataLayer<TypeParam> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_a_->num(), 5);\n  EXPECT_EQ(this->blob_top_a_->channels(), 3);\n  EXPECT_EQ(this->blob_top_a_->height(), 2);\n  EXPECT_EQ(this->blob_top_a_->width(), 4);\n  EXPECT_EQ(this->blob_top_b_->count(), 0);\n  EXPECT_EQ(this->blob_top_c_->count(), 0);\n  for (int i = 0; i < this->blob_top_vec_.size(); ++i) {\n    for (int j = 0; j < this->blob_top_vec_[i]->count(); ++j) {\n      EXPECT_EQ(0, this->blob_top_vec_[i]->cpu_data()[j]);\n    }\n  }\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_top_vec_.size(); ++i) {\n    for (int j = 0; j < this->blob_top_vec_[i]->count(); ++j) {\n      EXPECT_EQ(0, this->blob_top_vec_[i]->cpu_data()[j]);\n    }\n  }\n}\n\nTYPED_TEST(DummyDataLayerTest, TestTwoTopConstant) {\n  LayerParameter param;\n  DummyDataParameter* dummy_data_param = param.mutable_dummy_data_param();\n  dummy_data_param->add_num(5);\n  dummy_data_param->add_channels(3);\n  dummy_data_param->add_height(2);\n  dummy_data_param->add_width(4);\n  dummy_data_param->add_num(5);\n  // Don't explicitly set number of channels or height for 2nd top blob; should\n  // default to first channels and height (as we check later).\n  dummy_data_param->add_height(1);\n  FillerParameter* data_filler_param = dummy_data_param->add_data_filler();\n  data_filler_param->set_value(7);\n  this->blob_top_vec_.resize(2);\n  DummyDataLayer<TypeParam> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_a_->num(), 5);\n  EXPECT_EQ(this->blob_top_a_->channels(), 3);\n  EXPECT_EQ(this->blob_top_a_->height(), 2);\n  EXPECT_EQ(this->blob_top_a_->width(), 4);\n  EXPECT_EQ(this->blob_top_b_->num(), 5);\n  EXPECT_EQ(this->blob_top_b_->channels(), 3);\n  EXPECT_EQ(this->blob_top_b_->height(), 1);\n  EXPECT_EQ(this->blob_top_b_->width(), 4);\n  EXPECT_EQ(this->blob_top_c_->count(), 0);\n  for (int i = 0; i < this->blob_top_vec_.size(); ++i) {\n    for (int j = 0; j < this->blob_top_vec_[i]->count(); ++j) {\n      EXPECT_EQ(7, this->blob_top_vec_[i]->cpu_data()[j]);\n    }\n  }\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_top_vec_.size(); ++i) {\n    for (int j = 0; j < this->blob_top_vec_[i]->count(); ++j) {\n      EXPECT_EQ(7, this->blob_top_vec_[i]->cpu_data()[j]);\n    }\n  }\n}\n\nTYPED_TEST(DummyDataLayerTest, TestThreeTopConstantGaussianConstant) {\n  LayerParameter param;\n  DummyDataParameter* dummy_data_param = param.mutable_dummy_data_param();\n  dummy_data_param->add_num(5);\n  dummy_data_param->add_channels(3);\n  dummy_data_param->add_height(2);\n  dummy_data_param->add_width(4);\n  FillerParameter* data_filler_param_a = dummy_data_param->add_data_filler();\n  data_filler_param_a->set_value(7);\n  FillerParameter* data_filler_param_b = dummy_data_param->add_data_filler();\n  data_filler_param_b->set_type(\"gaussian\");\n  TypeParam gaussian_mean = 3.0;\n  TypeParam gaussian_std = 0.01;\n  data_filler_param_b->set_mean(gaussian_mean);\n  data_filler_param_b->set_std(gaussian_std);\n  FillerParameter* data_filler_param_c = dummy_data_param->add_data_filler();\n  data_filler_param_c->set_value(9);\n  DummyDataLayer<TypeParam> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_a_->num(), 5);\n  EXPECT_EQ(this->blob_top_a_->channels(), 3);\n  EXPECT_EQ(this->blob_top_a_->height(), 2);\n  EXPECT_EQ(this->blob_top_a_->width(), 4);\n  EXPECT_EQ(this->blob_top_b_->num(), 5);\n  EXPECT_EQ(this->blob_top_b_->channels(), 3);\n  EXPECT_EQ(this->blob_top_b_->height(), 2);\n  EXPECT_EQ(this->blob_top_b_->width(), 4);\n  EXPECT_EQ(this->blob_top_c_->num(), 5);\n  EXPECT_EQ(this->blob_top_c_->channels(), 3);\n  EXPECT_EQ(this->blob_top_c_->height(), 2);\n  EXPECT_EQ(this->blob_top_c_->width(), 4);\n  for (int i = 0; i < this->blob_top_a_->count(); ++i) {\n    EXPECT_EQ(7, this->blob_top_a_->cpu_data()[i]);\n  }\n  // Blob b uses a Gaussian filler, so SetUp should not have initialized it.\n  // Blob b's data should therefore be the default Blob data value: 0.\n  for (int i = 0; i < this->blob_top_b_->count(); ++i) {\n    EXPECT_EQ(0, this->blob_top_b_->cpu_data()[i]);\n  }\n  for (int i = 0; i < this->blob_top_c_->count(); ++i) {\n    EXPECT_EQ(9, this->blob_top_c_->cpu_data()[i]);\n  }\n\n  // Do a Forward pass to fill in Blob b with Gaussian data.\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_top_a_->count(); ++i) {\n    EXPECT_EQ(7, this->blob_top_a_->cpu_data()[i]);\n  }\n  // Check that the Gaussian's data has been filled in with values within\n  // 10 standard deviations of the mean. Record the first and last sample.\n  // to check that they're different after the next Forward pass.\n  for (int i = 0; i < this->blob_top_b_->count(); ++i) {\n    EXPECT_NEAR(gaussian_mean, this->blob_top_b_->cpu_data()[i],\n                gaussian_std * 10);\n  }\n  const TypeParam first_gaussian_sample = this->blob_top_b_->cpu_data()[0];\n  const TypeParam last_gaussian_sample =\n      this->blob_top_b_->cpu_data()[this->blob_top_b_->count() - 1];\n  for (int i = 0; i < this->blob_top_c_->count(); ++i) {\n    EXPECT_EQ(9, this->blob_top_c_->cpu_data()[i]);\n  }\n\n  // Do another Forward pass to fill in Blob b with Gaussian data again,\n  // checking that we get different values.\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_top_a_->count(); ++i) {\n    EXPECT_EQ(7, this->blob_top_a_->cpu_data()[i]);\n  }\n  for (int i = 0; i < this->blob_top_b_->count(); ++i) {\n    EXPECT_NEAR(gaussian_mean, this->blob_top_b_->cpu_data()[i],\n                gaussian_std * 10);\n  }\n  EXPECT_NE(first_gaussian_sample, this->blob_top_b_->cpu_data()[0]);\n  EXPECT_NE(last_gaussian_sample,\n      this->blob_top_b_->cpu_data()[this->blob_top_b_->count() - 1]);\n  for (int i = 0; i < this->blob_top_c_->count(); ++i) {\n    EXPECT_EQ(9, this->blob_top_c_->cpu_data()[i]);\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_eltwise_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass EltwiseLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  EltwiseLayerTest()\n      : blob_bottom_a_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_bottom_b_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_bottom_c_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    // fill the values\n    Caffe::set_random_seed(1701);\n    FillerParameter filler_param;\n    UniformFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_a_);\n    filler.Fill(this->blob_bottom_b_);\n    filler.Fill(this->blob_bottom_c_);\n    blob_bottom_vec_.push_back(blob_bottom_a_);\n    blob_bottom_vec_.push_back(blob_bottom_b_);\n    blob_bottom_vec_.push_back(blob_bottom_c_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~EltwiseLayerTest() {\n    delete blob_bottom_a_;\n    delete blob_bottom_b_;\n    delete blob_bottom_c_;\n    delete blob_top_;\n  }\n  Blob<Dtype>* const blob_bottom_a_;\n  Blob<Dtype>* const blob_bottom_b_;\n  Blob<Dtype>* const blob_bottom_c_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(EltwiseLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(EltwiseLayerTest, TestSetUp) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_PROD);\n  shared_ptr<EltwiseLayer<Dtype> > layer(\n      new EltwiseLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 3);\n  EXPECT_EQ(this->blob_top_->height(), 4);\n  EXPECT_EQ(this->blob_top_->width(), 5);\n}\n\nTYPED_TEST(EltwiseLayerTest, TestProd) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_PROD);\n  shared_ptr<EltwiseLayer<Dtype> > layer(\n      new EltwiseLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  const Dtype* data = this->blob_top_->cpu_data();\n  const int count = this->blob_top_->count();\n  const Dtype* in_data_a = this->blob_bottom_a_->cpu_data();\n  const Dtype* in_data_b = this->blob_bottom_b_->cpu_data();\n  const Dtype* in_data_c = this->blob_bottom_c_->cpu_data();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_EQ(data[i], in_data_a[i] * in_data_b[i] * in_data_c[i]);\n  }\n}\n\nTYPED_TEST(EltwiseLayerTest, TestSum) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_SUM);\n  shared_ptr<EltwiseLayer<Dtype> > layer(\n      new EltwiseLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  const Dtype* data = this->blob_top_->cpu_data();\n  const int count = this->blob_top_->count();\n  const Dtype* in_data_a = this->blob_bottom_a_->cpu_data();\n  const Dtype* in_data_b = this->blob_bottom_b_->cpu_data();\n  const Dtype* in_data_c = this->blob_bottom_c_->cpu_data();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_EQ(data[i], in_data_a[i] + in_data_b[i] + in_data_c[i]);\n  }\n}\n\nTYPED_TEST(EltwiseLayerTest, TestSumCoeff) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_SUM);\n  eltwise_param->add_coeff(1);\n  eltwise_param->add_coeff(-0.5);\n  eltwise_param->add_coeff(2);\n  shared_ptr<EltwiseLayer<Dtype> > layer(\n      new EltwiseLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  const Dtype* data = this->blob_top_->cpu_data();\n  const int count = this->blob_top_->count();\n  const Dtype* in_data_a = this->blob_bottom_a_->cpu_data();\n  const Dtype* in_data_b = this->blob_bottom_b_->cpu_data();\n  const Dtype* in_data_c = this->blob_bottom_c_->cpu_data();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_NEAR(data[i], in_data_a[i] - 0.5*in_data_b[i] + 2*in_data_c[i],\n        1e-4);\n  }\n}\n\nTYPED_TEST(EltwiseLayerTest, TestStableProdGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_PROD);\n  eltwise_param->set_stable_prod_grad(true);\n  EltwiseLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(EltwiseLayerTest, TestUnstableProdGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_PROD);\n  eltwise_param->set_stable_prod_grad(false);\n  EltwiseLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(EltwiseLayerTest, TestSumGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_SUM);\n  EltwiseLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(EltwiseLayerTest, TestSumCoeffGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_SUM);\n  eltwise_param->add_coeff(1);\n  eltwise_param->add_coeff(-0.5);\n  eltwise_param->add_coeff(2);\n  EltwiseLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(EltwiseLayerTest, TestMax) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_MAX);\n  shared_ptr<EltwiseLayer<Dtype> > layer(\n      new EltwiseLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  const Dtype* data = this->blob_top_->cpu_data();\n  const int count = this->blob_top_->count();\n  const Dtype* in_data_a = this->blob_bottom_a_->cpu_data();\n  const Dtype* in_data_b = this->blob_bottom_b_->cpu_data();\n  const Dtype* in_data_c = this->blob_bottom_c_->cpu_data();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_EQ(data[i],\n              std::max(in_data_a[i], std::max(in_data_b[i], in_data_c[i])));\n  }\n}\n\nTYPED_TEST(EltwiseLayerTest, TestMaxGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();\n  eltwise_param->set_operation(EltwiseParameter_EltwiseOp_MAX);\n  EltwiseLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-4, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_euclidean_loss_layer.cpp",
    "content": "#include <cmath>\n#include <cstdlib>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass EuclideanLossLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  EuclideanLossLayerTest()\n      : blob_bottom_data_(new Blob<Dtype>(10, 5, 1, 1)),\n        blob_bottom_label_(new Blob<Dtype>(10, 5, 1, 1)),\n        blob_top_loss_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_data_);\n    blob_bottom_vec_.push_back(blob_bottom_data_);\n    filler.Fill(this->blob_bottom_label_);\n    blob_bottom_vec_.push_back(blob_bottom_label_);\n    blob_top_vec_.push_back(blob_top_loss_);\n  }\n  virtual ~EuclideanLossLayerTest() {\n    delete blob_bottom_data_;\n    delete blob_bottom_label_;\n    delete blob_top_loss_;\n  }\n\n  void TestForward() {\n    // Get the loss without a specified objective weight -- should be\n    // equivalent to explicitly specifiying a weight of 1.\n    LayerParameter layer_param;\n    EuclideanLossLayer<Dtype> layer_weight_1(layer_param);\n    layer_weight_1.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    const Dtype loss_weight_1 =\n        layer_weight_1.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n\n    // Get the loss again with a different objective weight; check that it is\n    // scaled appropriately.\n    const Dtype kLossWeight = 3.7;\n    layer_param.add_loss_weight(kLossWeight);\n    EuclideanLossLayer<Dtype> layer_weight_2(layer_param);\n    layer_weight_2.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    const Dtype loss_weight_2 =\n        layer_weight_2.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    const Dtype kErrorMargin = 1e-5;\n    EXPECT_NEAR(loss_weight_1 * kLossWeight, loss_weight_2, kErrorMargin);\n    // Make sure the loss is non-trivial.\n    const Dtype kNonTrivialAbsThresh = 1e-1;\n    EXPECT_GE(fabs(loss_weight_1), kNonTrivialAbsThresh);\n  }\n\n  Blob<Dtype>* const blob_bottom_data_;\n  Blob<Dtype>* const blob_bottom_label_;\n  Blob<Dtype>* const blob_top_loss_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(EuclideanLossLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(EuclideanLossLayerTest, TestForward) {\n  this->TestForward();\n}\n\nTYPED_TEST(EuclideanLossLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  const Dtype kLossWeight = 3.7;\n  layer_param.add_loss_weight(kLossWeight);\n  EuclideanLossLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_filler.cpp",
    "content": "#include <cstring>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/filler.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nclass ConstantFillerTest : public ::testing::Test {\n protected:\n  ConstantFillerTest()\n      : blob_(new Blob<Dtype>(2, 3, 4, 5)),\n        filler_param_() {\n    filler_param_.set_value(10.);\n    filler_.reset(new ConstantFiller<Dtype>(filler_param_));\n    filler_->Fill(blob_);\n  }\n  virtual ~ConstantFillerTest() { delete blob_; }\n  Blob<Dtype>* const blob_;\n  FillerParameter filler_param_;\n  shared_ptr<ConstantFiller<Dtype> > filler_;\n};\n\nTYPED_TEST_CASE(ConstantFillerTest, TestDtypes);\n\nTYPED_TEST(ConstantFillerTest, TestFill) {\n  EXPECT_TRUE(this->blob_);\n  const int count = this->blob_->count();\n  const TypeParam* data = this->blob_->cpu_data();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_GE(data[i], this->filler_param_.value());\n  }\n}\n\n\ntemplate <typename Dtype>\nclass UniformFillerTest : public ::testing::Test {\n protected:\n  UniformFillerTest()\n      : blob_(new Blob<Dtype>(2, 3, 4, 5)),\n        filler_param_() {\n    filler_param_.set_min(1.);\n    filler_param_.set_max(2.);\n    filler_.reset(new UniformFiller<Dtype>(filler_param_));\n    filler_->Fill(blob_);\n  }\n  virtual ~UniformFillerTest() { delete blob_; }\n  Blob<Dtype>* const blob_;\n  FillerParameter filler_param_;\n  shared_ptr<UniformFiller<Dtype> > filler_;\n};\n\nTYPED_TEST_CASE(UniformFillerTest, TestDtypes);\n\nTYPED_TEST(UniformFillerTest, TestFill) {\n  EXPECT_TRUE(this->blob_);\n  const int count = this->blob_->count();\n  const TypeParam* data = this->blob_->cpu_data();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_GE(data[i], this->filler_param_.min());\n    EXPECT_LE(data[i], this->filler_param_.max());\n  }\n}\n\ntemplate <typename Dtype>\nclass PositiveUnitballFillerTest : public ::testing::Test {\n protected:\n  PositiveUnitballFillerTest()\n      : blob_(new Blob<Dtype>(2, 3, 4, 5)),\n        filler_param_() {\n    filler_.reset(new PositiveUnitballFiller<Dtype>(filler_param_));\n    filler_->Fill(blob_);\n  }\n  virtual ~PositiveUnitballFillerTest() { delete blob_; }\n  Blob<Dtype>* const blob_;\n  FillerParameter filler_param_;\n  shared_ptr<PositiveUnitballFiller<Dtype> > filler_;\n};\n\nTYPED_TEST_CASE(PositiveUnitballFillerTest, TestDtypes);\n\nTYPED_TEST(PositiveUnitballFillerTest, TestFill) {\n  EXPECT_TRUE(this->blob_);\n  const int num = this->blob_->num();\n  const int count = this->blob_->count();\n  const int dim = count / num;\n  const TypeParam* data = this->blob_->cpu_data();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_GE(data[i], 0);\n    EXPECT_LE(data[i], 1);\n  }\n  for (int i = 0; i < num; ++i) {\n    TypeParam sum = 0;\n    for (int j = 0; j < dim; ++j) {\n      sum += data[i * dim + j];\n    }\n    EXPECT_GE(sum, 0.999);\n    EXPECT_LE(sum, 1.001);\n  }\n}\n\ntemplate <typename Dtype>\nclass GaussianFillerTest : public ::testing::Test {\n protected:\n  GaussianFillerTest()\n      : blob_(new Blob<Dtype>(2, 3, 4, 5)),\n        filler_param_() {\n    filler_param_.set_mean(10.);\n    filler_param_.set_std(0.1);\n    filler_.reset(new GaussianFiller<Dtype>(filler_param_));\n    filler_->Fill(blob_);\n  }\n  virtual ~GaussianFillerTest() { delete blob_; }\n  Blob<Dtype>* const blob_;\n  FillerParameter filler_param_;\n  shared_ptr<GaussianFiller<Dtype> > filler_;\n};\n\nTYPED_TEST_CASE(GaussianFillerTest, TestDtypes);\n\nTYPED_TEST(GaussianFillerTest, TestFill) {\n  EXPECT_TRUE(this->blob_);\n  const int count = this->blob_->count();\n  const TypeParam* data = this->blob_->cpu_data();\n  TypeParam mean = 0.;\n  TypeParam var = 0.;\n  for (int i = 0; i < count; ++i) {\n    mean += data[i];\n    var += (data[i] - this->filler_param_.mean()) *\n        (data[i] - this->filler_param_.mean());\n  }\n  mean /= count;\n  var /= count;\n  // Very loose test.\n  EXPECT_GE(mean, this->filler_param_.mean() - this->filler_param_.std() * 5);\n  EXPECT_LE(mean, this->filler_param_.mean() + this->filler_param_.std() * 5);\n  TypeParam target_var = this->filler_param_.std() * this->filler_param_.std();\n  EXPECT_GE(var, target_var / 5.);\n  EXPECT_LE(var, target_var * 5.);\n}\n\ntemplate <typename Dtype>\nclass XavierFillerTest : public ::testing::Test {\n protected:\n  XavierFillerTest()\n      : blob_(new Blob<Dtype>(1000, 2, 4, 5)),\n        filler_param_() {\n  }\n  virtual void test_params(FillerParameter_VarianceNorm variance_norm,\n      Dtype n) {\n    this->filler_param_.set_variance_norm(variance_norm);\n    this->filler_.reset(new XavierFiller<Dtype>(this->filler_param_));\n    this->filler_->Fill(blob_);\n    EXPECT_TRUE(this->blob_);\n    const int count = this->blob_->count();\n    const Dtype* data = this->blob_->cpu_data();\n    Dtype mean = 0.;\n    Dtype ex2 = 0.;\n    for (int i = 0; i < count; ++i) {\n      mean += data[i];\n      ex2 += data[i] * data[i];\n    }\n    mean /= count;\n    ex2 /= count;\n    Dtype std = sqrt(ex2 - mean*mean);\n    Dtype target_std = sqrt(2.0 / n);\n    EXPECT_NEAR(mean, 0.0, 0.1);\n    EXPECT_NEAR(std, target_std, 0.1);\n  }\n  virtual ~XavierFillerTest() { delete blob_; }\n  Blob<Dtype>* const blob_;\n  FillerParameter filler_param_;\n  shared_ptr<XavierFiller<Dtype> > filler_;\n};\n\nTYPED_TEST_CASE(XavierFillerTest, TestDtypes);\n\nTYPED_TEST(XavierFillerTest, TestFillFanIn) {\n  TypeParam n = 2*4*5;\n  this->test_params(FillerParameter_VarianceNorm_FAN_IN, n);\n}\nTYPED_TEST(XavierFillerTest, TestFillFanOut) {\n  TypeParam n = 1000*4*5;\n  this->test_params(FillerParameter_VarianceNorm_FAN_OUT, n);\n}\nTYPED_TEST(XavierFillerTest, TestFillAverage) {\n  TypeParam n = (2*4*5 + 1000*4*5) / 2.0;\n  this->test_params(FillerParameter_VarianceNorm_AVERAGE, n);\n}\n\ntemplate <typename Dtype>\nclass MSRAFillerTest : public ::testing::Test {\n protected:\n  MSRAFillerTest()\n      : blob_(new Blob<Dtype>(1000, 2, 4, 5)),\n        filler_param_() {\n  }\n  virtual void test_params(FillerParameter_VarianceNorm variance_norm,\n      Dtype n) {\n    this->filler_param_.set_variance_norm(variance_norm);\n    this->filler_.reset(new MSRAFiller<Dtype>(this->filler_param_));\n    this->filler_->Fill(blob_);\n    EXPECT_TRUE(this->blob_);\n    const int count = this->blob_->count();\n    const Dtype* data = this->blob_->cpu_data();\n    Dtype mean = 0.;\n    Dtype ex2 = 0.;\n    for (int i = 0; i < count; ++i) {\n      mean += data[i];\n      ex2 += data[i] * data[i];\n    }\n    mean /= count;\n    ex2 /= count;\n    Dtype std = sqrt(ex2 - mean*mean);\n    Dtype target_std = sqrt(2.0 / n);\n    EXPECT_NEAR(mean, 0.0, 0.1);\n    EXPECT_NEAR(std, target_std, 0.1);\n  }\n  virtual ~MSRAFillerTest() { delete blob_; }\n  Blob<Dtype>* const blob_;\n  FillerParameter filler_param_;\n  shared_ptr<MSRAFiller<Dtype> > filler_;\n};\n\nTYPED_TEST_CASE(MSRAFillerTest, TestDtypes);\n\nTYPED_TEST(MSRAFillerTest, TestFillFanIn) {\n  TypeParam n = 2*4*5;\n  this->test_params(FillerParameter_VarianceNorm_FAN_IN, n);\n}\nTYPED_TEST(MSRAFillerTest, TestFillFanOut) {\n  TypeParam n = 1000*4*5;\n  this->test_params(FillerParameter_VarianceNorm_FAN_OUT, n);\n}\nTYPED_TEST(MSRAFillerTest, TestFillAverage) {\n  TypeParam n = (2*4*5 + 1000*4*5) / 2.0;\n  this->test_params(FillerParameter_VarianceNorm_AVERAGE, n);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_filter_layer.cpp",
    "content": "#include <cstring>\n#include <limits>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass FilterLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  FilterLayerTest()\n      : blob_bottom_data_(new Blob<Dtype>(4, 3, 6, 4)),\n        blob_bottom_labels_(new Blob<Dtype>(4, 1, 1, 1)),\n        blob_bottom_selector_(new Blob<Dtype>(4, 1, 1, 1)),\n        blob_top_data_(new Blob<Dtype>()),\n        blob_top_labels_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    // fill the values\n    Caffe::set_random_seed(1890);\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    // fill the selector blob\n    Dtype* bottom_data_selector_ = blob_bottom_selector_->mutable_cpu_data();\n    bottom_data_selector_[0] = 0;\n    bottom_data_selector_[1] = 1;\n    bottom_data_selector_[2] = 1;\n    bottom_data_selector_[3] = 0;\n    // fill the other bottom blobs\n    filler.Fill(blob_bottom_data_);\n    for (int i = 0; i < blob_bottom_labels_->count(); ++i) {\n      blob_bottom_labels_->mutable_cpu_data()[i] = caffe_rng_rand() % 5;\n    }\n    blob_bottom_vec_.push_back(blob_bottom_data_);\n    blob_bottom_vec_.push_back(blob_bottom_labels_);\n    blob_bottom_vec_.push_back(blob_bottom_selector_);\n    blob_top_vec_.push_back(blob_top_data_);\n    blob_top_vec_.push_back(blob_top_labels_);\n  }\n  virtual ~FilterLayerTest() {\n    delete blob_bottom_data_;\n    delete blob_bottom_labels_;\n    delete blob_bottom_selector_;\n    delete blob_top_data_;\n    delete blob_top_labels_;\n  }\n  Blob<Dtype>* const blob_bottom_data_;\n  Blob<Dtype>* const blob_bottom_labels_;\n  Blob<Dtype>* const blob_bottom_selector_;\n  // blobs for the top of FilterLayer\n  Blob<Dtype>* const blob_top_data_;\n  Blob<Dtype>* const blob_top_labels_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(FilterLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(FilterLayerTest, TestReshape) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  FilterLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Reshape(this->blob_bottom_vec_, this->blob_top_vec_);\n  // In the test first and last items should have been filtered\n  // so we just expect 2 remaining items\n  EXPECT_EQ(this->blob_top_data_->shape(0), 2);\n  EXPECT_EQ(this->blob_top_labels_->shape(0), 2);\n  EXPECT_GT(this->blob_bottom_data_->shape(0),\n      this->blob_top_data_->shape(0));\n  EXPECT_GT(this->blob_bottom_labels_->shape(0),\n      this->blob_top_labels_->shape(0));\n  for (int i = 1; i < this->blob_bottom_labels_->num_axes(); i++) {\n    EXPECT_EQ(this->blob_bottom_labels_->shape(i),\n        this->blob_top_labels_->shape(i));\n  }\n}\n\nTYPED_TEST(FilterLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  FilterLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Reshape(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_labels_->data_at(0, 0, 0, 0),\n      this->blob_bottom_labels_->data_at(1, 0, 0, 0));\n  EXPECT_EQ(this->blob_top_labels_->data_at(1, 0, 0, 0),\n      this->blob_bottom_labels_->data_at(2, 0, 0, 0));\n\n  int dim = this->blob_top_data_->count() /\n      this->blob_top_data_->shape(0);\n  const Dtype* top_data = this->blob_top_data_->cpu_data();\n  const Dtype* bottom_data = this->blob_bottom_data_->cpu_data();\n  // selector is 0 1 1 0, so we need to compare bottom(1,c,h,w)\n  // with top(0,c,h,w) and bottom(2,c,h,w) with top(1,c,h,w)\n  bottom_data += dim;  // bottom(1,c,h,w)\n  for (size_t n = 0; n < dim; n++)\n    EXPECT_EQ(top_data[n], bottom_data[n]);\n\n  bottom_data += dim;  // bottom(2,c,h,w)\n  top_data += dim;  // top(1,c,h,w)\n  for (size_t n = 0; n < dim; n++)\n    EXPECT_EQ(top_data[n], bottom_data[n]);\n}\n\nTYPED_TEST(FilterLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  FilterLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  // check only input 0 (data) because labels and selector\n  // don't need backpropagation\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_flatten_layer.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass FlattenLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  FlattenLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 6, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    Caffe::set_random_seed(1701);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~FlattenLayerTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(FlattenLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(FlattenLayerTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  FlattenLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  ASSERT_EQ(this->blob_top_->num_axes(), 2);\n  EXPECT_EQ(this->blob_top_->shape(0), 2);\n  EXPECT_EQ(this->blob_top_->shape(1), 3 * 6 * 5);\n}\n\nTYPED_TEST(FlattenLayerTest, TestSetupWithAxis) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_flatten_param()->set_axis(2);\n  FlattenLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  ASSERT_EQ(this->blob_top_->num_axes(), 3);\n  EXPECT_EQ(this->blob_top_->shape(0), 2);\n  EXPECT_EQ(this->blob_top_->shape(1), 3);\n  EXPECT_EQ(this->blob_top_->shape(2), 6 * 5);\n}\n\nTYPED_TEST(FlattenLayerTest, TestSetupWithEndAxis) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_flatten_param()->set_end_axis(-2);\n  FlattenLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  ASSERT_EQ(this->blob_top_->num_axes(), 3);\n  EXPECT_EQ(this->blob_top_->shape(0), 2);\n  EXPECT_EQ(this->blob_top_->shape(1), 3 * 6);\n  EXPECT_EQ(this->blob_top_->shape(2), 5);\n}\n\nTYPED_TEST(FlattenLayerTest, TestSetupWithStartAndEndAxis) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_flatten_param()->set_axis(0);\n  layer_param.mutable_flatten_param()->set_end_axis(-2);\n  FlattenLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  ASSERT_EQ(this->blob_top_->num_axes(), 2);\n  EXPECT_EQ(this->blob_top_->shape(0), 2 * 3 * 6);\n  EXPECT_EQ(this->blob_top_->shape(1), 5);\n}\n\nTYPED_TEST(FlattenLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  FlattenLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int c = 0; c < 3 * 6 * 5; ++c) {\n    EXPECT_EQ(this->blob_top_->data_at(0, c, 0, 0),\n        this->blob_bottom_->data_at(0, c / (6 * 5), (c / 5) % 6, c % 5));\n    EXPECT_EQ(this->blob_top_->data_at(1, c, 0, 0),\n        this->blob_bottom_->data_at(1, c / (6 * 5), (c / 5) % 6, c % 5));\n  }\n}\n\nTYPED_TEST(FlattenLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  FlattenLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_gradient_based_solver.cpp",
    "content": "#include <algorithm>\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"google/protobuf/text_format.h\"\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/parallel.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/solver.hpp\"\n#include \"caffe/util/io.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nusing std::ostringstream;\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass GradientBasedSolverTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  GradientBasedSolverTest() :\n      seed_(1701), num_(4), channels_(3), height_(10), width_(10),\n      share_(false) {\n        input_file_ = new string(\n        CMAKE_SOURCE_DIR \"caffe/test/test_data/solver_data_list.txt\" CMAKE_EXT);\n      }\n  ~GradientBasedSolverTest() {\n    delete input_file_;\n  }\n\n  string snapshot_prefix_;\n  shared_ptr<SGDSolver<Dtype> > solver_;\n  shared_ptr<P2PSync<Dtype> > sync_;\n  int seed_;\n  // Dimensions are determined by generate_sample_data.py\n  // TODO this is brittle and the hdf5 file should be checked instead.\n  int num_, channels_, height_, width_;\n  bool share_;\n  Dtype delta_;  // Stability constant for RMSProp, AdaGrad, AdaDelta and Adam\n\n  // Test data: check out generate_sample_data.py in the same directory.\n  string* input_file_;\n\n  virtual SolverParameter_SolverType solver_type() = 0;\n  virtual void InitSolver(const SolverParameter& param) = 0;\n\n  virtual void InitSolverFromProtoString(const string& proto) {\n    SolverParameter param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(proto, &param));\n    // Set the solver_mode according to current Caffe::mode.\n    switch (Caffe::mode()) {\n      case Caffe::CPU:\n        param.set_solver_mode(SolverParameter_SolverMode_CPU);\n        break;\n      case Caffe::GPU:\n        param.set_solver_mode(SolverParameter_SolverMode_GPU);\n        break;\n      default:\n        LOG(FATAL) << \"Unknown Caffe mode: \" << Caffe::mode();\n    }\n    InitSolver(param);\n    delta_ = param.delta();\n  }\n\n  string RunLeastSquaresSolver(const Dtype learning_rate,\n      const Dtype weight_decay, const Dtype momentum, const int num_iters,\n      const int iter_size = 1, const int devices = 1,\n      const bool snapshot = false, const char* from_snapshot = NULL) {\n    ostringstream proto;\n    int device_id = 0;\n#ifndef CPU_ONLY\n    if (Caffe::mode() == Caffe::GPU) {\n      CUDA_CHECK(cudaGetDevice(&device_id));\n    }\n#endif\n    proto <<\n       \"snapshot_after_train: \" << snapshot << \" \"\n       \"max_iter: \" << num_iters << \" \"\n       \"base_lr: \" << learning_rate << \" \"\n       \"lr_policy: 'fixed' \"\n       \"iter_size: \" << iter_size << \" \"\n       \"device_id: \" << device_id << \" \"\n       \"net_param { \"\n       \"  name: 'TestNetwork' \"\n       \"  layer { \"\n       \"    name: 'data' \"\n       \"    type: 'HDF5Data' \"\n       \"    hdf5_data_param { \"\n       \"      source: '\" << *(this->input_file_) << \"' \"\n       \"      batch_size: \" << num_ / iter_size << \" \"\n       \"    } \"\n       \"    top: 'data' \"\n       \"    top: 'targets' \"\n       \"  } \";\n    if (share_) {\n      proto <<\n         \"  layer { \"\n         \"    name: 'slice' \"\n         \"    type: 'Slice' \"\n         \"    bottom: 'data' \"\n         \"    top: 'data1' \"\n         \"    top: 'data2' \"\n         \"    slice_param { \"\n         \"      axis: 0 \"\n         \"    } \"\n         \"  } \";\n    }\n    proto <<\n       \"  layer { \"\n       \"    name: 'innerprod' \"\n       \"    type: 'InnerProduct' \"\n       \"    param { name: 'weights' } \"\n       \"    param { name: 'bias' } \"\n       \"    inner_product_param { \"\n       \"      num_output: 1 \"\n       \"      weight_filler { \"\n       \"        type: 'gaussian' \"\n       \"        std: 1.0 \"\n       \"      } \"\n       \"      bias_filler { \"\n       \"        type: 'gaussian' \"\n       \"        std: 1.0 \"\n       \"      } \"\n       \"    } \"\n       \"    bottom: '\" << string(share_ ? \"data1\": \"data\") << \"' \"\n       \"    top: '\" << string(share_ ? \"innerprod1\": \"innerprod\") << \"' \"\n       \"  } \";\n    if (share_) {\n      proto <<\n         \"  layer { \"\n         \"    name: 'innerprod2' \"\n         \"    type: 'InnerProduct' \"\n         \"    param { name: 'weights' } \"\n         \"    param { name: 'bias' } \"\n         \"    inner_product_param { \"\n         \"      num_output: 1 \"\n         \"      weight_filler { \"\n         \"        type: 'gaussian' \"\n         \"        std: 1.0 \"\n         \"      } \"\n         \"      bias_filler { \"\n         \"        type: 'gaussian' \"\n         \"        std: 1.0 \"\n         \"      } \"\n         \"    } \"\n         \"    bottom: 'data2' \"\n         \"    top: 'innerprod2' \"\n         \"  } \"\n         \"  layer { \"\n         \"    name: 'concat' \"\n         \"    type: 'Concat' \"\n         \"    bottom: 'innerprod1' \"\n         \"    bottom: 'innerprod2' \"\n         \"    top: 'innerprod' \"\n         \"    concat_param { \"\n         \"      axis: 0 \"\n         \"    } \"\n         \"  } \";\n    }\n    proto <<\n       \"  layer { \"\n       \"    name: 'loss' \"\n       \"    type: 'EuclideanLoss' \"\n       \"    bottom: 'innerprod' \"\n       \"    bottom: 'targets' \"\n       \"  } \"\n       \"} \";\n    if (weight_decay != 0) {\n      proto << \"weight_decay: \" << weight_decay << \" \";\n    }\n    if (momentum != 0) {\n      proto << \"momentum: \" << momentum << \" \";\n    }\n    MakeTempDir(&snapshot_prefix_);\n    proto << \"snapshot_prefix: '\" << snapshot_prefix_ << \"/' \";\n    if (snapshot) {\n      proto << \"snapshot: \" << num_iters << \" \";\n    }\n    Caffe::set_random_seed(this->seed_);\n    this->InitSolverFromProtoString(proto.str());\n    if (from_snapshot != NULL) {\n      this->solver_->Restore(from_snapshot);\n      vector<Blob<Dtype>*> empty_bottom_vec;\n      for (int i = 0; i < this->solver_->iter(); ++i) {\n        this->solver_->net()->Forward(empty_bottom_vec);\n      }\n    }\n    if (devices == 1) {\n      this->solver_->Solve();\n    } else {\n      LOG(INFO) << \"Multi-GPU test on \" << devices << \" devices\";\n      vector<int> gpus;\n      // put current device at the beginning\n      int device_id = solver_->param().device_id();\n      gpus.push_back(device_id);\n      for (int i = 0; gpus.size() < devices; ++i) {\n        if (i != device_id)\n          gpus.push_back(i);\n      }\n      Caffe::set_solver_count(gpus.size());\n      this->sync_.reset(new P2PSync<Dtype>(\n          this->solver_, NULL, this->solver_->param()));\n      this->sync_->run(gpus);\n      Caffe::set_solver_count(1);\n    }\n    if (snapshot) {\n      ostringstream resume_file;\n      resume_file << snapshot_prefix_ << \"/_iter_\" << num_iters\n                  << \".solverstate\";\n      string resume_filename = resume_file.str();\n      return resume_filename;\n    }\n    return string();\n  }\n\n  // Compute an update value given the current state of the train net,\n  // using the analytical formula for the least squares gradient.\n  // updated_params will store the updated weight and bias results,\n  // using the blobs' diffs to hold the update values themselves.\n  void ComputeLeastSquaresUpdate(const Dtype learning_rate,\n      const Dtype weight_decay, const Dtype momentum, const int num_iters,\n      vector<shared_ptr<Blob<Dtype> > >* updated_params) {\n    const int N = num_;\n    const int D = channels_ * height_ * width_;\n\n    // Run a forward pass, and manually compute the update values from the\n    // result.\n    Net<Dtype>& net = *this->solver_->net();\n    vector<Blob<Dtype>*> empty_bottom_vec;\n    net.Forward(empty_bottom_vec);\n    ASSERT_TRUE(net.has_blob(\"data\"));\n    const Blob<Dtype>& data = *net.blob_by_name(\"data\");\n    ASSERT_TRUE(net.has_blob(\"targets\"));\n    const Blob<Dtype>& targets = *net.blob_by_name(\"targets\");\n    ASSERT_TRUE(net.has_layer(\"innerprod\"));\n    const vector<shared_ptr<Blob<Dtype> > >& param_blobs =\n        net.layer_by_name(\"innerprod\")->blobs();\n    const int num_param_blobs = 2;\n    ASSERT_EQ(num_param_blobs, param_blobs.size());\n    const Blob<Dtype>& weights = *param_blobs[0];\n    const Blob<Dtype>& bias = *param_blobs[1];\n    ASSERT_EQ(D * N, data.count());\n    ASSERT_EQ(N, targets.count());\n    ASSERT_EQ(D, weights.count());\n    ASSERT_EQ(1, bias.count());\n\n    updated_params->clear();\n    updated_params->resize(num_param_blobs);\n    for (int i = 0; i < num_param_blobs; ++i) {\n      (*updated_params)[i].reset(new Blob<Dtype>());\n    }\n    Blob<Dtype>& updated_weights = *(*updated_params)[0];\n    updated_weights.ReshapeLike(weights);\n    Blob<Dtype>& updated_bias = *(*updated_params)[1];\n    updated_bias.ReshapeLike(bias);\n\n    for (int i = 0; i <= D; ++i) {\n      // Compute the derivative with respect to the ith weight (i.e., the ith\n      // element of the gradient).\n      Dtype grad = 0;\n      for (int j = 0; j <= D; ++j) {\n        // Compute element (i, j) of X^T * X.\n        Dtype element = 0;\n        for (int k = 0; k < N; ++k) {\n          // (i, k) in X^T (== (k, i) in X) times (k, j) in X.\n          const Dtype element_i = (i == D) ? 1 : data.cpu_data()[k * D + i];\n          const Dtype element_j = (j == D) ? 1 : data.cpu_data()[k * D + j];\n          element += element_i * element_j;\n        }\n        if (j == D) {\n          grad += element * bias.cpu_data()[0];\n        } else {\n          grad += element * weights.cpu_data()[j];\n        }\n      }\n      for (int k = 0; k < N; ++k) {\n        const Dtype element_i = (i == D) ? 1 : data.cpu_data()[k * D + i];\n        grad -= element_i * targets.cpu_data()[k];\n      }\n      // Scale the gradient over the N samples.\n      grad /= N;\n      // Add the weight decay to the gradient.\n      grad += weight_decay *\n          ((i == D) ? bias.cpu_data()[0] : weights.cpu_data()[i]);\n      // Finally, compute update.\n      const vector<shared_ptr<Blob<Dtype> > >& history = solver_->history();\n      if (solver_type() != SolverParameter_SolverType_ADADELTA\n          && solver_type() != SolverParameter_SolverType_ADAM) {\n        ASSERT_EQ(2, history.size());  // 1 blob for weights, 1 for bias\n      } else {\n        ASSERT_EQ(4, history.size());  // additional blobs for update history\n      }\n      Dtype update_value = learning_rate * grad;\n      const Dtype history_value = (i == D) ?\n            history[1]->cpu_data()[0] : history[0]->cpu_data()[i];\n      const Dtype temp = momentum * history_value;\n      switch (solver_type()) {\n      case SolverParameter_SolverType_SGD:\n        update_value += temp;\n        break;\n      case SolverParameter_SolverType_NESTEROV:\n        update_value += temp;\n        // step back then over-step\n        update_value = (1 + momentum) * update_value - temp;\n        break;\n      case SolverParameter_SolverType_ADAGRAD:\n        update_value /= std::sqrt(history_value + grad * grad) + delta_;\n        break;\n      case SolverParameter_SolverType_RMSPROP: {\n        const Dtype rms_decay = 0.95;\n        update_value /= std::sqrt(rms_decay*history_value\n            + grad * grad * (1 - rms_decay)) + delta_;\n        }\n        break;\n      case SolverParameter_SolverType_ADADELTA:\n      {\n        const Dtype update_history_value = (i == D) ?\n            history[1 + num_param_blobs]->cpu_data()[0] :\n            history[0 + num_param_blobs]->cpu_data()[i];\n        const Dtype weighted_gradient_average =\n            momentum * history_value + (1 - momentum) * (grad * grad);\n        update_value = grad * std::sqrt((update_history_value + delta_) /\n            (weighted_gradient_average + delta_)) * learning_rate;\n        // not actually needed, just here for illustrative purposes\n        // const Dtype weighted_update_average =\n        //   momentum * update_history_value + (1 - momentum) * (update_value);\n        break;\n      }\n      case SolverParameter_SolverType_ADAM: {\n        const Dtype momentum2 = 0.999;\n        const Dtype m = history_value;\n        const Dtype v = (i == D) ?\n            history[1 + num_param_blobs]->cpu_data()[0] :\n            history[0 + num_param_blobs]->cpu_data()[i];\n        const Dtype val_m = (1 - momentum) * grad + momentum * m;\n        const Dtype val_v = (1 - momentum2) * grad * grad + momentum2 * v;\n        Dtype alpha_t = learning_rate *\n            std::sqrt(Dtype(1) - pow(momentum2, num_iters)) /\n            (Dtype(1.) - pow(momentum, num_iters));\n        update_value = alpha_t * val_m / (std::sqrt(val_v) + delta_);\n        break;\n      }\n      default:\n        LOG(FATAL) << \"Unknown solver type: \" << solver_type();\n      }\n      if (i == D) {\n        updated_bias.mutable_cpu_diff()[0] = update_value;\n        updated_bias.mutable_cpu_data()[0] = bias.cpu_data()[0] - update_value;\n      } else {\n        updated_weights.mutable_cpu_diff()[i] = update_value;\n        updated_weights.mutable_cpu_data()[i] =\n            weights.cpu_data()[i] - update_value;\n      }\n    }\n  }\n\n  void CheckLeastSquaresUpdate(\n      const vector<shared_ptr<Blob<Dtype> > >& updated_params) {\n    const int D = channels_ * height_ * width_;\n\n    const Blob<Dtype>& updated_weights = *updated_params[0];\n    const Blob<Dtype>& updated_bias = *updated_params[1];\n\n    Net<Dtype>& net = *this->solver_->net();\n    ASSERT_TRUE(net.has_layer(\"innerprod\"));\n    const vector<shared_ptr<Blob<Dtype> > >& param_blobs =\n        net.layer_by_name(\"innerprod\")->blobs();\n    ASSERT_EQ(2, param_blobs.size());\n    const Blob<Dtype>& solver_updated_weights = *param_blobs[0];\n    ASSERT_EQ(D, solver_updated_weights.count());\n    const double kPrecision = 1e-2;\n    const double kMinPrecision = 1e-7;\n    for (int i = 0; i < D; ++i) {\n      const Dtype expected_updated_weight = updated_weights.cpu_data()[i];\n      const Dtype solver_updated_weight = solver_updated_weights.cpu_data()[i];\n      const Dtype error_margin = std::max(kMinPrecision, kPrecision *\n          std::min(fabs(expected_updated_weight), fabs(solver_updated_weight)));\n      EXPECT_NEAR(expected_updated_weight, solver_updated_weight, error_margin);\n    }\n    const Blob<Dtype>& solver_updated_bias_blob = *param_blobs[1];\n    ASSERT_EQ(1, solver_updated_bias_blob.count());\n    const Dtype expected_updated_bias = updated_bias.cpu_data()[0];\n    const Dtype solver_updated_bias = solver_updated_bias_blob.cpu_data()[0];\n    const Dtype error_margin = std::max(kMinPrecision, kPrecision *\n          std::min(fabs(expected_updated_bias), fabs(solver_updated_bias)));\n    EXPECT_NEAR(expected_updated_bias, solver_updated_bias, error_margin);\n\n    // Check the solver's history -- should contain the previous update value.\n    if (solver_type() == SolverParameter_SolverType_SGD) {\n      const vector<shared_ptr<Blob<Dtype> > >& history = solver_->history();\n      ASSERT_EQ(2, history.size());\n      for (int i = 0; i < D; ++i) {\n        const Dtype expected_history = updated_weights.cpu_diff()[i];\n        const Dtype solver_history = history[0]->cpu_data()[i];\n        const Dtype error_margin_hist = std::max(kMinPrecision, kPrecision *\n            std::min(fabs(expected_history), fabs(solver_history)));\n        EXPECT_NEAR(expected_history, solver_history, error_margin_hist);\n      }\n      const Dtype expected_history = updated_bias.cpu_diff()[0];\n      const Dtype solver_history = history[1]->cpu_data()[0];\n      const Dtype error_margin_hist = std::max(kMinPrecision, kPrecision *\n          std::min(fabs(expected_history), fabs(solver_history)));\n      EXPECT_NEAR(expected_history, solver_history, error_margin_hist);\n    }\n  }\n\n  void CheckAccumulation(const Dtype kLearningRate, const Dtype kWeightDecay,\n      const Dtype kMomentum, const int kNumIters, const int kIterSize) {\n    const double kPrecision = 1e-2;\n    const double kMinPrecision = 1e-7;\n    // Solve without accumulation and save parameters.\n    this->RunLeastSquaresSolver(kLearningRate, kWeightDecay, kMomentum,\n        kNumIters);\n    // Save parameters for comparison.\n    Net<Dtype>& net = *this->solver_->net();\n    const vector<shared_ptr<Blob<Dtype> > >& param_blobs =\n        net.layer_by_name(\"innerprod\")->blobs();\n    vector<shared_ptr<Blob<Dtype> > > noaccum_params(param_blobs.size());\n    for (int i = 0; i < param_blobs.size(); ++i) {\n      noaccum_params[i].reset(new Blob<Dtype>());\n      noaccum_params[i]->CopyFrom(*param_blobs[i], false, true);\n    }\n    // Solve by equivalent accumulation of gradients over divided batches.\n    this->RunLeastSquaresSolver(kLearningRate, kWeightDecay, kMomentum,\n        kNumIters, kIterSize);\n    Net<Dtype>& net_accum = *this->solver_->net();\n    const vector<shared_ptr<Blob<Dtype> > >& accum_params =\n        net_accum.layer_by_name(\"innerprod\")->blobs();\n    // Compare accumulated parameters against no accumulation standard.\n    const int D = this->channels_ * this->height_ * this->width_;\n    for (int i = 0; i < D; ++i) {\n      const Dtype expected_param = noaccum_params[0]->cpu_data()[i];\n      const Dtype accum_param = accum_params[0]->cpu_data()[i];\n      const Dtype error_margin = std::max(kMinPrecision, kPrecision *\n          std::min(fabs(expected_param), fabs(accum_param)));\n      EXPECT_NEAR(expected_param, accum_param, error_margin);\n    }\n    ASSERT_EQ(1, accum_params[1]->count());\n    const Dtype expected_bias = noaccum_params[1]->cpu_data()[0];\n    const Dtype accum_bias = accum_params[1]->cpu_data()[0];\n    const Dtype error_margin = std::max(kMinPrecision, kPrecision *\n        std::min(fabs(expected_bias), fabs(accum_bias)));\n    EXPECT_NEAR(expected_bias, accum_bias, error_margin);\n  }\n\n  // Test that the correct update is computed for a regularized least squares\n  // problem:\n  //\n  //            E = (1/(2n)) || X w - y ||^2 + (lambda / 2) || w ||^2\n  //   \\nabla_w E = (1/n) (X^T X w - X^T y) + lambda * w\n  //\n  // X \\in R^{n x (d+1)} (each example is a row, (d+1)th element is always 1)\n  // w \\in R^{(d+1) x 1} ((d+1)th element is the bias)\n  // y \\in R^{n x 1}\n  // lambda is weight_decay\n  //\n  // TestLeastSquaresUpdate works \"inductively\", assuming that the solver\n  // correctly updates the net K (= iter_to_check) times, then given the history\n  // from the Kth update, we compute the (K+1)th update and check that it\n  // matches the solver's (K+1)th update.\n  void TestLeastSquaresUpdate(const Dtype learning_rate = 1.0,\n      const Dtype weight_decay = 0.0, const Dtype momentum = 0.0,\n      const int iter_to_check = 0) {\n    const int kNum = num_;\n    const int kIterSize = 1;\n    // Test over all numbers of devices.\n    int available_devices = 1;\n#ifndef CPU_ONLY\n    if (Caffe::mode() == Caffe::GPU) {\n      CUDA_CHECK(cudaGetDeviceCount(&available_devices));\n    }\n#endif\n    for (int devices = 1; devices <= available_devices; ++devices) {\n      // Configure batch size for single / multi device equivalence.\n      // Constant data is needed for multi device as for accumulation.\n      num_ = kNum * devices;\n\n      // Initialize the solver and run K (= iter_to_check) solver iterations\n      // (on single device).\n      RunLeastSquaresSolver(learning_rate, weight_decay, momentum,\n                            iter_to_check, kIterSize, 1);\n\n      // Compute the (K+1)th update using the analytic least squares gradient.\n      vector<shared_ptr<Blob<Dtype> > > updated_params;\n      ComputeLeastSquaresUpdate(learning_rate, weight_decay, momentum,\n          iter_to_check + 1, &updated_params);\n\n      // Reinitialize the solver and run K+1 solver iterations.\n      num_ = kNum;\n      RunLeastSquaresSolver(learning_rate, weight_decay, momentum,\n          iter_to_check + 1, kIterSize, devices);\n\n      // Check that the solver's solution matches ours.\n      CheckLeastSquaresUpdate(updated_params);\n    }\n  }\n\n  void TestSnapshot(const Dtype learning_rate = 1.0,\n      const Dtype weight_decay = 0.0, const Dtype momentum = 0.0,\n      const int num_iters = 1) {\n    // Run the solver for num_iters * 2 iterations.\n    const int total_num_iters = num_iters * 2;\n    bool snapshot = false;\n    const int kIterSize = 1;\n    const int kDevices = 1;\n    RunLeastSquaresSolver(learning_rate, weight_decay, momentum,\n        total_num_iters, kIterSize, kDevices, snapshot);\n\n    // Save the resulting param values.\n    vector<shared_ptr<Blob<Dtype> > > param_copies;\n    const vector<Blob<Dtype>*>& orig_params =\n        solver_->net()->learnable_params();\n    param_copies.resize(orig_params.size());\n    for (int i = 0; i < orig_params.size(); ++i) {\n      param_copies[i].reset(new Blob<Dtype>());\n      const bool kReshape = true;\n      for (int copy_diff = false; copy_diff <= true; ++copy_diff) {\n        param_copies[i]->CopyFrom(*orig_params[i], copy_diff, kReshape);\n      }\n    }\n\n    // Save the solver history\n    vector<shared_ptr<Blob<Dtype> > > history_copies;\n    const vector<shared_ptr<Blob<Dtype> > >& orig_history = solver_->history();\n    history_copies.resize(orig_history.size());\n    for (int i = 0; i < orig_history.size(); ++i) {\n      history_copies[i].reset(new Blob<Dtype>());\n      const bool kReshape = true;\n      for (int copy_diff = false; copy_diff <= true; ++copy_diff) {\n        history_copies[i]->CopyFrom(*orig_history[i], copy_diff, kReshape);\n      }\n    }\n\n    // Run the solver for num_iters iterations and snapshot.\n    snapshot = true;\n    string snapshot_name = RunLeastSquaresSolver(learning_rate, weight_decay,\n        momentum, num_iters, kIterSize, kDevices, snapshot);\n\n    // Reinitialize the solver and run for num_iters more iterations.\n    snapshot = false;\n    RunLeastSquaresSolver(learning_rate, weight_decay, momentum,\n        total_num_iters, kIterSize, kDevices,\n        snapshot, snapshot_name.c_str());\n\n    // Check that params now match.\n    const vector<Blob<Dtype>*>& params = solver_->net()->learnable_params();\n    for (int i = 0; i < params.size(); ++i) {\n      for (int j = 0; j < params[i]->count(); ++j) {\n        EXPECT_EQ(param_copies[i]->cpu_data()[j], params[i]->cpu_data()[j])\n            << \"param \" << i << \" data differed at dim \" << j;\n        EXPECT_EQ(param_copies[i]->cpu_diff()[j], params[i]->cpu_diff()[j])\n            << \"param \" << i << \" diff differed at dim \" << j;\n      }\n    }\n\n    // Check that history now matches.\n    const vector<shared_ptr<Blob<Dtype> > >& history = solver_->history();\n    for (int i = 0; i < history.size(); ++i) {\n      for (int j = 0; j < history[i]->count(); ++j) {\n        EXPECT_EQ(history_copies[i]->cpu_data()[j], history[i]->cpu_data()[j])\n            << \"history blob \" << i << \" data differed at dim \" << j;\n        EXPECT_EQ(history_copies[i]->cpu_diff()[j], history[i]->cpu_diff()[j])\n            << \"history blob \" << i << \" diff differed at dim \" << j;\n      }\n    }\n  }\n};\n\n\ntemplate <typename TypeParam>\nclass SGDSolverTest : public GradientBasedSolverTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  virtual void InitSolver(const SolverParameter& param) {\n    this->solver_.reset(new SGDSolver<Dtype>(param));\n  }\n\n  virtual SolverParameter_SolverType solver_type() {\n    return SolverParameter_SolverType_SGD;\n  }\n};\n\nTYPED_TEST_CASE(SGDSolverTest, TestDtypesAndDevices);\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdate) {\n  this->TestLeastSquaresUpdate();\n}\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateLROneHundredth) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  this->TestLeastSquaresUpdate(kLearningRate);\n}\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithWeightDecay) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 1;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithWeightDecayMultiIter) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithMomentum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0;\n  const Dtype kMomentum = 0.5;\n  const int kNumIters = 1;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithMomentumMultiIter) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0;\n  const Dtype kMomentum = 0.5;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithEverything) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.5;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithEverythingShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.5;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithEverythingAccum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithEverythingAccumShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->share_ = true;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(SGDSolverTest, TestSnapshot) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(SGDSolverTest, TestSnapshotShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\n\ntemplate <typename TypeParam>\nclass AdaGradSolverTest : public GradientBasedSolverTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  virtual void InitSolver(const SolverParameter& param) {\n    this->solver_.reset(new AdaGradSolver<Dtype>(param));\n  }\n  virtual SolverParameter_SolverType solver_type() {\n    return SolverParameter_SolverType_ADAGRAD;\n  }\n};\n\nTYPED_TEST_CASE(AdaGradSolverTest, TestDtypesAndDevices);\n\nTYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdate) {\n  this->TestLeastSquaresUpdate();\n}\n\nTYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdateLROneHundredth) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  this->TestLeastSquaresUpdate(kLearningRate);\n}\n\nTYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdateWithWeightDecay) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay);\n}\n\nTYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdateWithEverything) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdaGradSolverTest,\n      TestAdaGradLeastSquaresUpdateWithEverythingShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdaGradSolverTest, TestLeastSquaresUpdateWithEverythingAccum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(AdaGradSolverTest, TestLeastSquaresUpdateWithEverythingAccumShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->share_ = true;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(AdaGradSolverTest, TestSnapshot) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdaGradSolverTest, TestSnapshotShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\n\ntemplate <typename TypeParam>\nclass NesterovSolverTest : public GradientBasedSolverTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  virtual void InitSolver(const SolverParameter& param) {\n    this->solver_.reset(new NesterovSolver<Dtype>(param));\n  }\n  virtual SolverParameter_SolverType solver_type() {\n    return SolverParameter_SolverType_NESTEROV;\n  }\n};\n\nTYPED_TEST_CASE(NesterovSolverTest, TestDtypesAndDevices);\n\nTYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdate) {\n  this->TestLeastSquaresUpdate();\n}\n\nTYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateLROneHundredth) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  this->TestLeastSquaresUpdate(kLearningRate);\n}\n\nTYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateWithWeightDecay) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay);\n}\n\nTYPED_TEST(NesterovSolverTest,\n           TestNesterovLeastSquaresUpdateWithWeightDecayMultiIter) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateWithMomentum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0;\n  const Dtype kMomentum = 0.5;\n  const int kNumIters = 1;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(NesterovSolverTest, TestLeastSquaresUpdateWithMomentumMultiIter) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0;\n  const Dtype kMomentum = 0.5;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateWithEverything) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(NesterovSolverTest,\n           TestNesterovLeastSquaresUpdateWithEverythingShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(NesterovSolverTest, TestLeastSquaresUpdateWithEverythingAccum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(NesterovSolverTest, TestLeastSquaresUpdateWithEverythingAccumShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->share_ = true;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(NesterovSolverTest, TestSnapshot) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(NesterovSolverTest, TestSnapshotShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\ntemplate <typename TypeParam>\nclass AdaDeltaSolverTest : public GradientBasedSolverTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  virtual void InitSolver(const SolverParameter& param) {\n    this->solver_.reset(new AdaDeltaSolver<Dtype>(param));\n  }\n\n  virtual SolverParameter_SolverType solver_type() {\n    return SolverParameter_SolverType_ADADELTA;\n  }\n};\n\nTYPED_TEST_CASE(AdaDeltaSolverTest, TestDtypesAndDevices);\n\nTYPED_TEST(AdaDeltaSolverTest, TestAdaDeltaLeastSquaresUpdate) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  this->TestLeastSquaresUpdate(kLearningRate);\n}\n\nTYPED_TEST(AdaDeltaSolverTest, TestAdaDeltaLeastSquaresUpdateWithWeightDecay) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.95;\n  this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum);\n}\n\nTYPED_TEST(AdaDeltaSolverTest, TestAdaDeltaLeastSquaresUpdateWithHalfMomentum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.0;\n  const Dtype kMomentum = 0.5;\n  const int kNumIters = 1;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum);\n  }\n}\n\nTYPED_TEST(AdaDeltaSolverTest, TestAdaDeltaLeastSquaresUpdateWithMomentum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.0;\n  const Dtype kMomentum = 0.95;\n  const int kNumIters = 1;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum);\n  }\n}\n\nTYPED_TEST(AdaDeltaSolverTest, TestLeastSquaresUpdateWithMomentumMultiIter) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.0;\n  const Dtype kMomentum = 0.95;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdaDeltaSolverTest, TestAdaDeltaLeastSquaresUpdateWithEverything) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.1;\n  const Dtype kMomentum = 0.95;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdaDeltaSolverTest,\n           TestAdaDeltaLeastSquaresUpdateWithEverythingShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.1;\n  const Dtype kMomentum = 0.95;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdaDeltaSolverTest, TestLeastSquaresUpdateWithEverythingAccum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.1;\n  const Dtype kMomentum = 0.95;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(AdaDeltaSolverTest, TestLeastSquaresUpdateWithEverythingAccumShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.1;\n  const Dtype kMomentum = 0.95;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->share_ = true;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(AdaDeltaSolverTest, TestSnapshot) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.1;\n  const Dtype kMomentum = 0.95;\n  const int kNumIters = 4;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdaDeltaSolverTest, TestSnapshotShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.1;\n  const Dtype kWeightDecay = 0.1;\n  const Dtype kMomentum = 0.95;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\ntemplate <typename TypeParam>\nclass AdamSolverTest : public GradientBasedSolverTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  virtual void InitSolver(const SolverParameter& param) {\n    SolverParameter new_param = param;\n    const Dtype momentum = 0.9;\n    new_param.set_momentum(momentum);\n    const Dtype momentum2 = 0.999;\n    new_param.set_momentum2(momentum2);\n    this->solver_.reset(new AdamSolver<Dtype>(new_param));\n  }\n  virtual SolverParameter_SolverType solver_type() {\n    return SolverParameter_SolverType_ADAM;\n  }\n};\n\nTYPED_TEST_CASE(AdamSolverTest, TestDtypesAndDevices);\n\nTYPED_TEST(AdamSolverTest, TestAdamLeastSquaresUpdate) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0;\n  const Dtype kMomentum = 0.9;\n  this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum);\n}\n\nTYPED_TEST(AdamSolverTest, TestAdamLeastSquaresUpdateWithWeightDecay) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum);\n}\n\nTYPED_TEST(AdamSolverTest, TestAdamLeastSquaresUpdateWithEverything) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdamSolverTest, TestAdamLeastSquaresUpdateWithEverythingShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdamSolverTest, TestLeastSquaresUpdateWithEverythingAccum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(AdamSolverTest, TestLeastSquaresUpdateWithEverythingAccumShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->share_ = true;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(AdamSolverTest, TestSnapshot) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(AdamSolverTest, TestSnapshotShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.9;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\ntemplate <typename TypeParam>\nclass RMSPropSolverTest : public GradientBasedSolverTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  virtual void InitSolver(const SolverParameter& param) {\n    const Dtype rms_decay = 0.95;\n    SolverParameter new_param = param;\n    new_param.set_rms_decay(rms_decay);\n    this->solver_.reset(new RMSPropSolver<Dtype>(new_param));\n  }\n  virtual SolverParameter_SolverType solver_type() {\n    return SolverParameter_SolverType_RMSPROP;\n  }\n};\n\nTYPED_TEST_CASE(RMSPropSolverTest, TestDtypesAndDevices);\n\nTYPED_TEST(RMSPropSolverTest, TestRMSPropLeastSquaresUpdateWithWeightDecay) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 1.0;\n  const Dtype kWeightDecay = 0.5;\n  this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay);\n}\n\nTYPED_TEST(RMSPropSolverTest, TestRMSPropLeastSquaresUpdateWithRmsDecay) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.0;\n  const Dtype kMomentum = 0.0;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(RMSPropSolverTest, TestRMSPropLeastSquaresUpdateWithEverything) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.0;\n  const int kNumIters = 4;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(RMSPropSolverTest,\n      TestRMSPropLeastSquaresUpdateWithEverythingShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.0;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 0; i <= kNumIters; ++i) {\n    this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(RMSPropSolverTest, TestLeastSquaresUpdateWithEverythingAccum) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.0;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(RMSPropSolverTest, TestLeastSquaresUpdateWithEverythingAccumShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0.0;\n  const int kNumIters = 4;\n  const int kIterSize = 2;\n  this->share_ = true;\n  this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters,\n      kIterSize);\n}\n\nTYPED_TEST(RMSPropSolverTest, TestSnapshot) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\nTYPED_TEST(RMSPropSolverTest, TestSnapshotShare) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kLearningRate = 0.01;\n  const Dtype kWeightDecay = 0.5;\n  const Dtype kMomentum = 0;\n  const int kNumIters = 4;\n  this->share_ = true;\n  for (int i = 1; i <= kNumIters; ++i) {\n    this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i);\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_hdf5_output_layer.cpp",
    "content": "#include <string>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/hdf5.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate<typename TypeParam>\nclass HDF5OutputLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  HDF5OutputLayerTest()\n      : input_file_name_(\n        CMAKE_SOURCE_DIR \"caffe/test/test_data/sample_data.h5\"),\n        blob_data_(new Blob<Dtype>()),\n        blob_label_(new Blob<Dtype>()),\n        num_(5),\n        channels_(8),\n        height_(5),\n        width_(5) {\n    MakeTempFilename(&output_file_name_);\n  }\n\n  virtual ~HDF5OutputLayerTest() {\n    delete blob_data_;\n    delete blob_label_;\n  }\n\n  void CheckBlobEqual(const Blob<Dtype>& b1, const Blob<Dtype>& b2);\n\n  string output_file_name_;\n  string input_file_name_;\n  Blob<Dtype>* const blob_data_;\n  Blob<Dtype>* const blob_label_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n  int num_;\n  int channels_;\n  int height_;\n  int width_;\n};\n\ntemplate<typename TypeParam>\nvoid HDF5OutputLayerTest<TypeParam>::CheckBlobEqual(const Blob<Dtype>& b1,\n                                                    const Blob<Dtype>& b2) {\n  EXPECT_EQ(b1.num(), b2.num());\n  EXPECT_EQ(b1.channels(), b2.channels());\n  EXPECT_EQ(b1.height(), b2.height());\n  EXPECT_EQ(b1.width(), b2.width());\n  for (int n = 0; n < b1.num(); ++n) {\n    for (int c = 0; c < b1.channels(); ++c) {\n      for (int h = 0; h < b1.height(); ++h) {\n        for (int w = 0; w < b1.width(); ++w) {\n          EXPECT_EQ(b1.data_at(n, c, h, w), b2.data_at(n, c, h, w));\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST_CASE(HDF5OutputLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(HDF5OutputLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LOG(INFO) << \"Loading HDF5 file \" << this->input_file_name_;\n  hid_t file_id = H5Fopen(this->input_file_name_.c_str(), H5F_ACC_RDONLY,\n                          H5P_DEFAULT);\n  ASSERT_GE(file_id, 0)<< \"Failed to open HDF5 file\" <<\n      this->input_file_name_;\n  hdf5_load_nd_dataset(file_id, HDF5_DATA_DATASET_NAME, 0, 4,\n                       this->blob_data_);\n  hdf5_load_nd_dataset(file_id, HDF5_DATA_LABEL_NAME, 0, 4,\n                       this->blob_label_);\n  herr_t status = H5Fclose(file_id);\n  EXPECT_GE(status, 0)<< \"Failed to close HDF5 file \" <<\n      this->input_file_name_;\n  this->blob_bottom_vec_.push_back(this->blob_data_);\n  this->blob_bottom_vec_.push_back(this->blob_label_);\n\n  LayerParameter param;\n  param.mutable_hdf5_output_param()->set_file_name(this->output_file_name_);\n  // This code block ensures that the layer is deconstructed and\n  //   the output hdf5 file is closed.\n  {\n    HDF5OutputLayer<Dtype> layer(param);\n    layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    EXPECT_EQ(layer.file_name(), this->output_file_name_);\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  }\n  file_id = H5Fopen(this->output_file_name_.c_str(), H5F_ACC_RDONLY,\n                          H5P_DEFAULT);\n  ASSERT_GE(\n    file_id, 0)<< \"Failed to open HDF5 file\" <<\n          this->input_file_name_;\n\n  Blob<Dtype>* blob_data = new Blob<Dtype>();\n  hdf5_load_nd_dataset(file_id, HDF5_DATA_DATASET_NAME, 0, 4,\n                       blob_data);\n  this->CheckBlobEqual(*(this->blob_data_), *blob_data);\n\n  Blob<Dtype>* blob_label = new Blob<Dtype>();\n  hdf5_load_nd_dataset(file_id, HDF5_DATA_LABEL_NAME, 0, 4,\n                       blob_label);\n  this->CheckBlobEqual(*(this->blob_label_), *blob_label);\n\n  status = H5Fclose(file_id);\n  EXPECT_GE(status, 0) << \"Failed to close HDF5 file \" <<\n      this->output_file_name_;\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_hdf5data_layer.cpp",
    "content": "#include <string>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass HDF5DataLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  HDF5DataLayerTest()\n      : filename(NULL),\n        blob_top_data_(new Blob<Dtype>()),\n        blob_top_label_(new Blob<Dtype>()),\n        blob_top_label2_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    blob_top_vec_.push_back(blob_top_data_);\n    blob_top_vec_.push_back(blob_top_label_);\n    blob_top_vec_.push_back(blob_top_label2_);\n\n    // Check out generate_sample_data.py in the same directory.\n    filename = new string(\n    CMAKE_SOURCE_DIR \"caffe/test/test_data/sample_data_list.txt\" CMAKE_EXT);\n    LOG(INFO)<< \"Using sample HDF5 data file \" << filename;\n  }\n\n  virtual ~HDF5DataLayerTest() {\n    delete blob_top_data_;\n    delete blob_top_label_;\n    delete blob_top_label2_;\n    delete filename;\n  }\n\n  string* filename;\n  Blob<Dtype>* const blob_top_data_;\n  Blob<Dtype>* const blob_top_label_;\n  Blob<Dtype>* const blob_top_label2_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(HDF5DataLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(HDF5DataLayerTest, TestRead) {\n  typedef typename TypeParam::Dtype Dtype;\n  // Create LayerParameter with the known parameters.\n  // The data file we are reading has 10 rows and 8 columns,\n  // with values from 0 to 10*8 reshaped in row-major order.\n  LayerParameter param;\n  param.add_top(\"data\");\n  param.add_top(\"label\");\n  param.add_top(\"label2\");\n\n  HDF5DataParameter* hdf5_data_param = param.mutable_hdf5_data_param();\n  int batch_size = 5;\n  hdf5_data_param->set_batch_size(batch_size);\n  hdf5_data_param->set_source(*(this->filename));\n  int num_cols = 8;\n  int height = 6;\n  int width = 5;\n\n  // Test that the layer setup got the correct parameters.\n  HDF5DataLayer<Dtype> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_data_->num(), batch_size);\n  EXPECT_EQ(this->blob_top_data_->channels(), num_cols);\n  EXPECT_EQ(this->blob_top_data_->height(), height);\n  EXPECT_EQ(this->blob_top_data_->width(), width);\n\n  EXPECT_EQ(this->blob_top_label_->num_axes(), 2);\n  EXPECT_EQ(this->blob_top_label_->shape(0), batch_size);\n  EXPECT_EQ(this->blob_top_label_->shape(1), 1);\n\n  EXPECT_EQ(this->blob_top_label2_->num_axes(), 2);\n  EXPECT_EQ(this->blob_top_label2_->shape(0), batch_size);\n  EXPECT_EQ(this->blob_top_label2_->shape(1), 1);\n\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  // Go through the data 10 times (5 batches).\n  const int data_size = num_cols * height * width;\n  for (int iter = 0; iter < 10; ++iter) {\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n\n    // On even iterations, we're reading the first half of the data.\n    // On odd iterations, we're reading the second half of the data.\n    // NB: label is 1-indexed\n    int label_offset = 1 + ((iter % 2 == 0) ? 0 : batch_size);\n    int label2_offset = 1 + label_offset;\n    int data_offset = (iter % 2 == 0) ? 0 : batch_size * data_size;\n\n    // Every two iterations we are reading the second file,\n    // which has the same labels, but data is offset by total data size,\n    // which is 2400 (see generate_sample_data).\n    int file_offset = (iter % 4 < 2) ? 0 : 2400;\n\n    for (int i = 0; i < batch_size; ++i) {\n      EXPECT_EQ(\n        label_offset + i,\n        this->blob_top_label_->cpu_data()[i]);\n      EXPECT_EQ(\n        label2_offset + i,\n        this->blob_top_label2_->cpu_data()[i]);\n    }\n    for (int i = 0; i < batch_size; ++i) {\n      for (int j = 0; j < num_cols; ++j) {\n        for (int h = 0; h < height; ++h) {\n          for (int w = 0; w < width; ++w) {\n            int idx = (\n              i * num_cols * height * width +\n              j * height * width +\n              h * width + w);\n            EXPECT_EQ(\n              file_offset + data_offset + idx,\n              this->blob_top_data_->cpu_data()[idx])\n              << \"debug: i \" << i << \" j \" << j\n              << \" iter \" << iter;\n          }\n        }\n      }\n    }\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_hinge_loss_layer.cpp",
    "content": "#include <cmath>\n#include <cstdlib>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass HingeLossLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  HingeLossLayerTest()\n      : blob_bottom_data_(new Blob<Dtype>(10, 5, 1, 1)),\n        blob_bottom_label_(new Blob<Dtype>(10, 1, 1, 1)),\n        blob_top_loss_(new Blob<Dtype>()) {\n    // fill the values\n    Caffe::set_random_seed(1701);\n    FillerParameter filler_param;\n    filler_param.set_std(10);\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_data_);\n    blob_bottom_vec_.push_back(blob_bottom_data_);\n    for (int i = 0; i < blob_bottom_label_->count(); ++i) {\n      blob_bottom_label_->mutable_cpu_data()[i] = caffe_rng_rand() % 5;\n    }\n    blob_bottom_vec_.push_back(blob_bottom_label_);\n    blob_top_vec_.push_back(blob_top_loss_);\n  }\n  virtual ~HingeLossLayerTest() {\n    delete blob_bottom_data_;\n    delete blob_bottom_label_;\n    delete blob_top_loss_;\n  }\n  Blob<Dtype>* const blob_bottom_data_;\n  Blob<Dtype>* const blob_bottom_label_;\n  Blob<Dtype>* const blob_top_loss_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(HingeLossLayerTest, TestDtypesAndDevices);\n\n\nTYPED_TEST(HingeLossLayerTest, TestGradientL1) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  HingeLossLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 2e-3, 1701, 1, 0.01);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n}\n\nTYPED_TEST(HingeLossLayerTest, TestGradientL2) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  // Set norm to L2\n  HingeLossParameter* hinge_loss_param = layer_param.mutable_hinge_loss_param();\n  hinge_loss_param->set_norm(HingeLossParameter_Norm_L2);\n  HingeLossLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_im2col_kernel.cu",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\n// Forward declare kernel functions\ntemplate <typename Dtype>\n__global__ void im2col_gpu_kernel(const int n, const Dtype* data_im,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w,\n    const int stride_h, const int stride_w,\n    const int height_col, const int width_col,\n    Dtype* data_col);\n\nextern cudaDeviceProp CAFFE_TEST_CUDA_PROP;\n\ntemplate <typename Dtype>\nclass Im2colKernelTest : public GPUDeviceTest<Dtype> {\n protected:\n  Im2colKernelTest()\n        // big so launches > 1024 threads\n      : blob_bottom_(new Blob<Dtype>(5, 500, 10, 10)),\n        blob_top_(new Blob<Dtype>()),\n        blob_top_cpu_(new Blob<Dtype>()) {\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n\n    height_ = blob_bottom_->height();\n    width_ = blob_bottom_->width();\n    channels_ = blob_bottom_->channels();\n    pad_ = 0;\n    stride_ = 2;\n    kernel_size_ = 3;\n    height_col_ = (height_ + 2 * pad_ - kernel_size_) / stride_ + 1;\n    width_col_ = (width_ + 2 * pad_ - kernel_size_) / stride_ + 1;\n  }\n\n  virtual ~Im2colKernelTest() {\n      delete blob_bottom_;\n      delete blob_top_;\n      delete blob_top_cpu_;\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  Blob<Dtype>* const blob_top_cpu_;\n  int height_;\n  int width_;\n  int channels_;\n  int pad_;\n  int stride_;\n  int kernel_size_;\n  int height_col_;\n  int width_col_;\n};\n\nTYPED_TEST_CASE(Im2colKernelTest, TestDtypes);\n\nTYPED_TEST(Im2colKernelTest, TestGPU) {\n  // Reshape the blobs to correct size for im2col output\n  this->blob_top_->Reshape(this->blob_bottom_->num(),\n          this->channels_ * this->kernel_size_ * this->kernel_size_,\n          this->height_col_,\n          this->width_col_);\n\n  this->blob_top_cpu_->Reshape(this->blob_bottom_->num(),\n          this->channels_ * this->kernel_size_ * this->kernel_size_,\n          this->height_col_,\n          this->width_col_);\n\n  const TypeParam* bottom_data = this->blob_bottom_->gpu_data();\n  TypeParam* top_data = this->blob_top_->mutable_gpu_data();\n  TypeParam* cpu_data = this->blob_top_cpu_->mutable_cpu_data();\n\n  // CPU Version\n  for (int n = 0; n < this->blob_bottom_->num(); ++n) {\n    im2col_cpu(this->blob_bottom_->cpu_data() + this->blob_bottom_->offset(n),\n      this->channels_, this->height_, this->width_,\n      this->kernel_size_, this->kernel_size_, this->pad_, this->pad_,\n      this->stride_, this->stride_,\n      cpu_data + this->blob_top_cpu_->offset(n));\n  }\n\n  // GPU version\n  int num_kernels = this->channels_ * this->height_col_ * this->width_col_;\n  int default_grid_dim = CAFFE_GET_BLOCKS(num_kernels);\n\n  // Launch with different grid sizes\n  for (int grid_div = 2; grid_div <= 8; grid_div++) {\n    for (int n = 0; n < this->blob_bottom_->num(); ++n) {\n      int grid_dim = default_grid_dim/grid_div;\n      // NOLINT_NEXT_LINE(whitespace/operators)\n      im2col_gpu_kernel<TypeParam><<<grid_dim, CAFFE_CUDA_NUM_THREADS>>>(\n        num_kernels, bottom_data + this->blob_bottom_->offset(n),\n        this->height_, this->width_, this->kernel_size_, this->kernel_size_,\n        this->pad_, this->pad_, this->stride_, this->stride_,\n        this->height_col_, this->width_col_,\n        top_data + this->blob_top_->offset(n));\n      CUDA_POST_KERNEL_CHECK;\n    }\n\n    // Compare results against CPU version\n    for (int i = 0; i < this->blob_top_->count(); ++i) {\n      TypeParam cpuval = cpu_data[i];\n      TypeParam gpuval = this->blob_top_->cpu_data()[i];\n      EXPECT_EQ(cpuval, gpuval);\n      if (cpuval != gpuval) {\n        break;\n      }\n    }\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_im2col_layer.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass Im2colLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  Im2colLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 6, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~Im2colLayerTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(Im2colLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(Im2colLayerTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  Im2colLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 27);\n  EXPECT_EQ(this->blob_top_->height(), 2);\n  EXPECT_EQ(this->blob_top_->width(), 2);\n}\n\nTYPED_TEST(Im2colLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  Im2colLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // We are lazy and will only check the top left block\n  for (int c = 0; c < 27; ++c) {\n    EXPECT_EQ(this->blob_bottom_->data_at(0, (c / 9), (c / 3) % 3, c % 3),\n        this->blob_top_->data_at(0, c, 0, 0));\n  }\n}\n\nTYPED_TEST(Im2colLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_size(3);\n  convolution_param->set_stride(2);\n  Im2colLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n\nTYPED_TEST(Im2colLayerTest, TestRect) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_h(5);\n  convolution_param->set_kernel_w(3);\n  convolution_param->set_stride(2);\n  Im2colLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // We are lazy and will only check the top left block\n  for (int c = 0; c < 45; ++c) {\n    EXPECT_EQ(this->blob_top_->data_at(0, c, 0, 0),\n        this->blob_bottom_->data_at(0, (c / 15), (c / 3) % 5, c % 3));\n  }\n}\n\n\nTYPED_TEST(Im2colLayerTest, TestRectGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ConvolutionParameter* convolution_param =\n      layer_param.mutable_convolution_param();\n  convolution_param->set_kernel_h(5);\n  convolution_param->set_kernel_w(3);\n  convolution_param->set_stride(2);\n  Im2colLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_image_data_layer.cpp",
    "content": "#include <map>\n#include <string>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass ImageDataLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  ImageDataLayerTest()\n      : seed_(1701),\n        blob_top_data_(new Blob<Dtype>()),\n        blob_top_label_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    blob_top_vec_.push_back(blob_top_data_);\n    blob_top_vec_.push_back(blob_top_label_);\n    Caffe::set_random_seed(seed_);\n    // Create test input file.\n    MakeTempFilename(&filename_);\n    std::ofstream outfile(filename_.c_str(), std::ofstream::out);\n    LOG(INFO) << \"Using temporary file \" << filename_;\n    for (int i = 0; i < 5; ++i) {\n      outfile << EXAMPLES_SOURCE_DIR \"images/cat.jpg \" << i;\n    }\n    outfile.close();\n    // Create test input file for images of distinct sizes.\n    MakeTempFilename(&filename_reshape_);\n    std::ofstream reshapefile(filename_reshape_.c_str(), std::ofstream::out);\n    LOG(INFO) << \"Using temporary file \" << filename_reshape_;\n    reshapefile << EXAMPLES_SOURCE_DIR \"images/cat.jpg \" << 0;\n    reshapefile << EXAMPLES_SOURCE_DIR \"images/fish-bike.jpg \" << 1;\n    reshapefile.close();\n  }\n\n  virtual ~ImageDataLayerTest() {\n    delete blob_top_data_;\n    delete blob_top_label_;\n  }\n\n  int seed_;\n  string filename_;\n  string filename_reshape_;\n  Blob<Dtype>* const blob_top_data_;\n  Blob<Dtype>* const blob_top_label_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(ImageDataLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(ImageDataLayerTest, TestRead) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter param;\n  ImageDataParameter* image_data_param = param.mutable_image_data_param();\n  image_data_param->set_batch_size(5);\n  image_data_param->set_source(this->filename_.c_str());\n  image_data_param->set_shuffle(false);\n  ImageDataLayer<Dtype> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_data_->num(), 5);\n  EXPECT_EQ(this->blob_top_data_->channels(), 3);\n  EXPECT_EQ(this->blob_top_data_->height(), 360);\n  EXPECT_EQ(this->blob_top_data_->width(), 480);\n  EXPECT_EQ(this->blob_top_label_->num(), 5);\n  EXPECT_EQ(this->blob_top_label_->channels(), 1);\n  EXPECT_EQ(this->blob_top_label_->height(), 1);\n  EXPECT_EQ(this->blob_top_label_->width(), 1);\n  // Go through the data twice\n  for (int iter = 0; iter < 2; ++iter) {\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    for (int i = 0; i < 5; ++i) {\n      EXPECT_EQ(i, this->blob_top_label_->cpu_data()[i]);\n    }\n  }\n}\n\nTYPED_TEST(ImageDataLayerTest, TestResize) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter param;\n  ImageDataParameter* image_data_param = param.mutable_image_data_param();\n  image_data_param->set_batch_size(5);\n  image_data_param->set_source(this->filename_.c_str());\n  image_data_param->set_new_height(256);\n  image_data_param->set_new_width(256);\n  image_data_param->set_shuffle(false);\n  ImageDataLayer<Dtype> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_data_->num(), 5);\n  EXPECT_EQ(this->blob_top_data_->channels(), 3);\n  EXPECT_EQ(this->blob_top_data_->height(), 256);\n  EXPECT_EQ(this->blob_top_data_->width(), 256);\n  EXPECT_EQ(this->blob_top_label_->num(), 5);\n  EXPECT_EQ(this->blob_top_label_->channels(), 1);\n  EXPECT_EQ(this->blob_top_label_->height(), 1);\n  EXPECT_EQ(this->blob_top_label_->width(), 1);\n  // Go through the data twice\n  for (int iter = 0; iter < 2; ++iter) {\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    for (int i = 0; i < 5; ++i) {\n      EXPECT_EQ(i, this->blob_top_label_->cpu_data()[i]);\n    }\n  }\n}\n\nTYPED_TEST(ImageDataLayerTest, TestReshape) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter param;\n  ImageDataParameter* image_data_param = param.mutable_image_data_param();\n  image_data_param->set_batch_size(1);\n  image_data_param->set_source(this->filename_reshape_.c_str());\n  image_data_param->set_shuffle(false);\n  ImageDataLayer<Dtype> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_label_->num(), 1);\n  EXPECT_EQ(this->blob_top_label_->channels(), 1);\n  EXPECT_EQ(this->blob_top_label_->height(), 1);\n  EXPECT_EQ(this->blob_top_label_->width(), 1);\n  // cat.jpg\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_data_->num(), 1);\n  EXPECT_EQ(this->blob_top_data_->channels(), 3);\n  EXPECT_EQ(this->blob_top_data_->height(), 360);\n  EXPECT_EQ(this->blob_top_data_->width(), 480);\n  // fish-bike.jpg\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_data_->num(), 1);\n  EXPECT_EQ(this->blob_top_data_->channels(), 3);\n  EXPECT_EQ(this->blob_top_data_->height(), 323);\n  EXPECT_EQ(this->blob_top_data_->width(), 481);\n}\n\nTYPED_TEST(ImageDataLayerTest, TestShuffle) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter param;\n  ImageDataParameter* image_data_param = param.mutable_image_data_param();\n  image_data_param->set_batch_size(5);\n  image_data_param->set_source(this->filename_.c_str());\n  image_data_param->set_shuffle(true);\n  ImageDataLayer<Dtype> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_data_->num(), 5);\n  EXPECT_EQ(this->blob_top_data_->channels(), 3);\n  EXPECT_EQ(this->blob_top_data_->height(), 360);\n  EXPECT_EQ(this->blob_top_data_->width(), 480);\n  EXPECT_EQ(this->blob_top_label_->num(), 5);\n  EXPECT_EQ(this->blob_top_label_->channels(), 1);\n  EXPECT_EQ(this->blob_top_label_->height(), 1);\n  EXPECT_EQ(this->blob_top_label_->width(), 1);\n  // Go through the data twice\n  for (int iter = 0; iter < 2; ++iter) {\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    map<Dtype, int> values_to_indices;\n    int num_in_order = 0;\n    for (int i = 0; i < 5; ++i) {\n      Dtype value = this->blob_top_label_->cpu_data()[i];\n      // Check that the value has not been seen already (no duplicates).\n      EXPECT_EQ(values_to_indices.find(value), values_to_indices.end());\n      values_to_indices[value] = i;\n      num_in_order += (value == Dtype(i));\n    }\n    EXPECT_EQ(5, values_to_indices.size());\n    EXPECT_GT(5, num_in_order);\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_infogain_loss_layer.cpp",
    "content": "#include <cmath>\n#include <cstdlib>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/loss_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass InfogainLossLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  InfogainLossLayerTest()\n      : blob_bottom_data_(new Blob<Dtype>(10, 5, 1, 1)),\n        blob_bottom_label_(new Blob<Dtype>(10, 1, 1, 1)),\n        blob_bottom_infogain_(new Blob<Dtype>(1, 1, 5, 5)),\n        blob_top_loss_(new Blob<Dtype>()) {\n    Caffe::set_random_seed(1701);\n    FillerParameter filler_param;\n    PositiveUnitballFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_data_);\n    blob_bottom_vec_.push_back(blob_bottom_data_);\n    for (int i = 0; i < blob_bottom_label_->count(); ++i) {\n      blob_bottom_label_->mutable_cpu_data()[i] = caffe_rng_rand() % 5;\n    }\n    blob_bottom_vec_.push_back(blob_bottom_label_);\n    filler_param.set_min(0.1);\n    filler_param.set_max(2.0);\n    UniformFiller<Dtype> infogain_filler(filler_param);\n    infogain_filler.Fill(this->blob_bottom_infogain_);\n    blob_bottom_vec_.push_back(blob_bottom_infogain_);\n    blob_top_vec_.push_back(blob_top_loss_);\n  }\n  virtual ~InfogainLossLayerTest() {\n    delete blob_bottom_data_;\n    delete blob_bottom_label_;\n    delete blob_bottom_infogain_;\n    delete blob_top_loss_;\n  }\n  Blob<Dtype>* const blob_bottom_data_;\n  Blob<Dtype>* const blob_bottom_label_;\n  Blob<Dtype>* const blob_bottom_infogain_;\n  Blob<Dtype>* const blob_top_loss_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(InfogainLossLayerTest, TestDtypesAndDevices);\n\n\nTYPED_TEST(InfogainLossLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  InfogainLossLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-4, 2e-2, 1701, 1, 0.01);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_inner_product_layer.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\n#ifndef CPU_ONLY\nextern cudaDeviceProp CAFFE_TEST_CUDA_PROP;\n#endif\n\ntemplate <typename TypeParam>\nclass InnerProductLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  InnerProductLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_bottom_nobatch_(new Blob<Dtype>(1, 2, 3, 4)),\n        blob_top_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    UniformFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~InnerProductLayerTest() {\n    delete blob_bottom_;\n    delete blob_bottom_nobatch_;\n    delete blob_top_;\n  }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_bottom_nobatch_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(InnerProductLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(InnerProductLayerTest, TestSetUp) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->blob_bottom_vec_.push_back(this->blob_bottom_);\n  LayerParameter layer_param;\n  InnerProductParameter* inner_product_param =\n      layer_param.mutable_inner_product_param();\n  inner_product_param->set_num_output(10);\n  shared_ptr<InnerProductLayer<Dtype> > layer(\n      new InnerProductLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->height(), 1);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n  EXPECT_EQ(this->blob_top_->channels(), 10);\n}\n\nTYPED_TEST(InnerProductLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->blob_bottom_vec_.push_back(this->blob_bottom_);\n  bool IS_VALID_CUDA = false;\n#ifndef CPU_ONLY\n  IS_VALID_CUDA = CAFFE_TEST_CUDA_PROP.major >= 2;\n#endif\n  if (Caffe::mode() == Caffe::CPU ||\n      sizeof(Dtype) == 4 || IS_VALID_CUDA) {\n    LayerParameter layer_param;\n    InnerProductParameter* inner_product_param =\n        layer_param.mutable_inner_product_param();\n    inner_product_param->set_num_output(10);\n    inner_product_param->mutable_weight_filler()->set_type(\"uniform\");\n    inner_product_param->mutable_bias_filler()->set_type(\"uniform\");\n    inner_product_param->mutable_bias_filler()->set_min(1);\n    inner_product_param->mutable_bias_filler()->set_max(2);\n    shared_ptr<InnerProductLayer<Dtype> > layer(\n        new InnerProductLayer<Dtype>(layer_param));\n    layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    const Dtype* data = this->blob_top_->cpu_data();\n    const int count = this->blob_top_->count();\n    for (int i = 0; i < count; ++i) {\n      EXPECT_GE(data[i], 1.);\n    }\n  } else {\n    LOG(ERROR) << \"Skipping test due to old architecture.\";\n  }\n}\n\nTYPED_TEST(InnerProductLayerTest, TestForwardNoBatch) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->blob_bottom_vec_.push_back(this->blob_bottom_nobatch_);\n  bool IS_VALID_CUDA = false;\n#ifndef CPU_ONLY\n  IS_VALID_CUDA = CAFFE_TEST_CUDA_PROP.major >= 2;\n#endif\n  if (Caffe::mode() == Caffe::CPU ||\n      sizeof(Dtype) == 4 || IS_VALID_CUDA) {\n    LayerParameter layer_param;\n    InnerProductParameter* inner_product_param =\n        layer_param.mutable_inner_product_param();\n    inner_product_param->set_num_output(10);\n    inner_product_param->mutable_weight_filler()->set_type(\"uniform\");\n    inner_product_param->mutable_bias_filler()->set_type(\"uniform\");\n    inner_product_param->mutable_bias_filler()->set_min(1);\n    inner_product_param->mutable_bias_filler()->set_max(2);\n    shared_ptr<InnerProductLayer<Dtype> > layer(\n        new InnerProductLayer<Dtype>(layer_param));\n    layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    const Dtype* data = this->blob_top_->cpu_data();\n    const int count = this->blob_top_->count();\n    for (int i = 0; i < count; ++i) {\n      EXPECT_GE(data[i], 1.);\n    }\n  } else {\n    LOG(ERROR) << \"Skipping test due to old architecture.\";\n  }\n}\n\nTYPED_TEST(InnerProductLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->blob_bottom_vec_.push_back(this->blob_bottom_);\n  bool IS_VALID_CUDA = false;\n#ifndef CPU_ONLY\n  IS_VALID_CUDA = CAFFE_TEST_CUDA_PROP.major >= 2;\n#endif\n  if (Caffe::mode() == Caffe::CPU ||\n      sizeof(Dtype) == 4 || IS_VALID_CUDA) {\n    LayerParameter layer_param;\n    InnerProductParameter* inner_product_param =\n        layer_param.mutable_inner_product_param();\n    inner_product_param->set_num_output(10);\n    inner_product_param->mutable_weight_filler()->set_type(\"gaussian\");\n    inner_product_param->mutable_bias_filler()->set_type(\"gaussian\");\n    inner_product_param->mutable_bias_filler()->set_min(1);\n    inner_product_param->mutable_bias_filler()->set_max(2);\n    InnerProductLayer<Dtype> layer(layer_param);\n    GradientChecker<Dtype> checker(1e-2, 1e-3);\n    checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n        this->blob_top_vec_);\n  } else {\n    LOG(ERROR) << \"Skipping test due to old architecture.\";\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_internal_thread.cpp",
    "content": "#include \"glog/logging.h\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/internal_thread.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\n\nclass InternalThreadTest : public ::testing::Test {};\n\nTEST_F(InternalThreadTest, TestStartAndExit) {\n  InternalThread thread;\n  EXPECT_FALSE(thread.is_started());\n  thread.StartInternalThread();\n  EXPECT_TRUE(thread.is_started());\n  thread.StopInternalThread();\n  EXPECT_FALSE(thread.is_started());\n}\n\nclass TestThreadA : public InternalThread {\n  void InternalThreadEntry() {\n    EXPECT_EQ(4244559767, caffe_rng_rand());\n  }\n};\n\nclass TestThreadB : public InternalThread {\n  void InternalThreadEntry() {\n    EXPECT_EQ(1726478280, caffe_rng_rand());\n  }\n};\n\nTEST_F(InternalThreadTest, TestRandomSeed) {\n  TestThreadA t1;\n  Caffe::set_random_seed(9658361);\n  t1.StartInternalThread();\n  t1.StopInternalThread();\n\n  TestThreadA t2;\n  Caffe::set_random_seed(9658361);\n  t2.StartInternalThread();\n  t2.StopInternalThread();\n\n  TestThreadB t3;\n  Caffe::set_random_seed(3435563);\n  t3.StartInternalThread();\n  t3.StopInternalThread();\n}\n\n}  // namespace caffe\n\n"
  },
  {
    "path": "src/caffe/test/test_io.cpp",
    "content": "#include <opencv2/core/core.hpp>\n#include <opencv2/highgui/highgui.hpp>\n#include <opencv2/highgui/highgui_c.h>\n#include <opencv2/imgproc/imgproc.hpp>\n\n#include <string>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/io.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nclass IOTest : public ::testing::Test {};\n\nbool ReadImageToDatumReference(const string& filename, const int label,\n    const int height, const int width, const bool is_color, Datum* datum) {\n  cv::Mat cv_img;\n  int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :\n    CV_LOAD_IMAGE_GRAYSCALE);\n\n  cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);\n  if (!cv_img_origin.data) {\n    LOG(ERROR) << \"Could not open or find file \" << filename;\n    return false;\n  }\n  if (height > 0 && width > 0) {\n    cv::resize(cv_img_origin, cv_img, cv::Size(width, height));\n  } else {\n    cv_img = cv_img_origin;\n  }\n\n  int num_channels = (is_color ? 3 : 1);\n  datum->set_channels(num_channels);\n  datum->set_height(cv_img.rows);\n  datum->set_width(cv_img.cols);\n  datum->set_label(label);\n  datum->clear_data();\n  datum->clear_float_data();\n  string* datum_string = datum->mutable_data();\n  if (is_color) {\n    for (int c = 0; c < num_channels; ++c) {\n      for (int h = 0; h < cv_img.rows; ++h) {\n        for (int w = 0; w < cv_img.cols; ++w) {\n          datum_string->push_back(\n            static_cast<char>(cv_img.at<cv::Vec3b>(h, w)[c]));\n        }\n      }\n    }\n  } else {  // Faster than repeatedly testing is_color for each pixel w/i loop\n    for (int h = 0; h < cv_img.rows; ++h) {\n      for (int w = 0; w < cv_img.cols; ++w) {\n        datum_string->push_back(\n          static_cast<char>(cv_img.at<uchar>(h, w)));\n        }\n      }\n  }\n  return true;\n}\n\nTEST_F(IOTest, TestReadImageToDatum) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  ReadImageToDatum(filename, 0, &datum);\n  EXPECT_EQ(datum.channels(), 3);\n  EXPECT_EQ(datum.height(), 360);\n  EXPECT_EQ(datum.width(), 480);\n}\n\nTEST_F(IOTest, TestReadImageToDatumReference) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum, datum_ref;\n  ReadImageToDatum(filename, 0, 0, 0, true, &datum);\n  ReadImageToDatumReference(filename, 0, 0, 0, true, &datum_ref);\n  EXPECT_EQ(datum.channels(), datum_ref.channels());\n  EXPECT_EQ(datum.height(), datum_ref.height());\n  EXPECT_EQ(datum.width(), datum_ref.width());\n  EXPECT_EQ(datum.data().size(), datum_ref.data().size());\n\n  const string& data = datum.data();\n  const string& data_ref = datum.data();\n\n  for (int i = 0; i < datum.data().size(); ++i) {\n    EXPECT_TRUE(data[i] == data_ref[i]);\n  }\n}\n\n\nTEST_F(IOTest, TestReadImageToDatumReferenceResized) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum, datum_ref;\n  ReadImageToDatum(filename, 0, 100, 200, true, &datum);\n  ReadImageToDatumReference(filename, 0, 100, 200, true, &datum_ref);\n  EXPECT_EQ(datum.channels(), datum_ref.channels());\n  EXPECT_EQ(datum.height(), datum_ref.height());\n  EXPECT_EQ(datum.width(), datum_ref.width());\n  EXPECT_EQ(datum.data().size(), datum_ref.data().size());\n\n  const string& data = datum.data();\n  const string& data_ref = datum.data();\n\n  for (int i = 0; i < datum.data().size(); ++i) {\n    EXPECT_TRUE(data[i] == data_ref[i]);\n  }\n}\n\nTEST_F(IOTest, TestReadImageToDatumContent) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  ReadImageToDatum(filename, 0, &datum);\n  cv::Mat cv_img = ReadImageToCVMat(filename);\n  EXPECT_EQ(datum.channels(), cv_img.channels());\n  EXPECT_EQ(datum.height(), cv_img.rows);\n  EXPECT_EQ(datum.width(), cv_img.cols);\n\n  const string& data = datum.data();\n  int index = 0;\n  for (int c = 0; c < datum.channels(); ++c) {\n    for (int h = 0; h < datum.height(); ++h) {\n      for (int w = 0; w < datum.width(); ++w) {\n        EXPECT_TRUE(data[index++] ==\n          static_cast<char>(cv_img.at<cv::Vec3b>(h, w)[c]));\n      }\n    }\n  }\n}\n\nTEST_F(IOTest, TestReadImageToDatumContentGray) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  const bool is_color = false;\n  ReadImageToDatum(filename, 0, is_color, &datum);\n  cv::Mat cv_img = ReadImageToCVMat(filename, is_color);\n  EXPECT_EQ(datum.channels(), cv_img.channels());\n  EXPECT_EQ(datum.height(), cv_img.rows);\n  EXPECT_EQ(datum.width(), cv_img.cols);\n\n  const string& data = datum.data();\n  int index = 0;\n  for (int h = 0; h < datum.height(); ++h) {\n    for (int w = 0; w < datum.width(); ++w) {\n      EXPECT_TRUE(data[index++] == static_cast<char>(cv_img.at<uchar>(h, w)));\n    }\n  }\n}\n\nTEST_F(IOTest, TestReadImageToDatumResized) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  ReadImageToDatum(filename, 0, 100, 200, &datum);\n  EXPECT_EQ(datum.channels(), 3);\n  EXPECT_EQ(datum.height(), 100);\n  EXPECT_EQ(datum.width(), 200);\n}\n\n\nTEST_F(IOTest, TestReadImageToDatumResizedSquare) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  ReadImageToDatum(filename, 0, 256, 256, &datum);\n  EXPECT_EQ(datum.channels(), 3);\n  EXPECT_EQ(datum.height(), 256);\n  EXPECT_EQ(datum.width(), 256);\n}\n\nTEST_F(IOTest, TestReadImageToDatumGray) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  const bool is_color = false;\n  ReadImageToDatum(filename, 0, is_color, &datum);\n  EXPECT_EQ(datum.channels(), 1);\n  EXPECT_EQ(datum.height(), 360);\n  EXPECT_EQ(datum.width(), 480);\n}\n\nTEST_F(IOTest, TestReadImageToDatumResizedGray) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  const bool is_color = false;\n  ReadImageToDatum(filename, 0, 256, 256, is_color, &datum);\n  EXPECT_EQ(datum.channels(), 1);\n  EXPECT_EQ(datum.height(), 256);\n  EXPECT_EQ(datum.width(), 256);\n}\n\nTEST_F(IOTest, TestReadImageToCVMat) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  cv::Mat cv_img = ReadImageToCVMat(filename);\n  EXPECT_EQ(cv_img.channels(), 3);\n  EXPECT_EQ(cv_img.rows, 360);\n  EXPECT_EQ(cv_img.cols, 480);\n}\n\nTEST_F(IOTest, TestReadImageToCVMatResized) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  cv::Mat cv_img = ReadImageToCVMat(filename, 100, 200);\n  EXPECT_EQ(cv_img.channels(), 3);\n  EXPECT_EQ(cv_img.rows, 100);\n  EXPECT_EQ(cv_img.cols, 200);\n}\n\nTEST_F(IOTest, TestReadImageToCVMatResizedSquare) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  cv::Mat cv_img = ReadImageToCVMat(filename, 256, 256);\n  EXPECT_EQ(cv_img.channels(), 3);\n  EXPECT_EQ(cv_img.rows, 256);\n  EXPECT_EQ(cv_img.cols, 256);\n}\n\nTEST_F(IOTest, TestReadImageToCVMatGray) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  const bool is_color = false;\n  cv::Mat cv_img = ReadImageToCVMat(filename, is_color);\n  EXPECT_EQ(cv_img.channels(), 1);\n  EXPECT_EQ(cv_img.rows, 360);\n  EXPECT_EQ(cv_img.cols, 480);\n}\n\nTEST_F(IOTest, TestReadImageToCVMatResizedGray) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  const bool is_color = false;\n  cv::Mat cv_img = ReadImageToCVMat(filename, 256, 256, is_color);\n  EXPECT_EQ(cv_img.channels(), 1);\n  EXPECT_EQ(cv_img.rows, 256);\n  EXPECT_EQ(cv_img.cols, 256);\n}\n\nTEST_F(IOTest, TestCVMatToDatum) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  cv::Mat cv_img = ReadImageToCVMat(filename);\n  Datum datum;\n  CVMatToDatum(cv_img, &datum);\n  EXPECT_EQ(datum.channels(), 3);\n  EXPECT_EQ(datum.height(), 360);\n  EXPECT_EQ(datum.width(), 480);\n}\n\nTEST_F(IOTest, TestCVMatToDatumContent) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  cv::Mat cv_img = ReadImageToCVMat(filename);\n  Datum datum;\n  CVMatToDatum(cv_img, &datum);\n  Datum datum_ref;\n  ReadImageToDatum(filename, 0, &datum_ref);\n  EXPECT_EQ(datum.channels(), datum_ref.channels());\n  EXPECT_EQ(datum.height(), datum_ref.height());\n  EXPECT_EQ(datum.width(), datum_ref.width());\n  EXPECT_EQ(datum.data().size(), datum_ref.data().size());\n\n  const string& data = datum.data();\n  const string& data_ref = datum_ref.data();\n  for (int i = 0; i < datum.data().size(); ++i) {\n    EXPECT_TRUE(data[i] == data_ref[i]);\n  }\n}\n\nTEST_F(IOTest, TestCVMatToDatumReference) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  cv::Mat cv_img = ReadImageToCVMat(filename);\n  Datum datum;\n  CVMatToDatum(cv_img, &datum);\n  Datum datum_ref;\n  ReadImageToDatumReference(filename, 0, 0, 0, true, &datum_ref);\n  EXPECT_EQ(datum.channels(), datum_ref.channels());\n  EXPECT_EQ(datum.height(), datum_ref.height());\n  EXPECT_EQ(datum.width(), datum_ref.width());\n  EXPECT_EQ(datum.data().size(), datum_ref.data().size());\n\n  const string& data = datum.data();\n  const string& data_ref = datum_ref.data();\n  for (int i = 0; i < datum.data().size(); ++i) {\n    EXPECT_TRUE(data[i] == data_ref[i]);\n  }\n}\n\nTEST_F(IOTest, TestReadFileToDatum) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  EXPECT_TRUE(ReadFileToDatum(filename, &datum));\n  EXPECT_TRUE(datum.encoded());\n  EXPECT_EQ(datum.label(), -1);\n  EXPECT_EQ(datum.data().size(), 140391);\n}\n\nTEST_F(IOTest, TestDecodeDatum) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  EXPECT_TRUE(ReadFileToDatum(filename, &datum));\n  EXPECT_TRUE(DecodeDatum(&datum, true));\n  EXPECT_FALSE(DecodeDatum(&datum, true));\n  Datum datum_ref;\n  ReadImageToDatumReference(filename, 0, 0, 0, true, &datum_ref);\n  EXPECT_EQ(datum.channels(), datum_ref.channels());\n  EXPECT_EQ(datum.height(), datum_ref.height());\n  EXPECT_EQ(datum.width(), datum_ref.width());\n  EXPECT_EQ(datum.data().size(), datum_ref.data().size());\n\n  const string& data = datum.data();\n  const string& data_ref = datum_ref.data();\n  for (int i = 0; i < datum.data().size(); ++i) {\n    EXPECT_TRUE(data[i] == data_ref[i]);\n  }\n}\n\nTEST_F(IOTest, TestDecodeDatumToCVMat) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  EXPECT_TRUE(ReadFileToDatum(filename, &datum));\n  cv::Mat cv_img = DecodeDatumToCVMat(datum, true);\n  EXPECT_EQ(cv_img.channels(), 3);\n  EXPECT_EQ(cv_img.rows, 360);\n  EXPECT_EQ(cv_img.cols, 480);\n  cv_img = DecodeDatumToCVMat(datum, false);\n  EXPECT_EQ(cv_img.channels(), 1);\n  EXPECT_EQ(cv_img.rows, 360);\n  EXPECT_EQ(cv_img.cols, 480);\n}\n\nTEST_F(IOTest, TestDecodeDatumToCVMatContent) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  EXPECT_TRUE(ReadImageToDatum(filename, 0, std::string(\"jpg\"), &datum));\n  cv::Mat cv_img = DecodeDatumToCVMat(datum, true);\n  cv::Mat cv_img_ref = ReadImageToCVMat(filename);\n  EXPECT_EQ(cv_img_ref.channels(), cv_img.channels());\n  EXPECT_EQ(cv_img_ref.rows, cv_img.rows);\n  EXPECT_EQ(cv_img_ref.cols, cv_img.cols);\n\n  for (int c = 0; c < datum.channels(); ++c) {\n    for (int h = 0; h < datum.height(); ++h) {\n      for (int w = 0; w < datum.width(); ++w) {\n        EXPECT_TRUE(cv_img.at<cv::Vec3b>(h, w)[c]==\n          cv_img_ref.at<cv::Vec3b>(h, w)[c]);\n      }\n    }\n  }\n}\n\nTEST_F(IOTest, TestDecodeDatumNative) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  EXPECT_TRUE(ReadFileToDatum(filename, &datum));\n  EXPECT_TRUE(DecodeDatumNative(&datum));\n  EXPECT_FALSE(DecodeDatumNative(&datum));\n  Datum datum_ref;\n  ReadImageToDatumReference(filename, 0, 0, 0, true, &datum_ref);\n  EXPECT_EQ(datum.channels(), datum_ref.channels());\n  EXPECT_EQ(datum.height(), datum_ref.height());\n  EXPECT_EQ(datum.width(), datum_ref.width());\n  EXPECT_EQ(datum.data().size(), datum_ref.data().size());\n\n  const string& data = datum.data();\n  const string& data_ref = datum_ref.data();\n  for (int i = 0; i < datum.data().size(); ++i) {\n    EXPECT_TRUE(data[i] == data_ref[i]);\n  }\n}\n\nTEST_F(IOTest, TestDecodeDatumToCVMatNative) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  EXPECT_TRUE(ReadFileToDatum(filename, &datum));\n  cv::Mat cv_img = DecodeDatumToCVMatNative(datum);\n  EXPECT_EQ(cv_img.channels(), 3);\n  EXPECT_EQ(cv_img.rows, 360);\n  EXPECT_EQ(cv_img.cols, 480);\n}\n\nTEST_F(IOTest, TestDecodeDatumNativeGray) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat_gray.jpg\";\n  Datum datum;\n  EXPECT_TRUE(ReadFileToDatum(filename, &datum));\n  EXPECT_TRUE(DecodeDatumNative(&datum));\n  EXPECT_FALSE(DecodeDatumNative(&datum));\n  Datum datum_ref;\n  ReadImageToDatumReference(filename, 0, 0, 0, false, &datum_ref);\n  EXPECT_EQ(datum.channels(), datum_ref.channels());\n  EXPECT_EQ(datum.height(), datum_ref.height());\n  EXPECT_EQ(datum.width(), datum_ref.width());\n  EXPECT_EQ(datum.data().size(), datum_ref.data().size());\n\n  const string& data = datum.data();\n  const string& data_ref = datum_ref.data();\n  for (int i = 0; i < datum.data().size(); ++i) {\n    EXPECT_TRUE(data[i] == data_ref[i]);\n  }\n}\n\nTEST_F(IOTest, TestDecodeDatumToCVMatNativeGray) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat_gray.jpg\";\n  Datum datum;\n  EXPECT_TRUE(ReadFileToDatum(filename, &datum));\n  cv::Mat cv_img = DecodeDatumToCVMatNative(datum);\n  EXPECT_EQ(cv_img.channels(), 1);\n  EXPECT_EQ(cv_img.rows, 360);\n  EXPECT_EQ(cv_img.cols, 480);\n}\n\nTEST_F(IOTest, TestDecodeDatumToCVMatContentNative) {\n  string filename = EXAMPLES_SOURCE_DIR \"images/cat.jpg\";\n  Datum datum;\n  EXPECT_TRUE(ReadImageToDatum(filename, 0, std::string(\"jpg\"), &datum));\n  cv::Mat cv_img = DecodeDatumToCVMatNative(datum);\n  cv::Mat cv_img_ref = ReadImageToCVMat(filename);\n  EXPECT_EQ(cv_img_ref.channels(), cv_img.channels());\n  EXPECT_EQ(cv_img_ref.rows, cv_img.rows);\n  EXPECT_EQ(cv_img_ref.cols, cv_img.cols);\n\n  for (int c = 0; c < datum.channels(); ++c) {\n    for (int h = 0; h < datum.height(); ++h) {\n      for (int w = 0; w < datum.width(); ++w) {\n        EXPECT_TRUE(cv_img.at<cv::Vec3b>(h, w)[c]==\n          cv_img_ref.at<cv::Vec3b>(h, w)[c]);\n      }\n    }\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_layer_factory.cpp",
    "content": "#include <map>\n#include <string>\n\n#include \"boost/scoped_ptr.hpp\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/layer_factory.hpp\"\n#include \"caffe/util/db.hpp\"\n#include \"caffe/util/io.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass LayerFactoryTest : public MultiDeviceTest<TypeParam> {};\n\nTYPED_TEST_CASE(LayerFactoryTest, TestDtypesAndDevices);\n\nTYPED_TEST(LayerFactoryTest, TestCreateLayer) {\n  typedef typename TypeParam::Dtype Dtype;\n  typename LayerRegistry<Dtype>::CreatorRegistry& registry =\n      LayerRegistry<Dtype>::Registry();\n  shared_ptr<Layer<Dtype> > layer;\n  for (typename LayerRegistry<Dtype>::CreatorRegistry::iterator iter =\n       registry.begin(); iter != registry.end(); ++iter) {\n    // Special case: PythonLayer is checked by pytest\n    if (iter->first == \"Python\") { continue; }\n    LayerParameter layer_param;\n    // Data layers expect a DB\n    if (iter->first == \"Data\") {\n      string tmp;\n      MakeTempDir(&tmp);\n      boost::scoped_ptr<db::DB> db(db::GetDB(DataParameter_DB_LEVELDB));\n      db->Open(tmp, db::NEW);\n      db->Close();\n      layer_param.mutable_data_param()->set_source(tmp);\n    }\n    layer_param.set_type(iter->first);\n    layer = LayerRegistry<Dtype>::CreateLayer(layer_param);\n    EXPECT_EQ(iter->first, layer->type());\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_lrn_layer.cpp",
    "content": "#include <algorithm>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nusing std::min;\nusing std::max;\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass LRNLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  LRNLayerTest()\n      : epsilon_(Dtype(1e-5)),\n        blob_bottom_(new Blob<Dtype>()),\n        blob_top_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    Caffe::set_random_seed(1701);\n    blob_bottom_->Reshape(2, 7, 3, 3);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~LRNLayerTest() { delete blob_bottom_; delete blob_top_; }\n  void ReferenceLRNForward(const Blob<Dtype>& blob_bottom,\n      const LayerParameter& layer_param, Blob<Dtype>* blob_top);\n\n  Dtype epsilon_;\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\ntemplate <typename TypeParam>\nvoid LRNLayerTest<TypeParam>::ReferenceLRNForward(\n    const Blob<Dtype>& blob_bottom, const LayerParameter& layer_param,\n    Blob<Dtype>* blob_top) {\n  typedef typename TypeParam::Dtype Dtype;\n  blob_top->Reshape(blob_bottom.num(), blob_bottom.channels(),\n      blob_bottom.height(), blob_bottom.width());\n  Dtype* top_data = blob_top->mutable_cpu_data();\n  LRNParameter lrn_param = layer_param.lrn_param();\n  Dtype alpha = lrn_param.alpha();\n  Dtype beta = lrn_param.beta();\n  int size = lrn_param.local_size();\n  switch (lrn_param.norm_region()) {\n  case LRNParameter_NormRegion_ACROSS_CHANNELS:\n    for (int n = 0; n < blob_bottom.num(); ++n) {\n      for (int c = 0; c < blob_bottom.channels(); ++c) {\n        for (int h = 0; h < blob_bottom.height(); ++h) {\n          for (int w = 0; w < blob_bottom.width(); ++w) {\n            int c_start = c - (size - 1) / 2;\n            int c_end = min(c_start + size, blob_bottom.channels());\n            c_start = max(c_start, 0);\n            Dtype scale = 1.;\n            for (int i = c_start; i < c_end; ++i) {\n              Dtype value = blob_bottom.data_at(n, i, h, w);\n              scale += value * value * alpha / size;\n            }\n            *(top_data + blob_top->offset(n, c, h, w)) =\n              blob_bottom.data_at(n, c, h, w) / pow(scale, beta);\n          }\n        }\n      }\n    }\n    break;\n  case LRNParameter_NormRegion_WITHIN_CHANNEL:\n    for (int n = 0; n < blob_bottom.num(); ++n) {\n      for (int c = 0; c < blob_bottom.channels(); ++c) {\n        for (int h = 0; h < blob_bottom.height(); ++h) {\n          int h_start = h - (size - 1) / 2;\n          int h_end = min(h_start + size, blob_bottom.height());\n          h_start = max(h_start, 0);\n          for (int w = 0; w < blob_bottom.width(); ++w) {\n            Dtype scale = 1.;\n            int w_start = w - (size - 1) / 2;\n            int w_end = min(w_start + size, blob_bottom.width());\n            w_start = max(w_start, 0);\n            for (int nh = h_start; nh < h_end; ++nh) {\n              for (int nw = w_start; nw < w_end; ++nw) {\n                Dtype value = blob_bottom.data_at(n, c, nh, nw);\n                scale += value * value * alpha / (size * size);\n              }\n            }\n            *(top_data + blob_top->offset(n, c, h, w)) =\n              blob_bottom.data_at(n, c, h, w) / pow(scale, beta);\n          }\n        }\n      }\n    }\n    break;\n  default:\n    LOG(FATAL) << \"Unknown normalization region.\";\n  }\n}\n\nTYPED_TEST_CASE(LRNLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(LRNLayerTest, TestSetupAcrossChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  LRNLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 7);\n  EXPECT_EQ(this->blob_top_->height(), 3);\n  EXPECT_EQ(this->blob_top_->width(), 3);\n}\n\nTYPED_TEST(LRNLayerTest, TestForwardAcrossChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  LRNLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  Blob<Dtype> top_reference;\n  this->ReferenceLRNForward(*(this->blob_bottom_), layer_param,\n      &top_reference);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_NEAR(this->blob_top_->cpu_data()[i], top_reference.cpu_data()[i],\n                this->epsilon_);\n  }\n}\n\nTYPED_TEST(LRNLayerTest, TestForwardAcrossChannelsLargeRegion) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_lrn_param()->set_local_size(15);\n  LRNLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  Blob<Dtype> top_reference;\n  this->ReferenceLRNForward(*(this->blob_bottom_), layer_param,\n      &top_reference);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_NEAR(this->blob_top_->cpu_data()[i], top_reference.cpu_data()[i],\n                this->epsilon_);\n  }\n}\n\nTYPED_TEST(LRNLayerTest, TestGradientAcrossChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  LRNLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    this->blob_top_->mutable_cpu_diff()[i] = 1.;\n  }\n  vector<bool> propagate_down(this->blob_bottom_vec_.size(), true);\n  layer.Backward(this->blob_top_vec_, propagate_down,\n                 this->blob_bottom_vec_);\n  // for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n  //   std::cout << \"CPU diff \" << this->blob_bottom_->cpu_diff()[i]\n  //       << std::endl;\n  // }\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(LRNLayerTest, TestGradientAcrossChannelsLargeRegion) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_lrn_param()->set_local_size(15);\n  LRNLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    this->blob_top_->mutable_cpu_diff()[i] = 1.;\n  }\n  vector<bool> propagate_down(this->blob_bottom_vec_.size(), true);\n  layer.Backward(this->blob_top_vec_, propagate_down,\n                 this->blob_bottom_vec_);\n  // for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n  //   std::cout << \"CPU diff \" << this->blob_bottom_->cpu_diff()[i]\n  //       << std::endl;\n  // }\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(LRNLayerTest, TestSetupWithinChannel) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_lrn_param()->set_norm_region(\n      LRNParameter_NormRegion_WITHIN_CHANNEL);\n  layer_param.mutable_lrn_param()->set_local_size(3);\n  LRNLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 7);\n  EXPECT_EQ(this->blob_top_->height(), 3);\n  EXPECT_EQ(this->blob_top_->width(), 3);\n}\n\nTYPED_TEST(LRNLayerTest, TestForwardWithinChannel) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_lrn_param()->set_norm_region(\n      LRNParameter_NormRegion_WITHIN_CHANNEL);\n  layer_param.mutable_lrn_param()->set_local_size(3);\n  LRNLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  Blob<Dtype> top_reference;\n  this->ReferenceLRNForward(*(this->blob_bottom_), layer_param,\n      &top_reference);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_NEAR(this->blob_top_->cpu_data()[i], top_reference.cpu_data()[i],\n                this->epsilon_);\n  }\n}\n\nTYPED_TEST(LRNLayerTest, TestGradientWithinChannel) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_lrn_param()->set_norm_region(\n      LRNParameter_NormRegion_WITHIN_CHANNEL);\n  layer_param.mutable_lrn_param()->set_local_size(3);\n  LRNLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    this->blob_top_->mutable_cpu_diff()[i] = 1.;\n  }\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_math_functions.cpp",
    "content": "#include <stdint.h>  // for uint32_t & uint64_t\n#include <time.h>\n#include <climits>\n#include <cmath>  // for std::fabs\n#include <cstdlib>  // for rand_r\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass MathFunctionsTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  MathFunctionsTest()\n      : blob_bottom_(new Blob<Dtype>()),\n        blob_top_(new Blob<Dtype>()) {\n  }\n\n  virtual void SetUp() {\n    Caffe::set_random_seed(1701);\n    this->blob_bottom_->Reshape(11, 17, 19, 23);\n    this->blob_top_->Reshape(11, 17, 19, 23);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    filler.Fill(this->blob_top_);\n  }\n\n  virtual ~MathFunctionsTest() {\n    delete blob_bottom_;\n    delete blob_top_;\n  }\n\n  // http://en.wikipedia.org/wiki/Hamming_distance\n  int ReferenceHammingDistance(const int n, const Dtype* x, const Dtype* y) {\n    int dist = 0;\n    uint64_t val;\n    for (int i = 0; i < n; ++i) {\n      if (sizeof(Dtype) == 8) {\n        val = static_cast<uint64_t>(x[i]) ^ static_cast<uint64_t>(y[i]);\n      } else if (sizeof(Dtype) == 4) {\n        val = static_cast<uint32_t>(x[i]) ^ static_cast<uint32_t>(y[i]);\n      } else {\n        LOG(FATAL) << \"Unrecognized Dtype size: \" << sizeof(Dtype);\n      }\n      // Count the number of set bits\n      while (val) {\n        ++dist;\n        val &= val - 1;\n      }\n    }\n    return dist;\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n};\n\ntemplate <typename Dtype>\nclass CPUMathFunctionsTest\n  : public MathFunctionsTest<CPUDevice<Dtype> > {\n};\n\nTYPED_TEST_CASE(CPUMathFunctionsTest, TestDtypes);\n\nTYPED_TEST(CPUMathFunctionsTest, TestNothing) {\n  // The first test case of a test suite takes the longest time\n  //   due to the set up overhead.\n}\n\nTYPED_TEST(CPUMathFunctionsTest, TestHammingDistance) {\n  int n = this->blob_bottom_->count();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  const TypeParam* y = this->blob_top_->cpu_data();\n  EXPECT_EQ(this->ReferenceHammingDistance(n, x, y),\n            caffe_cpu_hamming_distance<TypeParam>(n, x, y));\n}\n\nTYPED_TEST(CPUMathFunctionsTest, TestAsum) {\n  int n = this->blob_bottom_->count();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  TypeParam std_asum = 0;\n  for (int i = 0; i < n; ++i) {\n    std_asum += std::fabs(x[i]);\n  }\n  TypeParam cpu_asum = caffe_cpu_asum<TypeParam>(n, x);\n  EXPECT_LT((cpu_asum - std_asum) / std_asum, 1e-2);\n}\n\nTYPED_TEST(CPUMathFunctionsTest, TestSign) {\n  int n = this->blob_bottom_->count();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  caffe_cpu_sign<TypeParam>(n, x, this->blob_bottom_->mutable_cpu_diff());\n  const TypeParam* signs = this->blob_bottom_->cpu_diff();\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(signs[i], x[i] > 0 ? 1 : (x[i] < 0 ? -1 : 0));\n  }\n}\n\nTYPED_TEST(CPUMathFunctionsTest, TestSgnbit) {\n  int n = this->blob_bottom_->count();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  caffe_cpu_sgnbit<TypeParam>(n, x, this->blob_bottom_->mutable_cpu_diff());\n  const TypeParam* signbits = this->blob_bottom_->cpu_diff();\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(signbits[i], x[i] < 0 ? 1 : 0);\n  }\n}\n\nTYPED_TEST(CPUMathFunctionsTest, TestFabs) {\n  int n = this->blob_bottom_->count();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  caffe_abs<TypeParam>(n, x, this->blob_bottom_->mutable_cpu_diff());\n  const TypeParam* abs_val = this->blob_bottom_->cpu_diff();\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(abs_val[i], x[i] > 0 ? x[i] : -x[i]);\n  }\n}\n\nTYPED_TEST(CPUMathFunctionsTest, TestScale) {\n  int n = this->blob_bottom_->count();\n  TypeParam alpha = this->blob_bottom_->cpu_diff()[caffe_rng_rand() %\n                                                   this->blob_bottom_->count()];\n  caffe_cpu_scale<TypeParam>(n, alpha, this->blob_bottom_->cpu_data(),\n                             this->blob_bottom_->mutable_cpu_diff());\n  const TypeParam* scaled = this->blob_bottom_->cpu_diff();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(scaled[i], x[i] * alpha);\n  }\n}\n\nTYPED_TEST(CPUMathFunctionsTest, TestCopy) {\n  const int n = this->blob_bottom_->count();\n  const TypeParam* bottom_data = this->blob_bottom_->cpu_data();\n  TypeParam* top_data = this->blob_top_->mutable_cpu_data();\n  caffe_copy(n, bottom_data, top_data);\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(bottom_data[i], top_data[i]);\n  }\n}\n\n#ifndef CPU_ONLY\n\ntemplate <typename Dtype>\nclass GPUMathFunctionsTest : public MathFunctionsTest<GPUDevice<Dtype> > {\n};\n\nTYPED_TEST_CASE(GPUMathFunctionsTest, TestDtypes);\n\n// TODO: Fix caffe_gpu_hamming_distance and re-enable this test.\nTYPED_TEST(GPUMathFunctionsTest, DISABLED_TestHammingDistance) {\n  int n = this->blob_bottom_->count();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  const TypeParam* y = this->blob_top_->cpu_data();\n  int reference_distance = this->ReferenceHammingDistance(n, x, y);\n  x = this->blob_bottom_->gpu_data();\n  y = this->blob_top_->gpu_data();\n  int computed_distance = caffe_gpu_hamming_distance<TypeParam>(n, x, y);\n  EXPECT_EQ(reference_distance, computed_distance);\n}\n\nTYPED_TEST(GPUMathFunctionsTest, TestAsum) {\n  int n = this->blob_bottom_->count();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  TypeParam std_asum = 0;\n  for (int i = 0; i < n; ++i) {\n    std_asum += std::fabs(x[i]);\n  }\n  TypeParam gpu_asum;\n  caffe_gpu_asum<TypeParam>(n, this->blob_bottom_->gpu_data(), &gpu_asum);\n  EXPECT_LT((gpu_asum - std_asum) / std_asum, 1e-2);\n}\n\nTYPED_TEST(GPUMathFunctionsTest, TestSign) {\n  int n = this->blob_bottom_->count();\n  caffe_gpu_sign<TypeParam>(n, this->blob_bottom_->gpu_data(),\n                            this->blob_bottom_->mutable_gpu_diff());\n  const TypeParam* signs = this->blob_bottom_->cpu_diff();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(signs[i], x[i] > 0 ? 1 : (x[i] < 0 ? -1 : 0));\n  }\n}\n\nTYPED_TEST(GPUMathFunctionsTest, TestSgnbit) {\n  int n = this->blob_bottom_->count();\n  caffe_gpu_sgnbit<TypeParam>(n, this->blob_bottom_->gpu_data(),\n                            this->blob_bottom_->mutable_gpu_diff());\n  const TypeParam* signbits = this->blob_bottom_->cpu_diff();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(signbits[i], x[i] < 0 ? 1 : 0);\n  }\n}\n\nTYPED_TEST(GPUMathFunctionsTest, TestFabs) {\n  int n = this->blob_bottom_->count();\n  caffe_gpu_abs<TypeParam>(n, this->blob_bottom_->gpu_data(),\n                            this->blob_bottom_->mutable_gpu_diff());\n  const TypeParam* abs_val = this->blob_bottom_->cpu_diff();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(abs_val[i], x[i] > 0 ? x[i] : -x[i]);\n  }\n}\n\nTYPED_TEST(GPUMathFunctionsTest, TestScale) {\n  int n = this->blob_bottom_->count();\n  TypeParam alpha = this->blob_bottom_->cpu_diff()[caffe_rng_rand() %\n                                                   this->blob_bottom_->count()];\n  caffe_gpu_scale<TypeParam>(n, alpha, this->blob_bottom_->gpu_data(),\n                             this->blob_bottom_->mutable_gpu_diff());\n  const TypeParam* scaled = this->blob_bottom_->cpu_diff();\n  const TypeParam* x = this->blob_bottom_->cpu_data();\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(scaled[i], x[i] * alpha);\n  }\n}\n\nTYPED_TEST(GPUMathFunctionsTest, TestCopy) {\n  const int n = this->blob_bottom_->count();\n  const TypeParam* bottom_data = this->blob_bottom_->gpu_data();\n  TypeParam* top_data = this->blob_top_->mutable_gpu_data();\n  caffe_copy(n, bottom_data, top_data);\n  bottom_data = this->blob_bottom_->cpu_data();\n  top_data = this->blob_top_->mutable_cpu_data();\n  for (int i = 0; i < n; ++i) {\n    EXPECT_EQ(bottom_data[i], top_data[i]);\n  }\n}\n\n#endif\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_maxpool_dropout_layers.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass MaxPoolingDropoutTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  MaxPoolingDropoutTest()\n      : blob_bottom_(new Blob<Dtype>()),\n        blob_top_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    Caffe::set_random_seed(1703);\n    blob_bottom_->Reshape(2, 3, 6, 5);\n    // fill the values\n    FillerParameter filler_param;\n    filler_param.set_value(1.);\n    ConstantFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~MaxPoolingDropoutTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(MaxPoolingDropoutTest, TestDtypesAndDevices);\n\nTYPED_TEST(MaxPoolingDropoutTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  PoolingLayer<Dtype> max_layer(layer_param);\n  max_layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  DropoutLayer<Dtype> dropout_layer(layer_param);\n  dropout_layer.SetUp(this->blob_top_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), this->blob_bottom_->channels());\n  EXPECT_EQ(this->blob_top_->height(), 3);\n  EXPECT_EQ(this->blob_top_->width(), 2);\n}\n\n\nTYPED_TEST(MaxPoolingDropoutTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  PoolingLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  Dtype sum = 0.;\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    sum += top_data[i];\n  }\n  EXPECT_EQ(sum, this->blob_top_->count());\n  // Dropout in-place\n  DropoutLayer<Dtype> dropout_layer(layer_param);\n  dropout_layer.SetUp(this->blob_top_vec_, this->blob_top_vec_);\n  dropout_layer.Forward(this->blob_top_vec_, this->blob_top_vec_);\n  sum = 0.;\n  Dtype scale = 1. / (1. - layer_param.dropout_param().dropout_ratio());\n  top_data = this->blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    sum += top_data[i];\n  }\n  EXPECT_GE(sum, 0);\n  EXPECT_LE(sum, this->blob_top_->count()*scale);\n}\n\nTYPED_TEST(MaxPoolingDropoutTest, TestBackward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.set_phase(TRAIN);\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  PoolingLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    this->blob_top_->mutable_cpu_diff()[i] = 1.;\n  }\n  vector<bool> propagate_down(this->blob_bottom_vec_.size(), true);\n  layer.Backward(this->blob_top_vec_, propagate_down,\n                 this->blob_bottom_vec_);\n  const Dtype* bottom_diff = this->blob_bottom_->cpu_diff();\n  Dtype sum = 0.;\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    sum += bottom_diff[i];\n  }\n  EXPECT_EQ(sum, this->blob_top_->count());\n  // Dropout in-place\n  DropoutLayer<Dtype> dropout_layer(layer_param);\n  dropout_layer.SetUp(this->blob_top_vec_, this->blob_top_vec_);\n  dropout_layer.Forward(this->blob_top_vec_, this->blob_top_vec_);\n  dropout_layer.Backward(this->blob_top_vec_, propagate_down,\n                         this->blob_top_vec_);\n  layer.Backward(this->blob_top_vec_, propagate_down,\n                 this->blob_bottom_vec_);\n  Dtype sum_with_dropout = 0.;\n  bottom_diff = this->blob_bottom_->cpu_diff();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    sum_with_dropout += bottom_diff[i];\n  }\n  EXPECT_GE(sum_with_dropout, sum);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_memory_data_layer.cpp",
    "content": "#include <opencv2/core/core.hpp>\n\n#include <string>\n#include <vector>\n\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/filler.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass MemoryDataLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  MemoryDataLayerTest()\n    : data_(new Blob<Dtype>()),\n      labels_(new Blob<Dtype>()),\n      data_blob_(new Blob<Dtype>()),\n      label_blob_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    batch_size_ = 8;\n    batches_ = 12;\n    channels_ = 4;\n    height_ = 7;\n    width_ = 11;\n    blob_top_vec_.push_back(data_blob_);\n    blob_top_vec_.push_back(label_blob_);\n    // pick random input data\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    data_->Reshape(batches_ * batch_size_, channels_, height_, width_);\n    labels_->Reshape(batches_ * batch_size_, 1, 1, 1);\n    filler.Fill(this->data_);\n    filler.Fill(this->labels_);\n  }\n\n  virtual ~MemoryDataLayerTest() {\n    delete data_blob_;\n    delete label_blob_;\n    delete data_;\n    delete labels_;\n  }\n  int batch_size_;\n  int batches_;\n  int channels_;\n  int height_;\n  int width_;\n  // we don't really need blobs for the input data, but it makes it\n  //  easier to call Filler\n  Blob<Dtype>* const data_;\n  Blob<Dtype>* const labels_;\n  // blobs for the top of MemoryDataLayer\n  Blob<Dtype>* const data_blob_;\n  Blob<Dtype>* const label_blob_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(MemoryDataLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(MemoryDataLayerTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n\n  LayerParameter layer_param;\n  MemoryDataParameter* md_param = layer_param.mutable_memory_data_param();\n  md_param->set_batch_size(this->batch_size_);\n  md_param->set_channels(this->channels_);\n  md_param->set_height(this->height_);\n  md_param->set_width(this->width_);\n  shared_ptr<Layer<Dtype> > layer(\n      new MemoryDataLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->data_blob_->num(), this->batch_size_);\n  EXPECT_EQ(this->data_blob_->channels(), this->channels_);\n  EXPECT_EQ(this->data_blob_->height(), this->height_);\n  EXPECT_EQ(this->data_blob_->width(), this->width_);\n  EXPECT_EQ(this->label_blob_->num(), this->batch_size_);\n  EXPECT_EQ(this->label_blob_->channels(), 1);\n  EXPECT_EQ(this->label_blob_->height(), 1);\n  EXPECT_EQ(this->label_blob_->width(), 1);\n}\n\n// run through a few batches and check that the right data appears\nTYPED_TEST(MemoryDataLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n\n  LayerParameter layer_param;\n  MemoryDataParameter* md_param = layer_param.mutable_memory_data_param();\n  md_param->set_batch_size(this->batch_size_);\n  md_param->set_channels(this->channels_);\n  md_param->set_height(this->height_);\n  md_param->set_width(this->width_);\n  shared_ptr<MemoryDataLayer<Dtype> > layer(\n      new MemoryDataLayer<Dtype>(layer_param));\n  layer->DataLayerSetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Reset(this->data_->mutable_cpu_data(),\n      this->labels_->mutable_cpu_data(), this->data_->num());\n  for (int i = 0; i < this->batches_ * 6; ++i) {\n    int batch_num = i % this->batches_;\n    layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    for (int j = 0; j < this->data_blob_->count(); ++j) {\n      EXPECT_EQ(this->data_blob_->cpu_data()[j],\n          this->data_->cpu_data()[\n              this->data_->offset(1) * this->batch_size_ * batch_num + j]);\n    }\n    for (int j = 0; j < this->label_blob_->count(); ++j) {\n      EXPECT_EQ(this->label_blob_->cpu_data()[j],\n          this->labels_->cpu_data()[this->batch_size_ * batch_num + j]);\n    }\n  }\n}\n\nTYPED_TEST(MemoryDataLayerTest, AddDatumVectorDefaultTransform) {\n  typedef typename TypeParam::Dtype Dtype;\n\n  LayerParameter param;\n  MemoryDataParameter* memory_data_param = param.mutable_memory_data_param();\n  memory_data_param->set_batch_size(this->batch_size_);\n  memory_data_param->set_channels(this->channels_);\n  memory_data_param->set_height(this->height_);\n  memory_data_param->set_width(this->width_);\n  MemoryDataLayer<Dtype> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  // We add batch_size*num_iter items, then for each iteration\n  // we forward batch_size elements\n  int num_iter = 5;\n  vector<Datum> datum_vector(this->batch_size_ * num_iter);\n  const size_t count = this->channels_ * this->height_ * this->width_;\n  size_t pixel_index = 0;\n  for (int i = 0; i < this->batch_size_ * num_iter; ++i) {\n    datum_vector[i].set_channels(this->channels_);\n    datum_vector[i].set_height(this->height_);\n    datum_vector[i].set_width(this->width_);\n    datum_vector[i].set_label(i);\n    vector<char> pixels(count);\n    for (int j = 0; j < count; ++j) {\n      pixels[j] = pixel_index++ % 256;\n    }\n    datum_vector[i].set_data(&(pixels[0]), count);\n  }\n  layer.AddDatumVector(datum_vector);\n\n  int data_index;\n  // Go through the data 5 times\n  for (int iter = 0; iter < num_iter; ++iter) {\n    int offset = this->batch_size_ * iter;\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    const Dtype* data = this->data_blob_->cpu_data();\n    size_t index = 0;\n    for (int i = 0; i < this->batch_size_; ++i) {\n      const string& data_string = datum_vector[offset + i].data();\n      EXPECT_EQ(offset + i, this->label_blob_->cpu_data()[i]);\n      for (int c = 0; c < this->channels_; ++c) {\n        for (int h = 0; h < this->height_; ++h) {\n          for (int w = 0; w < this->width_; ++w) {\n            data_index = (c * this->height_ + h) * this->width_ + w;\n            EXPECT_EQ(static_cast<Dtype>(\n                static_cast<uint8_t>(data_string[data_index])),\n                      data[index++]);\n          }\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(MemoryDataLayerTest, AddMatVectorDefaultTransform) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter param;\n  MemoryDataParameter* memory_data_param = param.mutable_memory_data_param();\n  memory_data_param->set_batch_size(this->batch_size_);\n  memory_data_param->set_channels(this->channels_);\n  memory_data_param->set_height(this->height_);\n  memory_data_param->set_width(this->width_);\n  MemoryDataLayer<Dtype> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  // We add batch_size*num_iter items, then for each iteration\n  // we forward batch_size elements\n  int num_iter = 5;\n  vector<cv::Mat> mat_vector(this->batch_size_ * num_iter);\n  vector<int> label_vector(this->batch_size_ * num_iter);\n  for (int i = 0; i < this->batch_size_*num_iter; ++i) {\n    mat_vector[i] = cv::Mat(this->height_, this->width_, CV_8UC4);\n    label_vector[i] = i;\n    cv::randu(mat_vector[i], cv::Scalar::all(0), cv::Scalar::all(255));\n  }\n  layer.AddMatVector(mat_vector, label_vector);\n\n  int data_index;\n  const size_t count = this->channels_ * this->height_ * this->width_;\n  for (int iter = 0; iter < num_iter; ++iter) {\n    int offset = this->batch_size_ * iter;\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    const Dtype* data = this->data_blob_->cpu_data();\n    for (int i = 0; i < this->batch_size_; ++i) {\n      EXPECT_EQ(offset + i, this->label_blob_->cpu_data()[i]);\n      for (int h = 0; h < this->height_; ++h) {\n        const unsigned char* ptr_mat = mat_vector[offset + i].ptr<uchar>(h);\n        int index = 0;\n        for (int w = 0; w < this->width_; ++w) {\n          for (int c = 0; c < this->channels_; ++c) {\n            data_index = (i*count) + (c * this->height_ + h) * this->width_ + w;\n            Dtype pixel = static_cast<Dtype>(ptr_mat[index++]);\n            EXPECT_EQ(static_cast<int>(pixel),\n                      data[data_index]);\n          }\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(MemoryDataLayerTest, TestSetBatchSize) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter param;\n  MemoryDataParameter* memory_data_param = param.mutable_memory_data_param();\n  memory_data_param->set_batch_size(this->batch_size_);\n  memory_data_param->set_channels(this->channels_);\n  memory_data_param->set_height(this->height_);\n  memory_data_param->set_width(this->width_);\n  MemoryDataLayer<Dtype> layer(param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  // first add data as usual\n  int num_iter = 5;\n  vector<cv::Mat> mat_vector(this->batch_size_ * num_iter);\n  vector<int> label_vector(this->batch_size_ * num_iter);\n  for (int i = 0; i < this->batch_size_*num_iter; ++i) {\n    mat_vector[i] = cv::Mat(this->height_, this->width_, CV_8UC4);\n    label_vector[i] = i;\n    cv::randu(mat_vector[i], cv::Scalar::all(0), cv::Scalar::all(255));\n  }\n  layer.AddMatVector(mat_vector, label_vector);\n  // then consume the data\n  int data_index;\n  const size_t count = this->channels_ * this->height_ * this->width_;\n  for (int iter = 0; iter < num_iter; ++iter) {\n    int offset = this->batch_size_ * iter;\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    const Dtype* data = this->data_blob_->cpu_data();\n    for (int i = 0; i < this->batch_size_; ++i) {\n      EXPECT_EQ(offset + i, this->label_blob_->cpu_data()[i]);\n      for (int h = 0; h < this->height_; ++h) {\n        const unsigned char* ptr_mat = mat_vector[offset + i].ptr<uchar>(h);\n        int index = 0;\n        for (int w = 0; w < this->width_; ++w) {\n          for (int c = 0; c < this->channels_; ++c) {\n            data_index = (i*count) + (c * this->height_ + h) * this->width_ + w;\n            Dtype pixel = static_cast<Dtype>(ptr_mat[index++]);\n            EXPECT_EQ(static_cast<int>(pixel), data[data_index]);\n          }\n        }\n      }\n    }\n  }\n  // and then add new data with different batch_size\n  int new_batch_size = 16;\n  layer.set_batch_size(new_batch_size);\n  mat_vector.clear();\n  mat_vector.resize(new_batch_size * num_iter);\n  label_vector.clear();\n  label_vector.resize(new_batch_size * num_iter);\n  for (int i = 0; i < new_batch_size*num_iter; ++i) {\n    mat_vector[i] = cv::Mat(this->height_, this->width_, CV_8UC4);\n    label_vector[i] = i;\n    cv::randu(mat_vector[i], cv::Scalar::all(0), cv::Scalar::all(255));\n  }\n  layer.AddMatVector(mat_vector, label_vector);\n\n  // finally consume new data and check if everything is fine\n  for (int iter = 0; iter < num_iter; ++iter) {\n    int offset = new_batch_size * iter;\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    EXPECT_EQ(new_batch_size, this->blob_top_vec_[0]->num());\n    EXPECT_EQ(new_batch_size, this->blob_top_vec_[1]->num());\n    const Dtype* data = this->data_blob_->cpu_data();\n    for (int i = 0; i < new_batch_size; ++i) {\n      EXPECT_EQ(offset + i, this->label_blob_->cpu_data()[i]);\n      for (int h = 0; h < this->height_; ++h) {\n        const unsigned char* ptr_mat = mat_vector[offset + i].ptr<uchar>(h);\n        int index = 0;\n        for (int w = 0; w < this->width_; ++w) {\n          for (int c = 0; c < this->channels_; ++c) {\n            data_index = (i*count) + (c * this->height_ + h) * this->width_ + w;\n            Dtype pixel = static_cast<Dtype>(ptr_mat[index++]);\n            EXPECT_EQ(static_cast<int>(pixel), data[data_index]);\n          }\n        }\n      }\n    }\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_multinomial_logistic_loss_layer.cpp",
    "content": "#include <cmath>\n#include <cstdlib>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nclass MultinomialLogisticLossLayerTest : public CPUDeviceTest<Dtype> {\n protected:\n  MultinomialLogisticLossLayerTest()\n      : blob_bottom_data_(new Blob<Dtype>(10, 5, 1, 1)),\n        blob_bottom_label_(new Blob<Dtype>(10, 1, 1, 1)),\n        blob_top_loss_(new Blob<Dtype>()) {\n    Caffe::set_random_seed(1701);\n    // fill the values\n    FillerParameter filler_param;\n    PositiveUnitballFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_data_);\n    blob_bottom_vec_.push_back(blob_bottom_data_);\n    for (int i = 0; i < blob_bottom_label_->count(); ++i) {\n      blob_bottom_label_->mutable_cpu_data()[i] = caffe_rng_rand() % 5;\n    }\n    blob_bottom_vec_.push_back(blob_bottom_label_);\n    blob_top_vec_.push_back(blob_top_loss_);\n  }\n  virtual ~MultinomialLogisticLossLayerTest() {\n    delete blob_bottom_data_;\n    delete blob_bottom_label_;\n    delete blob_top_loss_;\n  }\n  Blob<Dtype>* const blob_bottom_data_;\n  Blob<Dtype>* const blob_bottom_label_;\n  Blob<Dtype>* const blob_top_loss_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(MultinomialLogisticLossLayerTest, TestDtypes);\n\n\nTYPED_TEST(MultinomialLogisticLossLayerTest, TestGradientCPU) {\n  LayerParameter layer_param;\n  MultinomialLogisticLossLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  GradientChecker<TypeParam> checker(1e-2, 2*1e-2, 1701, 0, 0.05);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_mvn_layer.cpp",
    "content": "#include <cmath>\n#include <cstring>\n#include <vector>\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/common_layers.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass MVNLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  MVNLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~MVNLayerTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(MVNLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(MVNLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  MVNLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Test mean\n  int num = this->blob_bottom_->num();\n  int channels = this->blob_bottom_->channels();\n  int height = this->blob_bottom_->height();\n  int width = this->blob_bottom_->width();\n\n  for (int i = 0; i < num; ++i) {\n    for (int j = 0; j < channels; ++j) {\n      Dtype sum = 0, var = 0;\n      for (int k = 0; k < height; ++k) {\n        for (int l = 0; l < width; ++l) {\n          Dtype data = this->blob_top_->data_at(i, j, k, l);\n          sum += data;\n          var += data * data;\n        }\n      }\n      sum /= height * width;\n      var /= height * width;\n\n      const Dtype kErrorBound = 0.001;\n      // expect zero mean\n      EXPECT_NEAR(0, sum, kErrorBound);\n      // expect unit variance\n      EXPECT_NEAR(1, var, kErrorBound);\n    }\n  }\n}\n\nTYPED_TEST(MVNLayerTest, TestForwardMeanOnly) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.ParseFromString(\"mvn_param{normalize_variance: false}\");\n  MVNLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Test mean\n  int num = this->blob_bottom_->num();\n  int channels = this->blob_bottom_->channels();\n  int height = this->blob_bottom_->height();\n  int width = this->blob_bottom_->width();\n\n  for (int i = 0; i < num; ++i) {\n    for (int j = 0; j < channels; ++j) {\n      Dtype sum = 0, var = 0;\n      for (int k = 0; k < height; ++k) {\n        for (int l = 0; l < width; ++l) {\n          Dtype data = this->blob_top_->data_at(i, j, k, l);\n          sum += data;\n          var += data * data;\n        }\n      }\n      sum /= height * width;\n\n      const Dtype kErrorBound = 0.001;\n      // expect zero mean\n      EXPECT_NEAR(0, sum, kErrorBound);\n    }\n  }\n}\n\nTYPED_TEST(MVNLayerTest, TestForwardAcrossChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.ParseFromString(\"mvn_param{across_channels: true}\");\n  MVNLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Test mean\n  int num = this->blob_bottom_->num();\n  int channels = this->blob_bottom_->channels();\n  int height = this->blob_bottom_->height();\n  int width = this->blob_bottom_->width();\n\n  for (int i = 0; i < num; ++i) {\n    Dtype sum = 0, var = 0;\n    for (int j = 0; j < channels; ++j) {\n      for (int k = 0; k < height; ++k) {\n        for (int l = 0; l < width; ++l) {\n          Dtype data = this->blob_top_->data_at(i, j, k, l);\n          sum += data;\n          var += data * data;\n        }\n      }\n    }\n    sum /= height * width * channels;\n    var /= height * width * channels;\n\n    const Dtype kErrorBound = 0.001;\n    // expect zero mean\n    EXPECT_NEAR(0, sum, kErrorBound);\n    // expect unit variance\n    EXPECT_NEAR(1, var, kErrorBound);\n  }\n}\n\nTYPED_TEST(MVNLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  MVNLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(MVNLayerTest, TestGradientMeanOnly) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.ParseFromString(\"mvn_param{normalize_variance: false}\");\n  MVNLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(MVNLayerTest, TestGradientAcrossChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.ParseFromString(\"mvn_param{across_channels: true}\");\n  MVNLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_net.cpp",
    "content": "#include <string>\n#include <utility>\n#include <vector>\n\n#include \"google/protobuf/text_format.h\"\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/net.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass NetTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  NetTest() : seed_(1701) {}\n\n  virtual void InitNetFromProtoString(const string& proto) {\n    NetParameter param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(proto, &param));\n    net_.reset(new Net<Dtype>(param));\n  }\n\n  virtual void CopyNetBlobs(const bool copy_diff,\n      vector<shared_ptr<Blob<Dtype> > >* blobs_copy) {\n    CHECK(net_);\n    const vector<shared_ptr<Blob<Dtype> > >& net_blobs = net_->blobs();\n    blobs_copy->clear();\n    blobs_copy->resize(net_blobs.size());\n    const bool kReshape = true;\n    for (int i = 0; i < net_blobs.size(); ++i) {\n      (*blobs_copy)[i].reset(new Blob<Dtype>());\n      (*blobs_copy)[i]->CopyFrom(*net_blobs[i], copy_diff, kReshape);\n    }\n  }\n\n  virtual void CopyNetParams(const bool copy_diff,\n      vector<shared_ptr<Blob<Dtype> > >* params_copy) {\n    CHECK(net_);\n    const vector<shared_ptr<Blob<Dtype> > >& net_params = net_->params();\n    params_copy->clear();\n    params_copy->resize(net_params.size());\n    const bool kReshape = true;\n    for (int i = 0; i < net_params.size(); ++i) {\n      (*params_copy)[i].reset(new Blob<Dtype>());\n      (*params_copy)[i]->CopyFrom(*net_params[i], copy_diff, kReshape);\n    }\n  }\n\n  virtual void InitTinyNet(const bool force_backward = false,\n                           const bool accuracy_layer = false) {\n    string proto =\n        \"name: 'TinyTestNetwork' \"\n        \"layer { \"\n        \"  name: 'data' \"\n        \"  type: 'DummyData' \"\n        \"  dummy_data_param { \"\n        \"    shape { \"\n        \"      dim: 5 \"\n        \"      dim: 2 \"\n        \"      dim: 3 \"\n        \"      dim: 4 \"\n        \"    } \"\n        \"    data_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"    shape { \"\n        \"      dim: 5 \"\n        \"    } \"\n        \"    data_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0 \"\n        \"    } \"\n        \"  } \"\n        \"  top: 'data' \"\n        \"  top: 'label' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 1000 \"\n        \"    weight_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"    bias_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0 \"\n        \"    } \"\n        \"  } \"\n        \"  param { \"\n        \"    lr_mult: 1 \"\n        \"    decay_mult: 1 \"\n        \"  } \"\n        \"  param { \"\n        \"    lr_mult: 2 \"\n        \"    decay_mult: 0 \"\n        \"  } \"\n        \"  bottom: 'data' \"\n        \"  top: 'innerproduct' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'loss' \"\n        \"  type: 'SoftmaxWithLoss' \"\n        \"  bottom: 'innerproduct' \"\n        \"  bottom: 'label' \"\n        \"  top: 'top_loss' \"\n        \"} \";\n    if (accuracy_layer) {\n      proto +=\n          \"layer { \"\n          \"  name: 'loss' \"\n          \"  type: 'Accuracy' \"\n          \"  bottom: 'innerproduct' \"\n          \"  bottom: 'label' \"\n          \"  top: 'accuracy' \"\n          \"} \";\n    }\n    if (force_backward) {\n      proto += \"force_backward: true \";\n    }\n    InitNetFromProtoString(proto);\n  }\n\n  virtual void InitTinyNetEuclidean(const bool force_backward = false) {\n    string proto =\n        \"name: 'TinyTestEuclidLossNetwork' \"\n        \"layer { \"\n        \"  name: 'data' \"\n        \"  type: 'DummyData' \"\n        \"  dummy_data_param { \"\n        \"    num: 5 \"\n        \"    channels: 2 \"\n        \"    height: 3 \"\n        \"    width: 4 \"\n        \"    num: 5 \"\n        \"    channels: 1 \"\n        \"    height: 1 \"\n        \"    width: 1 \"\n        \"    data_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"  } \"\n        \"  top: 'data' \"\n        \"  top: 'label' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 1 \"\n        \"    weight_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"    bias_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0 \"\n        \"    } \"\n        \"  } \"\n        \"  param { \"\n        \"    lr_mult: 1 \"\n        \"    decay_mult: 1 \"\n        \"  } \"\n        \"  param { \"\n        \"    lr_mult: 2 \"\n        \"    decay_mult: 0 \"\n        \"  } \"\n        \"  bottom: 'data' \"\n        \"  top: 'innerproduct' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'loss' \"\n        \"  type: 'EuclideanLoss' \"\n        \"  bottom: 'innerproduct' \"\n        \"  bottom: 'label' \"\n        \"} \";\n    if (force_backward) {\n      proto += \"force_backward: true \";\n    }\n    InitNetFromProtoString(proto);\n  }\n\n  virtual void InitTrickyNet(Dtype* loss_weight = NULL) {\n    ostringstream loss_weight_stream;\n    if (loss_weight) {\n      loss_weight_stream << \"  loss_weight: \" << *loss_weight << \" \";\n    }\n    const string& proto =\n        \"name: 'TrickyTestNetwork' \"\n        \"layer { \"\n        \"  name: 'data' \"\n        \"  type: 'DummyData' \"\n        \"  dummy_data_param { \"\n        \"    num: 5 \"\n        \"    channels: 2 \"\n        \"    height: 3 \"\n        \"    width: 4 \"\n        \"    num: 5 \"\n        \"    channels: 1 \"\n        \"    height: 1 \"\n        \"    width: 1 \"\n        \"    data_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"  } \"\n        \"  top: 'data' \"\n        \"  top: 'label' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 1000 \"\n        \"    weight_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"    bias_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0 \"\n        \"    } \"\n        \"  } \"\n        \"  param { \"\n        \"    lr_mult: 1 \"\n        \"    decay_mult: 1 \"\n        \"  } \"\n        \"  param { \"\n        \"    lr_mult: 2 \"\n        \"    decay_mult: 0 \"\n        \"  } \"\n        \"  bottom: 'data' \"\n        \"  top: 'transformed_data' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 1 \"\n        \"    weight_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"    bias_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0 \"\n        \"    } \"\n        \"  } \"\n        \"  param { \"\n        \"    lr_mult: 1 \"\n        \"    decay_mult: 1 \"\n        \"  } \"\n        \"  param { \"\n        \"    lr_mult: 2 \"\n        \"    decay_mult: 0 \"\n        \"  } \"\n        \"  bottom: 'label' \"\n        \"  top: 'transformed_label' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'loss' \"\n        \"  type: 'SoftmaxWithLoss' \" +\n        loss_weight_stream.str() +\n        \"  bottom: 'transformed_data' \"\n        \"  bottom: 'transformed_label' \"\n        \"} \";\n    InitNetFromProtoString(proto);\n  }\n\n  // loss_weight is the loss weight for the 'EuclideanLoss' layer output.\n  // midnet_loss_weight is the loss weight for the first 'InnerProduct' layer\n  // output.  Should both default to 0.0 if unspecified (i.e., if NULL is\n  // passed to this function).\n  virtual void InitUnsharedWeightsNet(const Dtype* loss_weight = NULL,\n      const Dtype* midnet_loss_weight = NULL,\n      const bool force_backward = false, const bool bias_term = false,\n      const Dtype blobs_lr_w1 = 1, const Dtype blobs_lr_b1 = 2,\n      const Dtype blobs_lr_w2 = 1, const Dtype blobs_lr_b2 = 2) {\n    string bias_str = bias_term ? \"true \":\"false \";\n    ostringstream proto;\n    proto << \"name: 'UnsharedWeightsNetwork' \";\n    if (force_backward) {\n      proto << \"force_backward: true \";\n    }\n    proto <<\n        \"layer { \"\n        \"  name: 'data' \"\n        \"  type: 'DummyData' \"\n        \"  dummy_data_param { \"\n        \"    num: 5 \"\n        \"    channels: 2 \"\n        \"    height: 3 \"\n        \"    width: 4 \"\n        \"    data_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"  } \"\n        \"  top: 'data' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct1' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 10 \"\n        \"    bias_term: \" << bias_str <<\n        \"    weight_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 10 \"\n        \"    } \"\n        \"  } \"\n        \"  param { \"\n        \"    name: 'unsharedweights1' \"\n        \"    lr_mult: \" << blobs_lr_w1 <<\n        \"  } \";\n    if (bias_term) {\n      proto << \"  param { lr_mult: \" << blobs_lr_b1 << \" } \";\n    }\n    proto <<\n        \"  bottom: 'data' \"\n        \"  top: 'innerproduct1' \";\n    if (midnet_loss_weight) {\n      proto << \"  loss_weight: \" << *midnet_loss_weight << \" \";\n    }\n    proto <<\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct2' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 10 \"\n        \"    bias_term: \" << bias_str <<\n        \"    weight_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 10 \"\n        \"    } \"\n        \"  } \"\n        \"  param { \"\n        \"    name: 'unsharedweights2' \"\n        \"    lr_mult: \" << blobs_lr_w2 <<\n        \"  } \";\n    if (bias_term) {\n      proto << \"  param { lr_mult: \" << blobs_lr_b2 << \" } \";\n    }\n    proto <<\n        \"  bottom: 'data' \"\n        \"  top: 'innerproduct2' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'loss' \"\n        \"  type: 'EuclideanLoss' \";\n    if (loss_weight) {\n      proto << \"  loss_weight: \" << *loss_weight << \" \";\n    }\n    proto <<\n        \"  bottom: 'innerproduct1' \"\n        \"  bottom: 'innerproduct2' \"\n        \"} \";\n    InitNetFromProtoString(proto.str());\n  }\n\n  virtual void InitSharedWeightsNet() {\n    const string& proto =\n        \"name: 'SharedWeightsNetwork' \"\n        \"layer { \"\n        \"  name: 'data' \"\n        \"  type: 'DummyData' \"\n        \"  dummy_data_param { \"\n        \"    num: 5 \"\n        \"    channels: 2 \"\n        \"    height: 3 \"\n        \"    width: 4 \"\n        \"    data_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"  } \"\n        \"  top: 'data' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct1' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 10 \"\n        \"    bias_term: false \"\n        \"    weight_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 10 \"\n        \"    } \"\n        \"  } \"\n        \"  param { name: 'sharedweights' } \"\n        \"  bottom: 'data' \"\n        \"  top: 'innerproduct1' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct2' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 10 \"\n        \"    bias_term: false \"\n        \"    weight_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 10 \"\n        \"    } \"\n        \"  } \"\n        \"  param { name: 'sharedweights' } \"\n        \"  bottom: 'data' \"\n        \"  top: 'innerproduct2' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'loss' \"\n        \"  type: 'EuclideanLoss' \"\n        \"  bottom: 'innerproduct1' \"\n        \"  bottom: 'innerproduct2' \"\n        \"} \";\n    InitNetFromProtoString(proto);\n  }\n\n  virtual void InitDiffDataUnsharedWeightsNet() {\n    const string& proto =\n        \"name: 'DiffDataUnsharedWeightsNetwork' \"\n        \"layer { \"\n        \"  name: 'data' \"\n        \"  type: 'DummyData' \"\n        \"  dummy_data_param { \"\n        \"    num: 10 \"\n        \"    channels: 10 \"\n        \"    height: 1 \"\n        \"    width: 1 \"\n        \"    num: 10 \"\n        \"    channels: 10 \"\n        \"    height: 1 \"\n        \"    width: 1 \"\n        \"    data_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 10 \"\n        \"    } \"\n        \"  } \"\n        \"  top: 'data1' \"\n        \"  top: 'data2' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct1' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 10 \"\n        \"    bias_term: false \"\n        \"    weight_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0.5 \"\n        \"    } \"\n        \"  } \"\n        \"  param { name: 'unsharedweights1' } \"\n        \"  bottom: 'data1' \"\n        \"  top: 'innerproduct1' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct2' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 10 \"\n        \"    bias_term: false \"\n        \"    weight_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0.5 \"\n        \"    } \"\n        \"  } \"\n        \"  param { name: 'unsharedweights2' } \"\n        \"  bottom: 'innerproduct1' \"\n        \"  top: 'innerproduct2' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'loss' \"\n        \"  type: 'EuclideanLoss' \"\n        \"  bottom: 'data2' \"\n        \"  bottom: 'innerproduct2' \"\n        \"} \";\n    InitNetFromProtoString(proto);\n  }\n\n  virtual void InitDiffDataSharedWeightsNet() {\n    const string& proto =\n        \"name: 'DiffDataSharedWeightsNetwork' \"\n        \"layer { \"\n        \"  name: 'data' \"\n        \"  type: 'DummyData' \"\n        \"  dummy_data_param { \"\n        \"    num: 10 \"\n        \"    channels: 10 \"\n        \"    height: 1 \"\n        \"    width: 1 \"\n        \"    num: 10 \"\n        \"    channels: 10 \"\n        \"    height: 1 \"\n        \"    width: 1 \"\n        \"    data_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 10 \"\n        \"    } \"\n        \"  } \"\n        \"  top: 'data1' \"\n        \"  top: 'data2' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct1' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 10 \"\n        \"    bias_term: false \"\n        \"    weight_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0.5 \"\n        \"    } \"\n        \"  } \"\n        \"  param { name: 'sharedweights' } \"\n        \"  bottom: 'data1' \"\n        \"  top: 'innerproduct1' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'innerproduct2' \"\n        \"  type: 'InnerProduct' \"\n        \"  inner_product_param { \"\n        \"    num_output: 10 \"\n        \"    bias_term: false \"\n        \"    weight_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0.5 \"\n        \"    } \"\n        \"  } \"\n        \"  param { name: 'sharedweights' } \"\n        \"  bottom: 'innerproduct1' \"\n        \"  top: 'innerproduct2' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'loss' \"\n        \"  type: 'EuclideanLoss' \"\n        \"  bottom: 'data2' \"\n        \"  bottom: 'innerproduct2' \"\n        \"} \";\n    InitNetFromProtoString(proto);\n  }\n\n  virtual void InitReshapableNet() {\n    const string& proto =\n        \"name: 'ReshapableNetwork' \"\n        \"input: 'data' \"\n        \"input_dim: 1 \"\n        \"input_dim: 3 \"\n        \"input_dim: 100 \"\n        \"input_dim: 100 \"\n        \"layer { \"\n        \"  name: 'conv1' \"\n        \"  type: 'Convolution' \"\n        \"  bottom: 'data' \"\n        \"  top: 'conv1' \"\n        \"  convolution_param { \"\n        \"    num_output: 5 \"\n        \"    kernel_size: 3 \"\n        \"    stride: 2 \"\n        \"    weight_filler { \"\n        \"      type: 'gaussian' \"\n        \"      std: 0.01 \"\n        \"    } \"\n        \"    bias_filler { \"\n        \"      type: 'constant' \"\n        \"      value: 0.2 \"\n        \"    } \"\n        \"  } \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'relu1' \"\n        \"  type: 'ReLU' \"\n        \"  bottom: 'conv1' \"\n        \"  top: 'conv1' \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'pool1' \"\n        \"  type: 'Pooling' \"\n        \"  bottom: 'conv1' \"\n        \"  top: 'pool1' \"\n        \"  pooling_param { \"\n        \"    pool: MAX \"\n        \"    kernel_size: 2 \"\n        \"    stride: 2 \"\n        \"  } \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'norm1' \"\n        \"  type: 'LRN' \"\n        \"  bottom: 'pool1' \"\n        \"  top: 'norm1' \"\n        \"  lrn_param { \"\n        \"    local_size: 3 \"\n        \"  } \"\n        \"} \"\n        \"layer { \"\n        \"  name: 'softmax' \"\n        \"  type: 'Softmax' \"\n        \"  bottom: 'norm1' \"\n        \"  top: 'softmax' \"\n        \"} \";\n    InitNetFromProtoString(proto);\n  }\n\n  virtual void InitSkipPropNet(bool test_skip_true) {\n    string proto =\n      \"name: 'SkipPropTestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'DummyData' \"\n      \"  dummy_data_param { \"\n      \"    shape { \"\n      \"      dim: 5 \"\n      \"      dim: 2 \"\n      \"      dim: 3 \"\n      \"      dim: 4 \"\n      \"    } \"\n      \"    data_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    shape { \"\n      \"      dim: 5 \"\n      \"    } \"\n      \"    data_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'silence' \"\n      \"  bottom: 'label' \"\n      \"  type: 'Silence' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerproduct' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerproduct' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'ip_fake_labels' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'fake_labels' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'argmax' \"\n      \"  bottom: 'fake_labels' \"\n      \"  top: 'label_argmax' \"\n      \"  type: 'ArgMax' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  bottom: 'innerproduct' \"\n      \"  bottom: 'label_argmax' \";\n    if (test_skip_true)\n      proto += \"  propagate_down: true \"\n               \"  propagate_down: false \";\n    else\n      proto += \"  propagate_down: true \"\n               \"  propagate_down: true \";\n    proto +=\n      \"  top: 'cross_entropy_loss' \"\n      \"  type: 'SigmoidCrossEntropyLoss' \"\n      \"  loss_weight: 0.1 \"\n      \"} \";\n    InitNetFromProtoString(proto);\n  }\n\n  int seed_;\n  shared_ptr<Net<Dtype> > net_;\n};\n\nTYPED_TEST_CASE(NetTest, TestDtypesAndDevices);\n\nTYPED_TEST(NetTest, TestHasBlob) {\n  this->InitTinyNet();\n  EXPECT_TRUE(this->net_->has_blob(\"data\"));\n  EXPECT_TRUE(this->net_->has_blob(\"label\"));\n  EXPECT_TRUE(this->net_->has_blob(\"innerproduct\"));\n  EXPECT_FALSE(this->net_->has_blob(\"loss\"));\n  EXPECT_TRUE(this->net_->has_blob(\"top_loss\"));\n}\n\nTYPED_TEST(NetTest, TestGetBlob) {\n  this->InitTinyNet();\n  EXPECT_EQ(this->net_->blob_by_name(\"data\"), this->net_->blobs()[0]);\n  EXPECT_EQ(this->net_->blob_by_name(\"label\"), this->net_->blobs()[1]);\n  EXPECT_EQ(this->net_->blob_by_name(\"innerproduct\"), this->net_->blobs()[2]);\n  EXPECT_FALSE(this->net_->blob_by_name(\"loss\"));\n  EXPECT_EQ(this->net_->blob_by_name(\"top_loss\"), this->net_->blobs()[3]);\n}\n\nTYPED_TEST(NetTest, TestHasLayer) {\n  this->InitTinyNet();\n  EXPECT_TRUE(this->net_->has_layer(\"data\"));\n  EXPECT_TRUE(this->net_->has_layer(\"innerproduct\"));\n  EXPECT_TRUE(this->net_->has_layer(\"loss\"));\n  EXPECT_FALSE(this->net_->has_layer(\"label\"));\n}\n\nTYPED_TEST(NetTest, TestGetLayerByName) {\n  this->InitTinyNet();\n  EXPECT_EQ(this->net_->layer_by_name(\"data\"), this->net_->layers()[0]);\n  EXPECT_EQ(this->net_->layer_by_name(\"innerproduct\"), this->net_->layers()[1]);\n  EXPECT_EQ(this->net_->layer_by_name(\"loss\"), this->net_->layers()[2]);\n  EXPECT_FALSE(this->net_->layer_by_name(\"label\"));\n}\n\nTYPED_TEST(NetTest, TestBottomNeedBackward) {\n  this->InitTinyNet();\n  const vector<vector<bool> >& bottom_need_backward =\n      this->net_->bottom_need_backward();\n  EXPECT_EQ(3, bottom_need_backward.size());\n  EXPECT_EQ(0, bottom_need_backward[0].size());\n  EXPECT_EQ(1, bottom_need_backward[1].size());\n  EXPECT_EQ(false, bottom_need_backward[1][0]);\n  EXPECT_EQ(2, bottom_need_backward[2].size());\n  EXPECT_EQ(true, bottom_need_backward[2][0]);\n  EXPECT_EQ(false, bottom_need_backward[2][1]);\n}\n\nTYPED_TEST(NetTest, TestBottomNeedBackwardForce) {\n  const bool force_backward = true;\n  this->InitTinyNet(force_backward);\n  const vector<vector<bool> >& bottom_need_backward =\n      this->net_->bottom_need_backward();\n  EXPECT_EQ(3, bottom_need_backward.size());\n  EXPECT_EQ(0, bottom_need_backward[0].size());\n  EXPECT_EQ(1, bottom_need_backward[1].size());\n  EXPECT_EQ(true, bottom_need_backward[1][0]);\n  EXPECT_EQ(2, bottom_need_backward[2].size());\n  EXPECT_EQ(true, bottom_need_backward[2][0]);\n  EXPECT_EQ(false, bottom_need_backward[2][1]);\n}\n\nTYPED_TEST(NetTest, TestBottomNeedBackwardEuclideanForce) {\n  const bool force_backward = true;\n  this->InitTinyNetEuclidean(force_backward);\n  const vector<vector<bool> >& bottom_need_backward =\n      this->net_->bottom_need_backward();\n  EXPECT_EQ(3, bottom_need_backward.size());\n  EXPECT_EQ(0, bottom_need_backward[0].size());\n  EXPECT_EQ(1, bottom_need_backward[1].size());\n  EXPECT_EQ(true, bottom_need_backward[1][0]);\n  EXPECT_EQ(2, bottom_need_backward[2].size());\n  EXPECT_EQ(true, bottom_need_backward[2][0]);\n  EXPECT_EQ(true, bottom_need_backward[2][1]);\n}\n\nTYPED_TEST(NetTest, TestBottomNeedBackwardTricky) {\n  this->InitTrickyNet();\n  const vector<vector<bool> >& bottom_need_backward =\n      this->net_->bottom_need_backward();\n  EXPECT_EQ(4, bottom_need_backward.size());\n  EXPECT_EQ(0, bottom_need_backward[0].size());\n  EXPECT_EQ(1, bottom_need_backward[1].size());\n  EXPECT_EQ(false, bottom_need_backward[1][0]);\n  EXPECT_EQ(1, bottom_need_backward[2].size());\n  EXPECT_EQ(false, bottom_need_backward[2][0]);\n  EXPECT_EQ(2, bottom_need_backward[3].size());\n  EXPECT_EQ(true, bottom_need_backward[3][0]);\n  // The label input to the SoftmaxLossLayer should say it \"needs backward\"\n  // since it has weights under it, even though we expect this to cause a crash\n  // at training/test time.\n  EXPECT_EQ(true, bottom_need_backward[3][1]);\n}\n\nTYPED_TEST(NetTest, TestLossWeight) {\n  typedef typename TypeParam::Dtype Dtype;\n  // First, compute the loss and gradients with no loss_weight specified.\n  // In this case, the loss weight for the 'EuclideanLoss' layer should default\n  // to 1.\n  vector<Blob<Dtype>*> bottom;\n  Caffe::set_random_seed(this->seed_);\n  const bool kForceBackward = true;\n  this->InitUnsharedWeightsNet(NULL, NULL, kForceBackward);\n  const Dtype loss = this->net_->ForwardBackward(bottom);\n  const bool kCopyDiff = true;\n  vector<shared_ptr<Blob<Dtype> > > blob_grads;\n  this->CopyNetBlobs(kCopyDiff, &blob_grads);\n  vector<shared_ptr<Blob<Dtype> > > param_grads;\n  this->CopyNetParams(kCopyDiff, &param_grads);\n  // Check that the loss is non-trivial, otherwise the test doesn't prove much.\n  const Dtype kMinLossAbsValue = 1e-2;\n  ASSERT_GE(fabs(loss), kMinLossAbsValue);\n  const Dtype kErrorMargin = 1e-4;\n  const int kNumLossWeights = 6;\n  Dtype kLossWeights[kNumLossWeights] = {2, 0, 1, -1, -2.5, 3.7};\n  for (int i = 0; i < kNumLossWeights; ++i) {\n    Caffe::set_random_seed(this->seed_);\n    this->InitUnsharedWeightsNet(&kLossWeights[i], NULL, kForceBackward);\n    const Dtype weighted_loss = this->net_->ForwardBackward(bottom);\n    const Dtype error_margin = kErrorMargin * fabs(kLossWeights[i]);\n    EXPECT_NEAR(loss * kLossWeights[i], weighted_loss, error_margin)\n        << \"loss weight = \" << kLossWeights[i];\n    const vector<shared_ptr<Blob<Dtype> > >& weighted_blobs =\n        this->net_->blobs();\n    ASSERT_EQ(blob_grads.size(), weighted_blobs.size());\n    for (int j = 0; j < blob_grads.size(); ++j) {\n      ASSERT_EQ(blob_grads[j]->count(), weighted_blobs[j]->count());\n      for (int k = 0; k < blob_grads[j]->count(); ++k) {\n        EXPECT_NEAR(blob_grads[j]->cpu_diff()[k] * kLossWeights[i],\n                    weighted_blobs[j]->cpu_diff()[k], error_margin);\n      }\n    }\n    const vector<shared_ptr<Blob<Dtype> > >& weighted_params =\n        this->net_->params();\n    ASSERT_EQ(param_grads.size(), weighted_params.size());\n    for (int j = 0; j < param_grads.size(); ++j) {\n      ASSERT_EQ(param_grads[j]->count(), weighted_params[j]->count());\n      for (int k = 0; k < param_grads[j]->count(); ++k) {\n        EXPECT_NEAR(param_grads[j]->cpu_diff()[k] * kLossWeights[i],\n                    weighted_params[j]->cpu_diff()[k], error_margin);\n      }\n    }\n  }\n}\n\nTYPED_TEST(NetTest, TestLossWeightMidNet) {\n  typedef typename TypeParam::Dtype Dtype;\n  vector<Blob<Dtype>*> bottom;\n  Caffe::set_random_seed(this->seed_);\n  const bool kForceBackward = true;\n  Dtype loss_weight = 0;\n  Dtype midnet_loss_weight = 1;\n  this->InitUnsharedWeightsNet(&loss_weight, &midnet_loss_weight,\n                               kForceBackward);\n  const Dtype loss = this->net_->ForwardBackward(bottom);\n  const bool kCopyDiff = true;\n  const bool kReshape = true;\n  Blob<Dtype> data_grad;\n  data_grad.CopyFrom(*this->net_->blob_by_name(\"data\"), kCopyDiff, kReshape);\n  // Check that the loss is non-trivial, otherwise the test doesn't prove much.\n  const Dtype kMinLossAbsValue = 1e-2;\n  ASSERT_GE(fabs(loss), kMinLossAbsValue);\n  const Dtype kErrorMargin = 1e-4;\n  const int kNumLossWeights = 6;\n  Dtype kLossWeights[kNumLossWeights] = {2, 0, 1, -1, -2.5, 3.7};\n  for (int i = 0; i < kNumLossWeights; ++i) {\n    Caffe::set_random_seed(this->seed_);\n    this->InitUnsharedWeightsNet(&loss_weight, &kLossWeights[i],\n                                 kForceBackward);\n    const Dtype weighted_loss = this->net_->ForwardBackward(bottom);\n    const Dtype error_margin = kErrorMargin * fabs(kLossWeights[i]);\n    EXPECT_NEAR(loss * kLossWeights[i], weighted_loss, error_margin)\n        << \"loss weight = \" << kLossWeights[i];\n    const shared_ptr<Blob<Dtype> >& weighted_blob =\n        this->net_->blob_by_name(\"data\");\n    ASSERT_EQ(data_grad.count(), weighted_blob->count());\n    for (int j = 0; j < data_grad.count(); ++j) {\n      EXPECT_NEAR(data_grad.cpu_diff()[j] * kLossWeights[i],\n                  weighted_blob->cpu_diff()[j], error_margin);\n    }\n  }\n}\n\nTYPED_TEST(NetTest, TestComboLossWeight) {\n  typedef typename TypeParam::Dtype Dtype;\n  vector<Blob<Dtype>*> bottom;\n  Dtype loss_weight;\n  Dtype midnet_loss_weight;\n  const bool kForceBackward = true;\n  const Dtype kErrorMargin = 1e-4;\n\n  // Get the loss and gradients with 'EuclideanLoss' weight 1,\n  // 'InnerProduct' weight 1.\n  loss_weight = 1;\n  midnet_loss_weight = 1;\n  Caffe::set_random_seed(this->seed_);\n  this->InitUnsharedWeightsNet(&loss_weight, &midnet_loss_weight,\n                               kForceBackward);\n  const Dtype loss = this->net_->ForwardBackward(bottom);\n  const bool kCopyDiff = true;\n  vector<shared_ptr<Blob<Dtype> > > blob_grads;\n  this->CopyNetBlobs(kCopyDiff, &blob_grads);\n  vector<shared_ptr<Blob<Dtype> > > param_grads;\n  this->CopyNetParams(kCopyDiff, &param_grads);\n\n  loss_weight = 2;\n  midnet_loss_weight = 1;\n  Caffe::set_random_seed(this->seed_);\n  this->InitUnsharedWeightsNet(&loss_weight, &midnet_loss_weight,\n                               kForceBackward);\n  const Dtype loss_main_2 = this->net_->ForwardBackward(bottom);\n  vector<shared_ptr<Blob<Dtype> > > blob_grads_loss_2;\n  this->CopyNetBlobs(kCopyDiff, &blob_grads_loss_2);\n  vector<shared_ptr<Blob<Dtype> > > param_grads_loss_2;\n  this->CopyNetParams(kCopyDiff, &param_grads_loss_2);\n\n  loss_weight = 3;\n  midnet_loss_weight = 1;\n  Caffe::set_random_seed(this->seed_);\n  this->InitUnsharedWeightsNet(&loss_weight, &midnet_loss_weight,\n                               kForceBackward);\n  const Dtype loss_main_3 = this->net_->ForwardBackward(bottom);\n  const vector<shared_ptr<Blob<Dtype> > >& blob_grads_loss_3 =\n      this->net_->blobs();\n  ASSERT_EQ(blob_grads.size(), blob_grads_loss_3.size());\n  ASSERT_EQ(blob_grads_loss_2.size(), blob_grads_loss_3.size());\n  for (int j = 0; j < blob_grads.size(); ++j) {\n    const string& blob_name = this->net_->blob_names()[j];\n    bool grad_should_change = true;\n    if (blob_name == \"innerproduct1_innerproduct1_0_split_0\") {\n      grad_should_change = false;\n    }\n    ASSERT_EQ(blob_grads[j]->count(), blob_grads_loss_3[j]->count());\n    ASSERT_EQ(blob_grads_loss_2[j]->count(), blob_grads_loss_3[j]->count());\n    for (int k = 0; k < blob_grads[j]->count(); ++k) {\n      const Dtype grad_diff_2 = blob_grads_loss_2[j]->cpu_diff()[k] -\n                                    blob_grads[j]->cpu_diff()[k];\n      const Dtype grad_diff_3 = blob_grads_loss_3[j]->cpu_diff()[k] -\n                                    blob_grads[j]->cpu_diff()[k];\n      if (grad_should_change) {\n        // Test non-triviality.\n        const Dtype kMinGradDiffAbsValue = 1e-4;\n        EXPECT_GT(fabs(grad_diff_2), kMinGradDiffAbsValue) << blob_name;\n        EXPECT_NEAR(2 * grad_diff_2, grad_diff_3, kErrorMargin) << blob_name;\n      } else {\n        EXPECT_EQ(0, grad_diff_2) << blob_name;\n        EXPECT_EQ(0, grad_diff_3) << blob_name;\n      }\n    }\n  }\n\n  loss_weight = 1;\n  midnet_loss_weight = 2;\n  Caffe::set_random_seed(this->seed_);\n  this->InitUnsharedWeightsNet(&loss_weight, &midnet_loss_weight,\n                               kForceBackward);\n  const Dtype loss_midnet_2 = this->net_->ForwardBackward(bottom);\n  this->CopyNetBlobs(kCopyDiff, &blob_grads_loss_2);\n  this->CopyNetParams(kCopyDiff, &param_grads_loss_2);\n\n  loss_weight = 1;\n  midnet_loss_weight = 3;\n  Caffe::set_random_seed(this->seed_);\n  this->InitUnsharedWeightsNet(&loss_weight, &midnet_loss_weight,\n                               kForceBackward);\n  const Dtype loss_midnet_3 = this->net_->ForwardBackward(bottom);\n  const vector<shared_ptr<Blob<Dtype> > >& blob_grads_midnet_loss_3 =\n      this->net_->blobs();\n  ASSERT_EQ(blob_grads.size(), blob_grads_midnet_loss_3.size());\n  ASSERT_EQ(blob_grads_loss_2.size(), blob_grads_midnet_loss_3.size());\n  const vector<string>& blob_names = this->net_->blob_names();\n  for (int j = 0; j < blob_grads.size(); ++j) {\n    const string& blob_name = blob_names[j];\n    bool grad_should_change = false;\n    if (blob_name == \"innerproduct1\" ||\n        blob_name == \"innerproduct1_innerproduct1_0_split_0\" ||\n        blob_name == \"data_data_0_split_0\" || blob_name == \"data\") {\n      grad_should_change = true;\n    }\n    ASSERT_EQ(blob_grads[j]->count(), blob_grads_midnet_loss_3[j]->count());\n    ASSERT_EQ(blob_grads[j]->count(), blob_grads_loss_2[j]->count());\n    for (int k = 0; k < blob_grads[j]->count(); ++k) {\n      const Dtype grad_diff_2 = blob_grads_loss_2[j]->cpu_diff()[k] -\n                                    blob_grads[j]->cpu_diff()[k];\n      const Dtype grad_diff_3 = blob_grads_midnet_loss_3[j]->cpu_diff()[k] -\n                                    blob_grads[j]->cpu_diff()[k];\n      if (grad_should_change) {\n        // Test non-triviality.\n        const Dtype kMinGradDiffAbsValue = 1e-4;\n        EXPECT_GT(fabs(grad_diff_2), kMinGradDiffAbsValue) << blob_name;\n        EXPECT_NEAR(2 * grad_diff_2, grad_diff_3, kErrorMargin) << blob_name;\n      } else {\n        EXPECT_EQ(0, grad_diff_2) << blob_name;\n        EXPECT_EQ(0, grad_diff_3) << blob_name;\n      }\n    }\n  }\n\n  const Dtype kMinLossDiffAbsValue = 1e-4;\n\n  Dtype loss_diff_2 = loss_main_2 - loss;\n  // Test non-triviality.\n  EXPECT_GT(fabs(loss_diff_2), kMinLossDiffAbsValue);\n  Dtype loss_diff_3 = loss_main_3 - loss;\n  EXPECT_NEAR(2 * loss_diff_2, loss_diff_3, kErrorMargin);\n\n  loss_diff_2 = loss_midnet_2 - loss;\n  // Test non-triviality.\n  EXPECT_GT(fabs(loss_diff_2), kMinLossDiffAbsValue);\n  loss_diff_3 = loss_midnet_3 - loss;\n  EXPECT_NEAR(2 * loss_diff_2, loss_diff_3, kErrorMargin);\n}\n\nTYPED_TEST(NetTest, TestBackwardWithAccuracyLayer) {\n  typedef typename TypeParam::Dtype Dtype;\n  const bool kForceBackward = false;\n  const bool kAccuracyLayer = true;\n  this->InitTinyNet(kForceBackward, kAccuracyLayer);\n  EXPECT_TRUE(this->net_->has_blob(\"accuracy\"));\n  vector<Blob<Dtype>*> bottom;\n  // Test that we can do Backward even though we have an 'Accuracy' layer.\n  this->net_->ForwardBackward(bottom);\n}\n\nTYPED_TEST(NetTest, TestUnsharedWeightsDataNet) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->InitUnsharedWeightsNet();\n  vector<Blob<Dtype>*> bottom;\n  Dtype loss;\n  this->net_->Forward(bottom, &loss);\n  EXPECT_GT(loss, 0);\n}\n\nTYPED_TEST(NetTest, TestSharedWeightsDataNet) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->InitSharedWeightsNet();\n  vector<Blob<Dtype>*> bottom;\n  Dtype loss;\n  this->net_->Forward(bottom, &loss);\n  EXPECT_FLOAT_EQ(loss, 0);\n}\n\nTYPED_TEST(NetTest, TestUnsharedWeightsDiffNet) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->InitUnsharedWeightsNet();\n  vector<Blob<Dtype>*> bottom;\n  Net<Dtype>* net = this->net_.get();\n  net->Forward(bottom);\n  net->Backward();\n  Layer<Dtype>* ip1_layer = net->layer_by_name(\"innerproduct1\").get();\n  Layer<Dtype>* ip2_layer = net->layer_by_name(\"innerproduct2\").get();\n  const int count = ip1_layer->blobs()[0]->count();\n  const Dtype* grad1 = ip1_layer->blobs()[0]->cpu_diff();\n  const Dtype* grad2 = ip2_layer->blobs()[0]->cpu_diff();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_GT(fabs(grad1[i]), 0);\n    EXPECT_FLOAT_EQ(-1 * grad1[i], grad2[i]);\n  }\n}\n\nTYPED_TEST(NetTest, TestSharedWeightsDiffNet) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->InitSharedWeightsNet();\n  vector<Blob<Dtype>*> bottom;\n  Net<Dtype>* net = this->net_.get();\n  Dtype loss;\n  net->Forward(bottom, &loss);\n  net->Backward();\n  EXPECT_FLOAT_EQ(loss, 0);\n  Layer<Dtype>* ip1_layer = net->layer_by_name(\"innerproduct1\").get();\n  Layer<Dtype>* ip2_layer = net->layer_by_name(\"innerproduct2\").get();\n  const int count = ip1_layer->blobs()[0]->count();\n  const Dtype* grad1 = ip1_layer->blobs()[0]->cpu_diff();\n  const Dtype* grad2 = ip2_layer->blobs()[0]->cpu_diff();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_FLOAT_EQ(0, grad1[i]);\n    EXPECT_FLOAT_EQ(0, grad2[i]);\n  }\n}\n\nTYPED_TEST(NetTest, TestSharedWeightsUpdate) {\n  typedef typename TypeParam::Dtype Dtype;\n  Caffe::set_random_seed(this->seed_);\n  this->InitDiffDataSharedWeightsNet();\n  vector<Blob<Dtype>*> bottom;\n  EXPECT_EQ(this->net_->layer_names()[1], \"innerproduct1\");\n  EXPECT_EQ(this->net_->layer_names()[2], \"innerproduct2\");\n  Blob<Dtype>* ip1_weights = this->net_->layers()[1]->blobs()[0].get();\n  Blob<Dtype>* ip2_weights = this->net_->layers()[2]->blobs()[0].get();\n  // Check that data and diff blobs of shared weights share the same memory\n  // locations.\n  EXPECT_EQ(ip1_weights->cpu_data(), ip2_weights->cpu_data());\n  EXPECT_EQ(ip1_weights->cpu_diff(), ip2_weights->cpu_diff());\n  this->net_->Forward(bottom);\n  this->net_->Backward();\n  // Compute the expected update as the data minus the two diffs.\n  Blob<Dtype> shared_params;\n  const bool reshape = true;\n  const bool copy_diff = false;\n  shared_params.CopyFrom(*ip1_weights, copy_diff, reshape);\n  shared_params.CopyFrom(*ip1_weights, !copy_diff, reshape);\n  const int count = ip1_weights->count();\n  // Make sure the diffs are non-trivial.\n  for (int i = 0; i < count; ++i) {\n    EXPECT_NE(0, ip1_weights->cpu_diff()[i]);\n  }\n  caffe_axpy(count, Dtype(-1), shared_params.cpu_diff(),\n             shared_params.mutable_cpu_data());\n  const Dtype* expected_updated_params = shared_params.cpu_data();\n  this->net_->Update();\n  const Dtype* actual_updated_params = ip1_weights->cpu_data();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_EQ(expected_updated_params[i], actual_updated_params[i]);\n  }\n  // Check that data blobs of shared weights STILL point to the same memory\n  // location (because ... who knows).\n  EXPECT_EQ(ip1_weights->cpu_data(), ip2_weights->cpu_data());\n\n  Caffe::set_random_seed(this->seed_);\n  this->InitDiffDataUnsharedWeightsNet();\n  EXPECT_EQ(this->net_->layer_names()[1], \"innerproduct1\");\n  EXPECT_EQ(this->net_->layer_names()[2], \"innerproduct2\");\n  ip1_weights = this->net_->layers()[1]->blobs()[0].get();\n  ip2_weights = this->net_->layers()[2]->blobs()[0].get();\n  // Check that data and diff blobs of unshared weights are at different\n  // locations in memory.\n  EXPECT_NE(ip1_weights->cpu_data(), ip2_weights->cpu_data());\n  EXPECT_NE(ip1_weights->cpu_diff(), ip2_weights->cpu_diff());\n  this->net_->Forward(bottom);\n  this->net_->Backward();\n  // Compute the expected update.\n  Blob<Dtype> unshared_params1;\n  unshared_params1.CopyFrom(*ip1_weights, copy_diff, reshape);\n  unshared_params1.CopyFrom(*ip1_weights, !copy_diff, reshape);\n  Blob<Dtype> unshared_params2;\n  unshared_params2.CopyFrom(*ip2_weights, copy_diff, reshape);\n  unshared_params2.CopyFrom(*ip2_weights, !copy_diff, reshape);\n  // Make sure the diffs are non-trivial and sum to the diff in the shared net.\n  for (int i = 0; i < count; ++i) {\n    EXPECT_NE(0, ip1_weights->cpu_diff()[i]);\n    EXPECT_NE(0, ip2_weights->cpu_diff()[i]);\n    EXPECT_NE(ip1_weights->cpu_diff()[i], ip2_weights->cpu_diff()[i]);\n    EXPECT_FLOAT_EQ(ip1_weights->cpu_diff()[i] + ip2_weights->cpu_diff()[i],\n                    shared_params.cpu_diff()[i]);\n  }\n  caffe_axpy(count, Dtype(-1), ip1_weights->cpu_diff(),\n             unshared_params1.mutable_cpu_data());\n  caffe_axpy(count, Dtype(-1), ip2_weights->cpu_diff(),\n             unshared_params2.mutable_cpu_data());\n  const Dtype* expected_updated_params1 = unshared_params1.cpu_data();\n  const Dtype* expected_updated_params2 = unshared_params2.cpu_data();\n  this->net_->Update();\n  const Dtype* actual_updated_params1 = ip1_weights->cpu_data();\n  const Dtype* actual_updated_params2 = ip2_weights->cpu_data();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_EQ(expected_updated_params1[i], actual_updated_params1[i]);\n    EXPECT_EQ(expected_updated_params2[i], actual_updated_params2[i]);\n    EXPECT_NE(actual_updated_params1[i], actual_updated_params2[i]);\n    EXPECT_NE(expected_updated_params, expected_updated_params1);\n  }\n}\n\nTYPED_TEST(NetTest, TestSharedWeightsResume) {\n  typedef typename TypeParam::Dtype Dtype;\n\n  // Create a net with weight sharing; Update it once.\n  Caffe::set_random_seed(this->seed_);\n  this->InitDiffDataSharedWeightsNet();\n  vector<Blob<Dtype>*> bottom;\n  EXPECT_EQ(this->net_->layer_names()[1], \"innerproduct1\");\n  EXPECT_EQ(this->net_->layer_names()[2], \"innerproduct2\");\n  Blob<Dtype>* ip1_weights = this->net_->layers()[1]->blobs()[0].get();\n  Blob<Dtype>* ip2_weights = this->net_->layers()[2]->blobs()[0].get();\n  // Check that data and diff blobs of shared weights share the same memory\n  // locations.\n  EXPECT_EQ(ip1_weights->cpu_data(), ip2_weights->cpu_data());\n  EXPECT_EQ(ip1_weights->cpu_diff(), ip2_weights->cpu_diff());\n  this->net_->ForwardBackward(bottom);\n  this->net_->Update();\n  Blob<Dtype> shared_params;\n  const bool kReshape = true;\n  const bool kCopyDiff = false;\n  shared_params.CopyFrom(*ip1_weights, kCopyDiff, kReshape);\n  const int count = ip1_weights->count();\n\n  // Write the net to a NetParameter, as in Solver::Snapshot.\n  NetParameter net_param;\n  this->net_->ToProto(&net_param);\n\n  // Reinitialize the net and copy parameters from net_param, as in\n  // Solver::Restore.\n  Caffe::set_random_seed(this->seed_);\n  this->InitDiffDataSharedWeightsNet();\n  this->net_->CopyTrainedLayersFrom(net_param);\n  ip1_weights = this->net_->layers()[1]->blobs()[0].get();\n  ip2_weights = this->net_->layers()[2]->blobs()[0].get();\n  ASSERT_FALSE(NULL == ip1_weights);\n  ASSERT_FALSE(NULL == ip2_weights);\n  EXPECT_NE(ip1_weights, ip2_weights);\n  // Check that data and diff blobs of shared weights share the same memory\n  // locations.\n  EXPECT_EQ(ip1_weights->cpu_data(), ip2_weights->cpu_data());\n  EXPECT_EQ(ip1_weights->cpu_diff(), ip2_weights->cpu_diff());\n  for (int i = 0; i < count; ++i) {\n    EXPECT_FLOAT_EQ(shared_params.cpu_data()[i], ip1_weights->cpu_data()[i]);\n  }\n}\n\nTYPED_TEST(NetTest, TestParamPropagateDown) {\n  typedef typename TypeParam::Dtype Dtype;\n  vector<Blob<Dtype>*> bottom;\n  const bool kBiasTerm = true, kForceBackward = false;\n  const Dtype* kLossWeight1 = NULL;\n  const Dtype* kLossWeight2 = NULL;\n\n  // Run the net with all params learned; check that gradients are non-zero.\n  Caffe::set_random_seed(this->seed_);\n  Dtype blobs_lr_w1 = 1, blobs_lr_w2 = 1, blobs_lr_b1 = 2, blobs_lr_b2 = 2;\n  this->InitUnsharedWeightsNet(kLossWeight1, kLossWeight2, kForceBackward,\n      kBiasTerm, blobs_lr_w1, blobs_lr_w2, blobs_lr_b1, blobs_lr_b2);\n  this->net_->Forward(bottom);\n  this->net_->Backward();\n  const vector<shared_ptr<Blob<Dtype> > >& params = this->net_->params();\n  const int num_params = params.size();\n  ASSERT_EQ(4, num_params);\n  const Dtype kNonZeroTestMin = 1e-3;\n  vector<Dtype> param_asums(params.size());\n  for (int i = 0; i < num_params; ++i) {\n    const Dtype param_asum =\n       caffe_cpu_asum(params[i]->count(), params[i]->cpu_diff());\n    param_asums[i] = param_asum;\n    EXPECT_GT(param_asum, kNonZeroTestMin);\n  }\n\n  // Change the learning rates to different non-zero values; should see same\n  // gradients.\n  Caffe::set_random_seed(this->seed_);\n  blobs_lr_w1 *= 2, blobs_lr_w2 *= 2, blobs_lr_b1 *= 2, blobs_lr_b2 *= 2;\n  this->InitUnsharedWeightsNet(kLossWeight1, kLossWeight2, kForceBackward,\n      kBiasTerm, blobs_lr_w1, blobs_lr_w2, blobs_lr_b1, blobs_lr_b2);\n  this->net_->Forward(bottom);\n  this->net_->Backward();\n  const vector<shared_ptr<Blob<Dtype> > >& params2 = this->net_->params();\n  ASSERT_EQ(num_params, params2.size());\n  for (int i = 0; i < num_params; ++i) {\n    const Dtype param_asum =\n       caffe_cpu_asum(params2[i]->count(), params2[i]->cpu_diff());\n    EXPECT_FLOAT_EQ(param_asum, param_asums[i]);\n  }\n\n  // Change a subset of the learning rates to zero; check that we see zero\n  // gradients for those.\n  Caffe::set_random_seed(this->seed_);\n  blobs_lr_w1 = 1, blobs_lr_w2 = 0, blobs_lr_b1 = 0, blobs_lr_b2 = 1;\n  this->InitUnsharedWeightsNet(kLossWeight1, kLossWeight2, kForceBackward,\n      kBiasTerm, blobs_lr_w1, blobs_lr_w2, blobs_lr_b1, blobs_lr_b2);\n  this->net_->Forward(bottom);\n  this->net_->Backward();\n  const vector<shared_ptr<Blob<Dtype> > >& params3 = this->net_->params();\n  ASSERT_EQ(num_params, params3.size());\n  for (int i = 0; i < num_params; ++i) {\n    const Dtype param_asum =\n       caffe_cpu_asum(params3[i]->count(), params3[i]->cpu_diff());\n    if (i == 1 || i == 2) {\n      EXPECT_FLOAT_EQ(0, param_asum);\n    } else {\n      EXPECT_FLOAT_EQ(param_asum, param_asums[i]);\n    }\n  }\n\n  // Change the opposite subset of the learning rates to zero.\n  Caffe::set_random_seed(this->seed_);\n  blobs_lr_w1 = 0, blobs_lr_w2 = 1, blobs_lr_b1 = 1, blobs_lr_b2 = 0;\n  this->InitUnsharedWeightsNet(kLossWeight1, kLossWeight2, kForceBackward,\n      kBiasTerm, blobs_lr_w1, blobs_lr_w2, blobs_lr_b1, blobs_lr_b2);\n  this->net_->Forward(bottom);\n  this->net_->Backward();\n  const vector<shared_ptr<Blob<Dtype> > >& params4 = this->net_->params();\n  ASSERT_EQ(num_params, params4.size());\n  for (int i = 0; i < num_params; ++i) {\n    const Dtype param_asum =\n       caffe_cpu_asum(params4[i]->count(), params4[i]->cpu_diff());\n    if (i == 0 || i == 3) {\n      EXPECT_FLOAT_EQ(0, param_asum);\n    } else {\n      EXPECT_FLOAT_EQ(param_asum, param_asums[i]);\n    }\n  }\n}\n\nTYPED_TEST(NetTest, TestFromTo) {\n  typedef typename TypeParam::Dtype Dtype;\n  this->InitTinyNet();\n\n  // Run Forward and Backward, recording the data diff and loss.\n  Blob<Dtype> data;\n  data.ReshapeLike(*this->net_->blob_by_name(\"data\"));\n  this->net_->ForwardPrefilled();\n  this->net_->Backward();\n  data.CopyFrom(*this->net_->blob_by_name(\"data\"), true, true);\n  const Dtype *loss_ptr = this->net_->output_blobs()[0]->cpu_data();\n  Dtype loss = *loss_ptr;\n\n  // Check that combining partial Forwards gives the same loss.\n  for (int i = 1; i < this->net_->layers().size(); ++i) {\n    // Note that we skip layer zero to keep the same data.\n    this->net_->ForwardFromTo(1, 1);\n    if (i < this->net_->layers().size() - 1) {\n      this->net_->ForwardFrom(i + 1);\n    }\n    EXPECT_EQ(loss, *loss_ptr);\n  }\n\n  // Check that combining partial Backwards gives the same data diff.\n  for (int i = 1; i < this->net_->layers().size(); ++i) {\n    this->net_->BackwardTo(i);\n    this->net_->BackwardFrom(i - 1);\n    for (int j = 0; j < data.count(); ++j) {\n      EXPECT_EQ(data.cpu_diff()[j],\n          this->net_->blob_by_name(\"data\")->cpu_diff()[j]);\n    }\n  }\n}\n\nclass FilterNetTest : public ::testing::Test {\n protected:\n  void RunFilterNetTest(\n      const string& input_param_string, const string& filtered_param_string) {\n    NetParameter input_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        input_param_string, &input_param));\n    NetParameter expected_filtered_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        filtered_param_string, &expected_filtered_param));\n    NetParameter actual_filtered_param;\n    Net<float>::FilterNet(input_param, &actual_filtered_param);\n    EXPECT_EQ(expected_filtered_param.DebugString(),\n        actual_filtered_param.DebugString());\n    // Also test idempotence.\n    NetParameter double_filtered_param;\n    Net<float>::FilterNet(actual_filtered_param, &double_filtered_param);\n    EXPECT_EQ(actual_filtered_param.DebugString(),\n       double_filtered_param.DebugString());\n  }\n};\n\nTEST_F(FilterNetTest, TestNoFilter) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterLeNetTrainTest) {\n  const string& input_proto =\n      \"name: 'LeNet' \"\n      \"layer { \"\n      \"  name: 'mnist' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"  data_param { \"\n      \"    source: 'mnist-train-leveldb' \"\n      \"    batch_size: 64 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    scale: 0.00390625 \"\n      \"  } \"\n      \"  include: { phase: TRAIN } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'mnist' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"  data_param { \"\n      \"    source: 'mnist-test-leveldb' \"\n      \"    batch_size: 100 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    scale: 0.00390625 \"\n      \"  } \"\n      \"  include: { phase: TEST } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv1' \"\n      \"  type: 'Convolution' \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"  } \"\n      \"  convolution_param { \"\n      \"    num_output: 20 \"\n      \"    kernel_size: 5 \"\n      \"    stride: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'xavier' \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"    } \"\n      \"  } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'ip1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'ip1' \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"  } \"\n      \"  inner_product_param { \"\n      \"    num_output: 10 \"\n      \"    weight_filler { \"\n      \"      type: 'xavier' \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"    } \"\n      \"  } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'accuracy' \"\n      \"  type: 'Accuracy' \"\n      \"  bottom: 'ip1' \"\n      \"  bottom: 'label' \"\n      \"  top: 'accuracy' \"\n      \"  include: { phase: TEST } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'ip2' \"\n      \"  bottom: 'label' \"\n      \"  top: 'loss' \"\n      \"} \";\n  const string input_proto_train = \"state: { phase: TRAIN } \" + input_proto;\n  const string input_proto_test = \"state: { phase: TEST } \" + input_proto;\n  const string output_proto_train =\n      \"name: 'LeNet' \"\n      \"layer { \"\n      \"  name: 'mnist' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"  data_param { \"\n      \"    source: 'mnist-train-leveldb' \"\n      \"    batch_size: 64 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    scale: 0.00390625 \"\n      \"  } \"\n      \"  include: { phase: TRAIN } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv1' \"\n      \"  type: 'Convolution' \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"  } \"\n      \"  convolution_param { \"\n      \"    num_output: 20 \"\n      \"    kernel_size: 5 \"\n      \"    stride: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'xavier' \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"    } \"\n      \"  } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'ip1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'ip1' \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"  } \"\n      \"  inner_product_param { \"\n      \"    num_output: 10 \"\n      \"    weight_filler { \"\n      \"      type: 'xavier' \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"    } \"\n      \"  } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'ip2' \"\n      \"  bottom: 'label' \"\n      \"  top: 'loss' \"\n      \"} \";\n  const string& output_proto_test =\n      \"name: 'LeNet' \"\n      \"layer { \"\n      \"  name: 'mnist' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"  data_param { \"\n      \"    source: 'mnist-test-leveldb' \"\n      \"    batch_size: 100 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    scale: 0.00390625 \"\n      \"  } \"\n      \"  include: { phase: TEST } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv1' \"\n      \"  type: 'Convolution' \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"  } \"\n      \"  convolution_param { \"\n      \"    num_output: 20 \"\n      \"    kernel_size: 5 \"\n      \"    stride: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'xavier' \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"    } \"\n      \"  } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'ip1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'ip1' \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"  } \"\n      \"  inner_product_param { \"\n      \"    num_output: 10 \"\n      \"    weight_filler { \"\n      \"      type: 'xavier' \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"    } \"\n      \"  } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'accuracy' \"\n      \"  type: 'Accuracy' \"\n      \"  bottom: 'ip1' \"\n      \"  bottom: 'label' \"\n      \"  top: 'accuracy' \"\n      \"  include: { phase: TEST } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'ip2' \"\n      \"  bottom: 'label' \"\n      \"  top: 'loss' \"\n      \"} \";\n  const string output_proto_train_explicit =\n      output_proto_train + \" state: { phase: TRAIN } \";\n  const string output_proto_test_explicit =\n      output_proto_test + \" state: { phase: TEST } \";\n  this->RunFilterNetTest(input_proto_train, output_proto_train_explicit);\n  this->RunFilterNetTest(input_proto_test, output_proto_test_explicit);\n}\n\nTEST_F(FilterNetTest, TestFilterOutByStage) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"  include: { stage: 'mystage' } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  const string& output_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, output_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterOutByStage2) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { stage: 'mystage' } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  const string& output_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, output_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInByStage) {\n  const string& input_proto =\n      \"state: { stage: 'mystage' } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { stage: 'mystage' } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInByStage2) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  exclude: { stage: 'mystage' } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterOutByMultipleStage) {\n  const string& input_proto =\n      \"state: { stage: 'mystage' } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { stage: 'mystage' stage: 'myotherstage' } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  include: { stage: 'mystage' } \"\n      \"} \";\n  const string& output_proto =\n      \"state: { stage: 'mystage' } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  include: { stage: 'mystage' } \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, output_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInByMultipleStage) {\n  const string& input_proto =\n      \"state: { stage: 'mystage' } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { stage: 'myotherstage' } \"\n      \"  include: { stage: 'mystage' } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  include: { stage: 'mystage' } \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInByMultipleStage2) {\n  const string& input_proto =\n      \"state: { stage: 'mystage' stage: 'myotherstage' } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { stage: 'mystage' stage: 'myotherstage' } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  include: { stage: 'mystage' } \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInByNotStage) {\n  const string& input_proto =\n      \"state: { stage: 'mystage' } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { not_stage: 'myotherstage' } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  include: { not_stage: 'myotherstage' } \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterOutByNotStage) {\n  const string& input_proto =\n      \"state: { stage: 'mystage' } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { not_stage: 'mystage' } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  include: { not_stage: 'mystage' } \"\n      \"} \";\n  const string& output_proto =\n      \"state: { stage: 'mystage' } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, output_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterOutByMinLevel) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { min_level: 3 } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  const string& output_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, output_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterOutByMaxLevel) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { max_level: -3 } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  const string& output_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, output_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInByMinLevel) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { min_level: 0 } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInByMinLevel2) {\n  const string& input_proto =\n      \"state: { level: 7 } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { min_level: 3 } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInByMaxLevel) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { max_level: 0 } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInByMaxLevel2) {\n  const string& input_proto =\n      \"state: { level: -7 } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { max_level: -3 } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunFilterNetTest(input_proto, input_proto);\n}\n\nTEST_F(FilterNetTest, TestFilterInOutByIncludeMultiRule) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { min_level: 2  phase: TRAIN } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  include: { min_level: 2  phase: TEST } \"\n      \"} \";\n  const string& input_proto_train =\n      \"state: { level: 4  phase: TRAIN } \" + input_proto;\n  const string& input_proto_test =\n      \"state: { level: 4  phase: TEST } \" + input_proto;\n  const string& output_proto_train =\n      \"state: { level: 4  phase: TRAIN } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { min_level: 2  phase: TRAIN } \"\n      \"} \";\n  const string& output_proto_test =\n      \"state: { level: 4  phase: TEST } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  include: { min_level: 2  phase: TEST } \"\n      \"} \";\n  this->RunFilterNetTest(input_proto_train, output_proto_train);\n  this->RunFilterNetTest(input_proto_test, output_proto_test);\n}\n\nTEST_F(FilterNetTest, TestFilterInByIncludeMultiRule) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  include: { min_level: 2  phase: TRAIN } \"\n      \"  include: { phase: TEST } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  include: { min_level: 2  phase: TEST } \"\n      \"  include: { phase: TRAIN } \"\n      \"} \";\n  const string& input_proto_train =\n      \"state: { level: 2  phase: TRAIN } \" + input_proto;\n  const string& input_proto_test =\n      \"state: { level: 2  phase: TEST } \" + input_proto;\n  this->RunFilterNetTest(input_proto_train, input_proto_train);\n  this->RunFilterNetTest(input_proto_test, input_proto_test);\n}\n\nTEST_F(FilterNetTest, TestFilterInOutByExcludeMultiRule) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  exclude: { min_level: 2  phase: TRAIN } \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  exclude: { min_level: 2  phase: TEST } \"\n      \"} \";\n  const string& input_proto_train =\n      \"state: { level: 4  phase: TRAIN } \" + input_proto;\n  const string& input_proto_test =\n      \"state: { level: 4  phase: TEST } \" + input_proto;\n  const string& output_proto_train =\n      \"state: { level: 4  phase: TRAIN } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"  exclude: { min_level: 2  phase: TEST } \"\n      \"} \";\n  const string& output_proto_test =\n      \"state: { level: 4  phase: TEST } \"\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"  exclude: { min_level: 2  phase: TRAIN } \"\n      \"} \";\n  this->RunFilterNetTest(input_proto_train, output_proto_train);\n  this->RunFilterNetTest(input_proto_test, output_proto_test);\n}\n\nTYPED_TEST(NetTest, TestReshape) {\n  typedef typename TypeParam::Dtype Dtype;\n  // We set up bottom blobs of two different sizes, switch between\n  // them, and check that forward and backward both run and the results\n  // are the same.\n  Caffe::set_random_seed(this->seed_);\n  Caffe::set_mode(Caffe::CPU);\n  FillerParameter filler_param;\n  filler_param.set_std(1);\n  GaussianFiller<Dtype> filler(filler_param);\n  Blob<Dtype> blob1(4, 3, 9, 11);\n  Blob<Dtype> blob2(2, 3, 12, 10);\n  filler.Fill(&blob1);\n  filler.Fill(&blob2);\n\n  this->InitReshapableNet();\n  Blob<Dtype>* input_blob = this->net_->input_blobs()[0];\n  Blob<Dtype>* output_blob = this->net_->output_blobs()[0];\n  input_blob->Reshape(blob1.num(), blob1.channels(), blob1.height(),\n      blob1.width());\n  caffe_copy(blob1.count(), blob1.cpu_data(), input_blob->mutable_cpu_data());\n  this->net_->ForwardPrefilled();\n  // call backward just to make sure it runs\n  this->net_->Backward();\n  Blob<Dtype> output1(output_blob->num(), output_blob->channels(),\n      output_blob->height(), output_blob->width());\n  caffe_copy(output1.count(), output_blob->cpu_data(),\n      output1.mutable_cpu_data());\n\n  input_blob->Reshape(blob2.num(), blob2.channels(), blob2.height(),\n      blob2.width());\n  caffe_copy(blob2.count(), blob2.cpu_data(), input_blob->mutable_cpu_data());\n  this->net_->ForwardPrefilled();\n  this->net_->Backward();\n  Blob<Dtype> output2(output_blob->num(), output_blob->channels(),\n      output_blob->height(), output_blob->width());\n  caffe_copy(output2.count(), output_blob->cpu_data(),\n      output2.mutable_cpu_data());\n\n  input_blob->Reshape(blob1.num(), blob1.channels(), blob1.height(),\n      blob1.width());\n  caffe_copy(blob1.count(), blob1.cpu_data(), input_blob->mutable_cpu_data());\n  this->net_->ForwardPrefilled();\n  this->net_->Backward();\n  for (int i = 0; i < output1.count(); ++i) {\n    CHECK_EQ(*(output1.cpu_data() + i), *(output_blob->cpu_data() + i));\n  }\n\n  input_blob->Reshape(blob2.num(), blob2.channels(), blob2.height(),\n      blob2.width());\n  caffe_copy(blob2.count(), blob2.cpu_data(), input_blob->mutable_cpu_data());\n  this->net_->ForwardPrefilled();\n  this->net_->Backward();\n  for (int i = 0; i < output2.count(); ++i) {\n    CHECK_EQ(*(output2.cpu_data() + i), *(output_blob->cpu_data() + i));\n  }\n}\n\nTYPED_TEST(NetTest, TestSkipPropagateDown) {\n  // check bottom_need_backward if propagate_down is true\n  this->InitSkipPropNet(false);\n  vector<bool> vec_layer_need_backward = this->net_->layer_need_backward();\n  for (int layer_id = 0; layer_id < this->net_->layers().size(); ++layer_id) {\n    string layer_name = this->net_->layer_names()[layer_id];\n    if (layer_name == \"loss\") {\n      // access to bottom_need_backward coresponding to label's blob\n      bool need_back = this->net_->bottom_need_backward()[layer_id][1];\n      // if propagate_down is true, the loss layer will try to\n      // backpropagate on labels\n      EXPECT_TRUE(need_back) << \"bottom_need_backward should be True\";\n    }\n    // layer_need_backward should be True except for data and silence layers\n    if (layer_name.find(\"data\") != std::string::npos ||\n          layer_name == \"silence\") {\n      EXPECT_FALSE(vec_layer_need_backward[layer_id])\n          << \"layer_need_backward for \" << layer_name << \" should be False\";\n    } else {\n      EXPECT_TRUE(vec_layer_need_backward[layer_id])\n          << \"layer_need_backward for \" << layer_name << \" should be True\";\n    }\n  }\n  // check bottom_need_backward if propagat_down is false\n  this->InitSkipPropNet(true);\n  vec_layer_need_backward.clear();\n  vec_layer_need_backward = this->net_->layer_need_backward();\n  for (int layer_id = 0; layer_id < this->net_->layers().size(); ++layer_id) {\n    string layer_name = this->net_->layer_names()[layer_id];\n    if (layer_name == \"loss\") {\n      // access to bottom_need_backward coresponding to label's blob\n      bool need_back = this->net_->bottom_need_backward()[layer_id][1];\n      // if propagate_down is false, the loss layer will not try to\n      // backpropagate on labels\n      EXPECT_FALSE(need_back) << \"bottom_need_backward should be False\";\n    }\n    // layer_need_backward should be False except for innerproduct and\n    // loss layers\n    if (layer_name == \"innerproduct\" || layer_name == \"loss\") {\n      EXPECT_TRUE(vec_layer_need_backward[layer_id])\n          << \"layer_need_backward for \" << layer_name << \" should be True\";\n    } else {\n      EXPECT_FALSE(vec_layer_need_backward[layer_id])\n          << \"layer_need_backward for \" << layer_name << \" should be False\";\n    }\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_neuron_layer.cpp",
    "content": "#include <algorithm>\n#include <cstring>\n#include <vector>\n\n#include \"google/protobuf/text_format.h\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass NeuronLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  NeuronLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    Caffe::set_random_seed(1701);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~NeuronLayerTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n\n  void TestDropoutForward(const float dropout_ratio) {\n    LayerParameter layer_param;\n    // Fill in the given dropout_ratio, unless it's 0.5, in which case we don't\n    // set it explicitly to test that 0.5 is the default.\n    if (dropout_ratio != 0.5) {\n      layer_param.mutable_dropout_param()->set_dropout_ratio(dropout_ratio);\n    }\n    DropoutLayer<Dtype> layer(layer_param);\n    layer_param.set_phase(TRAIN);\n    layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    // Now, check values\n    const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n    const Dtype* top_data = this->blob_top_->cpu_data();\n    float scale = 1. / (1. - layer_param.dropout_param().dropout_ratio());\n    const int count = this->blob_bottom_->count();\n    // Initialize num_kept to count the number of inputs NOT dropped out.\n    int num_kept = 0;\n    for (int i = 0; i < count; ++i) {\n      if (top_data[i] != 0) {\n        ++num_kept;\n        EXPECT_EQ(top_data[i], bottom_data[i] * scale);\n      }\n    }\n    const Dtype std_error = sqrt(dropout_ratio * (1 - dropout_ratio) / count);\n    // Fail if the number dropped was more than 1.96 * std_error away from the\n    // expected number -- requires 95% confidence that the dropout layer is not\n    // obeying the given dropout_ratio for test failure.\n    const Dtype empirical_dropout_ratio = 1 - num_kept / Dtype(count);\n    EXPECT_NEAR(empirical_dropout_ratio, dropout_ratio, 1.96 * std_error);\n  }\n\n  void TestExpForward(const float base, const float scale, const float shift) {\n    LayerParameter layer_param;\n    layer_param.mutable_exp_param()->set_base(base);\n    layer_param.mutable_exp_param()->set_scale(scale);\n    layer_param.mutable_exp_param()->set_shift(shift);\n    ExpLayer<Dtype> layer(layer_param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    layer.Forward(blob_bottom_vec_, blob_top_vec_);\n    const Dtype kDelta = 2e-4;\n    const Dtype* bottom_data = blob_bottom_->cpu_data();\n    const Dtype* top_data = blob_top_->cpu_data();\n    for (int i = 0; i < blob_bottom_->count(); ++i) {\n      const Dtype bottom_val = bottom_data[i];\n      const Dtype top_val = top_data[i];\n      if (base == -1) {\n        EXPECT_NEAR(top_val, exp(shift + scale * bottom_val), kDelta);\n      } else {\n        EXPECT_NEAR(top_val, pow(base, shift + scale * bottom_val), kDelta);\n      }\n    }\n  }\n\n  void TestExpGradient(const float base, const float scale, const float shift) {\n    LayerParameter layer_param;\n    layer_param.mutable_exp_param()->set_base(base);\n    layer_param.mutable_exp_param()->set_scale(scale);\n    layer_param.mutable_exp_param()->set_shift(shift);\n    ExpLayer<Dtype> layer(layer_param);\n    GradientChecker<Dtype> checker(1e-2, 1e-3);\n    checker.CheckGradientEltwise(&layer, blob_bottom_vec_, blob_top_vec_);\n  }\n\n  void TestPReLU(PReLULayer<Dtype> *layer) {\n    layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n    const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n    const Dtype* top_data = this->blob_top_->cpu_data();\n    const Dtype* slope_data = layer->blobs()[0]->cpu_data();\n    int hw = this->blob_bottom_->height() * this->blob_bottom_->width();\n    int channels = this->blob_bottom_->channels();\n    bool channel_shared = layer->layer_param().prelu_param().channel_shared();\n    for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n      int c = channel_shared ? 0 : (i / hw) % channels;\n      EXPECT_EQ(top_data[i],\n          std::max(bottom_data[i], (Dtype)(0))\n          + slope_data[c] * std::min(bottom_data[i], (Dtype)(0)));\n    }\n  }\n\n  void LogBottomInit() {\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    Dtype* bottom_data = this->blob_bottom_->mutable_cpu_data();\n    caffe_exp(this->blob_bottom_->count(), bottom_data, bottom_data);\n  }\n\n  void TestLogForward(const float base, const float scale, const float shift) {\n    LogBottomInit();\n    LayerParameter layer_param;\n    layer_param.mutable_log_param()->set_base(base);\n    layer_param.mutable_log_param()->set_scale(scale);\n    layer_param.mutable_log_param()->set_shift(shift);\n    LogLayer<Dtype> layer(layer_param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    layer.Forward(blob_bottom_vec_, blob_top_vec_);\n    const Dtype kDelta = 2e-4;\n    const Dtype* bottom_data = blob_bottom_->cpu_data();\n    const Dtype* top_data = blob_top_->cpu_data();\n    for (int i = 0; i < blob_bottom_->count(); ++i) {\n      const Dtype bottom_val = bottom_data[i];\n      const Dtype top_val = top_data[i];\n      if (base == -1) {\n        EXPECT_NEAR(top_val, log(shift + scale * bottom_val), kDelta);\n      } else {\n        EXPECT_NEAR(top_val, log(shift + scale * bottom_val) / log(base),\n                    kDelta);\n      }\n    }\n  }\n\n  void TestLogGradient(const float base, const float scale, const float shift) {\n    LogBottomInit();\n    LayerParameter layer_param;\n    layer_param.mutable_log_param()->set_base(base);\n    layer_param.mutable_log_param()->set_scale(scale);\n    layer_param.mutable_log_param()->set_shift(shift);\n    LogLayer<Dtype> layer(layer_param);\n    GradientChecker<Dtype> checker(1e-2, 1e-2);\n    checker.CheckGradientEltwise(&layer, blob_bottom_vec_, blob_top_vec_);\n  }\n};\n\nTYPED_TEST_CASE(NeuronLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(NeuronLayerTest, TestAbsVal) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  AbsValLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n  const Dtype* top_data    = this->blob_top_->cpu_data();\n  const int count = this->blob_bottom_->count();\n  for (int i = 0; i < count; ++i) {\n    EXPECT_EQ(top_data[i], fabs(bottom_data[i]));\n  }\n}\n\nTYPED_TEST(NeuronLayerTest, TestAbsGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  AbsValLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3, 1701, 0., 0.01);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestReLU) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ReLULayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_GE(top_data[i], 0.);\n    EXPECT_TRUE(top_data[i] == 0 || top_data[i] == bottom_data[i]);\n  }\n}\n\nTYPED_TEST(NeuronLayerTest, TestReLUGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ReLULayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3, 1701, 0., 0.01);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestReLUWithNegativeSlope) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  CHECK(google::protobuf::TextFormat::ParseFromString(\n      \"relu_param { negative_slope: 0.01 }\", &layer_param));\n  ReLULayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    if (top_data[i] >= 0) {\n      EXPECT_FLOAT_EQ(top_data[i], bottom_data[i]);\n    } else {\n      EXPECT_FLOAT_EQ(top_data[i], bottom_data[i] * 0.01);\n    }\n  }\n}\n\nTYPED_TEST(NeuronLayerTest, TestReLUGradientWithNegativeSlope) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  CHECK(google::protobuf::TextFormat::ParseFromString(\n      \"relu_param { negative_slope: 0.01 }\", &layer_param));\n  ReLULayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3, 1701, 0., 0.01);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestSigmoid) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  SigmoidLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_FLOAT_EQ(top_data[i], 1. / (1 + exp(-bottom_data[i])));\n    // check that we squashed the value between 0 and 1\n    EXPECT_GE(top_data[i], 0.);\n    EXPECT_LE(top_data[i], 1.);\n  }\n}\n\nTYPED_TEST(NeuronLayerTest, TestSigmoidGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  SigmoidLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3, 1701, 0., 0.01);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestTanH) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  TanHLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Test exact values\n  for (int i = 0; i < this->blob_bottom_->num(); ++i) {\n    for (int j = 0; j < this->blob_bottom_->channels(); ++j) {\n      for (int k = 0; k < this->blob_bottom_->height(); ++k) {\n        for (int l = 0; l < this->blob_bottom_->width(); ++l) {\n          EXPECT_GE(this->blob_top_->data_at(i, j, k, l) + 1e-4,\n             (exp(2*this->blob_bottom_->data_at(i, j, k, l)) - 1) /\n             (exp(2*this->blob_bottom_->data_at(i, j, k, l)) + 1));\n          EXPECT_LE(this->blob_top_->data_at(i, j, k, l) - 1e-4,\n             (exp(2*this->blob_bottom_->data_at(i, j, k, l)) - 1) /\n             (exp(2*this->blob_bottom_->data_at(i, j, k, l)) + 1));\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(NeuronLayerTest, TestTanHGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  TanHLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpLayer) {\n  typedef typename TypeParam::Dtype Dtype;\n  // Test default base of \"-1\" -- should actually set base := e.\n  const Dtype kBase = -1;\n  const Dtype kScale = 1;\n  const Dtype kShift = 0;\n  this->TestExpForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  // Test default base of \"-1\" -- should actually set base := e.\n  const Dtype kBase = -1;\n  const Dtype kScale = 1;\n  const Dtype kShift = 0;\n  this->TestExpGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpLayerBase2) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 1;\n  const Dtype kShift = 0;\n  this->TestExpForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpGradientBase2) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 1;\n  const Dtype kShift = 0;\n  this->TestExpGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpLayerBase2Shift1) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 1;\n  const Dtype kShift = 1;\n  this->TestExpForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpGradientBase2Shift1) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 1;\n  const Dtype kShift = 1;\n  this->TestExpGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpLayerBase2Scale3) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 3;\n  const Dtype kShift = 0;\n  this->TestExpForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpGradientBase2Scale3) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 3;\n  const Dtype kShift = 0;\n  this->TestExpGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpLayerBase2Shift1Scale3) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 3;\n  const Dtype kShift = 1;\n  this->TestExpForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestExpGradientBase2Shift1Scale3) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 3;\n  const Dtype kShift = 1;\n  this->TestExpGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogLayer) {\n  typedef typename TypeParam::Dtype Dtype;\n  // Test default base of \"-1\" -- should actually set base := e.\n  const Dtype kBase = -1;\n  const Dtype kScale = 1;\n  const Dtype kShift = 0;\n  this->TestLogForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  // Test default base of \"-1\" -- should actually set base := e.\n  const Dtype kBase = -1;\n  const Dtype kScale = 1;\n  const Dtype kShift = 0;\n  this->TestLogGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogLayerBase2) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 1;\n  const Dtype kShift = 0;\n  this->TestLogForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogGradientBase2) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 1;\n  const Dtype kShift = 0;\n  this->TestLogGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogLayerBase2Shift1) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 1;\n  const Dtype kShift = 1;\n  this->TestLogForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogGradientBase2Shift1) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 1;\n  const Dtype kShift = 1;\n  this->TestLogGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogLayerBase2Scale3) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 3;\n  const Dtype kShift = 0;\n  this->TestLogForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogGradientBase2Scale3) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 3;\n  const Dtype kShift = 0;\n  this->TestLogGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogLayerBase2Shift1Scale3) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 3;\n  const Dtype kShift = 1;\n  this->TestLogForward(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestLogGradientBase2Shift1Scale3) {\n  typedef typename TypeParam::Dtype Dtype;\n  const Dtype kBase = 2;\n  const Dtype kScale = 3;\n  const Dtype kShift = 1;\n  this->TestLogGradient(kBase, kScale, kShift);\n}\n\nTYPED_TEST(NeuronLayerTest, TestDropoutHalf) {\n  const float kDropoutRatio = 0.5;\n  this->TestDropoutForward(kDropoutRatio);\n}\n\nTYPED_TEST(NeuronLayerTest, TestDropoutThreeQuarters) {\n  const float kDropoutRatio = 0.75;\n  this->TestDropoutForward(kDropoutRatio);\n}\n\nTYPED_TEST(NeuronLayerTest, TestDropoutTestPhase) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.set_phase(TEST);\n  DropoutLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    if (top_data[i] != 0) {\n      EXPECT_EQ(top_data[i], bottom_data[i]);\n    }\n  }\n}\n\nTYPED_TEST(NeuronLayerTest, TestDropoutGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.set_phase(TRAIN);\n  DropoutLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestDropoutGradientTest) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.set_phase(TEST);\n  DropoutLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestBNLL) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  BNLLLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_GE(top_data[i], 0.);\n    EXPECT_GE(top_data[i], bottom_data[i]);\n  }\n}\n\nTYPED_TEST(NeuronLayerTest, TestBNLLGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  BNLLLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestPReLUParam) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PReLULayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  const Dtype* slopes = layer.blobs()[0]->cpu_data();\n  int count = layer.blobs()[0]->count();\n  for (int i = 0; i < count; ++i, ++slopes) {\n    EXPECT_EQ(*slopes, 0.25);\n  }\n}\n\nTYPED_TEST(NeuronLayerTest, TestPReLUForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PReLULayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  FillerParameter filler_param;\n  GaussianFiller<Dtype> filler(filler_param);\n  filler.Fill(layer.blobs()[0].get());\n  this->TestPReLU(&layer);\n}\n\nTYPED_TEST(NeuronLayerTest, TestPReLUForwardChannelShared) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_prelu_param()->set_channel_shared(true);\n  PReLULayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  this->TestPReLU(&layer);\n}\n\nTYPED_TEST(NeuronLayerTest, TestPReLUGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PReLULayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  FillerParameter filler_param;\n  GaussianFiller<Dtype> filler(filler_param);\n  filler.Fill(layer.blobs()[0].get());\n  GradientChecker<Dtype> checker(1e-2, 1e-3, 1701, 0., 0.01);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestPReLUGradientChannelShared) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_prelu_param()->set_channel_shared(true);\n  PReLULayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  GradientChecker<Dtype> checker(1e-2, 1e-3, 1701, 0., 0.01);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(NeuronLayerTest, TestPReLUConsistencyReLU) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter prelu_layer_param;\n  LayerParameter relu_layer_param;\n  relu_layer_param.mutable_relu_param()->set_negative_slope(0.25);\n  PReLULayer<Dtype> prelu(prelu_layer_param);\n  ReLULayer<Dtype> relu(relu_layer_param);\n  // Set up blobs\n  vector<Blob<Dtype>*> blob_bottom_vec_2;\n  vector<Blob<Dtype>*> blob_top_vec_2;\n  shared_ptr<Blob<Dtype> > blob_bottom_2(new Blob<Dtype>());\n  shared_ptr<Blob<Dtype> > blob_top_2(new Blob<Dtype>());\n  blob_bottom_vec_2.push_back(blob_bottom_2.get());\n  blob_top_vec_2.push_back(blob_top_2.get());\n  blob_bottom_2->CopyFrom(*this->blob_bottom_, false, true);\n  // SetUp layers\n  prelu.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  relu.SetUp(blob_bottom_vec_2, blob_top_vec_2);\n  // Check forward\n  prelu.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  relu.Forward(this->blob_bottom_vec_, blob_top_vec_2);\n  for (int s = 0; s < blob_top_2->count(); ++s) {\n    EXPECT_EQ(this->blob_top_->cpu_data()[s], blob_top_2->cpu_data()[s]);\n  }\n  // Check backward\n  shared_ptr<Blob<Dtype> > tmp_blob(new Blob<Dtype>());\n  tmp_blob->ReshapeLike(*blob_top_2.get());\n  FillerParameter filler_param;\n  GaussianFiller<Dtype> filler(filler_param);\n  filler.Fill(tmp_blob.get());\n  caffe_copy(blob_top_2->count(), tmp_blob->cpu_data(),\n      this->blob_top_->mutable_cpu_diff());\n  caffe_copy(blob_top_2->count(), tmp_blob->cpu_data(),\n      blob_top_2->mutable_cpu_diff());\n  vector<bool> propagate_down;\n  propagate_down.push_back(true);\n  prelu.Backward(this->blob_top_vec_, propagate_down, this->blob_bottom_vec_);\n  relu.Backward(blob_top_vec_2, propagate_down, blob_bottom_vec_2);\n  for (int s = 0; s < blob_bottom_2->count(); ++s) {\n    EXPECT_EQ(this->blob_bottom_->cpu_diff()[s], blob_bottom_2->cpu_diff()[s]);\n  }\n}\n\nTYPED_TEST(NeuronLayerTest, TestPReLUInPlace) {\n  typedef typename TypeParam::Dtype Dtype;\n  // Set layer parameters\n  LayerParameter ip_layer_param;\n  LayerParameter prelu_layer_param;\n  InnerProductParameter *ip_param =\n      ip_layer_param.mutable_inner_product_param();\n  ip_param->mutable_weight_filler()->set_type(\"gaussian\");\n  ip_param->set_num_output(3);\n  InnerProductLayer<Dtype> ip(ip_layer_param);\n  PReLULayer<Dtype> prelu(prelu_layer_param);\n  InnerProductLayer<Dtype> ip2(ip_layer_param);\n  PReLULayer<Dtype> prelu2(prelu_layer_param);\n  // Set up blobs\n  vector<Blob<Dtype>*> blob_bottom_vec_2;\n  vector<Blob<Dtype>*> blob_middle_vec_2;\n  vector<Blob<Dtype>*> blob_top_vec_2;\n  shared_ptr<Blob<Dtype> > blob_bottom_2(new Blob<Dtype>());\n  shared_ptr<Blob<Dtype> > blob_middle_2(new Blob<Dtype>());\n  shared_ptr<Blob<Dtype> > blob_top_2(new Blob<Dtype>());\n  blob_bottom_vec_2.push_back(blob_bottom_2.get());\n  blob_middle_vec_2.push_back(blob_middle_2.get());\n  blob_top_vec_2.push_back(blob_top_2.get());\n  blob_bottom_2->CopyFrom(*this->blob_bottom_, false, true);\n  // SetUp layers\n  ip.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  prelu.SetUp(this->blob_top_vec_, this->blob_top_vec_);\n  ip2.SetUp(blob_bottom_vec_2, blob_middle_vec_2);\n  prelu2.SetUp(blob_middle_vec_2, blob_top_vec_2);\n  caffe_copy(ip2.blobs()[0]->count(), ip.blobs()[0]->cpu_data(),\n      ip2.blobs()[0]->mutable_cpu_data());\n  // Forward in-place\n  ip.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  prelu.Forward(this->blob_top_vec_, this->blob_top_vec_);\n  // Forward non-in-place\n  ip2.Forward(blob_bottom_vec_2, blob_middle_vec_2);\n  prelu2.Forward(blob_middle_vec_2, blob_top_vec_2);\n  // Check numbers\n  for (int s = 0; s < blob_top_2->count(); ++s) {\n    EXPECT_EQ(this->blob_top_->cpu_data()[s], blob_top_2->cpu_data()[s]);\n  }\n  // Fill top diff with random numbers\n  shared_ptr<Blob<Dtype> > tmp_blob(new Blob<Dtype>());\n  tmp_blob->ReshapeLike(*blob_top_2.get());\n  FillerParameter filler_param;\n  GaussianFiller<Dtype> filler(filler_param);\n  filler.Fill(tmp_blob.get());\n  caffe_copy(blob_top_2->count(), tmp_blob->cpu_data(),\n      this->blob_top_->mutable_cpu_diff());\n  caffe_copy(blob_top_2->count(), tmp_blob->cpu_data(),\n      blob_top_2->mutable_cpu_diff());\n  // Backward in-place\n  vector<bool> propagate_down;\n  propagate_down.push_back(true);\n  prelu.Backward(this->blob_top_vec_, propagate_down, this->blob_top_vec_);\n  ip.Backward(this->blob_top_vec_, propagate_down, this->blob_bottom_vec_);\n  // Backward non-in-place\n  prelu2.Backward(blob_top_vec_2, propagate_down, blob_middle_vec_2);\n  ip2.Backward(blob_middle_vec_2, propagate_down, blob_bottom_vec_2);\n  // Check numbers\n  for (int s = 0; s < blob_bottom_2->count(); ++s) {\n    EXPECT_EQ(this->blob_bottom_->cpu_diff()[s], blob_bottom_2->cpu_diff()[s]);\n  }\n  for (int s = 0; s < ip.blobs()[0]->count(); ++s) {\n    EXPECT_EQ(ip.blobs()[0]->cpu_diff()[s], ip2.blobs()[0]->cpu_diff()[s]);\n  }\n  for (int s = 0; s < ip.blobs()[1]->count(); ++s) {\n    EXPECT_EQ(ip.blobs()[1]->cpu_diff()[s], ip2.blobs()[1]->cpu_diff()[s]);\n  }\n  for (int s = 0; s < prelu.blobs()[0]->count(); ++s) {\n    EXPECT_EQ(prelu.blobs()[0]->cpu_diff()[s],\n        prelu2.blobs()[0]->cpu_diff()[s]);\n  }\n}\n\n#ifdef USE_CUDNN\ntemplate <typename Dtype>\nclass CuDNNNeuronLayerTest : public GPUDeviceTest<Dtype> {\n protected:\n  CuDNNNeuronLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    Caffe::set_random_seed(1701);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~CuDNNNeuronLayerTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(CuDNNNeuronLayerTest, TestDtypes);\n\nTYPED_TEST(CuDNNNeuronLayerTest, TestReLUCuDNN) {\n  LayerParameter layer_param;\n  CuDNNReLULayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const TypeParam* bottom_data = this->blob_bottom_->cpu_data();\n  const TypeParam* top_data = this->blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_GE(top_data[i], 0.);\n    EXPECT_TRUE(top_data[i] == 0 || top_data[i] == bottom_data[i]);\n  }\n}\n\nTYPED_TEST(CuDNNNeuronLayerTest, TestReLUGradientCuDNN) {\n  LayerParameter layer_param;\n  CuDNNReLULayer<TypeParam> layer(layer_param);\n  GradientChecker<TypeParam> checker(1e-2, 1e-3, 1701, 0., 0.01);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(CuDNNNeuronLayerTest, TestReLUWithNegativeSlopeCuDNN) {\n  LayerParameter layer_param;\n  CHECK(google::protobuf::TextFormat::ParseFromString(\n      \"relu_param { negative_slope: 0.01 }\", &layer_param));\n  CuDNNReLULayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const TypeParam* bottom_data = this->blob_bottom_->cpu_data();\n  const TypeParam* top_data = this->blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    if (top_data[i] >= 0) {\n      EXPECT_FLOAT_EQ(top_data[i], bottom_data[i]);\n    } else {\n      EXPECT_FLOAT_EQ(top_data[i], bottom_data[i] * 0.01);\n    }\n  }\n}\n\nTYPED_TEST(CuDNNNeuronLayerTest, TestReLUGradientWithNegativeSlopeCuDNN) {\n  LayerParameter layer_param;\n  CHECK(google::protobuf::TextFormat::ParseFromString(\n      \"relu_param { negative_slope: 0.01 }\", &layer_param));\n  CuDNNReLULayer<TypeParam> layer(layer_param);\n  GradientChecker<TypeParam> checker(1e-2, 1e-3, 1701, 0., 0.01);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(CuDNNNeuronLayerTest, TestSigmoidCuDNN) {\n  LayerParameter layer_param;\n  CuDNNSigmoidLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const TypeParam* bottom_data = this->blob_bottom_->cpu_data();\n  const TypeParam* top_data = this->blob_top_->cpu_data();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_FLOAT_EQ(top_data[i], 1. / (1 + exp(-bottom_data[i])));\n    // check that we squashed the value between 0 and 1\n    EXPECT_GE(top_data[i], 0.);\n    EXPECT_LE(top_data[i], 1.);\n  }\n}\n\nTYPED_TEST(CuDNNNeuronLayerTest, TestSigmoidGradientCuDNN) {\n  LayerParameter layer_param;\n  CuDNNSigmoidLayer<TypeParam> layer(layer_param);\n  GradientChecker<TypeParam> checker(1e-2, 1e-3, 1701, 0., 0.01);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\nTYPED_TEST(CuDNNNeuronLayerTest, TestTanHCuDNN) {\n  LayerParameter layer_param;\n  CuDNNTanHLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Test exact values\n  for (int i = 0; i < this->blob_bottom_->num(); ++i) {\n    for (int j = 0; j < this->blob_bottom_->channels(); ++j) {\n      for (int k = 0; k < this->blob_bottom_->height(); ++k) {\n        for (int l = 0; l < this->blob_bottom_->width(); ++l) {\n          EXPECT_GE(this->blob_top_->data_at(i, j, k, l) + 1e-4,\n             (exp(2*this->blob_bottom_->data_at(i, j, k, l)) - 1) /\n             (exp(2*this->blob_bottom_->data_at(i, j, k, l)) + 1));\n          EXPECT_LE(this->blob_top_->data_at(i, j, k, l) - 1e-4,\n             (exp(2*this->blob_bottom_->data_at(i, j, k, l)) - 1) /\n             (exp(2*this->blob_bottom_->data_at(i, j, k, l)) + 1));\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(CuDNNNeuronLayerTest, TestTanHGradientCuDNN) {\n  LayerParameter layer_param;\n  CuDNNTanHLayer<TypeParam> layer(layer_param);\n  GradientChecker<TypeParam> checker(1e-2, 1e-3);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n#endif\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_platform.cpp",
    "content": "#ifndef CPU_ONLY\n\n#include <cstdio>\n#include <cstdlib>\n\n#include \"glog/logging.h\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nextern cudaDeviceProp CAFFE_TEST_CUDA_PROP;\n\nclass PlatformTest : public ::testing::Test {};\n\nTEST_F(PlatformTest, TestInitialization) {\n  printf(\"Major revision number:         %d\\n\",  CAFFE_TEST_CUDA_PROP.major);\n  printf(\"Minor revision number:         %d\\n\",  CAFFE_TEST_CUDA_PROP.minor);\n  printf(\"Name:                          %s\\n\",  CAFFE_TEST_CUDA_PROP.name);\n  printf(\"Total global memory:           %lu\\n\",\n         CAFFE_TEST_CUDA_PROP.totalGlobalMem);\n  printf(\"Total shared memory per block: %lu\\n\",\n         CAFFE_TEST_CUDA_PROP.sharedMemPerBlock);\n  printf(\"Total registers per block:     %d\\n\",\n         CAFFE_TEST_CUDA_PROP.regsPerBlock);\n  printf(\"Warp size:                     %d\\n\",\n         CAFFE_TEST_CUDA_PROP.warpSize);\n  printf(\"Maximum memory pitch:          %lu\\n\",\n         CAFFE_TEST_CUDA_PROP.memPitch);\n  printf(\"Maximum threads per block:     %d\\n\",\n         CAFFE_TEST_CUDA_PROP.maxThreadsPerBlock);\n  for (int i = 0; i < 3; ++i)\n    printf(\"Maximum dimension %d of block:  %d\\n\", i,\n           CAFFE_TEST_CUDA_PROP.maxThreadsDim[i]);\n  for (int i = 0; i < 3; ++i)\n    printf(\"Maximum dimension %d of grid:   %d\\n\", i,\n           CAFFE_TEST_CUDA_PROP.maxGridSize[i]);\n  printf(\"Clock rate:                    %d\\n\", CAFFE_TEST_CUDA_PROP.clockRate);\n  printf(\"Total constant memory:         %lu\\n\",\n         CAFFE_TEST_CUDA_PROP.totalConstMem);\n  printf(\"Texture alignment:             %lu\\n\",\n         CAFFE_TEST_CUDA_PROP.textureAlignment);\n  printf(\"Concurrent copy and execution: %s\\n\",\n         (CAFFE_TEST_CUDA_PROP.deviceOverlap ? \"Yes\" : \"No\"));\n  printf(\"Number of multiprocessors:     %d\\n\",\n         CAFFE_TEST_CUDA_PROP.multiProcessorCount);\n  printf(\"Kernel execution timeout:      %s\\n\",\n         (CAFFE_TEST_CUDA_PROP.kernelExecTimeoutEnabled ? \"Yes\" : \"No\"));\n  printf(\"Unified virtual addressing:    %s\\n\",\n         (CAFFE_TEST_CUDA_PROP.unifiedAddressing ? \"Yes\" : \"No\"));\n  EXPECT_TRUE(true);\n}\n\n}  // namespace caffe\n\n#endif  // CPU_ONLY\n"
  },
  {
    "path": "src/caffe/test/test_pooling_layer.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass PoolingLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  PoolingLayerTest()\n      : blob_bottom_(new Blob<Dtype>()),\n        blob_top_(new Blob<Dtype>()),\n        blob_top_mask_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    Caffe::set_random_seed(1701);\n    blob_bottom_->Reshape(2, 3, 6, 5);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~PoolingLayerTest() {\n    delete blob_bottom_;\n    delete blob_top_;\n    delete blob_top_mask_;\n  }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  Blob<Dtype>* const blob_top_mask_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n  // Test for 2x 2 square pooling layer\n  void TestForwardSquare() {\n    LayerParameter layer_param;\n    PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n    pooling_param->set_kernel_size(2);\n    pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n    const int num = 2;\n    const int channels = 2;\n    blob_bottom_->Reshape(num, channels, 3, 5);\n    // Input: 2x 2 channels of:\n    //     [1 2 5 2 3]\n    //     [9 4 1 4 8]\n    //     [1 2 5 2 3]\n    for (int i = 0; i < 15 * num * channels; i += 15) {\n      blob_bottom_->mutable_cpu_data()[i +  0] = 1;\n      blob_bottom_->mutable_cpu_data()[i +  1] = 2;\n      blob_bottom_->mutable_cpu_data()[i +  2] = 5;\n      blob_bottom_->mutable_cpu_data()[i +  3] = 2;\n      blob_bottom_->mutable_cpu_data()[i +  4] = 3;\n      blob_bottom_->mutable_cpu_data()[i +  5] = 9;\n      blob_bottom_->mutable_cpu_data()[i +  6] = 4;\n      blob_bottom_->mutable_cpu_data()[i +  7] = 1;\n      blob_bottom_->mutable_cpu_data()[i +  8] = 4;\n      blob_bottom_->mutable_cpu_data()[i +  9] = 8;\n      blob_bottom_->mutable_cpu_data()[i + 10] = 1;\n      blob_bottom_->mutable_cpu_data()[i + 11] = 2;\n      blob_bottom_->mutable_cpu_data()[i + 12] = 5;\n      blob_bottom_->mutable_cpu_data()[i + 13] = 2;\n      blob_bottom_->mutable_cpu_data()[i + 14] = 3;\n    }\n    PoolingLayer<Dtype> layer(layer_param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    EXPECT_EQ(blob_top_->num(), num);\n    EXPECT_EQ(blob_top_->channels(), channels);\n    EXPECT_EQ(blob_top_->height(), 2);\n    EXPECT_EQ(blob_top_->width(), 4);\n    if (blob_top_vec_.size() > 1) {\n      EXPECT_EQ(blob_top_mask_->num(), num);\n      EXPECT_EQ(blob_top_mask_->channels(), channels);\n      EXPECT_EQ(blob_top_mask_->height(), 2);\n      EXPECT_EQ(blob_top_mask_->width(), 4);\n    }\n    layer.Forward(blob_bottom_vec_, blob_top_vec_);\n    // Expected output: 2x 2 channels of:\n    //     [9 5 5 8]\n    //     [9 5 5 8]\n    for (int i = 0; i < 8 * num * channels; i += 8) {\n      EXPECT_EQ(blob_top_->cpu_data()[i + 0], 9);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 1], 5);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 2], 5);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 3], 8);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 4], 9);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 5], 5);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 6], 5);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 7], 8);\n    }\n    if (blob_top_vec_.size() > 1) {\n      // Expected mask output: 2x 2 channels of:\n      //     [5  2  2 9]\n      //     [5 12 12 9]\n      for (int i = 0; i < 8 * num * channels; i += 8) {\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 0],  5);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 1],  2);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 2],  2);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 3],  9);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 4],  5);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 5], 12);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 6], 12);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 7],  9);\n      }\n    }\n  }\n  // Test for 3x 2 rectangular pooling layer with kernel_h > kernel_w\n  void TestForwardRectHigh() {\n    LayerParameter layer_param;\n    PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n    pooling_param->set_kernel_h(3);\n    pooling_param->set_kernel_w(2);\n    pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n    const int num = 2;\n    const int channels = 2;\n    blob_bottom_->Reshape(num, channels, 6, 6);\n    // Input: 2x 2 channels of:\n    // [35     1     6    26    19    24]\n    // [ 3    32     7    21    23    25]\n    // [31     9     2    22    27    20]\n    // [ 8    28    33    17    10    15]\n    // [30     5    34    12    14    16]\n    // [ 4    36    29    13    18    11]\n    // (this is generated by magic(6) in MATLAB)\n    for (int i = 0; i < 36 * num * channels; i += 36) {\n      blob_bottom_->mutable_cpu_data()[i +  0] = 35;\n      blob_bottom_->mutable_cpu_data()[i +  1] = 1;\n      blob_bottom_->mutable_cpu_data()[i +  2] = 6;\n      blob_bottom_->mutable_cpu_data()[i +  3] = 26;\n      blob_bottom_->mutable_cpu_data()[i +  4] = 19;\n      blob_bottom_->mutable_cpu_data()[i +  5] = 24;\n      blob_bottom_->mutable_cpu_data()[i +  6] = 3;\n      blob_bottom_->mutable_cpu_data()[i +  7] = 32;\n      blob_bottom_->mutable_cpu_data()[i +  8] = 7;\n      blob_bottom_->mutable_cpu_data()[i +  9] = 21;\n      blob_bottom_->mutable_cpu_data()[i + 10] = 23;\n      blob_bottom_->mutable_cpu_data()[i + 11] = 25;\n      blob_bottom_->mutable_cpu_data()[i + 12] = 31;\n      blob_bottom_->mutable_cpu_data()[i + 13] = 9;\n      blob_bottom_->mutable_cpu_data()[i + 14] = 2;\n      blob_bottom_->mutable_cpu_data()[i + 15] = 22;\n      blob_bottom_->mutable_cpu_data()[i + 16] = 27;\n      blob_bottom_->mutable_cpu_data()[i + 17] = 20;\n      blob_bottom_->mutable_cpu_data()[i + 18] = 8;\n      blob_bottom_->mutable_cpu_data()[i + 19] = 28;\n      blob_bottom_->mutable_cpu_data()[i + 20] = 33;\n      blob_bottom_->mutable_cpu_data()[i + 21] = 17;\n      blob_bottom_->mutable_cpu_data()[i + 22] = 10;\n      blob_bottom_->mutable_cpu_data()[i + 23] = 15;\n      blob_bottom_->mutable_cpu_data()[i + 24] = 30;\n      blob_bottom_->mutable_cpu_data()[i + 25] = 5;\n      blob_bottom_->mutable_cpu_data()[i + 26] = 34;\n      blob_bottom_->mutable_cpu_data()[i + 27] = 12;\n      blob_bottom_->mutable_cpu_data()[i + 28] = 14;\n      blob_bottom_->mutable_cpu_data()[i + 29] = 16;\n      blob_bottom_->mutable_cpu_data()[i + 30] = 4;\n      blob_bottom_->mutable_cpu_data()[i + 31] = 36;\n      blob_bottom_->mutable_cpu_data()[i + 32] = 29;\n      blob_bottom_->mutable_cpu_data()[i + 33] = 13;\n      blob_bottom_->mutable_cpu_data()[i + 34] = 18;\n      blob_bottom_->mutable_cpu_data()[i + 35] = 11;\n    }\n    PoolingLayer<Dtype> layer(layer_param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    EXPECT_EQ(blob_top_->num(), num);\n    EXPECT_EQ(blob_top_->channels(), channels);\n    EXPECT_EQ(blob_top_->height(), 4);\n    EXPECT_EQ(blob_top_->width(), 5);\n    if (blob_top_vec_.size() > 1) {\n      EXPECT_EQ(blob_top_mask_->num(), num);\n      EXPECT_EQ(blob_top_mask_->channels(), channels);\n      EXPECT_EQ(blob_top_mask_->height(), 4);\n      EXPECT_EQ(blob_top_mask_->width(), 5);\n    }\n    layer.Forward(blob_bottom_vec_, blob_top_vec_);\n    // Expected output: 2x 2 channels of:\n    // [35    32    26    27    27]\n    // [32    33    33    27    27]\n    // [31    34    34    27    27]\n    // [36    36    34    18    18]\n    for (int i = 0; i < 20 * num * channels; i += 20) {\n      EXPECT_EQ(blob_top_->cpu_data()[i +  0], 35);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  1], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  2], 26);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  3], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  4], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  5], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  6], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  7], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  8], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  9], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 10], 31);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 11], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 12], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 13], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 14], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 15], 36);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 16], 36);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 17], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 18], 18);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 19], 18);\n    }\n    if (blob_top_vec_.size() > 1) {\n        // [ 1     8     4    17    17]\n        // [ 8    21    21    17    17]\n        // [13    27    27    17    17]\n        // [32    32    27    35    35]\n      for (int i = 0; i < 20 * num * channels; i += 20) {\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  0],  0);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  1],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  2],  3);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  3], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  4], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  5],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  6], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  7], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  8], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  9], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 10], 12);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 11], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 12], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 13], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 14], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 15], 31);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 16], 31);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 17], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 18], 34);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 19], 34);\n      }\n    }\n  }\n  // Test for rectangular pooling layer with kernel_w > kernel_h\n  void TestForwardRectWide() {\n    LayerParameter layer_param;\n    PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n    pooling_param->set_kernel_h(2);\n    pooling_param->set_kernel_w(3);\n    pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n    const int num = 2;\n    const int channels = 2;\n    blob_bottom_->Reshape(num, channels, 6, 6);\n    // Input: 2x 2 channels of:\n    // [35     1     6    26    19    24]\n    // [ 3    32     7    21    23    25]\n    // [31     9     2    22    27    20]\n    // [ 8    28    33    17    10    15]\n    // [30     5    34    12    14    16]\n    // [ 4    36    29    13    18    11]\n    // (this is generated by magic(6) in MATLAB)\n    for (int i = 0; i < 36 * num * channels; i += 36) {\n      blob_bottom_->mutable_cpu_data()[i +  0] = 35;\n      blob_bottom_->mutable_cpu_data()[i +  1] = 1;\n      blob_bottom_->mutable_cpu_data()[i +  2] = 6;\n      blob_bottom_->mutable_cpu_data()[i +  3] = 26;\n      blob_bottom_->mutable_cpu_data()[i +  4] = 19;\n      blob_bottom_->mutable_cpu_data()[i +  5] = 24;\n      blob_bottom_->mutable_cpu_data()[i +  6] = 3;\n      blob_bottom_->mutable_cpu_data()[i +  7] = 32;\n      blob_bottom_->mutable_cpu_data()[i +  8] = 7;\n      blob_bottom_->mutable_cpu_data()[i +  9] = 21;\n      blob_bottom_->mutable_cpu_data()[i + 10] = 23;\n      blob_bottom_->mutable_cpu_data()[i + 11] = 25;\n      blob_bottom_->mutable_cpu_data()[i + 12] = 31;\n      blob_bottom_->mutable_cpu_data()[i + 13] = 9;\n      blob_bottom_->mutable_cpu_data()[i + 14] = 2;\n      blob_bottom_->mutable_cpu_data()[i + 15] = 22;\n      blob_bottom_->mutable_cpu_data()[i + 16] = 27;\n      blob_bottom_->mutable_cpu_data()[i + 17] = 20;\n      blob_bottom_->mutable_cpu_data()[i + 18] = 8;\n      blob_bottom_->mutable_cpu_data()[i + 19] = 28;\n      blob_bottom_->mutable_cpu_data()[i + 20] = 33;\n      blob_bottom_->mutable_cpu_data()[i + 21] = 17;\n      blob_bottom_->mutable_cpu_data()[i + 22] = 10;\n      blob_bottom_->mutable_cpu_data()[i + 23] = 15;\n      blob_bottom_->mutable_cpu_data()[i + 24] = 30;\n      blob_bottom_->mutable_cpu_data()[i + 25] = 5;\n      blob_bottom_->mutable_cpu_data()[i + 26] = 34;\n      blob_bottom_->mutable_cpu_data()[i + 27] = 12;\n      blob_bottom_->mutable_cpu_data()[i + 28] = 14;\n      blob_bottom_->mutable_cpu_data()[i + 29] = 16;\n      blob_bottom_->mutable_cpu_data()[i + 30] = 4;\n      blob_bottom_->mutable_cpu_data()[i + 31] = 36;\n      blob_bottom_->mutable_cpu_data()[i + 32] = 29;\n      blob_bottom_->mutable_cpu_data()[i + 33] = 13;\n      blob_bottom_->mutable_cpu_data()[i + 34] = 18;\n      blob_bottom_->mutable_cpu_data()[i + 35] = 11;\n    }\n    PoolingLayer<Dtype> layer(layer_param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    EXPECT_EQ(blob_top_->num(), num);\n    EXPECT_EQ(blob_top_->channels(), channels);\n    EXPECT_EQ(blob_top_->height(), 5);\n    EXPECT_EQ(blob_top_->width(), 4);\n    if (blob_top_vec_.size() > 1) {\n      EXPECT_EQ(blob_top_mask_->num(), num);\n      EXPECT_EQ(blob_top_mask_->channels(), channels);\n      EXPECT_EQ(blob_top_mask_->height(), 5);\n      EXPECT_EQ(blob_top_mask_->width(), 4);\n    }\n    layer.Forward(blob_bottom_vec_, blob_top_vec_);\n    // Expected output: 2x 2 channels of:\n    // [35    32    26    26]\n    // [32    32    27    27]\n    // [33    33    33    27]\n    // [34    34    34    17]\n    // [36    36    34    18]\n    for (int i = 0; i < 20 * num * channels; i += 20) {\n      EXPECT_EQ(blob_top_->cpu_data()[i +  0], 35);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  1], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  2], 26);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  3], 26);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  4], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  5], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  6], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  7], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  8], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  9], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 10], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 11], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 12], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 13], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 14], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 15], 17);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 16], 36);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 17], 36);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 18], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 19], 18);\n    }\n    if (blob_top_vec_.size() > 1) {\n        // [ 1     8     4     4]\n        // [ 8     8    17    17]\n        // [21    21    21    17]\n        // [27    27    27    22]\n        // [32    32    27    35]\n      for (int i = 0; i < 20 * num * channels; i += 20) {\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  0],  0);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  1],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  2],  3);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  3],  3);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  4],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  5],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  6], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  7], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  8], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  9], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 10], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 11], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 12], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 13], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 14], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 15], 21);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 16], 31);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 17], 31);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 18], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 19], 34);\n      }\n    }\n  }\n};\n\nTYPED_TEST_CASE(PoolingLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(PoolingLayerTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  PoolingLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), this->blob_bottom_->channels());\n  EXPECT_EQ(this->blob_top_->height(), 3);\n  EXPECT_EQ(this->blob_top_->width(), 2);\n}\n\nTYPED_TEST(PoolingLayerTest, TestSetupPadded) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  pooling_param->set_pad(1);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_AVE);\n  PoolingLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), this->blob_bottom_->channels());\n  EXPECT_EQ(this->blob_top_->height(), 4);\n  EXPECT_EQ(this->blob_top_->width(), 3);\n}\n\nTYPED_TEST(PoolingLayerTest, TestSetupGlobalPooling) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_global_pooling(true);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_AVE);\n  PoolingLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), this->blob_bottom_->channels());\n  EXPECT_EQ(this->blob_top_->height(), 1);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n}\n\n/*\nTYPED_TEST(PoolingLayerTest, PrintBackward) {\n  LayerParameter layer_param;\n  layer_param.set_kernelsize(3);\n  layer_param.set_stride(2);\n  layer_param.set_pool(LayerParameter_PoolMethod_MAX);\n  PoolingLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    cout << \"bottom data \" << i << \" \" << this->blob_bottom_->cpu_data()[i] << endl;\n  }\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    cout << \"top data \" << i << \" \" << this->blob_top_->cpu_data()[i] << endl;\n  }\n\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    this->blob_top_->mutable_cpu_diff()[i] = i;\n  }\n  layer.Backward(this->blob_top_vec_, true, this->blob_bottom_vec_);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    cout << \"bottom diff \" << i << \" \" << this->blob_bottom_->cpu_diff()[i] << endl;\n  }\n}\n*/\n\nTYPED_TEST(PoolingLayerTest, TestForwardMax) {\n  this->TestForwardSquare();\n  this->TestForwardRectHigh();\n  this->TestForwardRectWide();\n}\n\nTYPED_TEST(PoolingLayerTest, TestForwardMaxTopMask) {\n  this->blob_top_vec_.push_back(this->blob_top_mask_);\n  this->TestForwardSquare();\n  this->TestForwardRectHigh();\n  this->TestForwardRectWide();\n}\n\nTYPED_TEST(PoolingLayerTest, TestGradientMax) {\n  typedef typename TypeParam::Dtype Dtype;\n  for (int kernel_h = 3; kernel_h <= 4; kernel_h++) {\n    for (int kernel_w = 3; kernel_w <= 4; kernel_w++) {\n      LayerParameter layer_param;\n      PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n      pooling_param->set_kernel_h(kernel_h);\n      pooling_param->set_kernel_w(kernel_w);\n      pooling_param->set_stride(2);\n      pooling_param->set_pad(1);\n      pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n      PoolingLayer<Dtype> layer(layer_param);\n      GradientChecker<Dtype> checker(1e-4, 1e-2);\n      checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n          this->blob_top_vec_);\n    }\n  }\n}\n\nTYPED_TEST(PoolingLayerTest, TestForwardMaxPadded) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  pooling_param->set_pad(2);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n  this->blob_bottom_->Reshape(1, 1, 3, 3);\n  // Input:\n  //     [ 1 2 4 ]\n  //     [ 2 3 2 ]\n  //     [ 4 2 1 ]\n  this->blob_bottom_->mutable_cpu_data()[0] = 1;\n  this->blob_bottom_->mutable_cpu_data()[1] = 2;\n  this->blob_bottom_->mutable_cpu_data()[2] = 4;\n  this->blob_bottom_->mutable_cpu_data()[3] = 2;\n  this->blob_bottom_->mutable_cpu_data()[4] = 3;\n  this->blob_bottom_->mutable_cpu_data()[5] = 2;\n  this->blob_bottom_->mutable_cpu_data()[6] = 4;\n  this->blob_bottom_->mutable_cpu_data()[7] = 2;\n  this->blob_bottom_->mutable_cpu_data()[8] = 1;\n  PoolingLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 1);\n  EXPECT_EQ(this->blob_top_->channels(), 1);\n  EXPECT_EQ(this->blob_top_->height(), 3);\n  EXPECT_EQ(this->blob_top_->width(), 3);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  Dtype epsilon = 1e-8;\n  // Output:\n  //     [ 1 4 4 ]\n  //     [ 4 4 4 ]\n  //     [ 4 4 1 ]\n  EXPECT_NEAR(this->blob_top_->cpu_data()[0], 1, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[1], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[2], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[3], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[4], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[5], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[6], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[7], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[8], 1, epsilon);\n}\n\nTYPED_TEST(PoolingLayerTest, TestGradientMaxTopMask) {\n  typedef typename TypeParam::Dtype Dtype;\n  for (int kernel_h = 3; kernel_h <= 4; kernel_h++) {\n    for (int kernel_w = 3; kernel_w <= 4; kernel_w++) {\n      LayerParameter layer_param;\n      PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n      pooling_param->set_kernel_h(kernel_h);\n      pooling_param->set_kernel_w(kernel_w);\n      pooling_param->set_stride(2);\n      pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n      this->blob_top_vec_.push_back(this->blob_top_mask_);\n      PoolingLayer<Dtype> layer(layer_param);\n      GradientChecker<Dtype> checker(1e-4, 1e-2);\n      checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n          this->blob_top_vec_);\n      this->blob_top_vec_.pop_back();\n    }\n  }\n}\n\nTYPED_TEST(PoolingLayerTest, TestForwardAve) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(1);\n  pooling_param->set_pad(1);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_AVE);\n  this->blob_bottom_->Reshape(1, 1, 3, 3);\n  FillerParameter filler_param;\n  filler_param.set_value(Dtype(2));\n  ConstantFiller<Dtype> filler(filler_param);\n  filler.Fill(this->blob_bottom_);\n  PoolingLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 1);\n  EXPECT_EQ(this->blob_top_->channels(), 1);\n  EXPECT_EQ(this->blob_top_->height(), 3);\n  EXPECT_EQ(this->blob_top_->width(), 3);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  Dtype epsilon = 1e-5;\n  EXPECT_NEAR(this->blob_top_->cpu_data()[0], 8.0 / 9, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[1], 4.0 / 3, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[2], 8.0 / 9, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[3], 4.0 / 3, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[4], 2.0    , epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[5], 4.0 / 3, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[6], 8.0 / 9, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[7], 4.0 / 3, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[8], 8.0 / 9, epsilon);\n}\n\nTYPED_TEST(PoolingLayerTest, TestGradientAve) {\n  typedef typename TypeParam::Dtype Dtype;\n  for (int kernel_h = 3; kernel_h <= 4; kernel_h++) {\n    for (int kernel_w = 3; kernel_w <= 4; kernel_w++) {\n      LayerParameter layer_param;\n      PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n      pooling_param->set_kernel_h(kernel_h);\n      pooling_param->set_kernel_w(kernel_w);\n      pooling_param->set_stride(2);\n      pooling_param->set_pool(PoolingParameter_PoolMethod_AVE);\n      PoolingLayer<Dtype> layer(layer_param);\n      GradientChecker<Dtype> checker(1e-2, 1e-2);\n      checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n          this->blob_top_vec_);\n    }\n  }\n}\n\nTYPED_TEST(PoolingLayerTest, TestGradientAvePadded) {\n  typedef typename TypeParam::Dtype Dtype;\n  for (int kernel_h = 3; kernel_h <= 4; kernel_h++) {\n    for (int kernel_w = 3; kernel_w <= 4; kernel_w++) {\n      LayerParameter layer_param;\n      PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n      pooling_param->set_kernel_h(kernel_h);\n      pooling_param->set_kernel_w(kernel_w);\n      pooling_param->set_stride(2);\n      pooling_param->set_pad(2);\n      pooling_param->set_pool(PoolingParameter_PoolMethod_AVE);\n      PoolingLayer<Dtype> layer(layer_param);\n      GradientChecker<Dtype> checker(1e-2, 1e-2);\n      checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n          this->blob_top_vec_);\n    }\n  }\n}\n\n#ifdef USE_CUDNN\ntemplate <typename Dtype>\nclass CuDNNPoolingLayerTest : public GPUDeviceTest<Dtype> {\n protected:\n  CuDNNPoolingLayerTest()\n      : blob_bottom_(new Blob<Dtype>()),\n        blob_top_(new Blob<Dtype>()),\n        blob_top_mask_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    Caffe::set_random_seed(1701);\n    blob_bottom_->Reshape(2, 3, 6, 5);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~CuDNNPoolingLayerTest() {\n    delete blob_bottom_;\n    delete blob_top_;\n    delete blob_top_mask_;\n  }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  Blob<Dtype>* const blob_top_mask_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n  // Test for 2x 2 square pooling layer\n  void TestForwardSquare() {\n    LayerParameter layer_param;\n    PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n    pooling_param->set_kernel_size(2);\n    pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n    const int num = 2;\n    const int channels = 2;\n    blob_bottom_->Reshape(num, channels, 3, 5);\n    // Input: 2x 2 channels of:\n    //     [1 2 5 2 3]\n    //     [9 4 1 4 8]\n    //     [1 2 5 2 3]\n    for (int i = 0; i < 15 * num * channels; i += 15) {\n      blob_bottom_->mutable_cpu_data()[i +  0] = 1;\n      blob_bottom_->mutable_cpu_data()[i +  1] = 2;\n      blob_bottom_->mutable_cpu_data()[i +  2] = 5;\n      blob_bottom_->mutable_cpu_data()[i +  3] = 2;\n      blob_bottom_->mutable_cpu_data()[i +  4] = 3;\n      blob_bottom_->mutable_cpu_data()[i +  5] = 9;\n      blob_bottom_->mutable_cpu_data()[i +  6] = 4;\n      blob_bottom_->mutable_cpu_data()[i +  7] = 1;\n      blob_bottom_->mutable_cpu_data()[i +  8] = 4;\n      blob_bottom_->mutable_cpu_data()[i +  9] = 8;\n      blob_bottom_->mutable_cpu_data()[i + 10] = 1;\n      blob_bottom_->mutable_cpu_data()[i + 11] = 2;\n      blob_bottom_->mutable_cpu_data()[i + 12] = 5;\n      blob_bottom_->mutable_cpu_data()[i + 13] = 2;\n      blob_bottom_->mutable_cpu_data()[i + 14] = 3;\n    }\n    CuDNNPoolingLayer<Dtype> layer(layer_param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    EXPECT_EQ(blob_top_->num(), num);\n    EXPECT_EQ(blob_top_->channels(), channels);\n    EXPECT_EQ(blob_top_->height(), 2);\n    EXPECT_EQ(blob_top_->width(), 4);\n    if (blob_top_vec_.size() > 1) {\n      EXPECT_EQ(blob_top_mask_->num(), num);\n      EXPECT_EQ(blob_top_mask_->channels(), channels);\n      EXPECT_EQ(blob_top_mask_->height(), 2);\n      EXPECT_EQ(blob_top_mask_->width(), 4);\n    }\n    layer.Forward(blob_bottom_vec_, blob_top_vec_);\n    // Expected output: 2x 2 channels of:\n    //     [9 5 5 8]\n    //     [9 5 5 8]\n    for (int i = 0; i < 8 * num * channels; i += 8) {\n      EXPECT_EQ(blob_top_->cpu_data()[i + 0], 9);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 1], 5);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 2], 5);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 3], 8);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 4], 9);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 5], 5);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 6], 5);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 7], 8);\n    }\n    if (blob_top_vec_.size() > 1) {\n      // Expected mask output: 2x 2 channels of:\n      //     [5  2  2 9]\n      //     [5 12 12 9]\n      for (int i = 0; i < 8 * num * channels; i += 8) {\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 0],  5);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 1],  2);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 2],  2);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 3],  9);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 4],  5);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 5], 12);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 6], 12);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 7],  9);\n      }\n    }\n  }\n  // Test for 3x 2 rectangular pooling layer with kernel_h > kernel_w\n  void TestForwardRectHigh() {\n    LayerParameter layer_param;\n    PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n    pooling_param->set_kernel_h(3);\n    pooling_param->set_kernel_w(2);\n    pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n    const int num = 2;\n    const int channels = 2;\n    blob_bottom_->Reshape(num, channels, 6, 6);\n    // Input: 2x 2 channels of:\n    // [35     1     6    26    19    24]\n    // [ 3    32     7    21    23    25]\n    // [31     9     2    22    27    20]\n    // [ 8    28    33    17    10    15]\n    // [30     5    34    12    14    16]\n    // [ 4    36    29    13    18    11]\n    // (this is generated by magic(6) in MATLAB)\n    for (int i = 0; i < 36 * num * channels; i += 36) {\n      blob_bottom_->mutable_cpu_data()[i +  0] = 35;\n      blob_bottom_->mutable_cpu_data()[i +  1] = 1;\n      blob_bottom_->mutable_cpu_data()[i +  2] = 6;\n      blob_bottom_->mutable_cpu_data()[i +  3] = 26;\n      blob_bottom_->mutable_cpu_data()[i +  4] = 19;\n      blob_bottom_->mutable_cpu_data()[i +  5] = 24;\n      blob_bottom_->mutable_cpu_data()[i +  6] = 3;\n      blob_bottom_->mutable_cpu_data()[i +  7] = 32;\n      blob_bottom_->mutable_cpu_data()[i +  8] = 7;\n      blob_bottom_->mutable_cpu_data()[i +  9] = 21;\n      blob_bottom_->mutable_cpu_data()[i + 10] = 23;\n      blob_bottom_->mutable_cpu_data()[i + 11] = 25;\n      blob_bottom_->mutable_cpu_data()[i + 12] = 31;\n      blob_bottom_->mutable_cpu_data()[i + 13] = 9;\n      blob_bottom_->mutable_cpu_data()[i + 14] = 2;\n      blob_bottom_->mutable_cpu_data()[i + 15] = 22;\n      blob_bottom_->mutable_cpu_data()[i + 16] = 27;\n      blob_bottom_->mutable_cpu_data()[i + 17] = 20;\n      blob_bottom_->mutable_cpu_data()[i + 18] = 8;\n      blob_bottom_->mutable_cpu_data()[i + 19] = 28;\n      blob_bottom_->mutable_cpu_data()[i + 20] = 33;\n      blob_bottom_->mutable_cpu_data()[i + 21] = 17;\n      blob_bottom_->mutable_cpu_data()[i + 22] = 10;\n      blob_bottom_->mutable_cpu_data()[i + 23] = 15;\n      blob_bottom_->mutable_cpu_data()[i + 24] = 30;\n      blob_bottom_->mutable_cpu_data()[i + 25] = 5;\n      blob_bottom_->mutable_cpu_data()[i + 26] = 34;\n      blob_bottom_->mutable_cpu_data()[i + 27] = 12;\n      blob_bottom_->mutable_cpu_data()[i + 28] = 14;\n      blob_bottom_->mutable_cpu_data()[i + 29] = 16;\n      blob_bottom_->mutable_cpu_data()[i + 30] = 4;\n      blob_bottom_->mutable_cpu_data()[i + 31] = 36;\n      blob_bottom_->mutable_cpu_data()[i + 32] = 29;\n      blob_bottom_->mutable_cpu_data()[i + 33] = 13;\n      blob_bottom_->mutable_cpu_data()[i + 34] = 18;\n      blob_bottom_->mutable_cpu_data()[i + 35] = 11;\n    }\n    CuDNNPoolingLayer<Dtype> layer(layer_param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    EXPECT_EQ(blob_top_->num(), num);\n    EXPECT_EQ(blob_top_->channels(), channels);\n    EXPECT_EQ(blob_top_->height(), 4);\n    EXPECT_EQ(blob_top_->width(), 5);\n    if (blob_top_vec_.size() > 1) {\n      EXPECT_EQ(blob_top_mask_->num(), num);\n      EXPECT_EQ(blob_top_mask_->channels(), channels);\n      EXPECT_EQ(blob_top_mask_->height(), 4);\n      EXPECT_EQ(blob_top_mask_->width(), 5);\n    }\n    layer.Forward(blob_bottom_vec_, blob_top_vec_);\n    // Expected output: 2x 2 channels of:\n    // [35    32    26    27    27]\n    // [32    33    33    27    27]\n    // [31    34    34    27    27]\n    // [36    36    34    18    18]\n    for (int i = 0; i < 20 * num * channels; i += 20) {\n      EXPECT_EQ(blob_top_->cpu_data()[i +  0], 35);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  1], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  2], 26);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  3], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  4], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  5], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  6], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  7], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  8], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  9], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 10], 31);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 11], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 12], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 13], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 14], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 15], 36);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 16], 36);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 17], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 18], 18);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 19], 18);\n    }\n    if (blob_top_vec_.size() > 1) {\n        // [ 1     8     4    17    17]\n        // [ 8    21    21    17    17]\n        // [13    27    27    17    17]\n        // [32    32    27    35    35]\n      for (int i = 0; i < 20 * num * channels; i += 20) {\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  0],  0);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  1],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  2],  3);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  3], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  4], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  5],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  6], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  7], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  8], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  9], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 10], 12);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 11], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 12], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 13], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 14], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 15], 31);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 16], 31);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 17], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 18], 34);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 19], 34);\n      }\n    }\n  }\n  // Test for rectangular pooling layer with kernel_w > kernel_h\n  void TestForwardRectWide() {\n    LayerParameter layer_param;\n    PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n    pooling_param->set_kernel_h(2);\n    pooling_param->set_kernel_w(3);\n    pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n    const int num = 2;\n    const int channels = 2;\n    blob_bottom_->Reshape(num, channels, 6, 6);\n    // Input: 2x 2 channels of:\n    // [35     1     6    26    19    24]\n    // [ 3    32     7    21    23    25]\n    // [31     9     2    22    27    20]\n    // [ 8    28    33    17    10    15]\n    // [30     5    34    12    14    16]\n    // [ 4    36    29    13    18    11]\n    // (this is generated by magic(6) in MATLAB)\n    for (int i = 0; i < 36 * num * channels; i += 36) {\n      blob_bottom_->mutable_cpu_data()[i +  0] = 35;\n      blob_bottom_->mutable_cpu_data()[i +  1] = 1;\n      blob_bottom_->mutable_cpu_data()[i +  2] = 6;\n      blob_bottom_->mutable_cpu_data()[i +  3] = 26;\n      blob_bottom_->mutable_cpu_data()[i +  4] = 19;\n      blob_bottom_->mutable_cpu_data()[i +  5] = 24;\n      blob_bottom_->mutable_cpu_data()[i +  6] = 3;\n      blob_bottom_->mutable_cpu_data()[i +  7] = 32;\n      blob_bottom_->mutable_cpu_data()[i +  8] = 7;\n      blob_bottom_->mutable_cpu_data()[i +  9] = 21;\n      blob_bottom_->mutable_cpu_data()[i + 10] = 23;\n      blob_bottom_->mutable_cpu_data()[i + 11] = 25;\n      blob_bottom_->mutable_cpu_data()[i + 12] = 31;\n      blob_bottom_->mutable_cpu_data()[i + 13] = 9;\n      blob_bottom_->mutable_cpu_data()[i + 14] = 2;\n      blob_bottom_->mutable_cpu_data()[i + 15] = 22;\n      blob_bottom_->mutable_cpu_data()[i + 16] = 27;\n      blob_bottom_->mutable_cpu_data()[i + 17] = 20;\n      blob_bottom_->mutable_cpu_data()[i + 18] = 8;\n      blob_bottom_->mutable_cpu_data()[i + 19] = 28;\n      blob_bottom_->mutable_cpu_data()[i + 20] = 33;\n      blob_bottom_->mutable_cpu_data()[i + 21] = 17;\n      blob_bottom_->mutable_cpu_data()[i + 22] = 10;\n      blob_bottom_->mutable_cpu_data()[i + 23] = 15;\n      blob_bottom_->mutable_cpu_data()[i + 24] = 30;\n      blob_bottom_->mutable_cpu_data()[i + 25] = 5;\n      blob_bottom_->mutable_cpu_data()[i + 26] = 34;\n      blob_bottom_->mutable_cpu_data()[i + 27] = 12;\n      blob_bottom_->mutable_cpu_data()[i + 28] = 14;\n      blob_bottom_->mutable_cpu_data()[i + 29] = 16;\n      blob_bottom_->mutable_cpu_data()[i + 30] = 4;\n      blob_bottom_->mutable_cpu_data()[i + 31] = 36;\n      blob_bottom_->mutable_cpu_data()[i + 32] = 29;\n      blob_bottom_->mutable_cpu_data()[i + 33] = 13;\n      blob_bottom_->mutable_cpu_data()[i + 34] = 18;\n      blob_bottom_->mutable_cpu_data()[i + 35] = 11;\n    }\n    CuDNNPoolingLayer<Dtype> layer(layer_param);\n    layer.SetUp(blob_bottom_vec_, blob_top_vec_);\n    EXPECT_EQ(blob_top_->num(), num);\n    EXPECT_EQ(blob_top_->channels(), channels);\n    EXPECT_EQ(blob_top_->height(), 5);\n    EXPECT_EQ(blob_top_->width(), 4);\n    if (blob_top_vec_.size() > 1) {\n      EXPECT_EQ(blob_top_mask_->num(), num);\n      EXPECT_EQ(blob_top_mask_->channels(), channels);\n      EXPECT_EQ(blob_top_mask_->height(), 5);\n      EXPECT_EQ(blob_top_mask_->width(), 4);\n    }\n    layer.Forward(blob_bottom_vec_, blob_top_vec_);\n    // Expected output: 2x 2 channels of:\n    // [35    32    26    26]\n    // [32    32    27    27]\n    // [33    33    33    27]\n    // [34    34    34    17]\n    // [36    36    34    18]\n    for (int i = 0; i < 20 * num * channels; i += 20) {\n      EXPECT_EQ(blob_top_->cpu_data()[i +  0], 35);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  1], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  2], 26);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  3], 26);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  4], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  5], 32);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  6], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  7], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  8], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i +  9], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 10], 33);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 11], 27);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 12], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 13], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 14], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 15], 17);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 16], 36);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 17], 36);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 18], 34);\n      EXPECT_EQ(blob_top_->cpu_data()[i + 19], 18);\n    }\n    if (blob_top_vec_.size() > 1) {\n        // [ 1     8     4     4]\n        // [ 8     8    17    17]\n        // [21    21    21    17]\n        // [27    27    27    22]\n        // [32    32    27    35]\n      for (int i = 0; i < 20 * num * channels; i += 20) {\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  0],  0);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  1],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  2],  3);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  3],  3);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  4],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  5],  7);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  6], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  7], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  8], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i +  9], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 10], 20);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 11], 16);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 12], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 13], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 14], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 15], 21);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 16], 31);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 17], 31);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 18], 26);\n        EXPECT_EQ(blob_top_mask_->cpu_data()[i + 19], 34);\n      }\n    }\n  }\n};\n\nTYPED_TEST_CASE(CuDNNPoolingLayerTest, TestDtypes);\n\nTYPED_TEST(CuDNNPoolingLayerTest, TestSetupCuDNN) {\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  CuDNNPoolingLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), this->blob_bottom_->channels());\n  EXPECT_EQ(this->blob_top_->height(), 3);\n  EXPECT_EQ(this->blob_top_->width(), 2);\n}\n\nTYPED_TEST(CuDNNPoolingLayerTest, TestSetupPaddedCuDNN) {\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  pooling_param->set_pad(1);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_AVE);\n  CuDNNPoolingLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), this->blob_bottom_->channels());\n  EXPECT_EQ(this->blob_top_->height(), 4);\n  EXPECT_EQ(this->blob_top_->width(), 3);\n}\n\n/*\nTYPED_TEST(CuDNNPoolingLayerTest, PrintBackwardCuDNN) {\n  LayerParameter layer_param;\n  layer_param.set_kernelsize(3);\n  layer_param.set_stride(2);\n  layer_param.set_pool(LayerParameter_PoolMethod_MAX);\n  CuDNNPoolingLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    cout << \"bottom data \" << i << \" \" << this->blob_bottom_->cpu_data()[i] << endl;\n  }\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    cout << \"top data \" << i << \" \" << this->blob_top_->cpu_data()[i] << endl;\n  }\n\n  for (int i = 0; i < this->blob_top_->count(); ++i) {\n    this->blob_top_->mutable_cpu_diff()[i] = i;\n  }\n  layer.Backward(this->blob_top_vec_, true, this->blob_bottom_vec_);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    cout << \"bottom diff \" << i << \" \" << this->blob_bottom_->cpu_diff()[i] << endl;\n  }\n}\n*/\n\nTYPED_TEST(CuDNNPoolingLayerTest, TestForwardMaxCuDNN) {\n  this->TestForwardSquare();\n  this->TestForwardRectHigh();\n  this->TestForwardRectWide();\n}\n\n// Currently, cuDNN does not support a top mask, so we comment this and\n// the corresponding backward test.\n/*\nTYPED_TEST(CuDNNPoolingLayerTest, TestForwardMaxTopMaskCuDNN) {\n  this->blob_top_vec_.push_back(this->blob_top_mask_);\n  this->TestForwardSquare();\n  this->TestForwardRectHigh();\n  this->TestForwardRectWide();\n}\n*/\n\nTYPED_TEST(CuDNNPoolingLayerTest, TestGradientMaxCuDNN) {\n  for (int kernel_h = 3; kernel_h <= 4; kernel_h++) {\n    for (int kernel_w = 3; kernel_w <= 4; kernel_w++) {\n      LayerParameter layer_param;\n      PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n      pooling_param->set_kernel_h(kernel_h);\n      pooling_param->set_kernel_w(kernel_w);\n      pooling_param->set_stride(2);\n      // currenty, cuDNN pooling does not support padding\n      pooling_param->set_pad(0);\n      pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n      CuDNNPoolingLayer<TypeParam> layer(layer_param);\n      GradientChecker<TypeParam> checker(1e-4, 1e-2);\n      checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n          this->blob_top_vec_);\n    }\n  }\n}\n\nTYPED_TEST(CuDNNPoolingLayerTest, TestForwardMaxPaddedCuDNN) {\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  pooling_param->set_pad(2);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n  this->blob_bottom_->Reshape(1, 1, 3, 3);\n  // Input:\n  //     [ 1 2 4 ]\n  //     [ 2 3 2 ]\n  //     [ 4 2 1 ]\n  this->blob_bottom_->mutable_cpu_data()[0] = 1;\n  this->blob_bottom_->mutable_cpu_data()[1] = 2;\n  this->blob_bottom_->mutable_cpu_data()[2] = 4;\n  this->blob_bottom_->mutable_cpu_data()[3] = 2;\n  this->blob_bottom_->mutable_cpu_data()[4] = 3;\n  this->blob_bottom_->mutable_cpu_data()[5] = 2;\n  this->blob_bottom_->mutable_cpu_data()[6] = 4;\n  this->blob_bottom_->mutable_cpu_data()[7] = 2;\n  this->blob_bottom_->mutable_cpu_data()[8] = 1;\n  CuDNNPoolingLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 1);\n  EXPECT_EQ(this->blob_top_->channels(), 1);\n  EXPECT_EQ(this->blob_top_->height(), 3);\n  EXPECT_EQ(this->blob_top_->width(), 3);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  TypeParam epsilon = 1e-8;\n  // Output:\n  //     [ 1 4 4 ]\n  //     [ 4 4 4 ]\n  //     [ 4 4 1 ]\n  EXPECT_NEAR(this->blob_top_->cpu_data()[0], 1, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[1], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[2], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[3], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[4], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[5], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[6], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[7], 4, epsilon);\n  EXPECT_NEAR(this->blob_top_->cpu_data()[8], 1, epsilon);\n}\n\n/*\nTYPED_TEST(CuDNNPoolingLayerTest, TestGradientMaxTopMaskCuDNN) {\n  for (int kernel_h = 3; kernel_h <= 4; kernel_h++) {\n    for (int kernel_w = 3; kernel_w <= 4; kernel_w++) {\n      LayerParameter layer_param;\n      PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n      pooling_param->set_kernel_h(kernel_h);\n      pooling_param->set_kernel_w(kernel_w);\n      pooling_param->set_stride(2);\n      pooling_param->set_pool(PoolingParameter_PoolMethod_MAX);\n      this->blob_top_vec_.push_back(this->blob_top_mask_);\n      CuDNNPoolingLayer<TypeParam> layer(layer_param);\n      GradientChecker<TypeParam> checker(1e-4, 1e-2);\n      checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n          this->blob_top_vec_);\n      this->blob_top_vec_.pop_back();\n    }\n  }\n}\n*/\n\nTYPED_TEST(CuDNNPoolingLayerTest, TestForwardAveCuDNN) {\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(1);\n  // Currently, cuDNN pooling does not support padding, so we use\n  // a simplified version of this test.\n  pooling_param->set_pad(0);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_AVE);\n  this->blob_bottom_->Reshape(1, 1, 3, 3);\n  FillerParameter filler_param;\n  filler_param.set_value(TypeParam(2));\n  ConstantFiller<TypeParam> filler(filler_param);\n  filler.Fill(this->blob_bottom_);\n  CuDNNPoolingLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 1);\n  EXPECT_EQ(this->blob_top_->channels(), 1);\n  EXPECT_EQ(this->blob_top_->height(), 1);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  TypeParam epsilon = 1e-5;\n  EXPECT_NEAR(this->blob_top_->cpu_data()[0], 2.0, epsilon);\n}\n\nTYPED_TEST(CuDNNPoolingLayerTest, TestGradientAveCuDNN) {\n  for (int kernel_h = 3; kernel_h <= 4; kernel_h++) {\n    for (int kernel_w = 3; kernel_w <= 4; kernel_w++) {\n      LayerParameter layer_param;\n      PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n      pooling_param->set_kernel_h(kernel_h);\n      pooling_param->set_kernel_w(kernel_w);\n      pooling_param->set_stride(2);\n      pooling_param->set_pool(PoolingParameter_PoolMethod_AVE);\n      CuDNNPoolingLayer<TypeParam> layer(layer_param);\n      GradientChecker<TypeParam> checker(1e-2, 1e-2);\n      checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n          this->blob_top_vec_);\n    }\n  }\n}\n\nTYPED_TEST(CuDNNPoolingLayerTest, TestGradientAvePaddedCuDNN) {\n  for (int kernel_h = 3; kernel_h <= 4; kernel_h++) {\n    for (int kernel_w = 3; kernel_w <= 4; kernel_w++) {\n      LayerParameter layer_param;\n      PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n      pooling_param->set_kernel_h(kernel_h);\n      pooling_param->set_kernel_w(kernel_w);\n      pooling_param->set_stride(2);\n      pooling_param->set_pad(2);\n      pooling_param->set_pool(PoolingParameter_PoolMethod_AVE);\n      CuDNNPoolingLayer<TypeParam> layer(layer_param);\n      GradientChecker<TypeParam> checker(1e-2, 1e-2);\n      checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n          this->blob_top_vec_);\n    }\n  }\n}\n\n#endif\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_power_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass PowerLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  PowerLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    Caffe::set_random_seed(1701);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~PowerLayerTest() { delete blob_bottom_; delete blob_top_; }\n\n  void TestForward(Dtype power, Dtype scale, Dtype shift) {\n    LayerParameter layer_param;\n    layer_param.mutable_power_param()->set_power(power);\n    layer_param.mutable_power_param()->set_scale(scale);\n    layer_param.mutable_power_param()->set_shift(shift);\n    PowerLayer<Dtype> layer(layer_param);\n    layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    // Now, check values\n    const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n    const Dtype* top_data = this->blob_top_->cpu_data();\n    const Dtype min_precision = 1e-5;\n    for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n      Dtype expected_value = pow(shift + scale * bottom_data[i], power);\n      if (power == Dtype(0) || power == Dtype(1) || power == Dtype(2)) {\n        EXPECT_FALSE(isnan(top_data[i]));\n      }\n      if (isnan(expected_value)) {\n        EXPECT_TRUE(isnan(top_data[i]));\n      } else {\n        Dtype precision = std::max(\n          Dtype(std::abs(expected_value * Dtype(1e-4))), min_precision);\n        EXPECT_NEAR(expected_value, top_data[i], precision);\n      }\n    }\n  }\n\n  void TestBackward(Dtype power, Dtype scale, Dtype shift) {\n    LayerParameter layer_param;\n    layer_param.mutable_power_param()->set_power(power);\n    layer_param.mutable_power_param()->set_scale(scale);\n    layer_param.mutable_power_param()->set_shift(shift);\n    PowerLayer<Dtype> layer(layer_param);\n    if (power != Dtype(0) && power != Dtype(1) && power != Dtype(2)) {\n      // Avoid NaNs by forcing (shift + scale * x) >= 0\n      Dtype* bottom_data = this->blob_bottom_->mutable_cpu_data();\n      Dtype min_value = -shift / scale;\n      for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n        if (bottom_data[i] < min_value) {\n          bottom_data[i] = min_value + (min_value - bottom_data[i]);\n        }\n      }\n    }\n    GradientChecker<Dtype> checker(1e-3, 1e-2, 1701, 0., 0.01);\n    checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n        this->blob_top_vec_);\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(PowerLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(PowerLayerTest, TestPower) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 0.37;\n  Dtype scale = 0.83;\n  Dtype shift = -2.4;\n  this->TestForward(power, scale, shift);\n}\n\nTYPED_TEST(PowerLayerTest, TestPowerGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 0.37;\n  Dtype scale = 0.83;\n  Dtype shift = -2.4;\n  this->TestBackward(power, scale, shift);\n}\n\nTYPED_TEST(PowerLayerTest, TestPowerGradientShiftZero) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 0.37;\n  Dtype scale = 0.83;\n  Dtype shift = 0.0;\n  this->TestBackward(power, scale, shift);\n}\n\nTYPED_TEST(PowerLayerTest, TestPowerZero) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 0.0;\n  Dtype scale = 0.83;\n  Dtype shift = -2.4;\n  this->TestForward(power, scale, shift);\n}\n\nTYPED_TEST(PowerLayerTest, TestPowerZeroGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 0.0;\n  Dtype scale = 0.83;\n  Dtype shift = -2.4;\n  this->TestBackward(power, scale, shift);\n}\n\nTYPED_TEST(PowerLayerTest, TestPowerOne) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 1.0;\n  Dtype scale = 0.83;\n  Dtype shift = -2.4;\n  this->TestForward(power, scale, shift);\n}\n\nTYPED_TEST(PowerLayerTest, TestPowerOneGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 1.0;\n  Dtype scale = 0.83;\n  Dtype shift = -2.4;\n  this->TestBackward(power, scale, shift);\n}\n\nTYPED_TEST(PowerLayerTest, TestPowerTwo) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 2.0;\n  Dtype scale = 0.34;\n  Dtype shift = -2.4;\n  this->TestForward(power, scale, shift);\n}\n\nTYPED_TEST(PowerLayerTest, TestPowerTwoGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 2.0;\n  Dtype scale = 0.83;\n  Dtype shift = -2.4;\n  this->TestBackward(power, scale, shift);\n}\n\nTYPED_TEST(PowerLayerTest, TestPowerTwoScaleHalfGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  Dtype power = 2.0;\n  Dtype scale = 0.5;\n  Dtype shift = -2.4;\n  this->TestBackward(power, scale, shift);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_protobuf.cpp",
    "content": "// This is simply a script that tries serializing protocol buffer in text\n// format. Nothing special here and no actual code is being tested.\n#include <string>\n\n#include \"google/protobuf/text_format.h\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/proto/caffe.pb.h\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nclass ProtoTest : public ::testing::Test {};\n\nTEST_F(ProtoTest, TestSerialization) {\n  LayerParameter param;\n  param.set_name(\"test\");\n  param.set_type(\"Test\");\n  std::cout << \"Printing in binary format.\" << std::endl;\n  std::cout << param.SerializeAsString() << std::endl;\n  std::cout << \"Printing in text format.\" << std::endl;\n  std::string str;\n  google::protobuf::TextFormat::PrintToString(param, &str);\n  std::cout << str << std::endl;\n  EXPECT_TRUE(true);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_random_number_generator.cpp",
    "content": "#include <cmath>\n#include <cstring>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nclass RandomNumberGeneratorTest : public ::testing::Test {\n protected:\n  RandomNumberGeneratorTest()\n     : mean_bound_multiplier_(3.8),  // ~99.99% confidence for test failure.\n       sample_size_(10000),\n       seed_(1701),\n       data_(new SyncedMemory(sample_size_ * sizeof(Dtype))),\n       data_2_(new SyncedMemory(sample_size_ * sizeof(Dtype))),\n       int_data_(new SyncedMemory(sample_size_ * sizeof(int))),\n       int_data_2_(new SyncedMemory(sample_size_ * sizeof(int))) {}\n\n  virtual void SetUp() {\n    Caffe::set_random_seed(this->seed_);\n  }\n\n  Dtype sample_mean(const Dtype* const seqs, const int sample_size) {\n    Dtype sum = 0;\n    for (int i = 0; i < sample_size; ++i) {\n      sum += seqs[i];\n    }\n    return sum / sample_size;\n  }\n\n  Dtype sample_mean(const Dtype* const seqs) {\n    return sample_mean(seqs, sample_size_);\n  }\n\n  Dtype sample_mean(const int* const seqs, const int sample_size) {\n    Dtype sum = 0;\n    for (int i = 0; i < sample_size; ++i) {\n      sum += Dtype(seqs[i]);\n    }\n    return sum / sample_size;\n  }\n\n  Dtype sample_mean(const int* const seqs) {\n    return sample_mean(seqs, sample_size_);\n  }\n\n  Dtype mean_bound(const Dtype std, const int sample_size) {\n    return mean_bound_multiplier_ * std / sqrt(static_cast<Dtype>(sample_size));\n  }\n\n  Dtype mean_bound(const Dtype std) {\n    return mean_bound(std, sample_size_);\n  }\n\n  void RngGaussianFill(const Dtype mu, const Dtype sigma, void* cpu_data) {\n    Dtype* rng_data = static_cast<Dtype*>(cpu_data);\n    caffe_rng_gaussian(sample_size_, mu, sigma, rng_data);\n  }\n\n  void RngGaussianChecks(const Dtype mu, const Dtype sigma,\n                         const void* cpu_data, const Dtype sparse_p = 0) {\n    const Dtype* rng_data = static_cast<const Dtype*>(cpu_data);\n    const Dtype true_mean = mu;\n    const Dtype true_std = sigma;\n    // Check that sample mean roughly matches true mean.\n    const Dtype bound = this->mean_bound(true_std);\n    const Dtype sample_mean = this->sample_mean(\n        static_cast<const Dtype*>(cpu_data));\n    EXPECT_NEAR(sample_mean, true_mean, bound);\n    // Check that roughly half the samples are above the true mean.\n    int num_above_mean = 0;\n    int num_below_mean = 0;\n    int num_mean = 0;\n    int num_nan = 0;\n    for (int i = 0; i < sample_size_; ++i) {\n      if (rng_data[i] > true_mean) {\n        ++num_above_mean;\n      } else if (rng_data[i] < true_mean) {\n        ++num_below_mean;\n      } else if (rng_data[i] == true_mean) {\n        ++num_mean;\n      } else {\n        ++num_nan;\n      }\n    }\n    EXPECT_EQ(0, num_nan);\n    if (sparse_p == Dtype(0)) {\n      EXPECT_EQ(0, num_mean);\n    }\n    const Dtype sample_p_above_mean =\n        static_cast<Dtype>(num_above_mean) / sample_size_;\n    const Dtype bernoulli_p = (1 - sparse_p) * 0.5;\n    const Dtype bernoulli_std = sqrt(bernoulli_p * (1 - bernoulli_p));\n    const Dtype bernoulli_bound = this->mean_bound(bernoulli_std);\n    EXPECT_NEAR(bernoulli_p, sample_p_above_mean, bernoulli_bound);\n  }\n\n  void RngUniformFill(const Dtype lower, const Dtype upper, void* cpu_data) {\n    CHECK_GE(upper, lower);\n    Dtype* rng_data = static_cast<Dtype*>(cpu_data);\n    caffe_rng_uniform(sample_size_, lower, upper, rng_data);\n  }\n\n  void RngUniformChecks(const Dtype lower, const Dtype upper,\n                        const void* cpu_data, const Dtype sparse_p = 0) {\n    const Dtype* rng_data = static_cast<const Dtype*>(cpu_data);\n    const Dtype true_mean = (lower + upper) / 2;\n    const Dtype true_std = (upper - lower) / sqrt(12);\n    // Check that sample mean roughly matches true mean.\n    const Dtype bound = this->mean_bound(true_std);\n    const Dtype sample_mean = this->sample_mean(rng_data);\n    EXPECT_NEAR(sample_mean, true_mean, bound);\n    // Check that roughly half the samples are above the true mean, and none are\n    // above upper or below lower.\n    int num_above_mean = 0;\n    int num_below_mean = 0;\n    int num_mean = 0;\n    int num_nan = 0;\n    int num_above_upper = 0;\n    int num_below_lower = 0;\n    for (int i = 0; i < sample_size_; ++i) {\n      if (rng_data[i] > true_mean) {\n        ++num_above_mean;\n      } else if (rng_data[i] < true_mean) {\n        ++num_below_mean;\n      } else if (rng_data[i] == true_mean) {\n        ++num_mean;\n      } else {\n        ++num_nan;\n      }\n      if (rng_data[i] > upper) {\n        ++num_above_upper;\n      } else if (rng_data[i] < lower) {\n        ++num_below_lower;\n      }\n    }\n    EXPECT_EQ(0, num_nan);\n    EXPECT_EQ(0, num_above_upper);\n    EXPECT_EQ(0, num_below_lower);\n    if (sparse_p == Dtype(0)) {\n      EXPECT_EQ(0, num_mean);\n    }\n    const Dtype sample_p_above_mean =\n        static_cast<Dtype>(num_above_mean) / sample_size_;\n    const Dtype bernoulli_p = (1 - sparse_p) * 0.5;\n    const Dtype bernoulli_std = sqrt(bernoulli_p * (1 - bernoulli_p));\n    const Dtype bernoulli_bound = this->mean_bound(bernoulli_std);\n    EXPECT_NEAR(bernoulli_p, sample_p_above_mean, bernoulli_bound);\n  }\n\n  void RngBernoulliFill(const Dtype p, void* cpu_data) {\n    int* rng_data = static_cast<int*>(cpu_data);\n    caffe_rng_bernoulli(sample_size_, p, rng_data);\n  }\n\n  void RngBernoulliChecks(const Dtype p, const void* cpu_data) {\n    const int* rng_data = static_cast<const int*>(cpu_data);\n    const Dtype true_mean = p;\n    const Dtype true_std = sqrt(p * (1 - p));\n    const Dtype bound = this->mean_bound(true_std);\n    const Dtype sample_mean = this->sample_mean(rng_data);\n    EXPECT_NEAR(sample_mean, true_mean, bound);\n  }\n\n#ifndef CPU_ONLY\n\n  void RngGaussianFillGPU(const Dtype mu, const Dtype sigma, void* gpu_data) {\n    Dtype* rng_data = static_cast<Dtype*>(gpu_data);\n    caffe_gpu_rng_gaussian(sample_size_, mu, sigma, rng_data);\n  }\n\n  void RngUniformFillGPU(const Dtype lower, const Dtype upper, void* gpu_data) {\n    CHECK_GE(upper, lower);\n    Dtype* rng_data = static_cast<Dtype*>(gpu_data);\n    caffe_gpu_rng_uniform(sample_size_, lower, upper, rng_data);\n  }\n\n  // Fills with uniform integers in [0, UINT_MAX] using 2 argument form of\n  // caffe_gpu_rng_uniform.\n  void RngUniformIntFillGPU(void* gpu_data) {\n    unsigned int* rng_data = static_cast<unsigned int*>(gpu_data);\n    caffe_gpu_rng_uniform(sample_size_, rng_data);\n  }\n\n#endif\n\n  int num_above_mean;\n  int num_below_mean;\n\n  Dtype mean_bound_multiplier_;\n\n  size_t sample_size_;\n  uint32_t seed_;\n\n  shared_ptr<SyncedMemory> data_;\n  shared_ptr<SyncedMemory> data_2_;\n  shared_ptr<SyncedMemory> int_data_;\n  shared_ptr<SyncedMemory> int_data_2_;\n};\n\nTYPED_TEST_CASE(RandomNumberGeneratorTest, TestDtypes);\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngGaussian) {\n  const TypeParam mu = 0;\n  const TypeParam sigma = 1;\n  void* gaussian_data = this->data_->mutable_cpu_data();\n  this->RngGaussianFill(mu, sigma, gaussian_data);\n  this->RngGaussianChecks(mu, sigma, gaussian_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngGaussian2) {\n  const TypeParam mu = -2;\n  const TypeParam sigma = 3;\n  void* gaussian_data = this->data_->mutable_cpu_data();\n  this->RngGaussianFill(mu, sigma, gaussian_data);\n  this->RngGaussianChecks(mu, sigma, gaussian_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngUniform) {\n  const TypeParam lower = 0;\n  const TypeParam upper = 1;\n  void* uniform_data = this->data_->mutable_cpu_data();\n  this->RngUniformFill(lower, upper, uniform_data);\n  this->RngUniformChecks(lower, upper, uniform_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngUniform2) {\n  const TypeParam lower = -7.3;\n  const TypeParam upper = -2.3;\n  void* uniform_data = this->data_->mutable_cpu_data();\n  this->RngUniformFill(lower, upper, uniform_data);\n  this->RngUniformChecks(lower, upper, uniform_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngBernoulli) {\n  const TypeParam p = 0.3;\n  void* bernoulli_data = this->int_data_->mutable_cpu_data();\n  this->RngBernoulliFill(p, bernoulli_data);\n  this->RngBernoulliChecks(p, bernoulli_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngBernoulli2) {\n  const TypeParam p = 0.9;\n  void* bernoulli_data = this->int_data_->mutable_cpu_data();\n  this->RngBernoulliFill(p, bernoulli_data);\n  this->RngBernoulliChecks(p, bernoulli_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngGaussianTimesGaussian) {\n  const TypeParam mu = 0;\n  const TypeParam sigma = 1;\n\n  // Sample from 0 mean Gaussian.\n  TypeParam* gaussian_data_1 =\n      static_cast<TypeParam*>(this->data_->mutable_cpu_data());\n  this->RngGaussianFill(mu, sigma, gaussian_data_1);\n\n  // Sample from 0 mean Gaussian again.\n  TypeParam* gaussian_data_2 =\n      static_cast<TypeParam*>(this->data_2_->mutable_cpu_data());\n  this->RngGaussianFill(mu, sigma, gaussian_data_2);\n\n  // Multiply Gaussians.\n  for (int i = 0; i < this->sample_size_; ++i) {\n    gaussian_data_1[i] *= gaussian_data_2[i];\n  }\n\n  // Check that result has mean 0.\n  TypeParam mu_product = pow(mu, 2);\n  TypeParam sigma_product = sqrt(pow(sigma, 2) / 2);\n  this->RngGaussianChecks(mu_product, sigma_product, gaussian_data_1);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngUniformTimesUniform) {\n  // Sample from Uniform on [-2, 2].\n  const TypeParam lower_1 = -2;\n  const TypeParam upper_1 = -lower_1;\n  TypeParam* uniform_data_1 =\n      static_cast<TypeParam*>(this->data_->mutable_cpu_data());\n  this->RngUniformFill(lower_1, upper_1, uniform_data_1);\n\n  // Sample from Uniform on [-3, 3].\n  const TypeParam lower_2 = -3;\n  const TypeParam upper_2 = -lower_2;\n  TypeParam* uniform_data_2 =\n      static_cast<TypeParam*>(this->data_2_->mutable_cpu_data());\n  this->RngUniformFill(lower_2, upper_2, uniform_data_2);\n\n  // Multiply Uniforms.\n  for (int i = 0; i < this->sample_size_; ++i) {\n    uniform_data_1[i] *= uniform_data_2[i];\n  }\n\n  // Check that result does not violate checked properties of Uniform on [-6, 6]\n  // (though it is not actually uniformly distributed).\n  const TypeParam lower_prod = lower_1 * upper_2;\n  const TypeParam upper_prod = -lower_prod;\n  this->RngUniformChecks(lower_prod, upper_prod, uniform_data_1);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngGaussianTimesBernoulli) {\n  // Sample from 0 mean Gaussian.\n  const TypeParam mu = 0;\n  const TypeParam sigma = 1;\n  TypeParam* gaussian_data =\n      static_cast<TypeParam*>(this->data_->mutable_cpu_data());\n  this->RngGaussianFill(mu, sigma, gaussian_data);\n\n  // Sample from Bernoulli with p = 0.3.\n  const TypeParam bernoulli_p = 0.3;\n  int* bernoulli_data =\n      static_cast<int*>(this->int_data_->mutable_cpu_data());\n  this->RngBernoulliFill(bernoulli_p, bernoulli_data);\n\n  // Multiply Gaussian by Bernoulli.\n  for (int i = 0; i < this->sample_size_; ++i) {\n    gaussian_data[i] *= bernoulli_data[i];\n  }\n\n  // Check that result does not violate checked properties of sparsified\n  // Gaussian (though it is not actually a Gaussian).\n  this->RngGaussianChecks(mu, sigma, gaussian_data, 1 - bernoulli_p);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngUniformTimesBernoulli) {\n  // Sample from Uniform on [-1, 1].\n  const TypeParam lower = -1;\n  const TypeParam upper = 1;\n  TypeParam* uniform_data =\n      static_cast<TypeParam*>(this->data_->mutable_cpu_data());\n  this->RngUniformFill(lower, upper, uniform_data);\n\n  // Sample from Bernoulli with p = 0.3.\n  const TypeParam bernoulli_p = 0.3;\n  int* bernoulli_data =\n      static_cast<int*>(this->int_data_->mutable_cpu_data());\n  this->RngBernoulliFill(bernoulli_p, bernoulli_data);\n\n  // Multiply Uniform by Bernoulli.\n  for (int i = 0; i < this->sample_size_; ++i) {\n    uniform_data[i] *= bernoulli_data[i];\n  }\n\n  // Check that result does not violate checked properties of sparsified\n  // Uniform on [-1, 1] (though it is not actually uniformly distributed).\n  this->RngUniformChecks(lower, upper, uniform_data, 1 - bernoulli_p);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngBernoulliTimesBernoulli) {\n  // Sample from Bernoulli with p = 0.5.\n  const TypeParam p_a = 0.5;\n  int* bernoulli_data_a =\n      static_cast<int*>(this->int_data_->mutable_cpu_data());\n  this->RngBernoulliFill(p_a, bernoulli_data_a);\n\n  // Sample from Bernoulli with p = 0.3.\n  const TypeParam p_b = 0.3;\n  int* bernoulli_data_b =\n      static_cast<int*>(this->int_data_2_->mutable_cpu_data());\n  this->RngBernoulliFill(p_b, bernoulli_data_b);\n\n  // Multiply Bernoullis.\n  for (int i = 0; i < this->sample_size_; ++i) {\n    bernoulli_data_a[i] *= bernoulli_data_b[i];\n  }\n  int num_ones = 0;\n  for (int i = 0; i < this->sample_size_; ++i) {\n    if (bernoulli_data_a[i] != TypeParam(0)) {\n      EXPECT_EQ(TypeParam(1), bernoulli_data_a[i]);\n      ++num_ones;\n    }\n  }\n\n  // Check that resulting product has roughly p_a * p_b ones.\n  const TypeParam sample_p = this->sample_mean(bernoulli_data_a);\n  const TypeParam true_mean = p_a * p_b;\n  const TypeParam true_std = sqrt(true_mean * (1 - true_mean));\n  const TypeParam bound = this->mean_bound(true_std);\n  EXPECT_NEAR(true_mean, sample_p, bound);\n}\n\n#ifndef CPU_ONLY\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngGaussianGPU) {\n  const TypeParam mu = 0;\n  const TypeParam sigma = 1;\n  void* gaussian_gpu_data = this->data_->mutable_gpu_data();\n  this->RngGaussianFillGPU(mu, sigma, gaussian_gpu_data);\n  const void* gaussian_data = this->data_->cpu_data();\n  this->RngGaussianChecks(mu, sigma, gaussian_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngGaussian2GPU) {\n  const TypeParam mu = -2;\n  const TypeParam sigma = 3;\n  void* gaussian_gpu_data = this->data_->mutable_gpu_data();\n  this->RngGaussianFillGPU(mu, sigma, gaussian_gpu_data);\n  const void* gaussian_data = this->data_->cpu_data();\n  this->RngGaussianChecks(mu, sigma, gaussian_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngUniformGPU) {\n  const TypeParam lower = 0;\n  const TypeParam upper = 1;\n  void* uniform_gpu_data = this->data_->mutable_gpu_data();\n  this->RngUniformFillGPU(lower, upper, uniform_gpu_data);\n  const void* uniform_data = this->data_->cpu_data();\n  this->RngUniformChecks(lower, upper, uniform_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngUniform2GPU) {\n  const TypeParam lower = -7.3;\n  const TypeParam upper = -2.3;\n  void* uniform_gpu_data = this->data_->mutable_gpu_data();\n  this->RngUniformFillGPU(lower, upper, uniform_gpu_data);\n  const void* uniform_data = this->data_->cpu_data();\n  this->RngUniformChecks(lower, upper, uniform_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngUniformIntGPU) {\n  unsigned int* uniform_uint_gpu_data =\n      static_cast<unsigned int*>(this->int_data_->mutable_gpu_data());\n  this->RngUniformIntFillGPU(uniform_uint_gpu_data);\n  const unsigned int* uniform_uint_data =\n      static_cast<const unsigned int*>(this->int_data_->cpu_data());\n  TypeParam* uniform_data =\n      static_cast<TypeParam*>(this->data_->mutable_cpu_data());\n  for (int i = 0; i < this->sample_size_; ++i) {\n    uniform_data[i] = static_cast<const TypeParam>(uniform_uint_data[i]);\n  }\n  const TypeParam lower = 0;\n  const TypeParam upper = UINT_MAX;\n  this->RngUniformChecks(lower, upper, uniform_data);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngGaussianTimesGaussianGPU) {\n  const TypeParam mu = 0;\n  const TypeParam sigma = 1;\n\n  // Sample from 0 mean Gaussian.\n  TypeParam* gaussian_gpu_data_1 =\n      static_cast<TypeParam*>(this->data_->mutable_gpu_data());\n  this->RngGaussianFillGPU(mu, sigma, gaussian_gpu_data_1);\n\n  // Sample from 0 mean Gaussian again.\n  TypeParam* gaussian_gpu_data_2 =\n      static_cast<TypeParam*>(this->data_2_->mutable_gpu_data());\n  this->RngGaussianFillGPU(mu, sigma, gaussian_gpu_data_2);\n\n  // Multiply Gaussians.\n  TypeParam* gaussian_data_1 =\n      static_cast<TypeParam*>(this->data_->mutable_cpu_data());\n  const TypeParam* gaussian_data_2 =\n      static_cast<const TypeParam*>(this->data_2_->cpu_data());\n  for (int i = 0; i < this->sample_size_; ++i) {\n    gaussian_data_1[i] *= gaussian_data_2[i];\n  }\n\n  // Check that result does not violate checked properties of Gaussian\n  // (though it is not actually a Gaussian).\n  TypeParam mu_product = pow(mu, 2);\n  TypeParam sigma_product = sqrt(pow(sigma, 2) / 2);\n  this->RngGaussianChecks(mu_product, sigma_product, gaussian_data_1);\n}\n\n\nTYPED_TEST(RandomNumberGeneratorTest, TestRngUniformTimesUniformGPU) {\n  // Sample from Uniform on [-2, 2].\n  const TypeParam lower_1 = -2;\n  const TypeParam upper_1 = -lower_1;\n  TypeParam* uniform_gpu_data_1 =\n      static_cast<TypeParam*>(this->data_->mutable_gpu_data());\n  this->RngUniformFillGPU(lower_1, upper_1, uniform_gpu_data_1);\n\n  // Sample from Uniform on [-3, 3].\n  const TypeParam lower_2 = -3;\n  const TypeParam upper_2 = -lower_2;\n  TypeParam* uniform_gpu_data_2 =\n      static_cast<TypeParam*>(this->data_2_->mutable_gpu_data());\n  this->RngUniformFillGPU(lower_2, upper_2, uniform_gpu_data_2);\n\n  // Multiply Uniforms.\n  TypeParam* uniform_data_1 =\n      static_cast<TypeParam*>(this->data_->mutable_cpu_data());\n  const TypeParam* uniform_data_2 =\n      static_cast<const TypeParam*>(this->data_2_->cpu_data());\n  for (int i = 0; i < this->sample_size_; ++i) {\n    uniform_data_1[i] *= uniform_data_2[i];\n  }\n\n  // Check that result does not violate properties of Uniform on [-7, -3].\n  const TypeParam lower_prod = lower_1 * upper_2;\n  const TypeParam upper_prod = -lower_prod;\n  this->RngUniformChecks(lower_prod, upper_prod, uniform_data_1);\n}\n\n#endif\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_reduction_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass ReductionLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  ReductionLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    // fill the values\n    Caffe::set_random_seed(1701);\n    FillerParameter filler_param;\n    UniformFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~ReductionLayerTest() {\n    delete blob_bottom_;\n    delete blob_top_;\n  }\n\n  void TestForward(ReductionParameter_ReductionOp op,\n                   float coeff = 1, int axis = 0) {\n    LayerParameter layer_param;\n    ReductionParameter* reduction_param = layer_param.mutable_reduction_param();\n    reduction_param->set_operation(op);\n    if (coeff != 1.0) { reduction_param->set_coeff(coeff); }\n    if (axis != 0) { reduction_param->set_axis(axis); }\n    shared_ptr<ReductionLayer<Dtype> > layer(\n        new ReductionLayer<Dtype>(layer_param));\n    layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    const Dtype* in_data = this->blob_bottom_->cpu_data();\n    const int num = this->blob_bottom_->count(0, axis);\n    const int dim = this->blob_bottom_->count(axis);\n    for (int n = 0; n < num; ++n) {\n      Dtype expected_result = 0;\n      for (int d = 0; d < dim; ++d) {\n        switch (op) {\n          case ReductionParameter_ReductionOp_SUM:\n            expected_result += *in_data;\n            break;\n          case ReductionParameter_ReductionOp_MEAN:\n            expected_result += *in_data / dim;\n            break;\n          case ReductionParameter_ReductionOp_ASUM:\n            expected_result += fabs(*in_data);\n            break;\n          case ReductionParameter_ReductionOp_SUMSQ:\n            expected_result += (*in_data) * (*in_data);\n            break;\n          default:\n            LOG(FATAL) << \"Unknown reduction op: \"\n                << ReductionParameter_ReductionOp_Name(op);\n        }\n        ++in_data;\n      }\n      expected_result *= coeff;\n      const Dtype computed_result = this->blob_top_->cpu_data()[n];\n      EXPECT_FLOAT_EQ(expected_result, computed_result)\n          << \"Incorrect result computed with op \"\n          << ReductionParameter_ReductionOp_Name(op) << \", coeff \" << coeff;\n    }\n  }\n\n  void TestGradient(ReductionParameter_ReductionOp op,\n                    float coeff = 1, int axis = 0) {\n    typedef typename TypeParam::Dtype Dtype;\n    LayerParameter layer_param;\n    ReductionParameter* reduction_param = layer_param.mutable_reduction_param();\n    reduction_param->set_operation(op);\n    reduction_param->set_coeff(coeff);\n    reduction_param->set_axis(axis);\n    ReductionLayer<Dtype> layer(layer_param);\n    GradientChecker<Dtype> checker(1e-2, 2e-3);\n    checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n        this->blob_top_vec_);\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(ReductionLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(ReductionLayerTest, TestSetUp) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  shared_ptr<ReductionLayer<Dtype> > layer(\n      new ReductionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  ASSERT_EQ(this->blob_top_->num_axes(), 0);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSetUpWithAxis1) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_reduction_param()->set_axis(1);\n  shared_ptr<ReductionLayer<Dtype> > layer(\n      new ReductionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  ASSERT_EQ(this->blob_top_->num_axes(), 1);\n  EXPECT_EQ(this->blob_top_->shape(0), 2);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSetUpWithAxis2) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_reduction_param()->set_axis(2);\n  shared_ptr<ReductionLayer<Dtype> > layer(\n      new ReductionLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  ASSERT_EQ(this->blob_top_->num_axes(), 2);\n  EXPECT_EQ(this->blob_top_->shape(0), 2);\n  EXPECT_EQ(this->blob_top_->shape(1), 3);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSum) {\n  const ReductionParameter_ReductionOp kOp = ReductionParameter_ReductionOp_SUM;\n  this->TestForward(kOp);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumCoeff) {\n  const ReductionParameter_ReductionOp kOp = ReductionParameter_ReductionOp_SUM;\n  const float kCoeff = 2.3;\n  this->TestForward(kOp, kCoeff);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumCoeffAxis1) {\n  const ReductionParameter_ReductionOp kOp = ReductionParameter_ReductionOp_SUM;\n  const float kCoeff = 2.3;\n  const int kAxis = 1;\n  this->TestForward(kOp, kCoeff, kAxis);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumGradient) {\n  const ReductionParameter_ReductionOp kOp = ReductionParameter_ReductionOp_SUM;\n  this->TestGradient(kOp);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumCoeffGradient) {\n  const ReductionParameter_ReductionOp kOp = ReductionParameter_ReductionOp_SUM;\n  const float kCoeff = 2.3;\n  this->TestGradient(kOp, kCoeff);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumCoeffAxis1Gradient) {\n  const ReductionParameter_ReductionOp kOp = ReductionParameter_ReductionOp_SUM;\n  const float kCoeff = 2.3;\n  const int kAxis = 1;\n  this->TestGradient(kOp, kCoeff, kAxis);\n}\n\nTYPED_TEST(ReductionLayerTest, TestMean) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_MEAN;\n  this->TestForward(kOp);\n}\n\nTYPED_TEST(ReductionLayerTest, TestMeanCoeff) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_MEAN;\n  const float kCoeff = 2.3;\n  this->TestForward(kOp, kCoeff);\n}\n\nTYPED_TEST(ReductionLayerTest, TestMeanCoeffAxis1) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_MEAN;\n  const float kCoeff = 2.3;\n  const int kAxis = 1;\n  this->TestForward(kOp, kCoeff, kAxis);\n}\n\nTYPED_TEST(ReductionLayerTest, TestMeanGradient) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_MEAN;\n  this->TestGradient(kOp);\n}\n\nTYPED_TEST(ReductionLayerTest, TestMeanCoeffGradient) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_MEAN;\n  const float kCoeff = 2.3;\n  this->TestGradient(kOp, kCoeff);\n}\n\nTYPED_TEST(ReductionLayerTest, TestMeanCoeffGradientAxis1) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_MEAN;\n  const float kCoeff = 2.3;\n  const int kAxis = 1;\n  this->TestGradient(kOp, kCoeff, kAxis);\n}\n\nTYPED_TEST(ReductionLayerTest, TestAbsSum) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_ASUM;\n  this->TestForward(kOp);\n}\n\nTYPED_TEST(ReductionLayerTest, TestAbsSumCoeff) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_ASUM;\n  const float kCoeff = 2.3;\n  this->TestForward(kOp, kCoeff);\n}\n\nTYPED_TEST(ReductionLayerTest, TestAbsSumCoeffAxis1) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_ASUM;\n  const float kCoeff = 2.3;\n  const int kAxis = 1;\n  this->TestForward(kOp, kCoeff, kAxis);\n}\n\nTYPED_TEST(ReductionLayerTest, TestAbsSumGradient) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_ASUM;\n  this->TestGradient(kOp);\n}\n\nTYPED_TEST(ReductionLayerTest, TestAbsSumCoeffGradient) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_ASUM;\n  const float kCoeff = 2.3;\n  this->TestGradient(kOp, kCoeff);\n}\n\nTYPED_TEST(ReductionLayerTest, TestAbsSumCoeffAxis1Gradient) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_ASUM;\n  const float kCoeff = 2.3;\n  const int kAxis = 1;\n  this->TestGradient(kOp, kCoeff, kAxis);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumOfSquares) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_SUMSQ;\n  this->TestForward(kOp);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumOfSquaresCoeff) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_SUMSQ;\n  const float kCoeff = 2.3;\n  this->TestForward(kOp, kCoeff);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumOfSquaresCoeffAxis1) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_SUMSQ;\n  const float kCoeff = 2.3;\n  const int kAxis = 1;\n  this->TestForward(kOp, kCoeff, kAxis);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumOfSquaresGradient) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_SUMSQ;\n  this->TestGradient(kOp);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumOfSquaresCoeffGradient) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_SUMSQ;\n  const float kCoeff = 2.3;\n  this->TestGradient(kOp, kCoeff);\n}\n\nTYPED_TEST(ReductionLayerTest, TestSumOfSquaresCoeffAxis1Gradient) {\n  const ReductionParameter_ReductionOp kOp =\n      ReductionParameter_ReductionOp_SUMSQ;\n  const float kCoeff = 2.3;\n  const int kAxis = 1;\n  this->TestGradient(kOp, kCoeff, kAxis);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_reshape_layer.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/common_layers.hpp\"\n#include \"caffe/filler.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass ReshapeLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  ReshapeLayerTest()\n    : blob_bottom_(new Blob<Dtype>(2, 3, 6, 5)),\n      blob_top_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n\n  virtual ~ReshapeLayerTest() { delete blob_bottom_; delete blob_top_; }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(ReshapeLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(ReshapeLayerTest, TestFlattenOutputSizes) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  BlobShape* blob_shape = layer_param.mutable_reshape_param()->mutable_shape();\n  blob_shape->add_dim(0);\n  blob_shape->add_dim(-1);\n  blob_shape->add_dim(1);\n  blob_shape->add_dim(1);\n\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 3 * 6 * 5);\n  EXPECT_EQ(this->blob_top_->height(), 1);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n}\n\nTYPED_TEST(ReshapeLayerTest, TestFlattenValues) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  BlobShape* blob_shape = layer_param.mutable_reshape_param()->mutable_shape();\n  blob_shape->add_dim(0);\n  blob_shape->add_dim(-1);\n  blob_shape->add_dim(1);\n  blob_shape->add_dim(1);\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int c = 0; c < 3 * 6 * 5; ++c) {\n    EXPECT_EQ(this->blob_top_->data_at(0, c, 0, 0),\n        this->blob_bottom_->data_at(0, c / (6 * 5), (c / 5) % 6, c % 5));\n    EXPECT_EQ(this->blob_top_->data_at(1, c, 0, 0),\n        this->blob_bottom_->data_at(1, c / (6 * 5), (c / 5) % 6, c % 5));\n  }\n}\n\n// Test whether setting output dimensions to 0 either explicitly or implicitly\n// copies the respective dimension of the input layer.\nTYPED_TEST(ReshapeLayerTest, TestCopyDimensions) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  BlobShape* blob_shape = layer_param.mutable_reshape_param()->mutable_shape();\n  blob_shape->add_dim(0);\n  blob_shape->add_dim(0);\n  blob_shape->add_dim(0);\n  blob_shape->add_dim(0);\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 3);\n  EXPECT_EQ(this->blob_top_->height(), 6);\n  EXPECT_EQ(this->blob_top_->width(), 5);\n}\n\n// When a dimension is set to -1, we should infer its value from the other\n// dimensions (including those that get copied from below).\nTYPED_TEST(ReshapeLayerTest, TestInferenceOfUnspecified) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  BlobShape* blob_shape = layer_param.mutable_reshape_param()->mutable_shape();\n  blob_shape->add_dim(0);\n  blob_shape->add_dim(3);\n  blob_shape->add_dim(10);\n  blob_shape->add_dim(-1);\n\n  // Count is 180, thus height should be 180 / (2*3*10) = 3.\n\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 3);\n  EXPECT_EQ(this->blob_top_->height(), 10);\n  EXPECT_EQ(this->blob_top_->width(), 3);\n}\n\nTYPED_TEST(ReshapeLayerTest, TestInferenceOfUnspecifiedWithStartAxis) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_reshape_param()->set_axis(1);\n  BlobShape* blob_shape = layer_param.mutable_reshape_param()->mutable_shape();\n  blob_shape->add_dim(3);\n  blob_shape->add_dim(10);\n  blob_shape->add_dim(-1);\n\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  ASSERT_EQ(this->blob_top_->num_axes(), 4);\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 3);\n  EXPECT_EQ(this->blob_top_->height(), 10);\n  EXPECT_EQ(this->blob_top_->width(), 3);\n}\n\nTYPED_TEST(ReshapeLayerTest, TestInsertSingletonAxesStart) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_reshape_param()->set_axis(0);\n  layer_param.mutable_reshape_param()->set_num_axes(0);\n  BlobShape* blob_shape = layer_param.mutable_reshape_param()->mutable_shape();\n  blob_shape->add_dim(1);\n  blob_shape->add_dim(1);\n  blob_shape->add_dim(1);\n\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  ASSERT_EQ(this->blob_top_->num_axes(), 7);\n  EXPECT_EQ(this->blob_top_->shape(0), 1);\n  EXPECT_EQ(this->blob_top_->shape(1), 1);\n  EXPECT_EQ(this->blob_top_->shape(2), 1);\n  EXPECT_EQ(this->blob_top_->shape(3), 2);\n  EXPECT_EQ(this->blob_top_->shape(4), 3);\n  EXPECT_EQ(this->blob_top_->shape(5), 6);\n  EXPECT_EQ(this->blob_top_->shape(6), 5);\n}\n\nTYPED_TEST(ReshapeLayerTest, TestInsertSingletonAxesMiddle) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_reshape_param()->set_axis(2);\n  layer_param.mutable_reshape_param()->set_num_axes(0);\n  BlobShape* blob_shape = layer_param.mutable_reshape_param()->mutable_shape();\n  blob_shape->add_dim(1);\n  blob_shape->add_dim(1);\n  blob_shape->add_dim(1);\n\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  ASSERT_EQ(this->blob_top_->num_axes(), 7);\n  EXPECT_EQ(this->blob_top_->shape(0), 2);\n  EXPECT_EQ(this->blob_top_->shape(1), 3);\n  EXPECT_EQ(this->blob_top_->shape(2), 1);\n  EXPECT_EQ(this->blob_top_->shape(3), 1);\n  EXPECT_EQ(this->blob_top_->shape(4), 1);\n  EXPECT_EQ(this->blob_top_->shape(5), 6);\n  EXPECT_EQ(this->blob_top_->shape(6), 5);\n}\n\nTYPED_TEST(ReshapeLayerTest, TestInsertSingletonAxesEnd) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_reshape_param()->set_axis(-1);\n  layer_param.mutable_reshape_param()->set_num_axes(0);\n  BlobShape* blob_shape = layer_param.mutable_reshape_param()->mutable_shape();\n  blob_shape->add_dim(1);\n  blob_shape->add_dim(1);\n  blob_shape->add_dim(1);\n\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  ASSERT_EQ(this->blob_top_->num_axes(), 7);\n  EXPECT_EQ(this->blob_top_->shape(0), 2);\n  EXPECT_EQ(this->blob_top_->shape(1), 3);\n  EXPECT_EQ(this->blob_top_->shape(2), 6);\n  EXPECT_EQ(this->blob_top_->shape(3), 5);\n  EXPECT_EQ(this->blob_top_->shape(4), 1);\n  EXPECT_EQ(this->blob_top_->shape(5), 1);\n  EXPECT_EQ(this->blob_top_->shape(6), 1);\n}\n\nTYPED_TEST(ReshapeLayerTest, TestFlattenMiddle) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_reshape_param()->set_axis(1);\n  layer_param.mutable_reshape_param()->set_num_axes(2);\n  BlobShape* blob_shape = layer_param.mutable_reshape_param()->mutable_shape();\n  blob_shape->add_dim(-1);\n\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  ASSERT_EQ(this->blob_top_->num_axes(), 3);\n  EXPECT_EQ(this->blob_top_->shape(0), 2);\n  EXPECT_EQ(this->blob_top_->shape(1), 3 * 6);\n  EXPECT_EQ(this->blob_top_->shape(2), 5);\n}\n\nTYPED_TEST(ReshapeLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  BlobShape* shape = layer_param.mutable_reshape_param()->mutable_shape();\n  shape->add_dim(6);\n  shape->add_dim(2);\n  shape->add_dim(3);\n  shape->add_dim(5);\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_EQ(this->blob_top_->cpu_data()[i],\n              this->blob_bottom_->cpu_data()[i]);\n  }\n}\n\nTYPED_TEST(ReshapeLayerTest, TestForwardAfterReshape) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  BlobShape* shape = layer_param.mutable_reshape_param()->mutable_shape();\n  shape->add_dim(6);\n  shape->add_dim(2);\n  shape->add_dim(3);\n  shape->add_dim(5);\n  ReshapeLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // We know the above produced the correct result from TestForward.\n  // Reshape the bottom and call layer.Reshape, then try again.\n  vector<int> new_bottom_shape(1, 2 * 3 * 6 * 5);\n  this->blob_bottom_->Reshape(new_bottom_shape);\n  layer.Reshape(this->blob_bottom_vec_, this->blob_top_vec_);\n  FillerParameter filler_param;\n  GaussianFiller<Dtype> filler(filler_param);\n  filler.Fill(this->blob_bottom_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_EQ(this->blob_top_->cpu_data()[i],\n              this->blob_bottom_->cpu_data()[i]);\n  }\n}\n\nTYPED_TEST(ReshapeLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  BlobShape* shape = layer_param.mutable_reshape_param()->mutable_shape();\n  shape->add_dim(6);\n  shape->add_dim(2);\n  shape->add_dim(3);\n  shape->add_dim(5);\n  ReshapeLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_sigmoid_cross_entropy_loss_layer.cpp",
    "content": "#include <cmath>\n#include <cstdlib>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass SigmoidCrossEntropyLossLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  SigmoidCrossEntropyLossLayerTest()\n      : blob_bottom_data_(new Blob<Dtype>(10, 5, 1, 1)),\n        blob_bottom_targets_(new Blob<Dtype>(10, 5, 1, 1)),\n        blob_top_loss_(new Blob<Dtype>()) {\n    // Fill the data vector\n    FillerParameter data_filler_param;\n    data_filler_param.set_std(1);\n    GaussianFiller<Dtype> data_filler(data_filler_param);\n    data_filler.Fill(blob_bottom_data_);\n    blob_bottom_vec_.push_back(blob_bottom_data_);\n    // Fill the targets vector\n    FillerParameter targets_filler_param;\n    targets_filler_param.set_min(0);\n    targets_filler_param.set_max(1);\n    UniformFiller<Dtype> targets_filler(targets_filler_param);\n    targets_filler.Fill(blob_bottom_targets_);\n    blob_bottom_vec_.push_back(blob_bottom_targets_);\n    blob_top_vec_.push_back(blob_top_loss_);\n  }\n  virtual ~SigmoidCrossEntropyLossLayerTest() {\n    delete blob_bottom_data_;\n    delete blob_bottom_targets_;\n    delete blob_top_loss_;\n  }\n\n  Dtype SigmoidCrossEntropyLossReference(const int count, const int num,\n                                         const Dtype* input,\n                                         const Dtype* target) {\n    Dtype loss = 0;\n    for (int i = 0; i < count; ++i) {\n      const Dtype prediction = 1 / (1 + exp(-input[i]));\n      EXPECT_LE(prediction, 1);\n      EXPECT_GE(prediction, 0);\n      EXPECT_LE(target[i], 1);\n      EXPECT_GE(target[i], 0);\n      loss -= target[i] * log(prediction + (target[i] == Dtype(0)));\n      loss -= (1 - target[i]) * log(1 - prediction + (target[i] == Dtype(1)));\n    }\n    return loss / num;\n  }\n\n  void TestForward() {\n    LayerParameter layer_param;\n    const Dtype kLossWeight = 3.7;\n    layer_param.add_loss_weight(kLossWeight);\n    FillerParameter data_filler_param;\n    data_filler_param.set_std(1);\n    GaussianFiller<Dtype> data_filler(data_filler_param);\n    FillerParameter targets_filler_param;\n    targets_filler_param.set_min(0.0);\n    targets_filler_param.set_max(1.0);\n    UniformFiller<Dtype> targets_filler(targets_filler_param);\n    Dtype eps = 2e-2;\n    for (int i = 0; i < 100; ++i) {\n      // Fill the data vector\n      data_filler.Fill(this->blob_bottom_data_);\n      // Fill the targets vector\n      targets_filler.Fill(this->blob_bottom_targets_);\n      SigmoidCrossEntropyLossLayer<Dtype> layer(layer_param);\n      layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n      Dtype layer_loss =\n          layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n      const int count = this->blob_bottom_data_->count();\n      const int num = this->blob_bottom_data_->num();\n      const Dtype* blob_bottom_data = this->blob_bottom_data_->cpu_data();\n      const Dtype* blob_bottom_targets =\n          this->blob_bottom_targets_->cpu_data();\n      Dtype reference_loss = kLossWeight * SigmoidCrossEntropyLossReference(\n          count, num, blob_bottom_data, blob_bottom_targets);\n      EXPECT_NEAR(reference_loss, layer_loss, eps) << \"debug: trial #\" << i;\n    }\n  }\n\n  Blob<Dtype>* const blob_bottom_data_;\n  Blob<Dtype>* const blob_bottom_targets_;\n  Blob<Dtype>* const blob_top_loss_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(SigmoidCrossEntropyLossLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(SigmoidCrossEntropyLossLayerTest, TestSigmoidCrossEntropyLoss) {\n  this->TestForward();\n}\n\nTYPED_TEST(SigmoidCrossEntropyLossLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  const Dtype kLossWeight = 3.7;\n  layer_param.add_loss_weight(kLossWeight);\n  SigmoidCrossEntropyLossLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n}\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_slice_layer.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass SliceLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  SliceLayerTest()\n      : blob_bottom_(new Blob<Dtype>(6, 12, 2, 3)),\n        blob_top_0_(new Blob<Dtype>()),\n        blob_top_1_(new Blob<Dtype>()),\n        blob_top_2_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    // fill the values\n    Caffe::set_random_seed(1701);\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_top_vec_0_.push_back(blob_top_0_);\n    blob_top_vec_0_.push_back(blob_top_1_);\n    blob_top_vec_1_.push_back(blob_top_0_);\n    blob_top_vec_1_.push_back(blob_top_1_);\n    blob_top_vec_1_.push_back(blob_top_2_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n  }\n\n  virtual void ReduceBottomBlobSize() {\n    blob_bottom_->Reshape(4, 5, 2, 2);\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n  }\n\n  virtual ~SliceLayerTest() {\n    delete blob_top_0_; delete blob_top_1_;\n    delete blob_top_2_; delete blob_bottom_;\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_0_;\n  Blob<Dtype>* const blob_top_1_;\n  Blob<Dtype>* const blob_top_2_;\n  vector<Blob<Dtype>*> blob_top_vec_0_, blob_top_vec_1_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n};\n\nTYPED_TEST_CASE(SliceLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(SliceLayerTest, TestSetupNum) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_slice_param()->set_axis(0);\n  SliceLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_1_);\n  EXPECT_EQ(this->blob_bottom_->num(), 3 * this->blob_top_0_->num());\n  EXPECT_EQ(this->blob_top_0_->num(), this->blob_top_1_->num());\n  EXPECT_EQ(this->blob_top_0_->num(), this->blob_top_2_->num());\n  EXPECT_EQ(this->blob_bottom_->channels(), this->blob_top_0_->channels());\n  EXPECT_EQ(this->blob_bottom_->height(), this->blob_top_0_->height());\n  EXPECT_EQ(this->blob_bottom_->width(), this->blob_top_0_->width());\n}\n\nTYPED_TEST(SliceLayerTest, TestSetupChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_slice_param()->add_slice_point(3);\n  SliceLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_0_);\n  EXPECT_EQ(this->blob_top_0_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_0_->channels(), 3);\n  EXPECT_EQ(this->blob_top_1_->channels(), 9);\n  EXPECT_EQ(this->blob_bottom_->channels(),\n    this->blob_top_0_->channels() + this->blob_top_1_->channels());\n  EXPECT_EQ(this->blob_bottom_->height(), this->blob_top_0_->height());\n  EXPECT_EQ(this->blob_bottom_->width(), this->blob_top_0_->width());\n}\n\nTYPED_TEST(SliceLayerTest, TestSliceAcrossNum) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_slice_param()->set_axis(0);\n  SliceLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_0_);\n  const int top_num = this->blob_bottom_->num() / 2;\n  ASSERT_EQ(top_num, this->blob_top_0_->num());\n  ASSERT_EQ(top_num, this->blob_top_1_->num());\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_0_);\n  for (int n = 0; n < top_num; ++n) {\n    for (int c = 0; c < this->blob_top_0_->channels(); ++c) {\n      for (int h = 0; h < this->blob_bottom_->height(); ++h) {\n        for (int w = 0; w < this->blob_bottom_->width(); ++w) {\n          EXPECT_EQ(this->blob_bottom_->data_at(n, c, h, w),\n                    this->blob_top_0_->data_at(n, c, h, w));\n        }\n      }\n    }\n    for (int c = 0; c < this->blob_top_1_->channels(); ++c) {\n      for (int h = 0; h < this->blob_bottom_->height(); ++h) {\n        for (int w = 0; w < this->blob_bottom_->width(); ++w) {\n          EXPECT_EQ(this->blob_bottom_->data_at(n + 3, c, h, w),\n                    this->blob_top_1_->data_at(n, c, h, w));\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(SliceLayerTest, TestSliceAcrossChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  // Slice at 2, 8: should produce output blobs with #channels 2, 6, 4.\n  const int kSlicePoint0 = 2;\n  const int kSlicePoint1 = 8;\n  layer_param.mutable_slice_param()->add_slice_point(kSlicePoint0);\n  layer_param.mutable_slice_param()->add_slice_point(kSlicePoint1);\n  SliceLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_1_);\n  ASSERT_EQ(kSlicePoint0, this->blob_top_0_->channels());\n  ASSERT_EQ(kSlicePoint1 - kSlicePoint0, this->blob_top_1_->channels());\n  ASSERT_EQ(this->blob_bottom_->channels() - kSlicePoint1,\n            this->blob_top_2_->channels());\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_1_);\n  for (int n = 0; n < this->blob_bottom_->num(); ++n) {\n    for (int c = 0; c < this->blob_top_0_->channels(); ++c) {\n      for (int h = 0; h < this->blob_bottom_->height(); ++h) {\n        for (int w = 0; w < this->blob_bottom_->width(); ++w) {\n          EXPECT_EQ(this->blob_bottom_->data_at(n, c, h, w),\n              this->blob_top_0_->data_at(n, c, h, w));\n        }\n      }\n    }\n    for (int c = 0; c < this->blob_top_1_->channels(); ++c) {\n      for (int h = 0; h < this->blob_bottom_->height(); ++h) {\n        for (int w = 0; w < this->blob_bottom_->width(); ++w) {\n          EXPECT_EQ(this->blob_bottom_->data_at(n, c + kSlicePoint0, h, w),\n              this->blob_top_1_->data_at(n, c, h, w));\n        }\n      }\n    }\n    for (int c = 0; c < this->blob_top_2_->channels(); ++c) {\n      for (int h = 0; h < this->blob_bottom_->height(); ++h) {\n        for (int w = 0; w < this->blob_bottom_->width(); ++w) {\n          EXPECT_EQ(this->blob_bottom_->data_at(n, c + kSlicePoint1, h, w),\n              this->blob_top_2_->data_at(n, c, h, w));\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(SliceLayerTest, TestGradientAcrossNum) {\n  typedef typename TypeParam::Dtype Dtype;\n  // Gradient checks are slow; reduce blob size.\n  this->ReduceBottomBlobSize();\n  LayerParameter layer_param;\n  layer_param.mutable_slice_param()->set_axis(0);\n  SliceLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n    this->blob_top_vec_0_);\n}\n\nTYPED_TEST(SliceLayerTest, TestGradientAcrossChannels) {\n  typedef typename TypeParam::Dtype Dtype;\n  // Gradient checks are slow; reduce blob size.\n  this->ReduceBottomBlobSize();\n  LayerParameter layer_param;\n  const int kSlicePoint = 4;\n  layer_param.mutable_slice_param()->add_slice_point(kSlicePoint);\n  SliceLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n    this->blob_top_vec_0_);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_softmax_layer.cpp",
    "content": "#include <cmath>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass SoftmaxLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  SoftmaxLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 10, 2, 3)),\n        blob_top_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~SoftmaxLayerTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(SoftmaxLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(SoftmaxLayerTest, TestForward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  SoftmaxLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Test sum\n  for (int i = 0; i < this->blob_bottom_->num(); ++i) {\n    for (int k = 0; k < this->blob_bottom_->height(); ++k) {\n      for (int l = 0; l < this->blob_bottom_->width(); ++l) {\n        Dtype sum = 0;\n        for (int j = 0; j < this->blob_top_->channels(); ++j) {\n          sum += this->blob_top_->data_at(i, j, k, l);\n        }\n        EXPECT_GE(sum, 0.999);\n        EXPECT_LE(sum, 1.001);\n        // Test exact values\n        Dtype scale = 0;\n        for (int j = 0; j < this->blob_bottom_->channels(); ++j) {\n          scale += exp(this->blob_bottom_->data_at(i, j, k, l));\n        }\n        for (int j = 0; j < this->blob_bottom_->channels(); ++j) {\n          EXPECT_GE(this->blob_top_->data_at(i, j, k, l) + 1e-4,\n              exp(this->blob_bottom_->data_at(i, j, k, l)) / scale)\n              << \"debug: \" << i << \" \" << j;\n          EXPECT_LE(this->blob_top_->data_at(i, j, k, l) - 1e-4,\n              exp(this->blob_bottom_->data_at(i, j, k, l)) / scale)\n              << \"debug: \" << i << \" \" << j;\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(SoftmaxLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  SoftmaxLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n#ifdef USE_CUDNN\ntemplate <typename Dtype>\nclass CuDNNSoftmaxLayerTest : public GPUDeviceTest<Dtype> {\n protected:\n  CuDNNSoftmaxLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 10, 2, 3)),\n        blob_top_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~CuDNNSoftmaxLayerTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(CuDNNSoftmaxLayerTest, TestDtypes);\n\nTYPED_TEST(CuDNNSoftmaxLayerTest, TestForwardCuDNN) {\n  LayerParameter layer_param;\n  CuDNNSoftmaxLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Test sum\n  for (int i = 0; i < this->blob_bottom_->num(); ++i) {\n    for (int k = 0; k < this->blob_bottom_->height(); ++k) {\n      for (int l = 0; l < this->blob_bottom_->width(); ++l) {\n        TypeParam sum = 0;\n        for (int j = 0; j < this->blob_top_->channels(); ++j) {\n          sum += this->blob_top_->data_at(i, j, k, l);\n        }\n        EXPECT_GE(sum, 0.999);\n        EXPECT_LE(sum, 1.001);\n        // Test exact values\n        TypeParam scale = 0;\n        for (int j = 0; j < this->blob_bottom_->channels(); ++j) {\n          scale += exp(this->blob_bottom_->data_at(i, j, k, l));\n        }\n        for (int j = 0; j < this->blob_bottom_->channels(); ++j) {\n          EXPECT_GE(this->blob_top_->data_at(i, j, k, l) + 1e-4,\n              exp(this->blob_bottom_->data_at(i, j, k, l)) / scale)\n              << \"debug: \" << i << \" \" << j;\n          EXPECT_LE(this->blob_top_->data_at(i, j, k, l) - 1e-4,\n              exp(this->blob_bottom_->data_at(i, j, k, l)) / scale)\n              << \"debug: \" << i << \" \" << j;\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(CuDNNSoftmaxLayerTest, TestGradientCuDNN) {\n  LayerParameter layer_param;\n  CuDNNSoftmaxLayer<TypeParam> layer(layer_param);\n  GradientChecker<TypeParam> checker(1e-2, 1e-3);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n#endif\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_softmax_with_loss_layer.cpp",
    "content": "#include <cmath>\n#include <cstdlib>\n#include <cstring>\n#include <vector>\n\n#include \"boost/scoped_ptr.hpp\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nusing boost::scoped_ptr;\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass SoftmaxWithLossLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  SoftmaxWithLossLayerTest()\n      : blob_bottom_data_(new Blob<Dtype>(10, 5, 2, 3)),\n        blob_bottom_label_(new Blob<Dtype>(10, 1, 2, 3)),\n        blob_top_loss_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    filler_param.set_std(10);\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_data_);\n    blob_bottom_vec_.push_back(blob_bottom_data_);\n    for (int i = 0; i < blob_bottom_label_->count(); ++i) {\n      blob_bottom_label_->mutable_cpu_data()[i] = caffe_rng_rand() % 5;\n    }\n    blob_bottom_vec_.push_back(blob_bottom_label_);\n    blob_top_vec_.push_back(blob_top_loss_);\n  }\n  virtual ~SoftmaxWithLossLayerTest() {\n    delete blob_bottom_data_;\n    delete blob_bottom_label_;\n    delete blob_top_loss_;\n  }\n  Blob<Dtype>* const blob_bottom_data_;\n  Blob<Dtype>* const blob_bottom_label_;\n  Blob<Dtype>* const blob_top_loss_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(SoftmaxWithLossLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(SoftmaxWithLossLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.add_loss_weight(3);\n  SoftmaxWithLossLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n}\n\nTYPED_TEST(SoftmaxWithLossLayerTest, TestForwardIgnoreLabel) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_loss_param()->set_normalize(false);\n  // First, compute the loss with all labels\n  scoped_ptr<SoftmaxWithLossLayer<Dtype> > layer(\n      new SoftmaxWithLossLayer<Dtype>(layer_param));\n  layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  Dtype full_loss = this->blob_top_loss_->cpu_data()[0];\n  // Now, accumulate the loss, ignoring each label in {0, ..., 4} in turn.\n  Dtype accum_loss = 0;\n  for (int label = 0; label < 5; ++label) {\n    layer_param.mutable_loss_param()->set_ignore_label(label);\n    layer.reset(new SoftmaxWithLossLayer<Dtype>(layer_param));\n    layer->SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    layer->Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    accum_loss += this->blob_top_loss_->cpu_data()[0];\n  }\n  // Check that each label was included all but once.\n  EXPECT_NEAR(4 * full_loss, accum_loss, 1e-4);\n}\n\nTYPED_TEST(SoftmaxWithLossLayerTest, TestGradientIgnoreLabel) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  // labels are in {0, ..., 4}, so we'll ignore about a fifth of them\n  layer_param.mutable_loss_param()->set_ignore_label(0);\n  SoftmaxWithLossLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n}\n\nTYPED_TEST(SoftmaxWithLossLayerTest, TestGradientUnnormalized) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_loss_param()->set_normalize(false);\n  SoftmaxWithLossLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_, 0);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_solver.cpp",
    "content": "#include <string>\n#include <utility>\n#include <vector>\n\n#include \"google/protobuf/text_format.h\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/solver.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nusing std::ostringstream;\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass SolverTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  virtual void InitSolverFromProtoString(const string& proto) {\n    SolverParameter param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(proto, &param));\n    // Set the solver_mode according to current Caffe::mode.\n    switch (Caffe::mode()) {\n      case Caffe::CPU:\n        param.set_solver_mode(SolverParameter_SolverMode_CPU);\n        break;\n      case Caffe::GPU:\n        param.set_solver_mode(SolverParameter_SolverMode_GPU);\n        break;\n      default:\n        LOG(FATAL) << \"Unknown Caffe mode: \" << Caffe::mode();\n    }\n    solver_.reset(new SGDSolver<Dtype>(param));\n  }\n\n  shared_ptr<Solver<Dtype> > solver_;\n};\n\nTYPED_TEST_CASE(SolverTest, TestDtypesAndDevices);\n\nTYPED_TEST(SolverTest, TestInitTrainTestNets) {\n  const string& proto =\n     \"test_interval: 10 \"\n     \"test_iter: 10 \"\n     \"test_state: { stage: 'with-softmax' }\"\n     \"test_iter: 10 \"\n     \"test_state: {}\"\n     \"net_param { \"\n     \"  name: 'TestNetwork' \"\n     \"  layer { \"\n     \"    name: 'data' \"\n     \"    type: 'DummyData' \"\n     \"    dummy_data_param { \"\n     \"      shape { \"\n     \"        dim: 5 \"\n     \"        dim: 2 \"\n     \"        dim: 3 \"\n     \"        dim: 4 \"\n     \"      } \"\n     \"      shape { \"\n     \"        dim: 5 \"\n     \"      } \"\n     \"    } \"\n     \"    top: 'data' \"\n     \"    top: 'label' \"\n     \"  } \"\n     \"  layer { \"\n     \"    name: 'innerprod' \"\n     \"    type: 'InnerProduct' \"\n     \"    inner_product_param { \"\n     \"      num_output: 10 \"\n     \"    } \"\n     \"    bottom: 'data' \"\n     \"    top: 'innerprod' \"\n     \"  } \"\n     \"  layer { \"\n     \"    name: 'accuracy' \"\n     \"    type: 'Accuracy' \"\n     \"    bottom: 'innerprod' \"\n     \"    bottom: 'label' \"\n     \"    top: 'accuracy' \"\n     \"    exclude: { phase: TRAIN } \"\n     \"  } \"\n     \"  layer { \"\n     \"    name: 'loss' \"\n     \"    type: 'SoftmaxWithLoss' \"\n     \"    bottom: 'innerprod' \"\n     \"    bottom: 'label' \"\n     \"    include: { phase: TRAIN } \"\n     \"    include: { phase: TEST stage: 'with-softmax' } \"\n     \"  } \"\n     \"} \";\n  this->InitSolverFromProtoString(proto);\n  ASSERT_TRUE(this->solver_->net() != NULL);\n  EXPECT_TRUE(this->solver_->net()->has_layer(\"loss\"));\n  EXPECT_FALSE(this->solver_->net()->has_layer(\"accuracy\"));\n  ASSERT_EQ(2, this->solver_->test_nets().size());\n  EXPECT_TRUE(this->solver_->test_nets()[0]->has_layer(\"loss\"));\n  EXPECT_TRUE(this->solver_->test_nets()[0]->has_layer(\"accuracy\"));\n  EXPECT_FALSE(this->solver_->test_nets()[1]->has_layer(\"loss\"));\n  EXPECT_TRUE(this->solver_->test_nets()[1]->has_layer(\"accuracy\"));\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_split_layer.cpp",
    "content": "#include <cstring>\n#include <string>\n#include <vector>\n\n#include \"google/protobuf/text_format.h\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/insert_splits.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass SplitLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  SplitLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 6, 5)),\n        blob_top_a_(new Blob<Dtype>()),\n        blob_top_b_(new Blob<Dtype>()) {\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_a_);\n    blob_top_vec_.push_back(blob_top_b_);\n  }\n  virtual ~SplitLayerTest() {\n    delete blob_bottom_;\n    delete blob_top_a_;\n    delete blob_top_b_;\n  }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_a_;\n  Blob<Dtype>* const blob_top_b_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(SplitLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(SplitLayerTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  SplitLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_a_->num(), 2);\n  EXPECT_EQ(this->blob_top_a_->channels(), 3);\n  EXPECT_EQ(this->blob_top_a_->height(), 6);\n  EXPECT_EQ(this->blob_top_a_->width(), 5);\n  EXPECT_EQ(this->blob_top_b_->num(), 2);\n  EXPECT_EQ(this->blob_top_b_->channels(), 3);\n  EXPECT_EQ(this->blob_top_b_->height(), 6);\n  EXPECT_EQ(this->blob_top_b_->width(), 5);\n}\n\nTYPED_TEST(SplitLayerTest, Test) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  SplitLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    Dtype bottom_value = this->blob_bottom_->cpu_data()[i];\n    EXPECT_EQ(bottom_value, this->blob_top_a_->cpu_data()[i]);\n    EXPECT_EQ(bottom_value, this->blob_top_b_->cpu_data()[i]);\n  }\n}\n\nTYPED_TEST(SplitLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  SplitLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-2, 1e-2);\n  checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n\nclass SplitLayerInsertionTest : public ::testing::Test {\n protected:\n  void RunInsertionTest(\n      const string& input_param_string, const string& output_param_string) {\n    // Test that InsertSplits called on the proto specified by\n    // input_param_string results in the proto specified by\n    // output_param_string.\n    NetParameter input_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        input_param_string, &input_param));\n    NetParameter expected_output_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        output_param_string, &expected_output_param));\n    NetParameter actual_output_param;\n    InsertSplits(input_param, &actual_output_param);\n    EXPECT_EQ(expected_output_param.DebugString(),\n        actual_output_param.DebugString());\n    // Also test idempotence.\n    NetParameter double_split_insert_param;\n    InsertSplits(actual_output_param, &double_split_insert_param);\n    EXPECT_EQ(actual_output_param.DebugString(),\n       double_split_insert_param.DebugString());\n  }\n};\n\nTEST_F(SplitLayerInsertionTest, TestNoInsertion1) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunInsertionTest(input_proto, input_proto);\n}\n\nTEST_F(SplitLayerInsertionTest, TestNoInsertion2) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'data_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'data' \"\n      \"  top: 'data_split_0' \"\n      \"  top: 'data_split_1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_split_0' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_split_1' \"\n      \"  top: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod1' \"\n      \"  bottom: 'innerprod2' \"\n      \"} \";\n  this->RunInsertionTest(input_proto, input_proto);\n}\n\nTEST_F(SplitLayerInsertionTest, TestNoInsertionImageNet) {\n  const string& input_proto =\n      \"name: 'CaffeNet' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  data_param { \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    batch_size: 256 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    crop_size: 227 \"\n      \"    mirror: true \"\n      \"    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv1' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 96 \"\n      \"    kernel_size: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu1' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'pool1' \"\n      \"  type: 'Pooling' \"\n      \"  pooling_param { \"\n      \"    pool: MAX \"\n      \"    kernel_size: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'norm1' \"\n      \"  type: 'LRN' \"\n      \"  lrn_param { \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool1' \"\n      \"  top: 'norm1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv2' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernel_size: 5 \"\n      \"    pad: 2 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'norm1' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu2' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'pool2' \"\n      \"  type: 'Pooling' \"\n      \"  pooling_param { \"\n      \"    pool: MAX \"\n      \"    kernel_size: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'pool2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'norm2' \"\n      \"  type: 'LRN' \"\n      \"  lrn_param { \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool2' \"\n      \"  top: 'norm2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv3' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 384 \"\n      \"    kernel_size: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'norm2' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu3' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv4' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 384 \"\n      \"    group: 2 \"\n      \"    kernel_size: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu4' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv5' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernel_size: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu5' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'pool5' \"\n      \"  type: 'Pooling' \"\n      \"  pooling_param { \"\n      \"    kernel_size: 3 \"\n      \"    pool: MAX \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'pool5' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'fc6' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'pool5' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu6' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'drop6' \"\n      \"  type: 'Dropout' \"\n      \"  dropout_param { \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'fc7' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu7' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'drop7' \"\n      \"  type: 'Dropout' \"\n      \"  dropout_param { \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'fc8' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunInsertionTest(input_proto, input_proto);\n}\n\nTEST_F(SplitLayerInsertionTest, TestNoInsertionWithInPlace) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'innerprod' \"\n      \"  top: 'innerprod' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'innerprod' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunInsertionTest(input_proto, input_proto);\n}\n\nTEST_F(SplitLayerInsertionTest, TestLossInsertion) {\n  const string& input_proto =\n      \"name: 'UnsharedWeightsNetwork' \"\n      \"force_backward: true \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'DummyData' \"\n      \"  dummy_data_param { \"\n      \"    num: 5 \"\n      \"    channels: 2 \"\n      \"    height: 3 \"\n      \"    width: 4 \"\n      \"    data_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerproduct1' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 10 \"\n      \"    bias_term: false \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 10 \"\n      \"    } \"\n      \"  } \"\n      \"  param { name: 'unsharedweights1' } \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerproduct1' \"\n      \"  loss_weight: 2.5 \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerproduct2' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 10 \"\n      \"    bias_term: false \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 10 \"\n      \"    } \"\n      \"  } \"\n      \"  param { name: 'unsharedweights2' } \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerproduct2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerproduct1' \"\n      \"  bottom: 'innerproduct2' \"\n      \"} \";\n  const string& expected_output_proto =\n      \"name: 'UnsharedWeightsNetwork' \"\n      \"force_backward: true \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'DummyData' \"\n      \"  dummy_data_param { \"\n      \"    num: 5 \"\n      \"    channels: 2 \"\n      \"    height: 3 \"\n      \"    width: 4 \"\n      \"    data_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'data_data_0_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'data' \"\n      \"  top: 'data_data_0_split_0' \"\n      \"  top: 'data_data_0_split_1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerproduct1' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 10 \"\n      \"    bias_term: false \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 10 \"\n      \"    } \"\n      \"  } \"\n      \"  param { name: 'unsharedweights1' } \"\n      \"  bottom: 'data_data_0_split_0' \"\n      \"  top: 'innerproduct1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerproduct1_innerproduct1_0_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'innerproduct1' \"\n      \"  top: 'innerproduct1_innerproduct1_0_split_0' \"\n      \"  top: 'innerproduct1_innerproduct1_0_split_1' \"\n      \"  loss_weight: 2.5 \"\n      \"  loss_weight: 0 \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerproduct2' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 10 \"\n      \"    bias_term: false \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 10 \"\n      \"    } \"\n      \"  } \"\n      \"  param { name: 'unsharedweights2' } \"\n      \"  bottom: 'data_data_0_split_1' \"\n      \"  top: 'innerproduct2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerproduct1_innerproduct1_0_split_1' \"\n      \"  bottom: 'innerproduct2' \"\n      \"} \";\n  this->RunInsertionTest(input_proto, expected_output_proto);\n}\n\nTEST_F(SplitLayerInsertionTest, TestInsertion) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod3' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss1' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod1' \"\n      \"  bottom: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss2' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod2' \"\n      \"  bottom: 'innerprod3' \"\n      \"} \";\n  const string& expected_output_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'data_data_0_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'data' \"\n      \"  top: 'data_data_0_split_0' \"\n      \"  top: 'data_data_0_split_1' \"\n      \"  top: 'data_data_0_split_2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_data_0_split_0' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_data_0_split_1' \"\n      \"  top: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2_innerprod2_0_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'innerprod2' \"\n      \"  top: 'innerprod2_innerprod2_0_split_0' \"\n      \"  top: 'innerprod2_innerprod2_0_split_1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod3' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_data_0_split_2' \"\n      \"  top: 'innerprod3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss1' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod1' \"\n      \"  bottom: 'innerprod2_innerprod2_0_split_0' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss2' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod2_innerprod2_0_split_1' \"\n      \"  bottom: 'innerprod3' \"\n      \"} \";\n  this->RunInsertionTest(input_proto, expected_output_proto);\n}\n\nTEST_F(SplitLayerInsertionTest, TestInsertionTwoTop) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'label' \"\n      \"  top: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod3' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod4' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'label' \"\n      \"  top: 'innerprod4' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss1' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod1' \"\n      \"  bottom: 'innerprod3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss2' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod2' \"\n      \"  bottom: 'innerprod4' \"\n      \"} \";\n  const string& expected_output_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'data_data_0_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'data' \"\n      \"  top: 'data_data_0_split_0' \"\n      \"  top: 'data_data_0_split_1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'label_data_1_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'label' \"\n      \"  top: 'label_data_1_split_0' \"\n      \"  top: 'label_data_1_split_1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_data_0_split_0' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'label_data_1_split_0' \"\n      \"  top: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod3' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_data_0_split_1' \"\n      \"  top: 'innerprod3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod4' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'label_data_1_split_1' \"\n      \"  top: 'innerprod4' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss1' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod1' \"\n      \"  bottom: 'innerprod3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss2' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod2' \"\n      \"  bottom: 'innerprod4' \"\n      \"} \";\n  this->RunInsertionTest(input_proto, expected_output_proto);\n}\n\nTEST_F(SplitLayerInsertionTest, TestInputInsertion) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"input: 'data' \"\n      \"input_dim: 10 \"\n      \"input_dim: 3 \"\n      \"input_dim: 227 \"\n      \"input_dim: 227 \"\n      \"layer { \"\n      \"  name: 'innerprod1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod1' \"\n      \"  bottom: 'innerprod2' \"\n      \"} \";\n  const string& expected_output_proto =\n      \"name: 'TestNetwork' \"\n      \"input: 'data' \"\n      \"input_dim: 10 \"\n      \"input_dim: 3 \"\n      \"input_dim: 227 \"\n      \"input_dim: 227 \"\n      \"layer { \"\n      \"  name: 'data_input_0_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'data' \"\n      \"  top: 'data_input_0_split_0' \"\n      \"  top: 'data_input_0_split_1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_input_0_split_0' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_input_0_split_1' \"\n      \"  top: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod1' \"\n      \"  bottom: 'innerprod2' \"\n      \"} \";\n  this->RunInsertionTest(input_proto, expected_output_proto);\n}\n\nTEST_F(SplitLayerInsertionTest, TestWithInPlace) {\n  const string& input_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu1' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'innerprod1' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'innerprod1' \"\n      \"  top: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss1' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod1' \"\n      \"  bottom: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss2' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod2' \"\n      \"  bottom: 'data' \"\n      \"} \";\n  const string& expected_output_proto =\n      \"name: 'TestNetwork' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'data_data_0_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'data' \"\n      \"  top: 'data_data_0_split_0' \"\n      \"  top: 'data_data_0_split_1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod1' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'data_data_0_split_0' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu1' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'innerprod1' \"\n      \"  top: 'innerprod1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod1_relu1_0_split' \"\n      \"  type: 'Split' \"\n      \"  bottom: 'innerprod1' \"\n      \"  top: 'innerprod1_relu1_0_split_0' \"\n      \"  top: 'innerprod1_relu1_0_split_1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'innerprod2' \"\n      \"  type: 'InnerProduct' \"\n      \"  bottom: 'innerprod1_relu1_0_split_0' \"\n      \"  top: 'innerprod2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss1' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod1_relu1_0_split_1' \"\n      \"  bottom: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss2' \"\n      \"  type: 'EuclideanLoss' \"\n      \"  bottom: 'innerprod2' \"\n      \"  bottom: 'data_data_0_split_1' \"\n      \"} \";\n  this->RunInsertionTest(input_proto, expected_output_proto);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_spp_layer.cpp",
    "content": "#include <algorithm>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass SPPLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  SPPLayerTest()\n      : blob_bottom_(new Blob<Dtype>()),\n        blob_bottom_2_(new Blob<Dtype>()),\n        blob_bottom_3_(new Blob<Dtype>()),\n        blob_top_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    Caffe::set_random_seed(1701);\n    blob_bottom_->Reshape(2, 3, 9, 8);\n    blob_bottom_2_->Reshape(4, 3, 1024, 765);\n    blob_bottom_3_->Reshape(10, 3, 7, 7);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_bottom_vec_2_.push_back(blob_bottom_2_);\n    blob_bottom_vec_3_.push_back(blob_bottom_3_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~SPPLayerTest() { delete blob_bottom_; delete blob_top_; }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_bottom_2_;\n  Blob<Dtype>* const blob_bottom_3_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_bottom_vec_2_;\n  vector<Blob<Dtype>*> blob_bottom_vec_3_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(SPPLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(SPPLayerTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_spp_param()->set_pyramid_height(3);\n  SPPLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  // expected number of pool results is geometric sum\n  // (1 - r ** n)/(1 - r) where r = 4 and n = pyramid_height\n  // (1 - 4 ** 3)/(1 - 4) = 21\n  // multiply bottom num_channels * expected_pool_results\n  // to get expected num_channels (3 * 21 = 63)\n  EXPECT_EQ(this->blob_top_->num(), 2);\n  EXPECT_EQ(this->blob_top_->channels(), 63);\n  EXPECT_EQ(this->blob_top_->height(), 1);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n}\n\nTYPED_TEST(SPPLayerTest, TestEqualOutputDims) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_spp_param()->set_pyramid_height(5);\n  SPPLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_2_, this->blob_top_vec_);\n  // expected number of pool results is geometric sum\n  // (1 - r ** n)/(1 - r) where r = 4 and n = pyramid_height\n  // (1 - 4 ** 5)/(1 - 4) = 341\n  // multiply bottom num_channels * expected_pool_results\n  // to get expected num_channels (3 * 341 = 1023)\n  EXPECT_EQ(this->blob_top_->num(), 4);\n  EXPECT_EQ(this->blob_top_->channels(), 1023);\n  EXPECT_EQ(this->blob_top_->height(), 1);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n}\n\nTYPED_TEST(SPPLayerTest, TestEqualOutputDims2) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_spp_param()->set_pyramid_height(3);\n  SPPLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_3_, this->blob_top_vec_);\n  // expected number of pool results is geometric sum\n  // (1 - r ** n)/(1 - r) where r = 4 and n = pyramid_height\n  // (1 - 4 ** 3)/(1 - 4) = 21\n  // multiply bottom num_channels * expected_pool_results\n  // to get expected num_channels (3 * 21 = 63)\n  EXPECT_EQ(this->blob_top_->num(), 10);\n  EXPECT_EQ(this->blob_top_->channels(), 63);\n  EXPECT_EQ(this->blob_top_->height(), 1);\n  EXPECT_EQ(this->blob_top_->width(), 1);\n}\n\nTYPED_TEST(SPPLayerTest, TestForwardBackward) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  layer_param.mutable_spp_param()->set_pyramid_height(3);\n  SPPLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  vector<bool> propagate_down(this->blob_bottom_vec_.size(), true);\n  layer.Backward(this->blob_top_vec_, propagate_down,\n                 this->blob_bottom_vec_);\n}\n\nTYPED_TEST(SPPLayerTest, TestGradient) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  SPPParameter* spp_param = layer_param.mutable_spp_param();\n  spp_param->set_pyramid_height(3);\n  SPPLayer<Dtype> layer(layer_param);\n  GradientChecker<Dtype> checker(1e-4, 1e-2);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  checker.CheckGradientExhaustive(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_stochastic_pooling.cpp",
    "content": "#include <algorithm>\n#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nusing std::min;\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass StochasticPoolingLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  StochasticPoolingLayerTest()\n      : blob_bottom_(new Blob<Dtype>()),\n        blob_top_(new Blob<Dtype>()) {}\n  virtual void SetUp() {\n    Caffe::set_random_seed(1701);\n    blob_bottom_->Reshape(2, 3, 6, 5);\n    // fill the values\n    FillerParameter filler_param;\n    filler_param.set_min(0.1);\n    filler_param.set_max(1.);\n    UniformFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n\n  virtual ~StochasticPoolingLayerTest() {\n    delete blob_bottom_; delete blob_top_;\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\ntemplate <typename Dtype>\nclass CPUStochasticPoolingLayerTest\n  : public StochasticPoolingLayerTest<CPUDevice<Dtype> > {\n};\n\nTYPED_TEST_CASE(CPUStochasticPoolingLayerTest, TestDtypes);\n\nTYPED_TEST(CPUStochasticPoolingLayerTest, TestSetup) {\n  LayerParameter layer_param;\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  PoolingLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), this->blob_bottom_->channels());\n  EXPECT_EQ(this->blob_top_->height(), 3);\n  EXPECT_EQ(this->blob_top_->width(), 2);\n}\n\n#ifndef CPU_ONLY\n\ntemplate <typename Dtype>\nclass GPUStochasticPoolingLayerTest\n  : public StochasticPoolingLayerTest<GPUDevice<Dtype> > {\n};\n\nTYPED_TEST_CASE(GPUStochasticPoolingLayerTest, TestDtypes);\n\nTYPED_TEST(GPUStochasticPoolingLayerTest, TestStochastic) {\n  LayerParameter layer_param;\n  layer_param.set_phase(TRAIN);\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_STOCHASTIC);\n  PoolingLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  // Check if the output is correct - it should do random sampling\n  const TypeParam* bottom_data = this->blob_bottom_->cpu_data();\n  const TypeParam* top_data = this->blob_top_->cpu_data();\n  TypeParam total = 0;\n  for (int n = 0; n < this->blob_top_->num(); ++n) {\n    for (int c = 0; c < this->blob_top_->channels(); ++c) {\n      for (int ph = 0; ph < this->blob_top_->height(); ++ph) {\n        for (int pw = 0; pw < this->blob_top_->width(); ++pw) {\n          TypeParam pooled = top_data[this->blob_top_->offset(n, c, ph, pw)];\n          total += pooled;\n          int hstart = ph * 2;\n          int hend = min(hstart + 3, this->blob_bottom_->height());\n          int wstart = pw * 2;\n          int wend = min(wstart + 3, this->blob_bottom_->width());\n          bool has_equal = false;\n          for (int h = hstart; h < hend; ++h) {\n            for (int w = wstart; w < wend; ++w) {\n              has_equal |= (pooled == bottom_data[this->blob_bottom_->\n                  offset(n, c, h, w)]);\n            }\n          }\n          EXPECT_TRUE(has_equal);\n        }\n      }\n    }\n  }\n  // When we are doing stochastic pooling, the average we get should be higher\n  // than the simple data average since we are weighting more on higher-valued\n  // ones.\n  EXPECT_GE(total / this->blob_top_->count(), 0.55);\n}\n\nTYPED_TEST(GPUStochasticPoolingLayerTest, TestStochasticTestPhase) {\n  LayerParameter layer_param;\n  layer_param.set_phase(TEST);\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_STOCHASTIC);\n  PoolingLayer<TypeParam> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n\n  // Check if the output is correct - it should do random sampling\n  const TypeParam* bottom_data = this->blob_bottom_->cpu_data();\n  const TypeParam* top_data = this->blob_top_->cpu_data();\n  for (int n = 0; n < this->blob_top_->num(); ++n) {\n    for (int c = 0; c < this->blob_top_->channels(); ++c) {\n      for (int ph = 0; ph < this->blob_top_->height(); ++ph) {\n        for (int pw = 0; pw < this->blob_top_->width(); ++pw) {\n          TypeParam pooled = top_data[this->blob_top_->offset(n, c, ph, pw)];\n          int hstart = ph * 2;\n          int hend = min(hstart + 3, this->blob_bottom_->height());\n          int wstart = pw * 2;\n          int wend = min(wstart + 3, this->blob_bottom_->width());\n          bool smaller_than_max = false;\n          for (int h = hstart; h < hend; ++h) {\n            for (int w = wstart; w < wend; ++w) {\n              smaller_than_max |= (pooled <= bottom_data[this->blob_bottom_->\n                  offset(n, c, h, w)]);\n            }\n          }\n          EXPECT_TRUE(smaller_than_max);\n        }\n      }\n    }\n  }\n}\n\nTYPED_TEST(GPUStochasticPoolingLayerTest, TestGradient) {\n  LayerParameter layer_param;\n  layer_param.set_phase(TRAIN);\n  PoolingParameter* pooling_param = layer_param.mutable_pooling_param();\n  pooling_param->set_kernel_size(3);\n  pooling_param->set_stride(2);\n  pooling_param->set_pool(PoolingParameter_PoolMethod_STOCHASTIC);\n  PoolingLayer<TypeParam> layer(layer_param);\n  GradientChecker<TypeParam> checker(1e-4, 1e-2);\n  // it is too expensive to call curand multiple times, so we don't do an\n  // exhaustive gradient check.\n  checker.CheckGradient(&layer, this->blob_bottom_vec_,\n      this->blob_top_vec_);\n}\n\n#endif\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_syncedmem.cpp",
    "content": "#include <cstring>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/common.hpp\"\n#include \"caffe/syncedmem.hpp\"\n#include \"caffe/util/device_alternate.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nclass SyncedMemoryTest : public ::testing::Test {};\n\nTEST_F(SyncedMemoryTest, TestInitialization) {\n  SyncedMemory mem(10);\n  EXPECT_EQ(mem.head(), SyncedMemory::UNINITIALIZED);\n  EXPECT_EQ(mem.size(), 10);\n  SyncedMemory* p_mem = new SyncedMemory(10 * sizeof(float));\n  EXPECT_EQ(p_mem->size(), 10 * sizeof(float));\n  delete p_mem;\n}\n\n#ifndef CPU_ONLY  // GPU test\n\nTEST_F(SyncedMemoryTest, TestAllocationCPUGPU) {\n  SyncedMemory mem(10);\n  EXPECT_TRUE(mem.cpu_data());\n  EXPECT_TRUE(mem.gpu_data());\n  EXPECT_TRUE(mem.mutable_cpu_data());\n  EXPECT_TRUE(mem.mutable_gpu_data());\n}\n\n#endif\n\nTEST_F(SyncedMemoryTest, TestAllocationCPU) {\n  SyncedMemory mem(10);\n  EXPECT_TRUE(mem.cpu_data());\n  EXPECT_TRUE(mem.mutable_cpu_data());\n}\n\n#ifndef CPU_ONLY  // GPU test\n\nTEST_F(SyncedMemoryTest, TestAllocationGPU) {\n  SyncedMemory mem(10);\n  EXPECT_TRUE(mem.gpu_data());\n  EXPECT_TRUE(mem.mutable_gpu_data());\n}\n\n#endif\n\nTEST_F(SyncedMemoryTest, TestCPUWrite) {\n  SyncedMemory mem(10);\n  void* cpu_data = mem.mutable_cpu_data();\n  EXPECT_EQ(mem.head(), SyncedMemory::HEAD_AT_CPU);\n  caffe_memset(mem.size(), 1, cpu_data);\n  for (int i = 0; i < mem.size(); ++i) {\n    EXPECT_EQ((static_cast<char*>(cpu_data))[i], 1);\n  }\n  // do another round\n  cpu_data = mem.mutable_cpu_data();\n  EXPECT_EQ(mem.head(), SyncedMemory::HEAD_AT_CPU);\n  caffe_memset(mem.size(), 2, cpu_data);\n  for (int i = 0; i < mem.size(); ++i) {\n    EXPECT_EQ((static_cast<char*>(cpu_data))[i], 2);\n  }\n}\n\n#ifndef CPU_ONLY  // GPU test\n\nTEST_F(SyncedMemoryTest, TestGPURead) {\n  SyncedMemory mem(10);\n  void* cpu_data = mem.mutable_cpu_data();\n  EXPECT_EQ(mem.head(), SyncedMemory::HEAD_AT_CPU);\n  caffe_memset(mem.size(), 1, cpu_data);\n  const void* gpu_data = mem.gpu_data();\n  EXPECT_EQ(mem.head(), SyncedMemory::SYNCED);\n  // check if values are the same\n  char* recovered_value = new char[10];\n  caffe_gpu_memcpy(10, gpu_data, recovered_value);\n  for (int i = 0; i < mem.size(); ++i) {\n    EXPECT_EQ((static_cast<char*>(recovered_value))[i], 1);\n  }\n  // do another round\n  cpu_data = mem.mutable_cpu_data();\n  EXPECT_EQ(mem.head(), SyncedMemory::HEAD_AT_CPU);\n  caffe_memset(mem.size(), 2, cpu_data);\n  for (int i = 0; i < mem.size(); ++i) {\n    EXPECT_EQ((static_cast<char*>(cpu_data))[i], 2);\n  }\n  gpu_data = mem.gpu_data();\n  EXPECT_EQ(mem.head(), SyncedMemory::SYNCED);\n  // check if values are the same\n  caffe_gpu_memcpy(10, gpu_data, recovered_value);\n  for (int i = 0; i < mem.size(); ++i) {\n    EXPECT_EQ((static_cast<char*>(recovered_value))[i], 2);\n  }\n  delete[] recovered_value;\n}\n\nTEST_F(SyncedMemoryTest, TestGPUWrite) {\n  SyncedMemory mem(10);\n  void* gpu_data = mem.mutable_gpu_data();\n  EXPECT_EQ(mem.head(), SyncedMemory::HEAD_AT_GPU);\n  caffe_gpu_memset(mem.size(), 1, gpu_data);\n  const void* cpu_data = mem.cpu_data();\n  for (int i = 0; i < mem.size(); ++i) {\n    EXPECT_EQ((static_cast<const char*>(cpu_data))[i], 1);\n  }\n  EXPECT_EQ(mem.head(), SyncedMemory::SYNCED);\n\n  gpu_data = mem.mutable_gpu_data();\n  EXPECT_EQ(mem.head(), SyncedMemory::HEAD_AT_GPU);\n  caffe_gpu_memset(mem.size(), 2, gpu_data);\n  cpu_data = mem.cpu_data();\n  for (int i = 0; i < mem.size(); ++i) {\n    EXPECT_EQ((static_cast<const char*>(cpu_data))[i], 2);\n  }\n  EXPECT_EQ(mem.head(), SyncedMemory::SYNCED);\n}\n\n#endif\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_tanh_layer.cpp",
    "content": "#include <algorithm>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/common_layers.hpp\"\n#include \"caffe/filler.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n#include \"caffe/test/test_gradient_check_util.hpp\"\n\nnamespace caffe {\n\ndouble tanh_naive(double x) {\n  if (x < -40) {\n    // avoid negative overflow\n    return -1;\n  } else if (x > 40) {\n    // avoid positive overflow\n    return 1;\n  } else {\n    // exact expression for tanh, which is unstable for large x\n    double exp2x = exp(2 * x);\n    return (exp2x - 1.0) / (exp2x + 1.0);\n  }\n}\n\ntemplate <typename TypeParam>\nclass TanHLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n\n protected:\n  TanHLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 4, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    Caffe::set_random_seed(1701);\n    FillerParameter filler_param;\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~TanHLayerTest() { delete blob_bottom_; delete blob_top_; }\n\n  void TestForward(Dtype filler_std) {\n    FillerParameter filler_param;\n    filler_param.set_std(filler_std);\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n\n    LayerParameter layer_param;\n    TanHLayer<Dtype> layer(layer_param);\n    layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n    layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n    // Now, check values\n    const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n    const Dtype* top_data = this->blob_top_->cpu_data();\n    const Dtype min_precision = 1e-5;\n    for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n      Dtype expected_value = tanh_naive(bottom_data[i]);\n      Dtype precision = std::max(\n        Dtype(std::abs(expected_value * Dtype(1e-4))), min_precision);\n      EXPECT_NEAR(expected_value, top_data[i], precision);\n    }\n  }\n\n  void TestBackward(Dtype filler_std) {\n    FillerParameter filler_param;\n    filler_param.set_std(filler_std);\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n\n    LayerParameter layer_param;\n    TanHLayer<Dtype> layer(layer_param);\n    GradientChecker<Dtype> checker(1e-2, 1e-2, 1701);\n    checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,\n        this->blob_top_vec_);\n  }\n\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(TanHLayerTest, TestDtypesAndDevices);\n\nTYPED_TEST(TanHLayerTest, TestTanH) {\n  this->TestForward(1.0);\n}\n\nTYPED_TEST(TanHLayerTest, TestTanHOverflow) {\n  // this will fail if tanh overflow is not properly handled\n  this->TestForward(10000.0);\n}\n\nTYPED_TEST(TanHLayerTest, TestTanHGradient) {\n  this->TestBackward(1.0);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_threshold_layer.cpp",
    "content": "#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/filler.hpp\"\n#include \"caffe/vision_layers.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\ntemplate <typename TypeParam>\nclass ThresholdLayerTest : public MultiDeviceTest<TypeParam> {\n  typedef typename TypeParam::Dtype Dtype;\n protected:\n  ThresholdLayerTest()\n      : blob_bottom_(new Blob<Dtype>(2, 3, 6, 5)),\n        blob_top_(new Blob<Dtype>()) {\n    Caffe::set_random_seed(1701);\n    // fill the values\n    FillerParameter filler_param;\n    GaussianFiller<Dtype> filler(filler_param);\n    filler.Fill(this->blob_bottom_);\n    blob_bottom_vec_.push_back(blob_bottom_);\n    blob_top_vec_.push_back(blob_top_);\n  }\n  virtual ~ThresholdLayerTest() { delete blob_bottom_; delete blob_top_; }\n  Blob<Dtype>* const blob_bottom_;\n  Blob<Dtype>* const blob_top_;\n  vector<Blob<Dtype>*> blob_bottom_vec_;\n  vector<Blob<Dtype>*> blob_top_vec_;\n};\n\nTYPED_TEST_CASE(ThresholdLayerTest, TestDtypesAndDevices);\n\n\nTYPED_TEST(ThresholdLayerTest, TestSetup) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ThresholdLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  EXPECT_EQ(this->blob_top_->num(), this->blob_bottom_->num());\n  EXPECT_EQ(this->blob_top_->channels(), this->blob_bottom_->channels());\n  EXPECT_EQ(this->blob_top_->height(), this->blob_bottom_->height());\n  EXPECT_EQ(this->blob_top_->width(), this->blob_bottom_->width());\n}\n\nTYPED_TEST(ThresholdLayerTest, Test) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ThresholdLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  const Dtype threshold_ = layer_param.threshold_param().threshold();\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_GE(top_data[i], 0.);\n    EXPECT_LE(top_data[i], 1.);\n    if (top_data[i] == 0) {\n      EXPECT_LE(bottom_data[i], threshold_);\n    }\n    if (top_data[i] == 1) {\n      EXPECT_GT(bottom_data[i], threshold_);\n    }\n  }\n}\n\nTYPED_TEST(ThresholdLayerTest, Test2) {\n  typedef typename TypeParam::Dtype Dtype;\n  LayerParameter layer_param;\n  ThresholdParameter* threshold_param =\n    layer_param.mutable_threshold_param();\n  threshold_param->set_threshold(0.5);\n  ThresholdLayer<Dtype> layer(layer_param);\n  layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);\n  layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);\n  // Now, check values\n  const Dtype* bottom_data = this->blob_bottom_->cpu_data();\n  const Dtype* top_data = this->blob_top_->cpu_data();\n  const Dtype threshold_ = layer_param.threshold_param().threshold();\n  EXPECT_FLOAT_EQ(threshold_, 0.5);\n  for (int i = 0; i < this->blob_bottom_->count(); ++i) {\n    EXPECT_GE(top_data[i], 0.);\n    EXPECT_LE(top_data[i], 1.);\n    if (top_data[i] == 0) {\n      EXPECT_LE(bottom_data[i], threshold_);\n    }\n    if (top_data[i] == 1) {\n      EXPECT_GT(bottom_data[i], threshold_);\n    }\n  }\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_upgrade_proto.cpp",
    "content": "#include <cstring>\n#include <string>\n#include <vector>\n\n#include \"boost/scoped_ptr.hpp\"\n#include \"google/protobuf/text_format.h\"\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/common.hpp\"\n#include \"caffe/layer.hpp\"\n#include \"caffe/util/db.hpp\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/upgrade_proto.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nclass PaddingLayerUpgradeTest : public ::testing::Test {\n protected:\n  void RunPaddingUpgradeTest(\n      const string& input_param_string, const string& output_param_string) {\n    // Test that UpgradeV0PaddingLayers called on the proto specified by\n    // input_param_string results in the proto specified by\n    // output_param_string.\n    NetParameter input_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        input_param_string, &input_param));\n    NetParameter expected_output_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        output_param_string, &expected_output_param));\n    NetParameter actual_output_param;\n    UpgradeV0PaddingLayers(input_param, &actual_output_param);\n    EXPECT_EQ(expected_output_param.DebugString(),\n        actual_output_param.DebugString());\n    // Also test idempotence.\n    NetParameter double_pad_upgrade_param;\n    UpgradeV0PaddingLayers(actual_output_param, &double_pad_upgrade_param);\n    EXPECT_EQ(actual_output_param.DebugString(),\n       double_pad_upgrade_param.DebugString());\n  }\n};\n\nTEST_F(PaddingLayerUpgradeTest, TestSimple) {\n  const string& input_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'data' \"\n      \"    type: 'data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad1' \"\n      \"    type: 'padding' \"\n      \"    pad: 2 \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'pad1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv1' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad1' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc8' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'loss' \"\n      \"    type: 'softmax_loss' \"\n      \"  } \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  const string& expected_output_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'data' \"\n      \"    type: 'data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv1' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    pad: 2 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc8' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'loss' \"\n      \"    type: 'softmax_loss' \"\n      \"  } \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunPaddingUpgradeTest(input_proto, expected_output_proto);\n}\n\nTEST_F(PaddingLayerUpgradeTest, TestTwoTops) {\n  const string& input_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'data' \"\n      \"    type: 'data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad1' \"\n      \"    type: 'padding' \"\n      \"    pad: 2 \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'pad1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv1' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad1' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc8' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv2' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad1' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'loss' \"\n      \"    type: 'softmax_loss' \"\n      \"  } \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  const string& expected_output_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'data' \"\n      \"    type: 'data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv1' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    pad: 2 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc8' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv2' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    pad: 2 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'loss' \"\n      \"    type: 'softmax_loss' \"\n      \"  } \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunPaddingUpgradeTest(input_proto, expected_output_proto);\n}\n\nTEST_F(PaddingLayerUpgradeTest, TestImageNet) {\n  const string& input_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'data' \"\n      \"    type: 'data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv1' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu1' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool1' \"\n      \"    type: 'pool' \"\n      \"    pool: MAX \"\n      \"    kernelsize: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'norm1' \"\n      \"    type: 'lrn' \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool1' \"\n      \"  top: 'norm1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad2' \"\n      \"    type: 'padding' \"\n      \"    pad: 2 \"\n      \"  } \"\n      \"  bottom: 'norm1' \"\n      \"  top: 'pad2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv2' \"\n      \"    type: 'conv' \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernelsize: 5 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad2' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu2' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool2' \"\n      \"    type: 'pool' \"\n      \"    pool: MAX \"\n      \"    kernelsize: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'pool2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'norm2' \"\n      \"    type: 'lrn' \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool2' \"\n      \"  top: 'norm2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad3' \"\n      \"    type: 'padding' \"\n      \"    pad: 1 \"\n      \"  } \"\n      \"  bottom: 'norm2' \"\n      \"  top: 'pad3' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv3' \"\n      \"    type: 'conv' \"\n      \"    num_output: 384 \"\n      \"    kernelsize: 3 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad3' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu3' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad4' \"\n      \"    type: 'padding' \"\n      \"    pad: 1 \"\n      \"  } \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'pad4' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv4' \"\n      \"    type: 'conv' \"\n      \"    num_output: 384 \"\n      \"    group: 2 \"\n      \"    kernelsize: 3 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad4' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu4' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad5' \"\n      \"    type: 'padding' \"\n      \"    pad: 1 \"\n      \"  } \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'pad5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv5' \"\n      \"    type: 'conv' \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernelsize: 3 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad5' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu5' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool5' \"\n      \"    type: 'pool' \"\n      \"    kernelsize: 3 \"\n      \"    pool: MAX \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'pool5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc6' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pool5' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu6' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'drop6' \"\n      \"    type: 'dropout' \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc7' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu7' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'drop7' \"\n      \"    type: 'dropout' \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc8' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'loss' \"\n      \"    type: 'softmax_loss' \"\n      \"  } \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  const string& expected_output_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'data' \"\n      \"    type: 'data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv1' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu1' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool1' \"\n      \"    type: 'pool' \"\n      \"    pool: MAX \"\n      \"    kernelsize: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'norm1' \"\n      \"    type: 'lrn' \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool1' \"\n      \"  top: 'norm1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv2' \"\n      \"    type: 'conv' \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernelsize: 5 \"\n      \"    pad: 2 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'norm1' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu2' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool2' \"\n      \"    type: 'pool' \"\n      \"    pool: MAX \"\n      \"    kernelsize: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'pool2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'norm2' \"\n      \"    type: 'lrn' \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool2' \"\n      \"  top: 'norm2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv3' \"\n      \"    type: 'conv' \"\n      \"    num_output: 384 \"\n      \"    kernelsize: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'norm2' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu3' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv4' \"\n      \"    type: 'conv' \"\n      \"    num_output: 384 \"\n      \"    group: 2 \"\n      \"    kernelsize: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu4' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv5' \"\n      \"    type: 'conv' \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernelsize: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu5' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool5' \"\n      \"    type: 'pool' \"\n      \"    kernelsize: 3 \"\n      \"    pool: MAX \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'pool5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc6' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pool5' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu6' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'drop6' \"\n      \"    type: 'dropout' \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc7' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu7' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'drop7' \"\n      \"    type: 'dropout' \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc8' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'loss' \"\n      \"    type: 'softmax_loss' \"\n      \"  } \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunPaddingUpgradeTest(input_proto, expected_output_proto);\n}\n\nclass NetUpgradeTest : public ::testing::Test {\n protected:\n  void RunV0UpgradeTest(\n      const string& input_param_string, const string& output_param_string) {\n    // Test that UpgradeV0Net called on the NetParameter proto specified by\n    // input_param_string results in the NetParameter proto specified by\n    // output_param_string.\n    NetParameter input_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        input_param_string, &input_param));\n    NetParameter expected_output_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        output_param_string, &expected_output_param));\n    NetParameter actual_output_param;\n    UpgradeV0Net(input_param, &actual_output_param);\n    EXPECT_EQ(expected_output_param.DebugString(),\n        actual_output_param.DebugString());\n  }\n\n  void RunV1UpgradeTest(\n      const string& input_param_string, const string& output_param_string) {\n    // Test that UpgradeV0Net called on the NetParameter proto specified by\n    // input_param_string results in the NetParameter proto specified by\n    // output_param_string.\n    NetParameter input_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        input_param_string, &input_param));\n    NetParameter expected_output_param;\n    CHECK(google::protobuf::TextFormat::ParseFromString(\n        output_param_string, &expected_output_param));\n    NetParameter actual_output_param;\n    UpgradeV1Net(input_param, &actual_output_param);\n    EXPECT_EQ(expected_output_param.DebugString(),\n        actual_output_param.DebugString());\n  }\n};\n\nTEST_F(NetUpgradeTest, TestSimple) {\n  const string& v0_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'data' \"\n      \"    type: 'data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad1' \"\n      \"    type: 'padding' \"\n      \"    pad: 2 \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'pad1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv1' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad1' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc8' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'loss' \"\n      \"    type: 'softmax_loss' \"\n      \"  } \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  const string& expected_v1_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  name: 'data' \"\n      \"  type: DATA \"\n      \"  data_param { \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    batch_size: 256 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    crop_size: 227 \"\n      \"    mirror: true \"\n      \"    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'conv1' \"\n      \"  type: CONVOLUTION \"\n      \"  convolution_param { \"\n      \"    num_output: 96 \"\n      \"    kernel_size: 11 \"\n      \"    stride: 4 \"\n      \"    pad: 2 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'fc8' \"\n      \"  type: INNER_PRODUCT \"\n      \"  inner_product_param { \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'loss' \"\n      \"  type: SOFTMAX_LOSS \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunV0UpgradeTest(v0_proto, expected_v1_proto);\n\n  const string& expected_v2_proto =\n      \"name: 'CaffeNet' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  data_param { \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    batch_size: 256 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    crop_size: 227 \"\n      \"    mirror: true \"\n      \"    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv1' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 96 \"\n      \"    kernel_size: 11 \"\n      \"    stride: 4 \"\n      \"    pad: 2 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'fc8' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunV1UpgradeTest(expected_v1_proto, expected_v2_proto);\n}\n\n// Test any layer or parameter upgrades not covered by other tests.\nTEST_F(NetUpgradeTest, TestAllParams) {\n  const string& input_proto =\n      \"name: 'CaffeNet' \"\n      \"input: 'input_data' \"\n      \"input_dim: 64 \"\n      \"input_dim: 3 \"\n      \"input_dim: 32 \"\n      \"input_dim: 32 \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'data' \"\n      \"    type: 'data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"    scale: 0.25 \"\n      \"    rand_skip: 73 \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'images' \"\n      \"    type: 'images' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-images' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"    scale: 0.25 \"\n      \"    rand_skip: 73 \"\n      \"    shuffle_images: true \"\n      \"    new_height: 40 \"\n      \"    new_width: 30 \"\n      \"  } \"\n      \"  top: 'images_data' \"\n      \"  top: 'images_label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'window_data' \"\n      \"    type: 'window_data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"    det_fg_threshold: 0.25 \"\n      \"    det_bg_threshold: 0.75 \"\n      \"    det_fg_fraction: 0.5 \"\n      \"    det_context_pad: 16 \"\n      \"    det_crop_mode: 'square' \"\n      \"  } \"\n      \"  top: 'window_data' \"\n      \"  top: 'window_label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'hdf5data' \"\n      \"    type: 'hdf5_data' \"\n      \"    source: '/my/hdf5/data' \"\n      \"    batchsize: 256 \"\n      \"  } \"\n      \"  top: 'hdf5data' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv1' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    biasterm: false \"\n      \"    pad: 4 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 3. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool1ave' \"\n      \"    type: 'pool' \"\n      \"    pool: AVE \"\n      \"    kernelsize: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1ave' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool1stoch' \"\n      \"    type: 'pool' \"\n      \"    pool: STOCHASTIC \"\n      \"    kernelsize: 4 \"\n      \"    stride: 5 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1stoch' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'concat' \"\n      \"    type: 'concat' \"\n      \"    concat_dim: 2 \"\n      \"  } \"\n      \"  bottom: 'pool1ave' \"\n      \"  bottom: 'pool1stoch' \"\n      \"  top: 'pool1concat' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'norm1' \"\n      \"    type: 'lrn' \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool1concat' \"\n      \"  top: 'norm1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc6' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 4096 \"\n      \"    biasterm: false \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'norm1' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu6' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'drop6' \"\n      \"    type: 'dropout' \"\n      \"    dropout_ratio: 0.2 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'loss' \"\n      \"    type: 'infogain_loss' \"\n      \"    source: '/my/infogain/matrix' \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  bottom: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'accuracy' \"\n      \"    type: 'accuracy' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'bnll' \"\n      \"    type: 'bnll' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'euclidean_loss' \"\n      \"    type: 'euclidean_loss' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'flatten' \"\n      \"    type: 'flatten' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'hdf5_output' \"\n      \"    type: 'hdf5_output' \"\n      \"    hdf5_output_param { \"\n      \"      file_name: '/my/hdf5/output/file' \"\n      \"    } \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'im2col' \"\n      \"    type: 'im2col' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'images' \"\n      \"    type: 'images' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'multinomial_logistic_loss' \"\n      \"    type: 'multinomial_logistic_loss' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'sigmoid' \"\n      \"    type: 'sigmoid' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'softmax' \"\n      \"    type: 'softmax' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'split' \"\n      \"    type: 'split' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'tanh' \"\n      \"    type: 'tanh' \"\n      \"  } \"\n      \"} \";\n  const string& expected_output_proto =\n      \"name: 'CaffeNet' \"\n      \"input: 'input_data' \"\n      \"input_dim: 64 \"\n      \"input_dim: 3 \"\n      \"input_dim: 32 \"\n      \"input_dim: 32 \"\n      \"layers { \"\n      \"  name: 'data' \"\n      \"  type: DATA \"\n      \"  data_param { \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    batch_size: 256 \"\n      \"    rand_skip: 73 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    crop_size: 227 \"\n      \"    mirror: true \"\n      \"    scale: 0.25 \"\n      \"    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'images' \"\n      \"  type: IMAGE_DATA \"\n      \"  image_data_param { \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-images' \"\n      \"    batch_size: 256 \"\n      \"    rand_skip: 73 \"\n      \"    shuffle: true \"\n      \"    new_height: 40 \"\n      \"    new_width: 30 \"\n      \"  } \"\n      \"  transform_param {\"\n      \"    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    crop_size: 227 \"\n      \"    mirror: true \"\n      \"    scale: 0.25 \"\n      \"  } \"\n      \"  top: 'images_data' \"\n      \"  top: 'images_label' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'window_data' \"\n      \"  type: WINDOW_DATA \"\n      \"  window_data_param { \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    batch_size: 256 \"\n      \"    fg_threshold: 0.25 \"\n      \"    bg_threshold: 0.75 \"\n      \"    fg_fraction: 0.5 \"\n      \"    context_pad: 16 \"\n      \"    crop_mode: 'square' \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    mirror: true \"\n      \"    crop_size: 227 \"\n      \"    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"  }\"\n      \"  top: 'window_data' \"\n      \"  top: 'window_label' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'hdf5data' \"\n      \"  type: HDF5_DATA \"\n      \"  hdf5_data_param { \"\n      \"    source: '/my/hdf5/data' \"\n      \"    batch_size: 256 \"\n      \"  } \"\n      \"  top: 'hdf5data' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'conv1' \"\n      \"  type: CONVOLUTION \"\n      \"  convolution_param { \"\n      \"    num_output: 96 \"\n      \"    bias_term: false \"\n      \"    pad: 4 \"\n      \"    kernel_size: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 3. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'pool1ave' \"\n      \"  type: POOLING \"\n      \"  pooling_param { \"\n      \"    pool: AVE \"\n      \"    kernel_size: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1ave' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'pool1stoch' \"\n      \"  type: POOLING \"\n      \"  pooling_param { \"\n      \"    pool: STOCHASTIC \"\n      \"    kernel_size: 4 \"\n      \"    stride: 5 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1stoch' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'concat' \"\n      \"  type: CONCAT \"\n      \"  concat_param { \"\n      \"    concat_dim: 2 \"\n      \"  } \"\n      \"  bottom: 'pool1ave' \"\n      \"  bottom: 'pool1stoch' \"\n      \"  top: 'pool1concat' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'norm1' \"\n      \"  type: LRN \"\n      \"  lrn_param { \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool1concat' \"\n      \"  top: 'norm1' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'fc6' \"\n      \"  type: INNER_PRODUCT \"\n      \"  inner_product_param { \"\n      \"    num_output: 4096 \"\n      \"    bias_term: false \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'norm1' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'relu6' \"\n      \"  type: RELU \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'drop6' \"\n      \"  type: DROPOUT \"\n      \"  dropout_param { \"\n      \"    dropout_ratio: 0.2 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'loss' \"\n      \"  type: INFOGAIN_LOSS \"\n      \"  infogain_loss_param { \"\n      \"    source: '/my/infogain/matrix' \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  bottom: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'accuracy' \"\n      \"  type: ACCURACY \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'bnll' \"\n      \"  type: BNLL \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'euclidean_loss' \"\n      \"  type: EUCLIDEAN_LOSS \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'flatten' \"\n      \"  type: FLATTEN \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'hdf5_output' \"\n      \"  type: HDF5_OUTPUT \"\n      \"  hdf5_output_param { \"\n      \"    file_name: '/my/hdf5/output/file' \"\n      \"  } \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'im2col' \"\n      \"  type: IM2COL \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'images' \"\n      \"  type: IMAGE_DATA \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'multinomial_logistic_loss' \"\n      \"  type: MULTINOMIAL_LOGISTIC_LOSS \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'sigmoid' \"\n      \"  type: SIGMOID \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'softmax' \"\n      \"  type: SOFTMAX \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'split' \"\n      \"  type: SPLIT \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'tanh' \"\n      \"  type: TANH \"\n      \"} \";\n  this->RunV0UpgradeTest(input_proto, expected_output_proto);\n}\n\nTEST_F(NetUpgradeTest, TestImageNet) {\n  const string& v0_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'data' \"\n      \"    type: 'data' \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    meanfile: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"    batchsize: 256 \"\n      \"    cropsize: 227 \"\n      \"    mirror: true \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv1' \"\n      \"    type: 'conv' \"\n      \"    num_output: 96 \"\n      \"    kernelsize: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu1' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool1' \"\n      \"    type: 'pool' \"\n      \"    pool: MAX \"\n      \"    kernelsize: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'norm1' \"\n      \"    type: 'lrn' \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool1' \"\n      \"  top: 'norm1' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad2' \"\n      \"    type: 'padding' \"\n      \"    pad: 2 \"\n      \"  } \"\n      \"  bottom: 'norm1' \"\n      \"  top: 'pad2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv2' \"\n      \"    type: 'conv' \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernelsize: 5 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad2' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu2' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool2' \"\n      \"    type: 'pool' \"\n      \"    pool: MAX \"\n      \"    kernelsize: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'pool2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'norm2' \"\n      \"    type: 'lrn' \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool2' \"\n      \"  top: 'norm2' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad3' \"\n      \"    type: 'padding' \"\n      \"    pad: 1 \"\n      \"  } \"\n      \"  bottom: 'norm2' \"\n      \"  top: 'pad3' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv3' \"\n      \"    type: 'conv' \"\n      \"    num_output: 384 \"\n      \"    kernelsize: 3 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad3' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu3' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad4' \"\n      \"    type: 'padding' \"\n      \"    pad: 1 \"\n      \"  } \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'pad4' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv4' \"\n      \"    type: 'conv' \"\n      \"    num_output: 384 \"\n      \"    group: 2 \"\n      \"    kernelsize: 3 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad4' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu4' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pad5' \"\n      \"    type: 'padding' \"\n      \"    pad: 1 \"\n      \"  } \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'pad5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'conv5' \"\n      \"    type: 'conv' \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernelsize: 3 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pad5' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu5' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'pool5' \"\n      \"    type: 'pool' \"\n      \"    kernelsize: 3 \"\n      \"    pool: MAX \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'pool5' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc6' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'pool5' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu6' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'drop6' \"\n      \"    type: 'dropout' \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc7' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'relu7' \"\n      \"    type: 'relu' \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'drop7' \"\n      \"    type: 'dropout' \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'fc8' \"\n      \"    type: 'innerproduct' \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"    blobs_lr: 1. \"\n      \"    blobs_lr: 2. \"\n      \"    weight_decay: 1. \"\n      \"    weight_decay: 0. \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  layer { \"\n      \"    name: 'loss' \"\n      \"    type: 'softmax_loss' \"\n      \"  } \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  const string& expected_v1_proto =\n      \"name: 'CaffeNet' \"\n      \"layers { \"\n      \"  name: 'data' \"\n      \"  type: DATA \"\n      \"  data_param { \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    batch_size: 256 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    crop_size: 227 \"\n      \"    mirror: true \"\n      \"    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'conv1' \"\n      \"  type: CONVOLUTION \"\n      \"  convolution_param { \"\n      \"    num_output: 96 \"\n      \"    kernel_size: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'relu1' \"\n      \"  type: RELU \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'pool1' \"\n      \"  type: POOLING \"\n      \"  pooling_param { \"\n      \"    pool: MAX \"\n      \"    kernel_size: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'norm1' \"\n      \"  type: LRN \"\n      \"  lrn_param { \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool1' \"\n      \"  top: 'norm1' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'conv2' \"\n      \"  type: CONVOLUTION \"\n      \"  convolution_param { \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernel_size: 5 \"\n      \"    pad: 2 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'norm1' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'relu2' \"\n      \"  type: RELU \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'pool2' \"\n      \"  type: POOLING \"\n      \"  pooling_param { \"\n      \"    pool: MAX \"\n      \"    kernel_size: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'pool2' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'norm2' \"\n      \"  type: LRN \"\n      \"  lrn_param { \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool2' \"\n      \"  top: 'norm2' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'conv3' \"\n      \"  type: CONVOLUTION \"\n      \"  convolution_param { \"\n      \"    num_output: 384 \"\n      \"    kernel_size: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'norm2' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'relu3' \"\n      \"  type: RELU \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'conv4' \"\n      \"  type: CONVOLUTION \"\n      \"  convolution_param { \"\n      \"    num_output: 384 \"\n      \"    group: 2 \"\n      \"    kernel_size: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'relu4' \"\n      \"  type: RELU \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'conv5' \"\n      \"  type: CONVOLUTION \"\n      \"  convolution_param { \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernel_size: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'relu5' \"\n      \"  type: RELU \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'pool5' \"\n      \"  type: POOLING \"\n      \"  pooling_param { \"\n      \"    kernel_size: 3 \"\n      \"    pool: MAX \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'pool5' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'fc6' \"\n      \"  type: INNER_PRODUCT \"\n      \"  inner_product_param { \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'pool5' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'relu6' \"\n      \"  type: RELU \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'drop6' \"\n      \"  type: DROPOUT \"\n      \"  dropout_param { \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'fc7' \"\n      \"  type: INNER_PRODUCT \"\n      \"  inner_product_param { \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'relu7' \"\n      \"  type: RELU \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'drop7' \"\n      \"  type: DROPOUT \"\n      \"  dropout_param { \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'fc8' \"\n      \"  type: INNER_PRODUCT \"\n      \"  inner_product_param { \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"  } \"\n      \"  blobs_lr: 1. \"\n      \"  blobs_lr: 2. \"\n      \"  weight_decay: 1. \"\n      \"  weight_decay: 0. \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layers { \"\n      \"  name: 'loss' \"\n      \"  type: SOFTMAX_LOSS \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunV0UpgradeTest(v0_proto, expected_v1_proto);\n\n  const string& expected_v2_proto =\n      \"name: 'CaffeNet' \"\n      \"layer { \"\n      \"  name: 'data' \"\n      \"  type: 'Data' \"\n      \"  data_param { \"\n      \"    source: '/home/jiayq/Data/ILSVRC12/train-leveldb' \"\n      \"    batch_size: 256 \"\n      \"  } \"\n      \"  transform_param { \"\n      \"    crop_size: 227 \"\n      \"    mirror: true \"\n      \"    mean_file: '/home/jiayq/Data/ILSVRC12/image_mean.binaryproto' \"\n      \"  } \"\n      \"  top: 'data' \"\n      \"  top: 'label' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv1' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 96 \"\n      \"    kernel_size: 11 \"\n      \"    stride: 4 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'data' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu1' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'conv1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'pool1' \"\n      \"  type: 'Pooling' \"\n      \"  pooling_param { \"\n      \"    pool: MAX \"\n      \"    kernel_size: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv1' \"\n      \"  top: 'pool1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'norm1' \"\n      \"  type: 'LRN' \"\n      \"  lrn_param { \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool1' \"\n      \"  top: 'norm1' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv2' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernel_size: 5 \"\n      \"    pad: 2 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'norm1' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu2' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'conv2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'pool2' \"\n      \"  type: 'Pooling' \"\n      \"  pooling_param { \"\n      \"    pool: MAX \"\n      \"    kernel_size: 3 \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv2' \"\n      \"  top: 'pool2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'norm2' \"\n      \"  type: 'LRN' \"\n      \"  lrn_param { \"\n      \"    local_size: 5 \"\n      \"    alpha: 0.0001 \"\n      \"    beta: 0.75 \"\n      \"  } \"\n      \"  bottom: 'pool2' \"\n      \"  top: 'norm2' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv3' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 384 \"\n      \"    kernel_size: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'norm2' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu3' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv3' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv4' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 384 \"\n      \"    group: 2 \"\n      \"    kernel_size: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'conv3' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu4' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv4' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'conv5' \"\n      \"  type: 'Convolution' \"\n      \"  convolution_param { \"\n      \"    num_output: 256 \"\n      \"    group: 2 \"\n      \"    kernel_size: 3 \"\n      \"    pad: 1 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'conv4' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu5' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'conv5' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'pool5' \"\n      \"  type: 'Pooling' \"\n      \"  pooling_param { \"\n      \"    kernel_size: 3 \"\n      \"    pool: MAX \"\n      \"    stride: 2 \"\n      \"  } \"\n      \"  bottom: 'conv5' \"\n      \"  top: 'pool5' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'fc6' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'pool5' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu6' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'drop6' \"\n      \"  type: 'Dropout' \"\n      \"  dropout_param { \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc6' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'fc7' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 4096 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.005 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 1. \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'fc6' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'relu7' \"\n      \"  type: 'ReLU' \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'drop7' \"\n      \"  type: 'Dropout' \"\n      \"  dropout_param { \"\n      \"    dropout_ratio: 0.5 \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc7' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'fc8' \"\n      \"  type: 'InnerProduct' \"\n      \"  inner_product_param { \"\n      \"    num_output: 1000 \"\n      \"    weight_filler { \"\n      \"      type: 'gaussian' \"\n      \"      std: 0.01 \"\n      \"    } \"\n      \"    bias_filler { \"\n      \"      type: 'constant' \"\n      \"      value: 0 \"\n      \"    } \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 1 \"\n      \"    decay_mult: 1 \"\n      \"  } \"\n      \"  param { \"\n      \"    lr_mult: 2 \"\n      \"    decay_mult: 0 \"\n      \"  } \"\n      \"  bottom: 'fc7' \"\n      \"  top: 'fc8' \"\n      \"} \"\n      \"layer { \"\n      \"  name: 'loss' \"\n      \"  type: 'SoftmaxWithLoss' \"\n      \"  bottom: 'fc8' \"\n      \"  bottom: 'label' \"\n      \"} \";\n  this->RunV1UpgradeTest(expected_v1_proto, expected_v2_proto);\n}  // NOLINT(readability/fn_size)\n\nTEST_F(NetUpgradeTest, TestUpgradeV1LayerType) {\n  LayerParameter layer_param;\n  shared_ptr<Layer<float> > layer;\n  for (int i = 0; i < V1LayerParameter_LayerType_LayerType_ARRAYSIZE; ++i) {\n    ASSERT_TRUE(V1LayerParameter_LayerType_IsValid(i));\n    V1LayerParameter_LayerType v1_type = V1LayerParameter_LayerType(i);\n    string v2_layer_type(UpgradeV1LayerType(v1_type));\n    if (v2_layer_type == \"\") {\n      EXPECT_EQ(V1LayerParameter_LayerType_NONE, v1_type);\n      continue;  // Empty string isn't actually a valid layer type.\n    }\n    layer_param.set_type(v2_layer_type);\n    // Data layers expect a DB\n    if (v2_layer_type == \"Data\") {\n      string tmp;\n      MakeTempDir(&tmp);\n      boost::scoped_ptr<db::DB> db(db::GetDB(DataParameter_DB_LEVELDB));\n      db->Open(tmp, db::NEW);\n      db->Close();\n      layer_param.mutable_data_param()->set_source(tmp);\n    }\n    layer = LayerRegistry<float>::CreateLayer(layer_param);\n    EXPECT_EQ(v2_layer_type, layer->type());\n  }\n}\n\n}  // NOLINT(readability/fn_size)  // namespace caffe\n"
  },
  {
    "path": "src/caffe/test/test_util_blas.cpp",
    "content": "#ifndef CPU_ONLY  // CPU-GPU test\n\n#include <cstring>\n\n#include \"gtest/gtest.h\"\n\n#include \"caffe/blob.hpp\"\n#include \"caffe/util/device_alternate.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\n#include \"caffe/test/test_caffe_main.hpp\"\n\nnamespace caffe {\n\nextern cudaDeviceProp CAFFE_TEST_CUDA_PROP;\n\ntemplate <typename TypeParam>\nclass GemmTest : public ::testing::Test {};\n\nTYPED_TEST_CASE(GemmTest, TestDtypes);\n\nTYPED_TEST(GemmTest, TestGemmCPUGPU) {\n  Blob<TypeParam> A(1, 1, 2, 3);\n  Blob<TypeParam> B(1, 1, 3, 4);\n  Blob<TypeParam> C(1, 1, 2, 4);\n  TypeParam data[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};\n  TypeParam A_reshape_data[6] = {1, 4, 2, 5, 3, 6};\n  TypeParam B_reshape_data[12] = {1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12};\n  TypeParam result[8] = {38, 44, 50, 56, 83, 98, 113, 128};\n  caffe_copy(6, data, A.mutable_cpu_data());\n  caffe_copy(12, data, B.mutable_cpu_data());\n\n  if (sizeof(TypeParam) == 4 || CAFFE_TEST_CUDA_PROP.major >= 2) {\n    // [1, 2, 3; 4 5 6] * [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12];\n    caffe_cpu_gemm<TypeParam>(CblasNoTrans, CblasNoTrans, 2, 4, 3, 1.,\n        A.cpu_data(), B.cpu_data(), 0., C.mutable_cpu_data());\n    for (int i = 0; i < 8; ++i) {\n      EXPECT_EQ(C.cpu_data()[i], result[i]);\n    }\n    caffe_gpu_gemm<TypeParam>(CblasNoTrans, CblasNoTrans, 2, 4, 3, 1.,\n        A.gpu_data(), B.gpu_data(), 0., C.mutable_gpu_data());\n    for (int i = 0; i < 8; ++i) {\n      EXPECT_EQ(C.cpu_data()[i], result[i]);\n    }\n\n    // Test when we have a transposed A\n    A.Reshape(1, 1, 3, 2);\n    caffe_copy(6, A_reshape_data, A.mutable_cpu_data());\n    caffe_cpu_gemm<TypeParam>(CblasTrans, CblasNoTrans, 2, 4, 3, 1.,\n        A.cpu_data(), B.cpu_data(), 0., C.mutable_cpu_data());\n    for (int i = 0; i < 8; ++i) {\n      EXPECT_EQ(C.cpu_data()[i], result[i]);\n    }\n    caffe_gpu_gemm<TypeParam>(CblasTrans, CblasNoTrans, 2, 4, 3, 1.,\n        A.gpu_data(), B.gpu_data(), 0., C.mutable_gpu_data());\n    for (int i = 0; i < 8; ++i) {\n      EXPECT_EQ(C.cpu_data()[i], result[i]);\n    }\n\n    // Test when we have a transposed A and a transposed B too\n    B.Reshape(1, 1, 4, 3);\n    caffe_copy(12, B_reshape_data, B.mutable_cpu_data());\n    caffe_cpu_gemm<TypeParam>(CblasTrans, CblasTrans, 2, 4, 3, 1.,\n        A.cpu_data(), B.cpu_data(), 0., C.mutable_cpu_data());\n    for (int i = 0; i < 8; ++i) {\n      EXPECT_EQ(C.cpu_data()[i], result[i]);\n    }\n    caffe_gpu_gemm<TypeParam>(CblasTrans, CblasTrans, 2, 4, 3, 1.,\n        A.gpu_data(), B.gpu_data(), 0., C.mutable_gpu_data());\n    for (int i = 0; i < 8; ++i) {\n      EXPECT_EQ(C.cpu_data()[i], result[i]);\n    }\n\n    // Test when we have a transposed B\n    A.Reshape(1, 1, 2, 3);\n    caffe_copy(6, data, A.mutable_cpu_data());\n    caffe_cpu_gemm<TypeParam>(CblasNoTrans, CblasTrans, 2, 4, 3, 1.,\n        A.cpu_data(), B.cpu_data(), 0., C.mutable_cpu_data());\n    for (int i = 0; i < 8; ++i) {\n      EXPECT_EQ(C.cpu_data()[i], result[i]);\n    }\n    caffe_gpu_gemm<TypeParam>(CblasNoTrans, CblasTrans, 2, 4, 3, 1.,\n        A.gpu_data(), B.gpu_data(), 0., C.mutable_gpu_data());\n    for (int i = 0; i < 8; ++i) {\n      EXPECT_EQ(C.cpu_data()[i], result[i]);\n    }\n  } else {\n    LOG(ERROR) << \"Skipping test due to old architecture.\";\n  }\n}\n\n\nTYPED_TEST(GemmTest, TestGemvCPUGPU) {\n  Blob<TypeParam> A(1, 1, 2, 3);\n  Blob<TypeParam> x(1, 1, 1, 3);\n  Blob<TypeParam> y(1, 1, 1, 2);\n  TypeParam data[6] = {1, 2, 3, 4, 5, 6};\n  TypeParam result_2[2] = {14, 32};\n  TypeParam result_3[3] = {9, 12, 15};\n  caffe_copy(6, data, A.mutable_cpu_data());\n  caffe_copy(3, data, x.mutable_cpu_data());\n\n  if (sizeof(TypeParam) == 4 || CAFFE_TEST_CUDA_PROP.major >= 2) {\n    caffe_cpu_gemv<TypeParam>(CblasNoTrans, 2, 3, 1., A.cpu_data(),\n        x.cpu_data(), 0., y.mutable_cpu_data());\n    for (int i = 0; i < 2; ++i) {\n      EXPECT_EQ(y.cpu_data()[i], result_2[i]);\n    }\n    caffe_gpu_gemv<TypeParam>(CblasNoTrans, 2, 3, 1., A.gpu_data(),\n        x.gpu_data(), 0., y.mutable_gpu_data());\n    for (int i = 0; i < 2; ++i) {\n      EXPECT_EQ(y.cpu_data()[i], result_2[i]);\n    }\n\n    // Test transpose case\n    caffe_copy(2, data, y.mutable_cpu_data());\n    caffe_cpu_gemv<TypeParam>(CblasTrans, 2, 3, 1., A.cpu_data(),\n        y.cpu_data(), 0., x.mutable_cpu_data());\n    for (int i = 0; i < 3; ++i) {\n      EXPECT_EQ(x.cpu_data()[i], result_3[i]);\n    }\n    caffe_gpu_gemv<TypeParam>(CblasTrans, 2, 3, 1., A.gpu_data(),\n        y.gpu_data(), 0., x.mutable_gpu_data());\n    for (int i = 0; i < 3; ++i) {\n      EXPECT_EQ(x.cpu_data()[i], result_3[i]);\n    }\n  } else {\n    LOG(ERROR) << \"Skipping test due to old architecture.\";\n  }\n}\n\n}  // namespace caffe\n\n#endif  // CPU_ONLY\n"
  },
  {
    "path": "src/caffe/util/benchmark.cpp",
    "content": "#include <boost/date_time/posix_time/posix_time.hpp>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/benchmark.hpp\"\n\nnamespace caffe {\n\nTimer::Timer()\n    : initted_(false),\n      running_(false),\n      has_run_at_least_once_(false) {\n  Init();\n}\n\nTimer::~Timer() {\n  if (Caffe::mode() == Caffe::GPU) {\n#ifndef CPU_ONLY\n    CUDA_CHECK(cudaEventDestroy(start_gpu_));\n    CUDA_CHECK(cudaEventDestroy(stop_gpu_));\n#else\n    NO_GPU;\n#endif\n  }\n}\n\nvoid Timer::Start() {\n  if (!running()) {\n    if (Caffe::mode() == Caffe::GPU) {\n#ifndef CPU_ONLY\n      CUDA_CHECK(cudaEventRecord(start_gpu_, 0));\n#else\n      NO_GPU;\n#endif\n    } else {\n      start_cpu_ = boost::posix_time::microsec_clock::local_time();\n    }\n    running_ = true;\n    has_run_at_least_once_ = true;\n  }\n}\n\nvoid Timer::Stop() {\n  if (running()) {\n    if (Caffe::mode() == Caffe::GPU) {\n#ifndef CPU_ONLY\n      CUDA_CHECK(cudaEventRecord(stop_gpu_, 0));\n      CUDA_CHECK(cudaEventSynchronize(stop_gpu_));\n#else\n      NO_GPU;\n#endif\n    } else {\n      stop_cpu_ = boost::posix_time::microsec_clock::local_time();\n    }\n    running_ = false;\n  }\n}\n\n\nfloat Timer::MicroSeconds() {\n  if (!has_run_at_least_once()) {\n    LOG(WARNING) << \"Timer has never been run before reading time.\";\n    return 0;\n  }\n  if (running()) {\n    Stop();\n  }\n  if (Caffe::mode() == Caffe::GPU) {\n#ifndef CPU_ONLY\n    CUDA_CHECK(cudaEventElapsedTime(&elapsed_milliseconds_, start_gpu_,\n                                    stop_gpu_));\n    // Cuda only measure milliseconds\n    elapsed_microseconds_ = elapsed_milliseconds_ * 1000;\n#else\n      NO_GPU;\n#endif\n  } else {\n    elapsed_microseconds_ = (stop_cpu_ - start_cpu_).total_microseconds();\n  }\n  return elapsed_microseconds_;\n}\n\nfloat Timer::MilliSeconds() {\n  if (!has_run_at_least_once()) {\n    LOG(WARNING) << \"Timer has never been run before reading time.\";\n    return 0;\n  }\n  if (running()) {\n    Stop();\n  }\n  if (Caffe::mode() == Caffe::GPU) {\n#ifndef CPU_ONLY\n    CUDA_CHECK(cudaEventElapsedTime(&elapsed_milliseconds_, start_gpu_,\n                                    stop_gpu_));\n#else\n      NO_GPU;\n#endif\n  } else {\n    elapsed_milliseconds_ = (stop_cpu_ - start_cpu_).total_milliseconds();\n  }\n  return elapsed_milliseconds_;\n}\n\nfloat Timer::Seconds() {\n  return MilliSeconds() / 1000.;\n}\n\nvoid Timer::Init() {\n  if (!initted()) {\n    if (Caffe::mode() == Caffe::GPU) {\n#ifndef CPU_ONLY\n      CUDA_CHECK(cudaEventCreate(&start_gpu_));\n      CUDA_CHECK(cudaEventCreate(&stop_gpu_));\n#else\n      NO_GPU;\n#endif\n    }\n    initted_ = true;\n  }\n}\n\nCPUTimer::CPUTimer() {\n  this->initted_ = true;\n  this->running_ = false;\n  this->has_run_at_least_once_ = false;\n}\n\nvoid CPUTimer::Start() {\n  if (!running()) {\n    this->start_cpu_ = boost::posix_time::microsec_clock::local_time();\n    this->running_ = true;\n    this->has_run_at_least_once_ = true;\n  }\n}\n\nvoid CPUTimer::Stop() {\n  if (running()) {\n    this->stop_cpu_ = boost::posix_time::microsec_clock::local_time();\n    this->running_ = false;\n  }\n}\n\nfloat CPUTimer::MilliSeconds() {\n  if (!has_run_at_least_once()) {\n    LOG(WARNING) << \"Timer has never been run before reading time.\";\n    return 0;\n  }\n  if (running()) {\n    Stop();\n  }\n  this->elapsed_milliseconds_ = (this->stop_cpu_ -\n                                this->start_cpu_).total_milliseconds();\n  return this->elapsed_milliseconds_;\n}\n\nfloat CPUTimer::MicroSeconds() {\n  if (!has_run_at_least_once()) {\n    LOG(WARNING) << \"Timer has never been run before reading time.\";\n    return 0;\n  }\n  if (running()) {\n    Stop();\n  }\n  this->elapsed_microseconds_ = (this->stop_cpu_ -\n                                this->start_cpu_).total_microseconds();\n  return this->elapsed_microseconds_;\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/blocking_queue.cpp",
    "content": "#include <boost/thread.hpp>\n#include <string>\n\n#include \"caffe/data_layers.hpp\"\n#include \"caffe/data_reader.hpp\"\n#include \"caffe/parallel.hpp\"\n#include \"caffe/util/blocking_queue.hpp\"\n\nnamespace caffe {\n\ntemplate<typename T>\nclass BlockingQueue<T>::sync {\n public:\n  mutable boost::mutex mutex_;\n  boost::condition_variable condition_;\n};\n\ntemplate<typename T>\nBlockingQueue<T>::BlockingQueue()\n    : sync_(new sync()) {\n}\n\ntemplate<typename T>\nvoid BlockingQueue<T>::push(const T& t) {\n  boost::mutex::scoped_lock lock(sync_->mutex_);\n  queue_.push(t);\n  lock.unlock();\n  sync_->condition_.notify_one();\n}\n\ntemplate<typename T>\nbool BlockingQueue<T>::try_pop(T* t) {\n  boost::mutex::scoped_lock lock(sync_->mutex_);\n\n  if (queue_.empty()) {\n    return false;\n  }\n\n  *t = queue_.front();\n  queue_.pop();\n  return true;\n}\n\ntemplate<typename T>\nT BlockingQueue<T>::pop(const string& log_on_wait) {\n  boost::mutex::scoped_lock lock(sync_->mutex_);\n\n  while (queue_.empty()) {\n    if (!log_on_wait.empty()) {\n      LOG_EVERY_N(INFO, 1000)<< log_on_wait;\n    }\n    sync_->condition_.wait(lock);\n  }\n\n  T t = queue_.front();\n  queue_.pop();\n  return t;\n}\n\ntemplate<typename T>\nbool BlockingQueue<T>::try_peek(T* t) {\n  boost::mutex::scoped_lock lock(sync_->mutex_);\n\n  if (queue_.empty()) {\n    return false;\n  }\n\n  *t = queue_.front();\n  return true;\n}\n\ntemplate<typename T>\nT BlockingQueue<T>::peek() {\n  boost::mutex::scoped_lock lock(sync_->mutex_);\n\n  while (queue_.empty()) {\n    sync_->condition_.wait(lock);\n  }\n\n  return queue_.front();\n}\n\ntemplate<typename T>\nsize_t BlockingQueue<T>::size() const {\n  boost::mutex::scoped_lock lock(sync_->mutex_);\n  return queue_.size();\n}\n\ntemplate class BlockingQueue<Batch<float>*>;\ntemplate class BlockingQueue<Batch<double>*>;\ntemplate class BlockingQueue<Datum*>;\ntemplate class BlockingQueue<shared_ptr<DataReader::QueuePair> >;\ntemplate class BlockingQueue<P2PSync<float>*>;\ntemplate class BlockingQueue<P2PSync<double>*>;\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/cudnn.cpp",
    "content": "#ifdef USE_CUDNN\n#include \"caffe/util/cudnn.hpp\"\n\nnamespace caffe {\nnamespace cudnn {\n\nfloat dataType<float>::oneval = 1.0;\nfloat dataType<float>::zeroval = 0.0;\nconst void* dataType<float>::one =\n    static_cast<void *>(&dataType<float>::oneval);\nconst void* dataType<float>::zero =\n    static_cast<void *>(&dataType<float>::zeroval);\n\ndouble dataType<double>::oneval = 1.0;\ndouble dataType<double>::zeroval = 0.0;\nconst void* dataType<double>::one =\n    static_cast<void *>(&dataType<double>::oneval);\nconst void* dataType<double>::zero =\n    static_cast<void *>(&dataType<double>::zeroval);\n\n}  // namespace cudnn\n}  // namespace caffe\n#endif\n"
  },
  {
    "path": "src/caffe/util/db.cpp",
    "content": "#include \"caffe/util/db.hpp\"\n#include \"caffe/util/db_leveldb.hpp\"\n#include \"caffe/util/db_lmdb.hpp\"\n\n#include <string>\n\nnamespace caffe { namespace db {\n\nDB* GetDB(DataParameter::DB backend) {\n  switch (backend) {\n  case DataParameter_DB_LEVELDB:\n    return new LevelDB();\n  case DataParameter_DB_LMDB:\n    return new LMDB();\n  default:\n    LOG(FATAL) << \"Unknown database backend\";\n  }\n}\n\nDB* GetDB(const string& backend) {\n  if (backend == \"leveldb\") {\n    return new LevelDB();\n  } else if (backend == \"lmdb\") {\n    return new LMDB();\n  } else {\n    LOG(FATAL) << \"Unknown database backend\";\n  }\n}\n\n}  // namespace db\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/db_leveldb.cpp",
    "content": "#include \"caffe/util/db_leveldb.hpp\"\n\n#include <string>\n\nnamespace caffe { namespace db {\n\nvoid LevelDB::Open(const string& source, Mode mode) {\n  leveldb::Options options;\n  options.block_size = 65536;\n  options.write_buffer_size = 268435456;\n  options.max_open_files = 100;\n  options.error_if_exists = mode == NEW;\n  options.create_if_missing = mode != READ;\n  leveldb::Status status = leveldb::DB::Open(options, source, &db_);\n  CHECK(status.ok()) << \"Failed to open leveldb \" << source\n                     << std::endl << status.ToString();\n  LOG(INFO) << \"Opened leveldb \" << source;\n}\n\n}  // namespace db\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/db_lmdb.cpp",
    "content": "#include \"caffe/util/db_lmdb.hpp\"\n\n#include <sys/stat.h>\n\n#include <string>\n\nnamespace caffe { namespace db {\n\nconst size_t LMDB_MAP_SIZE = 1099511627776;  // 1 TB\n\nvoid LMDB::Open(const string& source, Mode mode) {\n  MDB_CHECK(mdb_env_create(&mdb_env_));\n  MDB_CHECK(mdb_env_set_mapsize(mdb_env_, LMDB_MAP_SIZE));\n  if (mode == NEW) {\n    CHECK_EQ(mkdir(source.c_str(), 0744), 0) << \"mkdir \" << source << \"failed\";\n  }\n  int flags = 0;\n  if (mode == READ) {\n    flags = MDB_RDONLY | MDB_NOTLS;\n  }\n  MDB_CHECK(mdb_env_open(mdb_env_, source.c_str(), flags, 0664));\n  LOG(INFO) << \"Opened lmdb \" << source;\n}\n\nLMDBCursor* LMDB::NewCursor() {\n  MDB_txn* mdb_txn;\n  MDB_cursor* mdb_cursor;\n  MDB_CHECK(mdb_txn_begin(mdb_env_, NULL, MDB_RDONLY, &mdb_txn));\n  MDB_CHECK(mdb_dbi_open(mdb_txn, NULL, 0, &mdb_dbi_));\n  MDB_CHECK(mdb_cursor_open(mdb_txn, mdb_dbi_, &mdb_cursor));\n  return new LMDBCursor(mdb_txn, mdb_cursor);\n}\n\nLMDBTransaction* LMDB::NewTransaction() {\n  MDB_txn* mdb_txn;\n  MDB_CHECK(mdb_txn_begin(mdb_env_, NULL, 0, &mdb_txn));\n  MDB_CHECK(mdb_dbi_open(mdb_txn, NULL, 0, &mdb_dbi_));\n  return new LMDBTransaction(&mdb_dbi_, mdb_txn);\n}\n\nvoid LMDBTransaction::Put(const string& key, const string& value) {\n  MDB_val mdb_key, mdb_value;\n  mdb_key.mv_data = const_cast<char*>(key.data());\n  mdb_key.mv_size = key.size();\n  mdb_value.mv_data = const_cast<char*>(value.data());\n  mdb_value.mv_size = value.size();\n  MDB_CHECK(mdb_put(mdb_txn_, *mdb_dbi_, &mdb_key, &mdb_value, 0));\n}\n\n}  // namespace db\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/hdf5.cpp",
    "content": "#include \"caffe/util/hdf5.hpp\"\n\n#include <string>\n#include <vector>\n\nnamespace caffe {\n\n// Verifies format of data stored in HDF5 file and reshapes blob accordingly.\ntemplate <typename Dtype>\nvoid hdf5_load_nd_dataset_helper(\n    hid_t file_id, const char* dataset_name_, int min_dim, int max_dim,\n    Blob<Dtype>* blob) {\n  // Verify that the dataset exists.\n  CHECK(H5LTfind_dataset(file_id, dataset_name_))\n      << \"Failed to find HDF5 dataset \" << dataset_name_;\n  // Verify that the number of dimensions is in the accepted range.\n  herr_t status;\n  int ndims;\n  status = H5LTget_dataset_ndims(file_id, dataset_name_, &ndims);\n  CHECK_GE(status, 0) << \"Failed to get dataset ndims for \" << dataset_name_;\n  CHECK_GE(ndims, min_dim);\n  CHECK_LE(ndims, max_dim);\n\n  // Verify that the data format is what we expect: float or double.\n  std::vector<hsize_t> dims(ndims);\n  H5T_class_t class_;\n  status = H5LTget_dataset_info(\n      file_id, dataset_name_, dims.data(), &class_, NULL);\n  CHECK_GE(status, 0) << \"Failed to get dataset info for \" << dataset_name_;\n  CHECK_EQ(class_, H5T_FLOAT) << \"Expected float or double data\";\n\n  vector<int> blob_dims(dims.size());\n  for (int i = 0; i < dims.size(); ++i) {\n    blob_dims[i] = dims[i];\n  }\n  blob->Reshape(blob_dims);\n}\n\ntemplate <>\nvoid hdf5_load_nd_dataset<float>(hid_t file_id, const char* dataset_name_,\n        int min_dim, int max_dim, Blob<float>* blob) {\n  hdf5_load_nd_dataset_helper(file_id, dataset_name_, min_dim, max_dim, blob);\n  herr_t status = H5LTread_dataset_float(\n    file_id, dataset_name_, blob->mutable_cpu_data());\n  CHECK_GE(status, 0) << \"Failed to read float dataset \" << dataset_name_;\n}\n\ntemplate <>\nvoid hdf5_load_nd_dataset<double>(hid_t file_id, const char* dataset_name_,\n        int min_dim, int max_dim, Blob<double>* blob) {\n  hdf5_load_nd_dataset_helper(file_id, dataset_name_, min_dim, max_dim, blob);\n  herr_t status = H5LTread_dataset_double(\n    file_id, dataset_name_, blob->mutable_cpu_data());\n  CHECK_GE(status, 0) << \"Failed to read double dataset \" << dataset_name_;\n}\n\ntemplate <>\nvoid hdf5_save_nd_dataset<float>(\n    const hid_t file_id, const string& dataset_name, const Blob<float>& blob,\n    bool write_diff) {\n  int num_axes = blob.num_axes();\n  hsize_t *dims = new hsize_t[num_axes];\n  for (int i = 0; i < num_axes; ++i) {\n    dims[i] = blob.shape(i);\n  }\n  const float* data;\n  if (write_diff) {\n    data = blob.cpu_diff();\n  } else {\n    data = blob.cpu_data();\n  }\n  herr_t status = H5LTmake_dataset_float(\n      file_id, dataset_name.c_str(), num_axes, dims, data);\n  CHECK_GE(status, 0) << \"Failed to make float dataset \" << dataset_name;\n  delete[] dims;\n}\n\ntemplate <>\nvoid hdf5_save_nd_dataset<double>(\n    hid_t file_id, const string& dataset_name, const Blob<double>& blob,\n    bool write_diff) {\n  int num_axes = blob.num_axes();\n  hsize_t *dims = new hsize_t[num_axes];\n  for (int i = 0; i < num_axes; ++i) {\n    dims[i] = blob.shape(i);\n  }\n  const double* data;\n  if (write_diff) {\n    data = blob.cpu_diff();\n  } else {\n    data = blob.cpu_data();\n  }\n  herr_t status = H5LTmake_dataset_double(\n      file_id, dataset_name.c_str(), num_axes, dims, data);\n  CHECK_GE(status, 0) << \"Failed to make double dataset \" << dataset_name;\n  delete[] dims;\n}\n\nstring hdf5_load_string(hid_t loc_id, const string& dataset_name) {\n  // Get size of dataset\n  size_t size;\n  H5T_class_t class_;\n  herr_t status = \\\n    H5LTget_dataset_info(loc_id, dataset_name.c_str(), NULL, &class_, &size);\n  CHECK_GE(status, 0) << \"Failed to get dataset info for \" << dataset_name;\n  char *buf = new char[size];\n  status = H5LTread_dataset_string(loc_id, dataset_name.c_str(), buf);\n  CHECK_GE(status, 0)\n    << \"Failed to load int dataset with name \" << dataset_name;\n  string val(buf);\n  delete[] buf;\n  return val;\n}\n\nvoid hdf5_save_string(hid_t loc_id, const string& dataset_name,\n                      const string& s) {\n  herr_t status = \\\n    H5LTmake_dataset_string(loc_id, dataset_name.c_str(), s.c_str());\n  CHECK_GE(status, 0)\n    << \"Failed to save string dataset with name \" << dataset_name;\n}\n\nint hdf5_load_int(hid_t loc_id, const string& dataset_name) {\n  int val;\n  herr_t status = H5LTread_dataset_int(loc_id, dataset_name.c_str(), &val);\n  CHECK_GE(status, 0)\n    << \"Failed to load int dataset with name \" << dataset_name;\n  return val;\n}\n\nvoid hdf5_save_int(hid_t loc_id, const string& dataset_name, int i) {\n  hsize_t one = 1;\n  herr_t status = \\\n    H5LTmake_dataset_int(loc_id, dataset_name.c_str(), 1, &one, &i);\n  CHECK_GE(status, 0)\n    << \"Failed to save int dataset with name \" << dataset_name;\n}\n\nint hdf5_get_num_links(hid_t loc_id) {\n  H5G_info_t info;\n  herr_t status = H5Gget_info(loc_id, &info);\n  CHECK_GE(status, 0) << \"Error while counting HDF5 links.\";\n  return info.nlinks;\n}\n\nstring hdf5_get_name_by_idx(hid_t loc_id, int idx) {\n  ssize_t str_size = H5Lget_name_by_idx(\n      loc_id, \".\", H5_INDEX_NAME, H5_ITER_NATIVE, idx, NULL, 0, H5P_DEFAULT);\n  CHECK_GE(str_size, 0) << \"Error retrieving HDF5 dataset at index \" << idx;\n  char *c_str = new char[str_size+1];\n  ssize_t status = H5Lget_name_by_idx(\n      loc_id, \".\", H5_INDEX_NAME, H5_ITER_NATIVE, idx, c_str, str_size+1,\n      H5P_DEFAULT);\n  CHECK_GE(status, 0) << \"Error retrieving HDF5 dataset at index \" << idx;\n  string result(c_str);\n  delete[] c_str;\n  return result;\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/im2col.cpp",
    "content": "#include <cmath>\n#include <cstdlib>\n#include <cstring>\n\n#include \"caffe/util/im2col.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\nvoid im2col_cpu(const Dtype* data_im, const int channels,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w,\n    const int stride_h, const int stride_w,\n    Dtype* data_col) {\n  int height_col = (height + 2 * pad_h - kernel_h) / stride_h + 1;\n  int width_col = (width + 2 * pad_w - kernel_w) / stride_w + 1;\n  int channels_col = channels * kernel_h * kernel_w;\n  for (int c = 0; c < channels_col; ++c) {\n    int w_offset = c % kernel_w;\n    int h_offset = (c / kernel_w) % kernel_h;\n    int c_im = c / kernel_h / kernel_w;\n    for (int h = 0; h < height_col; ++h) {\n      for (int w = 0; w < width_col; ++w) {\n        int h_pad = h * stride_h - pad_h + h_offset;\n        int w_pad = w * stride_w - pad_w + w_offset;\n        if (h_pad >= 0 && h_pad < height && w_pad >= 0 && w_pad < width)\n          data_col[(c * height_col + h) * width_col + w] =\n            data_im[(c_im * height + h_pad) * width + w_pad];\n        else\n          data_col[(c * height_col + h) * width_col + w] = 0;\n      }\n    }\n  }\n}\n\n// Explicit instantiation\ntemplate void im2col_cpu<float>(const float* data_im, const int channels,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, float* data_col);\ntemplate void im2col_cpu<double>(const double* data_im, const int channels,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, double* data_col);\n\ntemplate <typename Dtype>\nvoid col2im_cpu(const Dtype* data_col, const int channels,\n    const int height, const int width, const int patch_h, const int patch_w,\n    const int pad_h, const int pad_w,\n    const int stride_h, const int stride_w,\n    Dtype* data_im) {\n  caffe_set(height * width * channels, Dtype(0), data_im);\n  int height_col = (height + 2 * pad_h - patch_h) / stride_h + 1;\n  int width_col = (width + 2 * pad_w - patch_w) / stride_w + 1;\n  int channels_col = channels * patch_h * patch_w;\n  for (int c = 0; c < channels_col; ++c) {\n    int w_offset = c % patch_w;\n    int h_offset = (c / patch_w) % patch_h;\n    int c_im = c / patch_h / patch_w;\n    for (int h = 0; h < height_col; ++h) {\n      for (int w = 0; w < width_col; ++w) {\n        int h_pad = h * stride_h - pad_h + h_offset;\n        int w_pad = w * stride_w - pad_w + w_offset;\n        if (h_pad >= 0 && h_pad < height && w_pad >= 0 && w_pad < width)\n          data_im[(c_im * height + h_pad) * width + w_pad] +=\n              data_col[(c * height_col + h) * width_col + w];\n      }\n    }\n  }\n}\n\n// Explicit instantiation\ntemplate void col2im_cpu<float>(const float* data_col, const int channels,\n    const int height, const int width, const int patch_h, const int patch_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, float* data_im);\ntemplate void col2im_cpu<double>(const double* data_col, const int channels,\n    const int height, const int width, const int patch_h, const int patch_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, double* data_im);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/im2col.cu",
    "content": "#include <algorithm>\n#include <cmath>\n#include <cstdlib>\n#include <cstring>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/im2col.hpp\"\n\nnamespace caffe {\n\ntemplate <typename Dtype>\n__global__ void im2col_gpu_kernel(const int n, const Dtype* data_im,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w,\n    const int stride_h, const int stride_w,\n    const int height_col, const int width_col,\n    Dtype* data_col) {\n  CUDA_KERNEL_LOOP(index, n) {\n    int w_out = index % width_col;\n    int h_index = index / width_col;\n    int h_out = h_index % height_col;\n    int channel_in = h_index / height_col;\n    int channel_out = channel_in * kernel_h * kernel_w;\n    int h_in = h_out * stride_h - pad_h;\n    int w_in = w_out * stride_w - pad_w;\n    Dtype* data_col_ptr = data_col;\n    data_col_ptr += (channel_out * height_col + h_out) * width_col + w_out;\n    const Dtype* data_im_ptr = data_im;\n    data_im_ptr += (channel_in * height + h_in) * width + w_in;\n    for (int i = 0; i < kernel_h; ++i) {\n      for (int j = 0; j < kernel_w; ++j) {\n        int h = h_in + i;\n        int w = w_in + j;\n        *data_col_ptr = (h >= 0 && w >= 0 && h < height && w < width) ?\n            data_im_ptr[i * width + j] : 0;\n        data_col_ptr += height_col * width_col;\n      }\n    }\n  }\n}\n\ntemplate <typename Dtype>\nvoid im2col_gpu(const Dtype* data_im, const int channels,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w,\n    const int stride_h, const int stride_w,\n    Dtype* data_col) {\n  // We are going to launch channels * height_col * width_col kernels, each\n  // kernel responsible for copying a single-channel grid.\n  int height_col = (height + 2 * pad_h - kernel_h) / stride_h + 1;\n  int width_col = (width + 2 * pad_w - kernel_w) / stride_w + 1;\n  int num_kernels = channels * height_col * width_col;\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  im2col_gpu_kernel<Dtype><<<CAFFE_GET_BLOCKS(num_kernels),\n                             CAFFE_CUDA_NUM_THREADS>>>(\n      num_kernels, data_im, height, width, kernel_h, kernel_w, pad_h,\n      pad_w, stride_h, stride_w, height_col,\n      width_col, data_col);\n  CUDA_POST_KERNEL_CHECK;\n}\n\n\n// Explicit instantiation\ntemplate void im2col_gpu<float>(const float* data_im, const int channels,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w, const int stride_h, const int stride_w,\n    float* data_col);\ntemplate void im2col_gpu<double>(const double* data_im, const int channels,\n    const int height, const int width, const int kernel_h, const int kernel_w,\n    const int pad_h, const int pad_w, const int stride_h, const int stride_w,\n    double* data_col);\n\ntemplate <typename Dtype>\n__global__ void col2im_gpu_kernel(const int n, const Dtype* data_col,\n    const int height, const int width, const int channels,\n    const int patch_h, const int patch_w,\n    const int pad_h, const int pad_w,\n    const int stride_h, const int stride_w,\n    const int height_col, const int width_col,\n    Dtype* data_im) {\n  CUDA_KERNEL_LOOP(index, n) {\n    Dtype val = 0;\n    int w = index % width + pad_w;\n    int h = (index / width) % height + pad_h;\n    int c = index / (width * height);\n    // compute the start and end of the output\n    int w_col_start = (w < patch_w) ? 0 : (w - patch_w) / stride_w + 1;\n    int w_col_end = min(w / stride_w + 1, width_col);\n    int h_col_start = (h < patch_h) ? 0 : (h - patch_h) / stride_h + 1;\n    int h_col_end = min(h / stride_h + 1, height_col);\n    /*\n    for (int h_col = h_col_start; h_col < h_col_end; ++h_col) {\n      for (int w_col = w_col_start; w_col < w_col_end; ++w_col) {\n        // the col location: [c * width * height + h_out, w_out]\n        int c_col = c * patch_h * patch_w + (h - h_col * stride_h) * ksize\n            + (w - w_col * stride_w);\n        val += data_col[(c_col * height_col + h_col) * width_col + w_col];\n      }\n    }\n    */\n    // equivalent implementation\n    int offset =\n        (c * patch_h * patch_w + h * patch_w + w) * height_col * width_col;\n    int coeff_h_col = (1 - stride_h * patch_w * height_col) * width_col;\n    int coeff_w_col = (1 - stride_w * height_col * width_col);\n    for (int h_col = h_col_start; h_col < h_col_end; ++h_col) {\n      for (int w_col = w_col_start; w_col < w_col_end; ++w_col) {\n        val += data_col[offset + h_col * coeff_h_col + w_col * coeff_w_col];\n      }\n    }\n    data_im[index] = val;\n  }\n}\n\ntemplate <typename Dtype>\nvoid col2im_gpu(const Dtype* data_col, const int channels,\n    const int height, const int width, const int patch_h, const int patch_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, Dtype* data_im) {\n  int height_col = (height + 2 * pad_h - patch_h) / stride_h + 1;\n  int width_col = (width + 2 * pad_w - patch_w) / stride_w + 1;\n  int num_kernels = channels * height * width;\n  // To avoid involving atomic operations, we will launch one kernel per\n  // bottom dimension, and then in the kernel add up the top dimensions.\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  col2im_gpu_kernel<Dtype><<<CAFFE_GET_BLOCKS(num_kernels),\n                             CAFFE_CUDA_NUM_THREADS>>>(\n      num_kernels, data_col, height, width, channels, patch_h, patch_w,\n      pad_h, pad_w, stride_h, stride_w,\n      height_col, width_col, data_im);\n  CUDA_POST_KERNEL_CHECK;\n}\n\n// Explicit instantiation\ntemplate void col2im_gpu<float>(const float* data_col, const int channels,\n    const int height, const int width, const int patch_h, const int patch_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, float* data_im);\ntemplate void col2im_gpu<double>(const double* data_col, const int channels,\n    const int height, const int width, const int patch_h, const int patch_w,\n    const int pad_h, const int pad_w, const int stride_h,\n    const int stride_w, double* data_im);\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/insert_splits.cpp",
    "content": "#include <algorithm>\n#include <map>\n#include <sstream>\n#include <string>\n#include <utility>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/insert_splits.hpp\"\n\nnamespace caffe {\n\nvoid InsertSplits(const NetParameter& param, NetParameter* param_split) {\n  // Initialize by copying from the input NetParameter.\n  param_split->CopyFrom(param);\n  param_split->clear_layer();\n  map<string, pair<int, int> > blob_name_to_last_top_idx;\n  map<pair<int, int>, pair<int, int> > bottom_idx_to_source_top_idx;\n  map<pair<int, int>, int> top_idx_to_bottom_count;\n  map<pair<int, int>, float> top_idx_to_loss_weight;\n  map<pair<int, int>, int> top_idx_to_bottom_split_idx;\n  map<int, string> layer_idx_to_layer_name;\n  layer_idx_to_layer_name[-1] = \"input\";\n  // Determine the number of times each blob is used as an input (bottom) blob.\n  for (int i = 0; i < param.input_size(); ++i) {\n    const string& blob_name = param.input(i);\n    blob_name_to_last_top_idx[blob_name] = make_pair(-1, i);\n  }\n  for (int i = 0; i < param.layer_size(); ++i) {\n    const LayerParameter& layer_param = param.layer(i);\n    layer_idx_to_layer_name[i] = layer_param.name();\n    for (int j = 0; j < layer_param.bottom_size(); ++j) {\n      const string& blob_name = layer_param.bottom(j);\n      if (blob_name_to_last_top_idx.find(blob_name) ==\n          blob_name_to_last_top_idx.end()) {\n        LOG(FATAL) << \"Unknown blob input \" << blob_name << \" to layer \" << j;\n      }\n      const pair<int, int>& bottom_idx = make_pair(i, j);\n      const pair<int, int>& top_idx = blob_name_to_last_top_idx[blob_name];\n      bottom_idx_to_source_top_idx[bottom_idx] = top_idx;\n      ++top_idx_to_bottom_count[top_idx];\n    }\n    for (int j = 0; j < layer_param.top_size(); ++j) {\n      const string& blob_name = layer_param.top(j);\n      blob_name_to_last_top_idx[blob_name] = make_pair(i, j);\n    }\n    // A use of a top blob as a loss should be handled similarly to the use of\n    // a top blob as an input (bottom) blob to another layer.\n    const int last_loss =\n        std::min(layer_param.loss_weight_size(), layer_param.top_size());\n    for (int j = 0; j < last_loss; ++j) {\n      const string& blob_name = layer_param.top(j);\n      const pair<int, int>& top_idx = blob_name_to_last_top_idx[blob_name];\n      top_idx_to_loss_weight[top_idx] = layer_param.loss_weight(j);\n      if (top_idx_to_loss_weight[top_idx]) {\n        ++top_idx_to_bottom_count[top_idx];\n      }\n    }\n  }\n  // Create split layer for any input blobs used by other layer as bottom\n  // blobs more than once.\n  for (int i = 0; i < param.input_size(); ++i) {\n    const int split_count = top_idx_to_bottom_count[make_pair(-1, i)];\n    if (split_count > 1) {\n      const string& layer_name = layer_idx_to_layer_name[-1];\n      const string& blob_name = param.input(i);\n      LayerParameter* split_layer_param = param_split->add_layer();\n      const float kZeroLossWeight = 0;\n      ConfigureSplitLayer(layer_name, blob_name, i, split_count,\n          kZeroLossWeight, split_layer_param);\n    }\n  }\n  for (int i = 0; i < param.layer_size(); ++i) {\n    LayerParameter* layer_param = param_split->add_layer();\n    layer_param->CopyFrom(param.layer(i));\n    // Replace any shared bottom blobs with split layer outputs.\n    for (int j = 0; j < layer_param->bottom_size(); ++j) {\n      const pair<int, int>& top_idx =\n          bottom_idx_to_source_top_idx[make_pair(i, j)];\n      const int split_count = top_idx_to_bottom_count[top_idx];\n      if (split_count > 1) {\n        const string& layer_name = layer_idx_to_layer_name[top_idx.first];\n        const string& blob_name = layer_param->bottom(j);\n        layer_param->set_bottom(j, SplitBlobName(layer_name,\n            blob_name, top_idx.second, top_idx_to_bottom_split_idx[top_idx]++));\n      }\n    }\n    // Create split layer for any top blobs used by other layer as bottom\n    // blobs more than once.\n    for (int j = 0; j < layer_param->top_size(); ++j) {\n      const pair<int, int>& top_idx = make_pair(i, j);\n      const int split_count = top_idx_to_bottom_count[top_idx];\n      if (split_count > 1) {\n        const string& layer_name = layer_idx_to_layer_name[i];\n        const string& blob_name = layer_param->top(j);\n        LayerParameter* split_layer_param = param_split->add_layer();\n        const float loss_weight = top_idx_to_loss_weight[top_idx];\n        ConfigureSplitLayer(layer_name, blob_name, j, split_count,\n            loss_weight, split_layer_param);\n        if (loss_weight) {\n          layer_param->clear_loss_weight();\n          top_idx_to_bottom_split_idx[top_idx]++;\n        }\n      }\n    }\n  }\n}\n\nvoid ConfigureSplitLayer(const string& layer_name, const string& blob_name,\n    const int blob_idx, const int split_count, const float loss_weight,\n    LayerParameter* split_layer_param) {\n  split_layer_param->Clear();\n  split_layer_param->add_bottom(blob_name);\n  split_layer_param->set_name(SplitLayerName(layer_name, blob_name, blob_idx));\n  split_layer_param->set_type(\"Split\");\n  for (int k = 0; k < split_count; ++k) {\n    split_layer_param->add_top(\n        SplitBlobName(layer_name, blob_name, blob_idx, k));\n    if (loss_weight) {\n      if (k == 0) {\n        split_layer_param->add_loss_weight(loss_weight);\n      } else {\n        split_layer_param->add_loss_weight(0);\n      }\n    }\n  }\n}\n\nstring SplitLayerName(const string& layer_name, const string& blob_name,\n    const int blob_idx) {\n  ostringstream split_layer_name;\n  split_layer_name << blob_name << \"_\" << layer_name << \"_\" << blob_idx\n      << \"_split\";\n  return split_layer_name.str();\n}\n\nstring SplitBlobName(const string& layer_name, const string& blob_name,\n    const int blob_idx, const int split_idx) {\n  ostringstream split_blob_name;\n  split_blob_name << blob_name << \"_\" << layer_name << \"_\" << blob_idx\n      << \"_split_\" << split_idx;\n  return split_blob_name.str();\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/io.cpp",
    "content": "#include <fcntl.h>\n#include <google/protobuf/io/coded_stream.h>\n#include <google/protobuf/io/zero_copy_stream_impl.h>\n#include <google/protobuf/text_format.h>\n#include <opencv2/core/core.hpp>\n#include <opencv2/highgui/highgui.hpp>\n#include <opencv2/highgui/highgui_c.h>\n#include <opencv2/imgproc/imgproc.hpp>\n#include <stdint.h>\n\n#include <algorithm>\n#include <fstream>  // NOLINT(readability/streams)\n#include <string>\n#include <vector>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/io.hpp\"\n\nconst int kProtoReadBytesLimit = INT_MAX;  // Max size of 2 GB minus 1 byte.\n\nnamespace caffe {\n\nusing google::protobuf::io::FileInputStream;\nusing google::protobuf::io::FileOutputStream;\nusing google::protobuf::io::ZeroCopyInputStream;\nusing google::protobuf::io::CodedInputStream;\nusing google::protobuf::io::ZeroCopyOutputStream;\nusing google::protobuf::io::CodedOutputStream;\nusing google::protobuf::Message;\n\nbool ReadProtoFromTextFile(const char* filename, Message* proto) {\n  int fd = open(filename, O_RDONLY);\n  CHECK_NE(fd, -1) << \"File not found: \" << filename;\n  FileInputStream* input = new FileInputStream(fd);\n  bool success = google::protobuf::TextFormat::Parse(input, proto);\n  delete input;\n  close(fd);\n  return success;\n}\n\nvoid WriteProtoToTextFile(const Message& proto, const char* filename) {\n  int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);\n  FileOutputStream* output = new FileOutputStream(fd);\n  CHECK(google::protobuf::TextFormat::Print(proto, output));\n  delete output;\n  close(fd);\n}\n\nbool ReadProtoFromBinaryFile(const char* filename, Message* proto) {\n  int fd = open(filename, O_RDONLY);\n  CHECK_NE(fd, -1) << \"File not found: \" << filename;\n  ZeroCopyInputStream* raw_input = new FileInputStream(fd);\n  CodedInputStream* coded_input = new CodedInputStream(raw_input);\n  coded_input->SetTotalBytesLimit(kProtoReadBytesLimit, 536870912);\n\n  bool success = proto->ParseFromCodedStream(coded_input);\n\n  delete coded_input;\n  delete raw_input;\n  close(fd);\n  return success;\n}\n\nvoid WriteProtoToBinaryFile(const Message& proto, const char* filename) {\n  fstream output(filename, ios::out | ios::trunc | ios::binary);\n  CHECK(proto.SerializeToOstream(&output));\n}\n\ncv::Mat ReadImageToCVMat(const string& filename,\n    const int height, const int width, const bool is_color) {\n  cv::Mat cv_img;\n  int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :\n    CV_LOAD_IMAGE_GRAYSCALE);\n  cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);\n  if (!cv_img_origin.data) {\n    LOG(ERROR) << \"Could not open or find file \" << filename;\n    return cv_img_origin;\n  }\n  if (height > 0 && width > 0) {\n    cv::resize(cv_img_origin, cv_img, cv::Size(width, height));\n  } else {\n    cv_img = cv_img_origin;\n  }\n  return cv_img;\n}\n\ncv::Mat ReadImageToCVMat(const string& filename,\n    const int height, const int width) {\n  return ReadImageToCVMat(filename, height, width, true);\n}\n\ncv::Mat ReadImageToCVMat(const string& filename,\n    const bool is_color) {\n  return ReadImageToCVMat(filename, 0, 0, is_color);\n}\n\ncv::Mat ReadImageToCVMat(const string& filename) {\n  return ReadImageToCVMat(filename, 0, 0, true);\n}\n// Do the file extension and encoding match?\nstatic bool matchExt(const std::string & fn,\n                     std::string en) {\n  size_t p = fn.rfind('.');\n  std::string ext = p != fn.npos ? fn.substr(p) : fn;\n  std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);\n  std::transform(en.begin(), en.end(), en.begin(), ::tolower);\n  if ( ext == en )\n    return true;\n  if ( en == \"jpg\" && ext == \"jpeg\" )\n    return true;\n  return false;\n}\nbool ReadImageToDatum(const string& filename, const int label,\n    const int height, const int width, const bool is_color,\n    const std::string & encoding, Datum* datum) {\n  cv::Mat cv_img = ReadImageToCVMat(filename, height, width, is_color);\n  if (cv_img.data) {\n    if (encoding.size()) {\n      if ( (cv_img.channels() == 3) == is_color && !height && !width &&\n          matchExt(filename, encoding) )\n        return ReadFileToDatum(filename, label, datum);\n      std::vector<uchar> buf;\n      cv::imencode(\".\"+encoding, cv_img, buf);\n      datum->set_data(std::string(reinterpret_cast<char*>(&buf[0]),\n                      buf.size()));\n      datum->set_label(label);\n      datum->set_encoded(true);\n      return true;\n    }\n    CVMatToDatum(cv_img, datum);\n    datum->set_label(label);\n    return true;\n  } else {\n    return false;\n  }\n}\n\nbool ReadFileToDatum(const string& filename, const int label,\n    Datum* datum) {\n  std::streampos size;\n\n  fstream file(filename.c_str(), ios::in|ios::binary|ios::ate);\n  if (file.is_open()) {\n    size = file.tellg();\n    std::string buffer(size, ' ');\n    file.seekg(0, ios::beg);\n    file.read(&buffer[0], size);\n    file.close();\n    datum->set_data(buffer);\n    datum->set_label(label);\n    datum->set_encoded(true);\n    return true;\n  } else {\n    return false;\n  }\n}\n\ncv::Mat DecodeDatumToCVMatNative(const Datum& datum) {\n  cv::Mat cv_img;\n  CHECK(datum.encoded()) << \"Datum not encoded\";\n  const string& data = datum.data();\n  std::vector<char> vec_data(data.c_str(), data.c_str() + data.size());\n  cv_img = cv::imdecode(vec_data, -1);\n  if (!cv_img.data) {\n    LOG(ERROR) << \"Could not decode datum \";\n  }\n  return cv_img;\n}\ncv::Mat DecodeDatumToCVMat(const Datum& datum, bool is_color) {\n  cv::Mat cv_img;\n  CHECK(datum.encoded()) << \"Datum not encoded\";\n  const string& data = datum.data();\n  std::vector<char> vec_data(data.c_str(), data.c_str() + data.size());\n  int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :\n    CV_LOAD_IMAGE_GRAYSCALE);\n  cv_img = cv::imdecode(vec_data, cv_read_flag);\n  if (!cv_img.data) {\n    LOG(ERROR) << \"Could not decode datum \";\n  }\n  return cv_img;\n}\n\n// If Datum is encoded will decoded using DecodeDatumToCVMat and CVMatToDatum\n// If Datum is not encoded will do nothing\nbool DecodeDatumNative(Datum* datum) {\n  if (datum->encoded()) {\n    cv::Mat cv_img = DecodeDatumToCVMatNative((*datum));\n    CVMatToDatum(cv_img, datum);\n    return true;\n  } else {\n    return false;\n  }\n}\nbool DecodeDatum(Datum* datum, bool is_color) {\n  if (datum->encoded()) {\n    cv::Mat cv_img = DecodeDatumToCVMat((*datum), is_color);\n    CVMatToDatum(cv_img, datum);\n    return true;\n  } else {\n    return false;\n  }\n}\n\nvoid CVMatToDatum(const cv::Mat& cv_img, Datum* datum) {\n  CHECK(cv_img.depth() == CV_8U) << \"Image data type must be unsigned byte\";\n  datum->set_channels(cv_img.channels());\n  datum->set_height(cv_img.rows);\n  datum->set_width(cv_img.cols);\n  datum->clear_data();\n  datum->clear_float_data();\n  datum->set_encoded(false);\n  int datum_channels = datum->channels();\n  int datum_height = datum->height();\n  int datum_width = datum->width();\n  int datum_size = datum_channels * datum_height * datum_width;\n  std::string buffer(datum_size, ' ');\n  for (int h = 0; h < datum_height; ++h) {\n    const uchar* ptr = cv_img.ptr<uchar>(h);\n    int img_index = 0;\n    for (int w = 0; w < datum_width; ++w) {\n      for (int c = 0; c < datum_channels; ++c) {\n        int datum_index = (c * datum_height + h) * datum_width + w;\n        buffer[datum_index] = static_cast<char>(ptr[img_index++]);\n      }\n    }\n  }\n  datum->set_data(buffer);\n}\n\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/math_functions.cpp",
    "content": "#include <boost/math/special_functions/next.hpp>\n#include <boost/random.hpp>\n\n#include <limits>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n#include \"caffe/util/rng.hpp\"\n\nnamespace caffe {\n\ntemplate<>\nvoid caffe_cpu_gemm<float>(const CBLAS_TRANSPOSE TransA,\n    const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,\n    const float alpha, const float* A, const float* B, const float beta,\n    float* C) {\n  int lda = (TransA == CblasNoTrans) ? K : M;\n  int ldb = (TransB == CblasNoTrans) ? N : K;\n  cblas_sgemm(CblasRowMajor, TransA, TransB, M, N, K, alpha, A, lda, B,\n      ldb, beta, C, N);\n}\n\ntemplate<>\nvoid caffe_cpu_gemm<double>(const CBLAS_TRANSPOSE TransA,\n    const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,\n    const double alpha, const double* A, const double* B, const double beta,\n    double* C) {\n  int lda = (TransA == CblasNoTrans) ? K : M;\n  int ldb = (TransB == CblasNoTrans) ? N : K;\n  cblas_dgemm(CblasRowMajor, TransA, TransB, M, N, K, alpha, A, lda, B,\n      ldb, beta, C, N);\n}\n\ntemplate <>\nvoid caffe_cpu_gemv<float>(const CBLAS_TRANSPOSE TransA, const int M,\n    const int N, const float alpha, const float* A, const float* x,\n    const float beta, float* y) {\n  cblas_sgemv(CblasRowMajor, TransA, M, N, alpha, A, N, x, 1, beta, y, 1);\n}\n\ntemplate <>\nvoid caffe_cpu_gemv<double>(const CBLAS_TRANSPOSE TransA, const int M,\n    const int N, const double alpha, const double* A, const double* x,\n    const double beta, double* y) {\n  cblas_dgemv(CblasRowMajor, TransA, M, N, alpha, A, N, x, 1, beta, y, 1);\n}\n\ntemplate <>\nvoid caffe_axpy<float>(const int N, const float alpha, const float* X,\n    float* Y) { cblas_saxpy(N, alpha, X, 1, Y, 1); }\n\ntemplate <>\nvoid caffe_axpy<double>(const int N, const double alpha, const double* X,\n    double* Y) { cblas_daxpy(N, alpha, X, 1, Y, 1); }\n\ntemplate <typename Dtype>\nvoid caffe_set(const int N, const Dtype alpha, Dtype* Y) {\n  if (alpha == 0) {\n    memset(Y, 0, sizeof(Dtype) * N);  // NOLINT(caffe/alt_fn)\n    return;\n  }\n  for (int i = 0; i < N; ++i) {\n    Y[i] = alpha;\n  }\n}\n\ntemplate void caffe_set<int>(const int N, const int alpha, int* Y);\ntemplate void caffe_set<float>(const int N, const float alpha, float* Y);\ntemplate void caffe_set<double>(const int N, const double alpha, double* Y);\n\ntemplate <>\nvoid caffe_add_scalar(const int N, const float alpha, float* Y) {\n  for (int i = 0; i < N; ++i) {\n    Y[i] += alpha;\n  }\n}\n\ntemplate <>\nvoid caffe_add_scalar(const int N, const double alpha, double* Y) {\n  for (int i = 0; i < N; ++i) {\n    Y[i] += alpha;\n  }\n}\n\ntemplate <typename Dtype>\nvoid caffe_copy(const int N, const Dtype* X, Dtype* Y) {\n  if (X != Y) {\n    if (Caffe::mode() == Caffe::GPU) {\n#ifndef CPU_ONLY\n      // NOLINT_NEXT_LINE(caffe/alt_fn)\n      CUDA_CHECK(cudaMemcpy(Y, X, sizeof(Dtype) * N, cudaMemcpyDefault));\n#else\n      NO_GPU;\n#endif\n    } else {\n      memcpy(Y, X, sizeof(Dtype) * N);  // NOLINT(caffe/alt_fn)\n    }\n  }\n}\n\ntemplate void caffe_copy<int>(const int N, const int* X, int* Y);\ntemplate void caffe_copy<unsigned int>(const int N, const unsigned int* X,\n    unsigned int* Y);\ntemplate void caffe_copy<float>(const int N, const float* X, float* Y);\ntemplate void caffe_copy<double>(const int N, const double* X, double* Y);\n\ntemplate <>\nvoid caffe_scal<float>(const int N, const float alpha, float *X) {\n  cblas_sscal(N, alpha, X, 1);\n}\n\ntemplate <>\nvoid caffe_scal<double>(const int N, const double alpha, double *X) {\n  cblas_dscal(N, alpha, X, 1);\n}\n\ntemplate <>\nvoid caffe_cpu_axpby<float>(const int N, const float alpha, const float* X,\n                            const float beta, float* Y) {\n  cblas_saxpby(N, alpha, X, 1, beta, Y, 1);\n}\n\ntemplate <>\nvoid caffe_cpu_axpby<double>(const int N, const double alpha, const double* X,\n                             const double beta, double* Y) {\n  cblas_daxpby(N, alpha, X, 1, beta, Y, 1);\n}\n\ntemplate <>\nvoid caffe_add<float>(const int n, const float* a, const float* b,\n    float* y) {\n  vsAdd(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_add<double>(const int n, const double* a, const double* b,\n    double* y) {\n  vdAdd(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_sub<float>(const int n, const float* a, const float* b,\n    float* y) {\n  vsSub(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_sub<double>(const int n, const double* a, const double* b,\n    double* y) {\n  vdSub(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_mul<float>(const int n, const float* a, const float* b,\n    float* y) {\n  vsMul(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_mul<double>(const int n, const double* a, const double* b,\n    double* y) {\n  vdMul(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_div<float>(const int n, const float* a, const float* b,\n    float* y) {\n  vsDiv(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_div<double>(const int n, const double* a, const double* b,\n    double* y) {\n  vdDiv(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_powx<float>(const int n, const float* a, const float b,\n    float* y) {\n  vsPowx(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_powx<double>(const int n, const double* a, const double b,\n    double* y) {\n  vdPowx(n, a, b, y);\n}\n\ntemplate <>\nvoid caffe_sqr<float>(const int n, const float* a, float* y) {\n  vsSqr(n, a, y);\n}\n\ntemplate <>\nvoid caffe_sqr<double>(const int n, const double* a, double* y) {\n  vdSqr(n, a, y);\n}\n\ntemplate <>\nvoid caffe_exp<float>(const int n, const float* a, float* y) {\n  vsExp(n, a, y);\n}\n\ntemplate <>\nvoid caffe_exp<double>(const int n, const double* a, double* y) {\n  vdExp(n, a, y);\n}\n\ntemplate <>\nvoid caffe_log<float>(const int n, const float* a, float* y) {\n  vsLn(n, a, y);\n}\n\ntemplate <>\nvoid caffe_log<double>(const int n, const double* a, double* y) {\n  vdLn(n, a, y);\n}\n\ntemplate <>\nvoid caffe_abs<float>(const int n, const float* a, float* y) {\n    vsAbs(n, a, y);\n}\n\ntemplate <>\nvoid caffe_abs<double>(const int n, const double* a, double* y) {\n    vdAbs(n, a, y);\n}\n\nunsigned int caffe_rng_rand() {\n  return (*caffe_rng())();\n}\n\ntemplate <typename Dtype>\nDtype caffe_nextafter(const Dtype b) {\n  return boost::math::nextafter<Dtype>(\n      b, std::numeric_limits<Dtype>::max());\n}\n\ntemplate\nfloat caffe_nextafter(const float b);\n\ntemplate\ndouble caffe_nextafter(const double b);\n\ntemplate <typename Dtype>\nvoid caffe_rng_uniform(const int n, const Dtype a, const Dtype b, Dtype* r) {\n  CHECK_GE(n, 0);\n  CHECK(r);\n  CHECK_LE(a, b);\n  boost::uniform_real<Dtype> random_distribution(a, caffe_nextafter<Dtype>(b));\n  boost::variate_generator<caffe::rng_t*, boost::uniform_real<Dtype> >\n      variate_generator(caffe_rng(), random_distribution);\n  for (int i = 0; i < n; ++i) {\n    r[i] = variate_generator();\n  }\n}\n\ntemplate\nvoid caffe_rng_uniform<float>(const int n, const float a, const float b,\n                              float* r);\n\ntemplate\nvoid caffe_rng_uniform<double>(const int n, const double a, const double b,\n                               double* r);\n\ntemplate <typename Dtype>\nvoid caffe_rng_gaussian(const int n, const Dtype a,\n                        const Dtype sigma, Dtype* r) {\n  CHECK_GE(n, 0);\n  CHECK(r);\n  CHECK_GT(sigma, 0);\n  boost::normal_distribution<Dtype> random_distribution(a, sigma);\n  boost::variate_generator<caffe::rng_t*, boost::normal_distribution<Dtype> >\n      variate_generator(caffe_rng(), random_distribution);\n  for (int i = 0; i < n; ++i) {\n    r[i] = variate_generator();\n  }\n}\n\ntemplate\nvoid caffe_rng_gaussian<float>(const int n, const float mu,\n                               const float sigma, float* r);\n\ntemplate\nvoid caffe_rng_gaussian<double>(const int n, const double mu,\n                                const double sigma, double* r);\n\ntemplate <typename Dtype>\nvoid caffe_rng_bernoulli(const int n, const Dtype p, int* r) {\n  CHECK_GE(n, 0);\n  CHECK(r);\n  CHECK_GE(p, 0);\n  CHECK_LE(p, 1);\n  boost::bernoulli_distribution<Dtype> random_distribution(p);\n  boost::variate_generator<caffe::rng_t*, boost::bernoulli_distribution<Dtype> >\n      variate_generator(caffe_rng(), random_distribution);\n  for (int i = 0; i < n; ++i) {\n    r[i] = variate_generator();\n  }\n}\n\ntemplate\nvoid caffe_rng_bernoulli<double>(const int n, const double p, int* r);\n\ntemplate\nvoid caffe_rng_bernoulli<float>(const int n, const float p, int* r);\n\ntemplate <typename Dtype>\nvoid caffe_rng_bernoulli(const int n, const Dtype p, unsigned int* r) {\n  CHECK_GE(n, 0);\n  CHECK(r);\n  CHECK_GE(p, 0);\n  CHECK_LE(p, 1);\n  boost::bernoulli_distribution<Dtype> random_distribution(p);\n  boost::variate_generator<caffe::rng_t*, boost::bernoulli_distribution<Dtype> >\n      variate_generator(caffe_rng(), random_distribution);\n  for (int i = 0; i < n; ++i) {\n    r[i] = static_cast<unsigned int>(variate_generator());\n  }\n}\n\ntemplate\nvoid caffe_rng_bernoulli<double>(const int n, const double p, unsigned int* r);\n\ntemplate\nvoid caffe_rng_bernoulli<float>(const int n, const float p, unsigned int* r);\n\ntemplate <>\nfloat caffe_cpu_strided_dot<float>(const int n, const float* x, const int incx,\n    const float* y, const int incy) {\n  return cblas_sdot(n, x, incx, y, incy);\n}\n\ntemplate <>\ndouble caffe_cpu_strided_dot<double>(const int n, const double* x,\n    const int incx, const double* y, const int incy) {\n  return cblas_ddot(n, x, incx, y, incy);\n}\n\ntemplate <typename Dtype>\nDtype caffe_cpu_dot(const int n, const Dtype* x, const Dtype* y) {\n  return caffe_cpu_strided_dot(n, x, 1, y, 1);\n}\n\ntemplate\nfloat caffe_cpu_dot<float>(const int n, const float* x, const float* y);\n\ntemplate\ndouble caffe_cpu_dot<double>(const int n, const double* x, const double* y);\n\ntemplate <>\nint caffe_cpu_hamming_distance<float>(const int n, const float* x,\n                                  const float* y) {\n  int dist = 0;\n  for (int i = 0; i < n; ++i) {\n    dist += __builtin_popcount(static_cast<uint32_t>(x[i]) ^\n                               static_cast<uint32_t>(y[i]));\n  }\n  return dist;\n}\n\ntemplate <>\nint caffe_cpu_hamming_distance<double>(const int n, const double* x,\n                                   const double* y) {\n  int dist = 0;\n  for (int i = 0; i < n; ++i) {\n    dist += __builtin_popcountl(static_cast<uint64_t>(x[i]) ^\n                                static_cast<uint64_t>(y[i]));\n  }\n  return dist;\n}\n\ntemplate <>\nfloat caffe_cpu_asum<float>(const int n, const float* x) {\n  return cblas_sasum(n, x, 1);\n}\n\ntemplate <>\ndouble caffe_cpu_asum<double>(const int n, const double* x) {\n  return cblas_dasum(n, x, 1);\n}\n\ntemplate <>\nvoid caffe_cpu_scale<float>(const int n, const float alpha, const float *x,\n                            float* y) {\n  cblas_scopy(n, x, 1, y, 1);\n  cblas_sscal(n, alpha, y, 1);\n}\n\ntemplate <>\nvoid caffe_cpu_scale<double>(const int n, const double alpha, const double *x,\n                             double* y) {\n  cblas_dcopy(n, x, 1, y, 1);\n  cblas_dscal(n, alpha, y, 1);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/math_functions.cu",
    "content": "#include <math_functions.h>  // CUDA's, not caffe's, for fabs, signbit\n#include <thrust/device_vector.h>\n#include <thrust/functional.h>  // thrust::plus\n#include <thrust/reduce.h>\n\n#include <cmath>\n#include <cstdlib>\n#include <cstring>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/util/math_functions.hpp\"\n\nnamespace caffe {\n\ntemplate <>\nvoid caffe_gpu_gemm<float>(const CBLAS_TRANSPOSE TransA,\n    const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,\n    const float alpha, const float* A, const float* B, const float beta,\n    float* C) {\n  // Note that cublas follows fortran order.\n  int lda = (TransA == CblasNoTrans) ? K : M;\n  int ldb = (TransB == CblasNoTrans) ? N : K;\n  cublasOperation_t cuTransA =\n      (TransA == CblasNoTrans) ? CUBLAS_OP_N : CUBLAS_OP_T;\n  cublasOperation_t cuTransB =\n      (TransB == CblasNoTrans) ? CUBLAS_OP_N : CUBLAS_OP_T;\n  CUBLAS_CHECK(cublasSgemm(Caffe::cublas_handle(), cuTransB, cuTransA,\n      N, M, K, &alpha, B, ldb, A, lda, &beta, C, N));\n}\n\ntemplate <>\nvoid caffe_gpu_gemm<double>(const CBLAS_TRANSPOSE TransA,\n    const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,\n    const double alpha, const double* A, const double* B, const double beta,\n    double* C) {\n  // Note that cublas follows fortran order.\n  int lda = (TransA == CblasNoTrans) ? K : M;\n  int ldb = (TransB == CblasNoTrans) ? N : K;\n  cublasOperation_t cuTransA =\n      (TransA == CblasNoTrans) ? CUBLAS_OP_N : CUBLAS_OP_T;\n  cublasOperation_t cuTransB =\n      (TransB == CblasNoTrans) ? CUBLAS_OP_N : CUBLAS_OP_T;\n  CUBLAS_CHECK(cublasDgemm(Caffe::cublas_handle(), cuTransB, cuTransA,\n      N, M, K, &alpha, B, ldb, A, lda, &beta, C, N));\n}\n\ntemplate <>\nvoid caffe_gpu_gemv<float>(const CBLAS_TRANSPOSE TransA, const int M,\n    const int N, const float alpha, const float* A, const float* x,\n    const float beta, float* y) {\n  cublasOperation_t cuTransA =\n      (TransA == CblasNoTrans) ? CUBLAS_OP_T : CUBLAS_OP_N;\n  CUBLAS_CHECK(cublasSgemv(Caffe::cublas_handle(), cuTransA, N, M, &alpha,\n      A, N, x, 1, &beta, y, 1));\n}\n\ntemplate <>\nvoid caffe_gpu_gemv<double>(const CBLAS_TRANSPOSE TransA, const int M,\n    const int N, const double alpha, const double* A, const double* x,\n    const double beta, double* y) {\n  cublasOperation_t cuTransA =\n      (TransA == CblasNoTrans) ? CUBLAS_OP_T : CUBLAS_OP_N;\n  CUBLAS_CHECK(cublasDgemv(Caffe::cublas_handle(), cuTransA, N, M, &alpha,\n      A, N, x, 1, &beta, y, 1));\n}\n\ntemplate <>\nvoid caffe_gpu_axpy<float>(const int N, const float alpha, const float* X,\n    float* Y) {\n  CUBLAS_CHECK(cublasSaxpy(Caffe::cublas_handle(), N, &alpha, X, 1, Y, 1));\n}\n\ntemplate <>\nvoid caffe_gpu_axpy<double>(const int N, const double alpha, const double* X,\n    double* Y) {\n  CUBLAS_CHECK(cublasDaxpy(Caffe::cublas_handle(), N, &alpha, X, 1, Y, 1));\n}\n\nvoid caffe_gpu_memcpy(const size_t N, const void* X, void* Y) {\n  if (X != Y) {\n    CUDA_CHECK(cudaMemcpy(Y, X, N, cudaMemcpyDefault));  // NOLINT(caffe/alt_fn)\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_scal<float>(const int N, const float alpha, float *X) {\n  CUBLAS_CHECK(cublasSscal(Caffe::cublas_handle(), N, &alpha, X, 1));\n}\n\ntemplate <>\nvoid caffe_gpu_scal<double>(const int N, const double alpha, double *X) {\n  CUBLAS_CHECK(cublasDscal(Caffe::cublas_handle(), N, &alpha, X, 1));\n}\n\ntemplate <>\nvoid caffe_gpu_axpby<float>(const int N, const float alpha, const float* X,\n    const float beta, float* Y) {\n  caffe_gpu_scal<float>(N, beta, Y);\n  caffe_gpu_axpy<float>(N, alpha, X, Y);\n}\n\ntemplate <>\nvoid caffe_gpu_axpby<double>(const int N, const double alpha, const double* X,\n    const double beta, double* Y) {\n  caffe_gpu_scal<double>(N, beta, Y);\n  caffe_gpu_axpy<double>(N, alpha, X, Y);\n}\n\ntemplate <>\nvoid caffe_gpu_dot<float>(const int n, const float* x, const float* y,\n    float* out) {\n  CUBLAS_CHECK(cublasSdot(Caffe::cublas_handle(), n, x, 1, y, 1, out));\n}\n\ntemplate <>\nvoid caffe_gpu_dot<double>(const int n, const double* x, const double* y,\n    double * out) {\n  CUBLAS_CHECK(cublasDdot(Caffe::cublas_handle(), n, x, 1, y, 1, out));\n}\n\ntemplate <>\nvoid caffe_gpu_asum<float>(const int n, const float* x, float* y) {\n  CUBLAS_CHECK(cublasSasum(Caffe::cublas_handle(), n, x, 1, y));\n}\n\ntemplate <>\nvoid caffe_gpu_asum<double>(const int n, const double* x, double* y) {\n  CUBLAS_CHECK(cublasDasum(Caffe::cublas_handle(), n, x, 1, y));\n}\n\ntemplate <>\nvoid caffe_gpu_scale<float>(const int n, const float alpha, const float *x,\n                            float* y) {\n  CUBLAS_CHECK(cublasScopy(Caffe::cublas_handle(), n, x, 1, y, 1));\n  CUBLAS_CHECK(cublasSscal(Caffe::cublas_handle(), n, &alpha, y, 1));\n}\n\ntemplate <>\nvoid caffe_gpu_scale<double>(const int n, const double alpha, const double *x,\n                             double* y) {\n  CUBLAS_CHECK(cublasDcopy(Caffe::cublas_handle(), n, x, 1, y, 1));\n  CUBLAS_CHECK(cublasDscal(Caffe::cublas_handle(), n, &alpha, y, 1));\n}\n\ntemplate <typename Dtype>\n__global__ void set_kernel(const int n, const Dtype alpha, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = alpha;\n  }\n}\n\ntemplate <typename Dtype>\nvoid caffe_gpu_set(const int N, const Dtype alpha, Dtype* Y) {\n  if (alpha == 0) {\n    CUDA_CHECK(cudaMemset(Y, 0, sizeof(Dtype) * N));  // NOLINT(caffe/alt_fn)\n    return;\n  }\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  set_kernel<Dtype><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, alpha, Y);\n}\n\ntemplate void caffe_gpu_set<int>(const int N, const int alpha, int* Y);\ntemplate void caffe_gpu_set<float>(const int N, const float alpha, float* Y);\ntemplate void caffe_gpu_set<double>(const int N, const double alpha, double* Y);\n\ntemplate <typename Dtype>\n__global__ void add_scalar_kernel(const int n, const Dtype alpha, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] += alpha;\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_add_scalar(const int N, const float alpha, float* Y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  add_scalar_kernel<float><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, alpha, Y);\n}\n\ntemplate <>\nvoid caffe_gpu_add_scalar(const int N, const double alpha, double* Y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  add_scalar_kernel<double><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, alpha, Y);\n}\n\ntemplate <typename Dtype>\n__global__ void add_kernel(const int n, const Dtype* a,\n    const Dtype* b, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = a[index] + b[index];\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_add<float>(const int N, const float* a, const float* b,\n    float* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  add_kernel<float><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, b, y);\n}\n\ntemplate <>\nvoid caffe_gpu_add<double>(const int N, const double* a, const double* b,\n    double* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  add_kernel<double><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, b, y);\n}\n\ntemplate <typename Dtype>\n__global__ void sub_kernel(const int n, const Dtype* a,\n    const Dtype* b, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = a[index] - b[index];\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_sub<float>(const int N, const float* a, const float* b,\n    float* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  sub_kernel<float><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, b, y);\n}\n\ntemplate <>\nvoid caffe_gpu_sub<double>(const int N, const double* a, const double* b,\n    double* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  sub_kernel<double><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, b, y);\n}\n\ntemplate <typename Dtype>\n__global__ void mul_kernel(const int n, const Dtype* a,\n    const Dtype* b, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = a[index] * b[index];\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_mul<float>(const int N, const float* a,\n    const float* b, float* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  mul_kernel<float><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, b, y);\n}\n\ntemplate <>\nvoid caffe_gpu_mul<double>(const int N, const double* a,\n    const double* b, double* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  mul_kernel<double><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, b, y);\n}\n\ntemplate <typename Dtype>\n__global__ void div_kernel(const int n, const Dtype* a,\n    const Dtype* b, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = a[index] / b[index];\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_div<float>(const int N, const float* a,\n    const float* b, float* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  div_kernel<float><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, b, y);\n}\n\ntemplate <>\nvoid caffe_gpu_div<double>(const int N, const double* a,\n    const double* b, double* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  div_kernel<double><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, b, y);\n}\n\ntemplate <typename Dtype>\n__global__ void abs_kernel(const int n, const Dtype* a, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = abs(a[index]);\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_abs<float>(const int N, const float* a, float* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  abs_kernel<float><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, y);\n}\n\ntemplate <>\nvoid caffe_gpu_abs<double>(const int N, const double* a, double* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  abs_kernel<double><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, y);\n}\n\n\ntemplate <typename Dtype>\n__global__ void exp_kernel(const int n, const Dtype* a, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = exp(a[index]);\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_exp<float>(const int N, const float* a, float* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  exp_kernel<float><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, y);\n}\n\ntemplate <>\nvoid caffe_gpu_exp<double>(const int N, const double* a, double* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  exp_kernel<double><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, y);\n}\n\ntemplate <typename Dtype>\n__global__ void log_kernel(const int n, const Dtype* a, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = log(a[index]);\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_log<float>(const int N, const float* a, float* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  log_kernel<float><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, y);\n}\n\ntemplate <>\nvoid caffe_gpu_log<double>(const int N, const double* a, double* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  log_kernel<double><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, y);\n}\n\ntemplate <typename Dtype>\n__global__ void powx_kernel(const int n, const Dtype* a,\n    const Dtype alpha, Dtype* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = pow(a[index], alpha);\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_powx<float>(const int N, const float* a,\n    const float alpha, float* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  powx_kernel<float><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, alpha, y);\n}\n\ntemplate <>\nvoid caffe_gpu_powx<double>(const int N, const double* a,\n    const double alpha, double* y) {\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  powx_kernel<double><<<CAFFE_GET_BLOCKS(N), CAFFE_CUDA_NUM_THREADS>>>(\n      N, a, alpha, y);\n}\n\nDEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(sign, y[index] = (Dtype(0) < x[index])\n                                      - (x[index] < Dtype(0)));\nDEFINE_AND_INSTANTIATE_GPU_UNARY_FUNC(sgnbit, y[index] = signbit(x[index]));\n\n__global__ void popc_kernel(const int n, const float* a,\n    const float* b, uint8_t* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = __popc(static_cast<uint32_t>(a[index]) ^\n                      static_cast<uint32_t>(b[index]));\n  }\n}\n\n__global__ void popcll_kernel(const int n, const double* a,\n    const double* b, uint8_t* y) {\n  CUDA_KERNEL_LOOP(index, n) {\n    y[index] = __popcll(static_cast<uint64_t>(a[index]) ^\n                      static_cast<uint64_t>(b[index]));\n  }\n}\n\ntemplate <>\nuint32_t caffe_gpu_hamming_distance<float>(const int n, const float* x,\n                                  const float* y) {\n  // TODO: Fix caffe_gpu_hamming_distance (see failing unit test\n  // TestHammingDistanceGPU in test_math_functions.cpp).\n  NOT_IMPLEMENTED;\n  thrust::device_vector<uint8_t> popcounts(n);\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  popc_kernel<<<CAFFE_GET_BLOCKS(n), CAFFE_CUDA_NUM_THREADS>>>(\n      n, x, y, thrust::raw_pointer_cast(popcounts.data()));\n  return thrust::reduce(popcounts.begin(), popcounts.end(),\n                        (uint32_t) 0, thrust::plus<uint32_t>());\n}\n\ntemplate <>\nuint32_t caffe_gpu_hamming_distance<double>(const int n, const double* x,\n                                   const double* y) {\n  // TODO: Fix caffe_gpu_hamming_distance (see failing unit test\n  // TestHammingDistanceGPU in test_math_functions.cpp).\n  NOT_IMPLEMENTED;\n  thrust::device_vector<uint8_t> popcounts(n);\n  // NOLINT_NEXT_LINE(whitespace/operators)\n  popcll_kernel<<<CAFFE_GET_BLOCKS(n), CAFFE_CUDA_NUM_THREADS>>>(\n      n, x, y, thrust::raw_pointer_cast(popcounts.data()));\n  return thrust::reduce(popcounts.begin(), popcounts.end(),\n                        /* NOLINT_NEXT_LINE(build/include_what_you_use) */\n                        (uint32_t) 0, thrust::plus<uint32_t>());\n}\n\nvoid caffe_gpu_rng_uniform(const int n, unsigned int* r) {\n  CURAND_CHECK(curandGenerate(Caffe::curand_generator(), r, n));\n}\n\ntemplate <>\nvoid caffe_gpu_rng_uniform<float>(const int n, const float a, const float b,\n                                  float* r) {\n  CURAND_CHECK(curandGenerateUniform(Caffe::curand_generator(), r, n));\n  const float range = b - a;\n  if (range != static_cast<float>(1)) {\n    caffe_gpu_scal(n, range, r);\n  }\n  if (a != static_cast<float>(0)) {\n    caffe_gpu_add_scalar(n, a, r);\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_rng_uniform<double>(const int n, const double a, const double b,\n                                   double* r) {\n  CURAND_CHECK(curandGenerateUniformDouble(Caffe::curand_generator(), r, n));\n  const double range = b - a;\n  if (range != static_cast<double>(1)) {\n    caffe_gpu_scal(n, range, r);\n  }\n  if (a != static_cast<double>(0)) {\n    caffe_gpu_add_scalar(n, a, r);\n  }\n}\n\ntemplate <>\nvoid caffe_gpu_rng_gaussian(const int n, const float mu, const float sigma,\n                            float* r) {\n  CURAND_CHECK(\n      curandGenerateNormal(Caffe::curand_generator(), r, n, mu, sigma));\n}\n\ntemplate <>\nvoid caffe_gpu_rng_gaussian(const int n, const double mu, const double sigma,\n                            double* r) {\n  CURAND_CHECK(\n      curandGenerateNormalDouble(Caffe::curand_generator(), r, n, mu, sigma));\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/caffe/util/upgrade_proto.cpp",
    "content": "#include <google/protobuf/io/coded_stream.h>\n#include <google/protobuf/io/zero_copy_stream_impl.h>\n#include <google/protobuf/text_format.h>\n\n#include <map>\n#include <string>\n\n#include \"caffe/common.hpp\"\n#include \"caffe/proto/caffe.pb.h\"\n#include \"caffe/util/io.hpp\"\n#include \"caffe/util/upgrade_proto.hpp\"\n\nnamespace caffe {\n\nbool NetNeedsUpgrade(const NetParameter& net_param) {\n  return NetNeedsV0ToV1Upgrade(net_param) || NetNeedsV1ToV2Upgrade(net_param);\n}\n\nbool NetNeedsV0ToV1Upgrade(const NetParameter& net_param) {\n  for (int i = 0; i < net_param.layers_size(); ++i) {\n    if (net_param.layers(i).has_layer()) {\n      return true;\n    }\n  }\n  return false;\n}\n\nbool NetNeedsV1ToV2Upgrade(const NetParameter& net_param) {\n  return net_param.layers_size() > 0;\n}\n\nbool UpgradeV0Net(const NetParameter& v0_net_param_padding_layers,\n                  NetParameter* net_param) {\n  // First upgrade padding layers to padded conv layers.\n  NetParameter v0_net_param;\n  UpgradeV0PaddingLayers(v0_net_param_padding_layers, &v0_net_param);\n  // Now upgrade layer parameters.\n  bool is_fully_compatible = true;\n  net_param->Clear();\n  if (v0_net_param.has_name()) {\n    net_param->set_name(v0_net_param.name());\n  }\n  for (int i = 0; i < v0_net_param.layers_size(); ++i) {\n    is_fully_compatible &= UpgradeV0LayerParameter(v0_net_param.layers(i),\n                                                   net_param->add_layers());\n  }\n  for (int i = 0; i < v0_net_param.input_size(); ++i) {\n    net_param->add_input(v0_net_param.input(i));\n  }\n  for (int i = 0; i < v0_net_param.input_dim_size(); ++i) {\n    net_param->add_input_dim(v0_net_param.input_dim(i));\n  }\n  if (v0_net_param.has_force_backward()) {\n    net_param->set_force_backward(v0_net_param.force_backward());\n  }\n  return is_fully_compatible;\n}\n\nvoid UpgradeV0PaddingLayers(const NetParameter& param,\n                            NetParameter* param_upgraded_pad) {\n  // Copy everything other than the layers from the original param.\n  param_upgraded_pad->Clear();\n  param_upgraded_pad->CopyFrom(param);\n  param_upgraded_pad->clear_layers();\n  // Figure out which layer each bottom blob comes from.\n  map<string, int> blob_name_to_last_top_idx;\n  for (int i = 0; i < param.input_size(); ++i) {\n    const string& blob_name = param.input(i);\n    blob_name_to_last_top_idx[blob_name] = -1;\n  }\n  for (int i = 0; i < param.layers_size(); ++i) {\n    const V1LayerParameter& layer_connection = param.layers(i);\n    const V0LayerParameter& layer_param = layer_connection.layer();\n    // Add the layer to the new net, unless it's a padding layer.\n    if (layer_param.type() != \"padding\") {\n      param_upgraded_pad->add_layers()->CopyFrom(layer_connection);\n    }\n    for (int j = 0; j < layer_connection.bottom_size(); ++j) {\n      const string& blob_name = layer_connection.bottom(j);\n      if (blob_name_to_last_top_idx.find(blob_name) ==\n          blob_name_to_last_top_idx.end()) {\n        LOG(FATAL) << \"Unknown blob input \" << blob_name << \" to layer \" << j;\n      }\n      const int top_idx = blob_name_to_last_top_idx[blob_name];\n      if (top_idx == -1) {\n        continue;\n      }\n      const V1LayerParameter& source_layer = param.layers(top_idx);\n      if (source_layer.layer().type() == \"padding\") {\n        // This layer has a padding layer as input -- check that it is a conv\n        // layer or a pooling layer and takes only one input.  Also check that\n        // the padding layer input has only one input and one output.  Other\n        // cases have undefined behavior in Caffe.\n        CHECK((layer_param.type() == \"conv\") || (layer_param.type() == \"pool\"))\n            << \"Padding layer input to \"\n            \"non-convolutional / non-pooling layer type \"\n            << layer_param.type();\n        CHECK_EQ(layer_connection.bottom_size(), 1)\n            << \"Conv Layer takes a single blob as input.\";\n        CHECK_EQ(source_layer.bottom_size(), 1)\n            << \"Padding Layer takes a single blob as input.\";\n        CHECK_EQ(source_layer.top_size(), 1)\n            << \"Padding Layer produces a single blob as output.\";\n        int layer_index = param_upgraded_pad->layers_size() - 1;\n        param_upgraded_pad->mutable_layers(layer_index)->mutable_layer()\n            ->set_pad(source_layer.layer().pad());\n        param_upgraded_pad->mutable_layers(layer_index)\n            ->set_bottom(j, source_layer.bottom(0));\n      }\n    }\n    for (int j = 0; j < layer_connection.top_size(); ++j) {\n      const string& blob_name = layer_connection.top(j);\n      blob_name_to_last_top_idx[blob_name] = i;\n    }\n  }\n}\n\nbool UpgradeV0LayerParameter(const V1LayerParameter& v0_layer_connection,\n                             V1LayerParameter* layer_param) {\n  bool is_fully_compatible = true;\n  layer_param->Clear();\n  for (int i = 0; i < v0_layer_connection.bottom_size(); ++i) {\n    layer_param->add_bottom(v0_layer_connection.bottom(i));\n  }\n  for (int i = 0; i < v0_layer_connection.top_size(); ++i) {\n    layer_param->add_top(v0_layer_connection.top(i));\n  }\n  if (v0_layer_connection.has_layer()) {\n    const V0LayerParameter& v0_layer_param = v0_layer_connection.layer();\n    if (v0_layer_param.has_name()) {\n      layer_param->set_name(v0_layer_param.name());\n    }\n    const string& type = v0_layer_param.type();\n    if (v0_layer_param.has_type()) {\n      layer_param->set_type(UpgradeV0LayerType(type));\n    }\n    for (int i = 0; i < v0_layer_param.blobs_size(); ++i) {\n      layer_param->add_blobs()->CopyFrom(v0_layer_param.blobs(i));\n    }\n    for (int i = 0; i < v0_layer_param.blobs_lr_size(); ++i) {\n      layer_param->add_blobs_lr(v0_layer_param.blobs_lr(i));\n    }\n    for (int i = 0; i < v0_layer_param.weight_decay_size(); ++i) {\n      layer_param->add_weight_decay(v0_layer_param.weight_decay(i));\n    }\n    if (v0_layer_param.has_num_output()) {\n      if (type == \"conv\") {\n        layer_param->mutable_convolution_param()->set_num_output(\n            v0_layer_param.num_output());\n      } else if (type == \"innerproduct\") {\n        layer_param->mutable_inner_product_param()->set_num_output(\n            v0_layer_param.num_output());\n      } else {\n        LOG(ERROR) << \"Unknown parameter num_output for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_biasterm()) {\n      if (type == \"conv\") {\n        layer_param->mutable_convolution_param()->set_bias_term(\n            v0_layer_param.biasterm());\n      } else if (type == \"innerproduct\") {\n        layer_param->mutable_inner_product_param()->set_bias_term(\n            v0_layer_param.biasterm());\n      } else {\n        LOG(ERROR) << \"Unknown parameter biasterm for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_weight_filler()) {\n      if (type == \"conv\") {\n        layer_param->mutable_convolution_param()->\n            mutable_weight_filler()->CopyFrom(v0_layer_param.weight_filler());\n      } else if (type == \"innerproduct\") {\n        layer_param->mutable_inner_product_param()->\n            mutable_weight_filler()->CopyFrom(v0_layer_param.weight_filler());\n      } else {\n        LOG(ERROR) << \"Unknown parameter weight_filler for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_bias_filler()) {\n      if (type == \"conv\") {\n        layer_param->mutable_convolution_param()->\n            mutable_bias_filler()->CopyFrom(v0_layer_param.bias_filler());\n      } else if (type == \"innerproduct\") {\n        layer_param->mutable_inner_product_param()->\n            mutable_bias_filler()->CopyFrom(v0_layer_param.bias_filler());\n      } else {\n        LOG(ERROR) << \"Unknown parameter bias_filler for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_pad()) {\n      if (type == \"conv\") {\n        layer_param->mutable_convolution_param()->set_pad(v0_layer_param.pad());\n      } else if (type == \"pool\") {\n        layer_param->mutable_pooling_param()->set_pad(v0_layer_param.pad());\n      } else {\n        LOG(ERROR) << \"Unknown parameter pad for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_kernelsize()) {\n      if (type == \"conv\") {\n        layer_param->mutable_convolution_param()->set_kernel_size(\n            v0_layer_param.kernelsize());\n      } else if (type == \"pool\") {\n        layer_param->mutable_pooling_param()->set_kernel_size(\n            v0_layer_param.kernelsize());\n      } else {\n        LOG(ERROR) << \"Unknown parameter kernelsize for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_group()) {\n      if (type == \"conv\") {\n        layer_param->mutable_convolution_param()->set_group(\n            v0_layer_param.group());\n      } else {\n        LOG(ERROR) << \"Unknown parameter group for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_stride()) {\n      if (type == \"conv\") {\n        layer_param->mutable_convolution_param()->set_stride(\n            v0_layer_param.stride());\n      } else if (type == \"pool\") {\n        layer_param->mutable_pooling_param()->set_stride(\n            v0_layer_param.stride());\n      } else {\n        LOG(ERROR) << \"Unknown parameter stride for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_pool()) {\n      if (type == \"pool\") {\n        V0LayerParameter_PoolMethod pool = v0_layer_param.pool();\n        switch (pool) {\n        case V0LayerParameter_PoolMethod_MAX:\n          layer_param->mutable_pooling_param()->set_pool(\n              PoolingParameter_PoolMethod_MAX);\n          break;\n        case V0LayerParameter_PoolMethod_AVE:\n          layer_param->mutable_pooling_param()->set_pool(\n              PoolingParameter_PoolMethod_AVE);\n          break;\n        case V0LayerParameter_PoolMethod_STOCHASTIC:\n          layer_param->mutable_pooling_param()->set_pool(\n              PoolingParameter_PoolMethod_STOCHASTIC);\n          break;\n        default:\n          LOG(ERROR) << \"Unknown pool method \" << pool;\n          is_fully_compatible = false;\n        }\n      } else {\n        LOG(ERROR) << \"Unknown parameter pool for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_dropout_ratio()) {\n      if (type == \"dropout\") {\n        layer_param->mutable_dropout_param()->set_dropout_ratio(\n            v0_layer_param.dropout_ratio());\n      } else {\n        LOG(ERROR) << \"Unknown parameter dropout_ratio for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_local_size()) {\n      if (type == \"lrn\") {\n        layer_param->mutable_lrn_param()->set_local_size(\n            v0_layer_param.local_size());\n      } else {\n        LOG(ERROR) << \"Unknown parameter local_size for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_alpha()) {\n      if (type == \"lrn\") {\n        layer_param->mutable_lrn_param()->set_alpha(v0_layer_param.alpha());\n      } else {\n        LOG(ERROR) << \"Unknown parameter alpha for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_beta()) {\n      if (type == \"lrn\") {\n        layer_param->mutable_lrn_param()->set_beta(v0_layer_param.beta());\n      } else {\n        LOG(ERROR) << \"Unknown parameter beta for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_k()) {\n      if (type == \"lrn\") {\n        layer_param->mutable_lrn_param()->set_k(v0_layer_param.k());\n      } else {\n        LOG(ERROR) << \"Unknown parameter k for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_source()) {\n      if (type == \"data\") {\n        layer_param->mutable_data_param()->set_source(v0_layer_param.source());\n      } else if (type == \"hdf5_data\") {\n        layer_param->mutable_hdf5_data_param()->set_source(\n            v0_layer_param.source());\n      } else if (type == \"images\") {\n        layer_param->mutable_image_data_param()->set_source(\n            v0_layer_param.source());\n      } else if (type == \"window_data\") {\n        layer_param->mutable_window_data_param()->set_source(\n            v0_layer_param.source());\n      } else if (type == \"infogain_loss\") {\n        layer_param->mutable_infogain_loss_param()->set_source(\n            v0_layer_param.source());\n      } else {\n        LOG(ERROR) << \"Unknown parameter source for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_scale()) {\n      layer_param->mutable_transform_param()->\n          set_scale(v0_layer_param.scale());\n    }\n    if (v0_layer_param.has_meanfile()) {\n      layer_param->mutable_transform_param()->\n          set_mean_file(v0_layer_param.meanfile());\n    }\n    if (v0_layer_param.has_batchsize()) {\n      if (type == \"data\") {\n        layer_param->mutable_data_param()->set_batch_size(\n            v0_layer_param.batchsize());\n      } else if (type == \"hdf5_data\") {\n        layer_param->mutable_hdf5_data_param()->set_batch_size(\n            v0_layer_param.batchsize());\n      } else if (type == \"images\") {\n        layer_param->mutable_image_data_param()->set_batch_size(\n            v0_layer_param.batchsize());\n      } else if (type == \"window_data\") {\n        layer_param->mutable_window_data_param()->set_batch_size(\n            v0_layer_param.batchsize());\n      } else {\n        LOG(ERROR) << \"Unknown parameter batchsize for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_cropsize()) {\n      layer_param->mutable_transform_param()->\n          set_crop_size(v0_layer_param.cropsize());\n    }\n    if (v0_layer_param.has_mirror()) {\n      layer_param->mutable_transform_param()->\n          set_mirror(v0_layer_param.mirror());\n    }\n    if (v0_layer_param.has_rand_skip()) {\n      if (type == \"data\") {\n        layer_param->mutable_data_param()->set_rand_skip(\n            v0_layer_param.rand_skip());\n      } else if (type == \"images\") {\n        layer_param->mutable_image_data_param()->set_rand_skip(\n            v0_layer_param.rand_skip());\n      } else {\n        LOG(ERROR) << \"Unknown parameter rand_skip for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_shuffle_images()) {\n      if (type == \"images\") {\n        layer_param->mutable_image_data_param()->set_shuffle(\n            v0_layer_param.shuffle_images());\n      } else {\n        LOG(ERROR) << \"Unknown parameter shuffle for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_new_height()) {\n      if (type == \"images\") {\n        layer_param->mutable_image_data_param()->set_new_height(\n            v0_layer_param.new_height());\n      } else {\n        LOG(ERROR) << \"Unknown parameter new_height for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_new_width()) {\n      if (type == \"images\") {\n        layer_param->mutable_image_data_param()->set_new_width(\n            v0_layer_param.new_width());\n      } else {\n        LOG(ERROR) << \"Unknown parameter new_width for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_concat_dim()) {\n      if (type == \"concat\") {\n        layer_param->mutable_concat_param()->set_concat_dim(\n            v0_layer_param.concat_dim());\n      } else {\n        LOG(ERROR) << \"Unknown parameter concat_dim for layer type \" << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_det_fg_threshold()) {\n      if (type == \"window_data\") {\n        layer_param->mutable_window_data_param()->set_fg_threshold(\n            v0_layer_param.det_fg_threshold());\n      } else {\n        LOG(ERROR) << \"Unknown parameter det_fg_threshold for layer type \"\n                   << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_det_bg_threshold()) {\n      if (type == \"window_data\") {\n        layer_param->mutable_window_data_param()->set_bg_threshold(\n            v0_layer_param.det_bg_threshold());\n      } else {\n        LOG(ERROR) << \"Unknown parameter det_bg_threshold for layer type \"\n                   << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_det_fg_fraction()) {\n      if (type == \"window_data\") {\n        layer_param->mutable_window_data_param()->set_fg_fraction(\n            v0_layer_param.det_fg_fraction());\n      } else {\n        LOG(ERROR) << \"Unknown parameter det_fg_fraction for layer type \"\n                   << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_det_context_pad()) {\n      if (type == \"window_data\") {\n        layer_param->mutable_window_data_param()->set_context_pad(\n            v0_layer_param.det_context_pad());\n      } else {\n        LOG(ERROR) << \"Unknown parameter det_context_pad for layer type \"\n                   << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_det_crop_mode()) {\n      if (type == \"window_data\") {\n        layer_param->mutable_window_data_param()->set_crop_mode(\n            v0_layer_param.det_crop_mode());\n      } else {\n        LOG(ERROR) << \"Unknown parameter det_crop_mode for layer type \"\n                   << type;\n        is_fully_compatible = false;\n      }\n    }\n    if (v0_layer_param.has_hdf5_output_param()) {\n      if (type == \"hdf5_output\") {\n        layer_param->mutable_hdf5_output_param()->CopyFrom(\n            v0_layer_param.hdf5_output_param());\n      } else {\n        LOG(ERROR) << \"Unknown parameter hdf5_output_param for layer type \"\n                   << type;\n        is_fully_compatible = false;\n      }\n    }\n  }\n  return is_fully_compatible;\n}\n\nV1LayerParameter_LayerType UpgradeV0LayerType(const string& type) {\n  if (type == \"accuracy\") {\n    return V1LayerParameter_LayerType_ACCURACY;\n  } else if (type == \"bnll\") {\n    return V1LayerParameter_LayerType_BNLL;\n  } else if (type == \"concat\") {\n    return V1LayerParameter_LayerType_CONCAT;\n  } else if (type == \"conv\") {\n    return V1LayerParameter_LayerType_CONVOLUTION;\n  } else if (type == \"data\") {\n    return V1LayerParameter_LayerType_DATA;\n  } else if (type == \"dropout\") {\n    return V1LayerParameter_LayerType_DROPOUT;\n  } else if (type == \"euclidean_loss\") {\n    return V1LayerParameter_LayerType_EUCLIDEAN_LOSS;\n  } else if (type == \"flatten\") {\n    return V1LayerParameter_LayerType_FLATTEN;\n  } else if (type == \"hdf5_data\") {\n    return V1LayerParameter_LayerType_HDF5_DATA;\n  } else if (type == \"hdf5_output\") {\n    return V1LayerParameter_LayerType_HDF5_OUTPUT;\n  } else if (type == \"im2col\") {\n    return V1LayerParameter_LayerType_IM2COL;\n  } else if (type == \"images\") {\n    return V1LayerParameter_LayerType_IMAGE_DATA;\n  } else if (type == \"infogain_loss\") {\n    return V1LayerParameter_LayerType_INFOGAIN_LOSS;\n  } else if (type == \"innerproduct\") {\n    return V1LayerParameter_LayerType_INNER_PRODUCT;\n  } else if (type == \"lrn\") {\n    return V1LayerParameter_LayerType_LRN;\n  } else if (type == \"multinomial_logistic_loss\") {\n    return V1LayerParameter_LayerType_MULTINOMIAL_LOGISTIC_LOSS;\n  } else if (type == \"pool\") {\n    return V1LayerParameter_LayerType_POOLING;\n  } else if (type == \"relu\") {\n    return V1LayerParameter_LayerType_RELU;\n  } else if (type == \"sigmoid\") {\n    return V1LayerParameter_LayerType_SIGMOID;\n  } else if (type == \"softmax\") {\n    return V1LayerParameter_LayerType_SOFTMAX;\n  } else if (type == \"softmax_loss\") {\n    return V1LayerParameter_LayerType_SOFTMAX_LOSS;\n  } else if (type == \"split\") {\n    return V1LayerParameter_LayerType_SPLIT;\n  } else if (type == \"tanh\") {\n    return V1LayerParameter_LayerType_TANH;\n  } else if (type == \"window_data\") {\n    return V1LayerParameter_LayerType_WINDOW_DATA;\n  } else {\n    LOG(FATAL) << \"Unknown layer name: \" << type;\n    return V1LayerParameter_LayerType_NONE;\n  }\n}\n\nbool NetNeedsDataUpgrade(const NetParameter& net_param) {\n  for (int i = 0; i < net_param.layers_size(); ++i) {\n    if (net_param.layers(i).type() == V1LayerParameter_LayerType_DATA) {\n      DataParameter layer_param = net_param.layers(i).data_param();\n      if (layer_param.has_scale()) { return true; }\n      if (layer_param.has_mean_file()) { return true; }\n      if (layer_param.has_crop_size()) { return true; }\n      if (layer_param.has_mirror()) { return true; }\n    }\n    if (net_param.layers(i).type() == V1LayerParameter_LayerType_IMAGE_DATA) {\n      ImageDataParameter layer_param = net_param.layers(i).image_data_param();\n      if (layer_param.has_scale()) { return true; }\n      if (layer_param.has_mean_file()) { return true; }\n      if (layer_param.has_crop_size()) { return true; }\n      if (layer_param.has_mirror()) { return true; }\n    }\n    if (net_param.layers(i).type() == V1LayerParameter_LayerType_WINDOW_DATA) {\n      WindowDataParameter layer_param = net_param.layers(i).window_data_param();\n      if (layer_param.has_scale()) { return true; }\n      if (layer_param.has_mean_file()) { return true; }\n      if (layer_param.has_crop_size()) { return true; }\n      if (layer_param.has_mirror()) { return true; }\n    }\n  }\n  return false;\n}\n\n#define CONVERT_LAYER_TRANSFORM_PARAM(TYPE, Name, param_name) \\\n  do { \\\n    if (net_param->layers(i).type() == V1LayerParameter_LayerType_##TYPE) { \\\n      Name##Parameter* layer_param = \\\n          net_param->mutable_layers(i)->mutable_##param_name##_param(); \\\n      TransformationParameter* transform_param = \\\n          net_param->mutable_layers(i)->mutable_transform_param(); \\\n      if (layer_param->has_scale()) { \\\n        transform_param->set_scale(layer_param->scale()); \\\n        layer_param->clear_scale(); \\\n      } \\\n      if (layer_param->has_mean_file()) { \\\n        transform_param->set_mean_file(layer_param->mean_file()); \\\n        layer_param->clear_mean_file(); \\\n      } \\\n      if (layer_param->has_crop_size()) { \\\n        transform_param->set_crop_size(layer_param->crop_size()); \\\n        layer_param->clear_crop_size(); \\\n      } \\\n      if (layer_param->has_mirror()) { \\\n        transform_param->set_mirror(layer_param->mirror()); \\\n        layer_param->clear_mirror(); \\\n      } \\\n    } \\\n  } while (0)\n\nvoid UpgradeNetDataTransformation(NetParameter* net_param) {\n  for (int i = 0; i < net_param->layers_size(); ++i) {\n    CONVERT_LAYER_TRANSFORM_PARAM(DATA, Data, data);\n    CONVERT_LAYER_TRANSFORM_PARAM(IMAGE_DATA, ImageData, image_data);\n    CONVERT_LAYER_TRANSFORM_PARAM(WINDOW_DATA, WindowData, window_data);\n  }\n}\n\nbool UpgradeNetAsNeeded(const string& param_file, NetParameter* param) {\n  bool success = true;\n  if (NetNeedsV0ToV1Upgrade(*param)) {\n    // NetParameter was specified using the old style (V0LayerParameter); try to\n    // upgrade it.\n    LOG(INFO) << \"Attempting to upgrade input file specified using deprecated \"\n              << \"V0LayerParameter: \" << param_file;\n    NetParameter original_param(*param);\n    if (!UpgradeV0Net(original_param, param)) {\n      success = false;\n      LOG(ERROR) << \"Warning: had one or more problems upgrading \"\n          << \"V0NetParameter to NetParameter (see above); continuing anyway.\";\n    } else {\n      LOG(INFO) << \"Successfully upgraded file specified using deprecated \"\n                << \"V0LayerParameter\";\n    }\n    LOG(WARNING) << \"Note that future Caffe releases will not support \"\n        << \"V0NetParameter; use ./build/tools/upgrade_net_proto_text for \"\n        << \"prototxt and ./build/tools/upgrade_net_proto_binary for model \"\n        << \"weights upgrade this and any other net protos to the new format.\";\n  }\n  // NetParameter uses old style data transformation fields; try to upgrade it.\n  if (NetNeedsDataUpgrade(*param)) {\n    LOG(INFO) << \"Attempting to upgrade input file specified using deprecated \"\n              << \"transformation parameters: \" << param_file;\n    UpgradeNetDataTransformation(param);\n    LOG(INFO) << \"Successfully upgraded file specified using deprecated \"\n              << \"data transformation parameters.\";\n    LOG(WARNING) << \"Note that future Caffe releases will only support \"\n                 << \"transform_param messages for transformation fields.\";\n  }\n  if (NetNeedsV1ToV2Upgrade(*param)) {\n    LOG(INFO) << \"Attempting to upgrade input file specified using deprecated \"\n              << \"V1LayerParameter: \" << param_file;\n    NetParameter original_param(*param);\n    if (!UpgradeV1Net(original_param, param)) {\n      success = false;\n      LOG(ERROR) << \"Warning: had one or more problems upgrading \"\n                 << \"V1LayerParameter (see above); continuing anyway.\";\n    } else {\n      LOG(INFO) << \"Successfully upgraded file specified using deprecated \"\n                << \"V1LayerParameter\";\n    }\n  }\n  return success;\n}\n\nbool UpgradeV1Net(const NetParameter& v1_net_param, NetParameter* net_param) {\n  bool is_fully_compatible = true;\n  if (v1_net_param.layer_size() > 0) {\n    LOG(ERROR) << \"Input NetParameter to be upgraded already specifies 'layer' \"\n               << \"fields; these will be ignored for the upgrade.\";\n    is_fully_compatible = false;\n  }\n  net_param->CopyFrom(v1_net_param);\n  net_param->clear_layers();\n  net_param->clear_layer();\n  for (int i = 0; i < v1_net_param.layers_size(); ++i) {\n    if (!UpgradeV1LayerParameter(v1_net_param.layers(i),\n                                 net_param->add_layer())) {\n      LOG(ERROR) << \"Upgrade of input layer \" << i << \" failed.\";\n      is_fully_compatible = false;\n    }\n  }\n  return is_fully_compatible;\n}\n\nbool UpgradeV1LayerParameter(const V1LayerParameter& v1_layer_param,\n                             LayerParameter* layer_param) {\n  layer_param->Clear();\n  bool is_fully_compatible = true;\n  for (int i = 0; i < v1_layer_param.bottom_size(); ++i) {\n    layer_param->add_bottom(v1_layer_param.bottom(i));\n  }\n  for (int i = 0; i < v1_layer_param.top_size(); ++i) {\n    layer_param->add_top(v1_layer_param.top(i));\n  }\n  if (v1_layer_param.has_name()) {\n    layer_param->set_name(v1_layer_param.name());\n  }\n  for (int i = 0; i < v1_layer_param.include_size(); ++i) {\n    layer_param->add_include()->CopyFrom(v1_layer_param.include(i));\n  }\n  for (int i = 0; i < v1_layer_param.exclude_size(); ++i) {\n    layer_param->add_exclude()->CopyFrom(v1_layer_param.exclude(i));\n  }\n  if (v1_layer_param.has_type()) {\n    layer_param->set_type(UpgradeV1LayerType(v1_layer_param.type()));\n  }\n  for (int i = 0; i < v1_layer_param.blobs_size(); ++i) {\n    layer_param->add_blobs()->CopyFrom(v1_layer_param.blobs(i));\n  }\n  for (int i = 0; i < v1_layer_param.param_size(); ++i) {\n    while (layer_param->param_size() <= i) { layer_param->add_param(); }\n    layer_param->mutable_param(i)->set_name(v1_layer_param.param(i));\n  }\n  ParamSpec_DimCheckMode mode;\n  for (int i = 0; i < v1_layer_param.blob_share_mode_size(); ++i) {\n    while (layer_param->param_size() <= i) { layer_param->add_param(); }\n    switch (v1_layer_param.blob_share_mode(i)) {\n    case V1LayerParameter_DimCheckMode_STRICT:\n      mode = ParamSpec_DimCheckMode_STRICT;\n      break;\n    case V1LayerParameter_DimCheckMode_PERMISSIVE:\n      mode = ParamSpec_DimCheckMode_PERMISSIVE;\n      break;\n    default:\n      LOG(FATAL) << \"Unknown blob_share_mode: \"\n                 << v1_layer_param.blob_share_mode(i);\n      break;\n    }\n    layer_param->mutable_param(i)->set_share_mode(mode);\n  }\n  for (int i = 0; i < v1_layer_param.blobs_lr_size(); ++i) {\n    while (layer_param->param_size() <= i) { layer_param->add_param(); }\n    layer_param->mutable_param(i)->set_lr_mult(v1_layer_param.blobs_lr(i));\n  }\n  for (int i = 0; i < v1_layer_param.weight_decay_size(); ++i) {\n    while (layer_param->param_size() <= i) { layer_param->add_param(); }\n    layer_param->mutable_param(i)->set_decay_mult(\n        v1_layer_param.weight_decay(i));\n  }\n  for (int i = 0; i < v1_layer_param.loss_weight_size(); ++i) {\n    layer_param->add_loss_weight(v1_layer_param.loss_weight(i));\n  }\n  if (v1_layer_param.has_accuracy_param()) {\n    layer_param->mutable_accuracy_param()->CopyFrom(\n        v1_layer_param.accuracy_param());\n  }\n  if (v1_layer_param.has_argmax_param()) {\n    layer_param->mutable_argmax_param()->CopyFrom(\n        v1_layer_param.argmax_param());\n  }\n  if (v1_layer_param.has_concat_param()) {\n    layer_param->mutable_concat_param()->CopyFrom(\n        v1_layer_param.concat_param());\n  }\n  if (v1_layer_param.has_contrastive_loss_param()) {\n    layer_param->mutable_contrastive_loss_param()->CopyFrom(\n        v1_layer_param.contrastive_loss_param());\n  }\n  if (v1_layer_param.has_convolution_param()) {\n    layer_param->mutable_convolution_param()->CopyFrom(\n        v1_layer_param.convolution_param());\n  }\n  if (v1_layer_param.has_data_param()) {\n    layer_param->mutable_data_param()->CopyFrom(\n        v1_layer_param.data_param());\n  }\n  if (v1_layer_param.has_dropout_param()) {\n    layer_param->mutable_dropout_param()->CopyFrom(\n        v1_layer_param.dropout_param());\n  }\n  if (v1_layer_param.has_dummy_data_param()) {\n    layer_param->mutable_dummy_data_param()->CopyFrom(\n        v1_layer_param.dummy_data_param());\n  }\n  if (v1_layer_param.has_eltwise_param()) {\n    layer_param->mutable_eltwise_param()->CopyFrom(\n        v1_layer_param.eltwise_param());\n  }\n  if (v1_layer_param.has_exp_param()) {\n    layer_param->mutable_exp_param()->CopyFrom(\n        v1_layer_param.exp_param());\n  }\n  if (v1_layer_param.has_hdf5_data_param()) {\n    layer_param->mutable_hdf5_data_param()->CopyFrom(\n        v1_layer_param.hdf5_data_param());\n  }\n  if (v1_layer_param.has_hdf5_output_param()) {\n    layer_param->mutable_hdf5_output_param()->CopyFrom(\n        v1_layer_param.hdf5_output_param());\n  }\n  if (v1_layer_param.has_hinge_loss_param()) {\n    layer_param->mutable_hinge_loss_param()->CopyFrom(\n        v1_layer_param.hinge_loss_param());\n  }\n  if (v1_layer_param.has_image_data_param()) {\n    layer_param->mutable_image_data_param()->CopyFrom(\n        v1_layer_param.image_data_param());\n  }\n  if (v1_layer_param.has_infogain_loss_param()) {\n    layer_param->mutable_infogain_loss_param()->CopyFrom(\n        v1_layer_param.infogain_loss_param());\n  }\n  if (v1_layer_param.has_inner_product_param()) {\n    layer_param->mutable_inner_product_param()->CopyFrom(\n        v1_layer_param.inner_product_param());\n  }\n  if (v1_layer_param.has_lrn_param()) {\n    layer_param->mutable_lrn_param()->CopyFrom(\n        v1_layer_param.lrn_param());\n  }\n  if (v1_layer_param.has_memory_data_param()) {\n    layer_param->mutable_memory_data_param()->CopyFrom(\n        v1_layer_param.memory_data_param());\n  }\n  if (v1_layer_param.has_mvn_param()) {\n    layer_param->mutable_mvn_param()->CopyFrom(\n        v1_layer_param.mvn_param());\n  }\n  if (v1_layer_param.has_pooling_param()) {\n    layer_param->mutable_pooling_param()->CopyFrom(\n        v1_layer_param.pooling_param());\n  }\n  if (v1_layer_param.has_power_param()) {\n    layer_param->mutable_power_param()->CopyFrom(\n        v1_layer_param.power_param());\n  }\n  if (v1_layer_param.has_relu_param()) {\n    layer_param->mutable_relu_param()->CopyFrom(\n        v1_layer_param.relu_param());\n  }\n  if (v1_layer_param.has_sigmoid_param()) {\n    layer_param->mutable_sigmoid_param()->CopyFrom(\n        v1_layer_param.sigmoid_param());\n  }\n  if (v1_layer_param.has_softmax_param()) {\n    layer_param->mutable_softmax_param()->CopyFrom(\n        v1_layer_param.softmax_param());\n  }\n  if (v1_layer_param.has_slice_param()) {\n    layer_param->mutable_slice_param()->CopyFrom(\n        v1_layer_param.slice_param());\n  }\n  if (v1_layer_param.has_tanh_param()) {\n    layer_param->mutable_tanh_param()->CopyFrom(\n        v1_layer_param.tanh_param());\n  }\n  if (v1_layer_param.has_threshold_param()) {\n    layer_param->mutable_threshold_param()->CopyFrom(\n        v1_layer_param.threshold_param());\n  }\n  if (v1_layer_param.has_window_data_param()) {\n    layer_param->mutable_window_data_param()->CopyFrom(\n        v1_layer_param.window_data_param());\n  }\n  if (v1_layer_param.has_transform_param()) {\n    layer_param->mutable_transform_param()->CopyFrom(\n        v1_layer_param.transform_param());\n  }\n  if (v1_layer_param.has_loss_param()) {\n    layer_param->mutable_loss_param()->CopyFrom(\n        v1_layer_param.loss_param());\n  }\n  if (v1_layer_param.has_layer()) {\n    LOG(ERROR) << \"Input NetParameter has V0 layer -- ignoring.\";\n    is_fully_compatible = false;\n  }\n  return is_fully_compatible;\n}\n\nconst char* UpgradeV1LayerType(const V1LayerParameter_LayerType type) {\n  switch (type) {\n  case V1LayerParameter_LayerType_NONE:\n    return \"\";\n  case V1LayerParameter_LayerType_ABSVAL:\n    return \"AbsVal\";\n  case V1LayerParameter_LayerType_ACCURACY:\n    return \"Accuracy\";\n  case V1LayerParameter_LayerType_ARGMAX:\n    return \"ArgMax\";\n  case V1LayerParameter_LayerType_BNLL:\n    return \"BNLL\";\n  case V1LayerParameter_LayerType_CONCAT:\n    return \"Concat\";\n  case V1LayerParameter_LayerType_CONTRASTIVE_LOSS:\n    return \"ContrastiveLoss\";\n  case V1LayerParameter_LayerType_CONVOLUTION:\n    return \"Convolution\";\n  case V1LayerParameter_LayerType_DECONVOLUTION:\n    return \"Deconvolution\";\n  case V1LayerParameter_LayerType_DATA:\n    return \"Data\";\n  case V1LayerParameter_LayerType_DROPOUT:\n    return \"Dropout\";\n  case V1LayerParameter_LayerType_DUMMY_DATA:\n    return \"DummyData\";\n  case V1LayerParameter_LayerType_EUCLIDEAN_LOSS:\n    return \"EuclideanLoss\";\n  case V1LayerParameter_LayerType_ELTWISE:\n    return \"Eltwise\";\n  case V1LayerParameter_LayerType_EXP:\n    return \"Exp\";\n  case V1LayerParameter_LayerType_FLATTEN:\n    return \"Flatten\";\n  case V1LayerParameter_LayerType_HDF5_DATA:\n    return \"HDF5Data\";\n  case V1LayerParameter_LayerType_HDF5_OUTPUT:\n    return \"HDF5Output\";\n  case V1LayerParameter_LayerType_HINGE_LOSS:\n    return \"HingeLoss\";\n  case V1LayerParameter_LayerType_IM2COL:\n    return \"Im2col\";\n  case V1LayerParameter_LayerType_IMAGE_DATA:\n    return \"ImageData\";\n  case V1LayerParameter_LayerType_INFOGAIN_LOSS:\n    return \"InfogainLoss\";\n  case V1LayerParameter_LayerType_INNER_PRODUCT:\n    return \"InnerProduct\";\n  case V1LayerParameter_LayerType_LRN:\n    return \"LRN\";\n  case V1LayerParameter_LayerType_MEMORY_DATA:\n    return \"MemoryData\";\n  case V1LayerParameter_LayerType_MULTINOMIAL_LOGISTIC_LOSS:\n    return \"MultinomialLogisticLoss\";\n  case V1LayerParameter_LayerType_MVN:\n    return \"MVN\";\n  case V1LayerParameter_LayerType_POOLING:\n    return \"Pooling\";\n  case V1LayerParameter_LayerType_POWER:\n    return \"Power\";\n  case V1LayerParameter_LayerType_RELU:\n    return \"ReLU\";\n  case V1LayerParameter_LayerType_SIGMOID:\n    return \"Sigmoid\";\n  case V1LayerParameter_LayerType_SIGMOID_CROSS_ENTROPY_LOSS:\n    return \"SigmoidCrossEntropyLoss\";\n  case V1LayerParameter_LayerType_SILENCE:\n    return \"Silence\";\n  case V1LayerParameter_LayerType_SOFTMAX:\n    return \"Softmax\";\n  case V1LayerParameter_LayerType_SOFTMAX_LOSS:\n    return \"SoftmaxWithLoss\";\n  case V1LayerParameter_LayerType_SPLIT:\n    return \"Split\";\n  case V1LayerParameter_LayerType_SLICE:\n    return \"Slice\";\n  case V1LayerParameter_LayerType_TANH:\n    return \"TanH\";\n  case V1LayerParameter_LayerType_WINDOW_DATA:\n    return \"WindowData\";\n  case V1LayerParameter_LayerType_THRESHOLD:\n    return \"Threshold\";\n  default:\n    LOG(FATAL) << \"Unknown V1LayerParameter layer type: \" << type;\n    return \"\";\n  }\n}\n\nvoid ReadNetParamsFromTextFileOrDie(const string& param_file,\n                                    NetParameter* param) {\n  CHECK(ReadProtoFromTextFile(param_file, param))\n      << \"Failed to parse NetParameter file: \" << param_file;\n  UpgradeNetAsNeeded(param_file, param);\n}\n\nvoid ReadNetParamsFromBinaryFileOrDie(const string& param_file,\n                                      NetParameter* param) {\n  CHECK(ReadProtoFromBinaryFile(param_file, param))\n      << \"Failed to parse NetParameter file: \" << param_file;\n  UpgradeNetAsNeeded(param_file, param);\n}\n\n}  // namespace caffe\n"
  },
  {
    "path": "src/gtest/CMakeLists.txt",
    "content": "add_library(gtest STATIC EXCLUDE_FROM_ALL gtest.h gtest-all.cpp)\ncaffe_default_properties(gtest)\n\n#add_library(gtest_main gtest_main.cc)\n#target_link_libraries(gtest_main gtest)\n"
  },
  {
    "path": "src/gtest/gtest-all.cpp",
    "content": "// Copyright 2008, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: mheule@google.com (Markus Heule)\n//\n// Google C++ Testing Framework (Google Test)\n//\n// Sometimes it's desirable to build Google Test by compiling a single file.\n// This file serves this purpose.\n\n// This line ensures that gtest.h can be compiled on its own, even\n// when it's fused.\n#include \"gtest/gtest.h\"\n\n// The following lines pull in the real gtest *.cc files.\n// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n//\n// The Google C++ Testing Framework (Google Test)\n\n// Copyright 2007, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n//\n// Utilities for testing Google Test itself and code that uses Google Test\n// (e.g. frameworks built on top of Google Test).\n\n#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_\n#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_\n\n\nnamespace testing {\n\n// This helper class can be used to mock out Google Test failure reporting\n// so that we can test Google Test or code that builds on Google Test.\n//\n// An object of this class appends a TestPartResult object to the\n// TestPartResultArray object given in the constructor whenever a Google Test\n// failure is reported. It can either intercept only failures that are\n// generated in the same thread that created this object or it can intercept\n// all generated failures. The scope of this mock object can be controlled with\n// the second argument to the two arguments constructor.\nclass GTEST_API_ ScopedFakeTestPartResultReporter\n    : public TestPartResultReporterInterface {\n public:\n  // The two possible mocking modes of this object.\n  enum InterceptMode {\n    INTERCEPT_ONLY_CURRENT_THREAD,  // Intercepts only thread local failures.\n    INTERCEPT_ALL_THREADS           // Intercepts all failures.\n  };\n\n  // The c'tor sets this object as the test part result reporter used\n  // by Google Test.  The 'result' parameter specifies where to report the\n  // results. This reporter will only catch failures generated in the current\n  // thread. DEPRECATED\n  explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result);\n\n  // Same as above, but you can choose the interception scope of this object.\n  ScopedFakeTestPartResultReporter(InterceptMode intercept_mode,\n                                   TestPartResultArray* result);\n\n  // The d'tor restores the previous test part result reporter.\n  virtual ~ScopedFakeTestPartResultReporter();\n\n  // Appends the TestPartResult object to the TestPartResultArray\n  // received in the constructor.\n  //\n  // This method is from the TestPartResultReporterInterface\n  // interface.\n  virtual void ReportTestPartResult(const TestPartResult& result);\n private:\n  void Init();\n\n  const InterceptMode intercept_mode_;\n  TestPartResultReporterInterface* old_reporter_;\n  TestPartResultArray* const result_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);\n};\n\nnamespace internal {\n\n// A helper class for implementing EXPECT_FATAL_FAILURE() and\n// EXPECT_NONFATAL_FAILURE().  Its destructor verifies that the given\n// TestPartResultArray contains exactly one failure that has the given\n// type and contains the given substring.  If that's not the case, a\n// non-fatal failure will be generated.\nclass GTEST_API_ SingleFailureChecker {\n public:\n  // The constructor remembers the arguments.\n  SingleFailureChecker(const TestPartResultArray* results,\n                       TestPartResult::Type type,\n                       const string& substr);\n  ~SingleFailureChecker();\n private:\n  const TestPartResultArray* const results_;\n  const TestPartResult::Type type_;\n  const string substr_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);\n};\n\n}  // namespace internal\n\n}  // namespace testing\n\n// A set of macros for testing Google Test assertions or code that's expected\n// to generate Google Test fatal failures.  It verifies that the given\n// statement will cause exactly one fatal Google Test failure with 'substr'\n// being part of the failure message.\n//\n// There are two different versions of this macro. EXPECT_FATAL_FAILURE only\n// affects and considers failures generated in the current thread and\n// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.\n//\n// The verification of the assertion is done correctly even when the statement\n// throws an exception or aborts the current function.\n//\n// Known restrictions:\n//   - 'statement' cannot reference local non-static variables or\n//     non-static members of the current object.\n//   - 'statement' cannot return a value.\n//   - You cannot stream a failure message to this macro.\n//\n// Note that even though the implementations of the following two\n// macros are much alike, we cannot refactor them to use a common\n// helper macro, due to some peculiarity in how the preprocessor\n// works.  The AcceptsMacroThatExpandsToUnprotectedComma test in\n// gtest_unittest.cc will fail to compile if we do that.\n#define EXPECT_FATAL_FAILURE(statement, substr) \\\n  do { \\\n    class GTestExpectFatalFailureHelper {\\\n     public:\\\n      static void Execute() { statement; }\\\n    };\\\n    ::testing::TestPartResultArray gtest_failures;\\\n    ::testing::internal::SingleFailureChecker gtest_checker(\\\n        &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\\\n    {\\\n      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\\\n          ::testing::ScopedFakeTestPartResultReporter:: \\\n          INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\\\n      GTestExpectFatalFailureHelper::Execute();\\\n    }\\\n  } while (::testing::internal::AlwaysFalse())\n\n#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \\\n  do { \\\n    class GTestExpectFatalFailureHelper {\\\n     public:\\\n      static void Execute() { statement; }\\\n    };\\\n    ::testing::TestPartResultArray gtest_failures;\\\n    ::testing::internal::SingleFailureChecker gtest_checker(\\\n        &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\\\n    {\\\n      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\\\n          ::testing::ScopedFakeTestPartResultReporter:: \\\n          INTERCEPT_ALL_THREADS, &gtest_failures);\\\n      GTestExpectFatalFailureHelper::Execute();\\\n    }\\\n  } while (::testing::internal::AlwaysFalse())\n\n// A macro for testing Google Test assertions or code that's expected to\n// generate Google Test non-fatal failures.  It asserts that the given\n// statement will cause exactly one non-fatal Google Test failure with 'substr'\n// being part of the failure message.\n//\n// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only\n// affects and considers failures generated in the current thread and\n// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.\n//\n// 'statement' is allowed to reference local variables and members of\n// the current object.\n//\n// The verification of the assertion is done correctly even when the statement\n// throws an exception or aborts the current function.\n//\n// Known restrictions:\n//   - You cannot stream a failure message to this macro.\n//\n// Note that even though the implementations of the following two\n// macros are much alike, we cannot refactor them to use a common\n// helper macro, due to some peculiarity in how the preprocessor\n// works.  If we do that, the code won't compile when the user gives\n// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that\n// expands to code containing an unprotected comma.  The\n// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc\n// catches that.\n//\n// For the same reason, we have to write\n//   if (::testing::internal::AlwaysTrue()) { statement; }\n// instead of\n//   GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)\n// to avoid an MSVC warning on unreachable code.\n#define EXPECT_NONFATAL_FAILURE(statement, substr) \\\n  do {\\\n    ::testing::TestPartResultArray gtest_failures;\\\n    ::testing::internal::SingleFailureChecker gtest_checker(\\\n        &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \\\n        (substr));\\\n    {\\\n      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\\\n          ::testing::ScopedFakeTestPartResultReporter:: \\\n          INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\\\n      if (::testing::internal::AlwaysTrue()) { statement; }\\\n    }\\\n  } while (::testing::internal::AlwaysFalse())\n\n#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \\\n  do {\\\n    ::testing::TestPartResultArray gtest_failures;\\\n    ::testing::internal::SingleFailureChecker gtest_checker(\\\n        &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \\\n        (substr));\\\n    {\\\n      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\\\n          ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\\\n          &gtest_failures);\\\n      if (::testing::internal::AlwaysTrue()) { statement; }\\\n    }\\\n  } while (::testing::internal::AlwaysFalse())\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_SPI_H_\n\n#include <ctype.h>\n#include <math.h>\n#include <stdarg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <wchar.h>\n#include <wctype.h>\n\n#include <algorithm>\n#include <ostream>  // NOLINT\n#include <sstream>\n#include <vector>\n\n#if GTEST_OS_LINUX\n\n// TODO(kenton@google.com): Use autoconf to detect availability of\n// gettimeofday().\n# define GTEST_HAS_GETTIMEOFDAY_ 1\n\n# include <fcntl.h>  // NOLINT\n# include <limits.h>  // NOLINT\n# include <sched.h>  // NOLINT\n// Declares vsnprintf().  This header is not available on Windows.\n# include <strings.h>  // NOLINT\n# include <sys/mman.h>  // NOLINT\n# include <sys/time.h>  // NOLINT\n# include <unistd.h>  // NOLINT\n# include <string>\n\n#elif GTEST_OS_SYMBIAN\n# define GTEST_HAS_GETTIMEOFDAY_ 1\n# include <sys/time.h>  // NOLINT\n\n#elif GTEST_OS_ZOS\n# define GTEST_HAS_GETTIMEOFDAY_ 1\n# include <sys/time.h>  // NOLINT\n\n// On z/OS we additionally need strings.h for strcasecmp.\n# include <strings.h>  // NOLINT\n\n#elif GTEST_OS_WINDOWS_MOBILE  // We are on Windows CE.\n\n# include <windows.h>  // NOLINT\n\n#elif GTEST_OS_WINDOWS  // We are on Windows proper.\n\n# include <io.h>  // NOLINT\n# include <sys/timeb.h>  // NOLINT\n# include <sys/types.h>  // NOLINT\n# include <sys/stat.h>  // NOLINT\n\n# if GTEST_OS_WINDOWS_MINGW\n// MinGW has gettimeofday() but not _ftime64().\n// TODO(kenton@google.com): Use autoconf to detect availability of\n//   gettimeofday().\n// TODO(kenton@google.com): There are other ways to get the time on\n//   Windows, like GetTickCount() or GetSystemTimeAsFileTime().  MinGW\n//   supports these.  consider using them instead.\n#  define GTEST_HAS_GETTIMEOFDAY_ 1\n#  include <sys/time.h>  // NOLINT\n# endif  // GTEST_OS_WINDOWS_MINGW\n\n// cpplint thinks that the header is already included, so we want to\n// silence it.\n# include <windows.h>  // NOLINT\n\n#else\n\n// Assume other platforms have gettimeofday().\n// TODO(kenton@google.com): Use autoconf to detect availability of\n//   gettimeofday().\n# define GTEST_HAS_GETTIMEOFDAY_ 1\n\n// cpplint thinks that the header is already included, so we want to\n// silence it.\n# include <sys/time.h>  // NOLINT\n# include <unistd.h>  // NOLINT\n\n#endif  // GTEST_OS_LINUX\n\n#if GTEST_HAS_EXCEPTIONS\n# include <stdexcept>\n#endif\n\n#if GTEST_CAN_STREAM_RESULTS_\n# include <arpa/inet.h>  // NOLINT\n# include <netdb.h>  // NOLINT\n#endif\n\n// Indicates that this translation unit is part of Google Test's\n// implementation.  It must come before gtest-internal-inl.h is\n// included, or there will be a compiler error.  This trick is to\n// prevent a user from accidentally including gtest-internal-inl.h in\n// his code.\n#define GTEST_IMPLEMENTATION_ 1\n// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n// Utility functions and classes used by the Google C++ testing framework.\n//\n// Author: wan@google.com (Zhanyong Wan)\n//\n// This file contains purely Google Test's internal implementation.  Please\n// DO NOT #INCLUDE IT IN A USER PROGRAM.\n\n#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_\n#define GTEST_SRC_GTEST_INTERNAL_INL_H_\n\n// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is\n// part of Google Test's implementation; otherwise it's undefined.\n#if !GTEST_IMPLEMENTATION_\n// A user is trying to include this from his code - just say no.\n# error \"gtest-internal-inl.h is part of Google Test's internal implementation.\"\n# error \"It must not be included except by Google Test itself.\"\n#endif  // GTEST_IMPLEMENTATION_\n\n#ifndef _WIN32_WCE\n# include <errno.h>\n#endif  // !_WIN32_WCE\n#include <stddef.h>\n#include <stdlib.h>  // For strtoll/_strtoul64/malloc/free.\n#include <string.h>  // For memmove.\n\n#include <algorithm>\n#include <string>\n#include <vector>\n\n\n#if GTEST_OS_WINDOWS\n# include <windows.h>  // NOLINT\n#endif  // GTEST_OS_WINDOWS\n\n\nnamespace testing {\n\n// Declares the flags.\n//\n// We don't want the users to modify this flag in the code, but want\n// Google Test's own unit tests to be able to access it. Therefore we\n// declare it here as opposed to in gtest.h.\nGTEST_DECLARE_bool_(death_test_use_fork);\n\nnamespace internal {\n\n// The value of GetTestTypeId() as seen from within the Google Test\n// library.  This is solely for testing GetTestTypeId().\nGTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;\n\n// Names of the flags (needed for parsing Google Test flags).\nconst char kAlsoRunDisabledTestsFlag[] = \"also_run_disabled_tests\";\nconst char kBreakOnFailureFlag[] = \"break_on_failure\";\nconst char kCatchExceptionsFlag[] = \"catch_exceptions\";\nconst char kColorFlag[] = \"color\";\nconst char kFilterFlag[] = \"filter\";\nconst char kListTestsFlag[] = \"list_tests\";\nconst char kOutputFlag[] = \"output\";\nconst char kPrintTimeFlag[] = \"print_time\";\nconst char kRandomSeedFlag[] = \"random_seed\";\nconst char kRepeatFlag[] = \"repeat\";\nconst char kShuffleFlag[] = \"shuffle\";\nconst char kStackTraceDepthFlag[] = \"stack_trace_depth\";\nconst char kStreamResultToFlag[] = \"stream_result_to\";\nconst char kThrowOnFailureFlag[] = \"throw_on_failure\";\n\n// A valid random seed must be in [1, kMaxRandomSeed].\nconst int kMaxRandomSeed = 99999;\n\n// g_help_flag is true iff the --help flag or an equivalent form is\n// specified on the command line.\nGTEST_API_ extern bool g_help_flag;\n\n// Returns the current time in milliseconds.\nGTEST_API_ TimeInMillis GetTimeInMillis();\n\n// Returns true iff Google Test should use colors in the output.\nGTEST_API_ bool ShouldUseColor(bool stdout_is_tty);\n\n// Formats the given time in milliseconds as seconds.\nGTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);\n\n// Parses a string for an Int32 flag, in the form of \"--flag=value\".\n//\n// On success, stores the value of the flag in *value, and returns\n// true.  On failure, returns false without changing *value.\nGTEST_API_ bool ParseInt32Flag(\n    const char* str, const char* flag, Int32* value);\n\n// Returns a random seed in range [1, kMaxRandomSeed] based on the\n// given --gtest_random_seed flag value.\ninline int GetRandomSeedFromFlag(Int32 random_seed_flag) {\n  const unsigned int raw_seed = (random_seed_flag == 0) ?\n      static_cast<unsigned int>(GetTimeInMillis()) :\n      static_cast<unsigned int>(random_seed_flag);\n\n  // Normalizes the actual seed to range [1, kMaxRandomSeed] such that\n  // it's easy to type.\n  const int normalized_seed =\n      static_cast<int>((raw_seed - 1U) %\n                       static_cast<unsigned int>(kMaxRandomSeed)) + 1;\n  return normalized_seed;\n}\n\n// Returns the first valid random seed after 'seed'.  The behavior is\n// undefined if 'seed' is invalid.  The seed after kMaxRandomSeed is\n// considered to be 1.\ninline int GetNextRandomSeed(int seed) {\n  GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)\n      << \"Invalid random seed \" << seed << \" - must be in [1, \"\n      << kMaxRandomSeed << \"].\";\n  const int next_seed = seed + 1;\n  return (next_seed > kMaxRandomSeed) ? 1 : next_seed;\n}\n\n// This class saves the values of all Google Test flags in its c'tor, and\n// restores them in its d'tor.\nclass GTestFlagSaver {\n public:\n  // The c'tor.\n  GTestFlagSaver() {\n    also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);\n    break_on_failure_ = GTEST_FLAG(break_on_failure);\n    catch_exceptions_ = GTEST_FLAG(catch_exceptions);\n    color_ = GTEST_FLAG(color);\n    death_test_style_ = GTEST_FLAG(death_test_style);\n    death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);\n    filter_ = GTEST_FLAG(filter);\n    internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);\n    list_tests_ = GTEST_FLAG(list_tests);\n    output_ = GTEST_FLAG(output);\n    print_time_ = GTEST_FLAG(print_time);\n    random_seed_ = GTEST_FLAG(random_seed);\n    repeat_ = GTEST_FLAG(repeat);\n    shuffle_ = GTEST_FLAG(shuffle);\n    stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);\n    stream_result_to_ = GTEST_FLAG(stream_result_to);\n    throw_on_failure_ = GTEST_FLAG(throw_on_failure);\n  }\n\n  // The d'tor is not virtual.  DO NOT INHERIT FROM THIS CLASS.\n  ~GTestFlagSaver() {\n    GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;\n    GTEST_FLAG(break_on_failure) = break_on_failure_;\n    GTEST_FLAG(catch_exceptions) = catch_exceptions_;\n    GTEST_FLAG(color) = color_;\n    GTEST_FLAG(death_test_style) = death_test_style_;\n    GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;\n    GTEST_FLAG(filter) = filter_;\n    GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;\n    GTEST_FLAG(list_tests) = list_tests_;\n    GTEST_FLAG(output) = output_;\n    GTEST_FLAG(print_time) = print_time_;\n    GTEST_FLAG(random_seed) = random_seed_;\n    GTEST_FLAG(repeat) = repeat_;\n    GTEST_FLAG(shuffle) = shuffle_;\n    GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;\n    GTEST_FLAG(stream_result_to) = stream_result_to_;\n    GTEST_FLAG(throw_on_failure) = throw_on_failure_;\n  }\n private:\n  // Fields for saving the original values of flags.\n  bool also_run_disabled_tests_;\n  bool break_on_failure_;\n  bool catch_exceptions_;\n  String color_;\n  String death_test_style_;\n  bool death_test_use_fork_;\n  String filter_;\n  String internal_run_death_test_;\n  bool list_tests_;\n  String output_;\n  bool print_time_;\n  internal::Int32 random_seed_;\n  internal::Int32 repeat_;\n  bool shuffle_;\n  internal::Int32 stack_trace_depth_;\n  String stream_result_to_;\n  bool throw_on_failure_;\n} GTEST_ATTRIBUTE_UNUSED_;\n\n// Converts a Unicode code point to a narrow string in UTF-8 encoding.\n// code_point parameter is of type UInt32 because wchar_t may not be\n// wide enough to contain a code point.\n// The output buffer str must containt at least 32 characters.\n// The function returns the address of the output buffer.\n// If the code_point is not a valid Unicode code point\n// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be output\n// as '(Invalid Unicode 0xXXXXXXXX)'.\nGTEST_API_ char* CodePointToUtf8(UInt32 code_point, char* str);\n\n// Converts a wide string to a narrow string in UTF-8 encoding.\n// The wide string is assumed to have the following encoding:\n//   UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)\n//   UTF-32 if sizeof(wchar_t) == 4 (on Linux)\n// Parameter str points to a null-terminated wide string.\n// Parameter num_chars may additionally limit the number\n// of wchar_t characters processed. -1 is used when the entire string\n// should be processed.\n// If the string contains code points that are not valid Unicode code points\n// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output\n// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding\n// and contains invalid UTF-16 surrogate pairs, values in those pairs\n// will be encoded as individual Unicode characters from Basic Normal Plane.\nGTEST_API_ String WideStringToUtf8(const wchar_t* str, int num_chars);\n\n// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file\n// if the variable is present. If a file already exists at this location, this\n// function will write over it. If the variable is present, but the file cannot\n// be created, prints an error and exits.\nvoid WriteToShardStatusFileIfNeeded();\n\n// Checks whether sharding is enabled by examining the relevant\n// environment variable values. If the variables are present,\n// but inconsistent (e.g., shard_index >= total_shards), prints\n// an error and exits. If in_subprocess_for_death_test, sharding is\n// disabled because it must only be applied to the original test\n// process. Otherwise, we could filter out death tests we intended to execute.\nGTEST_API_ bool ShouldShard(const char* total_shards_str,\n                            const char* shard_index_str,\n                            bool in_subprocess_for_death_test);\n\n// Parses the environment variable var as an Int32. If it is unset,\n// returns default_val. If it is not an Int32, prints an error and\n// and aborts.\nGTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);\n\n// Given the total number of shards, the shard index, and the test id,\n// returns true iff the test should be run on this shard. The test id is\n// some arbitrary but unique non-negative integer assigned to each test\n// method. Assumes that 0 <= shard_index < total_shards.\nGTEST_API_ bool ShouldRunTestOnShard(\n    int total_shards, int shard_index, int test_id);\n\n// STL container utilities.\n\n// Returns the number of elements in the given container that satisfy\n// the given predicate.\ntemplate <class Container, typename Predicate>\ninline int CountIf(const Container& c, Predicate predicate) {\n  // Implemented as an explicit loop since std::count_if() in libCstd on\n  // Solaris has a non-standard signature.\n  int count = 0;\n  for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {\n    if (predicate(*it))\n      ++count;\n  }\n  return count;\n}\n\n// Applies a function/functor to each element in the container.\ntemplate <class Container, typename Functor>\nvoid ForEach(const Container& c, Functor functor) {\n  std::for_each(c.begin(), c.end(), functor);\n}\n\n// Returns the i-th element of the vector, or default_value if i is not\n// in range [0, v.size()).\ntemplate <typename E>\ninline E GetElementOr(const std::vector<E>& v, int i, E default_value) {\n  return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];\n}\n\n// Performs an in-place shuffle of a range of the vector's elements.\n// 'begin' and 'end' are element indices as an STL-style range;\n// i.e. [begin, end) are shuffled, where 'end' == size() means to\n// shuffle to the end of the vector.\ntemplate <typename E>\nvoid ShuffleRange(internal::Random* random, int begin, int end,\n                  std::vector<E>* v) {\n  const int size = static_cast<int>(v->size());\n  GTEST_CHECK_(0 <= begin && begin <= size)\n      << \"Invalid shuffle range start \" << begin << \": must be in range [0, \"\n      << size << \"].\";\n  GTEST_CHECK_(begin <= end && end <= size)\n      << \"Invalid shuffle range finish \" << end << \": must be in range [\"\n      << begin << \", \" << size << \"].\";\n\n  // Fisher-Yates shuffle, from\n  // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle\n  for (int range_width = end - begin; range_width >= 2; range_width--) {\n    const int last_in_range = begin + range_width - 1;\n    const int selected = begin + random->Generate(range_width);\n    std::swap((*v)[selected], (*v)[last_in_range]);\n  }\n}\n\n// Performs an in-place shuffle of the vector's elements.\ntemplate <typename E>\ninline void Shuffle(internal::Random* random, std::vector<E>* v) {\n  ShuffleRange(random, 0, static_cast<int>(v->size()), v);\n}\n\n// A function for deleting an object.  Handy for being used as a\n// functor.\ntemplate <typename T>\nstatic void Delete(T* x) {\n  delete x;\n}\n\n// A predicate that checks the key of a TestProperty against a known key.\n//\n// TestPropertyKeyIs is copyable.\nclass TestPropertyKeyIs {\n public:\n  // Constructor.\n  //\n  // TestPropertyKeyIs has NO default constructor.\n  explicit TestPropertyKeyIs(const char* key)\n      : key_(key) {}\n\n  // Returns true iff the test name of test property matches on key_.\n  bool operator()(const TestProperty& test_property) const {\n    return String(test_property.key()).Compare(key_) == 0;\n  }\n\n private:\n  String key_;\n};\n\n// Class UnitTestOptions.\n//\n// This class contains functions for processing options the user\n// specifies when running the tests.  It has only static members.\n//\n// In most cases, the user can specify an option using either an\n// environment variable or a command line flag.  E.g. you can set the\n// test filter using either GTEST_FILTER or --gtest_filter.  If both\n// the variable and the flag are present, the latter overrides the\n// former.\nclass GTEST_API_ UnitTestOptions {\n public:\n  // Functions for processing the gtest_output flag.\n\n  // Returns the output format, or \"\" for normal printed output.\n  static String GetOutputFormat();\n\n  // Returns the absolute path of the requested output file, or the\n  // default (test_detail.xml in the original working directory) if\n  // none was explicitly specified.\n  static String GetAbsolutePathToOutputFile();\n\n  // Functions for processing the gtest_filter flag.\n\n  // Returns true iff the wildcard pattern matches the string.  The\n  // first ':' or '\\0' character in pattern marks the end of it.\n  //\n  // This recursive algorithm isn't very efficient, but is clear and\n  // works well enough for matching test names, which are short.\n  static bool PatternMatchesString(const char *pattern, const char *str);\n\n  // Returns true iff the user-specified filter matches the test case\n  // name and the test name.\n  static bool FilterMatchesTest(const String &test_case_name,\n                                const String &test_name);\n\n#if GTEST_OS_WINDOWS\n  // Function for supporting the gtest_catch_exception flag.\n\n  // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the\n  // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.\n  // This function is useful as an __except condition.\n  static int GTestShouldProcessSEH(DWORD exception_code);\n#endif  // GTEST_OS_WINDOWS\n\n  // Returns true if \"name\" matches the ':' separated list of glob-style\n  // filters in \"filter\".\n  static bool MatchesFilter(const String& name, const char* filter);\n};\n\n// Returns the current application's name, removing directory path if that\n// is present.  Used by UnitTestOptions::GetOutputFile.\nGTEST_API_ FilePath GetCurrentExecutableName();\n\n// The role interface for getting the OS stack trace as a string.\nclass OsStackTraceGetterInterface {\n public:\n  OsStackTraceGetterInterface() {}\n  virtual ~OsStackTraceGetterInterface() {}\n\n  // Returns the current OS stack trace as a String.  Parameters:\n  //\n  //   max_depth  - the maximum number of stack frames to be included\n  //                in the trace.\n  //   skip_count - the number of top frames to be skipped; doesn't count\n  //                against max_depth.\n  virtual String CurrentStackTrace(int max_depth, int skip_count) = 0;\n\n  // UponLeavingGTest() should be called immediately before Google Test calls\n  // user code. It saves some information about the current stack that\n  // CurrentStackTrace() will use to find and hide Google Test stack frames.\n  virtual void UponLeavingGTest() = 0;\n\n private:\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);\n};\n\n// A working implementation of the OsStackTraceGetterInterface interface.\nclass OsStackTraceGetter : public OsStackTraceGetterInterface {\n public:\n  OsStackTraceGetter() : caller_frame_(NULL) {}\n  virtual String CurrentStackTrace(int max_depth, int skip_count);\n  virtual void UponLeavingGTest();\n\n  // This string is inserted in place of stack frames that are part of\n  // Google Test's implementation.\n  static const char* const kElidedFramesMarker;\n\n private:\n  Mutex mutex_;  // protects all internal state\n\n  // We save the stack frame below the frame that calls user code.\n  // We do this because the address of the frame immediately below\n  // the user code changes between the call to UponLeavingGTest()\n  // and any calls to CurrentStackTrace() from within the user code.\n  void* caller_frame_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);\n};\n\n// Information about a Google Test trace point.\nstruct TraceInfo {\n  const char* file;\n  int line;\n  String message;\n};\n\n// This is the default global test part result reporter used in UnitTestImpl.\n// This class should only be used by UnitTestImpl.\nclass DefaultGlobalTestPartResultReporter\n  : public TestPartResultReporterInterface {\n public:\n  explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);\n  // Implements the TestPartResultReporterInterface. Reports the test part\n  // result in the current test.\n  virtual void ReportTestPartResult(const TestPartResult& result);\n\n private:\n  UnitTestImpl* const unit_test_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);\n};\n\n// This is the default per thread test part result reporter used in\n// UnitTestImpl. This class should only be used by UnitTestImpl.\nclass DefaultPerThreadTestPartResultReporter\n    : public TestPartResultReporterInterface {\n public:\n  explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);\n  // Implements the TestPartResultReporterInterface. The implementation just\n  // delegates to the current global test part result reporter of *unit_test_.\n  virtual void ReportTestPartResult(const TestPartResult& result);\n\n private:\n  UnitTestImpl* const unit_test_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);\n};\n\n// The private implementation of the UnitTest class.  We don't protect\n// the methods under a mutex, as this class is not accessible by a\n// user and the UnitTest class that delegates work to this class does\n// proper locking.\nclass GTEST_API_ UnitTestImpl {\n public:\n  explicit UnitTestImpl(UnitTest* parent);\n  virtual ~UnitTestImpl();\n\n  // There are two different ways to register your own TestPartResultReporter.\n  // You can register your own repoter to listen either only for test results\n  // from the current thread or for results from all threads.\n  // By default, each per-thread test result repoter just passes a new\n  // TestPartResult to the global test result reporter, which registers the\n  // test part result for the currently running test.\n\n  // Returns the global test part result reporter.\n  TestPartResultReporterInterface* GetGlobalTestPartResultReporter();\n\n  // Sets the global test part result reporter.\n  void SetGlobalTestPartResultReporter(\n      TestPartResultReporterInterface* reporter);\n\n  // Returns the test part result reporter for the current thread.\n  TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();\n\n  // Sets the test part result reporter for the current thread.\n  void SetTestPartResultReporterForCurrentThread(\n      TestPartResultReporterInterface* reporter);\n\n  // Gets the number of successful test cases.\n  int successful_test_case_count() const;\n\n  // Gets the number of failed test cases.\n  int failed_test_case_count() const;\n\n  // Gets the number of all test cases.\n  int total_test_case_count() const;\n\n  // Gets the number of all test cases that contain at least one test\n  // that should run.\n  int test_case_to_run_count() const;\n\n  // Gets the number of successful tests.\n  int successful_test_count() const;\n\n  // Gets the number of failed tests.\n  int failed_test_count() const;\n\n  // Gets the number of disabled tests.\n  int disabled_test_count() const;\n\n  // Gets the number of all tests.\n  int total_test_count() const;\n\n  // Gets the number of tests that should run.\n  int test_to_run_count() const;\n\n  // Gets the elapsed time, in milliseconds.\n  TimeInMillis elapsed_time() const { return elapsed_time_; }\n\n  // Returns true iff the unit test passed (i.e. all test cases passed).\n  bool Passed() const { return !Failed(); }\n\n  // Returns true iff the unit test failed (i.e. some test case failed\n  // or something outside of all tests failed).\n  bool Failed() const {\n    return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();\n  }\n\n  // Gets the i-th test case among all the test cases. i can range from 0 to\n  // total_test_case_count() - 1. If i is not in that range, returns NULL.\n  const TestCase* GetTestCase(int i) const {\n    const int index = GetElementOr(test_case_indices_, i, -1);\n    return index < 0 ? NULL : test_cases_[i];\n  }\n\n  // Gets the i-th test case among all the test cases. i can range from 0 to\n  // total_test_case_count() - 1. If i is not in that range, returns NULL.\n  TestCase* GetMutableTestCase(int i) {\n    const int index = GetElementOr(test_case_indices_, i, -1);\n    return index < 0 ? NULL : test_cases_[index];\n  }\n\n  // Provides access to the event listener list.\n  TestEventListeners* listeners() { return &listeners_; }\n\n  // Returns the TestResult for the test that's currently running, or\n  // the TestResult for the ad hoc test if no test is running.\n  TestResult* current_test_result();\n\n  // Returns the TestResult for the ad hoc test.\n  const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }\n\n  // Sets the OS stack trace getter.\n  //\n  // Does nothing if the input and the current OS stack trace getter\n  // are the same; otherwise, deletes the old getter and makes the\n  // input the current getter.\n  void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);\n\n  // Returns the current OS stack trace getter if it is not NULL;\n  // otherwise, creates an OsStackTraceGetter, makes it the current\n  // getter, and returns it.\n  OsStackTraceGetterInterface* os_stack_trace_getter();\n\n  // Returns the current OS stack trace as a String.\n  //\n  // The maximum number of stack frames to be included is specified by\n  // the gtest_stack_trace_depth flag.  The skip_count parameter\n  // specifies the number of top frames to be skipped, which doesn't\n  // count against the number of frames to be included.\n  //\n  // For example, if Foo() calls Bar(), which in turn calls\n  // CurrentOsStackTraceExceptTop(1), Foo() will be included in the\n  // trace but Bar() and CurrentOsStackTraceExceptTop() won't.\n  String CurrentOsStackTraceExceptTop(int skip_count);\n\n  // Finds and returns a TestCase with the given name.  If one doesn't\n  // exist, creates one and returns it.\n  //\n  // Arguments:\n  //\n  //   test_case_name: name of the test case\n  //   type_param:     the name of the test's type parameter, or NULL if\n  //                   this is not a typed or a type-parameterized test.\n  //   set_up_tc:      pointer to the function that sets up the test case\n  //   tear_down_tc:   pointer to the function that tears down the test case\n  TestCase* GetTestCase(const char* test_case_name,\n                        const char* type_param,\n                        Test::SetUpTestCaseFunc set_up_tc,\n                        Test::TearDownTestCaseFunc tear_down_tc);\n\n  // Adds a TestInfo to the unit test.\n  //\n  // Arguments:\n  //\n  //   set_up_tc:    pointer to the function that sets up the test case\n  //   tear_down_tc: pointer to the function that tears down the test case\n  //   test_info:    the TestInfo object\n  void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,\n                   Test::TearDownTestCaseFunc tear_down_tc,\n                   TestInfo* test_info) {\n    // In order to support thread-safe death tests, we need to\n    // remember the original working directory when the test program\n    // was first invoked.  We cannot do this in RUN_ALL_TESTS(), as\n    // the user may have changed the current directory before calling\n    // RUN_ALL_TESTS().  Therefore we capture the current directory in\n    // AddTestInfo(), which is called to register a TEST or TEST_F\n    // before main() is reached.\n    if (original_working_dir_.IsEmpty()) {\n      original_working_dir_.Set(FilePath::GetCurrentDir());\n      GTEST_CHECK_(!original_working_dir_.IsEmpty())\n          << \"Failed to get the current working directory.\";\n    }\n\n    GetTestCase(test_info->test_case_name(),\n                test_info->type_param(),\n                set_up_tc,\n                tear_down_tc)->AddTestInfo(test_info);\n  }\n\n#if GTEST_HAS_PARAM_TEST\n  // Returns ParameterizedTestCaseRegistry object used to keep track of\n  // value-parameterized tests and instantiate and register them.\n  internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {\n    return parameterized_test_registry_;\n  }\n#endif  // GTEST_HAS_PARAM_TEST\n\n  // Sets the TestCase object for the test that's currently running.\n  void set_current_test_case(TestCase* a_current_test_case) {\n    current_test_case_ = a_current_test_case;\n  }\n\n  // Sets the TestInfo object for the test that's currently running.  If\n  // current_test_info is NULL, the assertion results will be stored in\n  // ad_hoc_test_result_.\n  void set_current_test_info(TestInfo* a_current_test_info) {\n    current_test_info_ = a_current_test_info;\n  }\n\n  // Registers all parameterized tests defined using TEST_P and\n  // INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter\n  // combination. This method can be called more then once; it has guards\n  // protecting from registering the tests more then once.  If\n  // value-parameterized tests are disabled, RegisterParameterizedTests is\n  // present but does nothing.\n  void RegisterParameterizedTests();\n\n  // Runs all tests in this UnitTest object, prints the result, and\n  // returns true if all tests are successful.  If any exception is\n  // thrown during a test, this test is considered to be failed, but\n  // the rest of the tests will still be run.\n  bool RunAllTests();\n\n  // Clears the results of all tests, except the ad hoc tests.\n  void ClearNonAdHocTestResult() {\n    ForEach(test_cases_, TestCase::ClearTestCaseResult);\n  }\n\n  // Clears the results of ad-hoc test assertions.\n  void ClearAdHocTestResult() {\n    ad_hoc_test_result_.Clear();\n  }\n\n  enum ReactionToSharding {\n    HONOR_SHARDING_PROTOCOL,\n    IGNORE_SHARDING_PROTOCOL\n  };\n\n  // Matches the full name of each test against the user-specified\n  // filter to decide whether the test should run, then records the\n  // result in each TestCase and TestInfo object.\n  // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests\n  // based on sharding variables in the environment.\n  // Returns the number of tests that should run.\n  int FilterTests(ReactionToSharding shard_tests);\n\n  // Prints the names of the tests matching the user-specified filter flag.\n  void ListTestsMatchingFilter();\n\n  const TestCase* current_test_case() const { return current_test_case_; }\n  TestInfo* current_test_info() { return current_test_info_; }\n  const TestInfo* current_test_info() const { return current_test_info_; }\n\n  // Returns the vector of environments that need to be set-up/torn-down\n  // before/after the tests are run.\n  std::vector<Environment*>& environments() { return environments_; }\n\n  // Getters for the per-thread Google Test trace stack.\n  std::vector<TraceInfo>& gtest_trace_stack() {\n    return *(gtest_trace_stack_.pointer());\n  }\n  const std::vector<TraceInfo>& gtest_trace_stack() const {\n    return gtest_trace_stack_.get();\n  }\n\n#if GTEST_HAS_DEATH_TEST\n  void InitDeathTestSubprocessControlInfo() {\n    internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());\n  }\n  // Returns a pointer to the parsed --gtest_internal_run_death_test\n  // flag, or NULL if that flag was not specified.\n  // This information is useful only in a death test child process.\n  // Must not be called before a call to InitGoogleTest.\n  const InternalRunDeathTestFlag* internal_run_death_test_flag() const {\n    return internal_run_death_test_flag_.get();\n  }\n\n  // Returns a pointer to the current death test factory.\n  internal::DeathTestFactory* death_test_factory() {\n    return death_test_factory_.get();\n  }\n\n  void SuppressTestEventsIfInSubprocess();\n\n  friend class ReplaceDeathTestFactory;\n#endif  // GTEST_HAS_DEATH_TEST\n\n  // Initializes the event listener performing XML output as specified by\n  // UnitTestOptions. Must not be called before InitGoogleTest.\n  void ConfigureXmlOutput();\n\n#if GTEST_CAN_STREAM_RESULTS_\n  // Initializes the event listener for streaming test results to a socket.\n  // Must not be called before InitGoogleTest.\n  void ConfigureStreamingOutput();\n#endif\n\n  // Performs initialization dependent upon flag values obtained in\n  // ParseGoogleTestFlagsOnly.  Is called from InitGoogleTest after the call to\n  // ParseGoogleTestFlagsOnly.  In case a user neglects to call InitGoogleTest\n  // this function is also called from RunAllTests.  Since this function can be\n  // called more than once, it has to be idempotent.\n  void PostFlagParsingInit();\n\n  // Gets the random seed used at the start of the current test iteration.\n  int random_seed() const { return random_seed_; }\n\n  // Gets the random number generator.\n  internal::Random* random() { return &random_; }\n\n  // Shuffles all test cases, and the tests within each test case,\n  // making sure that death tests are still run first.\n  void ShuffleTests();\n\n  // Restores the test cases and tests to their order before the first shuffle.\n  void UnshuffleTests();\n\n  // Returns the value of GTEST_FLAG(catch_exceptions) at the moment\n  // UnitTest::Run() starts.\n  bool catch_exceptions() const { return catch_exceptions_; }\n\n private:\n  friend class ::testing::UnitTest;\n\n  // Used by UnitTest::Run() to capture the state of\n  // GTEST_FLAG(catch_exceptions) at the moment it starts.\n  void set_catch_exceptions(bool value) { catch_exceptions_ = value; }\n\n  // The UnitTest object that owns this implementation object.\n  UnitTest* const parent_;\n\n  // The working directory when the first TEST() or TEST_F() was\n  // executed.\n  internal::FilePath original_working_dir_;\n\n  // The default test part result reporters.\n  DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;\n  DefaultPerThreadTestPartResultReporter\n      default_per_thread_test_part_result_reporter_;\n\n  // Points to (but doesn't own) the global test part result reporter.\n  TestPartResultReporterInterface* global_test_part_result_repoter_;\n\n  // Protects read and write access to global_test_part_result_reporter_.\n  internal::Mutex global_test_part_result_reporter_mutex_;\n\n  // Points to (but doesn't own) the per-thread test part result reporter.\n  internal::ThreadLocal<TestPartResultReporterInterface*>\n      per_thread_test_part_result_reporter_;\n\n  // The vector of environments that need to be set-up/torn-down\n  // before/after the tests are run.\n  std::vector<Environment*> environments_;\n\n  // The vector of TestCases in their original order.  It owns the\n  // elements in the vector.\n  std::vector<TestCase*> test_cases_;\n\n  // Provides a level of indirection for the test case list to allow\n  // easy shuffling and restoring the test case order.  The i-th\n  // element of this vector is the index of the i-th test case in the\n  // shuffled order.\n  std::vector<int> test_case_indices_;\n\n#if GTEST_HAS_PARAM_TEST\n  // ParameterizedTestRegistry object used to register value-parameterized\n  // tests.\n  internal::ParameterizedTestCaseRegistry parameterized_test_registry_;\n\n  // Indicates whether RegisterParameterizedTests() has been called already.\n  bool parameterized_tests_registered_;\n#endif  // GTEST_HAS_PARAM_TEST\n\n  // Index of the last death test case registered.  Initially -1.\n  int last_death_test_case_;\n\n  // This points to the TestCase for the currently running test.  It\n  // changes as Google Test goes through one test case after another.\n  // When no test is running, this is set to NULL and Google Test\n  // stores assertion results in ad_hoc_test_result_.  Initially NULL.\n  TestCase* current_test_case_;\n\n  // This points to the TestInfo for the currently running test.  It\n  // changes as Google Test goes through one test after another.  When\n  // no test is running, this is set to NULL and Google Test stores\n  // assertion results in ad_hoc_test_result_.  Initially NULL.\n  TestInfo* current_test_info_;\n\n  // Normally, a user only writes assertions inside a TEST or TEST_F,\n  // or inside a function called by a TEST or TEST_F.  Since Google\n  // Test keeps track of which test is current running, it can\n  // associate such an assertion with the test it belongs to.\n  //\n  // If an assertion is encountered when no TEST or TEST_F is running,\n  // Google Test attributes the assertion result to an imaginary \"ad hoc\"\n  // test, and records the result in ad_hoc_test_result_.\n  TestResult ad_hoc_test_result_;\n\n  // The list of event listeners that can be used to track events inside\n  // Google Test.\n  TestEventListeners listeners_;\n\n  // The OS stack trace getter.  Will be deleted when the UnitTest\n  // object is destructed.  By default, an OsStackTraceGetter is used,\n  // but the user can set this field to use a custom getter if that is\n  // desired.\n  OsStackTraceGetterInterface* os_stack_trace_getter_;\n\n  // True iff PostFlagParsingInit() has been called.\n  bool post_flag_parse_init_performed_;\n\n  // The random number seed used at the beginning of the test run.\n  int random_seed_;\n\n  // Our random number generator.\n  internal::Random random_;\n\n  // How long the test took to run, in milliseconds.\n  TimeInMillis elapsed_time_;\n\n#if GTEST_HAS_DEATH_TEST\n  // The decomposed components of the gtest_internal_run_death_test flag,\n  // parsed when RUN_ALL_TESTS is called.\n  internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;\n  internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;\n#endif  // GTEST_HAS_DEATH_TEST\n\n  // A per-thread stack of traces created by the SCOPED_TRACE() macro.\n  internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;\n\n  // The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()\n  // starts.\n  bool catch_exceptions_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);\n};  // class UnitTestImpl\n\n// Convenience function for accessing the global UnitTest\n// implementation object.\ninline UnitTestImpl* GetUnitTestImpl() {\n  return UnitTest::GetInstance()->impl();\n}\n\n#if GTEST_USES_SIMPLE_RE\n\n// Internal helper functions for implementing the simple regular\n// expression matcher.\nGTEST_API_ bool IsInSet(char ch, const char* str);\nGTEST_API_ bool IsAsciiDigit(char ch);\nGTEST_API_ bool IsAsciiPunct(char ch);\nGTEST_API_ bool IsRepeat(char ch);\nGTEST_API_ bool IsAsciiWhiteSpace(char ch);\nGTEST_API_ bool IsAsciiWordChar(char ch);\nGTEST_API_ bool IsValidEscape(char ch);\nGTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);\nGTEST_API_ bool ValidateRegex(const char* regex);\nGTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);\nGTEST_API_ bool MatchRepetitionAndRegexAtHead(\n    bool escaped, char ch, char repeat, const char* regex, const char* str);\nGTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);\n\n#endif  // GTEST_USES_SIMPLE_RE\n\n// Parses the command line for Google Test flags, without initializing\n// other parts of Google Test.\nGTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);\nGTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);\n\n#if GTEST_HAS_DEATH_TEST\n\n// Returns the message describing the last system error, regardless of the\n// platform.\nGTEST_API_ String GetLastErrnoDescription();\n\n# if GTEST_OS_WINDOWS\n// Provides leak-safe Windows kernel handle ownership.\nclass AutoHandle {\n public:\n  AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}\n  explicit AutoHandle(HANDLE handle) : handle_(handle) {}\n\n  ~AutoHandle() { Reset(); }\n\n  HANDLE Get() const { return handle_; }\n  void Reset() { Reset(INVALID_HANDLE_VALUE); }\n  void Reset(HANDLE handle) {\n    if (handle != handle_) {\n      if (handle_ != INVALID_HANDLE_VALUE)\n        ::CloseHandle(handle_);\n      handle_ = handle;\n    }\n  }\n\n private:\n  HANDLE handle_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);\n};\n# endif  // GTEST_OS_WINDOWS\n\n// Attempts to parse a string into a positive integer pointed to by the\n// number parameter.  Returns true if that is possible.\n// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use\n// it here.\ntemplate <typename Integer>\nbool ParseNaturalNumber(const ::std::string& str, Integer* number) {\n  // Fail fast if the given string does not begin with a digit;\n  // this bypasses strtoXXX's \"optional leading whitespace and plus\n  // or minus sign\" semantics, which are undesirable here.\n  if (str.empty() || !IsDigit(str[0])) {\n    return false;\n  }\n  errno = 0;\n\n  char* end;\n  // BiggestConvertible is the largest integer type that system-provided\n  // string-to-number conversion routines can return.\n\n# if GTEST_OS_WINDOWS && !defined(__GNUC__)\n\n  // MSVC and C++ Builder define __int64 instead of the standard long long.\n  typedef unsigned __int64 BiggestConvertible;\n  const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);\n\n# else\n\n  typedef unsigned long long BiggestConvertible;  // NOLINT\n  const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);\n\n# endif  // GTEST_OS_WINDOWS && !defined(__GNUC__)\n\n  const bool parse_success = *end == '\\0' && errno == 0;\n\n  // TODO(vladl@google.com): Convert this to compile time assertion when it is\n  // available.\n  GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));\n\n  const Integer result = static_cast<Integer>(parsed);\n  if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {\n    *number = result;\n    return true;\n  }\n  return false;\n}\n#endif  // GTEST_HAS_DEATH_TEST\n\n// TestResult contains some private methods that should be hidden from\n// Google Test user but are required for testing. This class allow our tests\n// to access them.\n//\n// This class is supplied only for the purpose of testing Google Test's own\n// constructs. Do not use it in user tests, either directly or indirectly.\nclass TestResultAccessor {\n public:\n  static void RecordProperty(TestResult* test_result,\n                             const TestProperty& property) {\n    test_result->RecordProperty(property);\n  }\n\n  static void ClearTestPartResults(TestResult* test_result) {\n    test_result->ClearTestPartResults();\n  }\n\n  static const std::vector<testing::TestPartResult>& test_part_results(\n      const TestResult& test_result) {\n    return test_result.test_part_results();\n  }\n};\n\n}  // namespace internal\n}  // namespace testing\n\n#endif  // GTEST_SRC_GTEST_INTERNAL_INL_H_\n#undef GTEST_IMPLEMENTATION_\n\n#if GTEST_OS_WINDOWS\n# define vsnprintf _vsnprintf\n#endif  // GTEST_OS_WINDOWS\n\nnamespace testing {\n\nusing internal::CountIf;\nusing internal::ForEach;\nusing internal::GetElementOr;\nusing internal::Shuffle;\n\n// Constants.\n\n// A test whose test case name or test name matches this filter is\n// disabled and not run.\nstatic const char kDisableTestFilter[] = \"DISABLED_*:*/DISABLED_*\";\n\n// A test case whose name matches this filter is considered a death\n// test case and will be run before test cases whose name doesn't\n// match this filter.\nstatic const char kDeathTestCaseFilter[] = \"*DeathTest:*DeathTest/*\";\n\n// A test filter that matches everything.\nstatic const char kUniversalFilter[] = \"*\";\n\n// The default output file for XML output.\nstatic const char kDefaultOutputFile[] = \"test_detail.xml\";\n\n// The environment variable name for the test shard index.\nstatic const char kTestShardIndex[] = \"GTEST_SHARD_INDEX\";\n// The environment variable name for the total number of test shards.\nstatic const char kTestTotalShards[] = \"GTEST_TOTAL_SHARDS\";\n// The environment variable name for the test shard status file.\nstatic const char kTestShardStatusFile[] = \"GTEST_SHARD_STATUS_FILE\";\n\nnamespace internal {\n\n// The text used in failure messages to indicate the start of the\n// stack trace.\nconst char kStackTraceMarker[] = \"\\nStack trace:\\n\";\n\n// g_help_flag is true iff the --help flag or an equivalent form is\n// specified on the command line.\nbool g_help_flag = false;\n\n}  // namespace internal\n\nGTEST_DEFINE_bool_(\n    also_run_disabled_tests,\n    internal::BoolFromGTestEnv(\"also_run_disabled_tests\", false),\n    \"Run disabled tests too, in addition to the tests normally being run.\");\n\nGTEST_DEFINE_bool_(\n    break_on_failure,\n    internal::BoolFromGTestEnv(\"break_on_failure\", false),\n    \"True iff a failed assertion should be a debugger break-point.\");\n\nGTEST_DEFINE_bool_(\n    catch_exceptions,\n    internal::BoolFromGTestEnv(\"catch_exceptions\", true),\n    \"True iff \" GTEST_NAME_\n    \" should catch exceptions and treat them as test failures.\");\n\nGTEST_DEFINE_string_(\n    color,\n    internal::StringFromGTestEnv(\"color\", \"auto\"),\n    \"Whether to use colors in the output.  Valid values: yes, no, \"\n    \"and auto.  'auto' means to use colors if the output is \"\n    \"being sent to a terminal and the TERM environment variable \"\n    \"is set to xterm, xterm-color, xterm-256color, linux or cygwin.\");\n\nGTEST_DEFINE_string_(\n    filter,\n    internal::StringFromGTestEnv(\"filter\", kUniversalFilter),\n    \"A colon-separated list of glob (not regex) patterns \"\n    \"for filtering the tests to run, optionally followed by a \"\n    \"'-' and a : separated list of negative patterns (tests to \"\n    \"exclude).  A test is run if it matches one of the positive \"\n    \"patterns and does not match any of the negative patterns.\");\n\nGTEST_DEFINE_bool_(list_tests, false,\n                   \"List all tests without running them.\");\n\nGTEST_DEFINE_string_(\n    output,\n    internal::StringFromGTestEnv(\"output\", \"\"),\n    \"A format (currently must be \\\"xml\\\"), optionally followed \"\n    \"by a colon and an output file name or directory. A directory \"\n    \"is indicated by a trailing pathname separator. \"\n    \"Examples: \\\"xml:filename.xml\\\", \\\"xml::directoryname/\\\". \"\n    \"If a directory is specified, output files will be created \"\n    \"within that directory, with file-names based on the test \"\n    \"executable's name and, if necessary, made unique by adding \"\n    \"digits.\");\n\nGTEST_DEFINE_bool_(\n    print_time,\n    internal::BoolFromGTestEnv(\"print_time\", true),\n    \"True iff \" GTEST_NAME_\n    \" should display elapsed time in text output.\");\n\nGTEST_DEFINE_int32_(\n    random_seed,\n    internal::Int32FromGTestEnv(\"random_seed\", 0),\n    \"Random number seed to use when shuffling test orders.  Must be in range \"\n    \"[1, 99999], or 0 to use a seed based on the current time.\");\n\nGTEST_DEFINE_int32_(\n    repeat,\n    internal::Int32FromGTestEnv(\"repeat\", 1),\n    \"How many times to repeat each test.  Specify a negative number \"\n    \"for repeating forever.  Useful for shaking out flaky tests.\");\n\nGTEST_DEFINE_bool_(\n    show_internal_stack_frames, false,\n    \"True iff \" GTEST_NAME_ \" should include internal stack frames when \"\n    \"printing test failure stack traces.\");\n\nGTEST_DEFINE_bool_(\n    shuffle,\n    internal::BoolFromGTestEnv(\"shuffle\", false),\n    \"True iff \" GTEST_NAME_\n    \" should randomize tests' order on every run.\");\n\nGTEST_DEFINE_int32_(\n    stack_trace_depth,\n    internal::Int32FromGTestEnv(\"stack_trace_depth\", kMaxStackTraceDepth),\n    \"The maximum number of stack frames to print when an \"\n    \"assertion fails.  The valid range is 0 through 100, inclusive.\");\n\nGTEST_DEFINE_string_(\n    stream_result_to,\n    internal::StringFromGTestEnv(\"stream_result_to\", \"\"),\n    \"This flag specifies the host name and the port number on which to stream \"\n    \"test results. Example: \\\"localhost:555\\\". The flag is effective only on \"\n    \"Linux.\");\n\nGTEST_DEFINE_bool_(\n    throw_on_failure,\n    internal::BoolFromGTestEnv(\"throw_on_failure\", false),\n    \"When this flag is specified, a failed assertion will throw an exception \"\n    \"if exceptions are enabled or exit the program with a non-zero code \"\n    \"otherwise.\");\n\nnamespace internal {\n\n// Generates a random number from [0, range), using a Linear\n// Congruential Generator (LCG).  Crashes if 'range' is 0 or greater\n// than kMaxRange.\nUInt32 Random::Generate(UInt32 range) {\n  // These constants are the same as are used in glibc's rand(3).\n  state_ = (1103515245U*state_ + 12345U) % kMaxRange;\n\n  GTEST_CHECK_(range > 0)\n      << \"Cannot generate a number in the range [0, 0).\";\n  GTEST_CHECK_(range <= kMaxRange)\n      << \"Generation of a number in [0, \" << range << \") was requested, \"\n      << \"but this can only generate numbers in [0, \" << kMaxRange << \").\";\n\n  // Converting via modulus introduces a bit of downward bias, but\n  // it's simple, and a linear congruential generator isn't too good\n  // to begin with.\n  return state_ % range;\n}\n\n// GTestIsInitialized() returns true iff the user has initialized\n// Google Test.  Useful for catching the user mistake of not initializing\n// Google Test before calling RUN_ALL_TESTS().\n//\n// A user must call testing::InitGoogleTest() to initialize Google\n// Test.  g_init_gtest_count is set to the number of times\n// InitGoogleTest() has been called.  We don't protect this variable\n// under a mutex as it is only accessed in the main thread.\nint g_init_gtest_count = 0;\nstatic bool GTestIsInitialized() { return g_init_gtest_count != 0; }\n\n// Iterates over a vector of TestCases, keeping a running sum of the\n// results of calling a given int-returning method on each.\n// Returns the sum.\nstatic int SumOverTestCaseList(const std::vector<TestCase*>& case_list,\n                               int (TestCase::*method)() const) {\n  int sum = 0;\n  for (size_t i = 0; i < case_list.size(); i++) {\n    sum += (case_list[i]->*method)();\n  }\n  return sum;\n}\n\n// Returns true iff the test case passed.\nstatic bool TestCasePassed(const TestCase* test_case) {\n  return test_case->should_run() && test_case->Passed();\n}\n\n// Returns true iff the test case failed.\nstatic bool TestCaseFailed(const TestCase* test_case) {\n  return test_case->should_run() && test_case->Failed();\n}\n\n// Returns true iff test_case contains at least one test that should\n// run.\nstatic bool ShouldRunTestCase(const TestCase* test_case) {\n  return test_case->should_run();\n}\n\n// AssertHelper constructor.\nAssertHelper::AssertHelper(TestPartResult::Type type,\n                           const char* file,\n                           int line,\n                           const char* message)\n    : data_(new AssertHelperData(type, file, line, message)) {\n}\n\nAssertHelper::~AssertHelper() {\n  delete data_;\n}\n\n// Message assignment, for assertion streaming support.\nvoid AssertHelper::operator=(const Message& message) const {\n  UnitTest::GetInstance()->\n    AddTestPartResult(data_->type, data_->file, data_->line,\n                      AppendUserMessage(data_->message, message),\n                      UnitTest::GetInstance()->impl()\n                      ->CurrentOsStackTraceExceptTop(1)\n                      // Skips the stack frame for this function itself.\n                      );  // NOLINT\n}\n\n// Mutex for linked pointers.\nGTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex);\n\n// Application pathname gotten in InitGoogleTest.\nString g_executable_path;\n\n// Returns the current application's name, removing directory path if that\n// is present.\nFilePath GetCurrentExecutableName() {\n  FilePath result;\n\n#if GTEST_OS_WINDOWS\n  result.Set(FilePath(g_executable_path).RemoveExtension(\"exe\"));\n#else\n  result.Set(FilePath(g_executable_path));\n#endif  // GTEST_OS_WINDOWS\n\n  return result.RemoveDirectoryName();\n}\n\n// Functions for processing the gtest_output flag.\n\n// Returns the output format, or \"\" for normal printed output.\nString UnitTestOptions::GetOutputFormat() {\n  const char* const gtest_output_flag = GTEST_FLAG(output).c_str();\n  if (gtest_output_flag == NULL) return String(\"\");\n\n  const char* const colon = strchr(gtest_output_flag, ':');\n  return (colon == NULL) ?\n      String(gtest_output_flag) :\n      String(gtest_output_flag, colon - gtest_output_flag);\n}\n\n// Returns the name of the requested output file, or the default if none\n// was explicitly specified.\nString UnitTestOptions::GetAbsolutePathToOutputFile() {\n  const char* const gtest_output_flag = GTEST_FLAG(output).c_str();\n  if (gtest_output_flag == NULL)\n    return String(\"\");\n\n  const char* const colon = strchr(gtest_output_flag, ':');\n  if (colon == NULL)\n    return String(internal::FilePath::ConcatPaths(\n               internal::FilePath(\n                   UnitTest::GetInstance()->original_working_dir()),\n               internal::FilePath(kDefaultOutputFile)).ToString() );\n\n  internal::FilePath output_name(colon + 1);\n  if (!output_name.IsAbsolutePath())\n    // TODO(wan@google.com): on Windows \\some\\path is not an absolute\n    // path (as its meaning depends on the current drive), yet the\n    // following logic for turning it into an absolute path is wrong.\n    // Fix it.\n    output_name = internal::FilePath::ConcatPaths(\n        internal::FilePath(UnitTest::GetInstance()->original_working_dir()),\n        internal::FilePath(colon + 1));\n\n  if (!output_name.IsDirectory())\n    return output_name.ToString();\n\n  internal::FilePath result(internal::FilePath::GenerateUniqueFileName(\n      output_name, internal::GetCurrentExecutableName(),\n      GetOutputFormat().c_str()));\n  return result.ToString();\n}\n\n// Returns true iff the wildcard pattern matches the string.  The\n// first ':' or '\\0' character in pattern marks the end of it.\n//\n// This recursive algorithm isn't very efficient, but is clear and\n// works well enough for matching test names, which are short.\nbool UnitTestOptions::PatternMatchesString(const char *pattern,\n                                           const char *str) {\n  switch (*pattern) {\n    case '\\0':\n    case ':':  // Either ':' or '\\0' marks the end of the pattern.\n      return *str == '\\0';\n    case '?':  // Matches any single character.\n      return *str != '\\0' && PatternMatchesString(pattern + 1, str + 1);\n    case '*':  // Matches any string (possibly empty) of characters.\n      return (*str != '\\0' && PatternMatchesString(pattern, str + 1)) ||\n          PatternMatchesString(pattern + 1, str);\n    default:  // Non-special character.  Matches itself.\n      return *pattern == *str &&\n          PatternMatchesString(pattern + 1, str + 1);\n  }\n}\n\nbool UnitTestOptions::MatchesFilter(const String& name, const char* filter) {\n  const char *cur_pattern = filter;\n  for (;;) {\n    if (PatternMatchesString(cur_pattern, name.c_str())) {\n      return true;\n    }\n\n    // Finds the next pattern in the filter.\n    cur_pattern = strchr(cur_pattern, ':');\n\n    // Returns if no more pattern can be found.\n    if (cur_pattern == NULL) {\n      return false;\n    }\n\n    // Skips the pattern separater (the ':' character).\n    cur_pattern++;\n  }\n}\n\n// TODO(keithray): move String function implementations to gtest-string.cc.\n\n// Returns true iff the user-specified filter matches the test case\n// name and the test name.\nbool UnitTestOptions::FilterMatchesTest(const String &test_case_name,\n                                        const String &test_name) {\n  const String& full_name = String::Format(\"%s.%s\",\n                                           test_case_name.c_str(),\n                                           test_name.c_str());\n\n  // Split --gtest_filter at '-', if there is one, to separate into\n  // positive filter and negative filter portions\n  const char* const p = GTEST_FLAG(filter).c_str();\n  const char* const dash = strchr(p, '-');\n  String positive;\n  String negative;\n  if (dash == NULL) {\n    positive = GTEST_FLAG(filter).c_str();  // Whole string is a positive filter\n    negative = String(\"\");\n  } else {\n    positive = String(p, dash - p);  // Everything up to the dash\n    negative = String(dash+1);       // Everything after the dash\n    if (positive.empty()) {\n      // Treat '-test1' as the same as '*-test1'\n      positive = kUniversalFilter;\n    }\n  }\n\n  // A filter is a colon-separated list of patterns.  It matches a\n  // test if any pattern in it matches the test.\n  return (MatchesFilter(full_name, positive.c_str()) &&\n          !MatchesFilter(full_name, negative.c_str()));\n}\n\n#if GTEST_HAS_SEH\n// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the\n// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.\n// This function is useful as an __except condition.\nint UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {\n  // Google Test should handle a SEH exception if:\n  //   1. the user wants it to, AND\n  //   2. this is not a breakpoint exception, AND\n  //   3. this is not a C++ exception (VC++ implements them via SEH,\n  //      apparently).\n  //\n  // SEH exception code for C++ exceptions.\n  // (see http://support.microsoft.com/kb/185294 for more information).\n  const DWORD kCxxExceptionCode = 0xe06d7363;\n\n  bool should_handle = true;\n\n  if (!GTEST_FLAG(catch_exceptions))\n    should_handle = false;\n  else if (exception_code == EXCEPTION_BREAKPOINT)\n    should_handle = false;\n  else if (exception_code == kCxxExceptionCode)\n    should_handle = false;\n\n  return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;\n}\n#endif  // GTEST_HAS_SEH\n\n}  // namespace internal\n\n// The c'tor sets this object as the test part result reporter used by\n// Google Test.  The 'result' parameter specifies where to report the\n// results. Intercepts only failures from the current thread.\nScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(\n    TestPartResultArray* result)\n    : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),\n      result_(result) {\n  Init();\n}\n\n// The c'tor sets this object as the test part result reporter used by\n// Google Test.  The 'result' parameter specifies where to report the\n// results.\nScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(\n    InterceptMode intercept_mode, TestPartResultArray* result)\n    : intercept_mode_(intercept_mode),\n      result_(result) {\n  Init();\n}\n\nvoid ScopedFakeTestPartResultReporter::Init() {\n  internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();\n  if (intercept_mode_ == INTERCEPT_ALL_THREADS) {\n    old_reporter_ = impl->GetGlobalTestPartResultReporter();\n    impl->SetGlobalTestPartResultReporter(this);\n  } else {\n    old_reporter_ = impl->GetTestPartResultReporterForCurrentThread();\n    impl->SetTestPartResultReporterForCurrentThread(this);\n  }\n}\n\n// The d'tor restores the test part result reporter used by Google Test\n// before.\nScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() {\n  internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();\n  if (intercept_mode_ == INTERCEPT_ALL_THREADS) {\n    impl->SetGlobalTestPartResultReporter(old_reporter_);\n  } else {\n    impl->SetTestPartResultReporterForCurrentThread(old_reporter_);\n  }\n}\n\n// Increments the test part result count and remembers the result.\n// This method is from the TestPartResultReporterInterface interface.\nvoid ScopedFakeTestPartResultReporter::ReportTestPartResult(\n    const TestPartResult& result) {\n  result_->Append(result);\n}\n\nnamespace internal {\n\n// Returns the type ID of ::testing::Test.  We should always call this\n// instead of GetTypeId< ::testing::Test>() to get the type ID of\n// testing::Test.  This is to work around a suspected linker bug when\n// using Google Test as a framework on Mac OS X.  The bug causes\n// GetTypeId< ::testing::Test>() to return different values depending\n// on whether the call is from the Google Test framework itself or\n// from user test code.  GetTestTypeId() is guaranteed to always\n// return the same value, as it always calls GetTypeId<>() from the\n// gtest.cc, which is within the Google Test framework.\nTypeId GetTestTypeId() {\n  return GetTypeId<Test>();\n}\n\n// The value of GetTestTypeId() as seen from within the Google Test\n// library.  This is solely for testing GetTestTypeId().\nextern const TypeId kTestTypeIdInGoogleTest = GetTestTypeId();\n\n// This predicate-formatter checks that 'results' contains a test part\n// failure of the given type and that the failure message contains the\n// given substring.\nAssertionResult HasOneFailure(const char* /* results_expr */,\n                              const char* /* type_expr */,\n                              const char* /* substr_expr */,\n                              const TestPartResultArray& results,\n                              TestPartResult::Type type,\n                              const string& substr) {\n  const String expected(type == TestPartResult::kFatalFailure ?\n                        \"1 fatal failure\" :\n                        \"1 non-fatal failure\");\n  Message msg;\n  if (results.size() != 1) {\n    msg << \"Expected: \" << expected << \"\\n\"\n        << \"  Actual: \" << results.size() << \" failures\";\n    for (int i = 0; i < results.size(); i++) {\n      msg << \"\\n\" << results.GetTestPartResult(i);\n    }\n    return AssertionFailure() << msg;\n  }\n\n  const TestPartResult& r = results.GetTestPartResult(0);\n  if (r.type() != type) {\n    return AssertionFailure() << \"Expected: \" << expected << \"\\n\"\n                              << \"  Actual:\\n\"\n                              << r;\n  }\n\n  if (strstr(r.message(), substr.c_str()) == NULL) {\n    return AssertionFailure() << \"Expected: \" << expected << \" containing \\\"\"\n                              << substr << \"\\\"\\n\"\n                              << \"  Actual:\\n\"\n                              << r;\n  }\n\n  return AssertionSuccess();\n}\n\n// The constructor of SingleFailureChecker remembers where to look up\n// test part results, what type of failure we expect, and what\n// substring the failure message should contain.\nSingleFailureChecker:: SingleFailureChecker(\n    const TestPartResultArray* results,\n    TestPartResult::Type type,\n    const string& substr)\n    : results_(results),\n      type_(type),\n      substr_(substr) {}\n\n// The destructor of SingleFailureChecker verifies that the given\n// TestPartResultArray contains exactly one failure that has the given\n// type and contains the given substring.  If that's not the case, a\n// non-fatal failure will be generated.\nSingleFailureChecker::~SingleFailureChecker() {\n  EXPECT_PRED_FORMAT3(HasOneFailure, *results_, type_, substr_);\n}\n\nDefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(\n    UnitTestImpl* unit_test) : unit_test_(unit_test) {}\n\nvoid DefaultGlobalTestPartResultReporter::ReportTestPartResult(\n    const TestPartResult& result) {\n  unit_test_->current_test_result()->AddTestPartResult(result);\n  unit_test_->listeners()->repeater()->OnTestPartResult(result);\n}\n\nDefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(\n    UnitTestImpl* unit_test) : unit_test_(unit_test) {}\n\nvoid DefaultPerThreadTestPartResultReporter::ReportTestPartResult(\n    const TestPartResult& result) {\n  unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result);\n}\n\n// Returns the global test part result reporter.\nTestPartResultReporterInterface*\nUnitTestImpl::GetGlobalTestPartResultReporter() {\n  internal::MutexLock lock(&global_test_part_result_reporter_mutex_);\n  return global_test_part_result_repoter_;\n}\n\n// Sets the global test part result reporter.\nvoid UnitTestImpl::SetGlobalTestPartResultReporter(\n    TestPartResultReporterInterface* reporter) {\n  internal::MutexLock lock(&global_test_part_result_reporter_mutex_);\n  global_test_part_result_repoter_ = reporter;\n}\n\n// Returns the test part result reporter for the current thread.\nTestPartResultReporterInterface*\nUnitTestImpl::GetTestPartResultReporterForCurrentThread() {\n  return per_thread_test_part_result_reporter_.get();\n}\n\n// Sets the test part result reporter for the current thread.\nvoid UnitTestImpl::SetTestPartResultReporterForCurrentThread(\n    TestPartResultReporterInterface* reporter) {\n  per_thread_test_part_result_reporter_.set(reporter);\n}\n\n// Gets the number of successful test cases.\nint UnitTestImpl::successful_test_case_count() const {\n  return CountIf(test_cases_, TestCasePassed);\n}\n\n// Gets the number of failed test cases.\nint UnitTestImpl::failed_test_case_count() const {\n  return CountIf(test_cases_, TestCaseFailed);\n}\n\n// Gets the number of all test cases.\nint UnitTestImpl::total_test_case_count() const {\n  return static_cast<int>(test_cases_.size());\n}\n\n// Gets the number of all test cases that contain at least one test\n// that should run.\nint UnitTestImpl::test_case_to_run_count() const {\n  return CountIf(test_cases_, ShouldRunTestCase);\n}\n\n// Gets the number of successful tests.\nint UnitTestImpl::successful_test_count() const {\n  return SumOverTestCaseList(test_cases_, &TestCase::successful_test_count);\n}\n\n// Gets the number of failed tests.\nint UnitTestImpl::failed_test_count() const {\n  return SumOverTestCaseList(test_cases_, &TestCase::failed_test_count);\n}\n\n// Gets the number of disabled tests.\nint UnitTestImpl::disabled_test_count() const {\n  return SumOverTestCaseList(test_cases_, &TestCase::disabled_test_count);\n}\n\n// Gets the number of all tests.\nint UnitTestImpl::total_test_count() const {\n  return SumOverTestCaseList(test_cases_, &TestCase::total_test_count);\n}\n\n// Gets the number of tests that should run.\nint UnitTestImpl::test_to_run_count() const {\n  return SumOverTestCaseList(test_cases_, &TestCase::test_to_run_count);\n}\n\n// Returns the current OS stack trace as a String.\n//\n// The maximum number of stack frames to be included is specified by\n// the gtest_stack_trace_depth flag.  The skip_count parameter\n// specifies the number of top frames to be skipped, which doesn't\n// count against the number of frames to be included.\n//\n// For example, if Foo() calls Bar(), which in turn calls\n// CurrentOsStackTraceExceptTop(1), Foo() will be included in the\n// trace but Bar() and CurrentOsStackTraceExceptTop() won't.\nString UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {\n  (void)skip_count;\n  return String(\"\");\n}\n\n// Returns the current time in milliseconds.\nTimeInMillis GetTimeInMillis() {\n#if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__)\n  // Difference between 1970-01-01 and 1601-01-01 in milliseconds.\n  // http://analogous.blogspot.com/2005/04/epoch.html\n  const TimeInMillis kJavaEpochToWinFileTimeDelta =\n    static_cast<TimeInMillis>(116444736UL) * 100000UL;\n  const DWORD kTenthMicrosInMilliSecond = 10000;\n\n  SYSTEMTIME now_systime;\n  FILETIME now_filetime;\n  ULARGE_INTEGER now_int64;\n  // TODO(kenton@google.com): Shouldn't this just use\n  //   GetSystemTimeAsFileTime()?\n  GetSystemTime(&now_systime);\n  if (SystemTimeToFileTime(&now_systime, &now_filetime)) {\n    now_int64.LowPart = now_filetime.dwLowDateTime;\n    now_int64.HighPart = now_filetime.dwHighDateTime;\n    now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -\n      kJavaEpochToWinFileTimeDelta;\n    return now_int64.QuadPart;\n  }\n  return 0;\n#elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_\n  __timeb64 now;\n\n# ifdef _MSC_VER\n\n  // MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996\n  // (deprecated function) there.\n  // TODO(kenton@google.com): Use GetTickCount()?  Or use\n  //   SystemTimeToFileTime()\n#  pragma warning(push)          // Saves the current warning state.\n#  pragma warning(disable:4996)  // Temporarily disables warning 4996.\n  _ftime64(&now);\n#  pragma warning(pop)           // Restores the warning state.\n# else\n\n  _ftime64(&now);\n\n# endif  // _MSC_VER\n\n  return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;\n#elif GTEST_HAS_GETTIMEOFDAY_\n  struct timeval now;\n  gettimeofday(&now, NULL);\n  return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000;\n#else\n# error \"Don't know how to get the current time on your system.\"\n#endif\n}\n\n// Utilities\n\n// class String\n\n// Returns the input enclosed in double quotes if it's not NULL;\n// otherwise returns \"(null)\".  For example, \"\\\"Hello\\\"\" is returned\n// for input \"Hello\".\n//\n// This is useful for printing a C string in the syntax of a literal.\n//\n// Known issue: escape sequences are not handled yet.\nString String::ShowCStringQuoted(const char* c_str) {\n  return c_str ? String::Format(\"\\\"%s\\\"\", c_str) : String(\"(null)\");\n}\n\n// Copies at most length characters from str into a newly-allocated\n// piece of memory of size length+1.  The memory is allocated with new[].\n// A terminating null byte is written to the memory, and a pointer to it\n// is returned.  If str is NULL, NULL is returned.\nstatic char* CloneString(const char* str, size_t length) {\n  if (str == NULL) {\n    return NULL;\n  } else {\n    char* const clone = new char[length + 1];\n    posix::StrNCpy(clone, str, length);\n    clone[length] = '\\0';\n    return clone;\n  }\n}\n\n// Clones a 0-terminated C string, allocating memory using new.  The\n// caller is responsible for deleting[] the return value.  Returns the\n// cloned string, or NULL if the input is NULL.\nconst char * String::CloneCString(const char* c_str) {\n  return (c_str == NULL) ?\n                    NULL : CloneString(c_str, strlen(c_str));\n}\n\n#if GTEST_OS_WINDOWS_MOBILE\n// Creates a UTF-16 wide string from the given ANSI string, allocating\n// memory using new. The caller is responsible for deleting the return\n// value using delete[]. Returns the wide string, or NULL if the\n// input is NULL.\nLPCWSTR String::AnsiToUtf16(const char* ansi) {\n  if (!ansi) return NULL;\n  const int length = strlen(ansi);\n  const int unicode_length =\n      MultiByteToWideChar(CP_ACP, 0, ansi, length,\n                          NULL, 0);\n  WCHAR* unicode = new WCHAR[unicode_length + 1];\n  MultiByteToWideChar(CP_ACP, 0, ansi, length,\n                      unicode, unicode_length);\n  unicode[unicode_length] = 0;\n  return unicode;\n}\n\n// Creates an ANSI string from the given wide string, allocating\n// memory using new. The caller is responsible for deleting the return\n// value using delete[]. Returns the ANSI string, or NULL if the\n// input is NULL.\nconst char* String::Utf16ToAnsi(LPCWSTR utf16_str)  {\n  if (!utf16_str) return NULL;\n  const int ansi_length =\n      WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,\n                          NULL, 0, NULL, NULL);\n  char* ansi = new char[ansi_length + 1];\n  WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,\n                      ansi, ansi_length, NULL, NULL);\n  ansi[ansi_length] = 0;\n  return ansi;\n}\n\n#endif  // GTEST_OS_WINDOWS_MOBILE\n\n// Compares two C strings.  Returns true iff they have the same content.\n//\n// Unlike strcmp(), this function can handle NULL argument(s).  A NULL\n// C string is considered different to any non-NULL C string,\n// including the empty string.\nbool String::CStringEquals(const char * lhs, const char * rhs) {\n  if ( lhs == NULL ) return rhs == NULL;\n\n  if ( rhs == NULL ) return false;\n\n  return strcmp(lhs, rhs) == 0;\n}\n\n#if GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING\n\n// Converts an array of wide chars to a narrow string using the UTF-8\n// encoding, and streams the result to the given Message object.\nstatic void StreamWideCharsToMessage(const wchar_t* wstr, size_t length,\n                                     Message* msg) {\n  // TODO(wan): consider allowing a testing::String object to\n  // contain '\\0'.  This will make it behave more like std::string,\n  // and will allow ToUtf8String() to return the correct encoding\n  // for '\\0' s.t. we can get rid of the conditional here (and in\n  // several other places).\n  for (size_t i = 0; i != length; ) {  // NOLINT\n    if (wstr[i] != L'\\0') {\n      *msg << WideStringToUtf8(wstr + i, static_cast<int>(length - i));\n      while (i != length && wstr[i] != L'\\0')\n        i++;\n    } else {\n      *msg << '\\0';\n      i++;\n    }\n  }\n}\n\n#endif  // GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING\n\n}  // namespace internal\n\n#if GTEST_HAS_STD_WSTRING\n// Converts the given wide string to a narrow string using the UTF-8\n// encoding, and streams the result to this Message object.\nMessage& Message::operator <<(const ::std::wstring& wstr) {\n  internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this);\n  return *this;\n}\n#endif  // GTEST_HAS_STD_WSTRING\n\n#if GTEST_HAS_GLOBAL_WSTRING\n// Converts the given wide string to a narrow string using the UTF-8\n// encoding, and streams the result to this Message object.\nMessage& Message::operator <<(const ::wstring& wstr) {\n  internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this);\n  return *this;\n}\n#endif  // GTEST_HAS_GLOBAL_WSTRING\n\n// AssertionResult constructors.\n// Used in EXPECT_TRUE/FALSE(assertion_result).\nAssertionResult::AssertionResult(const AssertionResult& other)\n    : success_(other.success_),\n      message_(other.message_.get() != NULL ?\n               new ::std::string(*other.message_) :\n               static_cast< ::std::string*>(NULL)) {\n}\n\n// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.\nAssertionResult AssertionResult::operator!() const {\n  AssertionResult negation(!success_);\n  if (message_.get() != NULL)\n    negation << *message_;\n  return negation;\n}\n\n// Makes a successful assertion result.\nAssertionResult AssertionSuccess() {\n  return AssertionResult(true);\n}\n\n// Makes a failed assertion result.\nAssertionResult AssertionFailure() {\n  return AssertionResult(false);\n}\n\n// Makes a failed assertion result with the given failure message.\n// Deprecated; use AssertionFailure() << message.\nAssertionResult AssertionFailure(const Message& message) {\n  return AssertionFailure() << message;\n}\n\nnamespace internal {\n\n// Constructs and returns the message for an equality assertion\n// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.\n//\n// The first four parameters are the expressions used in the assertion\n// and their values, as strings.  For example, for ASSERT_EQ(foo, bar)\n// where foo is 5 and bar is 6, we have:\n//\n//   expected_expression: \"foo\"\n//   actual_expression:   \"bar\"\n//   expected_value:      \"5\"\n//   actual_value:        \"6\"\n//\n// The ignoring_case parameter is true iff the assertion is a\n// *_STRCASEEQ*.  When it's true, the string \" (ignoring case)\" will\n// be inserted into the message.\nAssertionResult EqFailure(const char* expected_expression,\n                          const char* actual_expression,\n                          const String& expected_value,\n                          const String& actual_value,\n                          bool ignoring_case) {\n  Message msg;\n  msg << \"Value of: \" << actual_expression;\n  if (actual_value != actual_expression) {\n    msg << \"\\n  Actual: \" << actual_value;\n  }\n\n  msg << \"\\nExpected: \" << expected_expression;\n  if (ignoring_case) {\n    msg << \" (ignoring case)\";\n  }\n  if (expected_value != expected_expression) {\n    msg << \"\\nWhich is: \" << expected_value;\n  }\n\n  return AssertionFailure() << msg;\n}\n\n// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.\nString GetBoolAssertionFailureMessage(const AssertionResult& assertion_result,\n                                      const char* expression_text,\n                                      const char* actual_predicate_value,\n                                      const char* expected_predicate_value) {\n  const char* actual_message = assertion_result.message();\n  Message msg;\n  msg << \"Value of: \" << expression_text\n      << \"\\n  Actual: \" << actual_predicate_value;\n  if (actual_message[0] != '\\0')\n    msg << \" (\" << actual_message << \")\";\n  msg << \"\\nExpected: \" << expected_predicate_value;\n  return msg.GetString();\n}\n\n// Helper function for implementing ASSERT_NEAR.\nAssertionResult DoubleNearPredFormat(const char* expr1,\n                                     const char* expr2,\n                                     const char* abs_error_expr,\n                                     double val1,\n                                     double val2,\n                                     double abs_error) {\n  const double diff = fabs(val1 - val2);\n  if (diff <= abs_error) return AssertionSuccess();\n\n  // TODO(wan): do not print the value of an expression if it's\n  // already a literal.\n  return AssertionFailure()\n      << \"The difference between \" << expr1 << \" and \" << expr2\n      << \" is \" << diff << \", which exceeds \" << abs_error_expr << \", where\\n\"\n      << expr1 << \" evaluates to \" << val1 << \",\\n\"\n      << expr2 << \" evaluates to \" << val2 << \", and\\n\"\n      << abs_error_expr << \" evaluates to \" << abs_error << \".\";\n}\n\n\n// Helper template for implementing FloatLE() and DoubleLE().\ntemplate <typename RawType>\nAssertionResult FloatingPointLE(const char* expr1,\n                                const char* expr2,\n                                RawType val1,\n                                RawType val2) {\n  // Returns success if val1 is less than val2,\n  if (val1 < val2) {\n    return AssertionSuccess();\n  }\n\n  // or if val1 is almost equal to val2.\n  const FloatingPoint<RawType> lhs(val1), rhs(val2);\n  if (lhs.AlmostEquals(rhs)) {\n    return AssertionSuccess();\n  }\n\n  // Note that the above two checks will both fail if either val1 or\n  // val2 is NaN, as the IEEE floating-point standard requires that\n  // any predicate involving a NaN must return false.\n\n  ::std::stringstream val1_ss;\n  val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)\n          << val1;\n\n  ::std::stringstream val2_ss;\n  val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)\n          << val2;\n\n  return AssertionFailure()\n      << \"Expected: (\" << expr1 << \") <= (\" << expr2 << \")\\n\"\n      << \"  Actual: \" << StringStreamToString(&val1_ss) << \" vs \"\n      << StringStreamToString(&val2_ss);\n}\n\n}  // namespace internal\n\n// Asserts that val1 is less than, or almost equal to, val2.  Fails\n// otherwise.  In particular, it fails if either val1 or val2 is NaN.\nAssertionResult FloatLE(const char* expr1, const char* expr2,\n                        float val1, float val2) {\n  return internal::FloatingPointLE<float>(expr1, expr2, val1, val2);\n}\n\n// Asserts that val1 is less than, or almost equal to, val2.  Fails\n// otherwise.  In particular, it fails if either val1 or val2 is NaN.\nAssertionResult DoubleLE(const char* expr1, const char* expr2,\n                         double val1, double val2) {\n  return internal::FloatingPointLE<double>(expr1, expr2, val1, val2);\n}\n\nnamespace internal {\n\n// The helper function for {ASSERT|EXPECT}_EQ with int or enum\n// arguments.\nAssertionResult CmpHelperEQ(const char* expected_expression,\n                            const char* actual_expression,\n                            BiggestInt expected,\n                            BiggestInt actual) {\n  if (expected == actual) {\n    return AssertionSuccess();\n  }\n\n  return EqFailure(expected_expression,\n                   actual_expression,\n                   FormatForComparisonFailureMessage(expected, actual),\n                   FormatForComparisonFailureMessage(actual, expected),\n                   false);\n}\n\n// A macro for implementing the helper functions needed to implement\n// ASSERT_?? and EXPECT_?? with integer or enum arguments.  It is here\n// just to avoid copy-and-paste of similar code.\n#define GTEST_IMPL_CMP_HELPER_(op_name, op)\\\nAssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \\\n                                   BiggestInt val1, BiggestInt val2) {\\\n  if (val1 op val2) {\\\n    return AssertionSuccess();\\\n  } else {\\\n    return AssertionFailure() \\\n        << \"Expected: (\" << expr1 << \") \" #op \" (\" << expr2\\\n        << \"), actual: \" << FormatForComparisonFailureMessage(val1, val2)\\\n        << \" vs \" << FormatForComparisonFailureMessage(val2, val1);\\\n  }\\\n}\n\n// Implements the helper function for {ASSERT|EXPECT}_NE with int or\n// enum arguments.\nGTEST_IMPL_CMP_HELPER_(NE, !=)\n// Implements the helper function for {ASSERT|EXPECT}_LE with int or\n// enum arguments.\nGTEST_IMPL_CMP_HELPER_(LE, <=)\n// Implements the helper function for {ASSERT|EXPECT}_LT with int or\n// enum arguments.\nGTEST_IMPL_CMP_HELPER_(LT, < )\n// Implements the helper function for {ASSERT|EXPECT}_GE with int or\n// enum arguments.\nGTEST_IMPL_CMP_HELPER_(GE, >=)\n// Implements the helper function for {ASSERT|EXPECT}_GT with int or\n// enum arguments.\nGTEST_IMPL_CMP_HELPER_(GT, > )\n\n#undef GTEST_IMPL_CMP_HELPER_\n\n// The helper function for {ASSERT|EXPECT}_STREQ.\nAssertionResult CmpHelperSTREQ(const char* expected_expression,\n                               const char* actual_expression,\n                               const char* expected,\n                               const char* actual) {\n  if (String::CStringEquals(expected, actual)) {\n    return AssertionSuccess();\n  }\n\n  return EqFailure(expected_expression,\n                   actual_expression,\n                   String::ShowCStringQuoted(expected),\n                   String::ShowCStringQuoted(actual),\n                   false);\n}\n\n// The helper function for {ASSERT|EXPECT}_STRCASEEQ.\nAssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,\n                                   const char* actual_expression,\n                                   const char* expected,\n                                   const char* actual) {\n  if (String::CaseInsensitiveCStringEquals(expected, actual)) {\n    return AssertionSuccess();\n  }\n\n  return EqFailure(expected_expression,\n                   actual_expression,\n                   String::ShowCStringQuoted(expected),\n                   String::ShowCStringQuoted(actual),\n                   true);\n}\n\n// The helper function for {ASSERT|EXPECT}_STRNE.\nAssertionResult CmpHelperSTRNE(const char* s1_expression,\n                               const char* s2_expression,\n                               const char* s1,\n                               const char* s2) {\n  if (!String::CStringEquals(s1, s2)) {\n    return AssertionSuccess();\n  } else {\n    return AssertionFailure() << \"Expected: (\" << s1_expression << \") != (\"\n                              << s2_expression << \"), actual: \\\"\"\n                              << s1 << \"\\\" vs \\\"\" << s2 << \"\\\"\";\n  }\n}\n\n// The helper function for {ASSERT|EXPECT}_STRCASENE.\nAssertionResult CmpHelperSTRCASENE(const char* s1_expression,\n                                   const char* s2_expression,\n                                   const char* s1,\n                                   const char* s2) {\n  if (!String::CaseInsensitiveCStringEquals(s1, s2)) {\n    return AssertionSuccess();\n  } else {\n    return AssertionFailure()\n        << \"Expected: (\" << s1_expression << \") != (\"\n        << s2_expression << \") (ignoring case), actual: \\\"\"\n        << s1 << \"\\\" vs \\\"\" << s2 << \"\\\"\";\n  }\n}\n\n}  // namespace internal\n\nnamespace {\n\n// Helper functions for implementing IsSubString() and IsNotSubstring().\n\n// This group of overloaded functions return true iff needle is a\n// substring of haystack.  NULL is considered a substring of itself\n// only.\n\nbool IsSubstringPred(const char* needle, const char* haystack) {\n  if (needle == NULL || haystack == NULL)\n    return needle == haystack;\n\n  return strstr(haystack, needle) != NULL;\n}\n\nbool IsSubstringPred(const wchar_t* needle, const wchar_t* haystack) {\n  if (needle == NULL || haystack == NULL)\n    return needle == haystack;\n\n  return wcsstr(haystack, needle) != NULL;\n}\n\n// StringType here can be either ::std::string or ::std::wstring.\ntemplate <typename StringType>\nbool IsSubstringPred(const StringType& needle,\n                     const StringType& haystack) {\n  return haystack.find(needle) != StringType::npos;\n}\n\n// This function implements either IsSubstring() or IsNotSubstring(),\n// depending on the value of the expected_to_be_substring parameter.\n// StringType here can be const char*, const wchar_t*, ::std::string,\n// or ::std::wstring.\ntemplate <typename StringType>\nAssertionResult IsSubstringImpl(\n    bool expected_to_be_substring,\n    const char* needle_expr, const char* haystack_expr,\n    const StringType& needle, const StringType& haystack) {\n  if (IsSubstringPred(needle, haystack) == expected_to_be_substring)\n    return AssertionSuccess();\n\n  const bool is_wide_string = sizeof(needle[0]) > 1;\n  const char* const begin_string_quote = is_wide_string ? \"L\\\"\" : \"\\\"\";\n  return AssertionFailure()\n      << \"Value of: \" << needle_expr << \"\\n\"\n      << \"  Actual: \" << begin_string_quote << needle << \"\\\"\\n\"\n      << \"Expected: \" << (expected_to_be_substring ? \"\" : \"not \")\n      << \"a substring of \" << haystack_expr << \"\\n\"\n      << \"Which is: \" << begin_string_quote << haystack << \"\\\"\";\n}\n\n}  // namespace\n\n// IsSubstring() and IsNotSubstring() check whether needle is a\n// substring of haystack (NULL is considered a substring of itself\n// only), and return an appropriate error message when they fail.\n\nAssertionResult IsSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const char* needle, const char* haystack) {\n  return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);\n}\n\nAssertionResult IsSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const wchar_t* needle, const wchar_t* haystack) {\n  return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);\n}\n\nAssertionResult IsNotSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const char* needle, const char* haystack) {\n  return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);\n}\n\nAssertionResult IsNotSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const wchar_t* needle, const wchar_t* haystack) {\n  return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);\n}\n\nAssertionResult IsSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const ::std::string& needle, const ::std::string& haystack) {\n  return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);\n}\n\nAssertionResult IsNotSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const ::std::string& needle, const ::std::string& haystack) {\n  return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);\n}\n\n#if GTEST_HAS_STD_WSTRING\nAssertionResult IsSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const ::std::wstring& needle, const ::std::wstring& haystack) {\n  return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);\n}\n\nAssertionResult IsNotSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const ::std::wstring& needle, const ::std::wstring& haystack) {\n  return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);\n}\n#endif  // GTEST_HAS_STD_WSTRING\n\nnamespace internal {\n\n#if GTEST_OS_WINDOWS\n\nnamespace {\n\n// Helper function for IsHRESULT{SuccessFailure} predicates\nAssertionResult HRESULTFailureHelper(const char* expr,\n                                     const char* expected,\n                                     long hr) {  // NOLINT\n# if GTEST_OS_WINDOWS_MOBILE\n\n  // Windows CE doesn't support FormatMessage.\n  const char error_text[] = \"\";\n\n# else\n\n  // Looks up the human-readable system message for the HRESULT code\n  // and since we're not passing any params to FormatMessage, we don't\n  // want inserts expanded.\n  const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |\n                       FORMAT_MESSAGE_IGNORE_INSERTS;\n  const DWORD kBufSize = 4096;  // String::Format can't exceed this length.\n  // Gets the system's human readable message string for this HRESULT.\n  char error_text[kBufSize] = { '\\0' };\n  DWORD message_length = ::FormatMessageA(kFlags,\n                                          0,  // no source, we're asking system\n                                          hr,  // the error\n                                          0,  // no line width restrictions\n                                          error_text,  // output buffer\n                                          kBufSize,  // buf size\n                                          NULL);  // no arguments for inserts\n  // Trims tailing white space (FormatMessage leaves a trailing cr-lf)\n  for (; message_length && IsSpace(error_text[message_length - 1]);\n          --message_length) {\n    error_text[message_length - 1] = '\\0';\n  }\n\n# endif  // GTEST_OS_WINDOWS_MOBILE\n\n  const String error_hex(String::Format(\"0x%08X \", hr));\n  return ::testing::AssertionFailure()\n      << \"Expected: \" << expr << \" \" << expected << \".\\n\"\n      << \"  Actual: \" << error_hex << error_text << \"\\n\";\n}\n\n}  // namespace\n\nAssertionResult IsHRESULTSuccess(const char* expr, long hr) {  // NOLINT\n  if (SUCCEEDED(hr)) {\n    return AssertionSuccess();\n  }\n  return HRESULTFailureHelper(expr, \"succeeds\", hr);\n}\n\nAssertionResult IsHRESULTFailure(const char* expr, long hr) {  // NOLINT\n  if (FAILED(hr)) {\n    return AssertionSuccess();\n  }\n  return HRESULTFailureHelper(expr, \"fails\", hr);\n}\n\n#endif  // GTEST_OS_WINDOWS\n\n// Utility functions for encoding Unicode text (wide strings) in\n// UTF-8.\n\n// A Unicode code-point can have upto 21 bits, and is encoded in UTF-8\n// like this:\n//\n// Code-point length   Encoding\n//   0 -  7 bits       0xxxxxxx\n//   8 - 11 bits       110xxxxx 10xxxxxx\n//  12 - 16 bits       1110xxxx 10xxxxxx 10xxxxxx\n//  17 - 21 bits       11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n\n// The maximum code-point a one-byte UTF-8 sequence can represent.\nconst UInt32 kMaxCodePoint1 = (static_cast<UInt32>(1) <<  7) - 1;\n\n// The maximum code-point a two-byte UTF-8 sequence can represent.\nconst UInt32 kMaxCodePoint2 = (static_cast<UInt32>(1) << (5 + 6)) - 1;\n\n// The maximum code-point a three-byte UTF-8 sequence can represent.\nconst UInt32 kMaxCodePoint3 = (static_cast<UInt32>(1) << (4 + 2*6)) - 1;\n\n// The maximum code-point a four-byte UTF-8 sequence can represent.\nconst UInt32 kMaxCodePoint4 = (static_cast<UInt32>(1) << (3 + 3*6)) - 1;\n\n// Chops off the n lowest bits from a bit pattern.  Returns the n\n// lowest bits.  As a side effect, the original bit pattern will be\n// shifted to the right by n bits.\ninline UInt32 ChopLowBits(UInt32* bits, int n) {\n  const UInt32 low_bits = *bits & ((static_cast<UInt32>(1) << n) - 1);\n  *bits >>= n;\n  return low_bits;\n}\n\n// Converts a Unicode code point to a narrow string in UTF-8 encoding.\n// code_point parameter is of type UInt32 because wchar_t may not be\n// wide enough to contain a code point.\n// The output buffer str must containt at least 32 characters.\n// The function returns the address of the output buffer.\n// If the code_point is not a valid Unicode code point\n// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be output\n// as '(Invalid Unicode 0xXXXXXXXX)'.\nchar* CodePointToUtf8(UInt32 code_point, char* str) {\n  if (code_point <= kMaxCodePoint1) {\n    str[1] = '\\0';\n    str[0] = static_cast<char>(code_point);                          // 0xxxxxxx\n  } else if (code_point <= kMaxCodePoint2) {\n    str[2] = '\\0';\n    str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6));  // 10xxxxxx\n    str[0] = static_cast<char>(0xC0 | code_point);                   // 110xxxxx\n  } else if (code_point <= kMaxCodePoint3) {\n    str[3] = '\\0';\n    str[2] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6));  // 10xxxxxx\n    str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6));  // 10xxxxxx\n    str[0] = static_cast<char>(0xE0 | code_point);                   // 1110xxxx\n  } else if (code_point <= kMaxCodePoint4) {\n    str[4] = '\\0';\n    str[3] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6));  // 10xxxxxx\n    str[2] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6));  // 10xxxxxx\n    str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6));  // 10xxxxxx\n    str[0] = static_cast<char>(0xF0 | code_point);                   // 11110xxx\n  } else {\n    // The longest string String::Format can produce when invoked\n    // with these parameters is 28 character long (not including\n    // the terminating nul character). We are asking for 32 character\n    // buffer just in case. This is also enough for strncpy to\n    // null-terminate the destination string.\n    posix::StrNCpy(\n        str, String::Format(\"(Invalid Unicode 0x%X)\", code_point).c_str(), 32);\n    str[31] = '\\0';  // Makes sure no change in the format to strncpy leaves\n                     // the result unterminated.\n  }\n  return str;\n}\n\n// The following two functions only make sense if the the system\n// uses UTF-16 for wide string encoding. All supported systems\n// with 16 bit wchar_t (Windows, Cygwin, Symbian OS) do use UTF-16.\n\n// Determines if the arguments constitute UTF-16 surrogate pair\n// and thus should be combined into a single Unicode code point\n// using CreateCodePointFromUtf16SurrogatePair.\ninline bool IsUtf16SurrogatePair(wchar_t first, wchar_t second) {\n  return sizeof(wchar_t) == 2 &&\n      (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;\n}\n\n// Creates a Unicode code point from UTF16 surrogate pair.\ninline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first,\n                                                    wchar_t second) {\n  const UInt32 mask = (1 << 10) - 1;\n  return (sizeof(wchar_t) == 2) ?\n      (((first & mask) << 10) | (second & mask)) + 0x10000 :\n      // This function should not be called when the condition is\n      // false, but we provide a sensible default in case it is.\n      static_cast<UInt32>(first);\n}\n\n// Converts a wide string to a narrow string in UTF-8 encoding.\n// The wide string is assumed to have the following encoding:\n//   UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)\n//   UTF-32 if sizeof(wchar_t) == 4 (on Linux)\n// Parameter str points to a null-terminated wide string.\n// Parameter num_chars may additionally limit the number\n// of wchar_t characters processed. -1 is used when the entire string\n// should be processed.\n// If the string contains code points that are not valid Unicode code points\n// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output\n// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding\n// and contains invalid UTF-16 surrogate pairs, values in those pairs\n// will be encoded as individual Unicode characters from Basic Normal Plane.\nString WideStringToUtf8(const wchar_t* str, int num_chars) {\n  if (num_chars == -1)\n    num_chars = static_cast<int>(wcslen(str));\n\n  ::std::stringstream stream;\n  for (int i = 0; i < num_chars; ++i) {\n    UInt32 unicode_code_point;\n\n    if (str[i] == L'\\0') {\n      break;\n    } else if (i + 1 < num_chars && IsUtf16SurrogatePair(str[i], str[i + 1])) {\n      unicode_code_point = CreateCodePointFromUtf16SurrogatePair(str[i],\n                                                                 str[i + 1]);\n      i++;\n    } else {\n      unicode_code_point = static_cast<UInt32>(str[i]);\n    }\n\n    char buffer[32];  // CodePointToUtf8 requires a buffer this big.\n    stream << CodePointToUtf8(unicode_code_point, buffer);\n  }\n  return StringStreamToString(&stream);\n}\n\n// Converts a wide C string to a String using the UTF-8 encoding.\n// NULL will be converted to \"(null)\".\nString String::ShowWideCString(const wchar_t * wide_c_str) {\n  if (wide_c_str == NULL) return String(\"(null)\");\n\n  return String(internal::WideStringToUtf8(wide_c_str, -1).c_str());\n}\n\n// Similar to ShowWideCString(), except that this function encloses\n// the converted string in double quotes.\nString String::ShowWideCStringQuoted(const wchar_t* wide_c_str) {\n  if (wide_c_str == NULL) return String(\"(null)\");\n\n  return String::Format(\"L\\\"%s\\\"\",\n                        String::ShowWideCString(wide_c_str).c_str());\n}\n\n// Compares two wide C strings.  Returns true iff they have the same\n// content.\n//\n// Unlike wcscmp(), this function can handle NULL argument(s).  A NULL\n// C string is considered different to any non-NULL C string,\n// including the empty string.\nbool String::WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs) {\n  if (lhs == NULL) return rhs == NULL;\n\n  if (rhs == NULL) return false;\n\n  return wcscmp(lhs, rhs) == 0;\n}\n\n// Helper function for *_STREQ on wide strings.\nAssertionResult CmpHelperSTREQ(const char* expected_expression,\n                               const char* actual_expression,\n                               const wchar_t* expected,\n                               const wchar_t* actual) {\n  if (String::WideCStringEquals(expected, actual)) {\n    return AssertionSuccess();\n  }\n\n  return EqFailure(expected_expression,\n                   actual_expression,\n                   String::ShowWideCStringQuoted(expected),\n                   String::ShowWideCStringQuoted(actual),\n                   false);\n}\n\n// Helper function for *_STRNE on wide strings.\nAssertionResult CmpHelperSTRNE(const char* s1_expression,\n                               const char* s2_expression,\n                               const wchar_t* s1,\n                               const wchar_t* s2) {\n  if (!String::WideCStringEquals(s1, s2)) {\n    return AssertionSuccess();\n  }\n\n  return AssertionFailure() << \"Expected: (\" << s1_expression << \") != (\"\n                            << s2_expression << \"), actual: \"\n                            << String::ShowWideCStringQuoted(s1)\n                            << \" vs \" << String::ShowWideCStringQuoted(s2);\n}\n\n// Compares two C strings, ignoring case.  Returns true iff they have\n// the same content.\n//\n// Unlike strcasecmp(), this function can handle NULL argument(s).  A\n// NULL C string is considered different to any non-NULL C string,\n// including the empty string.\nbool String::CaseInsensitiveCStringEquals(const char * lhs, const char * rhs) {\n  if (lhs == NULL)\n    return rhs == NULL;\n  if (rhs == NULL)\n    return false;\n  return posix::StrCaseCmp(lhs, rhs) == 0;\n}\n\n  // Compares two wide C strings, ignoring case.  Returns true iff they\n  // have the same content.\n  //\n  // Unlike wcscasecmp(), this function can handle NULL argument(s).\n  // A NULL C string is considered different to any non-NULL wide C string,\n  // including the empty string.\n  // NB: The implementations on different platforms slightly differ.\n  // On windows, this method uses _wcsicmp which compares according to LC_CTYPE\n  // environment variable. On GNU platform this method uses wcscasecmp\n  // which compares according to LC_CTYPE category of the current locale.\n  // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the\n  // current locale.\nbool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs,\n                                              const wchar_t* rhs) {\n  if (lhs == NULL) return rhs == NULL;\n\n  if (rhs == NULL) return false;\n\n#if GTEST_OS_WINDOWS\n  return _wcsicmp(lhs, rhs) == 0;\n#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID\n  return wcscasecmp(lhs, rhs) == 0;\n#else\n  // Android, Mac OS X and Cygwin don't define wcscasecmp.\n  // Other unknown OSes may not define it either.\n  wint_t left, right;\n  do {\n    left = towlower(*lhs++);\n    right = towlower(*rhs++);\n  } while (left && left == right);\n  return left == right;\n#endif  // OS selector\n}\n\n// Compares this with another String.\n// Returns < 0 if this is less than rhs, 0 if this is equal to rhs, or > 0\n// if this is greater than rhs.\nint String::Compare(const String & rhs) const {\n  const char* const lhs_c_str = c_str();\n  const char* const rhs_c_str = rhs.c_str();\n\n  if (lhs_c_str == NULL) {\n    return rhs_c_str == NULL ? 0 : -1;  // NULL < anything except NULL\n  } else if (rhs_c_str == NULL) {\n    return 1;\n  }\n\n  const size_t shorter_str_len =\n      length() <= rhs.length() ? length() : rhs.length();\n  for (size_t i = 0; i != shorter_str_len; i++) {\n    if (lhs_c_str[i] < rhs_c_str[i]) {\n      return -1;\n    } else if (lhs_c_str[i] > rhs_c_str[i]) {\n      return 1;\n    }\n  }\n  return (length() < rhs.length()) ? -1 :\n      (length() > rhs.length()) ? 1 : 0;\n}\n\n// Returns true iff this String ends with the given suffix.  *Any*\n// String is considered to end with a NULL or empty suffix.\nbool String::EndsWith(const char* suffix) const {\n  if (suffix == NULL || CStringEquals(suffix, \"\")) return true;\n\n  if (c_str() == NULL) return false;\n\n  const size_t this_len = strlen(c_str());\n  const size_t suffix_len = strlen(suffix);\n  return (this_len >= suffix_len) &&\n         CStringEquals(c_str() + this_len - suffix_len, suffix);\n}\n\n// Returns true iff this String ends with the given suffix, ignoring case.\n// Any String is considered to end with a NULL or empty suffix.\nbool String::EndsWithCaseInsensitive(const char* suffix) const {\n  if (suffix == NULL || CStringEquals(suffix, \"\")) return true;\n\n  if (c_str() == NULL) return false;\n\n  const size_t this_len = strlen(c_str());\n  const size_t suffix_len = strlen(suffix);\n  return (this_len >= suffix_len) &&\n         CaseInsensitiveCStringEquals(c_str() + this_len - suffix_len, suffix);\n}\n\n// Formats a list of arguments to a String, using the same format\n// spec string as for printf.\n//\n// We do not use the StringPrintf class as it is not universally\n// available.\n//\n// The result is limited to 4096 characters (including the tailing 0).\n// If 4096 characters are not enough to format the input, or if\n// there's an error, \"<formatting error or buffer exceeded>\" is\n// returned.\nString String::Format(const char * format, ...) {\n  va_list args;\n  va_start(args, format);\n\n  char buffer[4096];\n  const int kBufferSize = sizeof(buffer)/sizeof(buffer[0]);\n\n  // MSVC 8 deprecates vsnprintf(), so we want to suppress warning\n  // 4996 (deprecated function) there.\n#ifdef _MSC_VER  // We are using MSVC.\n# pragma warning(push)          // Saves the current warning state.\n# pragma warning(disable:4996)  // Temporarily disables warning 4996.\n\n  const int size = vsnprintf(buffer, kBufferSize, format, args);\n\n# pragma warning(pop)           // Restores the warning state.\n#else  // We are not using MSVC.\n  const int size = vsnprintf(buffer, kBufferSize, format, args);\n#endif  // _MSC_VER\n  va_end(args);\n\n  // vsnprintf()'s behavior is not portable.  When the buffer is not\n  // big enough, it returns a negative value in MSVC, and returns the\n  // needed buffer size on Linux.  When there is an output error, it\n  // always returns a negative value.  For simplicity, we lump the two\n  // error cases together.\n  if (size < 0 || size >= kBufferSize) {\n    return String(\"<formatting error or buffer exceeded>\");\n  } else {\n    return String(buffer, size);\n  }\n}\n\n// Converts the buffer in a stringstream to a String, converting NUL\n// bytes to \"\\\\0\" along the way.\nString StringStreamToString(::std::stringstream* ss) {\n  const ::std::string& str = ss->str();\n  const char* const start = str.c_str();\n  const char* const end = start + str.length();\n\n  // We need to use a helper stringstream to do this transformation\n  // because String doesn't support push_back().\n  ::std::stringstream helper;\n  for (const char* ch = start; ch != end; ++ch) {\n    if (*ch == '\\0') {\n      helper << \"\\\\0\";  // Replaces NUL with \"\\\\0\";\n    } else {\n      helper.put(*ch);\n    }\n  }\n\n  return String(helper.str().c_str());\n}\n\n// Appends the user-supplied message to the Google-Test-generated message.\nString AppendUserMessage(const String& gtest_msg,\n                         const Message& user_msg) {\n  // Appends the user message if it's non-empty.\n  const String user_msg_string = user_msg.GetString();\n  if (user_msg_string.empty()) {\n    return gtest_msg;\n  }\n\n  Message msg;\n  msg << gtest_msg << \"\\n\" << user_msg_string;\n\n  return msg.GetString();\n}\n\n}  // namespace internal\n\n// class TestResult\n\n// Creates an empty TestResult.\nTestResult::TestResult()\n    : death_test_count_(0),\n      elapsed_time_(0) {\n}\n\n// D'tor.\nTestResult::~TestResult() {\n}\n\n// Returns the i-th test part result among all the results. i can\n// range from 0 to total_part_count() - 1. If i is not in that range,\n// aborts the program.\nconst TestPartResult& TestResult::GetTestPartResult(int i) const {\n  if (i < 0 || i >= total_part_count())\n    internal::posix::Abort();\n  return test_part_results_.at(i);\n}\n\n// Returns the i-th test property. i can range from 0 to\n// test_property_count() - 1. If i is not in that range, aborts the\n// program.\nconst TestProperty& TestResult::GetTestProperty(int i) const {\n  if (i < 0 || i >= test_property_count())\n    internal::posix::Abort();\n  return test_properties_.at(i);\n}\n\n// Clears the test part results.\nvoid TestResult::ClearTestPartResults() {\n  test_part_results_.clear();\n}\n\n// Adds a test part result to the list.\nvoid TestResult::AddTestPartResult(const TestPartResult& test_part_result) {\n  test_part_results_.push_back(test_part_result);\n}\n\n// Adds a test property to the list. If a property with the same key as the\n// supplied property is already represented, the value of this test_property\n// replaces the old value for that key.\nvoid TestResult::RecordProperty(const TestProperty& test_property) {\n  if (!ValidateTestProperty(test_property)) {\n    return;\n  }\n  internal::MutexLock lock(&test_properites_mutex_);\n  const std::vector<TestProperty>::iterator property_with_matching_key =\n      std::find_if(test_properties_.begin(), test_properties_.end(),\n                   internal::TestPropertyKeyIs(test_property.key()));\n  if (property_with_matching_key == test_properties_.end()) {\n    test_properties_.push_back(test_property);\n    return;\n  }\n  property_with_matching_key->SetValue(test_property.value());\n}\n\n// Adds a failure if the key is a reserved attribute of Google Test\n// testcase tags.  Returns true if the property is valid.\nbool TestResult::ValidateTestProperty(const TestProperty& test_property) {\n  internal::String key(test_property.key());\n  if (key == \"name\" || key == \"status\" || key == \"time\" || key == \"classname\") {\n    ADD_FAILURE()\n        << \"Reserved key used in RecordProperty(): \"\n        << key\n        << \" ('name', 'status', 'time', and 'classname' are reserved by \"\n        << GTEST_NAME_ << \")\";\n    return false;\n  }\n  return true;\n}\n\n// Clears the object.\nvoid TestResult::Clear() {\n  test_part_results_.clear();\n  test_properties_.clear();\n  death_test_count_ = 0;\n  elapsed_time_ = 0;\n}\n\n// Returns true iff the test failed.\nbool TestResult::Failed() const {\n  for (int i = 0; i < total_part_count(); ++i) {\n    if (GetTestPartResult(i).failed())\n      return true;\n  }\n  return false;\n}\n\n// Returns true iff the test part fatally failed.\nstatic bool TestPartFatallyFailed(const TestPartResult& result) {\n  return result.fatally_failed();\n}\n\n// Returns true iff the test fatally failed.\nbool TestResult::HasFatalFailure() const {\n  return CountIf(test_part_results_, TestPartFatallyFailed) > 0;\n}\n\n// Returns true iff the test part non-fatally failed.\nstatic bool TestPartNonfatallyFailed(const TestPartResult& result) {\n  return result.nonfatally_failed();\n}\n\n// Returns true iff the test has a non-fatal failure.\nbool TestResult::HasNonfatalFailure() const {\n  return CountIf(test_part_results_, TestPartNonfatallyFailed) > 0;\n}\n\n// Gets the number of all test parts.  This is the sum of the number\n// of successful test parts and the number of failed test parts.\nint TestResult::total_part_count() const {\n  return static_cast<int>(test_part_results_.size());\n}\n\n// Returns the number of the test properties.\nint TestResult::test_property_count() const {\n  return static_cast<int>(test_properties_.size());\n}\n\n// class Test\n\n// Creates a Test object.\n\n// The c'tor saves the values of all Google Test flags.\nTest::Test()\n    : gtest_flag_saver_(new internal::GTestFlagSaver) {\n}\n\n// The d'tor restores the values of all Google Test flags.\nTest::~Test() {\n  delete gtest_flag_saver_;\n}\n\n// Sets up the test fixture.\n//\n// A sub-class may override this.\nvoid Test::SetUp() {\n}\n\n// Tears down the test fixture.\n//\n// A sub-class may override this.\nvoid Test::TearDown() {\n}\n\n// Allows user supplied key value pairs to be recorded for later output.\nvoid Test::RecordProperty(const char* key, const char* value) {\n  UnitTest::GetInstance()->RecordPropertyForCurrentTest(key, value);\n}\n\n// Allows user supplied key value pairs to be recorded for later output.\nvoid Test::RecordProperty(const char* key, int value) {\n  Message value_message;\n  value_message << value;\n  RecordProperty(key, value_message.GetString().c_str());\n}\n\nnamespace internal {\n\nvoid ReportFailureInUnknownLocation(TestPartResult::Type result_type,\n                                    const String& message) {\n  // This function is a friend of UnitTest and as such has access to\n  // AddTestPartResult.\n  UnitTest::GetInstance()->AddTestPartResult(\n      result_type,\n      NULL,  // No info about the source file where the exception occurred.\n      -1,    // We have no info on which line caused the exception.\n      message,\n      String());  // No stack trace, either.\n}\n\n}  // namespace internal\n\n// Google Test requires all tests in the same test case to use the same test\n// fixture class.  This function checks if the current test has the\n// same fixture class as the first test in the current test case.  If\n// yes, it returns true; otherwise it generates a Google Test failure and\n// returns false.\nbool Test::HasSameFixtureClass() {\n  internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();\n  const TestCase* const test_case = impl->current_test_case();\n\n  // Info about the first test in the current test case.\n  const TestInfo* const first_test_info = test_case->test_info_list()[0];\n  const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;\n  const char* const first_test_name = first_test_info->name();\n\n  // Info about the current test.\n  const TestInfo* const this_test_info = impl->current_test_info();\n  const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;\n  const char* const this_test_name = this_test_info->name();\n\n  if (this_fixture_id != first_fixture_id) {\n    // Is the first test defined using TEST?\n    const bool first_is_TEST = first_fixture_id == internal::GetTestTypeId();\n    // Is this test defined using TEST?\n    const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId();\n\n    if (first_is_TEST || this_is_TEST) {\n      // The user mixed TEST and TEST_F in this test case - we'll tell\n      // him/her how to fix it.\n\n      // Gets the name of the TEST and the name of the TEST_F.  Note\n      // that first_is_TEST and this_is_TEST cannot both be true, as\n      // the fixture IDs are different for the two tests.\n      const char* const TEST_name =\n          first_is_TEST ? first_test_name : this_test_name;\n      const char* const TEST_F_name =\n          first_is_TEST ? this_test_name : first_test_name;\n\n      ADD_FAILURE()\n          << \"All tests in the same test case must use the same test fixture\\n\"\n          << \"class, so mixing TEST_F and TEST in the same test case is\\n\"\n          << \"illegal.  In test case \" << this_test_info->test_case_name()\n          << \",\\n\"\n          << \"test \" << TEST_F_name << \" is defined using TEST_F but\\n\"\n          << \"test \" << TEST_name << \" is defined using TEST.  You probably\\n\"\n          << \"want to change the TEST to TEST_F or move it to another test\\n\"\n          << \"case.\";\n    } else {\n      // The user defined two fixture classes with the same name in\n      // two namespaces - we'll tell him/her how to fix it.\n      ADD_FAILURE()\n          << \"All tests in the same test case must use the same test fixture\\n\"\n          << \"class.  However, in test case \"\n          << this_test_info->test_case_name() << \",\\n\"\n          << \"you defined test \" << first_test_name\n          << \" and test \" << this_test_name << \"\\n\"\n          << \"using two different test fixture classes.  This can happen if\\n\"\n          << \"the two classes are from different namespaces or translation\\n\"\n          << \"units and have the same name.  You should probably rename one\\n\"\n          << \"of the classes to put the tests into different test cases.\";\n    }\n    return false;\n  }\n\n  return true;\n}\n\n#if GTEST_HAS_SEH\n\n// Adds an \"exception thrown\" fatal failure to the current test.  This\n// function returns its result via an output parameter pointer because VC++\n// prohibits creation of objects with destructors on stack in functions\n// using __try (see error C2712).\nstatic internal::String* FormatSehExceptionMessage(DWORD exception_code,\n                                                   const char* location) {\n  Message message;\n  message << \"SEH exception with code 0x\" << std::setbase(16) <<\n    exception_code << std::setbase(10) << \" thrown in \" << location << \".\";\n\n  return new internal::String(message.GetString());\n}\n\n#endif  // GTEST_HAS_SEH\n\n#if GTEST_HAS_EXCEPTIONS\n\n// Adds an \"exception thrown\" fatal failure to the current test.\nstatic internal::String FormatCxxExceptionMessage(const char* description,\n                                                  const char* location) {\n  Message message;\n  if (description != NULL) {\n    message << \"C++ exception with description \\\"\" << description << \"\\\"\";\n  } else {\n    message << \"Unknown C++ exception\";\n  }\n  message << \" thrown in \" << location << \".\";\n\n  return message.GetString();\n}\n\nstatic internal::String PrintTestPartResultToString(\n    const TestPartResult& test_part_result);\n\n// A failed Google Test assertion will throw an exception of this type when\n// GTEST_FLAG(throw_on_failure) is true (if exceptions are enabled).  We\n// derive it from std::runtime_error, which is for errors presumably\n// detectable only at run time.  Since std::runtime_error inherits from\n// std::exception, many testing frameworks know how to extract and print the\n// message inside it.\nclass GoogleTestFailureException : public ::std::runtime_error {\n public:\n  explicit GoogleTestFailureException(const TestPartResult& failure)\n      : ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {}\n};\n#endif  // GTEST_HAS_EXCEPTIONS\n\nnamespace internal {\n// We put these helper functions in the internal namespace as IBM's xlC\n// compiler rejects the code if they were declared static.\n\n// Runs the given method and handles SEH exceptions it throws, when\n// SEH is supported; returns the 0-value for type Result in case of an\n// SEH exception.  (Microsoft compilers cannot handle SEH and C++\n// exceptions in the same function.  Therefore, we provide a separate\n// wrapper function for handling SEH exceptions.)\ntemplate <class T, typename Result>\nResult HandleSehExceptionsInMethodIfSupported(\n    T* object, Result (T::*method)(), const char* location) {\n#if GTEST_HAS_SEH\n  __try {\n    return (object->*method)();\n  } __except (internal::UnitTestOptions::GTestShouldProcessSEH(  // NOLINT\n      GetExceptionCode())) {\n    // We create the exception message on the heap because VC++ prohibits\n    // creation of objects with destructors on stack in functions using __try\n    // (see error C2712).\n    internal::String* exception_message = FormatSehExceptionMessage(\n        GetExceptionCode(), location);\n    internal::ReportFailureInUnknownLocation(TestPartResult::kFatalFailure,\n                                             *exception_message);\n    delete exception_message;\n    return static_cast<Result>(0);\n  }\n#else\n  (void)location;\n  return (object->*method)();\n#endif  // GTEST_HAS_SEH\n}\n\n// Runs the given method and catches and reports C++ and/or SEH-style\n// exceptions, if they are supported; returns the 0-value for type\n// Result in case of an SEH exception.\ntemplate <class T, typename Result>\nResult HandleExceptionsInMethodIfSupported(\n    T* object, Result (T::*method)(), const char* location) {\n  // NOTE: The user code can affect the way in which Google Test handles\n  // exceptions by setting GTEST_FLAG(catch_exceptions), but only before\n  // RUN_ALL_TESTS() starts. It is technically possible to check the flag\n  // after the exception is caught and either report or re-throw the\n  // exception based on the flag's value:\n  //\n  // try {\n  //   // Perform the test method.\n  // } catch (...) {\n  //   if (GTEST_FLAG(catch_exceptions))\n  //     // Report the exception as failure.\n  //   else\n  //     throw;  // Re-throws the original exception.\n  // }\n  //\n  // However, the purpose of this flag is to allow the program to drop into\n  // the debugger when the exception is thrown. On most platforms, once the\n  // control enters the catch block, the exception origin information is\n  // lost and the debugger will stop the program at the point of the\n  // re-throw in this function -- instead of at the point of the original\n  // throw statement in the code under test.  For this reason, we perform\n  // the check early, sacrificing the ability to affect Google Test's\n  // exception handling in the method where the exception is thrown.\n  if (internal::GetUnitTestImpl()->catch_exceptions()) {\n#if GTEST_HAS_EXCEPTIONS\n    try {\n      return HandleSehExceptionsInMethodIfSupported(object, method, location);\n    } catch (const GoogleTestFailureException&) {  // NOLINT\n      // This exception doesn't originate in code under test. It makes no\n      // sense to report it as a test failure.\n      throw;\n    } catch (const std::exception& e) {  // NOLINT\n      internal::ReportFailureInUnknownLocation(\n          TestPartResult::kFatalFailure,\n          FormatCxxExceptionMessage(e.what(), location));\n    } catch (...) {  // NOLINT\n      internal::ReportFailureInUnknownLocation(\n          TestPartResult::kFatalFailure,\n          FormatCxxExceptionMessage(NULL, location));\n    }\n    return static_cast<Result>(0);\n#else\n    return HandleSehExceptionsInMethodIfSupported(object, method, location);\n#endif  // GTEST_HAS_EXCEPTIONS\n  } else {\n    return (object->*method)();\n  }\n}\n\n}  // namespace internal\n\n// Runs the test and updates the test result.\nvoid Test::Run() {\n  if (!HasSameFixtureClass()) return;\n\n  internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();\n  impl->os_stack_trace_getter()->UponLeavingGTest();\n  internal::HandleExceptionsInMethodIfSupported(this, &Test::SetUp, \"SetUp()\");\n  // We will run the test only if SetUp() was successful.\n  if (!HasFatalFailure()) {\n    impl->os_stack_trace_getter()->UponLeavingGTest();\n    internal::HandleExceptionsInMethodIfSupported(\n        this, &Test::TestBody, \"the test body\");\n  }\n\n  // However, we want to clean up as much as possible.  Hence we will\n  // always call TearDown(), even if SetUp() or the test body has\n  // failed.\n  impl->os_stack_trace_getter()->UponLeavingGTest();\n  internal::HandleExceptionsInMethodIfSupported(\n      this, &Test::TearDown, \"TearDown()\");\n}\n\n// Returns true iff the current test has a fatal failure.\nbool Test::HasFatalFailure() {\n  return internal::GetUnitTestImpl()->current_test_result()->HasFatalFailure();\n}\n\n// Returns true iff the current test has a non-fatal failure.\nbool Test::HasNonfatalFailure() {\n  return internal::GetUnitTestImpl()->current_test_result()->\n      HasNonfatalFailure();\n}\n\n// class TestInfo\n\n// Constructs a TestInfo object. It assumes ownership of the test factory\n// object.\n// TODO(vladl@google.com): Make a_test_case_name and a_name const string&'s\n// to signify they cannot be NULLs.\nTestInfo::TestInfo(const char* a_test_case_name,\n                   const char* a_name,\n                   const char* a_type_param,\n                   const char* a_value_param,\n                   internal::TypeId fixture_class_id,\n                   internal::TestFactoryBase* factory)\n    : test_case_name_(a_test_case_name),\n      name_(a_name),\n      type_param_(a_type_param ? new std::string(a_type_param) : NULL),\n      value_param_(a_value_param ? new std::string(a_value_param) : NULL),\n      fixture_class_id_(fixture_class_id),\n      should_run_(false),\n      is_disabled_(false),\n      matches_filter_(false),\n      factory_(factory),\n      result_() {}\n\n// Destructs a TestInfo object.\nTestInfo::~TestInfo() { delete factory_; }\n\nnamespace internal {\n\n// Creates a new TestInfo object and registers it with Google Test;\n// returns the created object.\n//\n// Arguments:\n//\n//   test_case_name:   name of the test case\n//   name:             name of the test\n//   type_param:       the name of the test's type parameter, or NULL if\n//                     this is not a typed or a type-parameterized test.\n//   value_param:      text representation of the test's value parameter,\n//                     or NULL if this is not a value-parameterized test.\n//   fixture_class_id: ID of the test fixture class\n//   set_up_tc:        pointer to the function that sets up the test case\n//   tear_down_tc:     pointer to the function that tears down the test case\n//   factory:          pointer to the factory that creates a test object.\n//                     The newly created TestInfo instance will assume\n//                     ownership of the factory object.\nTestInfo* MakeAndRegisterTestInfo(\n    const char* test_case_name, const char* name,\n    const char* type_param,\n    const char* value_param,\n    TypeId fixture_class_id,\n    SetUpTestCaseFunc set_up_tc,\n    TearDownTestCaseFunc tear_down_tc,\n    TestFactoryBase* factory) {\n  TestInfo* const test_info =\n      new TestInfo(test_case_name, name, type_param, value_param,\n                   fixture_class_id, factory);\n  GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info);\n  return test_info;\n}\n\n#if GTEST_HAS_PARAM_TEST\nvoid ReportInvalidTestCaseType(const char* test_case_name,\n                               const char* file, int line) {\n  Message errors;\n  errors\n      << \"Attempted redefinition of test case \" << test_case_name << \".\\n\"\n      << \"All tests in the same test case must use the same test fixture\\n\"\n      << \"class.  However, in test case \" << test_case_name << \", you tried\\n\"\n      << \"to define a test using a fixture class different from the one\\n\"\n      << \"used earlier. This can happen if the two fixture classes are\\n\"\n      << \"from different namespaces and have the same name. You should\\n\"\n      << \"probably rename one of the classes to put the tests into different\\n\"\n      << \"test cases.\";\n\n  fprintf(stderr, \"%s %s\", FormatFileLocation(file, line).c_str(),\n          errors.GetString().c_str());\n}\n#endif  // GTEST_HAS_PARAM_TEST\n\n}  // namespace internal\n\nnamespace {\n\n// A predicate that checks the test name of a TestInfo against a known\n// value.\n//\n// This is used for implementation of the TestCase class only.  We put\n// it in the anonymous namespace to prevent polluting the outer\n// namespace.\n//\n// TestNameIs is copyable.\nclass TestNameIs {\n public:\n  // Constructor.\n  //\n  // TestNameIs has NO default constructor.\n  explicit TestNameIs(const char* name)\n      : name_(name) {}\n\n  // Returns true iff the test name of test_info matches name_.\n  bool operator()(const TestInfo * test_info) const {\n    return test_info && internal::String(test_info->name()).Compare(name_) == 0;\n  }\n\n private:\n  internal::String name_;\n};\n\n}  // namespace\n\nnamespace internal {\n\n// This method expands all parameterized tests registered with macros TEST_P\n// and INSTANTIATE_TEST_CASE_P into regular tests and registers those.\n// This will be done just once during the program runtime.\nvoid UnitTestImpl::RegisterParameterizedTests() {\n#if GTEST_HAS_PARAM_TEST\n  if (!parameterized_tests_registered_) {\n    parameterized_test_registry_.RegisterTests();\n    parameterized_tests_registered_ = true;\n  }\n#endif\n}\n\n}  // namespace internal\n\n// Creates the test object, runs it, records its result, and then\n// deletes it.\nvoid TestInfo::Run() {\n  if (!should_run_) return;\n\n  // Tells UnitTest where to store test result.\n  internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();\n  impl->set_current_test_info(this);\n\n  TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();\n\n  // Notifies the unit test event listeners that a test is about to start.\n  repeater->OnTestStart(*this);\n\n  const TimeInMillis start = internal::GetTimeInMillis();\n\n  impl->os_stack_trace_getter()->UponLeavingGTest();\n\n  // Creates the test object.\n  Test* const test = internal::HandleExceptionsInMethodIfSupported(\n      factory_, &internal::TestFactoryBase::CreateTest,\n      \"the test fixture's constructor\");\n\n  // Runs the test only if the test object was created and its\n  // constructor didn't generate a fatal failure.\n  if ((test != NULL) && !Test::HasFatalFailure()) {\n    // This doesn't throw as all user code that can throw are wrapped into\n    // exception handling code.\n    test->Run();\n  }\n\n  // Deletes the test object.\n  impl->os_stack_trace_getter()->UponLeavingGTest();\n  internal::HandleExceptionsInMethodIfSupported(\n      test, &Test::DeleteSelf_, \"the test fixture's destructor\");\n\n  result_.set_elapsed_time(internal::GetTimeInMillis() - start);\n\n  // Notifies the unit test event listener that a test has just finished.\n  repeater->OnTestEnd(*this);\n\n  // Tells UnitTest to stop associating assertion results to this\n  // test.\n  impl->set_current_test_info(NULL);\n}\n\n// class TestCase\n\n// Gets the number of successful tests in this test case.\nint TestCase::successful_test_count() const {\n  return CountIf(test_info_list_, TestPassed);\n}\n\n// Gets the number of failed tests in this test case.\nint TestCase::failed_test_count() const {\n  return CountIf(test_info_list_, TestFailed);\n}\n\nint TestCase::disabled_test_count() const {\n  return CountIf(test_info_list_, TestDisabled);\n}\n\n// Get the number of tests in this test case that should run.\nint TestCase::test_to_run_count() const {\n  return CountIf(test_info_list_, ShouldRunTest);\n}\n\n// Gets the number of all tests.\nint TestCase::total_test_count() const {\n  return static_cast<int>(test_info_list_.size());\n}\n\n// Creates a TestCase with the given name.\n//\n// Arguments:\n//\n//   name:         name of the test case\n//   a_type_param: the name of the test case's type parameter, or NULL if\n//                 this is not a typed or a type-parameterized test case.\n//   set_up_tc:    pointer to the function that sets up the test case\n//   tear_down_tc: pointer to the function that tears down the test case\nTestCase::TestCase(const char* a_name, const char* a_type_param,\n                   Test::SetUpTestCaseFunc set_up_tc,\n                   Test::TearDownTestCaseFunc tear_down_tc)\n    : name_(a_name),\n      type_param_(a_type_param ? new std::string(a_type_param) : NULL),\n      set_up_tc_(set_up_tc),\n      tear_down_tc_(tear_down_tc),\n      should_run_(false),\n      elapsed_time_(0) {\n}\n\n// Destructor of TestCase.\nTestCase::~TestCase() {\n  // Deletes every Test in the collection.\n  ForEach(test_info_list_, internal::Delete<TestInfo>);\n}\n\n// Returns the i-th test among all the tests. i can range from 0 to\n// total_test_count() - 1. If i is not in that range, returns NULL.\nconst TestInfo* TestCase::GetTestInfo(int i) const {\n  const int index = GetElementOr(test_indices_, i, -1);\n  return index < 0 ? NULL : test_info_list_[index];\n}\n\n// Returns the i-th test among all the tests. i can range from 0 to\n// total_test_count() - 1. If i is not in that range, returns NULL.\nTestInfo* TestCase::GetMutableTestInfo(int i) {\n  const int index = GetElementOr(test_indices_, i, -1);\n  return index < 0 ? NULL : test_info_list_[index];\n}\n\n// Adds a test to this test case.  Will delete the test upon\n// destruction of the TestCase object.\nvoid TestCase::AddTestInfo(TestInfo * test_info) {\n  test_info_list_.push_back(test_info);\n  test_indices_.push_back(static_cast<int>(test_indices_.size()));\n}\n\n// Runs every test in this TestCase.\nvoid TestCase::Run() {\n  if (!should_run_) return;\n\n  internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();\n  impl->set_current_test_case(this);\n\n  TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();\n\n  repeater->OnTestCaseStart(*this);\n  impl->os_stack_trace_getter()->UponLeavingGTest();\n  internal::HandleExceptionsInMethodIfSupported(\n      this, &TestCase::RunSetUpTestCase, \"SetUpTestCase()\");\n\n  const internal::TimeInMillis start = internal::GetTimeInMillis();\n  for (int i = 0; i < total_test_count(); i++) {\n    GetMutableTestInfo(i)->Run();\n  }\n  elapsed_time_ = internal::GetTimeInMillis() - start;\n\n  impl->os_stack_trace_getter()->UponLeavingGTest();\n  internal::HandleExceptionsInMethodIfSupported(\n      this, &TestCase::RunTearDownTestCase, \"TearDownTestCase()\");\n\n  repeater->OnTestCaseEnd(*this);\n  impl->set_current_test_case(NULL);\n}\n\n// Clears the results of all tests in this test case.\nvoid TestCase::ClearResult() {\n  ForEach(test_info_list_, TestInfo::ClearTestResult);\n}\n\n// Shuffles the tests in this test case.\nvoid TestCase::ShuffleTests(internal::Random* random) {\n  Shuffle(random, &test_indices_);\n}\n\n// Restores the test order to before the first shuffle.\nvoid TestCase::UnshuffleTests() {\n  for (size_t i = 0; i < test_indices_.size(); i++) {\n    test_indices_[i] = static_cast<int>(i);\n  }\n}\n\n// Formats a countable noun.  Depending on its quantity, either the\n// singular form or the plural form is used. e.g.\n//\n// FormatCountableNoun(1, \"formula\", \"formuli\") returns \"1 formula\".\n// FormatCountableNoun(5, \"book\", \"books\") returns \"5 books\".\nstatic internal::String FormatCountableNoun(int count,\n                                            const char * singular_form,\n                                            const char * plural_form) {\n  return internal::String::Format(\"%d %s\", count,\n                                  count == 1 ? singular_form : plural_form);\n}\n\n// Formats the count of tests.\nstatic internal::String FormatTestCount(int test_count) {\n  return FormatCountableNoun(test_count, \"test\", \"tests\");\n}\n\n// Formats the count of test cases.\nstatic internal::String FormatTestCaseCount(int test_case_count) {\n  return FormatCountableNoun(test_case_count, \"test case\", \"test cases\");\n}\n\n// Converts a TestPartResult::Type enum to human-friendly string\n// representation.  Both kNonFatalFailure and kFatalFailure are translated\n// to \"Failure\", as the user usually doesn't care about the difference\n// between the two when viewing the test result.\nstatic const char * TestPartResultTypeToString(TestPartResult::Type type) {\n  switch (type) {\n    case TestPartResult::kSuccess:\n      return \"Success\";\n\n    case TestPartResult::kNonFatalFailure:\n    case TestPartResult::kFatalFailure:\n#ifdef _MSC_VER\n      return \"error: \";\n#else\n      return \"Failure\\n\";\n#endif\n    default:\n      return \"Unknown result type\";\n  }\n}\n\n// Prints a TestPartResult to a String.\nstatic internal::String PrintTestPartResultToString(\n    const TestPartResult& test_part_result) {\n  return (Message()\n          << internal::FormatFileLocation(test_part_result.file_name(),\n                                          test_part_result.line_number())\n          << \" \" << TestPartResultTypeToString(test_part_result.type())\n          << test_part_result.message()).GetString();\n}\n\n// Prints a TestPartResult.\nstatic void PrintTestPartResult(const TestPartResult& test_part_result) {\n  const internal::String& result =\n      PrintTestPartResultToString(test_part_result);\n  printf(\"%s\\n\", result.c_str());\n  fflush(stdout);\n  // If the test program runs in Visual Studio or a debugger, the\n  // following statements add the test part result message to the Output\n  // window such that the user can double-click on it to jump to the\n  // corresponding source code location; otherwise they do nothing.\n#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE\n  // We don't call OutputDebugString*() on Windows Mobile, as printing\n  // to stdout is done by OutputDebugString() there already - we don't\n  // want the same message printed twice.\n  ::OutputDebugStringA(result.c_str());\n  ::OutputDebugStringA(\"\\n\");\n#endif\n}\n\n// class PrettyUnitTestResultPrinter\n\nnamespace internal {\n\nenum GTestColor {\n  COLOR_DEFAULT,\n  COLOR_RED,\n  COLOR_GREEN,\n  COLOR_YELLOW\n};\n\n#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE\n\n// Returns the character attribute for the given color.\nWORD GetColorAttribute(GTestColor color) {\n  switch (color) {\n    case COLOR_RED:    return FOREGROUND_RED;\n    case COLOR_GREEN:  return FOREGROUND_GREEN;\n    case COLOR_YELLOW: return FOREGROUND_RED | FOREGROUND_GREEN;\n    default:           return 0;\n  }\n}\n\n#else\n\n// Returns the ANSI color code for the given color.  COLOR_DEFAULT is\n// an invalid input.\nconst char* GetAnsiColorCode(GTestColor color) {\n  switch (color) {\n    case COLOR_RED:     return \"1\";\n    case COLOR_GREEN:   return \"2\";\n    case COLOR_YELLOW:  return \"3\";\n    default:            return NULL;\n  };\n}\n\n#endif  // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE\n\n// Returns true iff Google Test should use colors in the output.\nbool ShouldUseColor(bool stdout_is_tty) {\n  const char* const gtest_color = GTEST_FLAG(color).c_str();\n\n  if (String::CaseInsensitiveCStringEquals(gtest_color, \"auto\")) {\n#if GTEST_OS_WINDOWS\n    // On Windows the TERM variable is usually not set, but the\n    // console there does support colors.\n    return stdout_is_tty;\n#else\n    // On non-Windows platforms, we rely on the TERM variable.\n    const char* const term = posix::GetEnv(\"TERM\");\n    const bool term_supports_color =\n        String::CStringEquals(term, \"xterm\") ||\n        String::CStringEquals(term, \"xterm-color\") ||\n        String::CStringEquals(term, \"xterm-256color\") ||\n        String::CStringEquals(term, \"screen\") ||\n        String::CStringEquals(term, \"linux\") ||\n        String::CStringEquals(term, \"cygwin\");\n    return stdout_is_tty && term_supports_color;\n#endif  // GTEST_OS_WINDOWS\n  }\n\n  return String::CaseInsensitiveCStringEquals(gtest_color, \"yes\") ||\n      String::CaseInsensitiveCStringEquals(gtest_color, \"true\") ||\n      String::CaseInsensitiveCStringEquals(gtest_color, \"t\") ||\n      String::CStringEquals(gtest_color, \"1\");\n  // We take \"yes\", \"true\", \"t\", and \"1\" as meaning \"yes\".  If the\n  // value is neither one of these nor \"auto\", we treat it as \"no\" to\n  // be conservative.\n}\n\n// Helpers for printing colored strings to stdout. Note that on Windows, we\n// cannot simply emit special characters and have the terminal change colors.\n// This routine must actually emit the characters rather than return a string\n// that would be colored when printed, as can be done on Linux.\nvoid ColoredPrintf(GTestColor color, const char* fmt, ...) {\n  va_list args;\n  va_start(args, fmt);\n\n#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS\n  const bool use_color = false;\n#else\n  static const bool in_color_mode =\n      ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0);\n  const bool use_color = in_color_mode && (color != COLOR_DEFAULT);\n#endif  // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS\n  // The '!= 0' comparison is necessary to satisfy MSVC 7.1.\n\n  if (!use_color) {\n    vprintf(fmt, args);\n    va_end(args);\n    return;\n  }\n\n#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE\n  const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);\n\n  // Gets the current text color.\n  CONSOLE_SCREEN_BUFFER_INFO buffer_info;\n  GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);\n  const WORD old_color_attrs = buffer_info.wAttributes;\n\n  // We need to flush the stream buffers into the console before each\n  // SetConsoleTextAttribute call lest it affect the text that is already\n  // printed but has not yet reached the console.\n  fflush(stdout);\n  SetConsoleTextAttribute(stdout_handle,\n                          GetColorAttribute(color) | FOREGROUND_INTENSITY);\n  vprintf(fmt, args);\n\n  fflush(stdout);\n  // Restores the text color.\n  SetConsoleTextAttribute(stdout_handle, old_color_attrs);\n#else\n  printf(\"\\033[0;3%sm\", GetAnsiColorCode(color));\n  vprintf(fmt, args);\n  printf(\"\\033[m\");  // Resets the terminal to default.\n#endif  // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE\n  va_end(args);\n}\n\nvoid PrintFullTestCommentIfPresent(const TestInfo& test_info) {\n  const char* const type_param = test_info.type_param();\n  const char* const value_param = test_info.value_param();\n\n  if (type_param != NULL || value_param != NULL) {\n    printf(\", where \");\n    if (type_param != NULL) {\n      printf(\"TypeParam = %s\", type_param);\n      if (value_param != NULL)\n        printf(\" and \");\n    }\n    if (value_param != NULL) {\n      printf(\"GetParam() = %s\", value_param);\n    }\n  }\n}\n\n// This class implements the TestEventListener interface.\n//\n// Class PrettyUnitTestResultPrinter is copyable.\nclass PrettyUnitTestResultPrinter : public TestEventListener {\n public:\n  PrettyUnitTestResultPrinter() {}\n  static void PrintTestName(const char * test_case, const char * test) {\n    printf(\"%s.%s\", test_case, test);\n  }\n\n  // The following methods override what's in the TestEventListener class.\n  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}\n  virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);\n  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);\n  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}\n  virtual void OnTestCaseStart(const TestCase& test_case);\n  virtual void OnTestStart(const TestInfo& test_info);\n  virtual void OnTestPartResult(const TestPartResult& result);\n  virtual void OnTestEnd(const TestInfo& test_info);\n  virtual void OnTestCaseEnd(const TestCase& test_case);\n  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);\n  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}\n  virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);\n  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}\n\n private:\n  static void PrintFailedTests(const UnitTest& unit_test);\n\n  internal::String test_case_name_;\n};\n\n  // Fired before each iteration of tests starts.\nvoid PrettyUnitTestResultPrinter::OnTestIterationStart(\n    const UnitTest& unit_test, int iteration) {\n  if (GTEST_FLAG(repeat) != 1)\n    printf(\"\\nRepeating all tests (iteration %d) . . .\\n\\n\", iteration + 1);\n\n  const char* const filter = GTEST_FLAG(filter).c_str();\n\n  // Prints the filter if it's not *.  This reminds the user that some\n  // tests may be skipped.\n  if (!internal::String::CStringEquals(filter, kUniversalFilter)) {\n    ColoredPrintf(COLOR_YELLOW,\n                  \"Note: %s filter = %s\\n\", GTEST_NAME_, filter);\n  }\n\n  if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) {\n    const Int32 shard_index = Int32FromEnvOrDie(kTestShardIndex, -1);\n    ColoredPrintf(COLOR_YELLOW,\n                  \"Note: This is test shard %d of %s.\\n\",\n                  static_cast<int>(shard_index) + 1,\n                  internal::posix::GetEnv(kTestTotalShards));\n  }\n\n  if (GTEST_FLAG(shuffle)) {\n    ColoredPrintf(COLOR_YELLOW,\n                  \"Note: Randomizing tests' orders with a seed of %d .\\n\",\n                  unit_test.random_seed());\n  }\n\n  ColoredPrintf(COLOR_GREEN,  \"[==========] \");\n  printf(\"Running %s from %s.\\n\",\n         FormatTestCount(unit_test.test_to_run_count()).c_str(),\n         FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str());\n  fflush(stdout);\n}\n\nvoid PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(\n    const UnitTest& /*unit_test*/) {\n  ColoredPrintf(COLOR_GREEN,  \"[----------] \");\n  printf(\"Global test environment set-up.\\n\");\n  fflush(stdout);\n}\n\nvoid PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) {\n  test_case_name_ = test_case.name();\n  const internal::String counts =\n      FormatCountableNoun(test_case.test_to_run_count(), \"test\", \"tests\");\n  ColoredPrintf(COLOR_GREEN, \"[----------] \");\n  printf(\"%s from %s\", counts.c_str(), test_case_name_.c_str());\n  if (test_case.type_param() == NULL) {\n    printf(\"\\n\");\n  } else {\n    printf(\", where TypeParam = %s\\n\", test_case.type_param());\n  }\n  fflush(stdout);\n}\n\nvoid PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {\n  ColoredPrintf(COLOR_GREEN,  \"[ RUN      ] \");\n  PrintTestName(test_case_name_.c_str(), test_info.name());\n  printf(\"\\n\");\n  fflush(stdout);\n}\n\n// Called after an assertion failure.\nvoid PrettyUnitTestResultPrinter::OnTestPartResult(\n    const TestPartResult& result) {\n  // If the test part succeeded, we don't need to do anything.\n  if (result.type() == TestPartResult::kSuccess)\n    return;\n\n  // Print failure message from the assertion (e.g. expected this and got that).\n  PrintTestPartResult(result);\n  fflush(stdout);\n}\n\nvoid PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {\n  if (test_info.result()->Passed()) {\n    ColoredPrintf(COLOR_GREEN, \"[       OK ] \");\n  } else {\n    ColoredPrintf(COLOR_RED, \"[  FAILED  ] \");\n  }\n  PrintTestName(test_case_name_.c_str(), test_info.name());\n  if (test_info.result()->Failed())\n    PrintFullTestCommentIfPresent(test_info);\n\n  if (GTEST_FLAG(print_time)) {\n    printf(\" (%s ms)\\n\", internal::StreamableToString(\n           test_info.result()->elapsed_time()).c_str());\n  } else {\n    printf(\"\\n\");\n  }\n  fflush(stdout);\n}\n\nvoid PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) {\n  if (!GTEST_FLAG(print_time)) return;\n\n  test_case_name_ = test_case.name();\n  const internal::String counts =\n      FormatCountableNoun(test_case.test_to_run_count(), \"test\", \"tests\");\n  ColoredPrintf(COLOR_GREEN, \"[----------] \");\n  printf(\"%s from %s (%s ms total)\\n\\n\",\n         counts.c_str(), test_case_name_.c_str(),\n         internal::StreamableToString(test_case.elapsed_time()).c_str());\n  fflush(stdout);\n}\n\nvoid PrettyUnitTestResultPrinter::OnEnvironmentsTearDownStart(\n    const UnitTest& /*unit_test*/) {\n  ColoredPrintf(COLOR_GREEN,  \"[----------] \");\n  printf(\"Global test environment tear-down\\n\");\n  fflush(stdout);\n}\n\n// Internal helper for printing the list of failed tests.\nvoid PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) {\n  const int failed_test_count = unit_test.failed_test_count();\n  if (failed_test_count == 0) {\n    return;\n  }\n\n  for (int i = 0; i < unit_test.total_test_case_count(); ++i) {\n    const TestCase& test_case = *unit_test.GetTestCase(i);\n    if (!test_case.should_run() || (test_case.failed_test_count() == 0)) {\n      continue;\n    }\n    for (int j = 0; j < test_case.total_test_count(); ++j) {\n      const TestInfo& test_info = *test_case.GetTestInfo(j);\n      if (!test_info.should_run() || test_info.result()->Passed()) {\n        continue;\n      }\n      ColoredPrintf(COLOR_RED, \"[  FAILED  ] \");\n      printf(\"%s.%s\", test_case.name(), test_info.name());\n      PrintFullTestCommentIfPresent(test_info);\n      printf(\"\\n\");\n    }\n  }\n}\n\nvoid PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,\n                                                     int /*iteration*/) {\n  ColoredPrintf(COLOR_GREEN,  \"[==========] \");\n  printf(\"%s from %s ran.\",\n         FormatTestCount(unit_test.test_to_run_count()).c_str(),\n         FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str());\n  if (GTEST_FLAG(print_time)) {\n    printf(\" (%s ms total)\",\n           internal::StreamableToString(unit_test.elapsed_time()).c_str());\n  }\n  printf(\"\\n\");\n  ColoredPrintf(COLOR_GREEN,  \"[  PASSED  ] \");\n  printf(\"%s.\\n\", FormatTestCount(unit_test.successful_test_count()).c_str());\n\n  int num_failures = unit_test.failed_test_count();\n  if (!unit_test.Passed()) {\n    const int failed_test_count = unit_test.failed_test_count();\n    ColoredPrintf(COLOR_RED,  \"[  FAILED  ] \");\n    printf(\"%s, listed below:\\n\", FormatTestCount(failed_test_count).c_str());\n    PrintFailedTests(unit_test);\n    printf(\"\\n%2d FAILED %s\\n\", num_failures,\n                        num_failures == 1 ? \"TEST\" : \"TESTS\");\n  }\n\n  int num_disabled = unit_test.disabled_test_count();\n  if (num_disabled && !GTEST_FLAG(also_run_disabled_tests)) {\n    if (!num_failures) {\n      printf(\"\\n\");  // Add a spacer if no FAILURE banner is displayed.\n    }\n    ColoredPrintf(COLOR_YELLOW,\n                  \"  YOU HAVE %d DISABLED %s\\n\\n\",\n                  num_disabled,\n                  num_disabled == 1 ? \"TEST\" : \"TESTS\");\n  }\n  // Ensure that Google Test output is printed before, e.g., heapchecker output.\n  fflush(stdout);\n}\n\n// End PrettyUnitTestResultPrinter\n\n// class TestEventRepeater\n//\n// This class forwards events to other event listeners.\nclass TestEventRepeater : public TestEventListener {\n public:\n  TestEventRepeater() : forwarding_enabled_(true) {}\n  virtual ~TestEventRepeater();\n  void Append(TestEventListener *listener);\n  TestEventListener* Release(TestEventListener* listener);\n\n  // Controls whether events will be forwarded to listeners_. Set to false\n  // in death test child processes.\n  bool forwarding_enabled() const { return forwarding_enabled_; }\n  void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; }\n\n  virtual void OnTestProgramStart(const UnitTest& unit_test);\n  virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);\n  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);\n  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test);\n  virtual void OnTestCaseStart(const TestCase& test_case);\n  virtual void OnTestStart(const TestInfo& test_info);\n  virtual void OnTestPartResult(const TestPartResult& result);\n  virtual void OnTestEnd(const TestInfo& test_info);\n  virtual void OnTestCaseEnd(const TestCase& test_case);\n  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);\n  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test);\n  virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);\n  virtual void OnTestProgramEnd(const UnitTest& unit_test);\n\n private:\n  // Controls whether events will be forwarded to listeners_. Set to false\n  // in death test child processes.\n  bool forwarding_enabled_;\n  // The list of listeners that receive events.\n  std::vector<TestEventListener*> listeners_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater);\n};\n\nTestEventRepeater::~TestEventRepeater() {\n  ForEach(listeners_, Delete<TestEventListener>);\n}\n\nvoid TestEventRepeater::Append(TestEventListener *listener) {\n  listeners_.push_back(listener);\n}\n\n// TODO(vladl@google.com): Factor the search functionality into Vector::Find.\nTestEventListener* TestEventRepeater::Release(TestEventListener *listener) {\n  for (size_t i = 0; i < listeners_.size(); ++i) {\n    if (listeners_[i] == listener) {\n      listeners_.erase(listeners_.begin() + i);\n      return listener;\n    }\n  }\n\n  return NULL;\n}\n\n// Since most methods are very similar, use macros to reduce boilerplate.\n// This defines a member that forwards the call to all listeners.\n#define GTEST_REPEATER_METHOD_(Name, Type) \\\nvoid TestEventRepeater::Name(const Type& parameter) { \\\n  if (forwarding_enabled_) { \\\n    for (size_t i = 0; i < listeners_.size(); i++) { \\\n      listeners_[i]->Name(parameter); \\\n    } \\\n  } \\\n}\n// This defines a member that forwards the call to all listeners in reverse\n// order.\n#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \\\nvoid TestEventRepeater::Name(const Type& parameter) { \\\n  if (forwarding_enabled_) { \\\n    for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) { \\\n      listeners_[i]->Name(parameter); \\\n    } \\\n  } \\\n}\n\nGTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest)\nGTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest)\nGTEST_REPEATER_METHOD_(OnTestCaseStart, TestCase)\nGTEST_REPEATER_METHOD_(OnTestStart, TestInfo)\nGTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult)\nGTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest)\nGTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest)\nGTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest)\nGTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo)\nGTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestCase)\nGTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest)\n\n#undef GTEST_REPEATER_METHOD_\n#undef GTEST_REVERSE_REPEATER_METHOD_\n\nvoid TestEventRepeater::OnTestIterationStart(const UnitTest& unit_test,\n                                             int iteration) {\n  if (forwarding_enabled_) {\n    for (size_t i = 0; i < listeners_.size(); i++) {\n      listeners_[i]->OnTestIterationStart(unit_test, iteration);\n    }\n  }\n}\n\nvoid TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test,\n                                           int iteration) {\n  if (forwarding_enabled_) {\n    for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) {\n      listeners_[i]->OnTestIterationEnd(unit_test, iteration);\n    }\n  }\n}\n\n// End TestEventRepeater\n\n// This class generates an XML output file.\nclass XmlUnitTestResultPrinter : public EmptyTestEventListener {\n public:\n  explicit XmlUnitTestResultPrinter(const char* output_file);\n\n  virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);\n\n private:\n  // Is c a whitespace character that is normalized to a space character\n  // when it appears in an XML attribute value?\n  static bool IsNormalizableWhitespace(char c) {\n    return c == 0x9 || c == 0xA || c == 0xD;\n  }\n\n  // May c appear in a well-formed XML document?\n  static bool IsValidXmlCharacter(char c) {\n    return IsNormalizableWhitespace(c) || c >= 0x20;\n  }\n\n  // Returns an XML-escaped copy of the input string str.  If\n  // is_attribute is true, the text is meant to appear as an attribute\n  // value, and normalizable whitespace is preserved by replacing it\n  // with character references.\n  static String EscapeXml(const char* str, bool is_attribute);\n\n  // Returns the given string with all characters invalid in XML removed.\n  static string RemoveInvalidXmlCharacters(const string& str);\n\n  // Convenience wrapper around EscapeXml when str is an attribute value.\n  static String EscapeXmlAttribute(const char* str) {\n    return EscapeXml(str, true);\n  }\n\n  // Convenience wrapper around EscapeXml when str is not an attribute value.\n  static String EscapeXmlText(const char* str) { return EscapeXml(str, false); }\n\n  // Streams an XML CDATA section, escaping invalid CDATA sequences as needed.\n  static void OutputXmlCDataSection(::std::ostream* stream, const char* data);\n\n  // Streams an XML representation of a TestInfo object.\n  static void OutputXmlTestInfo(::std::ostream* stream,\n                                const char* test_case_name,\n                                const TestInfo& test_info);\n\n  // Prints an XML representation of a TestCase object\n  static void PrintXmlTestCase(FILE* out, const TestCase& test_case);\n\n  // Prints an XML summary of unit_test to output stream out.\n  static void PrintXmlUnitTest(FILE* out, const UnitTest& unit_test);\n\n  // Produces a string representing the test properties in a result as space\n  // delimited XML attributes based on the property key=\"value\" pairs.\n  // When the String is not empty, it includes a space at the beginning,\n  // to delimit this attribute from prior attributes.\n  static String TestPropertiesAsXmlAttributes(const TestResult& result);\n\n  // The output file.\n  const String output_file_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter);\n};\n\n// Creates a new XmlUnitTestResultPrinter.\nXmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)\n    : output_file_(output_file) {\n  if (output_file_.c_str() == NULL || output_file_.empty()) {\n    fprintf(stderr, \"XML output file may not be null\\n\");\n    fflush(stderr);\n    exit(EXIT_FAILURE);\n  }\n}\n\n// Called after the unit test ends.\nvoid XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,\n                                                  int /*iteration*/) {\n  FILE* xmlout = NULL;\n  FilePath output_file(output_file_);\n  FilePath output_dir(output_file.RemoveFileName());\n\n  if (output_dir.CreateDirectoriesRecursively()) {\n    xmlout = posix::FOpen(output_file_.c_str(), \"w\");\n  }\n  if (xmlout == NULL) {\n    // TODO(wan): report the reason of the failure.\n    //\n    // We don't do it for now as:\n    //\n    //   1. There is no urgent need for it.\n    //   2. It's a bit involved to make the errno variable thread-safe on\n    //      all three operating systems (Linux, Windows, and Mac OS).\n    //   3. To interpret the meaning of errno in a thread-safe way,\n    //      we need the strerror_r() function, which is not available on\n    //      Windows.\n    fprintf(stderr,\n            \"Unable to open file \\\"%s\\\"\\n\",\n            output_file_.c_str());\n    fflush(stderr);\n    exit(EXIT_FAILURE);\n  }\n  PrintXmlUnitTest(xmlout, unit_test);\n  fclose(xmlout);\n}\n\n// Returns an XML-escaped copy of the input string str.  If is_attribute\n// is true, the text is meant to appear as an attribute value, and\n// normalizable whitespace is preserved by replacing it with character\n// references.\n//\n// Invalid XML characters in str, if any, are stripped from the output.\n// It is expected that most, if not all, of the text processed by this\n// module will consist of ordinary English text.\n// If this module is ever modified to produce version 1.1 XML output,\n// most invalid characters can be retained using character references.\n// TODO(wan): It might be nice to have a minimally invasive, human-readable\n// escaping scheme for invalid characters, rather than dropping them.\nString XmlUnitTestResultPrinter::EscapeXml(const char* str, bool is_attribute) {\n  Message m;\n\n  if (str != NULL) {\n    for (const char* src = str; *src; ++src) {\n      switch (*src) {\n        case '<':\n          m << \"&lt;\";\n          break;\n        case '>':\n          m << \"&gt;\";\n          break;\n        case '&':\n          m << \"&amp;\";\n          break;\n        case '\\'':\n          if (is_attribute)\n            m << \"&apos;\";\n          else\n            m << '\\'';\n          break;\n        case '\"':\n          if (is_attribute)\n            m << \"&quot;\";\n          else\n            m << '\"';\n          break;\n        default:\n          if (IsValidXmlCharacter(*src)) {\n            if (is_attribute && IsNormalizableWhitespace(*src))\n              m << String::Format(\"&#x%02X;\", unsigned(*src));\n            else\n              m << *src;\n          }\n          break;\n      }\n    }\n  }\n\n  return m.GetString();\n}\n\n// Returns the given string with all characters invalid in XML removed.\n// Currently invalid characters are dropped from the string. An\n// alternative is to replace them with certain characters such as . or ?.\nstring XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(const string& str) {\n  string output;\n  output.reserve(str.size());\n  for (string::const_iterator it = str.begin(); it != str.end(); ++it)\n    if (IsValidXmlCharacter(*it))\n      output.push_back(*it);\n\n  return output;\n}\n\n// The following routines generate an XML representation of a UnitTest\n// object.\n//\n// This is how Google Test concepts map to the DTD:\n//\n// <testsuites name=\"AllTests\">        <-- corresponds to a UnitTest object\n//   <testsuite name=\"testcase-name\">  <-- corresponds to a TestCase object\n//     <testcase name=\"test-name\">     <-- corresponds to a TestInfo object\n//       <failure message=\"...\">...</failure>\n//       <failure message=\"...\">...</failure>\n//       <failure message=\"...\">...</failure>\n//                                     <-- individual assertion failures\n//     </testcase>\n//   </testsuite>\n// </testsuites>\n\n// Formats the given time in milliseconds as seconds.\nstd::string FormatTimeInMillisAsSeconds(TimeInMillis ms) {\n  ::std::stringstream ss;\n  ss << ms/1000.0;\n  return ss.str();\n}\n\n// Streams an XML CDATA section, escaping invalid CDATA sequences as needed.\nvoid XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream,\n                                                     const char* data) {\n  const char* segment = data;\n  *stream << \"<![CDATA[\";\n  for (;;) {\n    const char* const next_segment = strstr(segment, \"]]>\");\n    if (next_segment != NULL) {\n      stream->write(\n          segment, static_cast<std::streamsize>(next_segment - segment));\n      *stream << \"]]>]]&gt;<![CDATA[\";\n      segment = next_segment + strlen(\"]]>\");\n    } else {\n      *stream << segment;\n      break;\n    }\n  }\n  *stream << \"]]>\";\n}\n\n// Prints an XML representation of a TestInfo object.\n// TODO(wan): There is also value in printing properties with the plain printer.\nvoid XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,\n                                                 const char* test_case_name,\n                                                 const TestInfo& test_info) {\n  const TestResult& result = *test_info.result();\n  *stream << \"    <testcase name=\\\"\"\n          << EscapeXmlAttribute(test_info.name()).c_str() << \"\\\"\";\n\n  if (test_info.value_param() != NULL) {\n    *stream << \" value_param=\\\"\" << EscapeXmlAttribute(test_info.value_param())\n            << \"\\\"\";\n  }\n  if (test_info.type_param() != NULL) {\n    *stream << \" type_param=\\\"\" << EscapeXmlAttribute(test_info.type_param())\n            << \"\\\"\";\n  }\n\n  *stream << \" status=\\\"\"\n          << (test_info.should_run() ? \"run\" : \"notrun\")\n          << \"\\\" time=\\\"\"\n          << FormatTimeInMillisAsSeconds(result.elapsed_time())\n          << \"\\\" classname=\\\"\" << EscapeXmlAttribute(test_case_name).c_str()\n          << \"\\\"\" << TestPropertiesAsXmlAttributes(result).c_str();\n\n  int failures = 0;\n  for (int i = 0; i < result.total_part_count(); ++i) {\n    const TestPartResult& part = result.GetTestPartResult(i);\n    if (part.failed()) {\n      if (++failures == 1)\n        *stream << \">\\n\";\n      *stream << \"      <failure message=\\\"\"\n              << EscapeXmlAttribute(part.summary()).c_str()\n              << \"\\\" type=\\\"\\\">\";\n      const string location = internal::FormatCompilerIndependentFileLocation(\n          part.file_name(), part.line_number());\n      const string message = location + \"\\n\" + part.message();\n      OutputXmlCDataSection(stream,\n                            RemoveInvalidXmlCharacters(message).c_str());\n      *stream << \"</failure>\\n\";\n    }\n  }\n\n  if (failures == 0)\n    *stream << \" />\\n\";\n  else\n    *stream << \"    </testcase>\\n\";\n}\n\n// Prints an XML representation of a TestCase object\nvoid XmlUnitTestResultPrinter::PrintXmlTestCase(FILE* out,\n                                                const TestCase& test_case) {\n  fprintf(out,\n          \"  <testsuite name=\\\"%s\\\" tests=\\\"%d\\\" failures=\\\"%d\\\" \"\n          \"disabled=\\\"%d\\\" \",\n          EscapeXmlAttribute(test_case.name()).c_str(),\n          test_case.total_test_count(),\n          test_case.failed_test_count(),\n          test_case.disabled_test_count());\n  fprintf(out,\n          \"errors=\\\"0\\\" time=\\\"%s\\\">\\n\",\n          FormatTimeInMillisAsSeconds(test_case.elapsed_time()).c_str());\n  for (int i = 0; i < test_case.total_test_count(); ++i) {\n    ::std::stringstream stream;\n    OutputXmlTestInfo(&stream, test_case.name(), *test_case.GetTestInfo(i));\n    fprintf(out, \"%s\", StringStreamToString(&stream).c_str());\n  }\n  fprintf(out, \"  </testsuite>\\n\");\n}\n\n// Prints an XML summary of unit_test to output stream out.\nvoid XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,\n                                                const UnitTest& unit_test) {\n  fprintf(out, \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n\");\n  fprintf(out,\n          \"<testsuites tests=\\\"%d\\\" failures=\\\"%d\\\" disabled=\\\"%d\\\" \"\n          \"errors=\\\"0\\\" time=\\\"%s\\\" \",\n          unit_test.total_test_count(),\n          unit_test.failed_test_count(),\n          unit_test.disabled_test_count(),\n          FormatTimeInMillisAsSeconds(unit_test.elapsed_time()).c_str());\n  if (GTEST_FLAG(shuffle)) {\n    fprintf(out, \"random_seed=\\\"%d\\\" \", unit_test.random_seed());\n  }\n  fprintf(out, \"name=\\\"AllTests\\\">\\n\");\n  for (int i = 0; i < unit_test.total_test_case_count(); ++i)\n    PrintXmlTestCase(out, *unit_test.GetTestCase(i));\n  fprintf(out, \"</testsuites>\\n\");\n}\n\n// Produces a string representing the test properties in a result as space\n// delimited XML attributes based on the property key=\"value\" pairs.\nString XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(\n    const TestResult& result) {\n  Message attributes;\n  for (int i = 0; i < result.test_property_count(); ++i) {\n    const TestProperty& property = result.GetTestProperty(i);\n    attributes << \" \" << property.key() << \"=\"\n        << \"\\\"\" << EscapeXmlAttribute(property.value()) << \"\\\"\";\n  }\n  return attributes.GetString();\n}\n\n// End XmlUnitTestResultPrinter\n\n#if GTEST_CAN_STREAM_RESULTS_\n\n// Streams test results to the given port on the given host machine.\nclass StreamingListener : public EmptyTestEventListener {\n public:\n  // Escapes '=', '&', '%', and '\\n' characters in str as \"%xx\".\n  static string UrlEncode(const char* str);\n\n  StreamingListener(const string& host, const string& port)\n      : sockfd_(-1), host_name_(host), port_num_(port) {\n    MakeConnection();\n    Send(\"gtest_streaming_protocol_version=1.0\\n\");\n  }\n\n  virtual ~StreamingListener() {\n    if (sockfd_ != -1)\n      CloseConnection();\n  }\n\n  void OnTestProgramStart(const UnitTest& /* unit_test */) {\n    Send(\"event=TestProgramStart\\n\");\n  }\n\n  void OnTestProgramEnd(const UnitTest& unit_test) {\n    // Note that Google Test current only report elapsed time for each\n    // test iteration, not for the entire test program.\n    Send(String::Format(\"event=TestProgramEnd&passed=%d\\n\",\n                        unit_test.Passed()));\n\n    // Notify the streaming server to stop.\n    CloseConnection();\n  }\n\n  void OnTestIterationStart(const UnitTest& /* unit_test */, int iteration) {\n    Send(String::Format(\"event=TestIterationStart&iteration=%d\\n\",\n                        iteration));\n  }\n\n  void OnTestIterationEnd(const UnitTest& unit_test, int /* iteration */) {\n    Send(String::Format(\"event=TestIterationEnd&passed=%d&elapsed_time=%sms\\n\",\n                        unit_test.Passed(),\n                        StreamableToString(unit_test.elapsed_time()).c_str()));\n  }\n\n  void OnTestCaseStart(const TestCase& test_case) {\n    Send(String::Format(\"event=TestCaseStart&name=%s\\n\", test_case.name()));\n  }\n\n  void OnTestCaseEnd(const TestCase& test_case) {\n    Send(String::Format(\"event=TestCaseEnd&passed=%d&elapsed_time=%sms\\n\",\n                        test_case.Passed(),\n                        StreamableToString(test_case.elapsed_time()).c_str()));\n  }\n\n  void OnTestStart(const TestInfo& test_info) {\n    Send(String::Format(\"event=TestStart&name=%s\\n\", test_info.name()));\n  }\n\n  void OnTestEnd(const TestInfo& test_info) {\n    Send(String::Format(\n        \"event=TestEnd&passed=%d&elapsed_time=%sms\\n\",\n        (test_info.result())->Passed(),\n        StreamableToString((test_info.result())->elapsed_time()).c_str()));\n  }\n\n  void OnTestPartResult(const TestPartResult& test_part_result) {\n    const char* file_name = test_part_result.file_name();\n    if (file_name == NULL)\n      file_name = \"\";\n    Send(String::Format(\"event=TestPartResult&file=%s&line=%d&message=\",\n                        UrlEncode(file_name).c_str(),\n                        test_part_result.line_number()));\n    Send(UrlEncode(test_part_result.message()) + \"\\n\");\n  }\n\n private:\n  // Creates a client socket and connects to the server.\n  void MakeConnection();\n\n  // Closes the socket.\n  void CloseConnection() {\n    GTEST_CHECK_(sockfd_ != -1)\n        << \"CloseConnection() can be called only when there is a connection.\";\n\n    close(sockfd_);\n    sockfd_ = -1;\n  }\n\n  // Sends a string to the socket.\n  void Send(const string& message) {\n    GTEST_CHECK_(sockfd_ != -1)\n        << \"Send() can be called only when there is a connection.\";\n\n    const int len = static_cast<int>(message.length());\n    if (write(sockfd_, message.c_str(), len) != len) {\n      GTEST_LOG_(WARNING)\n          << \"stream_result_to: failed to stream to \"\n          << host_name_ << \":\" << port_num_;\n    }\n  }\n\n  int sockfd_;   // socket file descriptor\n  const string host_name_;\n  const string port_num_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);\n};  // class StreamingListener\n\n// Checks if str contains '=', '&', '%' or '\\n' characters. If yes,\n// replaces them by \"%xx\" where xx is their hexadecimal value. For\n// example, replaces \"=\" with \"%3D\".  This algorithm is O(strlen(str))\n// in both time and space -- important as the input str may contain an\n// arbitrarily long test failure message and stack trace.\nstring StreamingListener::UrlEncode(const char* str) {\n  string result;\n  result.reserve(strlen(str) + 1);\n  for (char ch = *str; ch != '\\0'; ch = *++str) {\n    switch (ch) {\n      case '%':\n      case '=':\n      case '&':\n      case '\\n':\n        result.append(String::Format(\"%%%02x\", static_cast<unsigned char>(ch)));\n        break;\n      default:\n        result.push_back(ch);\n        break;\n    }\n  }\n  return result;\n}\n\nvoid StreamingListener::MakeConnection() {\n  GTEST_CHECK_(sockfd_ == -1)\n      << \"MakeConnection() can't be called when there is already a connection.\";\n\n  addrinfo hints;\n  memset(&hints, 0, sizeof(hints));\n  hints.ai_family = AF_UNSPEC;    // To allow both IPv4 and IPv6 addresses.\n  hints.ai_socktype = SOCK_STREAM;\n  addrinfo* servinfo = NULL;\n\n  // Use the getaddrinfo() to get a linked list of IP addresses for\n  // the given host name.\n  const int error_num = getaddrinfo(\n      host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);\n  if (error_num != 0) {\n    GTEST_LOG_(WARNING) << \"stream_result_to: getaddrinfo() failed: \"\n                        << gai_strerror(error_num);\n  }\n\n  // Loop through all the results and connect to the first we can.\n  for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != NULL;\n       cur_addr = cur_addr->ai_next) {\n    sockfd_ = socket(\n        cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);\n    if (sockfd_ != -1) {\n      // Connect the client socket to the server socket.\n      if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {\n        close(sockfd_);\n        sockfd_ = -1;\n      }\n    }\n  }\n\n  freeaddrinfo(servinfo);  // all done with this structure\n\n  if (sockfd_ == -1) {\n    GTEST_LOG_(WARNING) << \"stream_result_to: failed to connect to \"\n                        << host_name_ << \":\" << port_num_;\n  }\n}\n\n// End of class Streaming Listener\n#endif  // GTEST_CAN_STREAM_RESULTS__\n\n// Class ScopedTrace\n\n// Pushes the given source file location and message onto a per-thread\n// trace stack maintained by Google Test.\n// L < UnitTest::mutex_\nScopedTrace::ScopedTrace(const char* file, int line, const Message& message) {\n  TraceInfo trace;\n  trace.file = file;\n  trace.line = line;\n  trace.message = message.GetString();\n\n  UnitTest::GetInstance()->PushGTestTrace(trace);\n}\n\n// Pops the info pushed by the c'tor.\n// L < UnitTest::mutex_\nScopedTrace::~ScopedTrace() {\n  UnitTest::GetInstance()->PopGTestTrace();\n}\n\n\n// class OsStackTraceGetter\n\n// Returns the current OS stack trace as a String.  Parameters:\n//\n//   max_depth  - the maximum number of stack frames to be included\n//                in the trace.\n//   skip_count - the number of top frames to be skipped; doesn't count\n//                against max_depth.\n//\n// L < mutex_\n// We use \"L < mutex_\" to denote that the function may acquire mutex_.\nString OsStackTraceGetter::CurrentStackTrace(int, int) {\n  return String(\"\");\n}\n\n// L < mutex_\nvoid OsStackTraceGetter::UponLeavingGTest() {\n}\n\nconst char* const\nOsStackTraceGetter::kElidedFramesMarker =\n    \"... \" GTEST_NAME_ \" internal frames ...\";\n\n}  // namespace internal\n\n// class TestEventListeners\n\nTestEventListeners::TestEventListeners()\n    : repeater_(new internal::TestEventRepeater()),\n      default_result_printer_(NULL),\n      default_xml_generator_(NULL) {\n}\n\nTestEventListeners::~TestEventListeners() { delete repeater_; }\n\n// Returns the standard listener responsible for the default console\n// output.  Can be removed from the listeners list to shut down default\n// console output.  Note that removing this object from the listener list\n// with Release transfers its ownership to the user.\nvoid TestEventListeners::Append(TestEventListener* listener) {\n  repeater_->Append(listener);\n}\n\n// Removes the given event listener from the list and returns it.  It then\n// becomes the caller's responsibility to delete the listener. Returns\n// NULL if the listener is not found in the list.\nTestEventListener* TestEventListeners::Release(TestEventListener* listener) {\n  if (listener == default_result_printer_)\n    default_result_printer_ = NULL;\n  else if (listener == default_xml_generator_)\n    default_xml_generator_ = NULL;\n  return repeater_->Release(listener);\n}\n\n// Returns repeater that broadcasts the TestEventListener events to all\n// subscribers.\nTestEventListener* TestEventListeners::repeater() { return repeater_; }\n\n// Sets the default_result_printer attribute to the provided listener.\n// The listener is also added to the listener list and previous\n// default_result_printer is removed from it and deleted. The listener can\n// also be NULL in which case it will not be added to the list. Does\n// nothing if the previous and the current listener objects are the same.\nvoid TestEventListeners::SetDefaultResultPrinter(TestEventListener* listener) {\n  if (default_result_printer_ != listener) {\n    // It is an error to pass this method a listener that is already in the\n    // list.\n    delete Release(default_result_printer_);\n    default_result_printer_ = listener;\n    if (listener != NULL)\n      Append(listener);\n  }\n}\n\n// Sets the default_xml_generator attribute to the provided listener.  The\n// listener is also added to the listener list and previous\n// default_xml_generator is removed from it and deleted. The listener can\n// also be NULL in which case it will not be added to the list. Does\n// nothing if the previous and the current listener objects are the same.\nvoid TestEventListeners::SetDefaultXmlGenerator(TestEventListener* listener) {\n  if (default_xml_generator_ != listener) {\n    // It is an error to pass this method a listener that is already in the\n    // list.\n    delete Release(default_xml_generator_);\n    default_xml_generator_ = listener;\n    if (listener != NULL)\n      Append(listener);\n  }\n}\n\n// Controls whether events will be forwarded by the repeater to the\n// listeners in the list.\nbool TestEventListeners::EventForwardingEnabled() const {\n  return repeater_->forwarding_enabled();\n}\n\nvoid TestEventListeners::SuppressEventForwarding() {\n  repeater_->set_forwarding_enabled(false);\n}\n\n// class UnitTest\n\n// Gets the singleton UnitTest object.  The first time this method is\n// called, a UnitTest object is constructed and returned.  Consecutive\n// calls will return the same object.\n//\n// We don't protect this under mutex_ as a user is not supposed to\n// call this before main() starts, from which point on the return\n// value will never change.\nUnitTest * UnitTest::GetInstance() {\n  // When compiled with MSVC 7.1 in optimized mode, destroying the\n  // UnitTest object upon exiting the program messes up the exit code,\n  // causing successful tests to appear failed.  We have to use a\n  // different implementation in this case to bypass the compiler bug.\n  // This implementation makes the compiler happy, at the cost of\n  // leaking the UnitTest object.\n\n  // CodeGear C++Builder insists on a public destructor for the\n  // default implementation.  Use this implementation to keep good OO\n  // design with private destructor.\n\n#if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)\n  static UnitTest* const instance = new UnitTest;\n  return instance;\n#else\n  static UnitTest instance;\n  return &instance;\n#endif  // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)\n}\n\n// Gets the number of successful test cases.\nint UnitTest::successful_test_case_count() const {\n  return impl()->successful_test_case_count();\n}\n\n// Gets the number of failed test cases.\nint UnitTest::failed_test_case_count() const {\n  return impl()->failed_test_case_count();\n}\n\n// Gets the number of all test cases.\nint UnitTest::total_test_case_count() const {\n  return impl()->total_test_case_count();\n}\n\n// Gets the number of all test cases that contain at least one test\n// that should run.\nint UnitTest::test_case_to_run_count() const {\n  return impl()->test_case_to_run_count();\n}\n\n// Gets the number of successful tests.\nint UnitTest::successful_test_count() const {\n  return impl()->successful_test_count();\n}\n\n// Gets the number of failed tests.\nint UnitTest::failed_test_count() const { return impl()->failed_test_count(); }\n\n// Gets the number of disabled tests.\nint UnitTest::disabled_test_count() const {\n  return impl()->disabled_test_count();\n}\n\n// Gets the number of all tests.\nint UnitTest::total_test_count() const { return impl()->total_test_count(); }\n\n// Gets the number of tests that should run.\nint UnitTest::test_to_run_count() const { return impl()->test_to_run_count(); }\n\n// Gets the elapsed time, in milliseconds.\ninternal::TimeInMillis UnitTest::elapsed_time() const {\n  return impl()->elapsed_time();\n}\n\n// Returns true iff the unit test passed (i.e. all test cases passed).\nbool UnitTest::Passed() const { return impl()->Passed(); }\n\n// Returns true iff the unit test failed (i.e. some test case failed\n// or something outside of all tests failed).\nbool UnitTest::Failed() const { return impl()->Failed(); }\n\n// Gets the i-th test case among all the test cases. i can range from 0 to\n// total_test_case_count() - 1. If i is not in that range, returns NULL.\nconst TestCase* UnitTest::GetTestCase(int i) const {\n  return impl()->GetTestCase(i);\n}\n\n// Gets the i-th test case among all the test cases. i can range from 0 to\n// total_test_case_count() - 1. If i is not in that range, returns NULL.\nTestCase* UnitTest::GetMutableTestCase(int i) {\n  return impl()->GetMutableTestCase(i);\n}\n\n// Returns the list of event listeners that can be used to track events\n// inside Google Test.\nTestEventListeners& UnitTest::listeners() {\n  return *impl()->listeners();\n}\n\n// Registers and returns a global test environment.  When a test\n// program is run, all global test environments will be set-up in the\n// order they were registered.  After all tests in the program have\n// finished, all global test environments will be torn-down in the\n// *reverse* order they were registered.\n//\n// The UnitTest object takes ownership of the given environment.\n//\n// We don't protect this under mutex_, as we only support calling it\n// from the main thread.\nEnvironment* UnitTest::AddEnvironment(Environment* env) {\n  if (env == NULL) {\n    return NULL;\n  }\n\n  impl_->environments().push_back(env);\n  return env;\n}\n\n// Adds a TestPartResult to the current TestResult object.  All Google Test\n// assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call\n// this to report their results.  The user code should use the\n// assertion macros instead of calling this directly.\n// L < mutex_\nvoid UnitTest::AddTestPartResult(TestPartResult::Type result_type,\n                                 const char* file_name,\n                                 int line_number,\n                                 const internal::String& message,\n                                 const internal::String& os_stack_trace) {\n  Message msg;\n  msg << message;\n\n  internal::MutexLock lock(&mutex_);\n  if (impl_->gtest_trace_stack().size() > 0) {\n    msg << \"\\n\" << GTEST_NAME_ << \" trace:\";\n\n    for (int i = static_cast<int>(impl_->gtest_trace_stack().size());\n         i > 0; --i) {\n      const internal::TraceInfo& trace = impl_->gtest_trace_stack()[i - 1];\n      msg << \"\\n\" << internal::FormatFileLocation(trace.file, trace.line)\n          << \" \" << trace.message;\n    }\n  }\n\n  if (os_stack_trace.c_str() != NULL && !os_stack_trace.empty()) {\n    msg << internal::kStackTraceMarker << os_stack_trace;\n  }\n\n  const TestPartResult result =\n    TestPartResult(result_type, file_name, line_number,\n                   msg.GetString().c_str());\n  impl_->GetTestPartResultReporterForCurrentThread()->\n      ReportTestPartResult(result);\n\n  if (result_type != TestPartResult::kSuccess) {\n    // gtest_break_on_failure takes precedence over\n    // gtest_throw_on_failure.  This allows a user to set the latter\n    // in the code (perhaps in order to use Google Test assertions\n    // with another testing framework) and specify the former on the\n    // command line for debugging.\n    if (GTEST_FLAG(break_on_failure)) {\n#if GTEST_OS_WINDOWS\n      // Using DebugBreak on Windows allows gtest to still break into a debugger\n      // when a failure happens and both the --gtest_break_on_failure and\n      // the --gtest_catch_exceptions flags are specified.\n      DebugBreak();\n#else\n      // Dereference NULL through a volatile pointer to prevent the compiler\n      // from removing. We use this rather than abort() or __builtin_trap() for\n      // portability: Symbian doesn't implement abort() well, and some debuggers\n      // don't correctly trap abort().\n      *static_cast<volatile int*>(NULL) = 1;\n#endif  // GTEST_OS_WINDOWS\n    } else if (GTEST_FLAG(throw_on_failure)) {\n#if GTEST_HAS_EXCEPTIONS\n      throw GoogleTestFailureException(result);\n#else\n      // We cannot call abort() as it generates a pop-up in debug mode\n      // that cannot be suppressed in VC 7.1 or below.\n      exit(1);\n#endif\n    }\n  }\n}\n\n// Creates and adds a property to the current TestResult. If a property matching\n// the supplied value already exists, updates its value instead.\nvoid UnitTest::RecordPropertyForCurrentTest(const char* key,\n                                            const char* value) {\n  const TestProperty test_property(key, value);\n  impl_->current_test_result()->RecordProperty(test_property);\n}\n\n// Runs all tests in this UnitTest object and prints the result.\n// Returns 0 if successful, or 1 otherwise.\n//\n// We don't protect this under mutex_, as we only support calling it\n// from the main thread.\nint UnitTest::Run() {\n  // Captures the value of GTEST_FLAG(catch_exceptions).  This value will be\n  // used for the duration of the program.\n  impl()->set_catch_exceptions(GTEST_FLAG(catch_exceptions));\n\n#if GTEST_HAS_SEH\n  const bool in_death_test_child_process =\n      internal::GTEST_FLAG(internal_run_death_test).length() > 0;\n\n  // Either the user wants Google Test to catch exceptions thrown by the\n  // tests or this is executing in the context of death test child\n  // process. In either case the user does not want to see pop-up dialogs\n  // about crashes - they are expected.\n  if (impl()->catch_exceptions() || in_death_test_child_process) {\n\n# if !GTEST_OS_WINDOWS_MOBILE\n    // SetErrorMode doesn't exist on CE.\n    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |\n                 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);\n# endif  // !GTEST_OS_WINDOWS_MOBILE\n\n# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE\n    // Death test children can be terminated with _abort().  On Windows,\n    // _abort() can show a dialog with a warning message.  This forces the\n    // abort message to go to stderr instead.\n    _set_error_mode(_OUT_TO_STDERR);\n# endif\n\n# if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE\n    // In the debug version, Visual Studio pops up a separate dialog\n    // offering a choice to debug the aborted program. We need to suppress\n    // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement\n    // executed. Google Test will notify the user of any unexpected\n    // failure via stderr.\n    //\n    // VC++ doesn't define _set_abort_behavior() prior to the version 8.0.\n    // Users of prior VC versions shall suffer the agony and pain of\n    // clicking through the countless debug dialogs.\n    // TODO(vladl@google.com): find a way to suppress the abort dialog() in the\n    // debug mode when compiled with VC 7.1 or lower.\n    if (!GTEST_FLAG(break_on_failure))\n      _set_abort_behavior(\n          0x0,                                    // Clear the following flags:\n          _WRITE_ABORT_MSG | _CALL_REPORTFAULT);  // pop-up window, core dump.\n# endif\n\n  }\n#endif  // GTEST_HAS_SEH\n\n  return internal::HandleExceptionsInMethodIfSupported(\n      impl(),\n      &internal::UnitTestImpl::RunAllTests,\n      \"auxiliary test code (environments or event listeners)\") ? 0 : 1;\n}\n\n// Returns the working directory when the first TEST() or TEST_F() was\n// executed.\nconst char* UnitTest::original_working_dir() const {\n  return impl_->original_working_dir_.c_str();\n}\n\n// Returns the TestCase object for the test that's currently running,\n// or NULL if no test is running.\n// L < mutex_\nconst TestCase* UnitTest::current_test_case() const {\n  internal::MutexLock lock(&mutex_);\n  return impl_->current_test_case();\n}\n\n// Returns the TestInfo object for the test that's currently running,\n// or NULL if no test is running.\n// L < mutex_\nconst TestInfo* UnitTest::current_test_info() const {\n  internal::MutexLock lock(&mutex_);\n  return impl_->current_test_info();\n}\n\n// Returns the random seed used at the start of the current test run.\nint UnitTest::random_seed() const { return impl_->random_seed(); }\n\n#if GTEST_HAS_PARAM_TEST\n// Returns ParameterizedTestCaseRegistry object used to keep track of\n// value-parameterized tests and instantiate and register them.\n// L < mutex_\ninternal::ParameterizedTestCaseRegistry&\n    UnitTest::parameterized_test_registry() {\n  return impl_->parameterized_test_registry();\n}\n#endif  // GTEST_HAS_PARAM_TEST\n\n// Creates an empty UnitTest.\nUnitTest::UnitTest() {\n  impl_ = new internal::UnitTestImpl(this);\n}\n\n// Destructor of UnitTest.\nUnitTest::~UnitTest() {\n  delete impl_;\n}\n\n// Pushes a trace defined by SCOPED_TRACE() on to the per-thread\n// Google Test trace stack.\n// L < mutex_\nvoid UnitTest::PushGTestTrace(const internal::TraceInfo& trace) {\n  internal::MutexLock lock(&mutex_);\n  impl_->gtest_trace_stack().push_back(trace);\n}\n\n// Pops a trace from the per-thread Google Test trace stack.\n// L < mutex_\nvoid UnitTest::PopGTestTrace() {\n  internal::MutexLock lock(&mutex_);\n  impl_->gtest_trace_stack().pop_back();\n}\n\nnamespace internal {\n\nUnitTestImpl::UnitTestImpl(UnitTest* parent)\n    : parent_(parent),\n#ifdef _MSC_VER\n# pragma warning(push)                    // Saves the current warning state.\n# pragma warning(disable:4355)            // Temporarily disables warning 4355\n                                         // (using this in initializer).\n      default_global_test_part_result_reporter_(this),\n      default_per_thread_test_part_result_reporter_(this),\n# pragma warning(pop)                     // Restores the warning state again.\n#else\n      default_global_test_part_result_reporter_(this),\n      default_per_thread_test_part_result_reporter_(this),\n#endif  // _MSC_VER\n      global_test_part_result_repoter_(\n          &default_global_test_part_result_reporter_),\n      per_thread_test_part_result_reporter_(\n          &default_per_thread_test_part_result_reporter_),\n#if GTEST_HAS_PARAM_TEST\n      parameterized_test_registry_(),\n      parameterized_tests_registered_(false),\n#endif  // GTEST_HAS_PARAM_TEST\n      last_death_test_case_(-1),\n      current_test_case_(NULL),\n      current_test_info_(NULL),\n      ad_hoc_test_result_(),\n      os_stack_trace_getter_(NULL),\n      post_flag_parse_init_performed_(false),\n      random_seed_(0),  // Will be overridden by the flag before first use.\n      random_(0),  // Will be reseeded before first use.\n      elapsed_time_(0),\n#if GTEST_HAS_DEATH_TEST\n      internal_run_death_test_flag_(NULL),\n      death_test_factory_(new DefaultDeathTestFactory),\n#endif\n      // Will be overridden by the flag before first use.\n      catch_exceptions_(false) {\n  listeners()->SetDefaultResultPrinter(new PrettyUnitTestResultPrinter);\n}\n\nUnitTestImpl::~UnitTestImpl() {\n  // Deletes every TestCase.\n  ForEach(test_cases_, internal::Delete<TestCase>);\n\n  // Deletes every Environment.\n  ForEach(environments_, internal::Delete<Environment>);\n\n  delete os_stack_trace_getter_;\n}\n\n#if GTEST_HAS_DEATH_TEST\n// Disables event forwarding if the control is currently in a death test\n// subprocess. Must not be called before InitGoogleTest.\nvoid UnitTestImpl::SuppressTestEventsIfInSubprocess() {\n  if (internal_run_death_test_flag_.get() != NULL)\n    listeners()->SuppressEventForwarding();\n}\n#endif  // GTEST_HAS_DEATH_TEST\n\n// Initializes event listeners performing XML output as specified by\n// UnitTestOptions. Must not be called before InitGoogleTest.\nvoid UnitTestImpl::ConfigureXmlOutput() {\n  const String& output_format = UnitTestOptions::GetOutputFormat();\n  if (output_format == \"xml\") {\n    listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter(\n        UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));\n  } else if (output_format != \"\") {\n    printf(\"WARNING: unrecognized output format \\\"%s\\\" ignored.\\n\",\n           output_format.c_str());\n    fflush(stdout);\n  }\n}\n\n#if GTEST_CAN_STREAM_RESULTS_\n// Initializes event listeners for streaming test results in String form.\n// Must not be called before InitGoogleTest.\nvoid UnitTestImpl::ConfigureStreamingOutput() {\n  const string& target = GTEST_FLAG(stream_result_to);\n  if (!target.empty()) {\n    const size_t pos = target.find(':');\n    if (pos != string::npos) {\n      listeners()->Append(new StreamingListener(target.substr(0, pos),\n                                                target.substr(pos+1)));\n    } else {\n      printf(\"WARNING: unrecognized streaming target \\\"%s\\\" ignored.\\n\",\n             target.c_str());\n      fflush(stdout);\n    }\n  }\n}\n#endif  // GTEST_CAN_STREAM_RESULTS_\n\n// Performs initialization dependent upon flag values obtained in\n// ParseGoogleTestFlagsOnly.  Is called from InitGoogleTest after the call to\n// ParseGoogleTestFlagsOnly.  In case a user neglects to call InitGoogleTest\n// this function is also called from RunAllTests.  Since this function can be\n// called more than once, it has to be idempotent.\nvoid UnitTestImpl::PostFlagParsingInit() {\n  // Ensures that this function does not execute more than once.\n  if (!post_flag_parse_init_performed_) {\n    post_flag_parse_init_performed_ = true;\n\n#if GTEST_HAS_DEATH_TEST\n    InitDeathTestSubprocessControlInfo();\n    SuppressTestEventsIfInSubprocess();\n#endif  // GTEST_HAS_DEATH_TEST\n\n    // Registers parameterized tests. This makes parameterized tests\n    // available to the UnitTest reflection API without running\n    // RUN_ALL_TESTS.\n    RegisterParameterizedTests();\n\n    // Configures listeners for XML output. This makes it possible for users\n    // to shut down the default XML output before invoking RUN_ALL_TESTS.\n    ConfigureXmlOutput();\n\n#if GTEST_CAN_STREAM_RESULTS_\n    // Configures listeners for streaming test results to the specified server.\n    ConfigureStreamingOutput();\n#endif  // GTEST_CAN_STREAM_RESULTS_\n  }\n}\n\n// A predicate that checks the name of a TestCase against a known\n// value.\n//\n// This is used for implementation of the UnitTest class only.  We put\n// it in the anonymous namespace to prevent polluting the outer\n// namespace.\n//\n// TestCaseNameIs is copyable.\nclass TestCaseNameIs {\n public:\n  // Constructor.\n  explicit TestCaseNameIs(const String& name)\n      : name_(name) {}\n\n  // Returns true iff the name of test_case matches name_.\n  bool operator()(const TestCase* test_case) const {\n    return test_case != NULL && strcmp(test_case->name(), name_.c_str()) == 0;\n  }\n\n private:\n  String name_;\n};\n\n// Finds and returns a TestCase with the given name.  If one doesn't\n// exist, creates one and returns it.  It's the CALLER'S\n// RESPONSIBILITY to ensure that this function is only called WHEN THE\n// TESTS ARE NOT SHUFFLED.\n//\n// Arguments:\n//\n//   test_case_name: name of the test case\n//   type_param:     the name of the test case's type parameter, or NULL if\n//                   this is not a typed or a type-parameterized test case.\n//   set_up_tc:      pointer to the function that sets up the test case\n//   tear_down_tc:   pointer to the function that tears down the test case\nTestCase* UnitTestImpl::GetTestCase(const char* test_case_name,\n                                    const char* type_param,\n                                    Test::SetUpTestCaseFunc set_up_tc,\n                                    Test::TearDownTestCaseFunc tear_down_tc) {\n  // Can we find a TestCase with the given name?\n  const std::vector<TestCase*>::const_iterator test_case =\n      std::find_if(test_cases_.begin(), test_cases_.end(),\n                   TestCaseNameIs(test_case_name));\n\n  if (test_case != test_cases_.end())\n    return *test_case;\n\n  // No.  Let's create one.\n  TestCase* const new_test_case =\n      new TestCase(test_case_name, type_param, set_up_tc, tear_down_tc);\n\n  // Is this a death test case?\n  if (internal::UnitTestOptions::MatchesFilter(String(test_case_name),\n                                               kDeathTestCaseFilter)) {\n    // Yes.  Inserts the test case after the last death test case\n    // defined so far.  This only works when the test cases haven't\n    // been shuffled.  Otherwise we may end up running a death test\n    // after a non-death test.\n    ++last_death_test_case_;\n    test_cases_.insert(test_cases_.begin() + last_death_test_case_,\n                       new_test_case);\n  } else {\n    // No.  Appends to the end of the list.\n    test_cases_.push_back(new_test_case);\n  }\n\n  test_case_indices_.push_back(static_cast<int>(test_case_indices_.size()));\n  return new_test_case;\n}\n\n// Helpers for setting up / tearing down the given environment.  They\n// are for use in the ForEach() function.\nstatic void SetUpEnvironment(Environment* env) { env->SetUp(); }\nstatic void TearDownEnvironment(Environment* env) { env->TearDown(); }\n\n// Runs all tests in this UnitTest object, prints the result, and\n// returns true if all tests are successful.  If any exception is\n// thrown during a test, the test is considered to be failed, but the\n// rest of the tests will still be run.\n//\n// When parameterized tests are enabled, it expands and registers\n// parameterized tests first in RegisterParameterizedTests().\n// All other functions called from RunAllTests() may safely assume that\n// parameterized tests are ready to be counted and run.\nbool UnitTestImpl::RunAllTests() {\n  // Makes sure InitGoogleTest() was called.\n  if (!GTestIsInitialized()) {\n    printf(\"%s\",\n           \"\\nThis test program did NOT call ::testing::InitGoogleTest \"\n           \"before calling RUN_ALL_TESTS().  Please fix it.\\n\");\n    return false;\n  }\n\n  // Do not run any test if the --help flag was specified.\n  if (g_help_flag)\n    return true;\n\n  // Repeats the call to the post-flag parsing initialization in case the\n  // user didn't call InitGoogleTest.\n  PostFlagParsingInit();\n\n  // Even if sharding is not on, test runners may want to use the\n  // GTEST_SHARD_STATUS_FILE to query whether the test supports the sharding\n  // protocol.\n  internal::WriteToShardStatusFileIfNeeded();\n\n  // True iff we are in a subprocess for running a thread-safe-style\n  // death test.\n  bool in_subprocess_for_death_test = false;\n\n#if GTEST_HAS_DEATH_TEST\n  in_subprocess_for_death_test = (internal_run_death_test_flag_.get() != NULL);\n#endif  // GTEST_HAS_DEATH_TEST\n\n  const bool should_shard = ShouldShard(kTestTotalShards, kTestShardIndex,\n                                        in_subprocess_for_death_test);\n\n  // Compares the full test names with the filter to decide which\n  // tests to run.\n  const bool has_tests_to_run = FilterTests(should_shard\n                                              ? HONOR_SHARDING_PROTOCOL\n                                              : IGNORE_SHARDING_PROTOCOL) > 0;\n\n  // Lists the tests and exits if the --gtest_list_tests flag was specified.\n  if (GTEST_FLAG(list_tests)) {\n    // This must be called *after* FilterTests() has been called.\n    ListTestsMatchingFilter();\n    return true;\n  }\n\n  random_seed_ = GTEST_FLAG(shuffle) ?\n      GetRandomSeedFromFlag(GTEST_FLAG(random_seed)) : 0;\n\n  // True iff at least one test has failed.\n  bool failed = false;\n\n  TestEventListener* repeater = listeners()->repeater();\n\n  repeater->OnTestProgramStart(*parent_);\n\n  // How many times to repeat the tests?  We don't want to repeat them\n  // when we are inside the subprocess of a death test.\n  const int repeat = in_subprocess_for_death_test ? 1 : GTEST_FLAG(repeat);\n  // Repeats forever if the repeat count is negative.\n  const bool forever = repeat < 0;\n  for (int i = 0; forever || i != repeat; i++) {\n    // We want to preserve failures generated by ad-hoc test\n    // assertions executed before RUN_ALL_TESTS().\n    ClearNonAdHocTestResult();\n\n    const TimeInMillis start = GetTimeInMillis();\n\n    // Shuffles test cases and tests if requested.\n    if (has_tests_to_run && GTEST_FLAG(shuffle)) {\n      random()->Reseed(random_seed_);\n      // This should be done before calling OnTestIterationStart(),\n      // such that a test event listener can see the actual test order\n      // in the event.\n      ShuffleTests();\n    }\n\n    // Tells the unit test event listeners that the tests are about to start.\n    repeater->OnTestIterationStart(*parent_, i);\n\n    // Runs each test case if there is at least one test to run.\n    if (has_tests_to_run) {\n      // Sets up all environments beforehand.\n      repeater->OnEnvironmentsSetUpStart(*parent_);\n      ForEach(environments_, SetUpEnvironment);\n      repeater->OnEnvironmentsSetUpEnd(*parent_);\n\n      // Runs the tests only if there was no fatal failure during global\n      // set-up.\n      if (!Test::HasFatalFailure()) {\n        for (int test_index = 0; test_index < total_test_case_count();\n             test_index++) {\n          GetMutableTestCase(test_index)->Run();\n        }\n      }\n\n      // Tears down all environments in reverse order afterwards.\n      repeater->OnEnvironmentsTearDownStart(*parent_);\n      std::for_each(environments_.rbegin(), environments_.rend(),\n                    TearDownEnvironment);\n      repeater->OnEnvironmentsTearDownEnd(*parent_);\n    }\n\n    elapsed_time_ = GetTimeInMillis() - start;\n\n    // Tells the unit test event listener that the tests have just finished.\n    repeater->OnTestIterationEnd(*parent_, i);\n\n    // Gets the result and clears it.\n    if (!Passed()) {\n      failed = true;\n    }\n\n    // Restores the original test order after the iteration.  This\n    // allows the user to quickly repro a failure that happens in the\n    // N-th iteration without repeating the first (N - 1) iterations.\n    // This is not enclosed in \"if (GTEST_FLAG(shuffle)) { ... }\", in\n    // case the user somehow changes the value of the flag somewhere\n    // (it's always safe to unshuffle the tests).\n    UnshuffleTests();\n\n    if (GTEST_FLAG(shuffle)) {\n      // Picks a new random seed for each iteration.\n      random_seed_ = GetNextRandomSeed(random_seed_);\n    }\n  }\n\n  repeater->OnTestProgramEnd(*parent_);\n\n  return !failed;\n}\n\n// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file\n// if the variable is present. If a file already exists at this location, this\n// function will write over it. If the variable is present, but the file cannot\n// be created, prints an error and exits.\nvoid WriteToShardStatusFileIfNeeded() {\n  const char* const test_shard_file = posix::GetEnv(kTestShardStatusFile);\n  if (test_shard_file != NULL) {\n    FILE* const file = posix::FOpen(test_shard_file, \"w\");\n    if (file == NULL) {\n      ColoredPrintf(COLOR_RED,\n                    \"Could not write to the test shard status file \\\"%s\\\" \"\n                    \"specified by the %s environment variable.\\n\",\n                    test_shard_file, kTestShardStatusFile);\n      fflush(stdout);\n      exit(EXIT_FAILURE);\n    }\n    fclose(file);\n  }\n}\n\n// Checks whether sharding is enabled by examining the relevant\n// environment variable values. If the variables are present,\n// but inconsistent (i.e., shard_index >= total_shards), prints\n// an error and exits. If in_subprocess_for_death_test, sharding is\n// disabled because it must only be applied to the original test\n// process. Otherwise, we could filter out death tests we intended to execute.\nbool ShouldShard(const char* total_shards_env,\n                 const char* shard_index_env,\n                 bool in_subprocess_for_death_test) {\n  if (in_subprocess_for_death_test) {\n    return false;\n  }\n\n  const Int32 total_shards = Int32FromEnvOrDie(total_shards_env, -1);\n  const Int32 shard_index = Int32FromEnvOrDie(shard_index_env, -1);\n\n  if (total_shards == -1 && shard_index == -1) {\n    return false;\n  } else if (total_shards == -1 && shard_index != -1) {\n    const Message msg = Message()\n      << \"Invalid environment variables: you have \"\n      << kTestShardIndex << \" = \" << shard_index\n      << \", but have left \" << kTestTotalShards << \" unset.\\n\";\n    ColoredPrintf(COLOR_RED, msg.GetString().c_str());\n    fflush(stdout);\n    exit(EXIT_FAILURE);\n  } else if (total_shards != -1 && shard_index == -1) {\n    const Message msg = Message()\n      << \"Invalid environment variables: you have \"\n      << kTestTotalShards << \" = \" << total_shards\n      << \", but have left \" << kTestShardIndex << \" unset.\\n\";\n    ColoredPrintf(COLOR_RED, msg.GetString().c_str());\n    fflush(stdout);\n    exit(EXIT_FAILURE);\n  } else if (shard_index < 0 || shard_index >= total_shards) {\n    const Message msg = Message()\n      << \"Invalid environment variables: we require 0 <= \"\n      << kTestShardIndex << \" < \" << kTestTotalShards\n      << \", but you have \" << kTestShardIndex << \"=\" << shard_index\n      << \", \" << kTestTotalShards << \"=\" << total_shards << \".\\n\";\n    ColoredPrintf(COLOR_RED, msg.GetString().c_str());\n    fflush(stdout);\n    exit(EXIT_FAILURE);\n  }\n\n  return total_shards > 1;\n}\n\n// Parses the environment variable var as an Int32. If it is unset,\n// returns default_val. If it is not an Int32, prints an error\n// and aborts.\nInt32 Int32FromEnvOrDie(const char* var, Int32 default_val) {\n  const char* str_val = posix::GetEnv(var);\n  if (str_val == NULL) {\n    return default_val;\n  }\n\n  Int32 result;\n  if (!ParseInt32(Message() << \"The value of environment variable \" << var,\n                  str_val, &result)) {\n    exit(EXIT_FAILURE);\n  }\n  return result;\n}\n\n// Given the total number of shards, the shard index, and the test id,\n// returns true iff the test should be run on this shard. The test id is\n// some arbitrary but unique non-negative integer assigned to each test\n// method. Assumes that 0 <= shard_index < total_shards.\nbool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) {\n  return (test_id % total_shards) == shard_index;\n}\n\n// Compares the name of each test with the user-specified filter to\n// decide whether the test should be run, then records the result in\n// each TestCase and TestInfo object.\n// If shard_tests == true, further filters tests based on sharding\n// variables in the environment - see\n// http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide.\n// Returns the number of tests that should run.\nint UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {\n  const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?\n      Int32FromEnvOrDie(kTestTotalShards, -1) : -1;\n  const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?\n      Int32FromEnvOrDie(kTestShardIndex, -1) : -1;\n\n  // num_runnable_tests are the number of tests that will\n  // run across all shards (i.e., match filter and are not disabled).\n  // num_selected_tests are the number of tests to be run on\n  // this shard.\n  int num_runnable_tests = 0;\n  int num_selected_tests = 0;\n  for (size_t i = 0; i < test_cases_.size(); i++) {\n    TestCase* const test_case = test_cases_[i];\n    const String &test_case_name = test_case->name();\n    test_case->set_should_run(false);\n\n    for (size_t j = 0; j < test_case->test_info_list().size(); j++) {\n      TestInfo* const test_info = test_case->test_info_list()[j];\n      const String test_name(test_info->name());\n      // A test is disabled if test case name or test name matches\n      // kDisableTestFilter.\n      const bool is_disabled =\n          internal::UnitTestOptions::MatchesFilter(test_case_name,\n                                                   kDisableTestFilter) ||\n          internal::UnitTestOptions::MatchesFilter(test_name,\n                                                   kDisableTestFilter);\n      test_info->is_disabled_ = is_disabled;\n\n      const bool matches_filter =\n          internal::UnitTestOptions::FilterMatchesTest(test_case_name,\n                                                       test_name);\n      test_info->matches_filter_ = matches_filter;\n\n      const bool is_runnable =\n          (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&\n          matches_filter;\n\n      const bool is_selected = is_runnable &&\n          (shard_tests == IGNORE_SHARDING_PROTOCOL ||\n           ShouldRunTestOnShard(total_shards, shard_index,\n                                num_runnable_tests));\n\n      num_runnable_tests += is_runnable;\n      num_selected_tests += is_selected;\n\n      test_info->should_run_ = is_selected;\n      test_case->set_should_run(test_case->should_run() || is_selected);\n    }\n  }\n  return num_selected_tests;\n}\n\n// Prints the names of the tests matching the user-specified filter flag.\nvoid UnitTestImpl::ListTestsMatchingFilter() {\n  for (size_t i = 0; i < test_cases_.size(); i++) {\n    const TestCase* const test_case = test_cases_[i];\n    bool printed_test_case_name = false;\n\n    for (size_t j = 0; j < test_case->test_info_list().size(); j++) {\n      const TestInfo* const test_info =\n          test_case->test_info_list()[j];\n      if (test_info->matches_filter_) {\n        if (!printed_test_case_name) {\n          printed_test_case_name = true;\n          printf(\"%s.\\n\", test_case->name());\n        }\n        printf(\"  %s\\n\", test_info->name());\n      }\n    }\n  }\n  fflush(stdout);\n}\n\n// Sets the OS stack trace getter.\n//\n// Does nothing if the input and the current OS stack trace getter are\n// the same; otherwise, deletes the old getter and makes the input the\n// current getter.\nvoid UnitTestImpl::set_os_stack_trace_getter(\n    OsStackTraceGetterInterface* getter) {\n  if (os_stack_trace_getter_ != getter) {\n    delete os_stack_trace_getter_;\n    os_stack_trace_getter_ = getter;\n  }\n}\n\n// Returns the current OS stack trace getter if it is not NULL;\n// otherwise, creates an OsStackTraceGetter, makes it the current\n// getter, and returns it.\nOsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() {\n  if (os_stack_trace_getter_ == NULL) {\n    os_stack_trace_getter_ = new OsStackTraceGetter;\n  }\n\n  return os_stack_trace_getter_;\n}\n\n// Returns the TestResult for the test that's currently running, or\n// the TestResult for the ad hoc test if no test is running.\nTestResult* UnitTestImpl::current_test_result() {\n  return current_test_info_ ?\n      &(current_test_info_->result_) : &ad_hoc_test_result_;\n}\n\n// Shuffles all test cases, and the tests within each test case,\n// making sure that death tests are still run first.\nvoid UnitTestImpl::ShuffleTests() {\n  // Shuffles the death test cases.\n  ShuffleRange(random(), 0, last_death_test_case_ + 1, &test_case_indices_);\n\n  // Shuffles the non-death test cases.\n  ShuffleRange(random(), last_death_test_case_ + 1,\n               static_cast<int>(test_cases_.size()), &test_case_indices_);\n\n  // Shuffles the tests inside each test case.\n  for (size_t i = 0; i < test_cases_.size(); i++) {\n    test_cases_[i]->ShuffleTests(random());\n  }\n}\n\n// Restores the test cases and tests to their order before the first shuffle.\nvoid UnitTestImpl::UnshuffleTests() {\n  for (size_t i = 0; i < test_cases_.size(); i++) {\n    // Unshuffles the tests in each test case.\n    test_cases_[i]->UnshuffleTests();\n    // Resets the index of each test case.\n    test_case_indices_[i] = static_cast<int>(i);\n  }\n}\n\n// Returns the current OS stack trace as a String.\n//\n// The maximum number of stack frames to be included is specified by\n// the gtest_stack_trace_depth flag.  The skip_count parameter\n// specifies the number of top frames to be skipped, which doesn't\n// count against the number of frames to be included.\n//\n// For example, if Foo() calls Bar(), which in turn calls\n// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in\n// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.\nString GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/,\n                                       int skip_count) {\n  // We pass skip_count + 1 to skip this wrapper function in addition\n  // to what the user really wants to skip.\n  return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1);\n}\n\n// Used by the GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ macro to\n// suppress unreachable code warnings.\nnamespace {\nclass ClassUniqueToAlwaysTrue {};\n}\n\nbool IsTrue(bool condition) { return condition; }\n\nbool AlwaysTrue() {\n#if GTEST_HAS_EXCEPTIONS\n  // This condition is always false so AlwaysTrue() never actually throws,\n  // but it makes the compiler think that it may throw.\n  if (IsTrue(false))\n    throw ClassUniqueToAlwaysTrue();\n#endif  // GTEST_HAS_EXCEPTIONS\n  return true;\n}\n\n// If *pstr starts with the given prefix, modifies *pstr to be right\n// past the prefix and returns true; otherwise leaves *pstr unchanged\n// and returns false.  None of pstr, *pstr, and prefix can be NULL.\nbool SkipPrefix(const char* prefix, const char** pstr) {\n  const size_t prefix_len = strlen(prefix);\n  if (strncmp(*pstr, prefix, prefix_len) == 0) {\n    *pstr += prefix_len;\n    return true;\n  }\n  return false;\n}\n\n// Parses a string as a command line flag.  The string should have\n// the format \"--flag=value\".  When def_optional is true, the \"=value\"\n// part can be omitted.\n//\n// Returns the value of the flag, or NULL if the parsing failed.\nconst char* ParseFlagValue(const char* str,\n                           const char* flag,\n                           bool def_optional) {\n  // str and flag must not be NULL.\n  if (str == NULL || flag == NULL) return NULL;\n\n  // The flag must start with \"--\" followed by GTEST_FLAG_PREFIX_.\n  const String flag_str = String::Format(\"--%s%s\", GTEST_FLAG_PREFIX_, flag);\n  const size_t flag_len = flag_str.length();\n  if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL;\n\n  // Skips the flag name.\n  const char* flag_end = str + flag_len;\n\n  // When def_optional is true, it's OK to not have a \"=value\" part.\n  if (def_optional && (flag_end[0] == '\\0')) {\n    return flag_end;\n  }\n\n  // If def_optional is true and there are more characters after the\n  // flag name, or if def_optional is false, there must be a '=' after\n  // the flag name.\n  if (flag_end[0] != '=') return NULL;\n\n  // Returns the string after \"=\".\n  return flag_end + 1;\n}\n\n// Parses a string for a bool flag, in the form of either\n// \"--flag=value\" or \"--flag\".\n//\n// In the former case, the value is taken as true as long as it does\n// not start with '0', 'f', or 'F'.\n//\n// In the latter case, the value is taken as true.\n//\n// On success, stores the value of the flag in *value, and returns\n// true.  On failure, returns false without changing *value.\nbool ParseBoolFlag(const char* str, const char* flag, bool* value) {\n  // Gets the value of the flag as a string.\n  const char* const value_str = ParseFlagValue(str, flag, true);\n\n  // Aborts if the parsing failed.\n  if (value_str == NULL) return false;\n\n  // Converts the string value to a bool.\n  *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F');\n  return true;\n}\n\n// Parses a string for an Int32 flag, in the form of\n// \"--flag=value\".\n//\n// On success, stores the value of the flag in *value, and returns\n// true.  On failure, returns false without changing *value.\nbool ParseInt32Flag(const char* str, const char* flag, Int32* value) {\n  // Gets the value of the flag as a string.\n  const char* const value_str = ParseFlagValue(str, flag, false);\n\n  // Aborts if the parsing failed.\n  if (value_str == NULL) return false;\n\n  // Sets *value to the value of the flag.\n  return ParseInt32(Message() << \"The value of flag --\" << flag,\n                    value_str, value);\n}\n\n// Parses a string for a string flag, in the form of\n// \"--flag=value\".\n//\n// On success, stores the value of the flag in *value, and returns\n// true.  On failure, returns false without changing *value.\nbool ParseStringFlag(const char* str, const char* flag, String* value) {\n  // Gets the value of the flag as a string.\n  const char* const value_str = ParseFlagValue(str, flag, false);\n\n  // Aborts if the parsing failed.\n  if (value_str == NULL) return false;\n\n  // Sets *value to the value of the flag.\n  *value = value_str;\n  return true;\n}\n\n// Determines whether a string has a prefix that Google Test uses for its\n// flags, i.e., starts with GTEST_FLAG_PREFIX_ or GTEST_FLAG_PREFIX_DASH_.\n// If Google Test detects that a command line flag has its prefix but is not\n// recognized, it will print its help message. Flags starting with\n// GTEST_INTERNAL_PREFIX_ followed by \"internal_\" are considered Google Test\n// internal flags and do not trigger the help message.\nstatic bool HasGoogleTestFlagPrefix(const char* str) {\n  return (SkipPrefix(\"--\", &str) ||\n          SkipPrefix(\"-\", &str) ||\n          SkipPrefix(\"/\", &str)) &&\n         !SkipPrefix(GTEST_FLAG_PREFIX_ \"internal_\", &str) &&\n         (SkipPrefix(GTEST_FLAG_PREFIX_, &str) ||\n          SkipPrefix(GTEST_FLAG_PREFIX_DASH_, &str));\n}\n\n// Prints a string containing code-encoded text.  The following escape\n// sequences can be used in the string to control the text color:\n//\n//   @@    prints a single '@' character.\n//   @R    changes the color to red.\n//   @G    changes the color to green.\n//   @Y    changes the color to yellow.\n//   @D    changes to the default terminal text color.\n//\n// TODO(wan@google.com): Write tests for this once we add stdout\n// capturing to Google Test.\nstatic void PrintColorEncoded(const char* str) {\n  GTestColor color = COLOR_DEFAULT;  // The current color.\n\n  // Conceptually, we split the string into segments divided by escape\n  // sequences.  Then we print one segment at a time.  At the end of\n  // each iteration, the str pointer advances to the beginning of the\n  // next segment.\n  for (;;) {\n    const char* p = strchr(str, '@');\n    if (p == NULL) {\n      ColoredPrintf(color, \"%s\", str);\n      return;\n    }\n\n    ColoredPrintf(color, \"%s\", String(str, p - str).c_str());\n\n    const char ch = p[1];\n    str = p + 2;\n    if (ch == '@') {\n      ColoredPrintf(color, \"@\");\n    } else if (ch == 'D') {\n      color = COLOR_DEFAULT;\n    } else if (ch == 'R') {\n      color = COLOR_RED;\n    } else if (ch == 'G') {\n      color = COLOR_GREEN;\n    } else if (ch == 'Y') {\n      color = COLOR_YELLOW;\n    } else {\n      --str;\n    }\n  }\n}\n\nstatic const char kColorEncodedHelpMessage[] =\n\"This program contains tests written using \" GTEST_NAME_ \". You can use the\\n\"\n\"following command line flags to control its behavior:\\n\"\n\"\\n\"\n\"Test Selection:\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"list_tests@D\\n\"\n\"      List the names of all tests instead of running them. The name of\\n\"\n\"      TEST(Foo, Bar) is \\\"Foo.Bar\\\".\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"filter=@YPOSTIVE_PATTERNS\"\n    \"[@G-@YNEGATIVE_PATTERNS]@D\\n\"\n\"      Run only the tests whose name matches one of the positive patterns but\\n\"\n\"      none of the negative patterns. '?' matches any single character; '*'\\n\"\n\"      matches any substring; ':' separates two patterns.\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"also_run_disabled_tests@D\\n\"\n\"      Run all disabled tests too.\\n\"\n\"\\n\"\n\"Test Execution:\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"repeat=@Y[COUNT]@D\\n\"\n\"      Run the tests repeatedly; use a negative count to repeat forever.\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"shuffle@D\\n\"\n\"      Randomize tests' orders on every iteration.\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"random_seed=@Y[NUMBER]@D\\n\"\n\"      Random number seed to use for shuffling test orders (between 1 and\\n\"\n\"      99999, or 0 to use a seed based on the current time).\\n\"\n\"\\n\"\n\"Test Output:\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\\n\"\n\"      Enable/disable colored output. The default is @Gauto@D.\\n\"\n\"  -@G-\" GTEST_FLAG_PREFIX_ \"print_time=0@D\\n\"\n\"      Don't print the elapsed time of each test.\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"output=xml@Y[@G:@YDIRECTORY_PATH@G\"\n    GTEST_PATH_SEP_ \"@Y|@G:@YFILE_PATH]@D\\n\"\n\"      Generate an XML report in the given directory or with the given file\\n\"\n\"      name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\\n\"\n#if GTEST_CAN_STREAM_RESULTS_\n\"  @G--\" GTEST_FLAG_PREFIX_ \"stream_result_to=@YHOST@G:@YPORT@D\\n\"\n\"      Stream test results to the given server.\\n\"\n#endif  // GTEST_CAN_STREAM_RESULTS_\n\"\\n\"\n\"Assertion Behavior:\\n\"\n#if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS\n\"  @G--\" GTEST_FLAG_PREFIX_ \"death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\\n\"\n\"      Set the default death test style.\\n\"\n#endif  // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS\n\"  @G--\" GTEST_FLAG_PREFIX_ \"break_on_failure@D\\n\"\n\"      Turn assertion failures into debugger break-points.\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"throw_on_failure@D\\n\"\n\"      Turn assertion failures into C++ exceptions.\\n\"\n\"  @G--\" GTEST_FLAG_PREFIX_ \"catch_exceptions=0@D\\n\"\n\"      Do not report exceptions as test failures. Instead, allow them\\n\"\n\"      to crash the program or throw a pop-up (on Windows).\\n\"\n\"\\n\"\n\"Except for @G--\" GTEST_FLAG_PREFIX_ \"list_tests@D, you can alternatively set \"\n    \"the corresponding\\n\"\n\"environment variable of a flag (all letters in upper-case). For example, to\\n\"\n\"disable colored text output, you can either specify @G--\" GTEST_FLAG_PREFIX_\n    \"color=no@D or set\\n\"\n\"the @G\" GTEST_FLAG_PREFIX_UPPER_ \"COLOR@D environment variable to @Gno@D.\\n\"\n\"\\n\"\n\"For more information, please read the \" GTEST_NAME_ \" documentation at\\n\"\n\"@G\" GTEST_PROJECT_URL_ \"@D. If you find a bug in \" GTEST_NAME_ \"\\n\"\n\"(not one in your own code or tests), please report it to\\n\"\n\"@G<\" GTEST_DEV_EMAIL_ \">@D.\\n\";\n\n// Parses the command line for Google Test flags, without initializing\n// other parts of Google Test.  The type parameter CharType can be\n// instantiated to either char or wchar_t.\ntemplate <typename CharType>\nvoid ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {\n  for (int i = 1; i < *argc; i++) {\n    const String arg_string = StreamableToString(argv[i]);\n    const char* const arg = arg_string.c_str();\n\n    using internal::ParseBoolFlag;\n    using internal::ParseInt32Flag;\n    using internal::ParseStringFlag;\n\n    // Do we see a Google Test flag?\n    if (ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag,\n                      &GTEST_FLAG(also_run_disabled_tests)) ||\n        ParseBoolFlag(arg, kBreakOnFailureFlag,\n                      &GTEST_FLAG(break_on_failure)) ||\n        ParseBoolFlag(arg, kCatchExceptionsFlag,\n                      &GTEST_FLAG(catch_exceptions)) ||\n        ParseStringFlag(arg, kColorFlag, &GTEST_FLAG(color)) ||\n        ParseStringFlag(arg, kDeathTestStyleFlag,\n                        &GTEST_FLAG(death_test_style)) ||\n        ParseBoolFlag(arg, kDeathTestUseFork,\n                      &GTEST_FLAG(death_test_use_fork)) ||\n        ParseStringFlag(arg, kFilterFlag, &GTEST_FLAG(filter)) ||\n        ParseStringFlag(arg, kInternalRunDeathTestFlag,\n                        &GTEST_FLAG(internal_run_death_test)) ||\n        ParseBoolFlag(arg, kListTestsFlag, &GTEST_FLAG(list_tests)) ||\n        ParseStringFlag(arg, kOutputFlag, &GTEST_FLAG(output)) ||\n        ParseBoolFlag(arg, kPrintTimeFlag, &GTEST_FLAG(print_time)) ||\n        ParseInt32Flag(arg, kRandomSeedFlag, &GTEST_FLAG(random_seed)) ||\n        ParseInt32Flag(arg, kRepeatFlag, &GTEST_FLAG(repeat)) ||\n        ParseBoolFlag(arg, kShuffleFlag, &GTEST_FLAG(shuffle)) ||\n        ParseInt32Flag(arg, kStackTraceDepthFlag,\n                       &GTEST_FLAG(stack_trace_depth)) ||\n        ParseStringFlag(arg, kStreamResultToFlag,\n                        &GTEST_FLAG(stream_result_to)) ||\n        ParseBoolFlag(arg, kThrowOnFailureFlag,\n                      &GTEST_FLAG(throw_on_failure))\n        ) {\n      // Yes.  Shift the remainder of the argv list left by one.  Note\n      // that argv has (*argc + 1) elements, the last one always being\n      // NULL.  The following loop moves the trailing NULL element as\n      // well.\n      for (int j = i; j != *argc; j++) {\n        argv[j] = argv[j + 1];\n      }\n\n      // Decrements the argument count.\n      (*argc)--;\n\n      // We also need to decrement the iterator as we just removed\n      // an element.\n      i--;\n    } else if (arg_string == \"--help\" || arg_string == \"-h\" ||\n               arg_string == \"-?\" || arg_string == \"/?\" ||\n               HasGoogleTestFlagPrefix(arg)) {\n      // Both help flag and unrecognized Google Test flags (excluding\n      // internal ones) trigger help display.\n      g_help_flag = true;\n    }\n  }\n\n  if (g_help_flag) {\n    // We print the help here instead of in RUN_ALL_TESTS(), as the\n    // latter may not be called at all if the user is using Google\n    // Test with another testing framework.\n    PrintColorEncoded(kColorEncodedHelpMessage);\n  }\n}\n\n// Parses the command line for Google Test flags, without initializing\n// other parts of Google Test.\nvoid ParseGoogleTestFlagsOnly(int* argc, char** argv) {\n  ParseGoogleTestFlagsOnlyImpl(argc, argv);\n}\nvoid ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv) {\n  ParseGoogleTestFlagsOnlyImpl(argc, argv);\n}\n\n// The internal implementation of InitGoogleTest().\n//\n// The type parameter CharType can be instantiated to either char or\n// wchar_t.\ntemplate <typename CharType>\nvoid InitGoogleTestImpl(int* argc, CharType** argv) {\n  g_init_gtest_count++;\n\n  // We don't want to run the initialization code twice.\n  if (g_init_gtest_count != 1) return;\n\n  if (*argc <= 0) return;\n\n  internal::g_executable_path = internal::StreamableToString(argv[0]);\n\n#if GTEST_HAS_DEATH_TEST\n\n  g_argvs.clear();\n  for (int i = 0; i != *argc; i++) {\n    g_argvs.push_back(StreamableToString(argv[i]));\n  }\n\n#endif  // GTEST_HAS_DEATH_TEST\n\n  ParseGoogleTestFlagsOnly(argc, argv);\n  GetUnitTestImpl()->PostFlagParsingInit();\n}\n\n}  // namespace internal\n\n// Initializes Google Test.  This must be called before calling\n// RUN_ALL_TESTS().  In particular, it parses a command line for the\n// flags that Google Test recognizes.  Whenever a Google Test flag is\n// seen, it is removed from argv, and *argc is decremented.\n//\n// No value is returned.  Instead, the Google Test flag variables are\n// updated.\n//\n// Calling the function for the second time has no user-visible effect.\nvoid InitGoogleTest(int* argc, char** argv) {\n  internal::InitGoogleTestImpl(argc, argv);\n}\n\n// This overloaded version can be used in Windows programs compiled in\n// UNICODE mode.\nvoid InitGoogleTest(int* argc, wchar_t** argv) {\n  internal::InitGoogleTestImpl(argc, argv);\n}\n\n}  // namespace testing\n// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev)\n//\n// This file implements death tests.\n\n\n#if GTEST_HAS_DEATH_TEST\n\n# if GTEST_OS_MAC\n#  include <crt_externs.h>\n# endif  // GTEST_OS_MAC\n\n# include <errno.h>\n# include <fcntl.h>\n# include <limits.h>\n# include <stdarg.h>\n\n# if GTEST_OS_WINDOWS\n#  include <windows.h>\n# else\n#  include <sys/mman.h>\n#  include <sys/wait.h>\n# endif  // GTEST_OS_WINDOWS\n\n#endif  // GTEST_HAS_DEATH_TEST\n\n\n// Indicates that this translation unit is part of Google Test's\n// implementation.  It must come before gtest-internal-inl.h is\n// included, or there will be a compiler error.  This trick is to\n// prevent a user from accidentally including gtest-internal-inl.h in\n// his code.\n#define GTEST_IMPLEMENTATION_ 1\n#undef GTEST_IMPLEMENTATION_\n\nnamespace testing {\n\n// Constants.\n\n// The default death test style.\nstatic const char kDefaultDeathTestStyle[] = \"fast\";\n\nGTEST_DEFINE_string_(\n    death_test_style,\n    internal::StringFromGTestEnv(\"death_test_style\", kDefaultDeathTestStyle),\n    \"Indicates how to run a death test in a forked child process: \"\n    \"\\\"threadsafe\\\" (child process re-executes the test binary \"\n    \"from the beginning, running only the specific death test) or \"\n    \"\\\"fast\\\" (child process runs the death test immediately \"\n    \"after forking).\");\n\nGTEST_DEFINE_bool_(\n    death_test_use_fork,\n    internal::BoolFromGTestEnv(\"death_test_use_fork\", false),\n    \"Instructs to use fork()/_exit() instead of clone() in death tests. \"\n    \"Ignored and always uses fork() on POSIX systems where clone() is not \"\n    \"implemented. Useful when running under valgrind or similar tools if \"\n    \"those do not support clone(). Valgrind 3.3.1 will just fail if \"\n    \"it sees an unsupported combination of clone() flags. \"\n    \"It is not recommended to use this flag w/o valgrind though it will \"\n    \"work in 99% of the cases. Once valgrind is fixed, this flag will \"\n    \"most likely be removed.\");\n\nnamespace internal {\nGTEST_DEFINE_string_(\n    internal_run_death_test, \"\",\n    \"Indicates the file, line number, temporal index of \"\n    \"the single death test to run, and a file descriptor to \"\n    \"which a success code may be sent, all separated by \"\n    \"colons.  This flag is specified if and only if the current \"\n    \"process is a sub-process launched for running a thread-safe \"\n    \"death test.  FOR INTERNAL USE ONLY.\");\n}  // namespace internal\n\n#if GTEST_HAS_DEATH_TEST\n\n// ExitedWithCode constructor.\nExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {\n}\n\n// ExitedWithCode function-call operator.\nbool ExitedWithCode::operator()(int exit_status) const {\n# if GTEST_OS_WINDOWS\n\n  return exit_status == exit_code_;\n\n# else\n\n  return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_;\n\n# endif  // GTEST_OS_WINDOWS\n}\n\n# if !GTEST_OS_WINDOWS\n// KilledBySignal constructor.\nKilledBySignal::KilledBySignal(int signum) : signum_(signum) {\n}\n\n// KilledBySignal function-call operator.\nbool KilledBySignal::operator()(int exit_status) const {\n  return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;\n}\n# endif  // !GTEST_OS_WINDOWS\n\nnamespace internal {\n\n// Utilities needed for death tests.\n\n// Generates a textual description of a given exit code, in the format\n// specified by wait(2).\nstatic String ExitSummary(int exit_code) {\n  Message m;\n\n# if GTEST_OS_WINDOWS\n\n  m << \"Exited with exit status \" << exit_code;\n\n# else\n\n  if (WIFEXITED(exit_code)) {\n    m << \"Exited with exit status \" << WEXITSTATUS(exit_code);\n  } else if (WIFSIGNALED(exit_code)) {\n    m << \"Terminated by signal \" << WTERMSIG(exit_code);\n  }\n#  ifdef WCOREDUMP\n  if (WCOREDUMP(exit_code)) {\n    m << \" (core dumped)\";\n  }\n#  endif\n# endif  // GTEST_OS_WINDOWS\n\n  return m.GetString();\n}\n\n// Returns true if exit_status describes a process that was terminated\n// by a signal, or exited normally with a nonzero exit code.\nbool ExitedUnsuccessfully(int exit_status) {\n  return !ExitedWithCode(0)(exit_status);\n}\n\n# if !GTEST_OS_WINDOWS\n// Generates a textual failure message when a death test finds more than\n// one thread running, or cannot determine the number of threads, prior\n// to executing the given statement.  It is the responsibility of the\n// caller not to pass a thread_count of 1.\nstatic String DeathTestThreadWarning(size_t thread_count) {\n  Message msg;\n  msg << \"Death tests use fork(), which is unsafe particularly\"\n      << \" in a threaded context. For this test, \" << GTEST_NAME_ << \" \";\n  if (thread_count == 0)\n    msg << \"couldn't detect the number of threads.\";\n  else\n    msg << \"detected \" << thread_count << \" threads.\";\n  return msg.GetString();\n}\n# endif  // !GTEST_OS_WINDOWS\n\n// Flag characters for reporting a death test that did not die.\nstatic const char kDeathTestLived = 'L';\nstatic const char kDeathTestReturned = 'R';\nstatic const char kDeathTestThrew = 'T';\nstatic const char kDeathTestInternalError = 'I';\n\n// An enumeration describing all of the possible ways that a death test can\n// conclude.  DIED means that the process died while executing the test\n// code; LIVED means that process lived beyond the end of the test code;\n// RETURNED means that the test statement attempted to execute a return\n// statement, which is not allowed; THREW means that the test statement\n// returned control by throwing an exception.  IN_PROGRESS means the test\n// has not yet concluded.\n// TODO(vladl@google.com): Unify names and possibly values for\n// AbortReason, DeathTestOutcome, and flag characters above.\nenum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };\n\n// Routine for aborting the program which is safe to call from an\n// exec-style death test child process, in which case the error\n// message is propagated back to the parent process.  Otherwise, the\n// message is simply printed to stderr.  In either case, the program\n// then exits with status 1.\nvoid DeathTestAbort(const String& message) {\n  // On a POSIX system, this function may be called from a threadsafe-style\n  // death test child process, which operates on a very small stack.  Use\n  // the heap for any additional non-minuscule memory requirements.\n  const InternalRunDeathTestFlag* const flag =\n      GetUnitTestImpl()->internal_run_death_test_flag();\n  if (flag != NULL) {\n    FILE* parent = posix::FDOpen(flag->write_fd(), \"w\");\n    fputc(kDeathTestInternalError, parent);\n    fprintf(parent, \"%s\", message.c_str());\n    fflush(parent);\n    _exit(1);\n  } else {\n    fprintf(stderr, \"%s\", message.c_str());\n    fflush(stderr);\n    posix::Abort();\n  }\n}\n\n// A replacement for CHECK that calls DeathTestAbort if the assertion\n// fails.\n# define GTEST_DEATH_TEST_CHECK_(expression) \\\n  do { \\\n    if (!::testing::internal::IsTrue(expression)) { \\\n      DeathTestAbort(::testing::internal::String::Format( \\\n          \"CHECK failed: File %s, line %d: %s\", \\\n          __FILE__, __LINE__, #expression)); \\\n    } \\\n  } while (::testing::internal::AlwaysFalse())\n\n// This macro is similar to GTEST_DEATH_TEST_CHECK_, but it is meant for\n// evaluating any system call that fulfills two conditions: it must return\n// -1 on failure, and set errno to EINTR when it is interrupted and\n// should be tried again.  The macro expands to a loop that repeatedly\n// evaluates the expression as long as it evaluates to -1 and sets\n// errno to EINTR.  If the expression evaluates to -1 but errno is\n// something other than EINTR, DeathTestAbort is called.\n# define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \\\n  do { \\\n    int gtest_retval; \\\n    do { \\\n      gtest_retval = (expression); \\\n    } while (gtest_retval == -1 && errno == EINTR); \\\n    if (gtest_retval == -1) { \\\n      DeathTestAbort(::testing::internal::String::Format( \\\n          \"CHECK failed: File %s, line %d: %s != -1\", \\\n          __FILE__, __LINE__, #expression)); \\\n    } \\\n  } while (::testing::internal::AlwaysFalse())\n\n// Returns the message describing the last system error in errno.\nString GetLastErrnoDescription() {\n    return String(errno == 0 ? \"\" : posix::StrError(errno));\n}\n\n// This is called from a death test parent process to read a failure\n// message from the death test child process and log it with the FATAL\n// severity. On Windows, the message is read from a pipe handle. On other\n// platforms, it is read from a file descriptor.\nstatic void FailFromInternalError(int fd) {\n  Message error;\n  char buffer[256];\n  int num_read;\n\n  do {\n    while ((num_read = posix::Read(fd, buffer, 255)) > 0) {\n      buffer[num_read] = '\\0';\n      error << buffer;\n    }\n  } while (num_read == -1 && errno == EINTR);\n\n  if (num_read == 0) {\n    GTEST_LOG_(FATAL) << error.GetString();\n  } else {\n    const int last_error = errno;\n    GTEST_LOG_(FATAL) << \"Error while reading death test internal: \"\n                      << GetLastErrnoDescription() << \" [\" << last_error << \"]\";\n  }\n}\n\n// Death test constructor.  Increments the running death test count\n// for the current test.\nDeathTest::DeathTest() {\n  TestInfo* const info = GetUnitTestImpl()->current_test_info();\n  if (info == NULL) {\n    DeathTestAbort(\"Cannot run a death test outside of a TEST or \"\n                   \"TEST_F construct\");\n  }\n}\n\n// Creates and returns a death test by dispatching to the current\n// death test factory.\nbool DeathTest::Create(const char* statement, const RE* regex,\n                       const char* file, int line, DeathTest** test) {\n  return GetUnitTestImpl()->death_test_factory()->Create(\n      statement, regex, file, line, test);\n}\n\nconst char* DeathTest::LastMessage() {\n  return last_death_test_message_.c_str();\n}\n\nvoid DeathTest::set_last_death_test_message(const String& message) {\n  last_death_test_message_ = message;\n}\n\nString DeathTest::last_death_test_message_;\n\n// Provides cross platform implementation for some death functionality.\nclass DeathTestImpl : public DeathTest {\n protected:\n  DeathTestImpl(const char* a_statement, const RE* a_regex)\n      : statement_(a_statement),\n        regex_(a_regex),\n        spawned_(false),\n        status_(-1),\n        outcome_(IN_PROGRESS),\n        read_fd_(-1),\n        write_fd_(-1) {}\n\n  // read_fd_ is expected to be closed and cleared by a derived class.\n  ~DeathTestImpl() { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }\n\n  void Abort(AbortReason reason);\n  virtual bool Passed(bool status_ok);\n\n  const char* statement() const { return statement_; }\n  const RE* regex() const { return regex_; }\n  bool spawned() const { return spawned_; }\n  void set_spawned(bool is_spawned) { spawned_ = is_spawned; }\n  int status() const { return status_; }\n  void set_status(int a_status) { status_ = a_status; }\n  DeathTestOutcome outcome() const { return outcome_; }\n  void set_outcome(DeathTestOutcome an_outcome) { outcome_ = an_outcome; }\n  int read_fd() const { return read_fd_; }\n  void set_read_fd(int fd) { read_fd_ = fd; }\n  int write_fd() const { return write_fd_; }\n  void set_write_fd(int fd) { write_fd_ = fd; }\n\n  // Called in the parent process only. Reads the result code of the death\n  // test child process via a pipe, interprets it to set the outcome_\n  // member, and closes read_fd_.  Outputs diagnostics and terminates in\n  // case of unexpected codes.\n  void ReadAndInterpretStatusByte();\n\n private:\n  // The textual content of the code this object is testing.  This class\n  // doesn't own this string and should not attempt to delete it.\n  const char* const statement_;\n  // The regular expression which test output must match.  DeathTestImpl\n  // doesn't own this object and should not attempt to delete it.\n  const RE* const regex_;\n  // True if the death test child process has been successfully spawned.\n  bool spawned_;\n  // The exit status of the child process.\n  int status_;\n  // How the death test concluded.\n  DeathTestOutcome outcome_;\n  // Descriptor to the read end of the pipe to the child process.  It is\n  // always -1 in the child process.  The child keeps its write end of the\n  // pipe in write_fd_.\n  int read_fd_;\n  // Descriptor to the child's write end of the pipe to the parent process.\n  // It is always -1 in the parent process.  The parent keeps its end of the\n  // pipe in read_fd_.\n  int write_fd_;\n};\n\n// Called in the parent process only. Reads the result code of the death\n// test child process via a pipe, interprets it to set the outcome_\n// member, and closes read_fd_.  Outputs diagnostics and terminates in\n// case of unexpected codes.\nvoid DeathTestImpl::ReadAndInterpretStatusByte() {\n  char flag;\n  int bytes_read;\n\n  // The read() here blocks until data is available (signifying the\n  // failure of the death test) or until the pipe is closed (signifying\n  // its success), so it's okay to call this in the parent before\n  // the child process has exited.\n  do {\n    bytes_read = posix::Read(read_fd(), &flag, 1);\n  } while (bytes_read == -1 && errno == EINTR);\n\n  if (bytes_read == 0) {\n    set_outcome(DIED);\n  } else if (bytes_read == 1) {\n    switch (flag) {\n      case kDeathTestReturned:\n        set_outcome(RETURNED);\n        break;\n      case kDeathTestThrew:\n        set_outcome(THREW);\n        break;\n      case kDeathTestLived:\n        set_outcome(LIVED);\n        break;\n      case kDeathTestInternalError:\n        FailFromInternalError(read_fd());  // Does not return.\n        break;\n      default:\n        GTEST_LOG_(FATAL) << \"Death test child process reported \"\n                          << \"unexpected status byte (\"\n                          << static_cast<unsigned int>(flag) << \")\";\n    }\n  } else {\n    GTEST_LOG_(FATAL) << \"Read from death test child process failed: \"\n                      << GetLastErrnoDescription();\n  }\n  GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(read_fd()));\n  set_read_fd(-1);\n}\n\n// Signals that the death test code which should have exited, didn't.\n// Should be called only in a death test child process.\n// Writes a status byte to the child's status file descriptor, then\n// calls _exit(1).\nvoid DeathTestImpl::Abort(AbortReason reason) {\n  // The parent process considers the death test to be a failure if\n  // it finds any data in our pipe.  So, here we write a single flag byte\n  // to the pipe, then exit.\n  const char status_ch =\n      reason == TEST_DID_NOT_DIE ? kDeathTestLived :\n      reason == TEST_THREW_EXCEPTION ? kDeathTestThrew : kDeathTestReturned;\n\n  GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Write(write_fd(), &status_ch, 1));\n  // We are leaking the descriptor here because on some platforms (i.e.,\n  // when built as Windows DLL), destructors of global objects will still\n  // run after calling _exit(). On such systems, write_fd_ will be\n  // indirectly closed from the destructor of UnitTestImpl, causing double\n  // close if it is also closed here. On debug configurations, double close\n  // may assert. As there are no in-process buffers to flush here, we are\n  // relying on the OS to close the descriptor after the process terminates\n  // when the destructors are not run.\n  _exit(1);  // Exits w/o any normal exit hooks (we were supposed to crash)\n}\n\n// Returns an indented copy of stderr output for a death test.\n// This makes distinguishing death test output lines from regular log lines\n// much easier.\nstatic ::std::string FormatDeathTestOutput(const ::std::string& output) {\n  ::std::string ret;\n  for (size_t at = 0; ; ) {\n    const size_t line_end = output.find('\\n', at);\n    ret += \"[  DEATH   ] \";\n    if (line_end == ::std::string::npos) {\n      ret += output.substr(at);\n      break;\n    }\n    ret += output.substr(at, line_end + 1 - at);\n    at = line_end + 1;\n  }\n  return ret;\n}\n\n// Assesses the success or failure of a death test, using both private\n// members which have previously been set, and one argument:\n//\n// Private data members:\n//   outcome:  An enumeration describing how the death test\n//             concluded: DIED, LIVED, THREW, or RETURNED.  The death test\n//             fails in the latter three cases.\n//   status:   The exit status of the child process. On *nix, it is in the\n//             in the format specified by wait(2). On Windows, this is the\n//             value supplied to the ExitProcess() API or a numeric code\n//             of the exception that terminated the program.\n//   regex:    A regular expression object to be applied to\n//             the test's captured standard error output; the death test\n//             fails if it does not match.\n//\n// Argument:\n//   status_ok: true if exit_status is acceptable in the context of\n//              this particular death test, which fails if it is false\n//\n// Returns true iff all of the above conditions are met.  Otherwise, the\n// first failing condition, in the order given above, is the one that is\n// reported. Also sets the last death test message string.\nbool DeathTestImpl::Passed(bool status_ok) {\n  if (!spawned())\n    return false;\n\n  const String error_message = GetCapturedStderr();\n\n  bool success = false;\n  Message buffer;\n\n  buffer << \"Death test: \" << statement() << \"\\n\";\n  switch (outcome()) {\n    case LIVED:\n      buffer << \"    Result: failed to die.\\n\"\n             << \" Error msg:\\n\" << FormatDeathTestOutput(error_message);\n      break;\n    case THREW:\n      buffer << \"    Result: threw an exception.\\n\"\n             << \" Error msg:\\n\" << FormatDeathTestOutput(error_message);\n      break;\n    case RETURNED:\n      buffer << \"    Result: illegal return in test statement.\\n\"\n             << \" Error msg:\\n\" << FormatDeathTestOutput(error_message);\n      break;\n    case DIED:\n      if (status_ok) {\n        const bool matched = RE::PartialMatch(error_message.c_str(), *regex());\n        if (matched) {\n          success = true;\n        } else {\n          buffer << \"    Result: died but not with expected error.\\n\"\n                 << \"  Expected: \" << regex()->pattern() << \"\\n\"\n                 << \"Actual msg:\\n\" << FormatDeathTestOutput(error_message);\n        }\n      } else {\n        buffer << \"    Result: died but not with expected exit code:\\n\"\n               << \"            \" << ExitSummary(status()) << \"\\n\"\n               << \"Actual msg:\\n\" << FormatDeathTestOutput(error_message);\n      }\n      break;\n    case IN_PROGRESS:\n    default:\n      GTEST_LOG_(FATAL)\n          << \"DeathTest::Passed somehow called before conclusion of test\";\n  }\n\n  DeathTest::set_last_death_test_message(buffer.GetString());\n  return success;\n}\n\n# if GTEST_OS_WINDOWS\n// WindowsDeathTest implements death tests on Windows. Due to the\n// specifics of starting new processes on Windows, death tests there are\n// always threadsafe, and Google Test considers the\n// --gtest_death_test_style=fast setting to be equivalent to\n// --gtest_death_test_style=threadsafe there.\n//\n// A few implementation notes:  Like the Linux version, the Windows\n// implementation uses pipes for child-to-parent communication. But due to\n// the specifics of pipes on Windows, some extra steps are required:\n//\n// 1. The parent creates a communication pipe and stores handles to both\n//    ends of it.\n// 2. The parent starts the child and provides it with the information\n//    necessary to acquire the handle to the write end of the pipe.\n// 3. The child acquires the write end of the pipe and signals the parent\n//    using a Windows event.\n// 4. Now the parent can release the write end of the pipe on its side. If\n//    this is done before step 3, the object's reference count goes down to\n//    0 and it is destroyed, preventing the child from acquiring it. The\n//    parent now has to release it, or read operations on the read end of\n//    the pipe will not return when the child terminates.\n// 5. The parent reads child's output through the pipe (outcome code and\n//    any possible error messages) from the pipe, and its stderr and then\n//    determines whether to fail the test.\n//\n// Note: to distinguish Win32 API calls from the local method and function\n// calls, the former are explicitly resolved in the global namespace.\n//\nclass WindowsDeathTest : public DeathTestImpl {\n public:\n  WindowsDeathTest(const char* a_statement,\n                   const RE* a_regex,\n                   const char* file,\n                   int line)\n      : DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}\n\n  // All of these virtual functions are inherited from DeathTest.\n  virtual int Wait();\n  virtual TestRole AssumeRole();\n\n private:\n  // The name of the file in which the death test is located.\n  const char* const file_;\n  // The line number on which the death test is located.\n  const int line_;\n  // Handle to the write end of the pipe to the child process.\n  AutoHandle write_handle_;\n  // Child process handle.\n  AutoHandle child_handle_;\n  // Event the child process uses to signal the parent that it has\n  // acquired the handle to the write end of the pipe. After seeing this\n  // event the parent can release its own handles to make sure its\n  // ReadFile() calls return when the child terminates.\n  AutoHandle event_handle_;\n};\n\n// Waits for the child in a death test to exit, returning its exit\n// status, or 0 if no child process exists.  As a side effect, sets the\n// outcome data member.\nint WindowsDeathTest::Wait() {\n  if (!spawned())\n    return 0;\n\n  // Wait until the child either signals that it has acquired the write end\n  // of the pipe or it dies.\n  const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() };\n  switch (::WaitForMultipleObjects(2,\n                                   wait_handles,\n                                   FALSE,  // Waits for any of the handles.\n                                   INFINITE)) {\n    case WAIT_OBJECT_0:\n    case WAIT_OBJECT_0 + 1:\n      break;\n    default:\n      GTEST_DEATH_TEST_CHECK_(false);  // Should not get here.\n  }\n\n  // The child has acquired the write end of the pipe or exited.\n  // We release the handle on our side and continue.\n  write_handle_.Reset();\n  event_handle_.Reset();\n\n  ReadAndInterpretStatusByte();\n\n  // Waits for the child process to exit if it haven't already. This\n  // returns immediately if the child has already exited, regardless of\n  // whether previous calls to WaitForMultipleObjects synchronized on this\n  // handle or not.\n  GTEST_DEATH_TEST_CHECK_(\n      WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(),\n                                             INFINITE));\n  DWORD status_code;\n  GTEST_DEATH_TEST_CHECK_(\n      ::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE);\n  child_handle_.Reset();\n  set_status(static_cast<int>(status_code));\n  return status();\n}\n\n// The AssumeRole process for a Windows death test.  It creates a child\n// process with the same executable as the current process to run the\n// death test.  The child process is given the --gtest_filter and\n// --gtest_internal_run_death_test flags such that it knows to run the\n// current death test only.\nDeathTest::TestRole WindowsDeathTest::AssumeRole() {\n  const UnitTestImpl* const impl = GetUnitTestImpl();\n  const InternalRunDeathTestFlag* const flag =\n      impl->internal_run_death_test_flag();\n  const TestInfo* const info = impl->current_test_info();\n  const int death_test_index = info->result()->death_test_count();\n\n  if (flag != NULL) {\n    // ParseInternalRunDeathTestFlag() has performed all the necessary\n    // processing.\n    set_write_fd(flag->write_fd());\n    return EXECUTE_TEST;\n  }\n\n  // WindowsDeathTest uses an anonymous pipe to communicate results of\n  // a death test.\n  SECURITY_ATTRIBUTES handles_are_inheritable = {\n    sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };\n  HANDLE read_handle, write_handle;\n  GTEST_DEATH_TEST_CHECK_(\n      ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable,\n                   0)  // Default buffer size.\n      != FALSE);\n  set_read_fd(::_open_osfhandle(reinterpret_cast<intptr_t>(read_handle),\n                                O_RDONLY));\n  write_handle_.Reset(write_handle);\n  event_handle_.Reset(::CreateEvent(\n      &handles_are_inheritable,\n      TRUE,    // The event will automatically reset to non-signaled state.\n      FALSE,   // The initial state is non-signalled.\n      NULL));  // The even is unnamed.\n  GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL);\n  const String filter_flag = String::Format(\"--%s%s=%s.%s\",\n                                            GTEST_FLAG_PREFIX_, kFilterFlag,\n                                            info->test_case_name(),\n                                            info->name());\n  const String internal_flag = String::Format(\n    \"--%s%s=%s|%d|%d|%u|%Iu|%Iu\",\n      GTEST_FLAG_PREFIX_,\n      kInternalRunDeathTestFlag,\n      file_, line_,\n      death_test_index,\n      static_cast<unsigned int>(::GetCurrentProcessId()),\n      // size_t has the same with as pointers on both 32-bit and 64-bit\n      // Windows platforms.\n      // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.\n      reinterpret_cast<size_t>(write_handle),\n      reinterpret_cast<size_t>(event_handle_.Get()));\n\n  char executable_path[_MAX_PATH + 1];  // NOLINT\n  GTEST_DEATH_TEST_CHECK_(\n      _MAX_PATH + 1 != ::GetModuleFileNameA(NULL,\n                                            executable_path,\n                                            _MAX_PATH));\n\n  String command_line = String::Format(\"%s %s \\\"%s\\\"\",\n                                       ::GetCommandLineA(),\n                                       filter_flag.c_str(),\n                                       internal_flag.c_str());\n\n  DeathTest::set_last_death_test_message(\"\");\n\n  CaptureStderr();\n  // Flush the log buffers since the log streams are shared with the child.\n  FlushInfoLog();\n\n  // The child process will share the standard handles with the parent.\n  STARTUPINFOA startup_info;\n  memset(&startup_info, 0, sizeof(STARTUPINFO));\n  startup_info.dwFlags = STARTF_USESTDHANDLES;\n  startup_info.hStdInput = ::GetStdHandle(STD_INPUT_HANDLE);\n  startup_info.hStdOutput = ::GetStdHandle(STD_OUTPUT_HANDLE);\n  startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE);\n\n  PROCESS_INFORMATION process_info;\n  GTEST_DEATH_TEST_CHECK_(::CreateProcessA(\n      executable_path,\n      const_cast<char*>(command_line.c_str()),\n      NULL,   // Retuned process handle is not inheritable.\n      NULL,   // Retuned thread handle is not inheritable.\n      TRUE,   // Child inherits all inheritable handles (for write_handle_).\n      0x0,    // Default creation flags.\n      NULL,   // Inherit the parent's environment.\n      UnitTest::GetInstance()->original_working_dir(),\n      &startup_info,\n      &process_info) != FALSE);\n  child_handle_.Reset(process_info.hProcess);\n  ::CloseHandle(process_info.hThread);\n  set_spawned(true);\n  return OVERSEE_TEST;\n}\n# else  // We are not on Windows.\n\n// ForkingDeathTest provides implementations for most of the abstract\n// methods of the DeathTest interface.  Only the AssumeRole method is\n// left undefined.\nclass ForkingDeathTest : public DeathTestImpl {\n public:\n  ForkingDeathTest(const char* statement, const RE* regex);\n\n  // All of these virtual functions are inherited from DeathTest.\n  virtual int Wait();\n\n protected:\n  void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; }\n\n private:\n  // PID of child process during death test; 0 in the child process itself.\n  pid_t child_pid_;\n};\n\n// Constructs a ForkingDeathTest.\nForkingDeathTest::ForkingDeathTest(const char* a_statement, const RE* a_regex)\n    : DeathTestImpl(a_statement, a_regex),\n      child_pid_(-1) {}\n\n// Waits for the child in a death test to exit, returning its exit\n// status, or 0 if no child process exists.  As a side effect, sets the\n// outcome data member.\nint ForkingDeathTest::Wait() {\n  if (!spawned())\n    return 0;\n\n  ReadAndInterpretStatusByte();\n\n  int status_value;\n  GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status_value, 0));\n  set_status(status_value);\n  return status_value;\n}\n\n// A concrete death test class that forks, then immediately runs the test\n// in the child process.\nclass NoExecDeathTest : public ForkingDeathTest {\n public:\n  NoExecDeathTest(const char* a_statement, const RE* a_regex) :\n      ForkingDeathTest(a_statement, a_regex) { }\n  virtual TestRole AssumeRole();\n};\n\n// The AssumeRole process for a fork-and-run death test.  It implements a\n// straightforward fork, with a simple pipe to transmit the status byte.\nDeathTest::TestRole NoExecDeathTest::AssumeRole() {\n  const size_t thread_count = GetThreadCount();\n  if (thread_count != 1) {\n    GTEST_LOG_(WARNING) << DeathTestThreadWarning(thread_count);\n  }\n\n  int pipe_fd[2];\n  GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);\n\n  DeathTest::set_last_death_test_message(\"\");\n  CaptureStderr();\n  // When we fork the process below, the log file buffers are copied, but the\n  // file descriptors are shared.  We flush all log files here so that closing\n  // the file descriptors in the child process doesn't throw off the\n  // synchronization between descriptors and buffers in the parent process.\n  // This is as close to the fork as possible to avoid a race condition in case\n  // there are multiple threads running before the death test, and another\n  // thread writes to the log file.\n  FlushInfoLog();\n\n  const pid_t child_pid = fork();\n  GTEST_DEATH_TEST_CHECK_(child_pid != -1);\n  set_child_pid(child_pid);\n  if (child_pid == 0) {\n    GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[0]));\n    set_write_fd(pipe_fd[1]);\n    // Redirects all logging to stderr in the child process to prevent\n    // concurrent writes to the log files.  We capture stderr in the parent\n    // process and append the child process' output to a log.\n    LogToStderr();\n    // Event forwarding to the listeners of event listener API mush be shut\n    // down in death test subprocesses.\n    GetUnitTestImpl()->listeners()->SuppressEventForwarding();\n    return EXECUTE_TEST;\n  } else {\n    GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));\n    set_read_fd(pipe_fd[0]);\n    set_spawned(true);\n    return OVERSEE_TEST;\n  }\n}\n\n// A concrete death test class that forks and re-executes the main\n// program from the beginning, with command-line flags set that cause\n// only this specific death test to be run.\nclass ExecDeathTest : public ForkingDeathTest {\n public:\n  ExecDeathTest(const char* a_statement, const RE* a_regex,\n                const char* file, int line) :\n      ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }\n  virtual TestRole AssumeRole();\n private:\n  // The name of the file in which the death test is located.\n  const char* const file_;\n  // The line number on which the death test is located.\n  const int line_;\n};\n\n// Utility class for accumulating command-line arguments.\nclass Arguments {\n public:\n  Arguments() {\n    args_.push_back(NULL);\n  }\n\n  ~Arguments() {\n    for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();\n         ++i) {\n      free(*i);\n    }\n  }\n  void AddArgument(const char* argument) {\n    args_.insert(args_.end() - 1, posix::StrDup(argument));\n  }\n\n  template <typename Str>\n  void AddArguments(const ::std::vector<Str>& arguments) {\n    for (typename ::std::vector<Str>::const_iterator i = arguments.begin();\n         i != arguments.end();\n         ++i) {\n      args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));\n    }\n  }\n  char* const* Argv() {\n    return &args_[0];\n  }\n private:\n  std::vector<char*> args_;\n};\n\n// A struct that encompasses the arguments to the child process of a\n// threadsafe-style death test process.\nstruct ExecDeathTestArgs {\n  char* const* argv;  // Command-line arguments for the child's call to exec\n  int close_fd;       // File descriptor to close; the read end of a pipe\n};\n\n#  if GTEST_OS_MAC\ninline char** GetEnviron() {\n  // When Google Test is built as a framework on MacOS X, the environ variable\n  // is unavailable. Apple's documentation (man environ) recommends using\n  // _NSGetEnviron() instead.\n  return *_NSGetEnviron();\n}\n#  else\n// Some POSIX platforms expect you to declare environ. extern \"C\" makes\n// it reside in the global namespace.\nextern \"C\" char** environ;\ninline char** GetEnviron() { return environ; }\n#  endif  // GTEST_OS_MAC\n\n// The main function for a threadsafe-style death test child process.\n// This function is called in a clone()-ed process and thus must avoid\n// any potentially unsafe operations like malloc or libc functions.\nstatic int ExecDeathTestChildMain(void* child_arg) {\n  ExecDeathTestArgs* const args = static_cast<ExecDeathTestArgs*>(child_arg);\n  GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd));\n\n  // We need to execute the test program in the same environment where\n  // it was originally invoked.  Therefore we change to the original\n  // working directory first.\n  const char* const original_dir =\n      UnitTest::GetInstance()->original_working_dir();\n  // We can safely call chdir() as it's a direct system call.\n  if (chdir(original_dir) != 0) {\n    DeathTestAbort(String::Format(\"chdir(\\\"%s\\\") failed: %s\",\n                                  original_dir,\n                                  GetLastErrnoDescription().c_str()));\n    return EXIT_FAILURE;\n  }\n\n  // We can safely call execve() as it's a direct system call.  We\n  // cannot use execvp() as it's a libc function and thus potentially\n  // unsafe.  Since execve() doesn't search the PATH, the user must\n  // invoke the test program via a valid path that contains at least\n  // one path separator.\n  execve(args->argv[0], args->argv, GetEnviron());\n  DeathTestAbort(String::Format(\"execve(%s, ...) in %s failed: %s\",\n                                args->argv[0],\n                                original_dir,\n                                GetLastErrnoDescription().c_str()));\n  return EXIT_FAILURE;\n}\n\n// Two utility routines that together determine the direction the stack\n// grows.\n// This could be accomplished more elegantly by a single recursive\n// function, but we want to guard against the unlikely possibility of\n// a smart compiler optimizing the recursion away.\n//\n// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining\n// StackLowerThanAddress into StackGrowsDown, which then doesn't give\n// correct answer.\nbool StackLowerThanAddress(const void* ptr) GTEST_NO_INLINE_;\nbool StackLowerThanAddress(const void* ptr) {\n  int dummy;\n  return &dummy < ptr;\n}\n\nbool StackGrowsDown() {\n  int dummy;\n  return StackLowerThanAddress(&dummy);\n}\n\n// A threadsafe implementation of fork(2) for threadsafe-style death tests\n// that uses clone(2).  It dies with an error message if anything goes\n// wrong.\nstatic pid_t ExecDeathTestFork(char* const* argv, int close_fd) {\n  ExecDeathTestArgs args = { argv, close_fd };\n  pid_t child_pid = -1;\n\n#  if GTEST_HAS_CLONE\n  const bool use_fork = GTEST_FLAG(death_test_use_fork);\n\n  if (!use_fork) {\n    static const bool stack_grows_down = StackGrowsDown();\n    const size_t stack_size = getpagesize();\n    // MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead.\n    void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,\n                             MAP_ANON | MAP_PRIVATE, -1, 0);\n    GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);\n    void* const stack_top =\n        static_cast<char*>(stack) + (stack_grows_down ? stack_size : 0);\n\n    child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);\n\n    GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);\n  }\n#  else\n  const bool use_fork = true;\n#  endif  // GTEST_HAS_CLONE\n\n  if (use_fork && (child_pid = fork()) == 0) {\n      ExecDeathTestChildMain(&args);\n      _exit(0);\n  }\n\n  GTEST_DEATH_TEST_CHECK_(child_pid != -1);\n  return child_pid;\n}\n\n// The AssumeRole process for a fork-and-exec death test.  It re-executes the\n// main program from the beginning, setting the --gtest_filter\n// and --gtest_internal_run_death_test flags to cause only the current\n// death test to be re-run.\nDeathTest::TestRole ExecDeathTest::AssumeRole() {\n  const UnitTestImpl* const impl = GetUnitTestImpl();\n  const InternalRunDeathTestFlag* const flag =\n      impl->internal_run_death_test_flag();\n  const TestInfo* const info = impl->current_test_info();\n  const int death_test_index = info->result()->death_test_count();\n\n  if (flag != NULL) {\n    set_write_fd(flag->write_fd());\n    return EXECUTE_TEST;\n  }\n\n  int pipe_fd[2];\n  GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);\n  // Clear the close-on-exec flag on the write end of the pipe, lest\n  // it be closed when the child process does an exec:\n  GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);\n\n  const String filter_flag =\n      String::Format(\"--%s%s=%s.%s\",\n                     GTEST_FLAG_PREFIX_, kFilterFlag,\n                     info->test_case_name(), info->name());\n  const String internal_flag =\n      String::Format(\"--%s%s=%s|%d|%d|%d\",\n                     GTEST_FLAG_PREFIX_, kInternalRunDeathTestFlag,\n                     file_, line_, death_test_index, pipe_fd[1]);\n  Arguments args;\n  args.AddArguments(GetArgvs());\n  args.AddArgument(filter_flag.c_str());\n  args.AddArgument(internal_flag.c_str());\n\n  DeathTest::set_last_death_test_message(\"\");\n\n  CaptureStderr();\n  // See the comment in NoExecDeathTest::AssumeRole for why the next line\n  // is necessary.\n  FlushInfoLog();\n\n  const pid_t child_pid = ExecDeathTestFork(args.Argv(), pipe_fd[0]);\n  GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));\n  set_child_pid(child_pid);\n  set_read_fd(pipe_fd[0]);\n  set_spawned(true);\n  return OVERSEE_TEST;\n}\n\n# endif  // !GTEST_OS_WINDOWS\n\n// Creates a concrete DeathTest-derived class that depends on the\n// --gtest_death_test_style flag, and sets the pointer pointed to\n// by the \"test\" argument to its address.  If the test should be\n// skipped, sets that pointer to NULL.  Returns true, unless the\n// flag is set to an invalid value.\nbool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,\n                                     const char* file, int line,\n                                     DeathTest** test) {\n  UnitTestImpl* const impl = GetUnitTestImpl();\n  const InternalRunDeathTestFlag* const flag =\n      impl->internal_run_death_test_flag();\n  const int death_test_index = impl->current_test_info()\n      ->increment_death_test_count();\n\n  if (flag != NULL) {\n    if (death_test_index > flag->index()) {\n      DeathTest::set_last_death_test_message(String::Format(\n          \"Death test count (%d) somehow exceeded expected maximum (%d)\",\n          death_test_index, flag->index()));\n      return false;\n    }\n\n    if (!(flag->file() == file && flag->line() == line &&\n          flag->index() == death_test_index)) {\n      *test = NULL;\n      return true;\n    }\n  }\n\n# if GTEST_OS_WINDOWS\n\n  if (GTEST_FLAG(death_test_style) == \"threadsafe\" ||\n      GTEST_FLAG(death_test_style) == \"fast\") {\n    *test = new WindowsDeathTest(statement, regex, file, line);\n  }\n\n# else\n\n  if (GTEST_FLAG(death_test_style) == \"threadsafe\") {\n    *test = new ExecDeathTest(statement, regex, file, line);\n  } else if (GTEST_FLAG(death_test_style) == \"fast\") {\n    *test = new NoExecDeathTest(statement, regex);\n  }\n\n# endif  // GTEST_OS_WINDOWS\n\n  else {  // NOLINT - this is more readable than unbalanced brackets inside #if.\n    DeathTest::set_last_death_test_message(String::Format(\n        \"Unknown death test style \\\"%s\\\" encountered\",\n        GTEST_FLAG(death_test_style).c_str()));\n    return false;\n  }\n\n  return true;\n}\n\n// Splits a given string on a given delimiter, populating a given\n// vector with the fields.  GTEST_HAS_DEATH_TEST implies that we have\n// ::std::string, so we can use it here.\nstatic void SplitString(const ::std::string& str, char delimiter,\n                        ::std::vector< ::std::string>* dest) {\n  ::std::vector< ::std::string> parsed;\n  ::std::string::size_type pos = 0;\n  while (::testing::internal::AlwaysTrue()) {\n    const ::std::string::size_type colon = str.find(delimiter, pos);\n    if (colon == ::std::string::npos) {\n      parsed.push_back(str.substr(pos));\n      break;\n    } else {\n      parsed.push_back(str.substr(pos, colon - pos));\n      pos = colon + 1;\n    }\n  }\n  dest->swap(parsed);\n}\n\n# if GTEST_OS_WINDOWS\n// Recreates the pipe and event handles from the provided parameters,\n// signals the event, and returns a file descriptor wrapped around the pipe\n// handle. This function is called in the child process only.\nint GetStatusFileDescriptor(unsigned int parent_process_id,\n                            size_t write_handle_as_size_t,\n                            size_t event_handle_as_size_t) {\n  AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE,\n                                                   FALSE,  // Non-inheritable.\n                                                   parent_process_id));\n  if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {\n    DeathTestAbort(String::Format(\"Unable to open parent process %u\",\n                                  parent_process_id));\n  }\n\n  // TODO(vladl@google.com): Replace the following check with a\n  // compile-time assertion when available.\n  GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t));\n\n  const HANDLE write_handle =\n      reinterpret_cast<HANDLE>(write_handle_as_size_t);\n  HANDLE dup_write_handle;\n\n  // The newly initialized handle is accessible only in in the parent\n  // process. To obtain one accessible within the child, we need to use\n  // DuplicateHandle.\n  if (!::DuplicateHandle(parent_process_handle.Get(), write_handle,\n                         ::GetCurrentProcess(), &dup_write_handle,\n                         0x0,    // Requested privileges ignored since\n                                 // DUPLICATE_SAME_ACCESS is used.\n                         FALSE,  // Request non-inheritable handler.\n                         DUPLICATE_SAME_ACCESS)) {\n    DeathTestAbort(String::Format(\n        \"Unable to duplicate the pipe handle %Iu from the parent process %u\",\n        write_handle_as_size_t, parent_process_id));\n  }\n\n  const HANDLE event_handle = reinterpret_cast<HANDLE>(event_handle_as_size_t);\n  HANDLE dup_event_handle;\n\n  if (!::DuplicateHandle(parent_process_handle.Get(), event_handle,\n                         ::GetCurrentProcess(), &dup_event_handle,\n                         0x0,\n                         FALSE,\n                         DUPLICATE_SAME_ACCESS)) {\n    DeathTestAbort(String::Format(\n        \"Unable to duplicate the event handle %Iu from the parent process %u\",\n        event_handle_as_size_t, parent_process_id));\n  }\n\n  const int write_fd =\n      ::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);\n  if (write_fd == -1) {\n    DeathTestAbort(String::Format(\n        \"Unable to convert pipe handle %Iu to a file descriptor\",\n        write_handle_as_size_t));\n  }\n\n  // Signals the parent that the write end of the pipe has been acquired\n  // so the parent can release its own write end.\n  ::SetEvent(dup_event_handle);\n\n  return write_fd;\n}\n# endif  // GTEST_OS_WINDOWS\n\n// Returns a newly created InternalRunDeathTestFlag object with fields\n// initialized from the GTEST_FLAG(internal_run_death_test) flag if\n// the flag is specified; otherwise returns NULL.\nInternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {\n  if (GTEST_FLAG(internal_run_death_test) == \"\") return NULL;\n\n  // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we\n  // can use it here.\n  int line = -1;\n  int index = -1;\n  ::std::vector< ::std::string> fields;\n  SplitString(GTEST_FLAG(internal_run_death_test).c_str(), '|', &fields);\n  int write_fd = -1;\n\n# if GTEST_OS_WINDOWS\n\n  unsigned int parent_process_id = 0;\n  size_t write_handle_as_size_t = 0;\n  size_t event_handle_as_size_t = 0;\n\n  if (fields.size() != 6\n      || !ParseNaturalNumber(fields[1], &line)\n      || !ParseNaturalNumber(fields[2], &index)\n      || !ParseNaturalNumber(fields[3], &parent_process_id)\n      || !ParseNaturalNumber(fields[4], &write_handle_as_size_t)\n      || !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {\n    DeathTestAbort(String::Format(\n        \"Bad --gtest_internal_run_death_test flag: %s\",\n        GTEST_FLAG(internal_run_death_test).c_str()));\n  }\n  write_fd = GetStatusFileDescriptor(parent_process_id,\n                                     write_handle_as_size_t,\n                                     event_handle_as_size_t);\n# else\n\n  if (fields.size() != 4\n      || !ParseNaturalNumber(fields[1], &line)\n      || !ParseNaturalNumber(fields[2], &index)\n      || !ParseNaturalNumber(fields[3], &write_fd)) {\n    DeathTestAbort(String::Format(\n        \"Bad --gtest_internal_run_death_test flag: %s\",\n        GTEST_FLAG(internal_run_death_test).c_str()));\n  }\n\n# endif  // GTEST_OS_WINDOWS\n\n  return new InternalRunDeathTestFlag(fields[0], line, index, write_fd);\n}\n\n}  // namespace internal\n\n#endif  // GTEST_HAS_DEATH_TEST\n\n}  // namespace testing\n// Copyright 2008, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Authors: keith.ray@gmail.com (Keith Ray)\n\n\n#include <stdlib.h>\n\n#if GTEST_OS_WINDOWS_MOBILE\n# include <windows.h>\n#elif GTEST_OS_WINDOWS\n# include <direct.h>\n# include <io.h>\n#elif GTEST_OS_SYMBIAN || GTEST_OS_NACL\n// Symbian OpenC and NaCl have PATH_MAX in sys/syslimits.h\n# include <sys/syslimits.h>\n#else\n# include <limits.h>\n# include <climits>  // Some Linux distributions define PATH_MAX here.\n#endif  // GTEST_OS_WINDOWS_MOBILE\n\n#if GTEST_OS_WINDOWS\n# define GTEST_PATH_MAX_ _MAX_PATH\n#elif defined(PATH_MAX)\n# define GTEST_PATH_MAX_ PATH_MAX\n#elif defined(_XOPEN_PATH_MAX)\n# define GTEST_PATH_MAX_ _XOPEN_PATH_MAX\n#else\n# define GTEST_PATH_MAX_ _POSIX_PATH_MAX\n#endif  // GTEST_OS_WINDOWS\n\n\nnamespace testing {\nnamespace internal {\n\n#if GTEST_OS_WINDOWS\n// On Windows, '\\\\' is the standard path separator, but many tools and the\n// Windows API also accept '/' as an alternate path separator. Unless otherwise\n// noted, a file path can contain either kind of path separators, or a mixture\n// of them.\nconst char kPathSeparator = '\\\\';\nconst char kAlternatePathSeparator = '/';\nconst char kPathSeparatorString[] = \"\\\\\";\nconst char kAlternatePathSeparatorString[] = \"/\";\n# if GTEST_OS_WINDOWS_MOBILE\n// Windows CE doesn't have a current directory. You should not use\n// the current directory in tests on Windows CE, but this at least\n// provides a reasonable fallback.\nconst char kCurrentDirectoryString[] = \"\\\\\";\n// Windows CE doesn't define INVALID_FILE_ATTRIBUTES\nconst DWORD kInvalidFileAttributes = 0xffffffff;\n# else\nconst char kCurrentDirectoryString[] = \".\\\\\";\n# endif  // GTEST_OS_WINDOWS_MOBILE\n#else\nconst char kPathSeparator = '/';\nconst char kPathSeparatorString[] = \"/\";\nconst char kCurrentDirectoryString[] = \"./\";\n#endif  // GTEST_OS_WINDOWS\n\n// Returns whether the given character is a valid path separator.\nstatic bool IsPathSeparator(char c) {\n#if GTEST_HAS_ALT_PATH_SEP_\n  return (c == kPathSeparator) || (c == kAlternatePathSeparator);\n#else\n  return c == kPathSeparator;\n#endif\n}\n\n// Returns the current working directory, or \"\" if unsuccessful.\nFilePath FilePath::GetCurrentDir() {\n#if GTEST_OS_WINDOWS_MOBILE\n  // Windows CE doesn't have a current directory, so we just return\n  // something reasonable.\n  return FilePath(kCurrentDirectoryString);\n#elif GTEST_OS_WINDOWS\n  char cwd[GTEST_PATH_MAX_ + 1] = { '\\0' };\n  return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? \"\" : cwd);\n#else\n  char cwd[GTEST_PATH_MAX_ + 1] = { '\\0' };\n  return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? \"\" : cwd);\n#endif  // GTEST_OS_WINDOWS_MOBILE\n}\n\n// Returns a copy of the FilePath with the case-insensitive extension removed.\n// Example: FilePath(\"dir/file.exe\").RemoveExtension(\"EXE\") returns\n// FilePath(\"dir/file\"). If a case-insensitive extension is not\n// found, returns a copy of the original FilePath.\nFilePath FilePath::RemoveExtension(const char* extension) const {\n  String dot_extension(String::Format(\".%s\", extension));\n  if (pathname_.EndsWithCaseInsensitive(dot_extension.c_str())) {\n    return FilePath(String(pathname_.c_str(), pathname_.length() - 4));\n  }\n  return *this;\n}\n\n// Returns a pointer to the last occurence of a valid path separator in\n// the FilePath. On Windows, for example, both '/' and '\\' are valid path\n// separators. Returns NULL if no path separator was found.\nconst char* FilePath::FindLastPathSeparator() const {\n  const char* const last_sep = strrchr(c_str(), kPathSeparator);\n#if GTEST_HAS_ALT_PATH_SEP_\n  const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator);\n  // Comparing two pointers of which only one is NULL is undefined.\n  if (last_alt_sep != NULL &&\n      (last_sep == NULL || last_alt_sep > last_sep)) {\n    return last_alt_sep;\n  }\n#endif\n  return last_sep;\n}\n\n// Returns a copy of the FilePath with the directory part removed.\n// Example: FilePath(\"path/to/file\").RemoveDirectoryName() returns\n// FilePath(\"file\"). If there is no directory part (\"just_a_file\"), it returns\n// the FilePath unmodified. If there is no file part (\"just_a_dir/\") it\n// returns an empty FilePath (\"\").\n// On Windows platform, '\\' is the path separator, otherwise it is '/'.\nFilePath FilePath::RemoveDirectoryName() const {\n  const char* const last_sep = FindLastPathSeparator();\n  return last_sep ? FilePath(String(last_sep + 1)) : *this;\n}\n\n// RemoveFileName returns the directory path with the filename removed.\n// Example: FilePath(\"path/to/file\").RemoveFileName() returns \"path/to/\".\n// If the FilePath is \"a_file\" or \"/a_file\", RemoveFileName returns\n// FilePath(\"./\") or, on Windows, FilePath(\".\\\\\"). If the filepath does\n// not have a file, like \"just/a/dir/\", it returns the FilePath unmodified.\n// On Windows platform, '\\' is the path separator, otherwise it is '/'.\nFilePath FilePath::RemoveFileName() const {\n  const char* const last_sep = FindLastPathSeparator();\n  String dir;\n  if (last_sep) {\n    dir = String(c_str(), last_sep + 1 - c_str());\n  } else {\n    dir = kCurrentDirectoryString;\n  }\n  return FilePath(dir);\n}\n\n// Helper functions for naming files in a directory for xml output.\n\n// Given directory = \"dir\", base_name = \"test\", number = 0,\n// extension = \"xml\", returns \"dir/test.xml\". If number is greater\n// than zero (e.g., 12), returns \"dir/test_12.xml\".\n// On Windows platform, uses \\ as the separator rather than /.\nFilePath FilePath::MakeFileName(const FilePath& directory,\n                                const FilePath& base_name,\n                                int number,\n                                const char* extension) {\n  String file;\n  if (number == 0) {\n    file = String::Format(\"%s.%s\", base_name.c_str(), extension);\n  } else {\n    file = String::Format(\"%s_%d.%s\", base_name.c_str(), number, extension);\n  }\n  return ConcatPaths(directory, FilePath(file));\n}\n\n// Given directory = \"dir\", relative_path = \"test.xml\", returns \"dir/test.xml\".\n// On Windows, uses \\ as the separator rather than /.\nFilePath FilePath::ConcatPaths(const FilePath& directory,\n                               const FilePath& relative_path) {\n  if (directory.IsEmpty())\n    return relative_path;\n  const FilePath dir(directory.RemoveTrailingPathSeparator());\n  return FilePath(String::Format(\"%s%c%s\", dir.c_str(), kPathSeparator,\n                                 relative_path.c_str()));\n}\n\n// Returns true if pathname describes something findable in the file-system,\n// either a file, directory, or whatever.\nbool FilePath::FileOrDirectoryExists() const {\n#if GTEST_OS_WINDOWS_MOBILE\n  LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());\n  const DWORD attributes = GetFileAttributes(unicode);\n  delete [] unicode;\n  return attributes != kInvalidFileAttributes;\n#else\n  posix::StatStruct file_stat;\n  return posix::Stat(pathname_.c_str(), &file_stat) == 0;\n#endif  // GTEST_OS_WINDOWS_MOBILE\n}\n\n// Returns true if pathname describes a directory in the file-system\n// that exists.\nbool FilePath::DirectoryExists() const {\n  bool result = false;\n#if GTEST_OS_WINDOWS\n  // Don't strip off trailing separator if path is a root directory on\n  // Windows (like \"C:\\\\\").\n  const FilePath& path(IsRootDirectory() ? *this :\n                                           RemoveTrailingPathSeparator());\n#else\n  const FilePath& path(*this);\n#endif\n\n#if GTEST_OS_WINDOWS_MOBILE\n  LPCWSTR unicode = String::AnsiToUtf16(path.c_str());\n  const DWORD attributes = GetFileAttributes(unicode);\n  delete [] unicode;\n  if ((attributes != kInvalidFileAttributes) &&\n      (attributes & FILE_ATTRIBUTE_DIRECTORY)) {\n    result = true;\n  }\n#else\n  posix::StatStruct file_stat;\n  result = posix::Stat(path.c_str(), &file_stat) == 0 &&\n      posix::IsDir(file_stat);\n#endif  // GTEST_OS_WINDOWS_MOBILE\n\n  return result;\n}\n\n// Returns true if pathname describes a root directory. (Windows has one\n// root directory per disk drive.)\nbool FilePath::IsRootDirectory() const {\n#if GTEST_OS_WINDOWS\n  // TODO(wan@google.com): on Windows a network share like\n  // \\\\server\\share can be a root directory, although it cannot be the\n  // current directory.  Handle this properly.\n  return pathname_.length() == 3 && IsAbsolutePath();\n#else\n  return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);\n#endif\n}\n\n// Returns true if pathname describes an absolute path.\nbool FilePath::IsAbsolutePath() const {\n  const char* const name = pathname_.c_str();\n#if GTEST_OS_WINDOWS\n  return pathname_.length() >= 3 &&\n     ((name[0] >= 'a' && name[0] <= 'z') ||\n      (name[0] >= 'A' && name[0] <= 'Z')) &&\n     name[1] == ':' &&\n     IsPathSeparator(name[2]);\n#else\n  return IsPathSeparator(name[0]);\n#endif\n}\n\n// Returns a pathname for a file that does not currently exist. The pathname\n// will be directory/base_name.extension or\n// directory/base_name_<number>.extension if directory/base_name.extension\n// already exists. The number will be incremented until a pathname is found\n// that does not already exist.\n// Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.\n// There could be a race condition if two or more processes are calling this\n// function at the same time -- they could both pick the same filename.\nFilePath FilePath::GenerateUniqueFileName(const FilePath& directory,\n                                          const FilePath& base_name,\n                                          const char* extension) {\n  FilePath full_pathname;\n  int number = 0;\n  do {\n    full_pathname.Set(MakeFileName(directory, base_name, number++, extension));\n  } while (full_pathname.FileOrDirectoryExists());\n  return full_pathname;\n}\n\n// Returns true if FilePath ends with a path separator, which indicates that\n// it is intended to represent a directory. Returns false otherwise.\n// This does NOT check that a directory (or file) actually exists.\nbool FilePath::IsDirectory() const {\n  return !pathname_.empty() &&\n         IsPathSeparator(pathname_.c_str()[pathname_.length() - 1]);\n}\n\n// Create directories so that path exists. Returns true if successful or if\n// the directories already exist; returns false if unable to create directories\n// for any reason.\nbool FilePath::CreateDirectoriesRecursively() const {\n  if (!this->IsDirectory()) {\n    return false;\n  }\n\n  if (pathname_.length() == 0 || this->DirectoryExists()) {\n    return true;\n  }\n\n  const FilePath parent(this->RemoveTrailingPathSeparator().RemoveFileName());\n  return parent.CreateDirectoriesRecursively() && this->CreateFolder();\n}\n\n// Create the directory so that path exists. Returns true if successful or\n// if the directory already exists; returns false if unable to create the\n// directory for any reason, including if the parent directory does not\n// exist. Not named \"CreateDirectory\" because that's a macro on Windows.\nbool FilePath::CreateFolder() const {\n#if GTEST_OS_WINDOWS_MOBILE\n  FilePath removed_sep(this->RemoveTrailingPathSeparator());\n  LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());\n  int result = CreateDirectory(unicode, NULL) ? 0 : -1;\n  delete [] unicode;\n#elif GTEST_OS_WINDOWS\n  int result = _mkdir(pathname_.c_str());\n#else\n  int result = mkdir(pathname_.c_str(), 0777);\n#endif  // GTEST_OS_WINDOWS_MOBILE\n\n  if (result == -1) {\n    return this->DirectoryExists();  // An error is OK if the directory exists.\n  }\n  return true;  // No error.\n}\n\n// If input name has a trailing separator character, remove it and return the\n// name, otherwise return the name string unmodified.\n// On Windows platform, uses \\ as the separator, other platforms use /.\nFilePath FilePath::RemoveTrailingPathSeparator() const {\n  return IsDirectory()\n      ? FilePath(String(pathname_.c_str(), pathname_.length() - 1))\n      : *this;\n}\n\n// Removes any redundant separators that might be in the pathname.\n// For example, \"bar///foo\" becomes \"bar/foo\". Does not eliminate other\n// redundancies that might be in a pathname involving \".\" or \"..\".\n// TODO(wan@google.com): handle Windows network shares (e.g. \\\\server\\share).\nvoid FilePath::Normalize() {\n  if (pathname_.c_str() == NULL) {\n    pathname_ = \"\";\n    return;\n  }\n  const char* src = pathname_.c_str();\n  char* const dest = new char[pathname_.length() + 1];\n  char* dest_ptr = dest;\n  memset(dest_ptr, 0, pathname_.length() + 1);\n\n  while (*src != '\\0') {\n    *dest_ptr = *src;\n    if (!IsPathSeparator(*src)) {\n      src++;\n    } else {\n#if GTEST_HAS_ALT_PATH_SEP_\n      if (*dest_ptr == kAlternatePathSeparator) {\n        *dest_ptr = kPathSeparator;\n      }\n#endif\n      while (IsPathSeparator(*src))\n        src++;\n    }\n    dest_ptr++;\n  }\n  *dest_ptr = '\\0';\n  pathname_ = dest;\n  delete[] dest;\n}\n\n}  // namespace internal\n}  // namespace testing\n// Copyright 2008, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n\n\n#include <limits.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n#if GTEST_OS_WINDOWS_MOBILE\n# include <windows.h>  // For TerminateProcess()\n#elif GTEST_OS_WINDOWS\n# include <io.h>\n# include <sys/stat.h>\n#else\n# include <unistd.h>\n#endif  // GTEST_OS_WINDOWS_MOBILE\n\n#if GTEST_OS_MAC\n# include <mach/mach_init.h>\n# include <mach/task.h>\n# include <mach/vm_map.h>\n#endif  // GTEST_OS_MAC\n\n\n// Indicates that this translation unit is part of Google Test's\n// implementation.  It must come before gtest-internal-inl.h is\n// included, or there will be a compiler error.  This trick is to\n// prevent a user from accidentally including gtest-internal-inl.h in\n// his code.\n#define GTEST_IMPLEMENTATION_ 1\n#undef GTEST_IMPLEMENTATION_\n\nnamespace testing {\nnamespace internal {\n\n#if defined(_MSC_VER) || defined(__BORLANDC__)\n// MSVC and C++Builder do not provide a definition of STDERR_FILENO.\nconst int kStdOutFileno = 1;\nconst int kStdErrFileno = 2;\n#else\nconst int kStdOutFileno = STDOUT_FILENO;\nconst int kStdErrFileno = STDERR_FILENO;\n#endif  // _MSC_VER\n\n#if GTEST_OS_MAC\n\n// Returns the number of threads running in the process, or 0 to indicate that\n// we cannot detect it.\nsize_t GetThreadCount() {\n  const task_t task = mach_task_self();\n  mach_msg_type_number_t thread_count;\n  thread_act_array_t thread_list;\n  const kern_return_t status = task_threads(task, &thread_list, &thread_count);\n  if (status == KERN_SUCCESS) {\n    // task_threads allocates resources in thread_list and we need to free them\n    // to avoid leaks.\n    vm_deallocate(task,\n                  reinterpret_cast<vm_address_t>(thread_list),\n                  sizeof(thread_t) * thread_count);\n    return static_cast<size_t>(thread_count);\n  } else {\n    return 0;\n  }\n}\n\n#else\n\nsize_t GetThreadCount() {\n  // There's no portable way to detect the number of threads, so we just\n  // return 0 to indicate that we cannot detect it.\n  return 0;\n}\n\n#endif  // GTEST_OS_MAC\n\n#if GTEST_USES_POSIX_RE\n\n// Implements RE.  Currently only needed for death tests.\n\nRE::~RE() {\n  if (is_valid_) {\n    // regfree'ing an invalid regex might crash because the content\n    // of the regex is undefined. Since the regex's are essentially\n    // the same, one cannot be valid (or invalid) without the other\n    // being so too.\n    regfree(&partial_regex_);\n    regfree(&full_regex_);\n  }\n  free(const_cast<char*>(pattern_));\n}\n\n// Returns true iff regular expression re matches the entire str.\nbool RE::FullMatch(const char* str, const RE& re) {\n  if (!re.is_valid_) return false;\n\n  regmatch_t match;\n  return regexec(&re.full_regex_, str, 1, &match, 0) == 0;\n}\n\n// Returns true iff regular expression re matches a substring of str\n// (including str itself).\nbool RE::PartialMatch(const char* str, const RE& re) {\n  if (!re.is_valid_) return false;\n\n  regmatch_t match;\n  return regexec(&re.partial_regex_, str, 1, &match, 0) == 0;\n}\n\n// Initializes an RE from its string representation.\nvoid RE::Init(const char* regex) {\n  pattern_ = posix::StrDup(regex);\n\n  // Reserves enough bytes to hold the regular expression used for a\n  // full match.\n  const size_t full_regex_len = strlen(regex) + 10;\n  char* const full_pattern = new char[full_regex_len];\n\n  snprintf(full_pattern, full_regex_len, \"^(%s)$\", regex);\n  is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0;\n  // We want to call regcomp(&partial_regex_, ...) even if the\n  // previous expression returns false.  Otherwise partial_regex_ may\n  // not be properly initialized can may cause trouble when it's\n  // freed.\n  //\n  // Some implementation of POSIX regex (e.g. on at least some\n  // versions of Cygwin) doesn't accept the empty string as a valid\n  // regex.  We change it to an equivalent form \"()\" to be safe.\n  if (is_valid_) {\n    const char* const partial_regex = (*regex == '\\0') ? \"()\" : regex;\n    is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0;\n  }\n  EXPECT_TRUE(is_valid_)\n      << \"Regular expression \\\"\" << regex\n      << \"\\\" is not a valid POSIX Extended regular expression.\";\n\n  delete[] full_pattern;\n}\n\n#elif GTEST_USES_SIMPLE_RE\n\n// Returns true iff ch appears anywhere in str (excluding the\n// terminating '\\0' character).\nbool IsInSet(char ch, const char* str) {\n  return ch != '\\0' && strchr(str, ch) != NULL;\n}\n\n// Returns true iff ch belongs to the given classification.  Unlike\n// similar functions in <ctype.h>, these aren't affected by the\n// current locale.\nbool IsAsciiDigit(char ch) { return '0' <= ch && ch <= '9'; }\nbool IsAsciiPunct(char ch) {\n  return IsInSet(ch, \"^-!\\\"#$%&'()*+,./:;<=>?@[\\\\]_`{|}~\");\n}\nbool IsRepeat(char ch) { return IsInSet(ch, \"?*+\"); }\nbool IsAsciiWhiteSpace(char ch) { return IsInSet(ch, \" \\f\\n\\r\\t\\v\"); }\nbool IsAsciiWordChar(char ch) {\n  return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') ||\n      ('0' <= ch && ch <= '9') || ch == '_';\n}\n\n// Returns true iff \"\\\\c\" is a supported escape sequence.\nbool IsValidEscape(char c) {\n  return (IsAsciiPunct(c) || IsInSet(c, \"dDfnrsStvwW\"));\n}\n\n// Returns true iff the given atom (specified by escaped and pattern)\n// matches ch.  The result is undefined if the atom is invalid.\nbool AtomMatchesChar(bool escaped, char pattern_char, char ch) {\n  if (escaped) {  // \"\\\\p\" where p is pattern_char.\n    switch (pattern_char) {\n      case 'd': return IsAsciiDigit(ch);\n      case 'D': return !IsAsciiDigit(ch);\n      case 'f': return ch == '\\f';\n      case 'n': return ch == '\\n';\n      case 'r': return ch == '\\r';\n      case 's': return IsAsciiWhiteSpace(ch);\n      case 'S': return !IsAsciiWhiteSpace(ch);\n      case 't': return ch == '\\t';\n      case 'v': return ch == '\\v';\n      case 'w': return IsAsciiWordChar(ch);\n      case 'W': return !IsAsciiWordChar(ch);\n    }\n    return IsAsciiPunct(pattern_char) && pattern_char == ch;\n  }\n\n  return (pattern_char == '.' && ch != '\\n') || pattern_char == ch;\n}\n\n// Helper function used by ValidateRegex() to format error messages.\nString FormatRegexSyntaxError(const char* regex, int index) {\n  return (Message() << \"Syntax error at index \" << index\n          << \" in simple regular expression \\\"\" << regex << \"\\\": \").GetString();\n}\n\n// Generates non-fatal failures and returns false if regex is invalid;\n// otherwise returns true.\nbool ValidateRegex(const char* regex) {\n  if (regex == NULL) {\n    // TODO(wan@google.com): fix the source file location in the\n    // assertion failures to match where the regex is used in user\n    // code.\n    ADD_FAILURE() << \"NULL is not a valid simple regular expression.\";\n    return false;\n  }\n\n  bool is_valid = true;\n\n  // True iff ?, *, or + can follow the previous atom.\n  bool prev_repeatable = false;\n  for (int i = 0; regex[i]; i++) {\n    if (regex[i] == '\\\\') {  // An escape sequence\n      i++;\n      if (regex[i] == '\\0') {\n        ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)\n                      << \"'\\\\' cannot appear at the end.\";\n        return false;\n      }\n\n      if (!IsValidEscape(regex[i])) {\n        ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)\n                      << \"invalid escape sequence \\\"\\\\\" << regex[i] << \"\\\".\";\n        is_valid = false;\n      }\n      prev_repeatable = true;\n    } else {  // Not an escape sequence.\n      const char ch = regex[i];\n\n      if (ch == '^' && i > 0) {\n        ADD_FAILURE() << FormatRegexSyntaxError(regex, i)\n                      << \"'^' can only appear at the beginning.\";\n        is_valid = false;\n      } else if (ch == '$' && regex[i + 1] != '\\0') {\n        ADD_FAILURE() << FormatRegexSyntaxError(regex, i)\n                      << \"'$' can only appear at the end.\";\n        is_valid = false;\n      } else if (IsInSet(ch, \"()[]{}|\")) {\n        ADD_FAILURE() << FormatRegexSyntaxError(regex, i)\n                      << \"'\" << ch << \"' is unsupported.\";\n        is_valid = false;\n      } else if (IsRepeat(ch) && !prev_repeatable) {\n        ADD_FAILURE() << FormatRegexSyntaxError(regex, i)\n                      << \"'\" << ch << \"' can only follow a repeatable token.\";\n        is_valid = false;\n      }\n\n      prev_repeatable = !IsInSet(ch, \"^$?*+\");\n    }\n  }\n\n  return is_valid;\n}\n\n// Matches a repeated regex atom followed by a valid simple regular\n// expression.  The regex atom is defined as c if escaped is false,\n// or \\c otherwise.  repeat is the repetition meta character (?, *,\n// or +).  The behavior is undefined if str contains too many\n// characters to be indexable by size_t, in which case the test will\n// probably time out anyway.  We are fine with this limitation as\n// std::string has it too.\nbool MatchRepetitionAndRegexAtHead(\n    bool escaped, char c, char repeat, const char* regex,\n    const char* str) {\n  const size_t min_count = (repeat == '+') ? 1 : 0;\n  const size_t max_count = (repeat == '?') ? 1 :\n      static_cast<size_t>(-1) - 1;\n  // We cannot call numeric_limits::max() as it conflicts with the\n  // max() macro on Windows.\n\n  for (size_t i = 0; i <= max_count; ++i) {\n    // We know that the atom matches each of the first i characters in str.\n    if (i >= min_count && MatchRegexAtHead(regex, str + i)) {\n      // We have enough matches at the head, and the tail matches too.\n      // Since we only care about *whether* the pattern matches str\n      // (as opposed to *how* it matches), there is no need to find a\n      // greedy match.\n      return true;\n    }\n    if (str[i] == '\\0' || !AtomMatchesChar(escaped, c, str[i]))\n      return false;\n  }\n  return false;\n}\n\n// Returns true iff regex matches a prefix of str.  regex must be a\n// valid simple regular expression and not start with \"^\", or the\n// result is undefined.\nbool MatchRegexAtHead(const char* regex, const char* str) {\n  if (*regex == '\\0')  // An empty regex matches a prefix of anything.\n    return true;\n\n  // \"$\" only matches the end of a string.  Note that regex being\n  // valid guarantees that there's nothing after \"$\" in it.\n  if (*regex == '$')\n    return *str == '\\0';\n\n  // Is the first thing in regex an escape sequence?\n  const bool escaped = *regex == '\\\\';\n  if (escaped)\n    ++regex;\n  if (IsRepeat(regex[1])) {\n    // MatchRepetitionAndRegexAtHead() calls MatchRegexAtHead(), so\n    // here's an indirect recursion.  It terminates as the regex gets\n    // shorter in each recursion.\n    return MatchRepetitionAndRegexAtHead(\n        escaped, regex[0], regex[1], regex + 2, str);\n  } else {\n    // regex isn't empty, isn't \"$\", and doesn't start with a\n    // repetition.  We match the first atom of regex with the first\n    // character of str and recurse.\n    return (*str != '\\0') && AtomMatchesChar(escaped, *regex, *str) &&\n        MatchRegexAtHead(regex + 1, str + 1);\n  }\n}\n\n// Returns true iff regex matches any substring of str.  regex must be\n// a valid simple regular expression, or the result is undefined.\n//\n// The algorithm is recursive, but the recursion depth doesn't exceed\n// the regex length, so we won't need to worry about running out of\n// stack space normally.  In rare cases the time complexity can be\n// exponential with respect to the regex length + the string length,\n// but usually it's must faster (often close to linear).\nbool MatchRegexAnywhere(const char* regex, const char* str) {\n  if (regex == NULL || str == NULL)\n    return false;\n\n  if (*regex == '^')\n    return MatchRegexAtHead(regex + 1, str);\n\n  // A successful match can be anywhere in str.\n  do {\n    if (MatchRegexAtHead(regex, str))\n      return true;\n  } while (*str++ != '\\0');\n  return false;\n}\n\n// Implements the RE class.\n\nRE::~RE() {\n  free(const_cast<char*>(pattern_));\n  free(const_cast<char*>(full_pattern_));\n}\n\n// Returns true iff regular expression re matches the entire str.\nbool RE::FullMatch(const char* str, const RE& re) {\n  return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_, str);\n}\n\n// Returns true iff regular expression re matches a substring of str\n// (including str itself).\nbool RE::PartialMatch(const char* str, const RE& re) {\n  return re.is_valid_ && MatchRegexAnywhere(re.pattern_, str);\n}\n\n// Initializes an RE from its string representation.\nvoid RE::Init(const char* regex) {\n  pattern_ = full_pattern_ = NULL;\n  if (regex != NULL) {\n    pattern_ = posix::StrDup(regex);\n  }\n\n  is_valid_ = ValidateRegex(regex);\n  if (!is_valid_) {\n    // No need to calculate the full pattern when the regex is invalid.\n    return;\n  }\n\n  const size_t len = strlen(regex);\n  // Reserves enough bytes to hold the regular expression used for a\n  // full match: we need space to prepend a '^', append a '$', and\n  // terminate the string with '\\0'.\n  char* buffer = static_cast<char*>(malloc(len + 3));\n  full_pattern_ = buffer;\n\n  if (*regex != '^')\n    *buffer++ = '^';  // Makes sure full_pattern_ starts with '^'.\n\n  // We don't use snprintf or strncpy, as they trigger a warning when\n  // compiled with VC++ 8.0.\n  memcpy(buffer, regex, len);\n  buffer += len;\n\n  if (len == 0 || regex[len - 1] != '$')\n    *buffer++ = '$';  // Makes sure full_pattern_ ends with '$'.\n\n  *buffer = '\\0';\n}\n\n#endif  // GTEST_USES_POSIX_RE\n\nconst char kUnknownFile[] = \"unknown file\";\n\n// Formats a source file path and a line number as they would appear\n// in an error message from the compiler used to compile this code.\nGTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {\n  const char* const file_name = file == NULL ? kUnknownFile : file;\n\n  if (line < 0) {\n    return String::Format(\"%s:\", file_name).c_str();\n  }\n#ifdef _MSC_VER\n  return String::Format(\"%s(%d):\", file_name, line).c_str();\n#else\n  return String::Format(\"%s:%d:\", file_name, line).c_str();\n#endif  // _MSC_VER\n}\n\n// Formats a file location for compiler-independent XML output.\n// Although this function is not platform dependent, we put it next to\n// FormatFileLocation in order to contrast the two functions.\n// Note that FormatCompilerIndependentFileLocation() does NOT append colon\n// to the file location it produces, unlike FormatFileLocation().\nGTEST_API_ ::std::string FormatCompilerIndependentFileLocation(\n    const char* file, int line) {\n  const char* const file_name = file == NULL ? kUnknownFile : file;\n\n  if (line < 0)\n    return file_name;\n  else\n    return String::Format(\"%s:%d\", file_name, line).c_str();\n}\n\n\nGTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)\n    : severity_(severity) {\n  const char* const marker =\n      severity == GTEST_INFO ?    \"[  INFO ]\" :\n      severity == GTEST_WARNING ? \"[WARNING]\" :\n      severity == GTEST_ERROR ?   \"[ ERROR ]\" : \"[ FATAL ]\";\n  GetStream() << ::std::endl << marker << \" \"\n              << FormatFileLocation(file, line).c_str() << \": \";\n}\n\n// Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.\nGTestLog::~GTestLog() {\n  GetStream() << ::std::endl;\n  if (severity_ == GTEST_FATAL) {\n    fflush(stderr);\n    posix::Abort();\n  }\n}\n// Disable Microsoft deprecation warnings for POSIX functions called from\n// this class (creat, dup, dup2, and close)\n#ifdef _MSC_VER\n# pragma warning(push)\n# pragma warning(disable: 4996)\n#endif  // _MSC_VER\n\n#if GTEST_HAS_STREAM_REDIRECTION\n\n// Object that captures an output stream (stdout/stderr).\nclass CapturedStream {\n public:\n  // The ctor redirects the stream to a temporary file.\n  CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {\n\n# if GTEST_OS_WINDOWS\n    char temp_dir_path[MAX_PATH + 1] = { '\\0' };  // NOLINT\n    char temp_file_path[MAX_PATH + 1] = { '\\0' };  // NOLINT\n\n    ::GetTempPathA(sizeof(temp_dir_path), temp_dir_path);\n    const UINT success = ::GetTempFileNameA(temp_dir_path,\n                                            \"gtest_redir\",\n                                            0,  // Generate unique file name.\n                                            temp_file_path);\n    GTEST_CHECK_(success != 0)\n        << \"Unable to create a temporary file in \" << temp_dir_path;\n    const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE);\n    GTEST_CHECK_(captured_fd != -1) << \"Unable to open temporary file \"\n                                    << temp_file_path;\n    filename_ = temp_file_path;\n# else\n    // There's no guarantee that a test has write access to the\n    // current directory, so we create the temporary file in the /tmp\n    // directory instead.\n    char name_template[] = \"/tmp/captured_stream.XXXXXX\";\n    const int captured_fd = mkstemp(name_template);\n    filename_ = name_template;\n# endif  // GTEST_OS_WINDOWS\n    fflush(NULL);\n    dup2(captured_fd, fd_);\n    close(captured_fd);\n  }\n\n  ~CapturedStream() {\n    remove(filename_.c_str());\n  }\n\n  String GetCapturedString() {\n    if (uncaptured_fd_ != -1) {\n      // Restores the original stream.\n      fflush(NULL);\n      dup2(uncaptured_fd_, fd_);\n      close(uncaptured_fd_);\n      uncaptured_fd_ = -1;\n    }\n\n    FILE* const file = posix::FOpen(filename_.c_str(), \"r\");\n    const String content = ReadEntireFile(file);\n    posix::FClose(file);\n    return content;\n  }\n\n private:\n  // Reads the entire content of a file as a String.\n  static String ReadEntireFile(FILE* file);\n\n  // Returns the size (in bytes) of a file.\n  static size_t GetFileSize(FILE* file);\n\n  const int fd_;  // A stream to capture.\n  int uncaptured_fd_;\n  // Name of the temporary file holding the stderr output.\n  ::std::string filename_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(CapturedStream);\n};\n\n// Returns the size (in bytes) of a file.\nsize_t CapturedStream::GetFileSize(FILE* file) {\n  fseek(file, 0, SEEK_END);\n  return static_cast<size_t>(ftell(file));\n}\n\n// Reads the entire content of a file as a string.\nString CapturedStream::ReadEntireFile(FILE* file) {\n  const size_t file_size = GetFileSize(file);\n  char* const buffer = new char[file_size];\n\n  size_t bytes_last_read = 0;  // # of bytes read in the last fread()\n  size_t bytes_read = 0;       // # of bytes read so far\n\n  fseek(file, 0, SEEK_SET);\n\n  // Keeps reading the file until we cannot read further or the\n  // pre-determined file size is reached.\n  do {\n    bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);\n    bytes_read += bytes_last_read;\n  } while (bytes_last_read > 0 && bytes_read < file_size);\n\n  const String content(buffer, bytes_read);\n  delete[] buffer;\n\n  return content;\n}\n\n# ifdef _MSC_VER\n#  pragma warning(pop)\n# endif  // _MSC_VER\n\nstatic CapturedStream* g_captured_stderr = NULL;\nstatic CapturedStream* g_captured_stdout = NULL;\n\n// Starts capturing an output stream (stdout/stderr).\nvoid CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {\n  if (*stream != NULL) {\n    GTEST_LOG_(FATAL) << \"Only one \" << stream_name\n                      << \" capturer can exist at a time.\";\n  }\n  *stream = new CapturedStream(fd);\n}\n\n// Stops capturing the output stream and returns the captured string.\nString GetCapturedStream(CapturedStream** captured_stream) {\n  const String content = (*captured_stream)->GetCapturedString();\n\n  delete *captured_stream;\n  *captured_stream = NULL;\n\n  return content;\n}\n\n// Starts capturing stdout.\nvoid CaptureStdout() {\n  CaptureStream(kStdOutFileno, \"stdout\", &g_captured_stdout);\n}\n\n// Starts capturing stderr.\nvoid CaptureStderr() {\n  CaptureStream(kStdErrFileno, \"stderr\", &g_captured_stderr);\n}\n\n// Stops capturing stdout and returns the captured string.\nString GetCapturedStdout() { return GetCapturedStream(&g_captured_stdout); }\n\n// Stops capturing stderr and returns the captured string.\nString GetCapturedStderr() { return GetCapturedStream(&g_captured_stderr); }\n\n#endif  // GTEST_HAS_STREAM_REDIRECTION\n\n#if GTEST_HAS_DEATH_TEST\n\n// A copy of all command line arguments.  Set by InitGoogleTest().\n::std::vector<String> g_argvs;\n\n// Returns the command line as a vector of strings.\nconst ::std::vector<String>& GetArgvs() { return g_argvs; }\n\n#endif  // GTEST_HAS_DEATH_TEST\n\n#if GTEST_OS_WINDOWS_MOBILE\nnamespace posix {\nvoid Abort() {\n  DebugBreak();\n  TerminateProcess(GetCurrentProcess(), 1);\n}\n}  // namespace posix\n#endif  // GTEST_OS_WINDOWS_MOBILE\n\n// Returns the name of the environment variable corresponding to the\n// given flag.  For example, FlagToEnvVar(\"foo\") will return\n// \"GTEST_FOO\" in the open-source version.\nstatic String FlagToEnvVar(const char* flag) {\n  const String full_flag =\n      (Message() << GTEST_FLAG_PREFIX_ << flag).GetString();\n\n  Message env_var;\n  for (size_t i = 0; i != full_flag.length(); i++) {\n    env_var << ToUpper(full_flag.c_str()[i]);\n  }\n\n  return env_var.GetString();\n}\n\n// Parses 'str' for a 32-bit signed integer.  If successful, writes\n// the result to *value and returns true; otherwise leaves *value\n// unchanged and returns false.\nbool ParseInt32(const Message& src_text, const char* str, Int32* value) {\n  // Parses the environment variable as a decimal integer.\n  char* end = NULL;\n  const long long_value = strtol(str, &end, 10);  // NOLINT\n\n  // Has strtol() consumed all characters in the string?\n  if (*end != '\\0') {\n    // No - an invalid character was encountered.\n    Message msg;\n    msg << \"WARNING: \" << src_text\n        << \" is expected to be a 32-bit integer, but actually\"\n        << \" has value \\\"\" << str << \"\\\".\\n\";\n    printf(\"%s\", msg.GetString().c_str());\n    fflush(stdout);\n    return false;\n  }\n\n  // Is the parsed value in the range of an Int32?\n  const Int32 result = static_cast<Int32>(long_value);\n  if (long_value == LONG_MAX || long_value == LONG_MIN ||\n      // The parsed value overflows as a long.  (strtol() returns\n      // LONG_MAX or LONG_MIN when the input overflows.)\n      result != long_value\n      // The parsed value overflows as an Int32.\n      ) {\n    Message msg;\n    msg << \"WARNING: \" << src_text\n        << \" is expected to be a 32-bit integer, but actually\"\n        << \" has value \" << str << \", which overflows.\\n\";\n    printf(\"%s\", msg.GetString().c_str());\n    fflush(stdout);\n    return false;\n  }\n\n  *value = result;\n  return true;\n}\n\n// Reads and returns the Boolean environment variable corresponding to\n// the given flag; if it's not set, returns default_value.\n//\n// The value is considered true iff it's not \"0\".\nbool BoolFromGTestEnv(const char* flag, bool default_value) {\n  const String env_var = FlagToEnvVar(flag);\n  const char* const string_value = posix::GetEnv(env_var.c_str());\n  return string_value == NULL ?\n      default_value : strcmp(string_value, \"0\") != 0;\n}\n\n// Reads and returns a 32-bit integer stored in the environment\n// variable corresponding to the given flag; if it isn't set or\n// doesn't represent a valid 32-bit integer, returns default_value.\nInt32 Int32FromGTestEnv(const char* flag, Int32 default_value) {\n  const String env_var = FlagToEnvVar(flag);\n  const char* const string_value = posix::GetEnv(env_var.c_str());\n  if (string_value == NULL) {\n    // The environment variable is not set.\n    return default_value;\n  }\n\n  Int32 result = default_value;\n  if (!ParseInt32(Message() << \"Environment variable \" << env_var,\n                  string_value, &result)) {\n    printf(\"The default value %s is used.\\n\",\n           (Message() << default_value).GetString().c_str());\n    fflush(stdout);\n    return default_value;\n  }\n\n  return result;\n}\n\n// Reads and returns the string environment variable corresponding to\n// the given flag; if it's not set, returns default_value.\nconst char* StringFromGTestEnv(const char* flag, const char* default_value) {\n  const String env_var = FlagToEnvVar(flag);\n  const char* const value = posix::GetEnv(env_var.c_str());\n  return value == NULL ? default_value : value;\n}\n\n}  // namespace internal\n}  // namespace testing\n// Copyright 2007, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n\n// Google Test - The Google C++ Testing Framework\n//\n// This file implements a universal value printer that can print a\n// value of any type T:\n//\n//   void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);\n//\n// It uses the << operator when possible, and prints the bytes in the\n// object otherwise.  A user can override its behavior for a class\n// type Foo by defining either operator<<(::std::ostream&, const Foo&)\n// or void PrintTo(const Foo&, ::std::ostream*) in the namespace that\n// defines Foo.\n\n#include <ctype.h>\n#include <stdio.h>\n#include <ostream>  // NOLINT\n#include <string>\n\nnamespace testing {\n\nnamespace {\n\nusing ::std::ostream;\n\n#if GTEST_OS_WINDOWS_MOBILE  // Windows CE does not define _snprintf_s.\n# define snprintf _snprintf\n#elif _MSC_VER >= 1400  // VC 8.0 and later deprecate snprintf and _snprintf.\n# define snprintf _snprintf_s\n#elif _MSC_VER\n# define snprintf _snprintf\n#endif  // GTEST_OS_WINDOWS_MOBILE\n\n// Prints a segment of bytes in the given object.\nvoid PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,\n                                size_t count, ostream* os) {\n  char text[5] = \"\";\n  for (size_t i = 0; i != count; i++) {\n    const size_t j = start + i;\n    if (i != 0) {\n      // Organizes the bytes into groups of 2 for easy parsing by\n      // human.\n      if ((j % 2) == 0)\n        *os << ' ';\n      else\n        *os << '-';\n    }\n    snprintf(text, sizeof(text), \"%02X\", obj_bytes[j]);\n    *os << text;\n  }\n}\n\n// Prints the bytes in the given value to the given ostream.\nvoid PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,\n                              ostream* os) {\n  // Tells the user how big the object is.\n  *os << count << \"-byte object <\";\n\n  const size_t kThreshold = 132;\n  const size_t kChunkSize = 64;\n  // If the object size is bigger than kThreshold, we'll have to omit\n  // some details by printing only the first and the last kChunkSize\n  // bytes.\n  // TODO(wan): let the user control the threshold using a flag.\n  if (count < kThreshold) {\n    PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);\n  } else {\n    PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);\n    *os << \" ... \";\n    // Rounds up to 2-byte boundary.\n    const size_t resume_pos = (count - kChunkSize + 1)/2*2;\n    PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os);\n  }\n  *os << \">\";\n}\n\n}  // namespace\n\nnamespace internal2 {\n\n// Delegates to PrintBytesInObjectToImpl() to print the bytes in the\n// given object.  The delegation simplifies the implementation, which\n// uses the << operator and thus is easier done outside of the\n// ::testing::internal namespace, which contains a << operator that\n// sometimes conflicts with the one in STL.\nvoid PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count,\n                          ostream* os) {\n  PrintBytesInObjectToImpl(obj_bytes, count, os);\n}\n\n}  // namespace internal2\n\nnamespace internal {\n\n// Depending on the value of a char (or wchar_t), we print it in one\n// of three formats:\n//   - as is if it's a printable ASCII (e.g. 'a', '2', ' '),\n//   - as a hexidecimal escape sequence (e.g. '\\x7F'), or\n//   - as a special escape sequence (e.g. '\\r', '\\n').\nenum CharFormat {\n  kAsIs,\n  kHexEscape,\n  kSpecialEscape\n};\n\n// Returns true if c is a printable ASCII character.  We test the\n// value of c directly instead of calling isprint(), which is buggy on\n// Windows Mobile.\ninline bool IsPrintableAscii(wchar_t c) {\n  return 0x20 <= c && c <= 0x7E;\n}\n\n// Prints a wide or narrow char c as a character literal without the\n// quotes, escaping it when necessary; returns how c was formatted.\n// The template argument UnsignedChar is the unsigned version of Char,\n// which is the type of c.\ntemplate <typename UnsignedChar, typename Char>\nstatic CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {\n  switch (static_cast<wchar_t>(c)) {\n    case L'\\0':\n      *os << \"\\\\0\";\n      break;\n    case L'\\'':\n      *os << \"\\\\'\";\n      break;\n    case L'\\\\':\n      *os << \"\\\\\\\\\";\n      break;\n    case L'\\a':\n      *os << \"\\\\a\";\n      break;\n    case L'\\b':\n      *os << \"\\\\b\";\n      break;\n    case L'\\f':\n      *os << \"\\\\f\";\n      break;\n    case L'\\n':\n      *os << \"\\\\n\";\n      break;\n    case L'\\r':\n      *os << \"\\\\r\";\n      break;\n    case L'\\t':\n      *os << \"\\\\t\";\n      break;\n    case L'\\v':\n      *os << \"\\\\v\";\n      break;\n    default:\n      if (IsPrintableAscii(c)) {\n        *os << static_cast<char>(c);\n        return kAsIs;\n      } else {\n        *os << String::Format(\"\\\\x%X\", static_cast<UnsignedChar>(c));\n        return kHexEscape;\n      }\n  }\n  return kSpecialEscape;\n}\n\n// Prints a char c as if it's part of a string literal, escaping it when\n// necessary; returns how c was formatted.\nstatic CharFormat PrintAsWideStringLiteralTo(wchar_t c, ostream* os) {\n  switch (c) {\n    case L'\\'':\n      *os << \"'\";\n      return kAsIs;\n    case L'\"':\n      *os << \"\\\\\\\"\";\n      return kSpecialEscape;\n    default:\n      return PrintAsCharLiteralTo<wchar_t>(c, os);\n  }\n}\n\n// Prints a char c as if it's part of a string literal, escaping it when\n// necessary; returns how c was formatted.\nstatic CharFormat PrintAsNarrowStringLiteralTo(char c, ostream* os) {\n  return PrintAsWideStringLiteralTo(static_cast<unsigned char>(c), os);\n}\n\n// Prints a wide or narrow character c and its code.  '\\0' is printed\n// as \"'\\\\0'\", other unprintable characters are also properly escaped\n// using the standard C++ escape sequence.  The template argument\n// UnsignedChar is the unsigned version of Char, which is the type of c.\ntemplate <typename UnsignedChar, typename Char>\nvoid PrintCharAndCodeTo(Char c, ostream* os) {\n  // First, print c as a literal in the most readable form we can find.\n  *os << ((sizeof(c) > 1) ? \"L'\" : \"'\");\n  const CharFormat format = PrintAsCharLiteralTo<UnsignedChar>(c, os);\n  *os << \"'\";\n\n  // To aid user debugging, we also print c's code in decimal, unless\n  // it's 0 (in which case c was printed as '\\\\0', making the code\n  // obvious).\n  if (c == 0)\n    return;\n  *os << \" (\" << String::Format(\"%d\", c).c_str();\n\n  // For more convenience, we print c's code again in hexidecimal,\n  // unless c was already printed in the form '\\x##' or the code is in\n  // [1, 9].\n  if (format == kHexEscape || (1 <= c && c <= 9)) {\n    // Do nothing.\n  } else {\n    *os << String::Format(\", 0x%X\",\n                          static_cast<UnsignedChar>(c)).c_str();\n  }\n  *os << \")\";\n}\n\nvoid PrintTo(unsigned char c, ::std::ostream* os) {\n  PrintCharAndCodeTo<unsigned char>(c, os);\n}\nvoid PrintTo(signed char c, ::std::ostream* os) {\n  PrintCharAndCodeTo<unsigned char>(c, os);\n}\n\n// Prints a wchar_t as a symbol if it is printable or as its internal\n// code otherwise and also as its code.  L'\\0' is printed as \"L'\\\\0'\".\nvoid PrintTo(wchar_t wc, ostream* os) {\n  PrintCharAndCodeTo<wchar_t>(wc, os);\n}\n\n// Prints the given array of characters to the ostream.\n// The array starts at *begin, the length is len, it may include '\\0' characters\n// and may not be null-terminated.\nstatic void PrintCharsAsStringTo(const char* begin, size_t len, ostream* os) {\n  *os << \"\\\"\";\n  bool is_previous_hex = false;\n  for (size_t index = 0; index < len; ++index) {\n    const char cur = begin[index];\n    if (is_previous_hex && IsXDigit(cur)) {\n      // Previous character is of '\\x..' form and this character can be\n      // interpreted as another hexadecimal digit in its number. Break string to\n      // disambiguate.\n      *os << \"\\\" \\\"\";\n    }\n    is_previous_hex = PrintAsNarrowStringLiteralTo(cur, os) == kHexEscape;\n  }\n  *os << \"\\\"\";\n}\n\n// Prints a (const) char array of 'len' elements, starting at address 'begin'.\nvoid UniversalPrintArray(const char* begin, size_t len, ostream* os) {\n  PrintCharsAsStringTo(begin, len, os);\n}\n\n// Prints the given array of wide characters to the ostream.\n// The array starts at *begin, the length is len, it may include L'\\0'\n// characters and may not be null-terminated.\nstatic void PrintWideCharsAsStringTo(const wchar_t* begin, size_t len,\n                                     ostream* os) {\n  *os << \"L\\\"\";\n  bool is_previous_hex = false;\n  for (size_t index = 0; index < len; ++index) {\n    const wchar_t cur = begin[index];\n    if (is_previous_hex && isascii(cur) && IsXDigit(static_cast<char>(cur))) {\n      // Previous character is of '\\x..' form and this character can be\n      // interpreted as another hexadecimal digit in its number. Break string to\n      // disambiguate.\n      *os << \"\\\" L\\\"\";\n    }\n    is_previous_hex = PrintAsWideStringLiteralTo(cur, os) == kHexEscape;\n  }\n  *os << \"\\\"\";\n}\n\n// Prints the given C string to the ostream.\nvoid PrintTo(const char* s, ostream* os) {\n  if (s == NULL) {\n    *os << \"NULL\";\n  } else {\n    *os << ImplicitCast_<const void*>(s) << \" pointing to \";\n    PrintCharsAsStringTo(s, strlen(s), os);\n  }\n}\n\n// MSVC compiler can be configured to define whar_t as a typedef\n// of unsigned short. Defining an overload for const wchar_t* in that case\n// would cause pointers to unsigned shorts be printed as wide strings,\n// possibly accessing more memory than intended and causing invalid\n// memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when\n// wchar_t is implemented as a native type.\n#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)\n// Prints the given wide C string to the ostream.\nvoid PrintTo(const wchar_t* s, ostream* os) {\n  if (s == NULL) {\n    *os << \"NULL\";\n  } else {\n    *os << ImplicitCast_<const void*>(s) << \" pointing to \";\n    PrintWideCharsAsStringTo(s, wcslen(s), os);\n  }\n}\n#endif  // wchar_t is native\n\n// Prints a ::string object.\n#if GTEST_HAS_GLOBAL_STRING\nvoid PrintStringTo(const ::string& s, ostream* os) {\n  PrintCharsAsStringTo(s.data(), s.size(), os);\n}\n#endif  // GTEST_HAS_GLOBAL_STRING\n\nvoid PrintStringTo(const ::std::string& s, ostream* os) {\n  PrintCharsAsStringTo(s.data(), s.size(), os);\n}\n\n// Prints a ::wstring object.\n#if GTEST_HAS_GLOBAL_WSTRING\nvoid PrintWideStringTo(const ::wstring& s, ostream* os) {\n  PrintWideCharsAsStringTo(s.data(), s.size(), os);\n}\n#endif  // GTEST_HAS_GLOBAL_WSTRING\n\n#if GTEST_HAS_STD_WSTRING\nvoid PrintWideStringTo(const ::std::wstring& s, ostream* os) {\n  PrintWideCharsAsStringTo(s.data(), s.size(), os);\n}\n#endif  // GTEST_HAS_STD_WSTRING\n\n}  // namespace internal\n\n}  // namespace testing\n// Copyright 2008, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: mheule@google.com (Markus Heule)\n//\n// The Google C++ Testing Framework (Google Test)\n\n\n// Indicates that this translation unit is part of Google Test's\n// implementation.  It must come before gtest-internal-inl.h is\n// included, or there will be a compiler error.  This trick is to\n// prevent a user from accidentally including gtest-internal-inl.h in\n// his code.\n#define GTEST_IMPLEMENTATION_ 1\n#undef GTEST_IMPLEMENTATION_\n\nnamespace testing {\n\nusing internal::GetUnitTestImpl;\n\n// Gets the summary of the failure message by omitting the stack trace\n// in it.\ninternal::String TestPartResult::ExtractSummary(const char* message) {\n  const char* const stack_trace = strstr(message, internal::kStackTraceMarker);\n  return stack_trace == NULL ? internal::String(message) :\n      internal::String(message, stack_trace - message);\n}\n\n// Prints a TestPartResult object.\nstd::ostream& operator<<(std::ostream& os, const TestPartResult& result) {\n  return os\n      << result.file_name() << \":\" << result.line_number() << \": \"\n      << (result.type() == TestPartResult::kSuccess ? \"Success\" :\n          result.type() == TestPartResult::kFatalFailure ? \"Fatal failure\" :\n          \"Non-fatal failure\") << \":\\n\"\n      << result.message() << std::endl;\n}\n\n// Appends a TestPartResult to the array.\nvoid TestPartResultArray::Append(const TestPartResult& result) {\n  array_.push_back(result);\n}\n\n// Returns the TestPartResult at the given index (0-based).\nconst TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {\n  if (index < 0 || index >= size()) {\n    printf(\"\\nInvalid index (%d) into TestPartResultArray.\\n\", index);\n    internal::posix::Abort();\n  }\n\n  return array_[index];\n}\n\n// Returns the number of TestPartResult objects in the array.\nint TestPartResultArray::size() const {\n  return static_cast<int>(array_.size());\n}\n\nnamespace internal {\n\nHasNewFatalFailureHelper::HasNewFatalFailureHelper()\n    : has_new_fatal_failure_(false),\n      original_reporter_(GetUnitTestImpl()->\n                         GetTestPartResultReporterForCurrentThread()) {\n  GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this);\n}\n\nHasNewFatalFailureHelper::~HasNewFatalFailureHelper() {\n  GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(\n      original_reporter_);\n}\n\nvoid HasNewFatalFailureHelper::ReportTestPartResult(\n    const TestPartResult& result) {\n  if (result.fatally_failed())\n    has_new_fatal_failure_ = true;\n  original_reporter_->ReportTestPartResult(result);\n}\n\n}  // namespace internal\n\n}  // namespace testing\n// Copyright 2008 Google Inc.\n// All Rights Reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n\n\nnamespace testing {\nnamespace internal {\n\n#if GTEST_HAS_TYPED_TEST_P\n\n// Skips to the first non-space char in str. Returns an empty string if str\n// contains only whitespace characters.\nstatic const char* SkipSpaces(const char* str) {\n  while (IsSpace(*str))\n    str++;\n  return str;\n}\n\n// Verifies that registered_tests match the test names in\n// defined_test_names_; returns registered_tests if successful, or\n// aborts the program otherwise.\nconst char* TypedTestCasePState::VerifyRegisteredTestNames(\n    const char* file, int line, const char* registered_tests) {\n  typedef ::std::set<const char*>::const_iterator DefinedTestIter;\n  registered_ = true;\n\n  // Skip initial whitespace in registered_tests since some\n  // preprocessors prefix stringizied literals with whitespace.\n  registered_tests = SkipSpaces(registered_tests);\n\n  Message errors;\n  ::std::set<String> tests;\n  for (const char* names = registered_tests; names != NULL;\n       names = SkipComma(names)) {\n    const String name = GetPrefixUntilComma(names);\n    if (tests.count(name) != 0) {\n      errors << \"Test \" << name << \" is listed more than once.\\n\";\n      continue;\n    }\n\n    bool found = false;\n    for (DefinedTestIter it = defined_test_names_.begin();\n         it != defined_test_names_.end();\n         ++it) {\n      if (name == *it) {\n        found = true;\n        break;\n      }\n    }\n\n    if (found) {\n      tests.insert(name);\n    } else {\n      errors << \"No test named \" << name\n             << \" can be found in this test case.\\n\";\n    }\n  }\n\n  for (DefinedTestIter it = defined_test_names_.begin();\n       it != defined_test_names_.end();\n       ++it) {\n    if (tests.count(*it) == 0) {\n      errors << \"You forgot to list test \" << *it << \".\\n\";\n    }\n  }\n\n  const String& errors_str = errors.GetString();\n  if (errors_str != \"\") {\n    fprintf(stderr, \"%s %s\", FormatFileLocation(file, line).c_str(),\n            errors_str.c_str());\n    fflush(stderr);\n    posix::Abort();\n  }\n\n  return registered_tests;\n}\n\n#endif  // GTEST_HAS_TYPED_TEST_P\n\n}  // namespace internal\n}  // namespace testing\n"
  },
  {
    "path": "src/gtest/gtest.h",
    "content": "// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n//\n// The Google C++ Testing Framework (Google Test)\n//\n// This header file defines the public API for Google Test.  It should be\n// included by any test program that uses Google Test.\n//\n// IMPORTANT NOTE: Due to limitation of the C++ language, we have to\n// leave some internal implementation details in this header file.\n// They are clearly marked by comments like this:\n//\n//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\n//\n// Such code is NOT meant to be used by a user directly, and is subject\n// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user\n// program!\n//\n// Acknowledgment: Google Test borrowed the idea of automatic test\n// registration from Barthelemy Dagenais' (barthelemy@prologique.com)\n// easyUnit framework.\n\n#ifndef GTEST_INCLUDE_GTEST_GTEST_H_\n#define GTEST_INCLUDE_GTEST_GTEST_H_\n\n#include <limits>\n#include <vector>\n\n// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)\n//\n// The Google C++ Testing Framework (Google Test)\n//\n// This header file declares functions and macros used internally by\n// Google Test.  They are subject to change without notice.\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_\n\n// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Authors: wan@google.com (Zhanyong Wan)\n//\n// Low-level types and utilities for porting Google Test to various\n// platforms.  They are subject to change without notice.  DO NOT USE\n// THEM IN USER CODE.\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_\n\n// The user can define the following macros in the build script to\n// control Google Test's behavior.  If the user doesn't define a macro\n// in this list, Google Test will define it.\n//\n//   GTEST_HAS_CLONE          - Define it to 1/0 to indicate that clone(2)\n//                              is/isn't available.\n//   GTEST_HAS_EXCEPTIONS     - Define it to 1/0 to indicate that exceptions\n//                              are enabled.\n//   GTEST_HAS_GLOBAL_STRING  - Define it to 1/0 to indicate that ::string\n//                              is/isn't available (some systems define\n//                              ::string, which is different to std::string).\n//   GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string\n//                              is/isn't available (some systems define\n//                              ::wstring, which is different to std::wstring).\n//   GTEST_HAS_POSIX_RE       - Define it to 1/0 to indicate that POSIX regular\n//                              expressions are/aren't available.\n//   GTEST_HAS_PTHREAD        - Define it to 1/0 to indicate that <pthread.h>\n//                              is/isn't available.\n//   GTEST_HAS_RTTI           - Define it to 1/0 to indicate that RTTI is/isn't\n//                              enabled.\n//   GTEST_HAS_STD_WSTRING    - Define it to 1/0 to indicate that\n//                              std::wstring does/doesn't work (Google Test can\n//                              be used where std::wstring is unavailable).\n//   GTEST_HAS_TR1_TUPLE      - Define it to 1/0 to indicate tr1::tuple\n//                              is/isn't available.\n//   GTEST_HAS_SEH            - Define it to 1/0 to indicate whether the\n//                              compiler supports Microsoft's \"Structured\n//                              Exception Handling\".\n//   GTEST_HAS_STREAM_REDIRECTION\n//                            - Define it to 1/0 to indicate whether the\n//                              platform supports I/O stream redirection using\n//                              dup() and dup2().\n//   GTEST_USE_OWN_TR1_TUPLE  - Define it to 1/0 to indicate whether Google\n//                              Test's own tr1 tuple implementation should be\n//                              used.  Unused when the user sets\n//                              GTEST_HAS_TR1_TUPLE to 0.\n//   GTEST_LINKED_AS_SHARED_LIBRARY\n//                            - Define to 1 when compiling tests that use\n//                              Google Test as a shared library (known as\n//                              DLL on Windows).\n//   GTEST_CREATE_SHARED_LIBRARY\n//                            - Define to 1 when compiling Google Test itself\n//                              as a shared library.\n\n// This header defines the following utilities:\n//\n// Macros indicating the current platform (defined to 1 if compiled on\n// the given platform; otherwise undefined):\n//   GTEST_OS_AIX      - IBM AIX\n//   GTEST_OS_CYGWIN   - Cygwin\n//   GTEST_OS_HPUX     - HP-UX\n//   GTEST_OS_LINUX    - Linux\n//     GTEST_OS_LINUX_ANDROID - Google Android\n//   GTEST_OS_MAC      - Mac OS X\n//   GTEST_OS_NACL     - Google Native Client (NaCl)\n//   GTEST_OS_SOLARIS  - Sun Solaris\n//   GTEST_OS_SYMBIAN  - Symbian\n//   GTEST_OS_WINDOWS  - Windows (Desktop, MinGW, or Mobile)\n//     GTEST_OS_WINDOWS_DESKTOP  - Windows Desktop\n//     GTEST_OS_WINDOWS_MINGW    - MinGW\n//     GTEST_OS_WINDOWS_MOBILE   - Windows Mobile\n//   GTEST_OS_ZOS      - z/OS\n//\n// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the\n// most stable support.  Since core members of the Google Test project\n// don't have access to other platforms, support for them may be less\n// stable.  If you notice any problems on your platform, please notify\n// googletestframework@googlegroups.com (patches for fixing them are\n// even more welcome!).\n//\n// Note that it is possible that none of the GTEST_OS_* macros are defined.\n//\n// Macros indicating available Google Test features (defined to 1 if\n// the corresponding feature is supported; otherwise undefined):\n//   GTEST_HAS_COMBINE      - the Combine() function (for value-parameterized\n//                            tests)\n//   GTEST_HAS_DEATH_TEST   - death tests\n//   GTEST_HAS_PARAM_TEST   - value-parameterized tests\n//   GTEST_HAS_TYPED_TEST   - typed tests\n//   GTEST_HAS_TYPED_TEST_P - type-parameterized tests\n//   GTEST_USES_POSIX_RE    - enhanced POSIX regex is used. Do not confuse with\n//                            GTEST_HAS_POSIX_RE (see above) which users can\n//                            define themselves.\n//   GTEST_USES_SIMPLE_RE   - our own simple regex is used;\n//                            the above two are mutually exclusive.\n//   GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().\n//\n// Macros for basic C++ coding:\n//   GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.\n//   GTEST_ATTRIBUTE_UNUSED_  - declares that a class' instances or a\n//                              variable don't have to be used.\n//   GTEST_DISALLOW_ASSIGN_   - disables operator=.\n//   GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.\n//   GTEST_MUST_USE_RESULT_   - declares that a function's result must be used.\n//\n// Synchronization:\n//   Mutex, MutexLock, ThreadLocal, GetThreadCount()\n//                  - synchronization primitives.\n//   GTEST_IS_THREADSAFE - defined to 1 to indicate that the above\n//                         synchronization primitives have real implementations\n//                         and Google Test is thread-safe; or 0 otherwise.\n//\n// Template meta programming:\n//   is_pointer     - as in TR1; needed on Symbian and IBM XL C/C++ only.\n//   IteratorTraits - partial implementation of std::iterator_traits, which\n//                    is not available in libCstd when compiled with Sun C++.\n//\n// Smart pointers:\n//   scoped_ptr     - as in TR2.\n//\n// Regular expressions:\n//   RE             - a simple regular expression class using the POSIX\n//                    Extended Regular Expression syntax on UNIX-like\n//                    platforms, or a reduced regular exception syntax on\n//                    other platforms, including Windows.\n//\n// Logging:\n//   GTEST_LOG_()   - logs messages at the specified severity level.\n//   LogToStderr()  - directs all log messages to stderr.\n//   FlushInfoLog() - flushes informational log messages.\n//\n// Stdout and stderr capturing:\n//   CaptureStdout()     - starts capturing stdout.\n//   GetCapturedStdout() - stops capturing stdout and returns the captured\n//                         string.\n//   CaptureStderr()     - starts capturing stderr.\n//   GetCapturedStderr() - stops capturing stderr and returns the captured\n//                         string.\n//\n// Integer types:\n//   TypeWithSize   - maps an integer to a int type.\n//   Int32, UInt32, Int64, UInt64, TimeInMillis\n//                  - integers of known sizes.\n//   BiggestInt     - the biggest signed integer type.\n//\n// Command-line utilities:\n//   GTEST_FLAG()       - references a flag.\n//   GTEST_DECLARE_*()  - declares a flag.\n//   GTEST_DEFINE_*()   - defines a flag.\n//   GetArgvs()         - returns the command line as a vector of strings.\n//\n// Environment variable utilities:\n//   GetEnv()             - gets the value of an environment variable.\n//   BoolFromGTestEnv()   - parses a bool environment variable.\n//   Int32FromGTestEnv()  - parses an Int32 environment variable.\n//   StringFromGTestEnv() - parses a string environment variable.\n\n#include <ctype.h>   // for isspace, etc\n#include <stddef.h>  // for ptrdiff_t\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#ifndef _WIN32_WCE\n# include <sys/types.h>\n# include <sys/stat.h>\n#endif  // !_WIN32_WCE\n\n#include <iostream>  // NOLINT\n#include <sstream>  // NOLINT\n#include <string>  // NOLINT\n\n#define GTEST_DEV_EMAIL_ \"googletestframework@@googlegroups.com\"\n#define GTEST_FLAG_PREFIX_ \"gtest_\"\n#define GTEST_FLAG_PREFIX_DASH_ \"gtest-\"\n#define GTEST_FLAG_PREFIX_UPPER_ \"GTEST_\"\n#define GTEST_NAME_ \"Google Test\"\n#define GTEST_PROJECT_URL_ \"http://code.google.com/p/googletest/\"\n\n// Determines the version of gcc that is used to compile this.\n#ifdef __GNUC__\n// 40302 means version 4.3.2.\n# define GTEST_GCC_VER_ \\\n    (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)\n#endif  // __GNUC__\n\n// Determines the platform on which Google Test is compiled.\n#ifdef __CYGWIN__\n# define GTEST_OS_CYGWIN 1\n#elif defined __SYMBIAN32__\n# define GTEST_OS_SYMBIAN 1\n#elif defined _WIN32\n# define GTEST_OS_WINDOWS 1\n# ifdef _WIN32_WCE\n#  define GTEST_OS_WINDOWS_MOBILE 1\n# elif defined(__MINGW__) || defined(__MINGW32__)\n#  define GTEST_OS_WINDOWS_MINGW 1\n# else\n#  define GTEST_OS_WINDOWS_DESKTOP 1\n# endif  // _WIN32_WCE\n#elif defined __APPLE__\n# define GTEST_OS_MAC 1\n#elif defined __linux__\n# define GTEST_OS_LINUX 1\n# ifdef ANDROID\n#  define GTEST_OS_LINUX_ANDROID 1\n# endif  // ANDROID\n#elif defined __MVS__\n# define GTEST_OS_ZOS 1\n#elif defined(__sun) && defined(__SVR4)\n# define GTEST_OS_SOLARIS 1\n#elif defined(_AIX)\n# define GTEST_OS_AIX 1\n#elif defined(__hpux)\n# define GTEST_OS_HPUX 1\n#elif defined __native_client__\n# define GTEST_OS_NACL 1\n#endif  // __CYGWIN__\n\n// Brings in definitions for functions used in the testing::internal::posix\n// namespace (read, write, close, chdir, isatty, stat). We do not currently\n// use them on Windows Mobile.\n#if !GTEST_OS_WINDOWS\n// This assumes that non-Windows OSes provide unistd.h. For OSes where this\n// is not the case, we need to include headers that provide the functions\n// mentioned above.\n# include <unistd.h>\n# if !GTEST_OS_NACL\n// TODO(vladl@google.com): Remove this condition when Native Client SDK adds\n// strings.h (tracked in\n// http://code.google.com/p/nativeclient/issues/detail?id=1175).\n#  include <strings.h>  // Native Client doesn't provide strings.h.\n# endif\n#elif !GTEST_OS_WINDOWS_MOBILE\n# include <direct.h>\n# include <io.h>\n#endif\n\n// Defines this to true iff Google Test can use POSIX regular expressions.\n#ifndef GTEST_HAS_POSIX_RE\n# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)\n#endif\n\n#if GTEST_HAS_POSIX_RE\n\n// On some platforms, <regex.h> needs someone to define size_t, and\n// won't compile otherwise.  We can #include it here as we already\n// included <stdlib.h>, which is guaranteed to define size_t through\n// <stddef.h>.\n# include <regex.h>  // NOLINT\n\n# define GTEST_USES_POSIX_RE 1\n\n#elif GTEST_OS_WINDOWS\n\n// <regex.h> is not available on Windows.  Use our own simple regex\n// implementation instead.\n# define GTEST_USES_SIMPLE_RE 1\n\n#else\n\n// <regex.h> may not be available on this platform.  Use our own\n// simple regex implementation instead.\n# define GTEST_USES_SIMPLE_RE 1\n\n#endif  // GTEST_HAS_POSIX_RE\n\n#ifndef GTEST_HAS_EXCEPTIONS\n// The user didn't tell us whether exceptions are enabled, so we need\n// to figure it out.\n# if defined(_MSC_VER) || defined(__BORLANDC__)\n// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS\n// macro to enable exceptions, so we'll do the same.\n// Assumes that exceptions are enabled by default.\n#  ifndef _HAS_EXCEPTIONS\n#   define _HAS_EXCEPTIONS 1\n#  endif  // _HAS_EXCEPTIONS\n#  define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS\n# elif defined(__GNUC__) && __EXCEPTIONS\n// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.\n#  define GTEST_HAS_EXCEPTIONS 1\n# elif defined(__SUNPRO_CC)\n// Sun Pro CC supports exceptions.  However, there is no compile-time way of\n// detecting whether they are enabled or not.  Therefore, we assume that\n// they are enabled unless the user tells us otherwise.\n#  define GTEST_HAS_EXCEPTIONS 1\n# elif defined(__IBMCPP__) && __EXCEPTIONS\n// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.\n#  define GTEST_HAS_EXCEPTIONS 1\n# elif defined(__HP_aCC)\n// Exception handling is in effect by default in HP aCC compiler. It has to\n// be turned of by +noeh compiler option if desired.\n#  define GTEST_HAS_EXCEPTIONS 1\n# else\n// For other compilers, we assume exceptions are disabled to be\n// conservative.\n#  define GTEST_HAS_EXCEPTIONS 0\n# endif  // defined(_MSC_VER) || defined(__BORLANDC__)\n#endif  // GTEST_HAS_EXCEPTIONS\n\n#if !defined(GTEST_HAS_STD_STRING)\n// Even though we don't use this macro any longer, we keep it in case\n// some clients still depend on it.\n# define GTEST_HAS_STD_STRING 1\n#elif !GTEST_HAS_STD_STRING\n// The user told us that ::std::string isn't available.\n# error \"Google Test cannot be used where ::std::string isn't available.\"\n#endif  // !defined(GTEST_HAS_STD_STRING)\n\n#ifndef GTEST_HAS_GLOBAL_STRING\n// The user didn't tell us whether ::string is available, so we need\n// to figure it out.\n\n# define GTEST_HAS_GLOBAL_STRING 0\n\n#endif  // GTEST_HAS_GLOBAL_STRING\n\n#ifndef GTEST_HAS_STD_WSTRING\n// The user didn't tell us whether ::std::wstring is available, so we need\n// to figure it out.\n// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring\n//   is available.\n\n// Cygwin 1.7 and below doesn't support ::std::wstring.\n// Solaris' libc++ doesn't support it either.  Android has\n// no support for it at least as recent as Froyo (2.2).\n# define GTEST_HAS_STD_WSTRING \\\n    (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))\n\n#endif  // GTEST_HAS_STD_WSTRING\n\n#ifndef GTEST_HAS_GLOBAL_WSTRING\n// The user didn't tell us whether ::wstring is available, so we need\n// to figure it out.\n# define GTEST_HAS_GLOBAL_WSTRING \\\n    (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)\n#endif  // GTEST_HAS_GLOBAL_WSTRING\n\n// Determines whether RTTI is available.\n#ifndef GTEST_HAS_RTTI\n// The user didn't tell us whether RTTI is enabled, so we need to\n// figure it out.\n\n# ifdef _MSC_VER\n\n#  ifdef _CPPRTTI  // MSVC defines this macro iff RTTI is enabled.\n#   define GTEST_HAS_RTTI 1\n#  else\n#   define GTEST_HAS_RTTI 0\n#  endif\n\n// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.\n# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)\n\n#  ifdef __GXX_RTTI\n#   define GTEST_HAS_RTTI 1\n#  else\n#   define GTEST_HAS_RTTI 0\n#  endif  // __GXX_RTTI\n\n// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if\n// both the typeid and dynamic_cast features are present.\n# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)\n\n#  ifdef __RTTI_ALL__\n#   define GTEST_HAS_RTTI 1\n#  else\n#   define GTEST_HAS_RTTI 0\n#  endif\n\n# else\n\n// For all other compilers, we assume RTTI is enabled.\n#  define GTEST_HAS_RTTI 1\n\n# endif  // _MSC_VER\n\n#endif  // GTEST_HAS_RTTI\n\n// It's this header's responsibility to #include <typeinfo> when RTTI\n// is enabled.\n#if GTEST_HAS_RTTI\n# include <typeinfo>\n#endif\n\n// Determines whether Google Test can use the pthreads library.\n#ifndef GTEST_HAS_PTHREAD\n// The user didn't tell us explicitly, so we assume pthreads support is\n// available on Linux and Mac.\n//\n// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0\n// to your compiler flags.\n# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX)\n#endif  // GTEST_HAS_PTHREAD\n\n#if GTEST_HAS_PTHREAD\n// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is\n// true.\n# include <pthread.h>  // NOLINT\n\n// For timespec and nanosleep, used below.\n# include <time.h>  // NOLINT\n#endif\n\n// Determines whether Google Test can use tr1/tuple.  You can define\n// this macro to 0 to prevent Google Test from using tuple (any\n// feature depending on tuple with be disabled in this mode).\n#ifndef GTEST_HAS_TR1_TUPLE\n// The user didn't tell us not to do it, so we assume it's OK.\n# define GTEST_HAS_TR1_TUPLE 1\n#endif  // GTEST_HAS_TR1_TUPLE\n\n// Determines whether Google Test's own tr1 tuple implementation\n// should be used.\n#ifndef GTEST_USE_OWN_TR1_TUPLE\n// The user didn't tell us, so we need to figure it out.\n\n// We use our own TR1 tuple if we aren't sure the user has an\n// implementation of it already.  At this time, GCC 4.0.0+ and MSVC\n// 2010 are the only mainstream compilers that come with a TR1 tuple\n// implementation.  NVIDIA's CUDA NVCC compiler pretends to be GCC by\n// defining __GNUC__ and friends, but cannot compile GCC's tuple\n// implementation.  MSVC 2008 (9.0) provides TR1 tuple in a 323 MB\n// Feature Pack download, which we cannot assume the user has.\n# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000)) \\\n    || _MSC_VER >= 1600\n#  define GTEST_USE_OWN_TR1_TUPLE 0\n# else\n#  define GTEST_USE_OWN_TR1_TUPLE 1\n# endif\n\n#endif  // GTEST_USE_OWN_TR1_TUPLE\n\n// To avoid conditional compilation everywhere, we make it\n// gtest-port.h's responsibility to #include the header implementing\n// tr1/tuple.\n#if GTEST_HAS_TR1_TUPLE\n\n# if GTEST_USE_OWN_TR1_TUPLE\n// This file was GENERATED by a script.  DO NOT EDIT BY HAND!!!\n\n// Copyright 2009 Google Inc.\n// All Rights Reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n\n// Implements a subset of TR1 tuple needed by Google Test and Google Mock.\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_\n\n#include <utility>  // For ::std::pair.\n\n// The compiler used in Symbian has a bug that prevents us from declaring the\n// tuple template as a friend (it complains that tuple is redefined).  This\n// hack bypasses the bug by declaring the members that should otherwise be\n// private as public.\n// Sun Studio versions < 12 also have the above bug.\n#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)\n# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:\n#else\n# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \\\n    template <GTEST_10_TYPENAMES_(U)> friend class tuple; \\\n   private:\n#endif\n\n// GTEST_n_TUPLE_(T) is the type of an n-tuple.\n#define GTEST_0_TUPLE_(T) tuple<>\n#define GTEST_1_TUPLE_(T) tuple<T##0, void, void, void, void, void, void, \\\n    void, void, void>\n#define GTEST_2_TUPLE_(T) tuple<T##0, T##1, void, void, void, void, void, \\\n    void, void, void>\n#define GTEST_3_TUPLE_(T) tuple<T##0, T##1, T##2, void, void, void, void, \\\n    void, void, void>\n#define GTEST_4_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, void, void, void, \\\n    void, void, void>\n#define GTEST_5_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, void, void, \\\n    void, void, void>\n#define GTEST_6_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, void, \\\n    void, void, void>\n#define GTEST_7_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \\\n    void, void, void>\n#define GTEST_8_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \\\n    T##7, void, void>\n#define GTEST_9_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \\\n    T##7, T##8, void>\n#define GTEST_10_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \\\n    T##7, T##8, T##9>\n\n// GTEST_n_TYPENAMES_(T) declares a list of n typenames.\n#define GTEST_0_TYPENAMES_(T)\n#define GTEST_1_TYPENAMES_(T) typename T##0\n#define GTEST_2_TYPENAMES_(T) typename T##0, typename T##1\n#define GTEST_3_TYPENAMES_(T) typename T##0, typename T##1, typename T##2\n#define GTEST_4_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \\\n    typename T##3\n#define GTEST_5_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \\\n    typename T##3, typename T##4\n#define GTEST_6_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \\\n    typename T##3, typename T##4, typename T##5\n#define GTEST_7_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \\\n    typename T##3, typename T##4, typename T##5, typename T##6\n#define GTEST_8_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \\\n    typename T##3, typename T##4, typename T##5, typename T##6, typename T##7\n#define GTEST_9_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \\\n    typename T##3, typename T##4, typename T##5, typename T##6, \\\n    typename T##7, typename T##8\n#define GTEST_10_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \\\n    typename T##3, typename T##4, typename T##5, typename T##6, \\\n    typename T##7, typename T##8, typename T##9\n\n// In theory, defining stuff in the ::std namespace is undefined\n// behavior.  We can do this as we are playing the role of a standard\n// library vendor.\nnamespace std {\nnamespace tr1 {\n\ntemplate <typename T0 = void, typename T1 = void, typename T2 = void,\n    typename T3 = void, typename T4 = void, typename T5 = void,\n    typename T6 = void, typename T7 = void, typename T8 = void,\n    typename T9 = void>\nclass tuple;\n\n// Anything in namespace gtest_internal is Google Test's INTERNAL\n// IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code.\nnamespace gtest_internal {\n\n// ByRef<T>::type is T if T is a reference; otherwise it's const T&.\ntemplate <typename T>\nstruct ByRef { typedef const T& type; };  // NOLINT\ntemplate <typename T>\nstruct ByRef<T&> { typedef T& type; };  // NOLINT\n\n// A handy wrapper for ByRef.\n#define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef<T>::type\n\n// AddRef<T>::type is T if T is a reference; otherwise it's T&.  This\n// is the same as tr1::add_reference<T>::type.\ntemplate <typename T>\nstruct AddRef { typedef T& type; };  // NOLINT\ntemplate <typename T>\nstruct AddRef<T&> { typedef T& type; };  // NOLINT\n\n// A handy wrapper for AddRef.\n#define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef<T>::type\n\n// A helper for implementing get<k>().\ntemplate <int k> class Get;\n\n// A helper for implementing tuple_element<k, T>.  kIndexValid is true\n// iff k < the number of fields in tuple type T.\ntemplate <bool kIndexValid, int kIndex, class Tuple>\nstruct TupleElement;\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 0, GTEST_10_TUPLE_(T)> { typedef T0 type; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 1, GTEST_10_TUPLE_(T)> { typedef T1 type; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 2, GTEST_10_TUPLE_(T)> { typedef T2 type; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 3, GTEST_10_TUPLE_(T)> { typedef T3 type; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 4, GTEST_10_TUPLE_(T)> { typedef T4 type; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 5, GTEST_10_TUPLE_(T)> { typedef T5 type; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 6, GTEST_10_TUPLE_(T)> { typedef T6 type; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 7, GTEST_10_TUPLE_(T)> { typedef T7 type; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 8, GTEST_10_TUPLE_(T)> { typedef T8 type; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct TupleElement<true, 9, GTEST_10_TUPLE_(T)> { typedef T9 type; };\n\n}  // namespace gtest_internal\n\ntemplate <>\nclass tuple<> {\n public:\n  tuple() {}\n  tuple(const tuple& /* t */)  {}\n  tuple& operator=(const tuple& /* t */) { return *this; }\n};\n\ntemplate <GTEST_1_TYPENAMES_(T)>\nclass GTEST_1_TUPLE_(T) {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0) : f0_(f0) {}\n\n  tuple(const tuple& t) : f0_(t.f0_) {}\n\n  template <GTEST_1_TYPENAMES_(U)>\n  tuple(const GTEST_1_TUPLE_(U)& t) : f0_(t.f0_) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_1_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_1_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_1_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_1_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    return *this;\n  }\n\n  T0 f0_;\n};\n\ntemplate <GTEST_2_TYPENAMES_(T)>\nclass GTEST_2_TUPLE_(T) {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_(), f1_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1) : f0_(f0),\n      f1_(f1) {}\n\n  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_) {}\n\n  template <GTEST_2_TYPENAMES_(U)>\n  tuple(const GTEST_2_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_) {}\n  template <typename U0, typename U1>\n  tuple(const ::std::pair<U0, U1>& p) : f0_(p.first), f1_(p.second) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_2_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_2_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n  template <typename U0, typename U1>\n  tuple& operator=(const ::std::pair<U0, U1>& p) {\n    f0_ = p.first;\n    f1_ = p.second;\n    return *this;\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_2_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_2_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    f1_ = t.f1_;\n    return *this;\n  }\n\n  T0 f0_;\n  T1 f1_;\n};\n\ntemplate <GTEST_3_TYPENAMES_(T)>\nclass GTEST_3_TUPLE_(T) {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_(), f1_(), f2_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,\n      GTEST_BY_REF_(T2) f2) : f0_(f0), f1_(f1), f2_(f2) {}\n\n  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}\n\n  template <GTEST_3_TYPENAMES_(U)>\n  tuple(const GTEST_3_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_3_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_3_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_3_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_3_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    f1_ = t.f1_;\n    f2_ = t.f2_;\n    return *this;\n  }\n\n  T0 f0_;\n  T1 f1_;\n  T2 f2_;\n};\n\ntemplate <GTEST_4_TYPENAMES_(T)>\nclass GTEST_4_TUPLE_(T) {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_(), f1_(), f2_(), f3_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,\n      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3) : f0_(f0), f1_(f1), f2_(f2),\n      f3_(f3) {}\n\n  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_) {}\n\n  template <GTEST_4_TYPENAMES_(U)>\n  tuple(const GTEST_4_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),\n      f3_(t.f3_) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_4_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_4_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_4_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_4_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    f1_ = t.f1_;\n    f2_ = t.f2_;\n    f3_ = t.f3_;\n    return *this;\n  }\n\n  T0 f0_;\n  T1 f1_;\n  T2 f2_;\n  T3 f3_;\n};\n\ntemplate <GTEST_5_TYPENAMES_(T)>\nclass GTEST_5_TUPLE_(T) {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_(), f1_(), f2_(), f3_(), f4_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,\n      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3,\n      GTEST_BY_REF_(T4) f4) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4) {}\n\n  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),\n      f4_(t.f4_) {}\n\n  template <GTEST_5_TYPENAMES_(U)>\n  tuple(const GTEST_5_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),\n      f3_(t.f3_), f4_(t.f4_) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_5_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_5_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_5_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_5_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    f1_ = t.f1_;\n    f2_ = t.f2_;\n    f3_ = t.f3_;\n    f4_ = t.f4_;\n    return *this;\n  }\n\n  T0 f0_;\n  T1 f1_;\n  T2 f2_;\n  T3 f3_;\n  T4 f4_;\n};\n\ntemplate <GTEST_6_TYPENAMES_(T)>\nclass GTEST_6_TUPLE_(T) {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,\n      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,\n      GTEST_BY_REF_(T5) f5) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),\n      f5_(f5) {}\n\n  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),\n      f4_(t.f4_), f5_(t.f5_) {}\n\n  template <GTEST_6_TYPENAMES_(U)>\n  tuple(const GTEST_6_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),\n      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_6_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_6_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_6_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_6_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    f1_ = t.f1_;\n    f2_ = t.f2_;\n    f3_ = t.f3_;\n    f4_ = t.f4_;\n    f5_ = t.f5_;\n    return *this;\n  }\n\n  T0 f0_;\n  T1 f1_;\n  T2 f2_;\n  T3 f3_;\n  T4 f4_;\n  T5 f5_;\n};\n\ntemplate <GTEST_7_TYPENAMES_(T)>\nclass GTEST_7_TUPLE_(T) {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,\n      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,\n      GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6) : f0_(f0), f1_(f1), f2_(f2),\n      f3_(f3), f4_(f4), f5_(f5), f6_(f6) {}\n\n  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),\n      f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {}\n\n  template <GTEST_7_TYPENAMES_(U)>\n  tuple(const GTEST_7_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),\n      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_7_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_7_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_7_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_7_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    f1_ = t.f1_;\n    f2_ = t.f2_;\n    f3_ = t.f3_;\n    f4_ = t.f4_;\n    f5_ = t.f5_;\n    f6_ = t.f6_;\n    return *this;\n  }\n\n  T0 f0_;\n  T1 f1_;\n  T2 f2_;\n  T3 f3_;\n  T4 f4_;\n  T5 f5_;\n  T6 f6_;\n};\n\ntemplate <GTEST_8_TYPENAMES_(T)>\nclass GTEST_8_TUPLE_(T) {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,\n      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,\n      GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6,\n      GTEST_BY_REF_(T7) f7) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),\n      f5_(f5), f6_(f6), f7_(f7) {}\n\n  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),\n      f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {}\n\n  template <GTEST_8_TYPENAMES_(U)>\n  tuple(const GTEST_8_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),\n      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_8_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_8_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_8_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_8_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    f1_ = t.f1_;\n    f2_ = t.f2_;\n    f3_ = t.f3_;\n    f4_ = t.f4_;\n    f5_ = t.f5_;\n    f6_ = t.f6_;\n    f7_ = t.f7_;\n    return *this;\n  }\n\n  T0 f0_;\n  T1 f1_;\n  T2 f2_;\n  T3 f3_;\n  T4 f4_;\n  T5 f5_;\n  T6 f6_;\n  T7 f7_;\n};\n\ntemplate <GTEST_9_TYPENAMES_(T)>\nclass GTEST_9_TUPLE_(T) {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,\n      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,\n      GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,\n      GTEST_BY_REF_(T8) f8) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),\n      f5_(f5), f6_(f6), f7_(f7), f8_(f8) {}\n\n  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),\n      f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {}\n\n  template <GTEST_9_TYPENAMES_(U)>\n  tuple(const GTEST_9_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),\n      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_9_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_9_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_9_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_9_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    f1_ = t.f1_;\n    f2_ = t.f2_;\n    f3_ = t.f3_;\n    f4_ = t.f4_;\n    f5_ = t.f5_;\n    f6_ = t.f6_;\n    f7_ = t.f7_;\n    f8_ = t.f8_;\n    return *this;\n  }\n\n  T0 f0_;\n  T1 f1_;\n  T2 f2_;\n  T3 f3_;\n  T4 f4_;\n  T5 f5_;\n  T6 f6_;\n  T7 f7_;\n  T8 f8_;\n};\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nclass tuple {\n public:\n  template <int k> friend class gtest_internal::Get;\n\n  tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_(),\n      f9_() {}\n\n  explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,\n      GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,\n      GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,\n      GTEST_BY_REF_(T8) f8, GTEST_BY_REF_(T9) f9) : f0_(f0), f1_(f1), f2_(f2),\n      f3_(f3), f4_(f4), f5_(f5), f6_(f6), f7_(f7), f8_(f8), f9_(f9) {}\n\n  tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),\n      f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_), f9_(t.f9_) {}\n\n  template <GTEST_10_TYPENAMES_(U)>\n  tuple(const GTEST_10_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),\n      f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_),\n      f9_(t.f9_) {}\n\n  tuple& operator=(const tuple& t) { return CopyFrom(t); }\n\n  template <GTEST_10_TYPENAMES_(U)>\n  tuple& operator=(const GTEST_10_TUPLE_(U)& t) {\n    return CopyFrom(t);\n  }\n\n  GTEST_DECLARE_TUPLE_AS_FRIEND_\n\n  template <GTEST_10_TYPENAMES_(U)>\n  tuple& CopyFrom(const GTEST_10_TUPLE_(U)& t) {\n    f0_ = t.f0_;\n    f1_ = t.f1_;\n    f2_ = t.f2_;\n    f3_ = t.f3_;\n    f4_ = t.f4_;\n    f5_ = t.f5_;\n    f6_ = t.f6_;\n    f7_ = t.f7_;\n    f8_ = t.f8_;\n    f9_ = t.f9_;\n    return *this;\n  }\n\n  T0 f0_;\n  T1 f1_;\n  T2 f2_;\n  T3 f3_;\n  T4 f4_;\n  T5 f5_;\n  T6 f6_;\n  T7 f7_;\n  T8 f8_;\n  T9 f9_;\n};\n\n// 6.1.3.2 Tuple creation functions.\n\n// Known limitations: we don't support passing an\n// std::tr1::reference_wrapper<T> to make_tuple().  And we don't\n// implement tie().\n\ninline tuple<> make_tuple() { return tuple<>(); }\n\ntemplate <GTEST_1_TYPENAMES_(T)>\ninline GTEST_1_TUPLE_(T) make_tuple(const T0& f0) {\n  return GTEST_1_TUPLE_(T)(f0);\n}\n\ntemplate <GTEST_2_TYPENAMES_(T)>\ninline GTEST_2_TUPLE_(T) make_tuple(const T0& f0, const T1& f1) {\n  return GTEST_2_TUPLE_(T)(f0, f1);\n}\n\ntemplate <GTEST_3_TYPENAMES_(T)>\ninline GTEST_3_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2) {\n  return GTEST_3_TUPLE_(T)(f0, f1, f2);\n}\n\ntemplate <GTEST_4_TYPENAMES_(T)>\ninline GTEST_4_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,\n    const T3& f3) {\n  return GTEST_4_TUPLE_(T)(f0, f1, f2, f3);\n}\n\ntemplate <GTEST_5_TYPENAMES_(T)>\ninline GTEST_5_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,\n    const T3& f3, const T4& f4) {\n  return GTEST_5_TUPLE_(T)(f0, f1, f2, f3, f4);\n}\n\ntemplate <GTEST_6_TYPENAMES_(T)>\ninline GTEST_6_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,\n    const T3& f3, const T4& f4, const T5& f5) {\n  return GTEST_6_TUPLE_(T)(f0, f1, f2, f3, f4, f5);\n}\n\ntemplate <GTEST_7_TYPENAMES_(T)>\ninline GTEST_7_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,\n    const T3& f3, const T4& f4, const T5& f5, const T6& f6) {\n  return GTEST_7_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6);\n}\n\ntemplate <GTEST_8_TYPENAMES_(T)>\ninline GTEST_8_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,\n    const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7) {\n  return GTEST_8_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7);\n}\n\ntemplate <GTEST_9_TYPENAMES_(T)>\ninline GTEST_9_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,\n    const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7,\n    const T8& f8) {\n  return GTEST_9_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8);\n}\n\ntemplate <GTEST_10_TYPENAMES_(T)>\ninline GTEST_10_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,\n    const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7,\n    const T8& f8, const T9& f9) {\n  return GTEST_10_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9);\n}\n\n// 6.1.3.3 Tuple helper classes.\n\ntemplate <typename Tuple> struct tuple_size;\n\ntemplate <GTEST_0_TYPENAMES_(T)>\nstruct tuple_size<GTEST_0_TUPLE_(T)> { static const int value = 0; };\n\ntemplate <GTEST_1_TYPENAMES_(T)>\nstruct tuple_size<GTEST_1_TUPLE_(T)> { static const int value = 1; };\n\ntemplate <GTEST_2_TYPENAMES_(T)>\nstruct tuple_size<GTEST_2_TUPLE_(T)> { static const int value = 2; };\n\ntemplate <GTEST_3_TYPENAMES_(T)>\nstruct tuple_size<GTEST_3_TUPLE_(T)> { static const int value = 3; };\n\ntemplate <GTEST_4_TYPENAMES_(T)>\nstruct tuple_size<GTEST_4_TUPLE_(T)> { static const int value = 4; };\n\ntemplate <GTEST_5_TYPENAMES_(T)>\nstruct tuple_size<GTEST_5_TUPLE_(T)> { static const int value = 5; };\n\ntemplate <GTEST_6_TYPENAMES_(T)>\nstruct tuple_size<GTEST_6_TUPLE_(T)> { static const int value = 6; };\n\ntemplate <GTEST_7_TYPENAMES_(T)>\nstruct tuple_size<GTEST_7_TUPLE_(T)> { static const int value = 7; };\n\ntemplate <GTEST_8_TYPENAMES_(T)>\nstruct tuple_size<GTEST_8_TUPLE_(T)> { static const int value = 8; };\n\ntemplate <GTEST_9_TYPENAMES_(T)>\nstruct tuple_size<GTEST_9_TUPLE_(T)> { static const int value = 9; };\n\ntemplate <GTEST_10_TYPENAMES_(T)>\nstruct tuple_size<GTEST_10_TUPLE_(T)> { static const int value = 10; };\n\ntemplate <int k, class Tuple>\nstruct tuple_element {\n  typedef typename gtest_internal::TupleElement<\n      k < (tuple_size<Tuple>::value), k, Tuple>::type type;\n};\n\n#define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element<k, Tuple >::type\n\n// 6.1.3.4 Element access.\n\nnamespace gtest_internal {\n\ntemplate <>\nclass Get<0> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple))\n  Field(Tuple& t) { return t.f0_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple))\n  ConstField(const Tuple& t) { return t.f0_; }\n};\n\ntemplate <>\nclass Get<1> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple))\n  Field(Tuple& t) { return t.f1_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple))\n  ConstField(const Tuple& t) { return t.f1_; }\n};\n\ntemplate <>\nclass Get<2> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple))\n  Field(Tuple& t) { return t.f2_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple))\n  ConstField(const Tuple& t) { return t.f2_; }\n};\n\ntemplate <>\nclass Get<3> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple))\n  Field(Tuple& t) { return t.f3_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple))\n  ConstField(const Tuple& t) { return t.f3_; }\n};\n\ntemplate <>\nclass Get<4> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple))\n  Field(Tuple& t) { return t.f4_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple))\n  ConstField(const Tuple& t) { return t.f4_; }\n};\n\ntemplate <>\nclass Get<5> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple))\n  Field(Tuple& t) { return t.f5_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple))\n  ConstField(const Tuple& t) { return t.f5_; }\n};\n\ntemplate <>\nclass Get<6> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple))\n  Field(Tuple& t) { return t.f6_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple))\n  ConstField(const Tuple& t) { return t.f6_; }\n};\n\ntemplate <>\nclass Get<7> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple))\n  Field(Tuple& t) { return t.f7_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple))\n  ConstField(const Tuple& t) { return t.f7_; }\n};\n\ntemplate <>\nclass Get<8> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple))\n  Field(Tuple& t) { return t.f8_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple))\n  ConstField(const Tuple& t) { return t.f8_; }\n};\n\ntemplate <>\nclass Get<9> {\n public:\n  template <class Tuple>\n  static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple))\n  Field(Tuple& t) { return t.f9_; }  // NOLINT\n\n  template <class Tuple>\n  static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple))\n  ConstField(const Tuple& t) { return t.f9_; }\n};\n\n}  // namespace gtest_internal\n\ntemplate <int k, GTEST_10_TYPENAMES_(T)>\nGTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_10_TUPLE_(T)))\nget(GTEST_10_TUPLE_(T)& t) {\n  return gtest_internal::Get<k>::Field(t);\n}\n\ntemplate <int k, GTEST_10_TYPENAMES_(T)>\nGTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k,  GTEST_10_TUPLE_(T)))\nget(const GTEST_10_TUPLE_(T)& t) {\n  return gtest_internal::Get<k>::ConstField(t);\n}\n\n// 6.1.3.5 Relational operators\n\n// We only implement == and !=, as we don't have a need for the rest yet.\n\nnamespace gtest_internal {\n\n// SameSizeTuplePrefixComparator<k, k>::Eq(t1, t2) returns true if the\n// first k fields of t1 equals the first k fields of t2.\n// SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if\n// k1 != k2.\ntemplate <int kSize1, int kSize2>\nstruct SameSizeTuplePrefixComparator;\n\ntemplate <>\nstruct SameSizeTuplePrefixComparator<0, 0> {\n  template <class Tuple1, class Tuple2>\n  static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) {\n    return true;\n  }\n};\n\ntemplate <int k>\nstruct SameSizeTuplePrefixComparator<k, k> {\n  template <class Tuple1, class Tuple2>\n  static bool Eq(const Tuple1& t1, const Tuple2& t2) {\n    return SameSizeTuplePrefixComparator<k - 1, k - 1>::Eq(t1, t2) &&\n        ::std::tr1::get<k - 1>(t1) == ::std::tr1::get<k - 1>(t2);\n  }\n};\n\n}  // namespace gtest_internal\n\ntemplate <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>\ninline bool operator==(const GTEST_10_TUPLE_(T)& t,\n                       const GTEST_10_TUPLE_(U)& u) {\n  return gtest_internal::SameSizeTuplePrefixComparator<\n      tuple_size<GTEST_10_TUPLE_(T)>::value,\n      tuple_size<GTEST_10_TUPLE_(U)>::value>::Eq(t, u);\n}\n\ntemplate <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>\ninline bool operator!=(const GTEST_10_TUPLE_(T)& t,\n                       const GTEST_10_TUPLE_(U)& u) { return !(t == u); }\n\n// 6.1.4 Pairs.\n// Unimplemented.\n\n}  // namespace tr1\n}  // namespace std\n\n#undef GTEST_0_TUPLE_\n#undef GTEST_1_TUPLE_\n#undef GTEST_2_TUPLE_\n#undef GTEST_3_TUPLE_\n#undef GTEST_4_TUPLE_\n#undef GTEST_5_TUPLE_\n#undef GTEST_6_TUPLE_\n#undef GTEST_7_TUPLE_\n#undef GTEST_8_TUPLE_\n#undef GTEST_9_TUPLE_\n#undef GTEST_10_TUPLE_\n\n#undef GTEST_0_TYPENAMES_\n#undef GTEST_1_TYPENAMES_\n#undef GTEST_2_TYPENAMES_\n#undef GTEST_3_TYPENAMES_\n#undef GTEST_4_TYPENAMES_\n#undef GTEST_5_TYPENAMES_\n#undef GTEST_6_TYPENAMES_\n#undef GTEST_7_TYPENAMES_\n#undef GTEST_8_TYPENAMES_\n#undef GTEST_9_TYPENAMES_\n#undef GTEST_10_TYPENAMES_\n\n#undef GTEST_DECLARE_TUPLE_AS_FRIEND_\n#undef GTEST_BY_REF_\n#undef GTEST_ADD_REF_\n#undef GTEST_TUPLE_ELEMENT_\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_\n# elif GTEST_OS_SYMBIAN\n\n// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to\n// use STLport's tuple implementation, which unfortunately doesn't\n// work as the copy of STLport distributed with Symbian is incomplete.\n// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to\n// use its own tuple implementation.\n#  ifdef BOOST_HAS_TR1_TUPLE\n#   undef BOOST_HAS_TR1_TUPLE\n#  endif  // BOOST_HAS_TR1_TUPLE\n\n// This prevents <boost/tr1/detail/config.hpp>, which defines\n// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.\n#  define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED\n#  include <tuple>\n\n# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)\n// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header.  This does\n// not conform to the TR1 spec, which requires the header to be <tuple>.\n\n#  if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302\n// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,\n// which is #included by <tr1/tuple>, to not compile when RTTI is\n// disabled.  _TR1_FUNCTIONAL is the header guard for\n// <tr1/functional>.  Hence the following #define is a hack to prevent\n// <tr1/functional> from being included.\n#   define _TR1_FUNCTIONAL 1\n#   include <tr1/tuple>\n#   undef _TR1_FUNCTIONAL  // Allows the user to #include\n                        // <tr1/functional> if he chooses to.\n#  else\n#   include <tr1/tuple>  // NOLINT\n#  endif  // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302\n\n# else\n// If the compiler is not GCC 4.0+, we assume the user is using a\n// spec-conforming TR1 implementation.\n#  include <tuple>  // NOLINT\n# endif  // GTEST_USE_OWN_TR1_TUPLE\n\n#endif  // GTEST_HAS_TR1_TUPLE\n\n// Determines whether clone(2) is supported.\n// Usually it will only be available on Linux, excluding\n// Linux on the Itanium architecture.\n// Also see http://linux.die.net/man/2/clone.\n#ifndef GTEST_HAS_CLONE\n// The user didn't tell us, so we need to figure it out.\n\n# if GTEST_OS_LINUX && !defined(__ia64__)\n#  define GTEST_HAS_CLONE 1\n# else\n#  define GTEST_HAS_CLONE 0\n# endif  // GTEST_OS_LINUX && !defined(__ia64__)\n\n#endif  // GTEST_HAS_CLONE\n\n// Determines whether to support stream redirection. This is used to test\n// output correctness and to implement death tests.\n#ifndef GTEST_HAS_STREAM_REDIRECTION\n// By default, we assume that stream redirection is supported on all\n// platforms except known mobile ones.\n# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN\n#  define GTEST_HAS_STREAM_REDIRECTION 0\n# else\n#  define GTEST_HAS_STREAM_REDIRECTION 1\n# endif  // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN\n#endif  // GTEST_HAS_STREAM_REDIRECTION\n\n// Determines whether to support death tests.\n// Google Test does not support death tests for VC 7.1 and earlier as\n// abort() in a VC 7.1 application compiled as GUI in debug config\n// pops up a dialog window that cannot be suppressed programmatically.\n#if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \\\n     (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \\\n     GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX)\n# define GTEST_HAS_DEATH_TEST 1\n# include <vector>  // NOLINT\n#endif\n\n// We don't support MSVC 7.1 with exceptions disabled now.  Therefore\n// all the compilers we care about are adequate for supporting\n// value-parameterized tests.\n#define GTEST_HAS_PARAM_TEST 1\n\n// Determines whether to support type-driven tests.\n\n// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,\n// Sun Pro CC, IBM Visual Age, and HP aCC support.\n#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \\\n    defined(__IBMCPP__) || defined(__HP_aCC)\n# define GTEST_HAS_TYPED_TEST 1\n# define GTEST_HAS_TYPED_TEST_P 1\n#endif\n\n// Determines whether to support Combine(). This only makes sense when\n// value-parameterized tests are enabled.  The implementation doesn't\n// work on Sun Studio since it doesn't understand templated conversion\n// operators.\n#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)\n# define GTEST_HAS_COMBINE 1\n#endif\n\n// Determines whether the system compiler uses UTF-16 for encoding wide strings.\n#define GTEST_WIDE_STRING_USES_UTF16_ \\\n    (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)\n\n// Determines whether test results can be streamed to a socket.\n#if GTEST_OS_LINUX\n# define GTEST_CAN_STREAM_RESULTS_ 1\n#endif\n\n// Defines some utility macros.\n\n// The GNU compiler emits a warning if nested \"if\" statements are followed by\n// an \"else\" statement and braces are not used to explicitly disambiguate the\n// \"else\" binding.  This leads to problems with code like:\n//\n//   if (gate)\n//     ASSERT_*(condition) << \"Some message\";\n//\n// The \"switch (0) case 0:\" idiom is used to suppress this.\n#ifdef __INTEL_COMPILER\n# define GTEST_AMBIGUOUS_ELSE_BLOCKER_\n#else\n# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default:  // NOLINT\n#endif\n\n// Use this annotation at the end of a struct/class definition to\n// prevent the compiler from optimizing away instances that are never\n// used.  This is useful when all interesting logic happens inside the\n// c'tor and / or d'tor.  Example:\n//\n//   struct Foo {\n//     Foo() { ... }\n//   } GTEST_ATTRIBUTE_UNUSED_;\n//\n// Also use it after a variable or parameter declaration to tell the\n// compiler the variable/parameter does not have to be used.\n#if defined(__GNUC__) && !defined(COMPILER_ICC)\n# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))\n#else\n# define GTEST_ATTRIBUTE_UNUSED_\n#endif\n\n// A macro to disallow operator=\n// This should be used in the private: declarations for a class.\n#define GTEST_DISALLOW_ASSIGN_(type)\\\n  void operator=(type const &)\n\n// A macro to disallow copy constructor and operator=\n// This should be used in the private: declarations for a class.\n#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\\\n  type(type const &);\\\n  GTEST_DISALLOW_ASSIGN_(type)\n\n// Tell the compiler to warn about unused return values for functions declared\n// with this macro.  The macro should be used on function declarations\n// following the argument list:\n//\n//   Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;\n#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)\n# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))\n#else\n# define GTEST_MUST_USE_RESULT_\n#endif  // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC\n\n// Determine whether the compiler supports Microsoft's Structured Exception\n// Handling.  This is supported by several Windows compilers but generally\n// does not exist on any other system.\n#ifndef GTEST_HAS_SEH\n// The user didn't tell us, so we need to figure it out.\n\n# if defined(_MSC_VER) || defined(__BORLANDC__)\n// These two compilers are known to support SEH.\n#  define GTEST_HAS_SEH 1\n# else\n// Assume no SEH.\n#  define GTEST_HAS_SEH 0\n# endif\n\n#endif  // GTEST_HAS_SEH\n\n#ifdef _MSC_VER\n\n# if GTEST_LINKED_AS_SHARED_LIBRARY\n#  define GTEST_API_ __declspec(dllimport)\n# elif GTEST_CREATE_SHARED_LIBRARY\n#  define GTEST_API_ __declspec(dllexport)\n# endif\n\n#endif  // _MSC_VER\n\n#ifndef GTEST_API_\n# define GTEST_API_\n#endif\n\n#ifdef __GNUC__\n// Ask the compiler to never inline a given function.\n# define GTEST_NO_INLINE_ __attribute__((noinline))\n#else\n# define GTEST_NO_INLINE_\n#endif\n\nnamespace testing {\n\nclass Message;\n\nnamespace internal {\n\nclass String;\n\n// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time\n// expression is true. For example, you could use it to verify the\n// size of a static array:\n//\n//   GTEST_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,\n//                         content_type_names_incorrect_size);\n//\n// or to make sure a struct is smaller than a certain size:\n//\n//   GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);\n//\n// The second argument to the macro is the name of the variable. If\n// the expression is false, most compilers will issue a warning/error\n// containing the name of the variable.\n\ntemplate <bool>\nstruct CompileAssert {\n};\n\n#define GTEST_COMPILE_ASSERT_(expr, msg) \\\n  typedef ::testing::internal::CompileAssert<(bool(expr))> \\\n      msg[bool(expr) ? 1 : -1]\n\n// Implementation details of GTEST_COMPILE_ASSERT_:\n//\n// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1\n//   elements (and thus is invalid) when the expression is false.\n//\n// - The simpler definition\n//\n//    #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]\n//\n//   does not work, as gcc supports variable-length arrays whose sizes\n//   are determined at run-time (this is gcc's extension and not part\n//   of the C++ standard).  As a result, gcc fails to reject the\n//   following code with the simple definition:\n//\n//     int foo;\n//     GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is\n//                                      // not a compile-time constant.\n//\n// - By using the type CompileAssert<(bool(expr))>, we ensures that\n//   expr is a compile-time constant.  (Template arguments must be\n//   determined at compile-time.)\n//\n// - The outter parentheses in CompileAssert<(bool(expr))> are necessary\n//   to work around a bug in gcc 3.4.4 and 4.0.1.  If we had written\n//\n//     CompileAssert<bool(expr)>\n//\n//   instead, these compilers will refuse to compile\n//\n//     GTEST_COMPILE_ASSERT_(5 > 0, some_message);\n//\n//   (They seem to think the \">\" in \"5 > 0\" marks the end of the\n//   template argument list.)\n//\n// - The array size is (bool(expr) ? 1 : -1), instead of simply\n//\n//     ((expr) ? 1 : -1).\n//\n//   This is to avoid running into a bug in MS VC 7.1, which\n//   causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.\n\n// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.\n//\n// This template is declared, but intentionally undefined.\ntemplate <typename T1, typename T2>\nstruct StaticAssertTypeEqHelper;\n\ntemplate <typename T>\nstruct StaticAssertTypeEqHelper<T, T> {};\n\n#if GTEST_HAS_GLOBAL_STRING\ntypedef ::string string;\n#else\ntypedef ::std::string string;\n#endif  // GTEST_HAS_GLOBAL_STRING\n\n#if GTEST_HAS_GLOBAL_WSTRING\ntypedef ::wstring wstring;\n#elif GTEST_HAS_STD_WSTRING\ntypedef ::std::wstring wstring;\n#endif  // GTEST_HAS_GLOBAL_WSTRING\n\n// A helper for suppressing warnings on constant condition.  It just\n// returns 'condition'.\nGTEST_API_ bool IsTrue(bool condition);\n\n// Defines scoped_ptr.\n\n// This implementation of scoped_ptr is PARTIAL - it only contains\n// enough stuff to satisfy Google Test's need.\ntemplate <typename T>\nclass scoped_ptr {\n public:\n  typedef T element_type;\n\n  explicit scoped_ptr(T* p = NULL) : ptr_(p) {}\n  ~scoped_ptr() { reset(); }\n\n  T& operator*() const { return *ptr_; }\n  T* operator->() const { return ptr_; }\n  T* get() const { return ptr_; }\n\n  T* release() {\n    T* const ptr = ptr_;\n    ptr_ = NULL;\n    return ptr;\n  }\n\n  void reset(T* p = NULL) {\n    if (p != ptr_) {\n      if (IsTrue(sizeof(T) > 0)) {  // Makes sure T is a complete type.\n        delete ptr_;\n      }\n      ptr_ = p;\n    }\n  }\n private:\n  T* ptr_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);\n};\n\n// Defines RE.\n\n// A simple C++ wrapper for <regex.h>.  It uses the POSIX Extended\n// Regular Expression syntax.\nclass GTEST_API_ RE {\n public:\n  // A copy constructor is required by the Standard to initialize object\n  // references from r-values.\n  RE(const RE& other) { Init(other.pattern()); }\n\n  // Constructs an RE from a string.\n  RE(const ::std::string& regex) { Init(regex.c_str()); }  // NOLINT\n\n#if GTEST_HAS_GLOBAL_STRING\n\n  RE(const ::string& regex) { Init(regex.c_str()); }  // NOLINT\n\n#endif  // GTEST_HAS_GLOBAL_STRING\n\n  RE(const char* regex) { Init(regex); }  // NOLINT\n  ~RE();\n\n  // Returns the string representation of the regex.\n  const char* pattern() const { return pattern_; }\n\n  // FullMatch(str, re) returns true iff regular expression re matches\n  // the entire str.\n  // PartialMatch(str, re) returns true iff regular expression re\n  // matches a substring of str (including str itself).\n  //\n  // TODO(wan@google.com): make FullMatch() and PartialMatch() work\n  // when str contains NUL characters.\n  static bool FullMatch(const ::std::string& str, const RE& re) {\n    return FullMatch(str.c_str(), re);\n  }\n  static bool PartialMatch(const ::std::string& str, const RE& re) {\n    return PartialMatch(str.c_str(), re);\n  }\n\n#if GTEST_HAS_GLOBAL_STRING\n\n  static bool FullMatch(const ::string& str, const RE& re) {\n    return FullMatch(str.c_str(), re);\n  }\n  static bool PartialMatch(const ::string& str, const RE& re) {\n    return PartialMatch(str.c_str(), re);\n  }\n\n#endif  // GTEST_HAS_GLOBAL_STRING\n\n  static bool FullMatch(const char* str, const RE& re);\n  static bool PartialMatch(const char* str, const RE& re);\n\n private:\n  void Init(const char* regex);\n\n  // We use a const char* instead of a string, as Google Test may be used\n  // where string is not available.  We also do not use Google Test's own\n  // String type here, in order to simplify dependencies between the\n  // files.\n  const char* pattern_;\n  bool is_valid_;\n\n#if GTEST_USES_POSIX_RE\n\n  regex_t full_regex_;     // For FullMatch().\n  regex_t partial_regex_;  // For PartialMatch().\n\n#else  // GTEST_USES_SIMPLE_RE\n\n  const char* full_pattern_;  // For FullMatch();\n\n#endif\n\n  GTEST_DISALLOW_ASSIGN_(RE);\n};\n\n// Formats a source file path and a line number as they would appear\n// in an error message from the compiler used to compile this code.\nGTEST_API_ ::std::string FormatFileLocation(const char* file, int line);\n\n// Formats a file location for compiler-independent XML output.\n// Although this function is not platform dependent, we put it next to\n// FormatFileLocation in order to contrast the two functions.\nGTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,\n                                                               int line);\n\n// Defines logging utilities:\n//   GTEST_LOG_(severity) - logs messages at the specified severity level. The\n//                          message itself is streamed into the macro.\n//   LogToStderr()  - directs all log messages to stderr.\n//   FlushInfoLog() - flushes informational log messages.\n\nenum GTestLogSeverity {\n  GTEST_INFO,\n  GTEST_WARNING,\n  GTEST_ERROR,\n  GTEST_FATAL\n};\n\n// Formats log entry severity, provides a stream object for streaming the\n// log message, and terminates the message with a newline when going out of\n// scope.\nclass GTEST_API_ GTestLog {\n public:\n  GTestLog(GTestLogSeverity severity, const char* file, int line);\n\n  // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.\n  ~GTestLog();\n\n  ::std::ostream& GetStream() { return ::std::cerr; }\n\n private:\n  const GTestLogSeverity severity_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);\n};\n\n#define GTEST_LOG_(severity) \\\n    ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \\\n                                  __FILE__, __LINE__).GetStream()\n\ninline void LogToStderr() {}\ninline void FlushInfoLog() { fflush(NULL); }\n\n// INTERNAL IMPLEMENTATION - DO NOT USE.\n//\n// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition\n// is not satisfied.\n//  Synopsys:\n//    GTEST_CHECK_(boolean_condition);\n//     or\n//    GTEST_CHECK_(boolean_condition) << \"Additional message\";\n//\n//    This checks the condition and if the condition is not satisfied\n//    it prints message about the condition violation, including the\n//    condition itself, plus additional message streamed into it, if any,\n//    and then it aborts the program. It aborts the program irrespective of\n//    whether it is built in the debug mode or not.\n#define GTEST_CHECK_(condition) \\\n    GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\\n    if (::testing::internal::IsTrue(condition)) \\\n      ; \\\n    else \\\n      GTEST_LOG_(FATAL) << \"Condition \" #condition \" failed. \"\n\n// An all-mode assert to verify that the given POSIX-style function\n// call returns 0 (indicating success).  Known limitation: this\n// doesn't expand to a balanced 'if' statement, so enclose the macro\n// in {} if you need to use it as the only statement in an 'if'\n// branch.\n#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \\\n  if (const int gtest_error = (posix_call)) \\\n    GTEST_LOG_(FATAL) << #posix_call << \"failed with error \" \\\n                      << gtest_error\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// Use ImplicitCast_ as a safe version of static_cast for upcasting in\n// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a\n// const Foo*).  When you use ImplicitCast_, the compiler checks that\n// the cast is safe.  Such explicit ImplicitCast_s are necessary in\n// surprisingly many situations where C++ demands an exact type match\n// instead of an argument type convertable to a target type.\n//\n// The syntax for using ImplicitCast_ is the same as for static_cast:\n//\n//   ImplicitCast_<ToType>(expr)\n//\n// ImplicitCast_ would have been part of the C++ standard library,\n// but the proposal was submitted too late.  It will probably make\n// its way into the language in the future.\n//\n// This relatively ugly name is intentional. It prevents clashes with\n// similar functions users may have (e.g., implicit_cast). The internal\n// namespace alone is not enough because the function can be found by ADL.\ntemplate<typename To>\ninline To ImplicitCast_(To x) { return x; }\n\n// When you upcast (that is, cast a pointer from type Foo to type\n// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts\n// always succeed.  When you downcast (that is, cast a pointer from\n// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because\n// how do you know the pointer is really of type SubclassOfFoo?  It\n// could be a bare Foo, or of type DifferentSubclassOfFoo.  Thus,\n// when you downcast, you should use this macro.  In debug mode, we\n// use dynamic_cast<> to double-check the downcast is legal (we die\n// if it's not).  In normal mode, we do the efficient static_cast<>\n// instead.  Thus, it's important to test in debug mode to make sure\n// the cast is legal!\n//    This is the only place in the code we should use dynamic_cast<>.\n// In particular, you SHOULDN'T be using dynamic_cast<> in order to\n// do RTTI (eg code like this:\n//    if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);\n//    if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);\n// You should design the code some other way not to need this.\n//\n// This relatively ugly name is intentional. It prevents clashes with\n// similar functions users may have (e.g., down_cast). The internal\n// namespace alone is not enough because the function can be found by ADL.\ntemplate<typename To, typename From>  // use like this: DownCast_<T*>(foo);\ninline To DownCast_(From* f) {  // so we only accept pointers\n  // Ensures that To is a sub-type of From *.  This test is here only\n  // for compile-time type checking, and has no overhead in an\n  // optimized build at run-time, as it will be optimized away\n  // completely.\n  if (false) {\n    const To to = NULL;\n    ::testing::internal::ImplicitCast_<From*>(to);\n  }\n\n#if GTEST_HAS_RTTI\n  // RTTI: debug mode only!\n  GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);\n#endif\n  return static_cast<To>(f);\n}\n\n// Downcasts the pointer of type Base to Derived.\n// Derived must be a subclass of Base. The parameter MUST\n// point to a class of type Derived, not any subclass of it.\n// When RTTI is available, the function performs a runtime\n// check to enforce this.\ntemplate <class Derived, class Base>\nDerived* CheckedDowncastToActualType(Base* base) {\n#if GTEST_HAS_RTTI\n  GTEST_CHECK_(typeid(*base) == typeid(Derived));\n  return dynamic_cast<Derived*>(base);  // NOLINT\n#else\n  return static_cast<Derived*>(base);  // Poor man's downcast.\n#endif\n}\n\n#if GTEST_HAS_STREAM_REDIRECTION\n\n// Defines the stderr capturer:\n//   CaptureStdout     - starts capturing stdout.\n//   GetCapturedStdout - stops capturing stdout and returns the captured string.\n//   CaptureStderr     - starts capturing stderr.\n//   GetCapturedStderr - stops capturing stderr and returns the captured string.\n//\nGTEST_API_ void CaptureStdout();\nGTEST_API_ String GetCapturedStdout();\nGTEST_API_ void CaptureStderr();\nGTEST_API_ String GetCapturedStderr();\n\n#endif  // GTEST_HAS_STREAM_REDIRECTION\n\n\n#if GTEST_HAS_DEATH_TEST\n\n// A copy of all command line arguments.  Set by InitGoogleTest().\nextern ::std::vector<String> g_argvs;\n\n// GTEST_HAS_DEATH_TEST implies we have ::std::string.\nconst ::std::vector<String>& GetArgvs();\n\n#endif  // GTEST_HAS_DEATH_TEST\n\n// Defines synchronization primitives.\n\n#if GTEST_HAS_PTHREAD\n\n// Sleeps for (roughly) n milli-seconds.  This function is only for\n// testing Google Test's own constructs.  Don't use it in user tests,\n// either directly or indirectly.\ninline void SleepMilliseconds(int n) {\n  const timespec time = {\n    0,                  // 0 seconds.\n    n * 1000L * 1000L,  // And n ms.\n  };\n  nanosleep(&time, NULL);\n}\n\n// Allows a controller thread to pause execution of newly created\n// threads until notified.  Instances of this class must be created\n// and destroyed in the controller thread.\n//\n// This class is only for testing Google Test's own constructs. Do not\n// use it in user tests, either directly or indirectly.\nclass Notification {\n public:\n  Notification() : notified_(false) {}\n\n  // Notifies all threads created with this notification to start. Must\n  // be called from the controller thread.\n  void Notify() { notified_ = true; }\n\n  // Blocks until the controller thread notifies. Must be called from a test\n  // thread.\n  void WaitForNotification() {\n    while(!notified_) {\n      SleepMilliseconds(10);\n    }\n  }\n\n private:\n  volatile bool notified_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);\n};\n\n// As a C-function, ThreadFuncWithCLinkage cannot be templated itself.\n// Consequently, it cannot select a correct instantiation of ThreadWithParam\n// in order to call its Run(). Introducing ThreadWithParamBase as a\n// non-templated base class for ThreadWithParam allows us to bypass this\n// problem.\nclass ThreadWithParamBase {\n public:\n  virtual ~ThreadWithParamBase() {}\n  virtual void Run() = 0;\n};\n\n// pthread_create() accepts a pointer to a function type with the C linkage.\n// According to the Standard (7.5/1), function types with different linkages\n// are different even if they are otherwise identical.  Some compilers (for\n// example, SunStudio) treat them as different types.  Since class methods\n// cannot be defined with C-linkage we need to define a free C-function to\n// pass into pthread_create().\nextern \"C\" inline void* ThreadFuncWithCLinkage(void* thread) {\n  static_cast<ThreadWithParamBase*>(thread)->Run();\n  return NULL;\n}\n\n// Helper class for testing Google Test's multi-threading constructs.\n// To use it, write:\n//\n//   void ThreadFunc(int param) { /* Do things with param */ }\n//   Notification thread_can_start;\n//   ...\n//   // The thread_can_start parameter is optional; you can supply NULL.\n//   ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);\n//   thread_can_start.Notify();\n//\n// These classes are only for testing Google Test's own constructs. Do\n// not use them in user tests, either directly or indirectly.\ntemplate <typename T>\nclass ThreadWithParam : public ThreadWithParamBase {\n public:\n  typedef void (*UserThreadFunc)(T);\n\n  ThreadWithParam(\n      UserThreadFunc func, T param, Notification* thread_can_start)\n      : func_(func),\n        param_(param),\n        thread_can_start_(thread_can_start),\n        finished_(false) {\n    ThreadWithParamBase* const base = this;\n    // The thread can be created only after all fields except thread_\n    // have been initialized.\n    GTEST_CHECK_POSIX_SUCCESS_(\n        pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));\n  }\n  ~ThreadWithParam() { Join(); }\n\n  void Join() {\n    if (!finished_) {\n      GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));\n      finished_ = true;\n    }\n  }\n\n  virtual void Run() {\n    if (thread_can_start_ != NULL)\n      thread_can_start_->WaitForNotification();\n    func_(param_);\n  }\n\n private:\n  const UserThreadFunc func_;  // User-supplied thread function.\n  const T param_;  // User-supplied parameter to the thread function.\n  // When non-NULL, used to block execution until the controller thread\n  // notifies.\n  Notification* const thread_can_start_;\n  bool finished_;  // true iff we know that the thread function has finished.\n  pthread_t thread_;  // The native thread object.\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);\n};\n\n// MutexBase and Mutex implement mutex on pthreads-based platforms. They\n// are used in conjunction with class MutexLock:\n//\n//   Mutex mutex;\n//   ...\n//   MutexLock lock(&mutex);  // Acquires the mutex and releases it at the end\n//                            // of the current scope.\n//\n// MutexBase implements behavior for both statically and dynamically\n// allocated mutexes.  Do not use MutexBase directly.  Instead, write\n// the following to define a static mutex:\n//\n//   GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);\n//\n// You can forward declare a static mutex like this:\n//\n//   GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);\n//\n// To create a dynamic mutex, just define an object of type Mutex.\nclass MutexBase {\n public:\n  // Acquires this mutex.\n  void Lock() {\n    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));\n    owner_ = pthread_self();\n  }\n\n  // Releases this mutex.\n  void Unlock() {\n    // We don't protect writing to owner_ here, as it's the caller's\n    // responsibility to ensure that the current thread holds the\n    // mutex when this is called.\n    owner_ = 0;\n    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));\n  }\n\n  // Does nothing if the current thread holds the mutex. Otherwise, crashes\n  // with high probability.\n  void AssertHeld() const {\n    GTEST_CHECK_(owner_ == pthread_self())\n        << \"The current thread is not holding the mutex @\" << this;\n  }\n\n  // A static mutex may be used before main() is entered.  It may even\n  // be used before the dynamic initialization stage.  Therefore we\n  // must be able to initialize a static mutex object at link time.\n  // This means MutexBase has to be a POD and its member variables\n  // have to be public.\n public:\n  pthread_mutex_t mutex_;  // The underlying pthread mutex.\n  pthread_t owner_;  // The thread holding the mutex; 0 means no one holds it.\n};\n\n// Forward-declares a static mutex.\n# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \\\n    extern ::testing::internal::MutexBase mutex\n\n// Defines and statically (i.e. at link time) initializes a static mutex.\n# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \\\n    ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, 0 }\n\n// The Mutex class can only be used for mutexes created at runtime. It\n// shares its API with MutexBase otherwise.\nclass Mutex : public MutexBase {\n public:\n  Mutex() {\n    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));\n    owner_ = 0;\n  }\n  ~Mutex() {\n    GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));\n  }\n\n private:\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);\n};\n\n// We cannot name this class MutexLock as the ctor declaration would\n// conflict with a macro named MutexLock, which is defined on some\n// platforms.  Hence the typedef trick below.\nclass GTestMutexLock {\n public:\n  explicit GTestMutexLock(MutexBase* mutex)\n      : mutex_(mutex) { mutex_->Lock(); }\n\n  ~GTestMutexLock() { mutex_->Unlock(); }\n\n private:\n  MutexBase* const mutex_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);\n};\n\ntypedef GTestMutexLock MutexLock;\n\n// Helpers for ThreadLocal.\n\n// pthread_key_create() requires DeleteThreadLocalValue() to have\n// C-linkage.  Therefore it cannot be templatized to access\n// ThreadLocal<T>.  Hence the need for class\n// ThreadLocalValueHolderBase.\nclass ThreadLocalValueHolderBase {\n public:\n  virtual ~ThreadLocalValueHolderBase() {}\n};\n\n// Called by pthread to delete thread-local data stored by\n// pthread_setspecific().\nextern \"C\" inline void DeleteThreadLocalValue(void* value_holder) {\n  delete static_cast<ThreadLocalValueHolderBase*>(value_holder);\n}\n\n// Implements thread-local storage on pthreads-based systems.\n//\n//   // Thread 1\n//   ThreadLocal<int> tl(100);  // 100 is the default value for each thread.\n//\n//   // Thread 2\n//   tl.set(150);  // Changes the value for thread 2 only.\n//   EXPECT_EQ(150, tl.get());\n//\n//   // Thread 1\n//   EXPECT_EQ(100, tl.get());  // In thread 1, tl has the original value.\n//   tl.set(200);\n//   EXPECT_EQ(200, tl.get());\n//\n// The template type argument T must have a public copy constructor.\n// In addition, the default ThreadLocal constructor requires T to have\n// a public default constructor.\n//\n// An object managed for a thread by a ThreadLocal instance is deleted\n// when the thread exits.  Or, if the ThreadLocal instance dies in\n// that thread, when the ThreadLocal dies.  It's the user's\n// responsibility to ensure that all other threads using a ThreadLocal\n// have exited when it dies, or the per-thread objects for those\n// threads will not be deleted.\n//\n// Google Test only uses global ThreadLocal objects.  That means they\n// will die after main() has returned.  Therefore, no per-thread\n// object managed by Google Test will be leaked as long as all threads\n// using Google Test have exited when main() returns.\ntemplate <typename T>\nclass ThreadLocal {\n public:\n  ThreadLocal() : key_(CreateKey()),\n                  default_() {}\n  explicit ThreadLocal(const T& value) : key_(CreateKey()),\n                                         default_(value) {}\n\n  ~ThreadLocal() {\n    // Destroys the managed object for the current thread, if any.\n    DeleteThreadLocalValue(pthread_getspecific(key_));\n\n    // Releases resources associated with the key.  This will *not*\n    // delete managed objects for other threads.\n    GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));\n  }\n\n  T* pointer() { return GetOrCreateValue(); }\n  const T* pointer() const { return GetOrCreateValue(); }\n  const T& get() const { return *pointer(); }\n  void set(const T& value) { *pointer() = value; }\n\n private:\n  // Holds a value of type T.\n  class ValueHolder : public ThreadLocalValueHolderBase {\n   public:\n    explicit ValueHolder(const T& value) : value_(value) {}\n\n    T* pointer() { return &value_; }\n\n   private:\n    T value_;\n    GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);\n  };\n\n  static pthread_key_t CreateKey() {\n    pthread_key_t key;\n    // When a thread exits, DeleteThreadLocalValue() will be called on\n    // the object managed for that thread.\n    GTEST_CHECK_POSIX_SUCCESS_(\n        pthread_key_create(&key, &DeleteThreadLocalValue));\n    return key;\n  }\n\n  T* GetOrCreateValue() const {\n    ThreadLocalValueHolderBase* const holder =\n        static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));\n    if (holder != NULL) {\n      return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();\n    }\n\n    ValueHolder* const new_holder = new ValueHolder(default_);\n    ThreadLocalValueHolderBase* const holder_base = new_holder;\n    GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));\n    return new_holder->pointer();\n  }\n\n  // A key pthreads uses for looking up per-thread values.\n  const pthread_key_t key_;\n  const T default_;  // The default value for each thread.\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);\n};\n\n# define GTEST_IS_THREADSAFE 1\n\n#else  // GTEST_HAS_PTHREAD\n\n// A dummy implementation of synchronization primitives (mutex, lock,\n// and thread-local variable).  Necessary for compiling Google Test where\n// mutex is not supported - using Google Test in multiple threads is not\n// supported on such platforms.\n\nclass Mutex {\n public:\n  Mutex() {}\n  void AssertHeld() const {}\n};\n\n# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \\\n  extern ::testing::internal::Mutex mutex\n\n# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex\n\nclass GTestMutexLock {\n public:\n  explicit GTestMutexLock(Mutex*) {}  // NOLINT\n};\n\ntypedef GTestMutexLock MutexLock;\n\ntemplate <typename T>\nclass ThreadLocal {\n public:\n  ThreadLocal() : value_() {}\n  explicit ThreadLocal(const T& value) : value_(value) {}\n  T* pointer() { return &value_; }\n  const T* pointer() const { return &value_; }\n  const T& get() const { return value_; }\n  void set(const T& value) { value_ = value; }\n private:\n  T value_;\n};\n\n// The above synchronization primitives have dummy implementations.\n// Therefore Google Test is not thread-safe.\n# define GTEST_IS_THREADSAFE 0\n\n#endif  // GTEST_HAS_PTHREAD\n\n// Returns the number of threads running in the process, or 0 to indicate that\n// we cannot detect it.\nGTEST_API_ size_t GetThreadCount();\n\n// Passing non-POD classes through ellipsis (...) crashes the ARM\n// compiler and generates a warning in Sun Studio.  The Nokia Symbian\n// and the IBM XL C/C++ compiler try to instantiate a copy constructor\n// for objects passed through ellipsis (...), failing for uncopyable\n// objects.  We define this to ensure that only POD is passed through\n// ellipsis on these systems.\n#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)\n// We lose support for NULL detection where the compiler doesn't like\n// passing non-POD classes through ellipsis (...).\n# define GTEST_ELLIPSIS_NEEDS_POD_ 1\n#else\n# define GTEST_CAN_COMPARE_NULL 1\n#endif\n\n// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between\n// const T& and const T* in a function template.  These compilers\n// _can_ decide between class template specializations for T and T*,\n// so a tr1::type_traits-like is_pointer works.\n#if defined(__SYMBIAN32__) || defined(__IBMCPP__)\n# define GTEST_NEEDS_IS_POINTER_ 1\n#endif\n\ntemplate <bool bool_value>\nstruct bool_constant {\n  typedef bool_constant<bool_value> type;\n  static const bool value = bool_value;\n};\ntemplate <bool bool_value> const bool bool_constant<bool_value>::value;\n\ntypedef bool_constant<false> false_type;\ntypedef bool_constant<true> true_type;\n\ntemplate <typename T>\nstruct is_pointer : public false_type {};\n\ntemplate <typename T>\nstruct is_pointer<T*> : public true_type {};\n\ntemplate <typename Iterator>\nstruct IteratorTraits {\n  typedef typename Iterator::value_type value_type;\n};\n\ntemplate <typename T>\nstruct IteratorTraits<T*> {\n  typedef T value_type;\n};\n\ntemplate <typename T>\nstruct IteratorTraits<const T*> {\n  typedef T value_type;\n};\n\n#if GTEST_OS_WINDOWS\n# define GTEST_PATH_SEP_ \"\\\\\"\n# define GTEST_HAS_ALT_PATH_SEP_ 1\n// The biggest signed integer type the compiler supports.\ntypedef __int64 BiggestInt;\n#else\n# define GTEST_PATH_SEP_ \"/\"\n# define GTEST_HAS_ALT_PATH_SEP_ 0\ntypedef long long BiggestInt;  // NOLINT\n#endif  // GTEST_OS_WINDOWS\n\n// Utilities for char.\n\n// isspace(int ch) and friends accept an unsigned char or EOF.  char\n// may be signed, depending on the compiler (or compiler flags).\n// Therefore we need to cast a char to unsigned char before calling\n// isspace(), etc.\n\ninline bool IsAlpha(char ch) {\n  return isalpha(static_cast<unsigned char>(ch)) != 0;\n}\ninline bool IsAlNum(char ch) {\n  return isalnum(static_cast<unsigned char>(ch)) != 0;\n}\ninline bool IsDigit(char ch) {\n  return isdigit(static_cast<unsigned char>(ch)) != 0;\n}\ninline bool IsLower(char ch) {\n  return islower(static_cast<unsigned char>(ch)) != 0;\n}\ninline bool IsSpace(char ch) {\n  return isspace(static_cast<unsigned char>(ch)) != 0;\n}\ninline bool IsUpper(char ch) {\n  return isupper(static_cast<unsigned char>(ch)) != 0;\n}\ninline bool IsXDigit(char ch) {\n  return isxdigit(static_cast<unsigned char>(ch)) != 0;\n}\n\ninline char ToLower(char ch) {\n  return static_cast<char>(tolower(static_cast<unsigned char>(ch)));\n}\ninline char ToUpper(char ch) {\n  return static_cast<char>(toupper(static_cast<unsigned char>(ch)));\n}\n\n// The testing::internal::posix namespace holds wrappers for common\n// POSIX functions.  These wrappers hide the differences between\n// Windows/MSVC and POSIX systems.  Since some compilers define these\n// standard functions as macros, the wrapper cannot have the same name\n// as the wrapped function.\n\nnamespace posix {\n\n// Functions with a different name on Windows.\n\n#if GTEST_OS_WINDOWS\n\ntypedef struct _stat StatStruct;\n\n# ifdef __BORLANDC__\ninline int IsATTY(int fd) { return isatty(fd); }\ninline int StrCaseCmp(const char* s1, const char* s2) {\n  return stricmp(s1, s2);\n}\ninline char* StrDup(const char* src) { return strdup(src); }\n# else  // !__BORLANDC__\n#  if GTEST_OS_WINDOWS_MOBILE\ninline int IsATTY(int /* fd */) { return 0; }\n#  else\ninline int IsATTY(int fd) { return _isatty(fd); }\n#  endif  // GTEST_OS_WINDOWS_MOBILE\ninline int StrCaseCmp(const char* s1, const char* s2) {\n  return _stricmp(s1, s2);\n}\ninline char* StrDup(const char* src) { return _strdup(src); }\n# endif  // __BORLANDC__\n\n# if GTEST_OS_WINDOWS_MOBILE\ninline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }\n// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this\n// time and thus not defined there.\n# else\ninline int FileNo(FILE* file) { return _fileno(file); }\ninline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }\ninline int RmDir(const char* dir) { return _rmdir(dir); }\ninline bool IsDir(const StatStruct& st) {\n  return (_S_IFDIR & st.st_mode) != 0;\n}\n# endif  // GTEST_OS_WINDOWS_MOBILE\n\n#else\n\ntypedef struct stat StatStruct;\n\ninline int FileNo(FILE* file) { return fileno(file); }\ninline int IsATTY(int fd) { return isatty(fd); }\ninline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }\ninline int StrCaseCmp(const char* s1, const char* s2) {\n  return strcasecmp(s1, s2);\n}\ninline char* StrDup(const char* src) { return strdup(src); }\ninline int RmDir(const char* dir) { return rmdir(dir); }\ninline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }\n\n#endif  // GTEST_OS_WINDOWS\n\n// Functions deprecated by MSVC 8.0.\n\n#ifdef _MSC_VER\n// Temporarily disable warning 4996 (deprecated function).\n# pragma warning(push)\n# pragma warning(disable:4996)\n#endif\n\ninline const char* StrNCpy(char* dest, const char* src, size_t n) {\n  return strncpy(dest, src, n);\n}\n\n// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and\n// StrError() aren't needed on Windows CE at this time and thus not\n// defined there.\n\n#if !GTEST_OS_WINDOWS_MOBILE\ninline int ChDir(const char* dir) { return chdir(dir); }\n#endif\ninline FILE* FOpen(const char* path, const char* mode) {\n  return fopen(path, mode);\n}\n#if !GTEST_OS_WINDOWS_MOBILE\ninline FILE *FReopen(const char* path, const char* mode, FILE* stream) {\n  return freopen(path, mode, stream);\n}\ninline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }\n#endif\ninline int FClose(FILE* fp) { return fclose(fp); }\n#if !GTEST_OS_WINDOWS_MOBILE\ninline int Read(int fd, void* buf, unsigned int count) {\n  return static_cast<int>(read(fd, buf, count));\n}\ninline int Write(int fd, const void* buf, unsigned int count) {\n  return static_cast<int>(write(fd, buf, count));\n}\ninline int Close(int fd) { return close(fd); }\ninline const char* StrError(int errnum) { return strerror(errnum); }\n#endif\ninline const char* GetEnv(const char* name) {\n#if GTEST_OS_WINDOWS_MOBILE\n  // We are on Windows CE, which has no environment variables.\n  return NULL;\n#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)\n  // Environment variables which we programmatically clear will be set to the\n  // empty string rather than unset (NULL).  Handle that case.\n  const char* const env = getenv(name);\n  return (env != NULL && env[0] != '\\0') ? env : NULL;\n#else\n  return getenv(name);\n#endif\n}\n\n#ifdef _MSC_VER\n# pragma warning(pop)  // Restores the warning state.\n#endif\n\n#if GTEST_OS_WINDOWS_MOBILE\n// Windows CE has no C library. The abort() function is used in\n// several places in Google Test. This implementation provides a reasonable\n// imitation of standard behaviour.\nvoid Abort();\n#else\ninline void Abort() { abort(); }\n#endif  // GTEST_OS_WINDOWS_MOBILE\n\n}  // namespace posix\n\n// The maximum number a BiggestInt can represent.  This definition\n// works no matter BiggestInt is represented in one's complement or\n// two's complement.\n//\n// We cannot rely on numeric_limits in STL, as __int64 and long long\n// are not part of standard C++ and numeric_limits doesn't need to be\n// defined for them.\nconst BiggestInt kMaxBiggestInt =\n    ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));\n\n// This template class serves as a compile-time function from size to\n// type.  It maps a size in bytes to a primitive type with that\n// size. e.g.\n//\n//   TypeWithSize<4>::UInt\n//\n// is typedef-ed to be unsigned int (unsigned integer made up of 4\n// bytes).\n//\n// Such functionality should belong to STL, but I cannot find it\n// there.\n//\n// Google Test uses this class in the implementation of floating-point\n// comparison.\n//\n// For now it only handles UInt (unsigned int) as that's all Google Test\n// needs.  Other types can be easily added in the future if need\n// arises.\ntemplate <size_t size>\nclass TypeWithSize {\n public:\n  // This prevents the user from using TypeWithSize<N> with incorrect\n  // values of N.\n  typedef void UInt;\n};\n\n// The specialization for size 4.\ntemplate <>\nclass TypeWithSize<4> {\n public:\n  // unsigned int has size 4 in both gcc and MSVC.\n  //\n  // As base/basictypes.h doesn't compile on Windows, we cannot use\n  // uint32, uint64, and etc here.\n  typedef int Int;\n  typedef unsigned int UInt;\n};\n\n// The specialization for size 8.\ntemplate <>\nclass TypeWithSize<8> {\n public:\n\n#if GTEST_OS_WINDOWS\n  typedef __int64 Int;\n  typedef unsigned __int64 UInt;\n#else\n  typedef long long Int;  // NOLINT\n  typedef unsigned long long UInt;  // NOLINT\n#endif  // GTEST_OS_WINDOWS\n};\n\n// Integer types of known sizes.\ntypedef TypeWithSize<4>::Int Int32;\ntypedef TypeWithSize<4>::UInt UInt32;\ntypedef TypeWithSize<8>::Int Int64;\ntypedef TypeWithSize<8>::UInt UInt64;\ntypedef TypeWithSize<8>::Int TimeInMillis;  // Represents time in milliseconds.\n\n// Utilities for command line flags and environment variables.\n\n// Macro for referencing flags.\n#define GTEST_FLAG(name) FLAGS_gtest_##name\n\n// Macros for declaring flags.\n#define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)\n#define GTEST_DECLARE_int32_(name) \\\n    GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)\n#define GTEST_DECLARE_string_(name) \\\n    GTEST_API_ extern ::testing::internal::String GTEST_FLAG(name)\n\n// Macros for defining flags.\n#define GTEST_DEFINE_bool_(name, default_val, doc) \\\n    GTEST_API_ bool GTEST_FLAG(name) = (default_val)\n#define GTEST_DEFINE_int32_(name, default_val, doc) \\\n    GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)\n#define GTEST_DEFINE_string_(name, default_val, doc) \\\n    GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val)\n\n// Parses 'str' for a 32-bit signed integer.  If successful, writes the result\n// to *value and returns true; otherwise leaves *value unchanged and returns\n// false.\n// TODO(chandlerc): Find a better way to refactor flag and environment parsing\n// out of both gtest-port.cc and gtest.cc to avoid exporting this utility\n// function.\nbool ParseInt32(const Message& src_text, const char* str, Int32* value);\n\n// Parses a bool/Int32/string from the environment variable\n// corresponding to the given Google Test flag.\nbool BoolFromGTestEnv(const char* flag, bool default_val);\nGTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);\nconst char* StringFromGTestEnv(const char* flag, const char* default_val);\n\n}  // namespace internal\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_\n\n#if GTEST_OS_LINUX\n# include <stdlib.h>\n# include <sys/types.h>\n# include <sys/wait.h>\n# include <unistd.h>\n#endif  // GTEST_OS_LINUX\n\n#include <ctype.h>\n#include <string.h>\n#include <iomanip>\n#include <limits>\n#include <set>\n\n// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)\n//\n// The Google C++ Testing Framework (Google Test)\n//\n// This header file declares the String class and functions used internally by\n// Google Test.  They are subject to change without notice. They should not used\n// by code external to Google Test.\n//\n// This header file is #included by <gtest/internal/gtest-internal.h>.\n// It should not be #included by other files.\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_\n\n#ifdef __BORLANDC__\n// string.h is not guaranteed to provide strcpy on C++ Builder.\n# include <mem.h>\n#endif\n\n#include <string.h>\n\n#include <string>\n\nnamespace testing {\nnamespace internal {\n\n// String - a UTF-8 string class.\n//\n// For historic reasons, we don't use std::string.\n//\n// TODO(wan@google.com): replace this class with std::string or\n// implement it in terms of the latter.\n//\n// Note that String can represent both NULL and the empty string,\n// while std::string cannot represent NULL.\n//\n// NULL and the empty string are considered different.  NULL is less\n// than anything (including the empty string) except itself.\n//\n// This class only provides minimum functionality necessary for\n// implementing Google Test.  We do not intend to implement a full-fledged\n// string class here.\n//\n// Since the purpose of this class is to provide a substitute for\n// std::string on platforms where it cannot be used, we define a copy\n// constructor and assignment operators such that we don't need\n// conditional compilation in a lot of places.\n//\n// In order to make the representation efficient, the d'tor of String\n// is not virtual.  Therefore DO NOT INHERIT FROM String.\nclass GTEST_API_ String {\n public:\n  // Static utility methods\n\n  // Returns the input enclosed in double quotes if it's not NULL;\n  // otherwise returns \"(null)\".  For example, \"\\\"Hello\\\"\" is returned\n  // for input \"Hello\".\n  //\n  // This is useful for printing a C string in the syntax of a literal.\n  //\n  // Known issue: escape sequences are not handled yet.\n  static String ShowCStringQuoted(const char* c_str);\n\n  // Clones a 0-terminated C string, allocating memory using new.  The\n  // caller is responsible for deleting the return value using\n  // delete[].  Returns the cloned string, or NULL if the input is\n  // NULL.\n  //\n  // This is different from strdup() in string.h, which allocates\n  // memory using malloc().\n  static const char* CloneCString(const char* c_str);\n\n#if GTEST_OS_WINDOWS_MOBILE\n  // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be\n  // able to pass strings to Win32 APIs on CE we need to convert them\n  // to 'Unicode', UTF-16.\n\n  // Creates a UTF-16 wide string from the given ANSI string, allocating\n  // memory using new. The caller is responsible for deleting the return\n  // value using delete[]. Returns the wide string, or NULL if the\n  // input is NULL.\n  //\n  // The wide string is created using the ANSI codepage (CP_ACP) to\n  // match the behaviour of the ANSI versions of Win32 calls and the\n  // C runtime.\n  static LPCWSTR AnsiToUtf16(const char* c_str);\n\n  // Creates an ANSI string from the given wide string, allocating\n  // memory using new. The caller is responsible for deleting the return\n  // value using delete[]. Returns the ANSI string, or NULL if the\n  // input is NULL.\n  //\n  // The returned string is created using the ANSI codepage (CP_ACP) to\n  // match the behaviour of the ANSI versions of Win32 calls and the\n  // C runtime.\n  static const char* Utf16ToAnsi(LPCWSTR utf16_str);\n#endif\n\n  // Compares two C strings.  Returns true iff they have the same content.\n  //\n  // Unlike strcmp(), this function can handle NULL argument(s).  A\n  // NULL C string is considered different to any non-NULL C string,\n  // including the empty string.\n  static bool CStringEquals(const char* lhs, const char* rhs);\n\n  // Converts a wide C string to a String using the UTF-8 encoding.\n  // NULL will be converted to \"(null)\".  If an error occurred during\n  // the conversion, \"(failed to convert from wide string)\" is\n  // returned.\n  static String ShowWideCString(const wchar_t* wide_c_str);\n\n  // Similar to ShowWideCString(), except that this function encloses\n  // the converted string in double quotes.\n  static String ShowWideCStringQuoted(const wchar_t* wide_c_str);\n\n  // Compares two wide C strings.  Returns true iff they have the same\n  // content.\n  //\n  // Unlike wcscmp(), this function can handle NULL argument(s).  A\n  // NULL C string is considered different to any non-NULL C string,\n  // including the empty string.\n  static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs);\n\n  // Compares two C strings, ignoring case.  Returns true iff they\n  // have the same content.\n  //\n  // Unlike strcasecmp(), this function can handle NULL argument(s).\n  // A NULL C string is considered different to any non-NULL C string,\n  // including the empty string.\n  static bool CaseInsensitiveCStringEquals(const char* lhs,\n                                           const char* rhs);\n\n  // Compares two wide C strings, ignoring case.  Returns true iff they\n  // have the same content.\n  //\n  // Unlike wcscasecmp(), this function can handle NULL argument(s).\n  // A NULL C string is considered different to any non-NULL wide C string,\n  // including the empty string.\n  // NB: The implementations on different platforms slightly differ.\n  // On windows, this method uses _wcsicmp which compares according to LC_CTYPE\n  // environment variable. On GNU platform this method uses wcscasecmp\n  // which compares according to LC_CTYPE category of the current locale.\n  // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the\n  // current locale.\n  static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs,\n                                               const wchar_t* rhs);\n\n  // Formats a list of arguments to a String, using the same format\n  // spec string as for printf.\n  //\n  // We do not use the StringPrintf class as it is not universally\n  // available.\n  //\n  // The result is limited to 4096 characters (including the tailing\n  // 0).  If 4096 characters are not enough to format the input,\n  // \"<buffer exceeded>\" is returned.\n  static String Format(const char* format, ...);\n\n  // C'tors\n\n  // The default c'tor constructs a NULL string.\n  String() : c_str_(NULL), length_(0) {}\n\n  // Constructs a String by cloning a 0-terminated C string.\n  String(const char* a_c_str) {  // NOLINT\n    if (a_c_str == NULL) {\n      c_str_ = NULL;\n      length_ = 0;\n    } else {\n      ConstructNonNull(a_c_str, strlen(a_c_str));\n    }\n  }\n\n  // Constructs a String by copying a given number of chars from a\n  // buffer.  E.g. String(\"hello\", 3) creates the string \"hel\",\n  // String(\"a\\0bcd\", 4) creates \"a\\0bc\", String(NULL, 0) creates \"\",\n  // and String(NULL, 1) results in access violation.\n  String(const char* buffer, size_t a_length) {\n    ConstructNonNull(buffer, a_length);\n  }\n\n  // The copy c'tor creates a new copy of the string.  The two\n  // String objects do not share content.\n  String(const String& str) : c_str_(NULL), length_(0) { *this = str; }\n\n  // D'tor.  String is intended to be a final class, so the d'tor\n  // doesn't need to be virtual.\n  ~String() { delete[] c_str_; }\n\n  // Allows a String to be implicitly converted to an ::std::string or\n  // ::string, and vice versa.  Converting a String containing a NULL\n  // pointer to ::std::string or ::string is undefined behavior.\n  // Converting a ::std::string or ::string containing an embedded NUL\n  // character to a String will result in the prefix up to the first\n  // NUL character.\n  String(const ::std::string& str) {\n    ConstructNonNull(str.c_str(), str.length());\n  }\n\n  operator ::std::string() const { return ::std::string(c_str(), length()); }\n\n#if GTEST_HAS_GLOBAL_STRING\n  String(const ::string& str) {\n    ConstructNonNull(str.c_str(), str.length());\n  }\n\n  operator ::string() const { return ::string(c_str(), length()); }\n#endif  // GTEST_HAS_GLOBAL_STRING\n\n  // Returns true iff this is an empty string (i.e. \"\").\n  bool empty() const { return (c_str() != NULL) && (length() == 0); }\n\n  // Compares this with another String.\n  // Returns < 0 if this is less than rhs, 0 if this is equal to rhs, or > 0\n  // if this is greater than rhs.\n  int Compare(const String& rhs) const;\n\n  // Returns true iff this String equals the given C string.  A NULL\n  // string and a non-NULL string are considered not equal.\n  bool operator==(const char* a_c_str) const { return Compare(a_c_str) == 0; }\n\n  // Returns true iff this String is less than the given String.  A\n  // NULL string is considered less than \"\".\n  bool operator<(const String& rhs) const { return Compare(rhs) < 0; }\n\n  // Returns true iff this String doesn't equal the given C string.  A NULL\n  // string and a non-NULL string are considered not equal.\n  bool operator!=(const char* a_c_str) const { return !(*this == a_c_str); }\n\n  // Returns true iff this String ends with the given suffix.  *Any*\n  // String is considered to end with a NULL or empty suffix.\n  bool EndsWith(const char* suffix) const;\n\n  // Returns true iff this String ends with the given suffix, not considering\n  // case. Any String is considered to end with a NULL or empty suffix.\n  bool EndsWithCaseInsensitive(const char* suffix) const;\n\n  // Returns the length of the encapsulated string, or 0 if the\n  // string is NULL.\n  size_t length() const { return length_; }\n\n  // Gets the 0-terminated C string this String object represents.\n  // The String object still owns the string.  Therefore the caller\n  // should NOT delete the return value.\n  const char* c_str() const { return c_str_; }\n\n  // Assigns a C string to this object.  Self-assignment works.\n  const String& operator=(const char* a_c_str) {\n    return *this = String(a_c_str);\n  }\n\n  // Assigns a String object to this object.  Self-assignment works.\n  const String& operator=(const String& rhs) {\n    if (this != &rhs) {\n      delete[] c_str_;\n      if (rhs.c_str() == NULL) {\n        c_str_ = NULL;\n        length_ = 0;\n      } else {\n        ConstructNonNull(rhs.c_str(), rhs.length());\n      }\n    }\n\n    return *this;\n  }\n\n private:\n  // Constructs a non-NULL String from the given content.  This\n  // function can only be called when c_str_ has not been allocated.\n  // ConstructNonNull(NULL, 0) results in an empty string (\"\").\n  // ConstructNonNull(NULL, non_zero) is undefined behavior.\n  void ConstructNonNull(const char* buffer, size_t a_length) {\n    char* const str = new char[a_length + 1];\n    memcpy(str, buffer, a_length);\n    str[a_length] = '\\0';\n    c_str_ = str;\n    length_ = a_length;\n  }\n\n  const char* c_str_;\n  size_t length_;\n};  // class String\n\n// Streams a String to an ostream.  Each '\\0' character in the String\n// is replaced with \"\\\\0\".\ninline ::std::ostream& operator<<(::std::ostream& os, const String& str) {\n  if (str.c_str() == NULL) {\n    os << \"(null)\";\n  } else {\n    const char* const c_str = str.c_str();\n    for (size_t i = 0; i != str.length(); i++) {\n      if (c_str[i] == '\\0') {\n        os << \"\\\\0\";\n      } else {\n        os << c_str[i];\n      }\n    }\n  }\n  return os;\n}\n\n// Gets the content of the stringstream's buffer as a String.  Each '\\0'\n// character in the buffer is replaced with \"\\\\0\".\nGTEST_API_ String StringStreamToString(::std::stringstream* stream);\n\n// Converts a streamable value to a String.  A NULL pointer is\n// converted to \"(null)\".  When the input value is a ::string,\n// ::std::string, ::wstring, or ::std::wstring object, each NUL\n// character in it is replaced with \"\\\\0\".\n\n// Declared here but defined in gtest.h, so that it has access\n// to the definition of the Message class, required by the ARM\n// compiler.\ntemplate <typename T>\nString StreamableToString(const T& streamable);\n\n}  // namespace internal\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_\n// Copyright 2008, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: keith.ray@gmail.com (Keith Ray)\n//\n// Google Test filepath utilities\n//\n// This header file declares classes and functions used internally by\n// Google Test.  They are subject to change without notice.\n//\n// This file is #included in <gtest/internal/gtest-internal.h>.\n// Do not include this header file separately!\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_\n\n\nnamespace testing {\nnamespace internal {\n\n// FilePath - a class for file and directory pathname manipulation which\n// handles platform-specific conventions (like the pathname separator).\n// Used for helper functions for naming files in a directory for xml output.\n// Except for Set methods, all methods are const or static, which provides an\n// \"immutable value object\" -- useful for peace of mind.\n// A FilePath with a value ending in a path separator (\"like/this/\") represents\n// a directory, otherwise it is assumed to represent a file. In either case,\n// it may or may not represent an actual file or directory in the file system.\n// Names are NOT checked for syntax correctness -- no checking for illegal\n// characters, malformed paths, etc.\n\nclass GTEST_API_ FilePath {\n public:\n  FilePath() : pathname_(\"\") { }\n  FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }\n\n  explicit FilePath(const char* pathname) : pathname_(pathname) {\n    Normalize();\n  }\n\n  explicit FilePath(const String& pathname) : pathname_(pathname) {\n    Normalize();\n  }\n\n  FilePath& operator=(const FilePath& rhs) {\n    Set(rhs);\n    return *this;\n  }\n\n  void Set(const FilePath& rhs) {\n    pathname_ = rhs.pathname_;\n  }\n\n  String ToString() const { return pathname_; }\n  const char* c_str() const { return pathname_.c_str(); }\n\n  // Returns the current working directory, or \"\" if unsuccessful.\n  static FilePath GetCurrentDir();\n\n  // Given directory = \"dir\", base_name = \"test\", number = 0,\n  // extension = \"xml\", returns \"dir/test.xml\". If number is greater\n  // than zero (e.g., 12), returns \"dir/test_12.xml\".\n  // On Windows platform, uses \\ as the separator rather than /.\n  static FilePath MakeFileName(const FilePath& directory,\n                               const FilePath& base_name,\n                               int number,\n                               const char* extension);\n\n  // Given directory = \"dir\", relative_path = \"test.xml\",\n  // returns \"dir/test.xml\".\n  // On Windows, uses \\ as the separator rather than /.\n  static FilePath ConcatPaths(const FilePath& directory,\n                              const FilePath& relative_path);\n\n  // Returns a pathname for a file that does not currently exist. The pathname\n  // will be directory/base_name.extension or\n  // directory/base_name_<number>.extension if directory/base_name.extension\n  // already exists. The number will be incremented until a pathname is found\n  // that does not already exist.\n  // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.\n  // There could be a race condition if two or more processes are calling this\n  // function at the same time -- they could both pick the same filename.\n  static FilePath GenerateUniqueFileName(const FilePath& directory,\n                                         const FilePath& base_name,\n                                         const char* extension);\n\n  // Returns true iff the path is NULL or \"\".\n  bool IsEmpty() const { return c_str() == NULL || *c_str() == '\\0'; }\n\n  // If input name has a trailing separator character, removes it and returns\n  // the name, otherwise return the name string unmodified.\n  // On Windows platform, uses \\ as the separator, other platforms use /.\n  FilePath RemoveTrailingPathSeparator() const;\n\n  // Returns a copy of the FilePath with the directory part removed.\n  // Example: FilePath(\"path/to/file\").RemoveDirectoryName() returns\n  // FilePath(\"file\"). If there is no directory part (\"just_a_file\"), it returns\n  // the FilePath unmodified. If there is no file part (\"just_a_dir/\") it\n  // returns an empty FilePath (\"\").\n  // On Windows platform, '\\' is the path separator, otherwise it is '/'.\n  FilePath RemoveDirectoryName() const;\n\n  // RemoveFileName returns the directory path with the filename removed.\n  // Example: FilePath(\"path/to/file\").RemoveFileName() returns \"path/to/\".\n  // If the FilePath is \"a_file\" or \"/a_file\", RemoveFileName returns\n  // FilePath(\"./\") or, on Windows, FilePath(\".\\\\\"). If the filepath does\n  // not have a file, like \"just/a/dir/\", it returns the FilePath unmodified.\n  // On Windows platform, '\\' is the path separator, otherwise it is '/'.\n  FilePath RemoveFileName() const;\n\n  // Returns a copy of the FilePath with the case-insensitive extension removed.\n  // Example: FilePath(\"dir/file.exe\").RemoveExtension(\"EXE\") returns\n  // FilePath(\"dir/file\"). If a case-insensitive extension is not\n  // found, returns a copy of the original FilePath.\n  FilePath RemoveExtension(const char* extension) const;\n\n  // Creates directories so that path exists. Returns true if successful or if\n  // the directories already exist; returns false if unable to create\n  // directories for any reason. Will also return false if the FilePath does\n  // not represent a directory (that is, it doesn't end with a path separator).\n  bool CreateDirectoriesRecursively() const;\n\n  // Create the directory so that path exists. Returns true if successful or\n  // if the directory already exists; returns false if unable to create the\n  // directory for any reason, including if the parent directory does not\n  // exist. Not named \"CreateDirectory\" because that's a macro on Windows.\n  bool CreateFolder() const;\n\n  // Returns true if FilePath describes something in the file-system,\n  // either a file, directory, or whatever, and that something exists.\n  bool FileOrDirectoryExists() const;\n\n  // Returns true if pathname describes a directory in the file-system\n  // that exists.\n  bool DirectoryExists() const;\n\n  // Returns true if FilePath ends with a path separator, which indicates that\n  // it is intended to represent a directory. Returns false otherwise.\n  // This does NOT check that a directory (or file) actually exists.\n  bool IsDirectory() const;\n\n  // Returns true if pathname describes a root directory. (Windows has one\n  // root directory per disk drive.)\n  bool IsRootDirectory() const;\n\n  // Returns true if pathname describes an absolute path.\n  bool IsAbsolutePath() const;\n\n private:\n  // Replaces multiple consecutive separators with a single separator.\n  // For example, \"bar///foo\" becomes \"bar/foo\". Does not eliminate other\n  // redundancies that might be in a pathname involving \".\" or \"..\".\n  //\n  // A pathname with multiple consecutive separators may occur either through\n  // user error or as a result of some scripts or APIs that generate a pathname\n  // with a trailing separator. On other platforms the same API or script\n  // may NOT generate a pathname with a trailing \"/\". Then elsewhere that\n  // pathname may have another \"/\" and pathname components added to it,\n  // without checking for the separator already being there.\n  // The script language and operating system may allow paths like \"foo//bar\"\n  // but some of the functions in FilePath will not handle that correctly. In\n  // particular, RemoveTrailingPathSeparator() only removes one separator, and\n  // it is called in CreateDirectoriesRecursively() assuming that it will change\n  // a pathname from directory syntax (trailing separator) to filename syntax.\n  //\n  // On Windows this method also replaces the alternate path separator '/' with\n  // the primary path separator '\\\\', so that for example \"bar\\\\/\\\\foo\" becomes\n  // \"bar\\\\foo\".\n\n  void Normalize();\n\n  // Returns a pointer to the last occurence of a valid path separator in\n  // the FilePath. On Windows, for example, both '/' and '\\' are valid path\n  // separators. Returns NULL if no path separator was found.\n  const char* FindLastPathSeparator() const;\n\n  String pathname_;\n};  // class FilePath\n\n}  // namespace internal\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_\n// This file was GENERATED by command:\n//     pump.py gtest-type-util.h.pump\n// DO NOT EDIT BY HAND!!!\n\n// Copyright 2008 Google Inc.\n// All Rights Reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n\n// Type utilities needed for implementing typed and type-parameterized\n// tests.  This file is generated by a SCRIPT.  DO NOT EDIT BY HAND!\n//\n// Currently we support at most 50 types in a list, and at most 50\n// type-parameterized tests in one type-parameterized test case.\n// Please contact googletestframework@googlegroups.com if you need\n// more.\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_\n\n\n// #ifdef __GNUC__ is too general here.  It is possible to use gcc without using\n// libstdc++ (which is where cxxabi.h comes from).\n# ifdef __GLIBCXX__\n#  include <cxxabi.h>\n# elif defined(__HP_aCC)\n#  include <acxx_demangle.h>\n# endif  // __GLIBCXX__\n\nnamespace testing {\nnamespace internal {\n\n// GetTypeName<T>() returns a human-readable name of type T.\n// NB: This function is also used in Google Mock, so don't move it inside of\n// the typed-test-only section below.\ntemplate <typename T>\nString GetTypeName() {\n# if GTEST_HAS_RTTI\n\n  const char* const name = typeid(T).name();\n#  if defined(__GLIBCXX__) || defined(__HP_aCC)\n  int status = 0;\n  // gcc's implementation of typeid(T).name() mangles the type name,\n  // so we have to demangle it.\n#   ifdef __GLIBCXX__\n  using abi::__cxa_demangle;\n#   endif // __GLIBCXX__\n  char* const readable_name = __cxa_demangle(name, 0, 0, &status);\n  const String name_str(status == 0 ? readable_name : name);\n  free(readable_name);\n  return name_str;\n#  else\n  return name;\n#  endif  // __GLIBCXX__ || __HP_aCC\n\n# else\n\n  return \"<type>\";\n\n# endif  // GTEST_HAS_RTTI\n}\n\n#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P\n\n// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same\n// type.  This can be used as a compile-time assertion to ensure that\n// two types are equal.\n\ntemplate <typename T1, typename T2>\nstruct AssertTypeEq;\n\ntemplate <typename T>\nstruct AssertTypeEq<T, T> {\n  typedef bool type;\n};\n\n// A unique type used as the default value for the arguments of class\n// template Types.  This allows us to simulate variadic templates\n// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't\n// support directly.\nstruct None {};\n\n// The following family of struct and struct templates are used to\n// represent type lists.  In particular, TypesN<T1, T2, ..., TN>\n// represents a type list with N types (T1, T2, ..., and TN) in it.\n// Except for Types0, every struct in the family has two member types:\n// Head for the first type in the list, and Tail for the rest of the\n// list.\n\n// The empty type list.\nstruct Types0 {};\n\n// Type lists of length 1, 2, 3, and so on.\n\ntemplate <typename T1>\nstruct Types1 {\n  typedef T1 Head;\n  typedef Types0 Tail;\n};\ntemplate <typename T1, typename T2>\nstruct Types2 {\n  typedef T1 Head;\n  typedef Types1<T2> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3>\nstruct Types3 {\n  typedef T1 Head;\n  typedef Types2<T2, T3> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4>\nstruct Types4 {\n  typedef T1 Head;\n  typedef Types3<T2, T3, T4> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5>\nstruct Types5 {\n  typedef T1 Head;\n  typedef Types4<T2, T3, T4, T5> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6>\nstruct Types6 {\n  typedef T1 Head;\n  typedef Types5<T2, T3, T4, T5, T6> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7>\nstruct Types7 {\n  typedef T1 Head;\n  typedef Types6<T2, T3, T4, T5, T6, T7> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8>\nstruct Types8 {\n  typedef T1 Head;\n  typedef Types7<T2, T3, T4, T5, T6, T7, T8> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9>\nstruct Types9 {\n  typedef T1 Head;\n  typedef Types8<T2, T3, T4, T5, T6, T7, T8, T9> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10>\nstruct Types10 {\n  typedef T1 Head;\n  typedef Types9<T2, T3, T4, T5, T6, T7, T8, T9, T10> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11>\nstruct Types11 {\n  typedef T1 Head;\n  typedef Types10<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12>\nstruct Types12 {\n  typedef T1 Head;\n  typedef Types11<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13>\nstruct Types13 {\n  typedef T1 Head;\n  typedef Types12<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14>\nstruct Types14 {\n  typedef T1 Head;\n  typedef Types13<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15>\nstruct Types15 {\n  typedef T1 Head;\n  typedef Types14<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16>\nstruct Types16 {\n  typedef T1 Head;\n  typedef Types15<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17>\nstruct Types17 {\n  typedef T1 Head;\n  typedef Types16<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18>\nstruct Types18 {\n  typedef T1 Head;\n  typedef Types17<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19>\nstruct Types19 {\n  typedef T1 Head;\n  typedef Types18<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20>\nstruct Types20 {\n  typedef T1 Head;\n  typedef Types19<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21>\nstruct Types21 {\n  typedef T1 Head;\n  typedef Types20<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22>\nstruct Types22 {\n  typedef T1 Head;\n  typedef Types21<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23>\nstruct Types23 {\n  typedef T1 Head;\n  typedef Types22<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24>\nstruct Types24 {\n  typedef T1 Head;\n  typedef Types23<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25>\nstruct Types25 {\n  typedef T1 Head;\n  typedef Types24<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26>\nstruct Types26 {\n  typedef T1 Head;\n  typedef Types25<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27>\nstruct Types27 {\n  typedef T1 Head;\n  typedef Types26<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28>\nstruct Types28 {\n  typedef T1 Head;\n  typedef Types27<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29>\nstruct Types29 {\n  typedef T1 Head;\n  typedef Types28<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30>\nstruct Types30 {\n  typedef T1 Head;\n  typedef Types29<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31>\nstruct Types31 {\n  typedef T1 Head;\n  typedef Types30<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32>\nstruct Types32 {\n  typedef T1 Head;\n  typedef Types31<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33>\nstruct Types33 {\n  typedef T1 Head;\n  typedef Types32<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34>\nstruct Types34 {\n  typedef T1 Head;\n  typedef Types33<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35>\nstruct Types35 {\n  typedef T1 Head;\n  typedef Types34<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36>\nstruct Types36 {\n  typedef T1 Head;\n  typedef Types35<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37>\nstruct Types37 {\n  typedef T1 Head;\n  typedef Types36<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38>\nstruct Types38 {\n  typedef T1 Head;\n  typedef Types37<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39>\nstruct Types39 {\n  typedef T1 Head;\n  typedef Types38<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40>\nstruct Types40 {\n  typedef T1 Head;\n  typedef Types39<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41>\nstruct Types41 {\n  typedef T1 Head;\n  typedef Types40<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42>\nstruct Types42 {\n  typedef T1 Head;\n  typedef Types41<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43>\nstruct Types43 {\n  typedef T1 Head;\n  typedef Types42<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n      T43> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44>\nstruct Types44 {\n  typedef T1 Head;\n  typedef Types43<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n      T44> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45>\nstruct Types45 {\n  typedef T1 Head;\n  typedef Types44<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n      T44, T45> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46>\nstruct Types46 {\n  typedef T1 Head;\n  typedef Types45<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n      T44, T45, T46> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47>\nstruct Types47 {\n  typedef T1 Head;\n  typedef Types46<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n      T44, T45, T46, T47> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48>\nstruct Types48 {\n  typedef T1 Head;\n  typedef Types47<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n      T44, T45, T46, T47, T48> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48, typename T49>\nstruct Types49 {\n  typedef T1 Head;\n  typedef Types48<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n      T44, T45, T46, T47, T48, T49> Tail;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48, typename T49, typename T50>\nstruct Types50 {\n  typedef T1 Head;\n  typedef Types49<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n      T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n      T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n      T44, T45, T46, T47, T48, T49, T50> Tail;\n};\n\n\n}  // namespace internal\n\n// We don't want to require the users to write TypesN<...> directly,\n// as that would require them to count the length.  Types<...> is much\n// easier to write, but generates horrible messages when there is a\n// compiler error, as gcc insists on printing out each template\n// argument, even if it has the default value (this means Types<int>\n// will appear as Types<int, None, None, ..., None> in the compiler\n// errors).\n//\n// Our solution is to combine the best part of the two approaches: a\n// user would write Types<T1, ..., TN>, and Google Test will translate\n// that to TypesN<T1, ..., TN> internally to make error messages\n// readable.  The translation is done by the 'type' member of the\n// Types template.\ntemplate <typename T1 = internal::None, typename T2 = internal::None,\n    typename T3 = internal::None, typename T4 = internal::None,\n    typename T5 = internal::None, typename T6 = internal::None,\n    typename T7 = internal::None, typename T8 = internal::None,\n    typename T9 = internal::None, typename T10 = internal::None,\n    typename T11 = internal::None, typename T12 = internal::None,\n    typename T13 = internal::None, typename T14 = internal::None,\n    typename T15 = internal::None, typename T16 = internal::None,\n    typename T17 = internal::None, typename T18 = internal::None,\n    typename T19 = internal::None, typename T20 = internal::None,\n    typename T21 = internal::None, typename T22 = internal::None,\n    typename T23 = internal::None, typename T24 = internal::None,\n    typename T25 = internal::None, typename T26 = internal::None,\n    typename T27 = internal::None, typename T28 = internal::None,\n    typename T29 = internal::None, typename T30 = internal::None,\n    typename T31 = internal::None, typename T32 = internal::None,\n    typename T33 = internal::None, typename T34 = internal::None,\n    typename T35 = internal::None, typename T36 = internal::None,\n    typename T37 = internal::None, typename T38 = internal::None,\n    typename T39 = internal::None, typename T40 = internal::None,\n    typename T41 = internal::None, typename T42 = internal::None,\n    typename T43 = internal::None, typename T44 = internal::None,\n    typename T45 = internal::None, typename T46 = internal::None,\n    typename T47 = internal::None, typename T48 = internal::None,\n    typename T49 = internal::None, typename T50 = internal::None>\nstruct Types {\n  typedef internal::Types50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42, T43, T44, T45, T46, T47, T48, T49, T50> type;\n};\n\ntemplate <>\nstruct Types<internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types0 type;\n};\ntemplate <typename T1>\nstruct Types<T1, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types1<T1> type;\n};\ntemplate <typename T1, typename T2>\nstruct Types<T1, T2, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types2<T1, T2> type;\n};\ntemplate <typename T1, typename T2, typename T3>\nstruct Types<T1, T2, T3, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types3<T1, T2, T3> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4>\nstruct Types<T1, T2, T3, T4, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types4<T1, T2, T3, T4> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5>\nstruct Types<T1, T2, T3, T4, T5, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types5<T1, T2, T3, T4, T5> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6>\nstruct Types<T1, T2, T3, T4, T5, T6, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types6<T1, T2, T3, T4, T5, T6> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types7<T1, T2, T3, T4, T5, T6, T7> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types8<T1, T2, T3, T4, T5, T6, T7, T8> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types9<T1, T2, T3, T4, T5, T6, T7, T8, T9> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, internal::None,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None, internal::None> {\n  typedef internal::Types43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42, T43> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None, internal::None> {\n  typedef internal::Types44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42, T43, T44> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,\n    internal::None, internal::None, internal::None, internal::None,\n    internal::None> {\n  typedef internal::Types45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42, T43, T44, T45> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,\n    T46, internal::None, internal::None, internal::None, internal::None> {\n  typedef internal::Types46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42, T43, T44, T45, T46> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,\n    T46, T47, internal::None, internal::None, internal::None> {\n  typedef internal::Types47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42, T43, T44, T45, T46, T47> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,\n    T46, T47, T48, internal::None, internal::None> {\n  typedef internal::Types48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42, T43, T44, T45, T46, T47, T48> type;\n};\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48, typename T49>\nstruct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,\n    T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,\n    T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,\n    T46, T47, T48, T49, internal::None> {\n  typedef internal::Types49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42, T43, T44, T45, T46, T47, T48, T49> type;\n};\n\nnamespace internal {\n\n# define GTEST_TEMPLATE_ template <typename T> class\n\n// The template \"selector\" struct TemplateSel<Tmpl> is used to\n// represent Tmpl, which must be a class template with one type\n// parameter, as a type.  TemplateSel<Tmpl>::Bind<T>::type is defined\n// as the type Tmpl<T>.  This allows us to actually instantiate the\n// template \"selected\" by TemplateSel<Tmpl>.\n//\n// This trick is necessary for simulating typedef for class templates,\n// which C++ doesn't support directly.\ntemplate <GTEST_TEMPLATE_ Tmpl>\nstruct TemplateSel {\n  template <typename T>\n  struct Bind {\n    typedef Tmpl<T> type;\n  };\n};\n\n# define GTEST_BIND_(TmplSel, T) \\\n  TmplSel::template Bind<T>::type\n\n// A unique struct template used as the default value for the\n// arguments of class template Templates.  This allows us to simulate\n// variadic templates (e.g. Templates<int>, Templates<int, double>,\n// and etc), which C++ doesn't support directly.\ntemplate <typename T>\nstruct NoneT {};\n\n// The following family of struct and struct templates are used to\n// represent template lists.  In particular, TemplatesN<T1, T2, ...,\n// TN> represents a list of N templates (T1, T2, ..., and TN).  Except\n// for Templates0, every struct in the family has two member types:\n// Head for the selector of the first template in the list, and Tail\n// for the rest of the list.\n\n// The empty template list.\nstruct Templates0 {};\n\n// Template lists of length 1, 2, 3, and so on.\n\ntemplate <GTEST_TEMPLATE_ T1>\nstruct Templates1 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates0 Tail;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2>\nstruct Templates2 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates1<T2> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3>\nstruct Templates3 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates2<T2, T3> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4>\nstruct Templates4 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates3<T2, T3, T4> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5>\nstruct Templates5 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates4<T2, T3, T4, T5> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6>\nstruct Templates6 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates5<T2, T3, T4, T5, T6> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7>\nstruct Templates7 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates6<T2, T3, T4, T5, T6, T7> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8>\nstruct Templates8 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates7<T2, T3, T4, T5, T6, T7, T8> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9>\nstruct Templates9 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates8<T2, T3, T4, T5, T6, T7, T8, T9> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10>\nstruct Templates10 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates9<T2, T3, T4, T5, T6, T7, T8, T9, T10> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11>\nstruct Templates11 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates10<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12>\nstruct Templates12 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates11<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13>\nstruct Templates13 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates12<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14>\nstruct Templates14 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates13<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15>\nstruct Templates15 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates14<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16>\nstruct Templates16 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates15<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17>\nstruct Templates17 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates16<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18>\nstruct Templates18 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates17<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19>\nstruct Templates19 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates18<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20>\nstruct Templates20 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates19<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21>\nstruct Templates21 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates20<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22>\nstruct Templates22 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates21<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23>\nstruct Templates23 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates22<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24>\nstruct Templates24 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates23<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25>\nstruct Templates25 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates24<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26>\nstruct Templates26 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates25<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27>\nstruct Templates27 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates26<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28>\nstruct Templates28 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates27<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29>\nstruct Templates29 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates28<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30>\nstruct Templates30 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates29<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31>\nstruct Templates31 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates30<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32>\nstruct Templates32 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates31<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33>\nstruct Templates33 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates32<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34>\nstruct Templates34 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates33<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35>\nstruct Templates35 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates34<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36>\nstruct Templates36 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates35<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37>\nstruct Templates37 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates36<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38>\nstruct Templates38 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates37<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39>\nstruct Templates39 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates38<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40>\nstruct Templates40 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates39<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41>\nstruct Templates41 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates40<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42>\nstruct Templates42 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates41<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43>\nstruct Templates43 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates42<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n      T43> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44>\nstruct Templates44 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates43<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n      T43, T44> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45>\nstruct Templates45 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates44<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n      T43, T44, T45> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,\n    GTEST_TEMPLATE_ T46>\nstruct Templates46 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates45<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n      T43, T44, T45, T46> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,\n    GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47>\nstruct Templates47 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates46<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n      T43, T44, T45, T46, T47> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,\n    GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48>\nstruct Templates48 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates47<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n      T43, T44, T45, T46, T47, T48> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,\n    GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48,\n    GTEST_TEMPLATE_ T49>\nstruct Templates49 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates48<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n      T43, T44, T45, T46, T47, T48, T49> Tail;\n};\n\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,\n    GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48,\n    GTEST_TEMPLATE_ T49, GTEST_TEMPLATE_ T50>\nstruct Templates50 {\n  typedef TemplateSel<T1> Head;\n  typedef Templates49<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n      T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n      T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n      T43, T44, T45, T46, T47, T48, T49, T50> Tail;\n};\n\n\n// We don't want to require the users to write TemplatesN<...> directly,\n// as that would require them to count the length.  Templates<...> is much\n// easier to write, but generates horrible messages when there is a\n// compiler error, as gcc insists on printing out each template\n// argument, even if it has the default value (this means Templates<list>\n// will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler\n// errors).\n//\n// Our solution is to combine the best part of the two approaches: a\n// user would write Templates<T1, ..., TN>, and Google Test will translate\n// that to TemplatesN<T1, ..., TN> internally to make error messages\n// readable.  The translation is done by the 'type' member of the\n// Templates template.\ntemplate <GTEST_TEMPLATE_ T1 = NoneT, GTEST_TEMPLATE_ T2 = NoneT,\n    GTEST_TEMPLATE_ T3 = NoneT, GTEST_TEMPLATE_ T4 = NoneT,\n    GTEST_TEMPLATE_ T5 = NoneT, GTEST_TEMPLATE_ T6 = NoneT,\n    GTEST_TEMPLATE_ T7 = NoneT, GTEST_TEMPLATE_ T8 = NoneT,\n    GTEST_TEMPLATE_ T9 = NoneT, GTEST_TEMPLATE_ T10 = NoneT,\n    GTEST_TEMPLATE_ T11 = NoneT, GTEST_TEMPLATE_ T12 = NoneT,\n    GTEST_TEMPLATE_ T13 = NoneT, GTEST_TEMPLATE_ T14 = NoneT,\n    GTEST_TEMPLATE_ T15 = NoneT, GTEST_TEMPLATE_ T16 = NoneT,\n    GTEST_TEMPLATE_ T17 = NoneT, GTEST_TEMPLATE_ T18 = NoneT,\n    GTEST_TEMPLATE_ T19 = NoneT, GTEST_TEMPLATE_ T20 = NoneT,\n    GTEST_TEMPLATE_ T21 = NoneT, GTEST_TEMPLATE_ T22 = NoneT,\n    GTEST_TEMPLATE_ T23 = NoneT, GTEST_TEMPLATE_ T24 = NoneT,\n    GTEST_TEMPLATE_ T25 = NoneT, GTEST_TEMPLATE_ T26 = NoneT,\n    GTEST_TEMPLATE_ T27 = NoneT, GTEST_TEMPLATE_ T28 = NoneT,\n    GTEST_TEMPLATE_ T29 = NoneT, GTEST_TEMPLATE_ T30 = NoneT,\n    GTEST_TEMPLATE_ T31 = NoneT, GTEST_TEMPLATE_ T32 = NoneT,\n    GTEST_TEMPLATE_ T33 = NoneT, GTEST_TEMPLATE_ T34 = NoneT,\n    GTEST_TEMPLATE_ T35 = NoneT, GTEST_TEMPLATE_ T36 = NoneT,\n    GTEST_TEMPLATE_ T37 = NoneT, GTEST_TEMPLATE_ T38 = NoneT,\n    GTEST_TEMPLATE_ T39 = NoneT, GTEST_TEMPLATE_ T40 = NoneT,\n    GTEST_TEMPLATE_ T41 = NoneT, GTEST_TEMPLATE_ T42 = NoneT,\n    GTEST_TEMPLATE_ T43 = NoneT, GTEST_TEMPLATE_ T44 = NoneT,\n    GTEST_TEMPLATE_ T45 = NoneT, GTEST_TEMPLATE_ T46 = NoneT,\n    GTEST_TEMPLATE_ T47 = NoneT, GTEST_TEMPLATE_ T48 = NoneT,\n    GTEST_TEMPLATE_ T49 = NoneT, GTEST_TEMPLATE_ T50 = NoneT>\nstruct Templates {\n  typedef Templates50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42, T43, T44, T45, T46, T47, T48, T49, T50> type;\n};\n\ntemplate <>\nstruct Templates<NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT> {\n  typedef Templates0 type;\n};\ntemplate <GTEST_TEMPLATE_ T1>\nstruct Templates<T1, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT> {\n  typedef Templates1<T1> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2>\nstruct Templates<T1, T2, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT> {\n  typedef Templates2<T1, T2> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3>\nstruct Templates<T1, T2, T3, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates3<T1, T2, T3> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4>\nstruct Templates<T1, T2, T3, T4, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates4<T1, T2, T3, T4> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5>\nstruct Templates<T1, T2, T3, T4, T5, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates5<T1, T2, T3, T4, T5> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6>\nstruct Templates<T1, T2, T3, T4, T5, T6, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates6<T1, T2, T3, T4, T5, T6> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates7<T1, T2, T3, T4, T5, T6, T7> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates8<T1, T2, T3, T4, T5, T6, T7, T8> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates9<T1, T2, T3, T4, T5, T6, T7, T8, T9> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT> {\n  typedef Templates22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT> {\n  typedef Templates23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT> {\n  typedef Templates24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT> {\n  typedef Templates25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT> {\n  typedef Templates26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT> {\n  typedef Templates27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT> {\n  typedef Templates28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT> {\n  typedef Templates29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, NoneT, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, NoneT, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, NoneT, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, NoneT, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, NoneT,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42, T43> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,\n    NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42, T43, T44> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,\n    T45, NoneT, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42, T43, T44, T45> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,\n    GTEST_TEMPLATE_ T46>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,\n    T45, T46, NoneT, NoneT, NoneT, NoneT> {\n  typedef Templates46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42, T43, T44, T45, T46> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,\n    GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,\n    T45, T46, T47, NoneT, NoneT, NoneT> {\n  typedef Templates47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42, T43, T44, T45, T46, T47> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,\n    GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,\n    T45, T46, T47, T48, NoneT, NoneT> {\n  typedef Templates48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42, T43, T44, T45, T46, T47, T48> type;\n};\ntemplate <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,\n    GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,\n    GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,\n    GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,\n    GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,\n    GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,\n    GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,\n    GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,\n    GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,\n    GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,\n    GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,\n    GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,\n    GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,\n    GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,\n    GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,\n    GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48,\n    GTEST_TEMPLATE_ T49>\nstruct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,\n    T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,\n    T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,\n    T45, T46, T47, T48, T49, NoneT> {\n  typedef Templates49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n      T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n      T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n      T42, T43, T44, T45, T46, T47, T48, T49> type;\n};\n\n// The TypeList template makes it possible to use either a single type\n// or a Types<...> list in TYPED_TEST_CASE() and\n// INSTANTIATE_TYPED_TEST_CASE_P().\n\ntemplate <typename T>\nstruct TypeList { typedef Types1<T> type; };\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48, typename T49, typename T50>\nstruct TypeList<Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    T44, T45, T46, T47, T48, T49, T50> > {\n  typedef typename Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n      T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n      T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n      T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>::type type;\n};\n\n#endif  // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P\n\n}  // namespace internal\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_\n\n// Due to C++ preprocessor weirdness, we need double indirection to\n// concatenate two tokens when one of them is __LINE__.  Writing\n//\n//   foo ## __LINE__\n//\n// will result in the token foo__LINE__, instead of foo followed by\n// the current line number.  For more details, see\n// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6\n#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)\n#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar\n\n// Google Test defines the testing::Message class to allow construction of\n// test messages via the << operator.  The idea is that anything\n// streamable to std::ostream can be streamed to a testing::Message.\n// This allows a user to use his own types in Google Test assertions by\n// overloading the << operator.\n//\n// util/gtl/stl_logging-inl.h overloads << for STL containers.  These\n// overloads cannot be defined in the std namespace, as that will be\n// undefined behavior.  Therefore, they are defined in the global\n// namespace instead.\n//\n// C++'s symbol lookup rule (i.e. Koenig lookup) says that these\n// overloads are visible in either the std namespace or the global\n// namespace, but not other namespaces, including the testing\n// namespace which Google Test's Message class is in.\n//\n// To allow STL containers (and other types that has a << operator\n// defined in the global namespace) to be used in Google Test assertions,\n// testing::Message must access the custom << operator from the global\n// namespace.  Hence this helper function.\n//\n// Note: Jeffrey Yasskin suggested an alternative fix by \"using\n// ::operator<<;\" in the definition of Message's operator<<.  That fix\n// doesn't require a helper function, but unfortunately doesn't\n// compile with MSVC.\ntemplate <typename T>\ninline void GTestStreamToHelper(std::ostream* os, const T& val) {\n  *os << val;\n}\n\nclass ProtocolMessage;\nnamespace proto2 { class Message; }\n\nnamespace testing {\n\n// Forward declarations.\n\nclass AssertionResult;                 // Result of an assertion.\nclass Message;                         // Represents a failure message.\nclass Test;                            // Represents a test.\nclass TestInfo;                        // Information about a test.\nclass TestPartResult;                  // Result of a test part.\nclass UnitTest;                        // A collection of test cases.\n\ntemplate <typename T>\n::std::string PrintToString(const T& value);\n\nnamespace internal {\n\nstruct TraceInfo;                      // Information about a trace point.\nclass ScopedTrace;                     // Implements scoped trace.\nclass TestInfoImpl;                    // Opaque implementation of TestInfo\nclass UnitTestImpl;                    // Opaque implementation of UnitTest\n\n// How many times InitGoogleTest() has been called.\nextern int g_init_gtest_count;\n\n// The text used in failure messages to indicate the start of the\n// stack trace.\nGTEST_API_ extern const char kStackTraceMarker[];\n\n// A secret type that Google Test users don't know about.  It has no\n// definition on purpose.  Therefore it's impossible to create a\n// Secret object, which is what we want.\nclass Secret;\n\n// Two overloaded helpers for checking at compile time whether an\n// expression is a null pointer literal (i.e. NULL or any 0-valued\n// compile-time integral constant).  Their return values have\n// different sizes, so we can use sizeof() to test which version is\n// picked by the compiler.  These helpers have no implementations, as\n// we only need their signatures.\n//\n// Given IsNullLiteralHelper(x), the compiler will pick the first\n// version if x can be implicitly converted to Secret*, and pick the\n// second version otherwise.  Since Secret is a secret and incomplete\n// type, the only expression a user can write that has type Secret* is\n// a null pointer literal.  Therefore, we know that x is a null\n// pointer literal if and only if the first version is picked by the\n// compiler.\nchar IsNullLiteralHelper(Secret* p);\nchar (&IsNullLiteralHelper(...))[2];  // NOLINT\n\n// A compile-time bool constant that is true if and only if x is a\n// null pointer literal (i.e. NULL or any 0-valued compile-time\n// integral constant).\n#ifdef GTEST_ELLIPSIS_NEEDS_POD_\n// We lose support for NULL detection where the compiler doesn't like\n// passing non-POD classes through ellipsis (...).\n# define GTEST_IS_NULL_LITERAL_(x) false\n#else\n# define GTEST_IS_NULL_LITERAL_(x) \\\n    (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)\n#endif  // GTEST_ELLIPSIS_NEEDS_POD_\n\n// Appends the user-supplied message to the Google-Test-generated message.\nGTEST_API_ String AppendUserMessage(const String& gtest_msg,\n                                    const Message& user_msg);\n\n// A helper class for creating scoped traces in user programs.\nclass GTEST_API_ ScopedTrace {\n public:\n  // The c'tor pushes the given source file location and message onto\n  // a trace stack maintained by Google Test.\n  ScopedTrace(const char* file, int line, const Message& message);\n\n  // The d'tor pops the info pushed by the c'tor.\n  //\n  // Note that the d'tor is not virtual in order to be efficient.\n  // Don't inherit from ScopedTrace!\n  ~ScopedTrace();\n\n private:\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);\n} GTEST_ATTRIBUTE_UNUSED_;  // A ScopedTrace object does its job in its\n                            // c'tor and d'tor.  Therefore it doesn't\n                            // need to be used otherwise.\n\n// Converts a streamable value to a String.  A NULL pointer is\n// converted to \"(null)\".  When the input value is a ::string,\n// ::std::string, ::wstring, or ::std::wstring object, each NUL\n// character in it is replaced with \"\\\\0\".\n// Declared here but defined in gtest.h, so that it has access\n// to the definition of the Message class, required by the ARM\n// compiler.\ntemplate <typename T>\nString StreamableToString(const T& streamable);\n\n// The Symbian compiler has a bug that prevents it from selecting the\n// correct overload of FormatForComparisonFailureMessage (see below)\n// unless we pass the first argument by reference.  If we do that,\n// however, Visual Age C++ 10.1 generates a compiler error.  Therefore\n// we only apply the work-around for Symbian.\n#if defined(__SYMBIAN32__)\n# define GTEST_CREF_WORKAROUND_ const&\n#else\n# define GTEST_CREF_WORKAROUND_\n#endif\n\n// When this operand is a const char* or char*, if the other operand\n// is a ::std::string or ::string, we print this operand as a C string\n// rather than a pointer (we do the same for wide strings); otherwise\n// we print it as a pointer to be safe.\n\n// This internal macro is used to avoid duplicated code.\n#define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\\\ninline String FormatForComparisonFailureMessage(\\\n    operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \\\n    const operand2_type& /*operand2*/) {\\\n  return operand1_printer(str);\\\n}\\\ninline String FormatForComparisonFailureMessage(\\\n    const operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \\\n    const operand2_type& /*operand2*/) {\\\n  return operand1_printer(str);\\\n}\n\nGTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted)\n#if GTEST_HAS_STD_WSTRING\nGTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted)\n#endif  // GTEST_HAS_STD_WSTRING\n\n#if GTEST_HAS_GLOBAL_STRING\nGTEST_FORMAT_IMPL_(::string, String::ShowCStringQuoted)\n#endif  // GTEST_HAS_GLOBAL_STRING\n#if GTEST_HAS_GLOBAL_WSTRING\nGTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted)\n#endif  // GTEST_HAS_GLOBAL_WSTRING\n\n#undef GTEST_FORMAT_IMPL_\n\n// The next four overloads handle the case where the operand being\n// printed is a char/wchar_t pointer and the other operand is not a\n// string/wstring object.  In such cases, we just print the operand as\n// a pointer to be safe.\n#define GTEST_FORMAT_CHAR_PTR_IMPL_(CharType)                       \\\n  template <typename T>                                             \\\n  String FormatForComparisonFailureMessage(CharType* GTEST_CREF_WORKAROUND_ p, \\\n                                           const T&) { \\\n    return PrintToString(static_cast<const void*>(p));              \\\n  }\n\nGTEST_FORMAT_CHAR_PTR_IMPL_(char)\nGTEST_FORMAT_CHAR_PTR_IMPL_(const char)\nGTEST_FORMAT_CHAR_PTR_IMPL_(wchar_t)\nGTEST_FORMAT_CHAR_PTR_IMPL_(const wchar_t)\n\n#undef GTEST_FORMAT_CHAR_PTR_IMPL_\n\n// Constructs and returns the message for an equality assertion\n// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.\n//\n// The first four parameters are the expressions used in the assertion\n// and their values, as strings.  For example, for ASSERT_EQ(foo, bar)\n// where foo is 5 and bar is 6, we have:\n//\n//   expected_expression: \"foo\"\n//   actual_expression:   \"bar\"\n//   expected_value:      \"5\"\n//   actual_value:        \"6\"\n//\n// The ignoring_case parameter is true iff the assertion is a\n// *_STRCASEEQ*.  When it's true, the string \" (ignoring case)\" will\n// be inserted into the message.\nGTEST_API_ AssertionResult EqFailure(const char* expected_expression,\n                                     const char* actual_expression,\n                                     const String& expected_value,\n                                     const String& actual_value,\n                                     bool ignoring_case);\n\n// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.\nGTEST_API_ String GetBoolAssertionFailureMessage(\n    const AssertionResult& assertion_result,\n    const char* expression_text,\n    const char* actual_predicate_value,\n    const char* expected_predicate_value);\n\n// This template class represents an IEEE floating-point number\n// (either single-precision or double-precision, depending on the\n// template parameters).\n//\n// The purpose of this class is to do more sophisticated number\n// comparison.  (Due to round-off error, etc, it's very unlikely that\n// two floating-points will be equal exactly.  Hence a naive\n// comparison by the == operation often doesn't work.)\n//\n// Format of IEEE floating-point:\n//\n//   The most-significant bit being the leftmost, an IEEE\n//   floating-point looks like\n//\n//     sign_bit exponent_bits fraction_bits\n//\n//   Here, sign_bit is a single bit that designates the sign of the\n//   number.\n//\n//   For float, there are 8 exponent bits and 23 fraction bits.\n//\n//   For double, there are 11 exponent bits and 52 fraction bits.\n//\n//   More details can be found at\n//   http://en.wikipedia.org/wiki/IEEE_floating-point_standard.\n//\n// Template parameter:\n//\n//   RawType: the raw floating-point type (either float or double)\ntemplate <typename RawType>\nclass FloatingPoint {\n public:\n  // Defines the unsigned integer type that has the same size as the\n  // floating point number.\n  typedef typename TypeWithSize<sizeof(RawType)>::UInt Bits;\n\n  // Constants.\n\n  // # of bits in a number.\n  static const size_t kBitCount = 8*sizeof(RawType);\n\n  // # of fraction bits in a number.\n  static const size_t kFractionBitCount =\n    std::numeric_limits<RawType>::digits - 1;\n\n  // # of exponent bits in a number.\n  static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;\n\n  // The mask for the sign bit.\n  static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1);\n\n  // The mask for the fraction bits.\n  static const Bits kFractionBitMask =\n    ~static_cast<Bits>(0) >> (kExponentBitCount + 1);\n\n  // The mask for the exponent bits.\n  static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);\n\n  // How many ULP's (Units in the Last Place) we want to tolerate when\n  // comparing two numbers.  The larger the value, the more error we\n  // allow.  A 0 value means that two numbers must be exactly the same\n  // to be considered equal.\n  //\n  // The maximum error of a single floating-point operation is 0.5\n  // units in the last place.  On Intel CPU's, all floating-point\n  // calculations are done with 80-bit precision, while double has 64\n  // bits.  Therefore, 4 should be enough for ordinary use.\n  //\n  // See the following article for more details on ULP:\n  // http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm.\n  static const size_t kMaxUlps = 4;\n\n  // Constructs a FloatingPoint from a raw floating-point number.\n  //\n  // On an Intel CPU, passing a non-normalized NAN (Not a Number)\n  // around may change its bits, although the new value is guaranteed\n  // to be also a NAN.  Therefore, don't expect this constructor to\n  // preserve the bits in x when x is a NAN.\n  explicit FloatingPoint(const RawType& x) { u_.value_ = x; }\n\n  // Static methods\n\n  // Reinterprets a bit pattern as a floating-point number.\n  //\n  // This function is needed to test the AlmostEquals() method.\n  static RawType ReinterpretBits(const Bits bits) {\n    FloatingPoint fp(0);\n    fp.u_.bits_ = bits;\n    return fp.u_.value_;\n  }\n\n  // Returns the floating-point number that represent positive infinity.\n  static RawType Infinity() {\n    return ReinterpretBits(kExponentBitMask);\n  }\n\n  // Non-static methods\n\n  // Returns the bits that represents this number.\n  const Bits &bits() const { return u_.bits_; }\n\n  // Returns the exponent bits of this number.\n  Bits exponent_bits() const { return kExponentBitMask & u_.bits_; }\n\n  // Returns the fraction bits of this number.\n  Bits fraction_bits() const { return kFractionBitMask & u_.bits_; }\n\n  // Returns the sign bit of this number.\n  Bits sign_bit() const { return kSignBitMask & u_.bits_; }\n\n  // Returns true iff this is NAN (not a number).\n  bool is_nan() const {\n    // It's a NAN if the exponent bits are all ones and the fraction\n    // bits are not entirely zeros.\n    return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);\n  }\n\n  // Returns true iff this number is at most kMaxUlps ULP's away from\n  // rhs.  In particular, this function:\n  //\n  //   - returns false if either number is (or both are) NAN.\n  //   - treats really large numbers as almost equal to infinity.\n  //   - thinks +0.0 and -0.0 are 0 DLP's apart.\n  bool AlmostEquals(const FloatingPoint& rhs) const {\n    // The IEEE standard says that any comparison operation involving\n    // a NAN must return false.\n    if (is_nan() || rhs.is_nan()) return false;\n\n    return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)\n        <= kMaxUlps;\n  }\n\n private:\n  // The data type used to store the actual floating-point number.\n  union FloatingPointUnion {\n    RawType value_;  // The raw floating-point number.\n    Bits bits_;      // The bits that represent the number.\n  };\n\n  // Converts an integer from the sign-and-magnitude representation to\n  // the biased representation.  More precisely, let N be 2 to the\n  // power of (kBitCount - 1), an integer x is represented by the\n  // unsigned number x + N.\n  //\n  // For instance,\n  //\n  //   -N + 1 (the most negative number representable using\n  //          sign-and-magnitude) is represented by 1;\n  //   0      is represented by N; and\n  //   N - 1  (the biggest number representable using\n  //          sign-and-magnitude) is represented by 2N - 1.\n  //\n  // Read http://en.wikipedia.org/wiki/Signed_number_representations\n  // for more details on signed number representations.\n  static Bits SignAndMagnitudeToBiased(const Bits &sam) {\n    if (kSignBitMask & sam) {\n      // sam represents a negative number.\n      return ~sam + 1;\n    } else {\n      // sam represents a positive number.\n      return kSignBitMask | sam;\n    }\n  }\n\n  // Given two numbers in the sign-and-magnitude representation,\n  // returns the distance between them as an unsigned number.\n  static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1,\n                                                     const Bits &sam2) {\n    const Bits biased1 = SignAndMagnitudeToBiased(sam1);\n    const Bits biased2 = SignAndMagnitudeToBiased(sam2);\n    return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);\n  }\n\n  FloatingPointUnion u_;\n};\n\n// Typedefs the instances of the FloatingPoint template class that we\n// care to use.\ntypedef FloatingPoint<float> Float;\ntypedef FloatingPoint<double> Double;\n\n// In order to catch the mistake of putting tests that use different\n// test fixture classes in the same test case, we need to assign\n// unique IDs to fixture classes and compare them.  The TypeId type is\n// used to hold such IDs.  The user should treat TypeId as an opaque\n// type: the only operation allowed on TypeId values is to compare\n// them for equality using the == operator.\ntypedef const void* TypeId;\n\ntemplate <typename T>\nclass TypeIdHelper {\n public:\n  // dummy_ must not have a const type.  Otherwise an overly eager\n  // compiler (e.g. MSVC 7.1 & 8.0) may try to merge\n  // TypeIdHelper<T>::dummy_ for different Ts as an \"optimization\".\n  static bool dummy_;\n};\n\ntemplate <typename T>\nbool TypeIdHelper<T>::dummy_ = false;\n\n// GetTypeId<T>() returns the ID of type T.  Different values will be\n// returned for different types.  Calling the function twice with the\n// same type argument is guaranteed to return the same ID.\ntemplate <typename T>\nTypeId GetTypeId() {\n  // The compiler is required to allocate a different\n  // TypeIdHelper<T>::dummy_ variable for each T used to instantiate\n  // the template.  Therefore, the address of dummy_ is guaranteed to\n  // be unique.\n  return &(TypeIdHelper<T>::dummy_);\n}\n\n// Returns the type ID of ::testing::Test.  Always call this instead\n// of GetTypeId< ::testing::Test>() to get the type ID of\n// ::testing::Test, as the latter may give the wrong result due to a\n// suspected linker bug when compiling Google Test as a Mac OS X\n// framework.\nGTEST_API_ TypeId GetTestTypeId();\n\n// Defines the abstract factory interface that creates instances\n// of a Test object.\nclass TestFactoryBase {\n public:\n  virtual ~TestFactoryBase() {}\n\n  // Creates a test instance to run. The instance is both created and destroyed\n  // within TestInfoImpl::Run()\n  virtual Test* CreateTest() = 0;\n\n protected:\n  TestFactoryBase() {}\n\n private:\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase);\n};\n\n// This class provides implementation of TeastFactoryBase interface.\n// It is used in TEST and TEST_F macros.\ntemplate <class TestClass>\nclass TestFactoryImpl : public TestFactoryBase {\n public:\n  virtual Test* CreateTest() { return new TestClass; }\n};\n\n#if GTEST_OS_WINDOWS\n\n// Predicate-formatters for implementing the HRESULT checking macros\n// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}\n// We pass a long instead of HRESULT to avoid causing an\n// include dependency for the HRESULT type.\nGTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,\n                                            long hr);  // NOLINT\nGTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,\n                                            long hr);  // NOLINT\n\n#endif  // GTEST_OS_WINDOWS\n\n// Types of SetUpTestCase() and TearDownTestCase() functions.\ntypedef void (*SetUpTestCaseFunc)();\ntypedef void (*TearDownTestCaseFunc)();\n\n// Creates a new TestInfo object and registers it with Google Test;\n// returns the created object.\n//\n// Arguments:\n//\n//   test_case_name:   name of the test case\n//   name:             name of the test\n//   type_param        the name of the test's type parameter, or NULL if\n//                     this is not  a typed or a type-parameterized test.\n//   value_param       text representation of the test's value parameter,\n//                     or NULL if this is not a type-parameterized test.\n//   fixture_class_id: ID of the test fixture class\n//   set_up_tc:        pointer to the function that sets up the test case\n//   tear_down_tc:     pointer to the function that tears down the test case\n//   factory:          pointer to the factory that creates a test object.\n//                     The newly created TestInfo instance will assume\n//                     ownership of the factory object.\nGTEST_API_ TestInfo* MakeAndRegisterTestInfo(\n    const char* test_case_name, const char* name,\n    const char* type_param,\n    const char* value_param,\n    TypeId fixture_class_id,\n    SetUpTestCaseFunc set_up_tc,\n    TearDownTestCaseFunc tear_down_tc,\n    TestFactoryBase* factory);\n\n// If *pstr starts with the given prefix, modifies *pstr to be right\n// past the prefix and returns true; otherwise leaves *pstr unchanged\n// and returns false.  None of pstr, *pstr, and prefix can be NULL.\nGTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);\n\n#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P\n\n// State of the definition of a type-parameterized test case.\nclass GTEST_API_ TypedTestCasePState {\n public:\n  TypedTestCasePState() : registered_(false) {}\n\n  // Adds the given test name to defined_test_names_ and return true\n  // if the test case hasn't been registered; otherwise aborts the\n  // program.\n  bool AddTestName(const char* file, int line, const char* case_name,\n                   const char* test_name) {\n    if (registered_) {\n      fprintf(stderr, \"%s Test %s must be defined before \"\n              \"REGISTER_TYPED_TEST_CASE_P(%s, ...).\\n\",\n              FormatFileLocation(file, line).c_str(), test_name, case_name);\n      fflush(stderr);\n      posix::Abort();\n    }\n    defined_test_names_.insert(test_name);\n    return true;\n  }\n\n  // Verifies that registered_tests match the test names in\n  // defined_test_names_; returns registered_tests if successful, or\n  // aborts the program otherwise.\n  const char* VerifyRegisteredTestNames(\n      const char* file, int line, const char* registered_tests);\n\n private:\n  bool registered_;\n  ::std::set<const char*> defined_test_names_;\n};\n\n// Skips to the first non-space char after the first comma in 'str';\n// returns NULL if no comma is found in 'str'.\ninline const char* SkipComma(const char* str) {\n  const char* comma = strchr(str, ',');\n  if (comma == NULL) {\n    return NULL;\n  }\n  while (IsSpace(*(++comma))) {}\n  return comma;\n}\n\n// Returns the prefix of 'str' before the first comma in it; returns\n// the entire string if it contains no comma.\ninline String GetPrefixUntilComma(const char* str) {\n  const char* comma = strchr(str, ',');\n  return comma == NULL ? String(str) : String(str, comma - str);\n}\n\n// TypeParameterizedTest<Fixture, TestSel, Types>::Register()\n// registers a list of type-parameterized tests with Google Test.  The\n// return value is insignificant - we just need to return something\n// such that we can call this function in a namespace scope.\n//\n// Implementation note: The GTEST_TEMPLATE_ macro declares a template\n// template parameter.  It's defined in gtest-type-util.h.\ntemplate <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>\nclass TypeParameterizedTest {\n public:\n  // 'index' is the index of the test in the type list 'Types'\n  // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,\n  // Types).  Valid values for 'index' are [0, N - 1] where N is the\n  // length of Types.\n  static bool Register(const char* prefix, const char* case_name,\n                       const char* test_names, int index) {\n    typedef typename Types::Head Type;\n    typedef Fixture<Type> FixtureClass;\n    typedef typename GTEST_BIND_(TestSel, Type) TestClass;\n\n    // First, registers the first type-parameterized test in the type\n    // list.\n    MakeAndRegisterTestInfo(\n        String::Format(\"%s%s%s/%d\", prefix, prefix[0] == '\\0' ? \"\" : \"/\",\n                       case_name, index).c_str(),\n        GetPrefixUntilComma(test_names).c_str(),\n        GetTypeName<Type>().c_str(),\n        NULL,  // No value parameter.\n        GetTypeId<FixtureClass>(),\n        TestClass::SetUpTestCase,\n        TestClass::TearDownTestCase,\n        new TestFactoryImpl<TestClass>);\n\n    // Next, recurses (at compile time) with the tail of the type list.\n    return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>\n        ::Register(prefix, case_name, test_names, index + 1);\n  }\n};\n\n// The base case for the compile time recursion.\ntemplate <GTEST_TEMPLATE_ Fixture, class TestSel>\nclass TypeParameterizedTest<Fixture, TestSel, Types0> {\n public:\n  static bool Register(const char* /*prefix*/, const char* /*case_name*/,\n                       const char* /*test_names*/, int /*index*/) {\n    return true;\n  }\n};\n\n// TypeParameterizedTestCase<Fixture, Tests, Types>::Register()\n// registers *all combinations* of 'Tests' and 'Types' with Google\n// Test.  The return value is insignificant - we just need to return\n// something such that we can call this function in a namespace scope.\ntemplate <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>\nclass TypeParameterizedTestCase {\n public:\n  static bool Register(const char* prefix, const char* case_name,\n                       const char* test_names) {\n    typedef typename Tests::Head Head;\n\n    // First, register the first test in 'Test' for each type in 'Types'.\n    TypeParameterizedTest<Fixture, Head, Types>::Register(\n        prefix, case_name, test_names, 0);\n\n    // Next, recurses (at compile time) with the tail of the test list.\n    return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>\n        ::Register(prefix, case_name, SkipComma(test_names));\n  }\n};\n\n// The base case for the compile time recursion.\ntemplate <GTEST_TEMPLATE_ Fixture, typename Types>\nclass TypeParameterizedTestCase<Fixture, Templates0, Types> {\n public:\n  static bool Register(const char* /*prefix*/, const char* /*case_name*/,\n                       const char* /*test_names*/) {\n    return true;\n  }\n};\n\n#endif  // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P\n\n// Returns the current OS stack trace as a String.\n//\n// The maximum number of stack frames to be included is specified by\n// the gtest_stack_trace_depth flag.  The skip_count parameter\n// specifies the number of top frames to be skipped, which doesn't\n// count against the number of frames to be included.\n//\n// For example, if Foo() calls Bar(), which in turn calls\n// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in\n// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.\nGTEST_API_ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test,\n                                                  int skip_count);\n\n// Helpers for suppressing warnings on unreachable code or constant\n// condition.\n\n// Always returns true.\nGTEST_API_ bool AlwaysTrue();\n\n// Always returns false.\ninline bool AlwaysFalse() { return !AlwaysTrue(); }\n\n// Helper for suppressing false warning from Clang on a const char*\n// variable declared in a conditional expression always being NULL in\n// the else branch.\nstruct GTEST_API_ ConstCharPtr {\n  ConstCharPtr(const char* str) : value(str) {}\n  operator bool() const { return true; }\n  const char* value;\n};\n\n// A simple Linear Congruential Generator for generating random\n// numbers with a uniform distribution.  Unlike rand() and srand(), it\n// doesn't use global state (and therefore can't interfere with user\n// code).  Unlike rand_r(), it's portable.  An LCG isn't very random,\n// but it's good enough for our purposes.\nclass GTEST_API_ Random {\n public:\n  static const UInt32 kMaxRange = 1u << 31;\n\n  explicit Random(UInt32 seed) : state_(seed) {}\n\n  void Reseed(UInt32 seed) { state_ = seed; }\n\n  // Generates a random number from [0, range).  Crashes if 'range' is\n  // 0 or greater than kMaxRange.\n  UInt32 Generate(UInt32 range);\n\n private:\n  UInt32 state_;\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);\n};\n\n// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a\n// compiler error iff T1 and T2 are different types.\ntemplate <typename T1, typename T2>\nstruct CompileAssertTypesEqual;\n\ntemplate <typename T>\nstruct CompileAssertTypesEqual<T, T> {\n};\n\n// Removes the reference from a type if it is a reference type,\n// otherwise leaves it unchanged.  This is the same as\n// tr1::remove_reference, which is not widely available yet.\ntemplate <typename T>\nstruct RemoveReference { typedef T type; };  // NOLINT\ntemplate <typename T>\nstruct RemoveReference<T&> { typedef T type; };  // NOLINT\n\n// A handy wrapper around RemoveReference that works when the argument\n// T depends on template parameters.\n#define GTEST_REMOVE_REFERENCE_(T) \\\n    typename ::testing::internal::RemoveReference<T>::type\n\n// Removes const from a type if it is a const type, otherwise leaves\n// it unchanged.  This is the same as tr1::remove_const, which is not\n// widely available yet.\ntemplate <typename T>\nstruct RemoveConst { typedef T type; };  // NOLINT\ntemplate <typename T>\nstruct RemoveConst<const T> { typedef T type; };  // NOLINT\n\n// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above\n// definition to fail to remove the const in 'const int[3]' and 'const\n// char[3][4]'.  The following specialization works around the bug.\n// However, it causes trouble with GCC and thus needs to be\n// conditionally compiled.\n#if defined(_MSC_VER) || defined(__SUNPRO_CC) || defined(__IBMCPP__)\ntemplate <typename T, size_t N>\nstruct RemoveConst<const T[N]> {\n  typedef typename RemoveConst<T>::type type[N];\n};\n#endif\n\n// A handy wrapper around RemoveConst that works when the argument\n// T depends on template parameters.\n#define GTEST_REMOVE_CONST_(T) \\\n    typename ::testing::internal::RemoveConst<T>::type\n\n// Turns const U&, U&, const U, and U all into U.\n#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \\\n    GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))\n\n// Adds reference to a type if it is not a reference type,\n// otherwise leaves it unchanged.  This is the same as\n// tr1::add_reference, which is not widely available yet.\ntemplate <typename T>\nstruct AddReference { typedef T& type; };  // NOLINT\ntemplate <typename T>\nstruct AddReference<T&> { typedef T& type; };  // NOLINT\n\n// A handy wrapper around AddReference that works when the argument T\n// depends on template parameters.\n#define GTEST_ADD_REFERENCE_(T) \\\n    typename ::testing::internal::AddReference<T>::type\n\n// Adds a reference to const on top of T as necessary.  For example,\n// it transforms\n//\n//   char         ==> const char&\n//   const char   ==> const char&\n//   char&        ==> const char&\n//   const char&  ==> const char&\n//\n// The argument T must depend on some template parameters.\n#define GTEST_REFERENCE_TO_CONST_(T) \\\n    GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))\n\n// ImplicitlyConvertible<From, To>::value is a compile-time bool\n// constant that's true iff type From can be implicitly converted to\n// type To.\ntemplate <typename From, typename To>\nclass ImplicitlyConvertible {\n private:\n  // We need the following helper functions only for their types.\n  // They have no implementations.\n\n  // MakeFrom() is an expression whose type is From.  We cannot simply\n  // use From(), as the type From may not have a public default\n  // constructor.\n  static From MakeFrom();\n\n  // These two functions are overloaded.  Given an expression\n  // Helper(x), the compiler will pick the first version if x can be\n  // implicitly converted to type To; otherwise it will pick the\n  // second version.\n  //\n  // The first version returns a value of size 1, and the second\n  // version returns a value of size 2.  Therefore, by checking the\n  // size of Helper(x), which can be done at compile time, we can tell\n  // which version of Helper() is used, and hence whether x can be\n  // implicitly converted to type To.\n  static char Helper(To);\n  static char (&Helper(...))[2];  // NOLINT\n\n  // We have to put the 'public' section after the 'private' section,\n  // or MSVC refuses to compile the code.\n public:\n  // MSVC warns about implicitly converting from double to int for\n  // possible loss of data, so we need to temporarily disable the\n  // warning.\n#ifdef _MSC_VER\n# pragma warning(push)          // Saves the current warning state.\n# pragma warning(disable:4244)  // Temporarily disables warning 4244.\n\n  static const bool value =\n      sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;\n# pragma warning(pop)           // Restores the warning state.\n#elif defined(__BORLANDC__)\n  // C++Builder cannot use member overload resolution during template\n  // instantiation.  The simplest workaround is to use its C++0x type traits\n  // functions (C++Builder 2009 and above only).\n  static const bool value = __is_convertible(From, To);\n#else\n  static const bool value =\n      sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;\n#endif  // _MSV_VER\n};\ntemplate <typename From, typename To>\nconst bool ImplicitlyConvertible<From, To>::value;\n\n// IsAProtocolMessage<T>::value is a compile-time bool constant that's\n// true iff T is type ProtocolMessage, proto2::Message, or a subclass\n// of those.\ntemplate <typename T>\nstruct IsAProtocolMessage\n    : public bool_constant<\n  ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||\n  ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {\n};\n\n// When the compiler sees expression IsContainerTest<C>(0), if C is an\n// STL-style container class, the first overload of IsContainerTest\n// will be viable (since both C::iterator* and C::const_iterator* are\n// valid types and NULL can be implicitly converted to them).  It will\n// be picked over the second overload as 'int' is a perfect match for\n// the type of argument 0.  If C::iterator or C::const_iterator is not\n// a valid type, the first overload is not viable, and the second\n// overload will be picked.  Therefore, we can determine whether C is\n// a container class by checking the type of IsContainerTest<C>(0).\n// The value of the expression is insignificant.\n//\n// Note that we look for both C::iterator and C::const_iterator.  The\n// reason is that C++ injects the name of a class as a member of the\n// class itself (e.g. you can refer to class iterator as either\n// 'iterator' or 'iterator::iterator').  If we look for C::iterator\n// only, for example, we would mistakenly think that a class named\n// iterator is an STL container.\n//\n// Also note that the simpler approach of overloading\n// IsContainerTest(typename C::const_iterator*) and\n// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.\ntypedef int IsContainer;\ntemplate <class C>\nIsContainer IsContainerTest(int /* dummy */,\n                            typename C::iterator* /* it */ = NULL,\n                            typename C::const_iterator* /* const_it */ = NULL) {\n  return 0;\n}\n\ntypedef char IsNotContainer;\ntemplate <class C>\nIsNotContainer IsContainerTest(long /* dummy */) { return '\\0'; }\n\n// EnableIf<condition>::type is void when 'Cond' is true, and\n// undefined when 'Cond' is false.  To use SFINAE to make a function\n// overload only apply when a particular expression is true, add\n// \"typename EnableIf<expression>::type* = 0\" as the last parameter.\ntemplate<bool> struct EnableIf;\ntemplate<> struct EnableIf<true> { typedef void type; };  // NOLINT\n\n// Utilities for native arrays.\n\n// ArrayEq() compares two k-dimensional native arrays using the\n// elements' operator==, where k can be any integer >= 0.  When k is\n// 0, ArrayEq() degenerates into comparing a single pair of values.\n\ntemplate <typename T, typename U>\nbool ArrayEq(const T* lhs, size_t size, const U* rhs);\n\n// This generic version is used when k is 0.\ntemplate <typename T, typename U>\ninline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }\n\n// This overload is used when k >= 1.\ntemplate <typename T, typename U, size_t N>\ninline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {\n  return internal::ArrayEq(lhs, N, rhs);\n}\n\n// This helper reduces code bloat.  If we instead put its logic inside\n// the previous ArrayEq() function, arrays with different sizes would\n// lead to different copies of the template code.\ntemplate <typename T, typename U>\nbool ArrayEq(const T* lhs, size_t size, const U* rhs) {\n  for (size_t i = 0; i != size; i++) {\n    if (!internal::ArrayEq(lhs[i], rhs[i]))\n      return false;\n  }\n  return true;\n}\n\n// Finds the first element in the iterator range [begin, end) that\n// equals elem.  Element may be a native array type itself.\ntemplate <typename Iter, typename Element>\nIter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {\n  for (Iter it = begin; it != end; ++it) {\n    if (internal::ArrayEq(*it, elem))\n      return it;\n  }\n  return end;\n}\n\n// CopyArray() copies a k-dimensional native array using the elements'\n// operator=, where k can be any integer >= 0.  When k is 0,\n// CopyArray() degenerates into copying a single value.\n\ntemplate <typename T, typename U>\nvoid CopyArray(const T* from, size_t size, U* to);\n\n// This generic version is used when k is 0.\ntemplate <typename T, typename U>\ninline void CopyArray(const T& from, U* to) { *to = from; }\n\n// This overload is used when k >= 1.\ntemplate <typename T, typename U, size_t N>\ninline void CopyArray(const T(&from)[N], U(*to)[N]) {\n  internal::CopyArray(from, N, *to);\n}\n\n// This helper reduces code bloat.  If we instead put its logic inside\n// the previous CopyArray() function, arrays with different sizes\n// would lead to different copies of the template code.\ntemplate <typename T, typename U>\nvoid CopyArray(const T* from, size_t size, U* to) {\n  for (size_t i = 0; i != size; i++) {\n    internal::CopyArray(from[i], to + i);\n  }\n}\n\n// The relation between an NativeArray object (see below) and the\n// native array it represents.\nenum RelationToSource {\n  kReference,  // The NativeArray references the native array.\n  kCopy        // The NativeArray makes a copy of the native array and\n               // owns the copy.\n};\n\n// Adapts a native array to a read-only STL-style container.  Instead\n// of the complete STL container concept, this adaptor only implements\n// members useful for Google Mock's container matchers.  New members\n// should be added as needed.  To simplify the implementation, we only\n// support Element being a raw type (i.e. having no top-level const or\n// reference modifier).  It's the client's responsibility to satisfy\n// this requirement.  Element can be an array type itself (hence\n// multi-dimensional arrays are supported).\ntemplate <typename Element>\nclass NativeArray {\n public:\n  // STL-style container typedefs.\n  typedef Element value_type;\n  typedef Element* iterator;\n  typedef const Element* const_iterator;\n\n  // Constructs from a native array.\n  NativeArray(const Element* array, size_t count, RelationToSource relation) {\n    Init(array, count, relation);\n  }\n\n  // Copy constructor.\n  NativeArray(const NativeArray& rhs) {\n    Init(rhs.array_, rhs.size_, rhs.relation_to_source_);\n  }\n\n  ~NativeArray() {\n    // Ensures that the user doesn't instantiate NativeArray with a\n    // const or reference type.\n    static_cast<void>(StaticAssertTypeEqHelper<Element,\n        GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>());\n    if (relation_to_source_ == kCopy)\n      delete[] array_;\n  }\n\n  // STL-style container methods.\n  size_t size() const { return size_; }\n  const_iterator begin() const { return array_; }\n  const_iterator end() const { return array_ + size_; }\n  bool operator==(const NativeArray& rhs) const {\n    return size() == rhs.size() &&\n        ArrayEq(begin(), size(), rhs.begin());\n  }\n\n private:\n  // Initializes this object; makes a copy of the input array if\n  // 'relation' is kCopy.\n  void Init(const Element* array, size_t a_size, RelationToSource relation) {\n    if (relation == kReference) {\n      array_ = array;\n    } else {\n      Element* const copy = new Element[a_size];\n      CopyArray(array, a_size, copy);\n      array_ = copy;\n    }\n    size_ = a_size;\n    relation_to_source_ = relation;\n  }\n\n  const Element* array_;\n  size_t size_;\n  RelationToSource relation_to_source_;\n\n  GTEST_DISALLOW_ASSIGN_(NativeArray);\n};\n\n}  // namespace internal\n}  // namespace testing\n\n#define GTEST_MESSAGE_AT_(file, line, message, result_type) \\\n  ::testing::internal::AssertHelper(result_type, file, line, message) \\\n    = ::testing::Message()\n\n#define GTEST_MESSAGE_(message, result_type) \\\n  GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)\n\n#define GTEST_FATAL_FAILURE_(message) \\\n  return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)\n\n#define GTEST_NONFATAL_FAILURE_(message) \\\n  GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)\n\n#define GTEST_SUCCESS_(message) \\\n  GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)\n\n// Suppresses MSVC warnings 4072 (unreachable code) for the code following\n// statement if it returns or throws (or doesn't return or throw in some\n// situations).\n#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \\\n  if (::testing::internal::AlwaysTrue()) { statement; }\n\n#define GTEST_TEST_THROW_(statement, expected_exception, fail) \\\n  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\\n  if (::testing::internal::ConstCharPtr gtest_msg = \"\") { \\\n    bool gtest_caught_expected = false; \\\n    try { \\\n      GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \\\n    } \\\n    catch (expected_exception const&) { \\\n      gtest_caught_expected = true; \\\n    } \\\n    catch (...) { \\\n      gtest_msg.value = \\\n          \"Expected: \" #statement \" throws an exception of type \" \\\n          #expected_exception \".\\n  Actual: it throws a different type.\"; \\\n      goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \\\n    } \\\n    if (!gtest_caught_expected) { \\\n      gtest_msg.value = \\\n          \"Expected: \" #statement \" throws an exception of type \" \\\n          #expected_exception \".\\n  Actual: it throws nothing.\"; \\\n      goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \\\n    } \\\n  } else \\\n    GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \\\n      fail(gtest_msg.value)\n\n#define GTEST_TEST_NO_THROW_(statement, fail) \\\n  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\\n  if (::testing::internal::AlwaysTrue()) { \\\n    try { \\\n      GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \\\n    } \\\n    catch (...) { \\\n      goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \\\n    } \\\n  } else \\\n    GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \\\n      fail(\"Expected: \" #statement \" doesn't throw an exception.\\n\" \\\n           \"  Actual: it throws.\")\n\n#define GTEST_TEST_ANY_THROW_(statement, fail) \\\n  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\\n  if (::testing::internal::AlwaysTrue()) { \\\n    bool gtest_caught_any = false; \\\n    try { \\\n      GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \\\n    } \\\n    catch (...) { \\\n      gtest_caught_any = true; \\\n    } \\\n    if (!gtest_caught_any) { \\\n      goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \\\n    } \\\n  } else \\\n    GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \\\n      fail(\"Expected: \" #statement \" throws an exception.\\n\" \\\n           \"  Actual: it doesn't.\")\n\n\n// Implements Boolean test assertions such as EXPECT_TRUE. expression can be\n// either a boolean expression or an AssertionResult. text is a textual\n// represenation of expression as it was passed into the EXPECT_TRUE.\n#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \\\n  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\\n  if (const ::testing::AssertionResult gtest_ar_ = \\\n      ::testing::AssertionResult(expression)) \\\n    ; \\\n  else \\\n    fail(::testing::internal::GetBoolAssertionFailureMessage(\\\n        gtest_ar_, text, #actual, #expected).c_str())\n\n#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \\\n  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\\n  if (::testing::internal::AlwaysTrue()) { \\\n    ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \\\n    GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \\\n    if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \\\n      goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \\\n    } \\\n  } else \\\n    GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \\\n      fail(\"Expected: \" #statement \" doesn't generate new fatal \" \\\n           \"failures in the current thread.\\n\" \\\n           \"  Actual: it does.\")\n\n// Expands to the name of the class that implements the given test.\n#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \\\n  test_case_name##_##test_name##_Test\n\n// Helper macro for defining tests.\n#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\\\nclass GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\\\n public:\\\n  GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\\\n private:\\\n  virtual void TestBody();\\\n  static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\\\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(\\\n      GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\\\n};\\\n\\\n::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\\\n  ::test_info_ =\\\n    ::testing::internal::MakeAndRegisterTestInfo(\\\n        #test_case_name, #test_name, NULL, NULL, \\\n        (parent_id), \\\n        parent_class::SetUpTestCase, \\\n        parent_class::TearDownTestCase, \\\n        new ::testing::internal::TestFactoryImpl<\\\n            GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\\\nvoid GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_\n// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n//\n// The Google C++ Testing Framework (Google Test)\n//\n// This header file defines the public API for death tests.  It is\n// #included by gtest.h so a user doesn't need to include this\n// directly.\n\n#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_\n#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_\n\n// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)\n//\n// The Google C++ Testing Framework (Google Test)\n//\n// This header file defines internal utilities needed for implementing\n// death tests.  They are subject to change without notice.\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_\n\n\n#include <stdio.h>\n\nnamespace testing {\nnamespace internal {\n\nGTEST_DECLARE_string_(internal_run_death_test);\n\n// Names of the flags (needed for parsing Google Test flags).\nconst char kDeathTestStyleFlag[] = \"death_test_style\";\nconst char kDeathTestUseFork[] = \"death_test_use_fork\";\nconst char kInternalRunDeathTestFlag[] = \"internal_run_death_test\";\n\n#if GTEST_HAS_DEATH_TEST\n\n// DeathTest is a class that hides much of the complexity of the\n// GTEST_DEATH_TEST_ macro.  It is abstract; its static Create method\n// returns a concrete class that depends on the prevailing death test\n// style, as defined by the --gtest_death_test_style and/or\n// --gtest_internal_run_death_test flags.\n\n// In describing the results of death tests, these terms are used with\n// the corresponding definitions:\n//\n// exit status:  The integer exit information in the format specified\n//               by wait(2)\n// exit code:    The integer code passed to exit(3), _exit(2), or\n//               returned from main()\nclass GTEST_API_ DeathTest {\n public:\n  // Create returns false if there was an error determining the\n  // appropriate action to take for the current death test; for example,\n  // if the gtest_death_test_style flag is set to an invalid value.\n  // The LastMessage method will return a more detailed message in that\n  // case.  Otherwise, the DeathTest pointer pointed to by the \"test\"\n  // argument is set.  If the death test should be skipped, the pointer\n  // is set to NULL; otherwise, it is set to the address of a new concrete\n  // DeathTest object that controls the execution of the current test.\n  static bool Create(const char* statement, const RE* regex,\n                     const char* file, int line, DeathTest** test);\n  DeathTest();\n  virtual ~DeathTest() { }\n\n  // A helper class that aborts a death test when it's deleted.\n  class ReturnSentinel {\n   public:\n    explicit ReturnSentinel(DeathTest* test) : test_(test) { }\n    ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }\n   private:\n    DeathTest* const test_;\n    GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel);\n  } GTEST_ATTRIBUTE_UNUSED_;\n\n  // An enumeration of possible roles that may be taken when a death\n  // test is encountered.  EXECUTE means that the death test logic should\n  // be executed immediately.  OVERSEE means that the program should prepare\n  // the appropriate environment for a child process to execute the death\n  // test, then wait for it to complete.\n  enum TestRole { OVERSEE_TEST, EXECUTE_TEST };\n\n  // An enumeration of the three reasons that a test might be aborted.\n  enum AbortReason {\n    TEST_ENCOUNTERED_RETURN_STATEMENT,\n    TEST_THREW_EXCEPTION,\n    TEST_DID_NOT_DIE\n  };\n\n  // Assumes one of the above roles.\n  virtual TestRole AssumeRole() = 0;\n\n  // Waits for the death test to finish and returns its status.\n  virtual int Wait() = 0;\n\n  // Returns true if the death test passed; that is, the test process\n  // exited during the test, its exit status matches a user-supplied\n  // predicate, and its stderr output matches a user-supplied regular\n  // expression.\n  // The user-supplied predicate may be a macro expression rather\n  // than a function pointer or functor, or else Wait and Passed could\n  // be combined.\n  virtual bool Passed(bool exit_status_ok) = 0;\n\n  // Signals that the death test did not die as expected.\n  virtual void Abort(AbortReason reason) = 0;\n\n  // Returns a human-readable outcome message regarding the outcome of\n  // the last death test.\n  static const char* LastMessage();\n\n  static void set_last_death_test_message(const String& message);\n\n private:\n  // A string containing a description of the outcome of the last death test.\n  static String last_death_test_message_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);\n};\n\n// Factory interface for death tests.  May be mocked out for testing.\nclass DeathTestFactory {\n public:\n  virtual ~DeathTestFactory() { }\n  virtual bool Create(const char* statement, const RE* regex,\n                      const char* file, int line, DeathTest** test) = 0;\n};\n\n// A concrete DeathTestFactory implementation for normal use.\nclass DefaultDeathTestFactory : public DeathTestFactory {\n public:\n  virtual bool Create(const char* statement, const RE* regex,\n                      const char* file, int line, DeathTest** test);\n};\n\n// Returns true if exit_status describes a process that was terminated\n// by a signal, or exited normally with a nonzero exit code.\nGTEST_API_ bool ExitedUnsuccessfully(int exit_status);\n\n// Traps C++ exceptions escaping statement and reports them as test\n// failures. Note that trapping SEH exceptions is not implemented here.\n# if GTEST_HAS_EXCEPTIONS\n#  define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \\\n  try { \\\n    GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \\\n  } catch (const ::std::exception& gtest_exception) { \\\n    fprintf(\\\n        stderr, \\\n        \"\\n%s: Caught std::exception-derived exception escaping the \" \\\n        \"death test statement. Exception message: %s\\n\", \\\n        ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \\\n        gtest_exception.what()); \\\n    fflush(stderr); \\\n    death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \\\n  } catch (...) { \\\n    death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \\\n  }\n\n# else\n#  define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \\\n  GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)\n\n# endif\n\n// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,\n// ASSERT_EXIT*, and EXPECT_EXIT*.\n# define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \\\n  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\\n  if (::testing::internal::AlwaysTrue()) { \\\n    const ::testing::internal::RE& gtest_regex = (regex); \\\n    ::testing::internal::DeathTest* gtest_dt; \\\n    if (!::testing::internal::DeathTest::Create(#statement, &gtest_regex, \\\n        __FILE__, __LINE__, &gtest_dt)) { \\\n      goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \\\n    } \\\n    if (gtest_dt != NULL) { \\\n      ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \\\n          gtest_dt_ptr(gtest_dt); \\\n      switch (gtest_dt->AssumeRole()) { \\\n        case ::testing::internal::DeathTest::OVERSEE_TEST: \\\n          if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \\\n            goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \\\n          } \\\n          break; \\\n        case ::testing::internal::DeathTest::EXECUTE_TEST: { \\\n          ::testing::internal::DeathTest::ReturnSentinel \\\n              gtest_sentinel(gtest_dt); \\\n          GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \\\n          gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \\\n          break; \\\n        } \\\n        default: \\\n          break; \\\n      } \\\n    } \\\n  } else \\\n    GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \\\n      fail(::testing::internal::DeathTest::LastMessage())\n// The symbol \"fail\" here expands to something into which a message\n// can be streamed.\n\n// A class representing the parsed contents of the\n// --gtest_internal_run_death_test flag, as it existed when\n// RUN_ALL_TESTS was called.\nclass InternalRunDeathTestFlag {\n public:\n  InternalRunDeathTestFlag(const String& a_file,\n                           int a_line,\n                           int an_index,\n                           int a_write_fd)\n      : file_(a_file), line_(a_line), index_(an_index),\n        write_fd_(a_write_fd) {}\n\n  ~InternalRunDeathTestFlag() {\n    if (write_fd_ >= 0)\n      posix::Close(write_fd_);\n  }\n\n  String file() const { return file_; }\n  int line() const { return line_; }\n  int index() const { return index_; }\n  int write_fd() const { return write_fd_; }\n\n private:\n  String file_;\n  int line_;\n  int index_;\n  int write_fd_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag);\n};\n\n// Returns a newly created InternalRunDeathTestFlag object with fields\n// initialized from the GTEST_FLAG(internal_run_death_test) flag if\n// the flag is specified; otherwise returns NULL.\nInternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();\n\n#else  // GTEST_HAS_DEATH_TEST\n\n// This macro is used for implementing macros such as\n// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where\n// death tests are not supported. Those macros must compile on such systems\n// iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on\n// systems that support death tests. This allows one to write such a macro\n// on a system that does not support death tests and be sure that it will\n// compile on a death-test supporting system.\n//\n// Parameters:\n//   statement -  A statement that a macro such as EXPECT_DEATH would test\n//                for program termination. This macro has to make sure this\n//                statement is compiled but not executed, to ensure that\n//                EXPECT_DEATH_IF_SUPPORTED compiles with a certain\n//                parameter iff EXPECT_DEATH compiles with it.\n//   regex     -  A regex that a macro such as EXPECT_DEATH would use to test\n//                the output of statement.  This parameter has to be\n//                compiled but not evaluated by this macro, to ensure that\n//                this macro only accepts expressions that a macro such as\n//                EXPECT_DEATH would accept.\n//   terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED\n//                and a return statement for ASSERT_DEATH_IF_SUPPORTED.\n//                This ensures that ASSERT_DEATH_IF_SUPPORTED will not\n//                compile inside functions where ASSERT_DEATH doesn't\n//                compile.\n//\n//  The branch that has an always false condition is used to ensure that\n//  statement and regex are compiled (and thus syntactically correct) but\n//  never executed. The unreachable code macro protects the terminator\n//  statement from generating an 'unreachable code' warning in case\n//  statement unconditionally returns or throws. The Message constructor at\n//  the end allows the syntax of streaming additional messages into the\n//  macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.\n# define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \\\n    GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\\n    if (::testing::internal::AlwaysTrue()) { \\\n      GTEST_LOG_(WARNING) \\\n          << \"Death tests are not supported on this platform.\\n\" \\\n          << \"Statement '\" #statement \"' cannot be verified.\"; \\\n    } else if (::testing::internal::AlwaysFalse()) { \\\n      ::testing::internal::RE::PartialMatch(\".*\", (regex)); \\\n      GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \\\n      terminator; \\\n    } else \\\n      ::testing::Message()\n\n#endif  // GTEST_HAS_DEATH_TEST\n\n}  // namespace internal\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_\n\nnamespace testing {\n\n// This flag controls the style of death tests.  Valid values are \"threadsafe\",\n// meaning that the death test child process will re-execute the test binary\n// from the start, running only a single death test, or \"fast\",\n// meaning that the child process will execute the test logic immediately\n// after forking.\nGTEST_DECLARE_string_(death_test_style);\n\n#if GTEST_HAS_DEATH_TEST\n\n// The following macros are useful for writing death tests.\n\n// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is\n// executed:\n//\n//   1. It generates a warning if there is more than one active\n//   thread.  This is because it's safe to fork() or clone() only\n//   when there is a single thread.\n//\n//   2. The parent process clone()s a sub-process and runs the death\n//   test in it; the sub-process exits with code 0 at the end of the\n//   death test, if it hasn't exited already.\n//\n//   3. The parent process waits for the sub-process to terminate.\n//\n//   4. The parent process checks the exit code and error message of\n//   the sub-process.\n//\n// Examples:\n//\n//   ASSERT_DEATH(server.SendMessage(56, \"Hello\"), \"Invalid port number\");\n//   for (int i = 0; i < 5; i++) {\n//     EXPECT_DEATH(server.ProcessRequest(i),\n//                  \"Invalid request .* in ProcessRequest()\")\n//         << \"Failed to die on request \" << i);\n//   }\n//\n//   ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), \"Exiting\");\n//\n//   bool KilledBySIGHUP(int exit_code) {\n//     return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP;\n//   }\n//\n//   ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, \"Hanging up!\");\n//\n// On the regular expressions used in death tests:\n//\n//   On POSIX-compliant systems (*nix), we use the <regex.h> library,\n//   which uses the POSIX extended regex syntax.\n//\n//   On other platforms (e.g. Windows), we only support a simple regex\n//   syntax implemented as part of Google Test.  This limited\n//   implementation should be enough most of the time when writing\n//   death tests; though it lacks many features you can find in PCRE\n//   or POSIX extended regex syntax.  For example, we don't support\n//   union (\"x|y\"), grouping (\"(xy)\"), brackets (\"[xy]\"), and\n//   repetition count (\"x{5,7}\"), among others.\n//\n//   Below is the syntax that we do support.  We chose it to be a\n//   subset of both PCRE and POSIX extended regex, so it's easy to\n//   learn wherever you come from.  In the following: 'A' denotes a\n//   literal character, period (.), or a single \\\\ escape sequence;\n//   'x' and 'y' denote regular expressions; 'm' and 'n' are for\n//   natural numbers.\n//\n//     c     matches any literal character c\n//     \\\\d   matches any decimal digit\n//     \\\\D   matches any character that's not a decimal digit\n//     \\\\f   matches \\f\n//     \\\\n   matches \\n\n//     \\\\r   matches \\r\n//     \\\\s   matches any ASCII whitespace, including \\n\n//     \\\\S   matches any character that's not a whitespace\n//     \\\\t   matches \\t\n//     \\\\v   matches \\v\n//     \\\\w   matches any letter, _, or decimal digit\n//     \\\\W   matches any character that \\\\w doesn't match\n//     \\\\c   matches any literal character c, which must be a punctuation\n//     .     matches any single character except \\n\n//     A?    matches 0 or 1 occurrences of A\n//     A*    matches 0 or many occurrences of A\n//     A+    matches 1 or many occurrences of A\n//     ^     matches the beginning of a string (not that of each line)\n//     $     matches the end of a string (not that of each line)\n//     xy    matches x followed by y\n//\n//   If you accidentally use PCRE or POSIX extended regex features\n//   not implemented by us, you will get a run-time failure.  In that\n//   case, please try to rewrite your regular expression within the\n//   above syntax.\n//\n//   This implementation is *not* meant to be as highly tuned or robust\n//   as a compiled regex library, but should perform well enough for a\n//   death test, which already incurs significant overhead by launching\n//   a child process.\n//\n// Known caveats:\n//\n//   A \"threadsafe\" style death test obtains the path to the test\n//   program from argv[0] and re-executes it in the sub-process.  For\n//   simplicity, the current implementation doesn't search the PATH\n//   when launching the sub-process.  This means that the user must\n//   invoke the test program via a path that contains at least one\n//   path separator (e.g. path/to/foo_test and\n//   /absolute/path/to/bar_test are fine, but foo_test is not).  This\n//   is rarely a problem as people usually don't put the test binary\n//   directory in PATH.\n//\n// TODO(wan@google.com): make thread-safe death tests search the PATH.\n\n// Asserts that a given statement causes the program to exit, with an\n// integer exit status that satisfies predicate, and emitting error output\n// that matches regex.\n# define ASSERT_EXIT(statement, predicate, regex) \\\n    GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)\n\n// Like ASSERT_EXIT, but continues on to successive tests in the\n// test case, if any:\n# define EXPECT_EXIT(statement, predicate, regex) \\\n    GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)\n\n// Asserts that a given statement causes the program to exit, either by\n// explicitly exiting with a nonzero exit code or being killed by a\n// signal, and emitting error output that matches regex.\n# define ASSERT_DEATH(statement, regex) \\\n    ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)\n\n// Like ASSERT_DEATH, but continues on to successive tests in the\n// test case, if any:\n# define EXPECT_DEATH(statement, regex) \\\n    EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)\n\n// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:\n\n// Tests that an exit code describes a normal exit with a given exit code.\nclass GTEST_API_ ExitedWithCode {\n public:\n  explicit ExitedWithCode(int exit_code);\n  bool operator()(int exit_status) const;\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ExitedWithCode& other);\n\n  const int exit_code_;\n};\n\n# if !GTEST_OS_WINDOWS\n// Tests that an exit code describes an exit due to termination by a\n// given signal.\nclass GTEST_API_ KilledBySignal {\n public:\n  explicit KilledBySignal(int signum);\n  bool operator()(int exit_status) const;\n private:\n  const int signum_;\n};\n# endif  // !GTEST_OS_WINDOWS\n\n// EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.\n// The death testing framework causes this to have interesting semantics,\n// since the sideeffects of the call are only visible in opt mode, and not\n// in debug mode.\n//\n// In practice, this can be used to test functions that utilize the\n// LOG(DFATAL) macro using the following style:\n//\n// int DieInDebugOr12(int* sideeffect) {\n//   if (sideeffect) {\n//     *sideeffect = 12;\n//   }\n//   LOG(DFATAL) << \"death\";\n//   return 12;\n// }\n//\n// TEST(TestCase, TestDieOr12WorksInDgbAndOpt) {\n//   int sideeffect = 0;\n//   // Only asserts in dbg.\n//   EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), \"death\");\n//\n// #ifdef NDEBUG\n//   // opt-mode has sideeffect visible.\n//   EXPECT_EQ(12, sideeffect);\n// #else\n//   // dbg-mode no visible sideeffect.\n//   EXPECT_EQ(0, sideeffect);\n// #endif\n// }\n//\n// This will assert that DieInDebugReturn12InOpt() crashes in debug\n// mode, usually due to a DCHECK or LOG(DFATAL), but returns the\n// appropriate fallback value (12 in this case) in opt mode. If you\n// need to test that a function has appropriate side-effects in opt\n// mode, include assertions against the side-effects.  A general\n// pattern for this is:\n//\n// EXPECT_DEBUG_DEATH({\n//   // Side-effects here will have an effect after this statement in\n//   // opt mode, but none in debug mode.\n//   EXPECT_EQ(12, DieInDebugOr12(&sideeffect));\n// }, \"death\");\n//\n# ifdef NDEBUG\n\n#  define EXPECT_DEBUG_DEATH(statement, regex) \\\n  do { statement; } while (::testing::internal::AlwaysFalse())\n\n#  define ASSERT_DEBUG_DEATH(statement, regex) \\\n  do { statement; } while (::testing::internal::AlwaysFalse())\n\n# else\n\n#  define EXPECT_DEBUG_DEATH(statement, regex) \\\n  EXPECT_DEATH(statement, regex)\n\n#  define ASSERT_DEBUG_DEATH(statement, regex) \\\n  ASSERT_DEATH(statement, regex)\n\n# endif  // NDEBUG for EXPECT_DEBUG_DEATH\n#endif  // GTEST_HAS_DEATH_TEST\n\n// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and\n// ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if\n// death tests are supported; otherwise they just issue a warning.  This is\n// useful when you are combining death test assertions with normal test\n// assertions in one test.\n#if GTEST_HAS_DEATH_TEST\n# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \\\n    EXPECT_DEATH(statement, regex)\n# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \\\n    ASSERT_DEATH(statement, regex)\n#else\n# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \\\n    GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, )\n# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \\\n    GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return)\n#endif\n\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_\n// Copyright 2005, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n//\n// The Google C++ Testing Framework (Google Test)\n//\n// This header file defines the Message class.\n//\n// IMPORTANT NOTE: Due to limitation of the C++ language, we have to\n// leave some internal implementation details in this header file.\n// They are clearly marked by comments like this:\n//\n//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\n//\n// Such code is NOT meant to be used by a user directly, and is subject\n// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user\n// program!\n\n#ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_\n#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_\n\n#include <limits>\n\n\nnamespace testing {\n\n// The Message class works like an ostream repeater.\n//\n// Typical usage:\n//\n//   1. You stream a bunch of values to a Message object.\n//      It will remember the text in a stringstream.\n//   2. Then you stream the Message object to an ostream.\n//      This causes the text in the Message to be streamed\n//      to the ostream.\n//\n// For example;\n//\n//   testing::Message foo;\n//   foo << 1 << \" != \" << 2;\n//   std::cout << foo;\n//\n// will print \"1 != 2\".\n//\n// Message is not intended to be inherited from.  In particular, its\n// destructor is not virtual.\n//\n// Note that stringstream behaves differently in gcc and in MSVC.  You\n// can stream a NULL char pointer to it in the former, but not in the\n// latter (it causes an access violation if you do).  The Message\n// class hides this difference by treating a NULL char pointer as\n// \"(null)\".\nclass GTEST_API_ Message {\n private:\n  // The type of basic IO manipulators (endl, ends, and flush) for\n  // narrow streams.\n  typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&);\n\n public:\n  // Constructs an empty Message.\n  // We allocate the stringstream separately because otherwise each use of\n  // ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's\n  // stack frame leading to huge stack frames in some cases; gcc does not reuse\n  // the stack space.\n  Message() : ss_(new ::std::stringstream) {\n    // By default, we want there to be enough precision when printing\n    // a double to a Message.\n    *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);\n  }\n\n  // Copy constructor.\n  Message(const Message& msg) : ss_(new ::std::stringstream) {  // NOLINT\n    *ss_ << msg.GetString();\n  }\n\n  // Constructs a Message from a C-string.\n  explicit Message(const char* str) : ss_(new ::std::stringstream) {\n    *ss_ << str;\n  }\n\n#if GTEST_OS_SYMBIAN\n  // Streams a value (either a pointer or not) to this object.\n  template <typename T>\n  inline Message& operator <<(const T& value) {\n    StreamHelper(typename internal::is_pointer<T>::type(), value);\n    return *this;\n  }\n#else\n  // Streams a non-pointer value to this object.\n  template <typename T>\n  inline Message& operator <<(const T& val) {\n    ::GTestStreamToHelper(ss_.get(), val);\n    return *this;\n  }\n\n  // Streams a pointer value to this object.\n  //\n  // This function is an overload of the previous one.  When you\n  // stream a pointer to a Message, this definition will be used as it\n  // is more specialized.  (The C++ Standard, section\n  // [temp.func.order].)  If you stream a non-pointer, then the\n  // previous definition will be used.\n  //\n  // The reason for this overload is that streaming a NULL pointer to\n  // ostream is undefined behavior.  Depending on the compiler, you\n  // may get \"0\", \"(nil)\", \"(null)\", or an access violation.  To\n  // ensure consistent result across compilers, we always treat NULL\n  // as \"(null)\".\n  template <typename T>\n  inline Message& operator <<(T* const& pointer) {  // NOLINT\n    if (pointer == NULL) {\n      *ss_ << \"(null)\";\n    } else {\n      ::GTestStreamToHelper(ss_.get(), pointer);\n    }\n    return *this;\n  }\n#endif  // GTEST_OS_SYMBIAN\n\n  // Since the basic IO manipulators are overloaded for both narrow\n  // and wide streams, we have to provide this specialized definition\n  // of operator <<, even though its body is the same as the\n  // templatized version above.  Without this definition, streaming\n  // endl or other basic IO manipulators to Message will confuse the\n  // compiler.\n  Message& operator <<(BasicNarrowIoManip val) {\n    *ss_ << val;\n    return *this;\n  }\n\n  // Instead of 1/0, we want to see true/false for bool values.\n  Message& operator <<(bool b) {\n    return *this << (b ? \"true\" : \"false\");\n  }\n\n  // These two overloads allow streaming a wide C string to a Message\n  // using the UTF-8 encoding.\n  Message& operator <<(const wchar_t* wide_c_str) {\n    return *this << internal::String::ShowWideCString(wide_c_str);\n  }\n  Message& operator <<(wchar_t* wide_c_str) {\n    return *this << internal::String::ShowWideCString(wide_c_str);\n  }\n\n#if GTEST_HAS_STD_WSTRING\n  // Converts the given wide string to a narrow string using the UTF-8\n  // encoding, and streams the result to this Message object.\n  Message& operator <<(const ::std::wstring& wstr);\n#endif  // GTEST_HAS_STD_WSTRING\n\n#if GTEST_HAS_GLOBAL_WSTRING\n  // Converts the given wide string to a narrow string using the UTF-8\n  // encoding, and streams the result to this Message object.\n  Message& operator <<(const ::wstring& wstr);\n#endif  // GTEST_HAS_GLOBAL_WSTRING\n\n  // Gets the text streamed to this object so far as a String.\n  // Each '\\0' character in the buffer is replaced with \"\\\\0\".\n  //\n  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\n  internal::String GetString() const {\n    return internal::StringStreamToString(ss_.get());\n  }\n\n private:\n\n#if GTEST_OS_SYMBIAN\n  // These are needed as the Nokia Symbian Compiler cannot decide between\n  // const T& and const T* in a function template. The Nokia compiler _can_\n  // decide between class template specializations for T and T*, so a\n  // tr1::type_traits-like is_pointer works, and we can overload on that.\n  template <typename T>\n  inline void StreamHelper(internal::true_type /*dummy*/, T* pointer) {\n    if (pointer == NULL) {\n      *ss_ << \"(null)\";\n    } else {\n      ::GTestStreamToHelper(ss_.get(), pointer);\n    }\n  }\n  template <typename T>\n  inline void StreamHelper(internal::false_type /*dummy*/, const T& value) {\n    ::GTestStreamToHelper(ss_.get(), value);\n  }\n#endif  // GTEST_OS_SYMBIAN\n\n  // We'll hold the text streamed to this object here.\n  const internal::scoped_ptr< ::std::stringstream> ss_;\n\n  // We declare (but don't implement) this to prevent the compiler\n  // from implementing the assignment operator.\n  void operator=(const Message&);\n};\n\n// Streams a Message to an ostream.\ninline std::ostream& operator <<(std::ostream& os, const Message& sb) {\n  return os << sb.GetString();\n}\n\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_\n// This file was GENERATED by command:\n//     pump.py gtest-param-test.h.pump\n// DO NOT EDIT BY HAND!!!\n\n// Copyright 2008, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Authors: vladl@google.com (Vlad Losev)\n//\n// Macros and functions for implementing parameterized tests\n// in Google C++ Testing Framework (Google Test)\n//\n// This file is generated by a SCRIPT.  DO NOT EDIT BY HAND!\n//\n#ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_\n#define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_\n\n\n// Value-parameterized tests allow you to test your code with different\n// parameters without writing multiple copies of the same test.\n//\n// Here is how you use value-parameterized tests:\n\n#if 0\n\n// To write value-parameterized tests, first you should define a fixture\n// class. It is usually derived from testing::TestWithParam<T> (see below for\n// another inheritance scheme that's sometimes useful in more complicated\n// class hierarchies), where the type of your parameter values.\n// TestWithParam<T> is itself derived from testing::Test. T can be any\n// copyable type. If it's a raw pointer, you are responsible for managing the\n// lifespan of the pointed values.\n\nclass FooTest : public ::testing::TestWithParam<const char*> {\n  // You can implement all the usual class fixture members here.\n};\n\n// Then, use the TEST_P macro to define as many parameterized tests\n// for this fixture as you want. The _P suffix is for \"parameterized\"\n// or \"pattern\", whichever you prefer to think.\n\nTEST_P(FooTest, DoesBlah) {\n  // Inside a test, access the test parameter with the GetParam() method\n  // of the TestWithParam<T> class:\n  EXPECT_TRUE(foo.Blah(GetParam()));\n  ...\n}\n\nTEST_P(FooTest, HasBlahBlah) {\n  ...\n}\n\n// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test\n// case with any set of parameters you want. Google Test defines a number\n// of functions for generating test parameters. They return what we call\n// (surprise!) parameter generators. Here is a  summary of them, which\n// are all in the testing namespace:\n//\n//\n//  Range(begin, end [, step]) - Yields values {begin, begin+step,\n//                               begin+step+step, ...}. The values do not\n//                               include end. step defaults to 1.\n//  Values(v1, v2, ..., vN)    - Yields values {v1, v2, ..., vN}.\n//  ValuesIn(container)        - Yields values from a C-style array, an STL\n//  ValuesIn(begin,end)          container, or an iterator range [begin, end).\n//  Bool()                     - Yields sequence {false, true}.\n//  Combine(g1, g2, ..., gN)   - Yields all combinations (the Cartesian product\n//                               for the math savvy) of the values generated\n//                               by the N generators.\n//\n// For more details, see comments at the definitions of these functions below\n// in this file.\n//\n// The following statement will instantiate tests from the FooTest test case\n// each with parameter values \"meeny\", \"miny\", and \"moe\".\n\nINSTANTIATE_TEST_CASE_P(InstantiationName,\n                        FooTest,\n                        Values(\"meeny\", \"miny\", \"moe\"));\n\n// To distinguish different instances of the pattern, (yes, you\n// can instantiate it more then once) the first argument to the\n// INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the\n// actual test case name. Remember to pick unique prefixes for different\n// instantiations. The tests from the instantiation above will have\n// these names:\n//\n//    * InstantiationName/FooTest.DoesBlah/0 for \"meeny\"\n//    * InstantiationName/FooTest.DoesBlah/1 for \"miny\"\n//    * InstantiationName/FooTest.DoesBlah/2 for \"moe\"\n//    * InstantiationName/FooTest.HasBlahBlah/0 for \"meeny\"\n//    * InstantiationName/FooTest.HasBlahBlah/1 for \"miny\"\n//    * InstantiationName/FooTest.HasBlahBlah/2 for \"moe\"\n//\n// You can use these names in --gtest_filter.\n//\n// This statement will instantiate all tests from FooTest again, each\n// with parameter values \"cat\" and \"dog\":\n\nconst char* pets[] = {\"cat\", \"dog\"};\nINSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));\n\n// The tests from the instantiation above will have these names:\n//\n//    * AnotherInstantiationName/FooTest.DoesBlah/0 for \"cat\"\n//    * AnotherInstantiationName/FooTest.DoesBlah/1 for \"dog\"\n//    * AnotherInstantiationName/FooTest.HasBlahBlah/0 for \"cat\"\n//    * AnotherInstantiationName/FooTest.HasBlahBlah/1 for \"dog\"\n//\n// Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests\n// in the given test case, whether their definitions come before or\n// AFTER the INSTANTIATE_TEST_CASE_P statement.\n//\n// Please also note that generator expressions (including parameters to the\n// generators) are evaluated in InitGoogleTest(), after main() has started.\n// This allows the user on one hand, to adjust generator parameters in order\n// to dynamically determine a set of tests to run and on the other hand,\n// give the user a chance to inspect the generated tests with Google Test\n// reflection API before RUN_ALL_TESTS() is executed.\n//\n// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc\n// for more examples.\n//\n// In the future, we plan to publish the API for defining new parameter\n// generators. But for now this interface remains part of the internal\n// implementation and is subject to change.\n//\n//\n// A parameterized test fixture must be derived from testing::Test and from\n// testing::WithParamInterface<T>, where T is the type of the parameter\n// values. Inheriting from TestWithParam<T> satisfies that requirement because\n// TestWithParam<T> inherits from both Test and WithParamInterface. In more\n// complicated hierarchies, however, it is occasionally useful to inherit\n// separately from Test and WithParamInterface. For example:\n\nclass BaseTest : public ::testing::Test {\n  // You can inherit all the usual members for a non-parameterized test\n  // fixture here.\n};\n\nclass DerivedTest : public BaseTest, public ::testing::WithParamInterface<int> {\n  // The usual test fixture members go here too.\n};\n\nTEST_F(BaseTest, HasFoo) {\n  // This is an ordinary non-parameterized test.\n}\n\nTEST_P(DerivedTest, DoesBlah) {\n  // GetParam works just the same here as if you inherit from TestWithParam.\n  EXPECT_TRUE(foo.Blah(GetParam()));\n}\n\n#endif  // 0\n\n\n#if !GTEST_OS_SYMBIAN\n# include <utility>\n#endif\n\n// scripts/fuse_gtest.py depends on gtest's own header being #included\n// *unconditionally*.  Therefore these #includes cannot be moved\n// inside #if GTEST_HAS_PARAM_TEST.\n// Copyright 2008 Google Inc.\n// All Rights Reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: vladl@google.com (Vlad Losev)\n\n// Type and function utilities for implementing parameterized tests.\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_\n\n#include <iterator>\n#include <utility>\n#include <vector>\n\n// scripts/fuse_gtest.py depends on gtest's own header being #included\n// *unconditionally*.  Therefore these #includes cannot be moved\n// inside #if GTEST_HAS_PARAM_TEST.\n// Copyright 2003 Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Authors: Dan Egnor (egnor@google.com)\n//\n// A \"smart\" pointer type with reference tracking.  Every pointer to a\n// particular object is kept on a circular linked list.  When the last pointer\n// to an object is destroyed or reassigned, the object is deleted.\n//\n// Used properly, this deletes the object when the last reference goes away.\n// There are several caveats:\n// - Like all reference counting schemes, cycles lead to leaks.\n// - Each smart pointer is actually two pointers (8 bytes instead of 4).\n// - Every time a pointer is assigned, the entire list of pointers to that\n//   object is traversed.  This class is therefore NOT SUITABLE when there\n//   will often be more than two or three pointers to a particular object.\n// - References are only tracked as long as linked_ptr<> objects are copied.\n//   If a linked_ptr<> is converted to a raw pointer and back, BAD THINGS\n//   will happen (double deletion).\n//\n// A good use of this class is storing object references in STL containers.\n// You can safely put linked_ptr<> in a vector<>.\n// Other uses may not be as good.\n//\n// Note: If you use an incomplete type with linked_ptr<>, the class\n// *containing* linked_ptr<> must have a constructor and destructor (even\n// if they do nothing!).\n//\n// Bill Gibbons suggested we use something like this.\n//\n// Thread Safety:\n//   Unlike other linked_ptr implementations, in this implementation\n//   a linked_ptr object is thread-safe in the sense that:\n//     - it's safe to copy linked_ptr objects concurrently,\n//     - it's safe to copy *from* a linked_ptr and read its underlying\n//       raw pointer (e.g. via get()) concurrently, and\n//     - it's safe to write to two linked_ptrs that point to the same\n//       shared object concurrently.\n// TODO(wan@google.com): rename this to safe_linked_ptr to avoid\n// confusion with normal linked_ptr.\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_\n\n#include <stdlib.h>\n#include <assert.h>\n\n\nnamespace testing {\nnamespace internal {\n\n// Protects copying of all linked_ptr objects.\nGTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_linked_ptr_mutex);\n\n// This is used internally by all instances of linked_ptr<>.  It needs to be\n// a non-template class because different types of linked_ptr<> can refer to\n// the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj)).\n// So, it needs to be possible for different types of linked_ptr to participate\n// in the same circular linked list, so we need a single class type here.\n//\n// DO NOT USE THIS CLASS DIRECTLY YOURSELF.  Use linked_ptr<T>.\nclass linked_ptr_internal {\n public:\n  // Create a new circle that includes only this instance.\n  void join_new() {\n    next_ = this;\n  }\n\n  // Many linked_ptr operations may change p.link_ for some linked_ptr\n  // variable p in the same circle as this object.  Therefore we need\n  // to prevent two such operations from occurring concurrently.\n  //\n  // Note that different types of linked_ptr objects can coexist in a\n  // circle (e.g. linked_ptr<Base>, linked_ptr<Derived1>, and\n  // linked_ptr<Derived2>).  Therefore we must use a single mutex to\n  // protect all linked_ptr objects.  This can create serious\n  // contention in production code, but is acceptable in a testing\n  // framework.\n\n  // Join an existing circle.\n  // L < g_linked_ptr_mutex\n  void join(linked_ptr_internal const* ptr) {\n    MutexLock lock(&g_linked_ptr_mutex);\n\n    linked_ptr_internal const* p = ptr;\n    while (p->next_ != ptr) p = p->next_;\n    p->next_ = this;\n    next_ = ptr;\n  }\n\n  // Leave whatever circle we're part of.  Returns true if we were the\n  // last member of the circle.  Once this is done, you can join() another.\n  // L < g_linked_ptr_mutex\n  bool depart() {\n    MutexLock lock(&g_linked_ptr_mutex);\n\n    if (next_ == this) return true;\n    linked_ptr_internal const* p = next_;\n    while (p->next_ != this) p = p->next_;\n    p->next_ = next_;\n    return false;\n  }\n\n private:\n  mutable linked_ptr_internal const* next_;\n};\n\ntemplate <typename T>\nclass linked_ptr {\n public:\n  typedef T element_type;\n\n  // Take over ownership of a raw pointer.  This should happen as soon as\n  // possible after the object is created.\n  explicit linked_ptr(T* ptr = NULL) { capture(ptr); }\n  ~linked_ptr() { depart(); }\n\n  // Copy an existing linked_ptr<>, adding ourselves to the list of references.\n  template <typename U> linked_ptr(linked_ptr<U> const& ptr) { copy(&ptr); }\n  linked_ptr(linked_ptr const& ptr) {  // NOLINT\n    assert(&ptr != this);\n    copy(&ptr);\n  }\n\n  // Assignment releases the old value and acquires the new.\n  template <typename U> linked_ptr& operator=(linked_ptr<U> const& ptr) {\n    depart();\n    copy(&ptr);\n    return *this;\n  }\n\n  linked_ptr& operator=(linked_ptr const& ptr) {\n    if (&ptr != this) {\n      depart();\n      copy(&ptr);\n    }\n    return *this;\n  }\n\n  // Smart pointer members.\n  void reset(T* ptr = NULL) {\n    depart();\n    capture(ptr);\n  }\n  T* get() const { return value_; }\n  T* operator->() const { return value_; }\n  T& operator*() const { return *value_; }\n\n  bool operator==(T* p) const { return value_ == p; }\n  bool operator!=(T* p) const { return value_ != p; }\n  template <typename U>\n  bool operator==(linked_ptr<U> const& ptr) const {\n    return value_ == ptr.get();\n  }\n  template <typename U>\n  bool operator!=(linked_ptr<U> const& ptr) const {\n    return value_ != ptr.get();\n  }\n\n private:\n  template <typename U>\n  friend class linked_ptr;\n\n  T* value_;\n  linked_ptr_internal link_;\n\n  void depart() {\n    if (link_.depart()) delete value_;\n  }\n\n  void capture(T* ptr) {\n    value_ = ptr;\n    link_.join_new();\n  }\n\n  template <typename U> void copy(linked_ptr<U> const* ptr) {\n    value_ = ptr->get();\n    if (value_)\n      link_.join(&ptr->link_);\n    else\n      link_.join_new();\n  }\n};\n\ntemplate<typename T> inline\nbool operator==(T* ptr, const linked_ptr<T>& x) {\n  return ptr == x.get();\n}\n\ntemplate<typename T> inline\nbool operator!=(T* ptr, const linked_ptr<T>& x) {\n  return ptr != x.get();\n}\n\n// A function to convert T* into linked_ptr<T>\n// Doing e.g. make_linked_ptr(new FooBarBaz<type>(arg)) is a shorter notation\n// for linked_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))\ntemplate <typename T>\nlinked_ptr<T> make_linked_ptr(T* ptr) {\n  return linked_ptr<T>(ptr);\n}\n\n}  // namespace internal\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_\n// Copyright 2007, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n\n// Google Test - The Google C++ Testing Framework\n//\n// This file implements a universal value printer that can print a\n// value of any type T:\n//\n//   void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);\n//\n// A user can teach this function how to print a class type T by\n// defining either operator<<() or PrintTo() in the namespace that\n// defines T.  More specifically, the FIRST defined function in the\n// following list will be used (assuming T is defined in namespace\n// foo):\n//\n//   1. foo::PrintTo(const T&, ostream*)\n//   2. operator<<(ostream&, const T&) defined in either foo or the\n//      global namespace.\n//\n// If none of the above is defined, it will print the debug string of\n// the value if it is a protocol buffer, or print the raw bytes in the\n// value otherwise.\n//\n// To aid debugging: when T is a reference type, the address of the\n// value is also printed; when T is a (const) char pointer, both the\n// pointer value and the NUL-terminated string it points to are\n// printed.\n//\n// We also provide some convenient wrappers:\n//\n//   // Prints a value to a string.  For a (const or not) char\n//   // pointer, the NUL-terminated string (but not the pointer) is\n//   // printed.\n//   std::string ::testing::PrintToString(const T& value);\n//\n//   // Prints a value tersely: for a reference type, the referenced\n//   // value (but not the address) is printed; for a (const or not) char\n//   // pointer, the NUL-terminated string (but not the pointer) is\n//   // printed.\n//   void ::testing::internal::UniversalTersePrint(const T& value, ostream*);\n//\n//   // Prints value using the type inferred by the compiler.  The difference\n//   // from UniversalTersePrint() is that this function prints both the\n//   // pointer and the NUL-terminated string for a (const or not) char pointer.\n//   void ::testing::internal::UniversalPrint(const T& value, ostream*);\n//\n//   // Prints the fields of a tuple tersely to a string vector, one\n//   // element for each field. Tuple support must be enabled in\n//   // gtest-port.h.\n//   std::vector<string> UniversalTersePrintTupleFieldsToStrings(\n//       const Tuple& value);\n//\n// Known limitation:\n//\n// The print primitives print the elements of an STL-style container\n// using the compiler-inferred type of *iter where iter is a\n// const_iterator of the container.  When const_iterator is an input\n// iterator but not a forward iterator, this inferred type may not\n// match value_type, and the print output may be incorrect.  In\n// practice, this is rarely a problem as for most containers\n// const_iterator is a forward iterator.  We'll fix this if there's an\n// actual need for it.  Note that this fix cannot rely on value_type\n// being defined as many user-defined container types don't have\n// value_type.\n\n#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_\n#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_\n\n#include <ostream>  // NOLINT\n#include <sstream>\n#include <string>\n#include <utility>\n#include <vector>\n\nnamespace testing {\n\n// Definitions in the 'internal' and 'internal2' name spaces are\n// subject to change without notice.  DO NOT USE THEM IN USER CODE!\nnamespace internal2 {\n\n// Prints the given number of bytes in the given object to the given\n// ostream.\nGTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes,\n                                     size_t count,\n                                     ::std::ostream* os);\n\n// For selecting which printer to use when a given type has neither <<\n// nor PrintTo().\nenum TypeKind {\n  kProtobuf,              // a protobuf type\n  kConvertibleToInteger,  // a type implicitly convertible to BiggestInt\n                          // (e.g. a named or unnamed enum type)\n  kOtherType              // anything else\n};\n\n// TypeWithoutFormatter<T, kTypeKind>::PrintValue(value, os) is called\n// by the universal printer to print a value of type T when neither\n// operator<< nor PrintTo() is defined for T, where kTypeKind is the\n// \"kind\" of T as defined by enum TypeKind.\ntemplate <typename T, TypeKind kTypeKind>\nclass TypeWithoutFormatter {\n public:\n  // This default version is called when kTypeKind is kOtherType.\n  static void PrintValue(const T& value, ::std::ostream* os) {\n    PrintBytesInObjectTo(reinterpret_cast<const unsigned char*>(&value),\n                         sizeof(value), os);\n  }\n};\n\n// We print a protobuf using its ShortDebugString() when the string\n// doesn't exceed this many characters; otherwise we print it using\n// DebugString() for better readability.\nconst size_t kProtobufOneLinerMaxLength = 50;\n\ntemplate <typename T>\nclass TypeWithoutFormatter<T, kProtobuf> {\n public:\n  static void PrintValue(const T& value, ::std::ostream* os) {\n    const ::testing::internal::string short_str = value.ShortDebugString();\n    const ::testing::internal::string pretty_str =\n        short_str.length() <= kProtobufOneLinerMaxLength ?\n        short_str : (\"\\n\" + value.DebugString());\n    *os << (\"<\" + pretty_str + \">\");\n  }\n};\n\ntemplate <typename T>\nclass TypeWithoutFormatter<T, kConvertibleToInteger> {\n public:\n  // Since T has no << operator or PrintTo() but can be implicitly\n  // converted to BiggestInt, we print it as a BiggestInt.\n  //\n  // Most likely T is an enum type (either named or unnamed), in which\n  // case printing it as an integer is the desired behavior.  In case\n  // T is not an enum, printing it as an integer is the best we can do\n  // given that it has no user-defined printer.\n  static void PrintValue(const T& value, ::std::ostream* os) {\n    const internal::BiggestInt kBigInt = value;\n    *os << kBigInt;\n  }\n};\n\n// Prints the given value to the given ostream.  If the value is a\n// protocol message, its debug string is printed; if it's an enum or\n// of a type implicitly convertible to BiggestInt, it's printed as an\n// integer; otherwise the bytes in the value are printed.  This is\n// what UniversalPrinter<T>::Print() does when it knows nothing about\n// type T and T has neither << operator nor PrintTo().\n//\n// A user can override this behavior for a class type Foo by defining\n// a << operator in the namespace where Foo is defined.\n//\n// We put this operator in namespace 'internal2' instead of 'internal'\n// to simplify the implementation, as much code in 'internal' needs to\n// use << in STL, which would conflict with our own << were it defined\n// in 'internal'.\n//\n// Note that this operator<< takes a generic std::basic_ostream<Char,\n// CharTraits> type instead of the more restricted std::ostream.  If\n// we define it to take an std::ostream instead, we'll get an\n// \"ambiguous overloads\" compiler error when trying to print a type\n// Foo that supports streaming to std::basic_ostream<Char,\n// CharTraits>, as the compiler cannot tell whether\n// operator<<(std::ostream&, const T&) or\n// operator<<(std::basic_stream<Char, CharTraits>, const Foo&) is more\n// specific.\ntemplate <typename Char, typename CharTraits, typename T>\n::std::basic_ostream<Char, CharTraits>& operator<<(\n    ::std::basic_ostream<Char, CharTraits>& os, const T& x) {\n  TypeWithoutFormatter<T,\n      (internal::IsAProtocolMessage<T>::value ? kProtobuf :\n       internal::ImplicitlyConvertible<const T&, internal::BiggestInt>::value ?\n       kConvertibleToInteger : kOtherType)>::PrintValue(x, &os);\n  return os;\n}\n\n}  // namespace internal2\n}  // namespace testing\n\n// This namespace MUST NOT BE NESTED IN ::testing, or the name look-up\n// magic needed for implementing UniversalPrinter won't work.\nnamespace testing_internal {\n\n// Used to print a value that is not an STL-style container when the\n// user doesn't define PrintTo() for it.\ntemplate <typename T>\nvoid DefaultPrintNonContainerTo(const T& value, ::std::ostream* os) {\n  // With the following statement, during unqualified name lookup,\n  // testing::internal2::operator<< appears as if it was declared in\n  // the nearest enclosing namespace that contains both\n  // ::testing_internal and ::testing::internal2, i.e. the global\n  // namespace.  For more details, refer to the C++ Standard section\n  // 7.3.4-1 [namespace.udir].  This allows us to fall back onto\n  // testing::internal2::operator<< in case T doesn't come with a <<\n  // operator.\n  //\n  // We cannot write 'using ::testing::internal2::operator<<;', which\n  // gcc 3.3 fails to compile due to a compiler bug.\n  using namespace ::testing::internal2;  // NOLINT\n\n  // Assuming T is defined in namespace foo, in the next statement,\n  // the compiler will consider all of:\n  //\n  //   1. foo::operator<< (thanks to Koenig look-up),\n  //   2. ::operator<< (as the current namespace is enclosed in ::),\n  //   3. testing::internal2::operator<< (thanks to the using statement above).\n  //\n  // The operator<< whose type matches T best will be picked.\n  //\n  // We deliberately allow #2 to be a candidate, as sometimes it's\n  // impossible to define #1 (e.g. when foo is ::std, defining\n  // anything in it is undefined behavior unless you are a compiler\n  // vendor.).\n  *os << value;\n}\n\n}  // namespace testing_internal\n\nnamespace testing {\nnamespace internal {\n\n// UniversalPrinter<T>::Print(value, ostream_ptr) prints the given\n// value to the given ostream.  The caller must ensure that\n// 'ostream_ptr' is not NULL, or the behavior is undefined.\n//\n// We define UniversalPrinter as a class template (as opposed to a\n// function template), as we need to partially specialize it for\n// reference types, which cannot be done with function templates.\ntemplate <typename T>\nclass UniversalPrinter;\n\ntemplate <typename T>\nvoid UniversalPrint(const T& value, ::std::ostream* os);\n\n// Used to print an STL-style container when the user doesn't define\n// a PrintTo() for it.\ntemplate <typename C>\nvoid DefaultPrintTo(IsContainer /* dummy */,\n                    false_type /* is not a pointer */,\n                    const C& container, ::std::ostream* os) {\n  const size_t kMaxCount = 32;  // The maximum number of elements to print.\n  *os << '{';\n  size_t count = 0;\n  for (typename C::const_iterator it = container.begin();\n       it != container.end(); ++it, ++count) {\n    if (count > 0) {\n      *os << ',';\n      if (count == kMaxCount) {  // Enough has been printed.\n        *os << \" ...\";\n        break;\n      }\n    }\n    *os << ' ';\n    // We cannot call PrintTo(*it, os) here as PrintTo() doesn't\n    // handle *it being a native array.\n    internal::UniversalPrint(*it, os);\n  }\n\n  if (count > 0) {\n    *os << ' ';\n  }\n  *os << '}';\n}\n\n// Used to print a pointer that is neither a char pointer nor a member\n// pointer, when the user doesn't define PrintTo() for it.  (A member\n// variable pointer or member function pointer doesn't really point to\n// a location in the address space.  Their representation is\n// implementation-defined.  Therefore they will be printed as raw\n// bytes.)\ntemplate <typename T>\nvoid DefaultPrintTo(IsNotContainer /* dummy */,\n                    true_type /* is a pointer */,\n                    T* p, ::std::ostream* os) {\n  if (p == NULL) {\n    *os << \"NULL\";\n  } else {\n    // C++ doesn't allow casting from a function pointer to any object\n    // pointer.\n    //\n    // IsTrue() silences warnings: \"Condition is always true\",\n    // \"unreachable code\".\n    if (IsTrue(ImplicitlyConvertible<T*, const void*>::value)) {\n      // T is not a function type.  We just call << to print p,\n      // relying on ADL to pick up user-defined << for their pointer\n      // types, if any.\n      *os << p;\n    } else {\n      // T is a function type, so '*os << p' doesn't do what we want\n      // (it just prints p as bool).  We want to print p as a const\n      // void*.  However, we cannot cast it to const void* directly,\n      // even using reinterpret_cast, as earlier versions of gcc\n      // (e.g. 3.4.5) cannot compile the cast when p is a function\n      // pointer.  Casting to UInt64 first solves the problem.\n      *os << reinterpret_cast<const void*>(\n          reinterpret_cast<internal::UInt64>(p));\n    }\n  }\n}\n\n// Used to print a non-container, non-pointer value when the user\n// doesn't define PrintTo() for it.\ntemplate <typename T>\nvoid DefaultPrintTo(IsNotContainer /* dummy */,\n                    false_type /* is not a pointer */,\n                    const T& value, ::std::ostream* os) {\n  ::testing_internal::DefaultPrintNonContainerTo(value, os);\n}\n\n// Prints the given value using the << operator if it has one;\n// otherwise prints the bytes in it.  This is what\n// UniversalPrinter<T>::Print() does when PrintTo() is not specialized\n// or overloaded for type T.\n//\n// A user can override this behavior for a class type Foo by defining\n// an overload of PrintTo() in the namespace where Foo is defined.  We\n// give the user this option as sometimes defining a << operator for\n// Foo is not desirable (e.g. the coding style may prevent doing it,\n// or there is already a << operator but it doesn't do what the user\n// wants).\ntemplate <typename T>\nvoid PrintTo(const T& value, ::std::ostream* os) {\n  // DefaultPrintTo() is overloaded.  The type of its first two\n  // arguments determine which version will be picked.  If T is an\n  // STL-style container, the version for container will be called; if\n  // T is a pointer, the pointer version will be called; otherwise the\n  // generic version will be called.\n  //\n  // Note that we check for container types here, prior to we check\n  // for protocol message types in our operator<<.  The rationale is:\n  //\n  // For protocol messages, we want to give people a chance to\n  // override Google Mock's format by defining a PrintTo() or\n  // operator<<.  For STL containers, other formats can be\n  // incompatible with Google Mock's format for the container\n  // elements; therefore we check for container types here to ensure\n  // that our format is used.\n  //\n  // The second argument of DefaultPrintTo() is needed to bypass a bug\n  // in Symbian's C++ compiler that prevents it from picking the right\n  // overload between:\n  //\n  //   PrintTo(const T& x, ...);\n  //   PrintTo(T* x, ...);\n  DefaultPrintTo(IsContainerTest<T>(0), is_pointer<T>(), value, os);\n}\n\n// The following list of PrintTo() overloads tells\n// UniversalPrinter<T>::Print() how to print standard types (built-in\n// types, strings, plain arrays, and pointers).\n\n// Overloads for various char types.\nGTEST_API_ void PrintTo(unsigned char c, ::std::ostream* os);\nGTEST_API_ void PrintTo(signed char c, ::std::ostream* os);\ninline void PrintTo(char c, ::std::ostream* os) {\n  // When printing a plain char, we always treat it as unsigned.  This\n  // way, the output won't be affected by whether the compiler thinks\n  // char is signed or not.\n  PrintTo(static_cast<unsigned char>(c), os);\n}\n\n// Overloads for other simple built-in types.\ninline void PrintTo(bool x, ::std::ostream* os) {\n  *os << (x ? \"true\" : \"false\");\n}\n\n// Overload for wchar_t type.\n// Prints a wchar_t as a symbol if it is printable or as its internal\n// code otherwise and also as its decimal code (except for L'\\0').\n// The L'\\0' char is printed as \"L'\\\\0'\". The decimal code is printed\n// as signed integer when wchar_t is implemented by the compiler\n// as a signed type and is printed as an unsigned integer when wchar_t\n// is implemented as an unsigned type.\nGTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);\n\n// Overloads for C strings.\nGTEST_API_ void PrintTo(const char* s, ::std::ostream* os);\ninline void PrintTo(char* s, ::std::ostream* os) {\n  PrintTo(ImplicitCast_<const char*>(s), os);\n}\n\n// signed/unsigned char is often used for representing binary data, so\n// we print pointers to it as void* to be safe.\ninline void PrintTo(const signed char* s, ::std::ostream* os) {\n  PrintTo(ImplicitCast_<const void*>(s), os);\n}\ninline void PrintTo(signed char* s, ::std::ostream* os) {\n  PrintTo(ImplicitCast_<const void*>(s), os);\n}\ninline void PrintTo(const unsigned char* s, ::std::ostream* os) {\n  PrintTo(ImplicitCast_<const void*>(s), os);\n}\ninline void PrintTo(unsigned char* s, ::std::ostream* os) {\n  PrintTo(ImplicitCast_<const void*>(s), os);\n}\n\n// MSVC can be configured to define wchar_t as a typedef of unsigned\n// short.  It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native\n// type.  When wchar_t is a typedef, defining an overload for const\n// wchar_t* would cause unsigned short* be printed as a wide string,\n// possibly causing invalid memory accesses.\n#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)\n// Overloads for wide C strings\nGTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os);\ninline void PrintTo(wchar_t* s, ::std::ostream* os) {\n  PrintTo(ImplicitCast_<const wchar_t*>(s), os);\n}\n#endif\n\n// Overload for C arrays.  Multi-dimensional arrays are printed\n// properly.\n\n// Prints the given number of elements in an array, without printing\n// the curly braces.\ntemplate <typename T>\nvoid PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {\n  UniversalPrint(a[0], os);\n  for (size_t i = 1; i != count; i++) {\n    *os << \", \";\n    UniversalPrint(a[i], os);\n  }\n}\n\n// Overloads for ::string and ::std::string.\n#if GTEST_HAS_GLOBAL_STRING\nGTEST_API_ void PrintStringTo(const ::string&s, ::std::ostream* os);\ninline void PrintTo(const ::string& s, ::std::ostream* os) {\n  PrintStringTo(s, os);\n}\n#endif  // GTEST_HAS_GLOBAL_STRING\n\nGTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os);\ninline void PrintTo(const ::std::string& s, ::std::ostream* os) {\n  PrintStringTo(s, os);\n}\n\n// Overloads for ::wstring and ::std::wstring.\n#if GTEST_HAS_GLOBAL_WSTRING\nGTEST_API_ void PrintWideStringTo(const ::wstring&s, ::std::ostream* os);\ninline void PrintTo(const ::wstring& s, ::std::ostream* os) {\n  PrintWideStringTo(s, os);\n}\n#endif  // GTEST_HAS_GLOBAL_WSTRING\n\n#if GTEST_HAS_STD_WSTRING\nGTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);\ninline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {\n  PrintWideStringTo(s, os);\n}\n#endif  // GTEST_HAS_STD_WSTRING\n\n#if GTEST_HAS_TR1_TUPLE\n// Overload for ::std::tr1::tuple.  Needed for printing function arguments,\n// which are packed as tuples.\n\n// Helper function for printing a tuple.  T must be instantiated with\n// a tuple type.\ntemplate <typename T>\nvoid PrintTupleTo(const T& t, ::std::ostream* os);\n\n// Overloaded PrintTo() for tuples of various arities.  We support\n// tuples of up-to 10 fields.  The following implementation works\n// regardless of whether tr1::tuple is implemented using the\n// non-standard variadic template feature or not.\n\ninline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1>\nvoid PrintTo(const ::std::tr1::tuple<T1>& t, ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1, typename T2>\nvoid PrintTo(const ::std::tr1::tuple<T1, T2>& t, ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1, typename T2, typename T3>\nvoid PrintTo(const ::std::tr1::tuple<T1, T2, T3>& t, ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4>\nvoid PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4>& t, ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5>\nvoid PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5>& t,\n             ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n          typename T6>\nvoid PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6>& t,\n             ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n          typename T6, typename T7>\nvoid PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7>& t,\n             ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n          typename T6, typename T7, typename T8>\nvoid PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8>& t,\n             ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n          typename T6, typename T7, typename T8, typename T9>\nvoid PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t,\n             ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n          typename T6, typename T7, typename T8, typename T9, typename T10>\nvoid PrintTo(\n    const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& t,\n    ::std::ostream* os) {\n  PrintTupleTo(t, os);\n}\n#endif  // GTEST_HAS_TR1_TUPLE\n\n// Overload for std::pair.\ntemplate <typename T1, typename T2>\nvoid PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {\n  *os << '(';\n  // We cannot use UniversalPrint(value.first, os) here, as T1 may be\n  // a reference type.  The same for printing value.second.\n  UniversalPrinter<T1>::Print(value.first, os);\n  *os << \", \";\n  UniversalPrinter<T2>::Print(value.second, os);\n  *os << ')';\n}\n\n// Implements printing a non-reference type T by letting the compiler\n// pick the right overload of PrintTo() for T.\ntemplate <typename T>\nclass UniversalPrinter {\n public:\n  // MSVC warns about adding const to a function type, so we want to\n  // disable the warning.\n#ifdef _MSC_VER\n# pragma warning(push)          // Saves the current warning state.\n# pragma warning(disable:4180)  // Temporarily disables warning 4180.\n#endif  // _MSC_VER\n\n  // Note: we deliberately don't call this PrintTo(), as that name\n  // conflicts with ::testing::internal::PrintTo in the body of the\n  // function.\n  static void Print(const T& value, ::std::ostream* os) {\n    // By default, ::testing::internal::PrintTo() is used for printing\n    // the value.\n    //\n    // Thanks to Koenig look-up, if T is a class and has its own\n    // PrintTo() function defined in its namespace, that function will\n    // be visible here.  Since it is more specific than the generic ones\n    // in ::testing::internal, it will be picked by the compiler in the\n    // following statement - exactly what we want.\n    PrintTo(value, os);\n  }\n\n#ifdef _MSC_VER\n# pragma warning(pop)           // Restores the warning state.\n#endif  // _MSC_VER\n};\n\n// UniversalPrintArray(begin, len, os) prints an array of 'len'\n// elements, starting at address 'begin'.\ntemplate <typename T>\nvoid UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {\n  if (len == 0) {\n    *os << \"{}\";\n  } else {\n    *os << \"{ \";\n    const size_t kThreshold = 18;\n    const size_t kChunkSize = 8;\n    // If the array has more than kThreshold elements, we'll have to\n    // omit some details by printing only the first and the last\n    // kChunkSize elements.\n    // TODO(wan@google.com): let the user control the threshold using a flag.\n    if (len <= kThreshold) {\n      PrintRawArrayTo(begin, len, os);\n    } else {\n      PrintRawArrayTo(begin, kChunkSize, os);\n      *os << \", ..., \";\n      PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os);\n    }\n    *os << \" }\";\n  }\n}\n// This overload prints a (const) char array compactly.\nGTEST_API_ void UniversalPrintArray(const char* begin,\n                                    size_t len,\n                                    ::std::ostream* os);\n\n// Implements printing an array type T[N].\ntemplate <typename T, size_t N>\nclass UniversalPrinter<T[N]> {\n public:\n  // Prints the given array, omitting some elements when there are too\n  // many.\n  static void Print(const T (&a)[N], ::std::ostream* os) {\n    UniversalPrintArray(a, N, os);\n  }\n};\n\n// Implements printing a reference type T&.\ntemplate <typename T>\nclass UniversalPrinter<T&> {\n public:\n  // MSVC warns about adding const to a function type, so we want to\n  // disable the warning.\n#ifdef _MSC_VER\n# pragma warning(push)          // Saves the current warning state.\n# pragma warning(disable:4180)  // Temporarily disables warning 4180.\n#endif  // _MSC_VER\n\n  static void Print(const T& value, ::std::ostream* os) {\n    // Prints the address of the value.  We use reinterpret_cast here\n    // as static_cast doesn't compile when T is a function type.\n    *os << \"@\" << reinterpret_cast<const void*>(&value) << \" \";\n\n    // Then prints the value itself.\n    UniversalPrint(value, os);\n  }\n\n#ifdef _MSC_VER\n# pragma warning(pop)           // Restores the warning state.\n#endif  // _MSC_VER\n};\n\n// Prints a value tersely: for a reference type, the referenced value\n// (but not the address) is printed; for a (const) char pointer, the\n// NUL-terminated string (but not the pointer) is printed.\ntemplate <typename T>\nvoid UniversalTersePrint(const T& value, ::std::ostream* os) {\n  UniversalPrint(value, os);\n}\ninline void UniversalTersePrint(const char* str, ::std::ostream* os) {\n  if (str == NULL) {\n    *os << \"NULL\";\n  } else {\n    UniversalPrint(string(str), os);\n  }\n}\ninline void UniversalTersePrint(char* str, ::std::ostream* os) {\n  UniversalTersePrint(static_cast<const char*>(str), os);\n}\n\n// Prints a value using the type inferred by the compiler.  The\n// difference between this and UniversalTersePrint() is that for a\n// (const) char pointer, this prints both the pointer and the\n// NUL-terminated string.\ntemplate <typename T>\nvoid UniversalPrint(const T& value, ::std::ostream* os) {\n  UniversalPrinter<T>::Print(value, os);\n}\n\n#if GTEST_HAS_TR1_TUPLE\ntypedef ::std::vector<string> Strings;\n\n// This helper template allows PrintTo() for tuples and\n// UniversalTersePrintTupleFieldsToStrings() to be defined by\n// induction on the number of tuple fields.  The idea is that\n// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N\n// fields in tuple t, and can be defined in terms of\n// TuplePrefixPrinter<N - 1>.\n\n// The inductive case.\ntemplate <size_t N>\nstruct TuplePrefixPrinter {\n  // Prints the first N fields of a tuple.\n  template <typename Tuple>\n  static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {\n    TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);\n    *os << \", \";\n    UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type>\n        ::Print(::std::tr1::get<N - 1>(t), os);\n  }\n\n  // Tersely prints the first N fields of a tuple to a string vector,\n  // one element for each field.\n  template <typename Tuple>\n  static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {\n    TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);\n    ::std::stringstream ss;\n    UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);\n    strings->push_back(ss.str());\n  }\n};\n\n// Base cases.\ntemplate <>\nstruct TuplePrefixPrinter<0> {\n  template <typename Tuple>\n  static void PrintPrefixTo(const Tuple&, ::std::ostream*) {}\n\n  template <typename Tuple>\n  static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}\n};\n// We have to specialize the entire TuplePrefixPrinter<> class\n// template here, even though the definition of\n// TersePrintPrefixToStrings() is the same as the generic version, as\n// Embarcadero (formerly CodeGear, formerly Borland) C++ doesn't\n// support specializing a method template of a class template.\ntemplate <>\nstruct TuplePrefixPrinter<1> {\n  template <typename Tuple>\n  static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {\n    UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::\n        Print(::std::tr1::get<0>(t), os);\n  }\n\n  template <typename Tuple>\n  static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {\n    ::std::stringstream ss;\n    UniversalTersePrint(::std::tr1::get<0>(t), &ss);\n    strings->push_back(ss.str());\n  }\n};\n\n// Helper function for printing a tuple.  T must be instantiated with\n// a tuple type.\ntemplate <typename T>\nvoid PrintTupleTo(const T& t, ::std::ostream* os) {\n  *os << \"(\";\n  TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::\n      PrintPrefixTo(t, os);\n  *os << \")\";\n}\n\n// Prints the fields of a tuple tersely to a string vector, one\n// element for each field.  See the comment before\n// UniversalTersePrint() for how we define \"tersely\".\ntemplate <typename Tuple>\nStrings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {\n  Strings result;\n  TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>::\n      TersePrintPrefixToStrings(value, &result);\n  return result;\n}\n#endif  // GTEST_HAS_TR1_TUPLE\n\n}  // namespace internal\n\ntemplate <typename T>\n::std::string PrintToString(const T& value) {\n  ::std::stringstream ss;\n  internal::UniversalTersePrint(value, &ss);\n  return ss.str();\n}\n\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_\n\n#if GTEST_HAS_PARAM_TEST\n\nnamespace testing {\nnamespace internal {\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// Outputs a message explaining invalid registration of different\n// fixture class for the same test case. This may happen when\n// TEST_P macro is used to define two tests with the same name\n// but in different namespaces.\nGTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,\n                                          const char* file, int line);\n\ntemplate <typename> class ParamGeneratorInterface;\ntemplate <typename> class ParamGenerator;\n\n// Interface for iterating over elements provided by an implementation\n// of ParamGeneratorInterface<T>.\ntemplate <typename T>\nclass ParamIteratorInterface {\n public:\n  virtual ~ParamIteratorInterface() {}\n  // A pointer to the base generator instance.\n  // Used only for the purposes of iterator comparison\n  // to make sure that two iterators belong to the same generator.\n  virtual const ParamGeneratorInterface<T>* BaseGenerator() const = 0;\n  // Advances iterator to point to the next element\n  // provided by the generator. The caller is responsible\n  // for not calling Advance() on an iterator equal to\n  // BaseGenerator()->End().\n  virtual void Advance() = 0;\n  // Clones the iterator object. Used for implementing copy semantics\n  // of ParamIterator<T>.\n  virtual ParamIteratorInterface* Clone() const = 0;\n  // Dereferences the current iterator and provides (read-only) access\n  // to the pointed value. It is the caller's responsibility not to call\n  // Current() on an iterator equal to BaseGenerator()->End().\n  // Used for implementing ParamGenerator<T>::operator*().\n  virtual const T* Current() const = 0;\n  // Determines whether the given iterator and other point to the same\n  // element in the sequence generated by the generator.\n  // Used for implementing ParamGenerator<T>::operator==().\n  virtual bool Equals(const ParamIteratorInterface& other) const = 0;\n};\n\n// Class iterating over elements provided by an implementation of\n// ParamGeneratorInterface<T>. It wraps ParamIteratorInterface<T>\n// and implements the const forward iterator concept.\ntemplate <typename T>\nclass ParamIterator {\n public:\n  typedef T value_type;\n  typedef const T& reference;\n  typedef ptrdiff_t difference_type;\n\n  // ParamIterator assumes ownership of the impl_ pointer.\n  ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {}\n  ParamIterator& operator=(const ParamIterator& other) {\n    if (this != &other)\n      impl_.reset(other.impl_->Clone());\n    return *this;\n  }\n\n  const T& operator*() const { return *impl_->Current(); }\n  const T* operator->() const { return impl_->Current(); }\n  // Prefix version of operator++.\n  ParamIterator& operator++() {\n    impl_->Advance();\n    return *this;\n  }\n  // Postfix version of operator++.\n  ParamIterator operator++(int /*unused*/) {\n    ParamIteratorInterface<T>* clone = impl_->Clone();\n    impl_->Advance();\n    return ParamIterator(clone);\n  }\n  bool operator==(const ParamIterator& other) const {\n    return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_);\n  }\n  bool operator!=(const ParamIterator& other) const {\n    return !(*this == other);\n  }\n\n private:\n  friend class ParamGenerator<T>;\n  explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {}\n  scoped_ptr<ParamIteratorInterface<T> > impl_;\n};\n\n// ParamGeneratorInterface<T> is the binary interface to access generators\n// defined in other translation units.\ntemplate <typename T>\nclass ParamGeneratorInterface {\n public:\n  typedef T ParamType;\n\n  virtual ~ParamGeneratorInterface() {}\n\n  // Generator interface definition\n  virtual ParamIteratorInterface<T>* Begin() const = 0;\n  virtual ParamIteratorInterface<T>* End() const = 0;\n};\n\n// Wraps ParamGeneratorInterface<T> and provides general generator syntax\n// compatible with the STL Container concept.\n// This class implements copy initialization semantics and the contained\n// ParamGeneratorInterface<T> instance is shared among all copies\n// of the original object. This is possible because that instance is immutable.\ntemplate<typename T>\nclass ParamGenerator {\n public:\n  typedef ParamIterator<T> iterator;\n\n  explicit ParamGenerator(ParamGeneratorInterface<T>* impl) : impl_(impl) {}\n  ParamGenerator(const ParamGenerator& other) : impl_(other.impl_) {}\n\n  ParamGenerator& operator=(const ParamGenerator& other) {\n    impl_ = other.impl_;\n    return *this;\n  }\n\n  iterator begin() const { return iterator(impl_->Begin()); }\n  iterator end() const { return iterator(impl_->End()); }\n\n private:\n  linked_ptr<const ParamGeneratorInterface<T> > impl_;\n};\n\n// Generates values from a range of two comparable values. Can be used to\n// generate sequences of user-defined types that implement operator+() and\n// operator<().\n// This class is used in the Range() function.\ntemplate <typename T, typename IncrementT>\nclass RangeGenerator : public ParamGeneratorInterface<T> {\n public:\n  RangeGenerator(T begin, T end, IncrementT step)\n      : begin_(begin), end_(end),\n        step_(step), end_index_(CalculateEndIndex(begin, end, step)) {}\n  virtual ~RangeGenerator() {}\n\n  virtual ParamIteratorInterface<T>* Begin() const {\n    return new Iterator(this, begin_, 0, step_);\n  }\n  virtual ParamIteratorInterface<T>* End() const {\n    return new Iterator(this, end_, end_index_, step_);\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<T> {\n   public:\n    Iterator(const ParamGeneratorInterface<T>* base, T value, int index,\n             IncrementT step)\n        : base_(base), value_(value), index_(index), step_(step) {}\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<T>* BaseGenerator() const {\n      return base_;\n    }\n    virtual void Advance() {\n      value_ = value_ + step_;\n      index_++;\n    }\n    virtual ParamIteratorInterface<T>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const T* Current() const { return &value_; }\n    virtual bool Equals(const ParamIteratorInterface<T>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const int other_index =\n          CheckedDowncastToActualType<const Iterator>(&other)->index_;\n      return index_ == other_index;\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : ParamIteratorInterface<T>(),\n          base_(other.base_), value_(other.value_), index_(other.index_),\n          step_(other.step_) {}\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<T>* const base_;\n    T value_;\n    int index_;\n    const IncrementT step_;\n  };  // class RangeGenerator::Iterator\n\n  static int CalculateEndIndex(const T& begin,\n                               const T& end,\n                               const IncrementT& step) {\n    int end_index = 0;\n    for (T i = begin; i < end; i = i + step)\n      end_index++;\n    return end_index;\n  }\n\n  // No implementation - assignment is unsupported.\n  void operator=(const RangeGenerator& other);\n\n  const T begin_;\n  const T end_;\n  const IncrementT step_;\n  // The index for the end() iterator. All the elements in the generated\n  // sequence are indexed (0-based) to aid iterator comparison.\n  const int end_index_;\n};  // class RangeGenerator\n\n\n// Generates values from a pair of STL-style iterators. Used in the\n// ValuesIn() function. The elements are copied from the source range\n// since the source can be located on the stack, and the generator\n// is likely to persist beyond that stack frame.\ntemplate <typename T>\nclass ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {\n public:\n  template <typename ForwardIterator>\n  ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)\n      : container_(begin, end) {}\n  virtual ~ValuesInIteratorRangeGenerator() {}\n\n  virtual ParamIteratorInterface<T>* Begin() const {\n    return new Iterator(this, container_.begin());\n  }\n  virtual ParamIteratorInterface<T>* End() const {\n    return new Iterator(this, container_.end());\n  }\n\n private:\n  typedef typename ::std::vector<T> ContainerType;\n\n  class Iterator : public ParamIteratorInterface<T> {\n   public:\n    Iterator(const ParamGeneratorInterface<T>* base,\n             typename ContainerType::const_iterator iterator)\n        : base_(base), iterator_(iterator) {}\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<T>* BaseGenerator() const {\n      return base_;\n    }\n    virtual void Advance() {\n      ++iterator_;\n      value_.reset();\n    }\n    virtual ParamIteratorInterface<T>* Clone() const {\n      return new Iterator(*this);\n    }\n    // We need to use cached value referenced by iterator_ because *iterator_\n    // can return a temporary object (and of type other then T), so just\n    // having \"return &*iterator_;\" doesn't work.\n    // value_ is updated here and not in Advance() because Advance()\n    // can advance iterator_ beyond the end of the range, and we cannot\n    // detect that fact. The client code, on the other hand, is\n    // responsible for not calling Current() on an out-of-range iterator.\n    virtual const T* Current() const {\n      if (value_.get() == NULL)\n        value_.reset(new T(*iterator_));\n      return value_.get();\n    }\n    virtual bool Equals(const ParamIteratorInterface<T>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      return iterator_ ==\n          CheckedDowncastToActualType<const Iterator>(&other)->iterator_;\n    }\n\n   private:\n    Iterator(const Iterator& other)\n          // The explicit constructor call suppresses a false warning\n          // emitted by gcc when supplied with the -Wextra option.\n        : ParamIteratorInterface<T>(),\n          base_(other.base_),\n          iterator_(other.iterator_) {}\n\n    const ParamGeneratorInterface<T>* const base_;\n    typename ContainerType::const_iterator iterator_;\n    // A cached value of *iterator_. We keep it here to allow access by\n    // pointer in the wrapping iterator's operator->().\n    // value_ needs to be mutable to be accessed in Current().\n    // Use of scoped_ptr helps manage cached value's lifetime,\n    // which is bound by the lifespan of the iterator itself.\n    mutable scoped_ptr<const T> value_;\n  };  // class ValuesInIteratorRangeGenerator::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const ValuesInIteratorRangeGenerator& other);\n\n  const ContainerType container_;\n};  // class ValuesInIteratorRangeGenerator\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// Stores a parameter value and later creates tests parameterized with that\n// value.\ntemplate <class TestClass>\nclass ParameterizedTestFactory : public TestFactoryBase {\n public:\n  typedef typename TestClass::ParamType ParamType;\n  explicit ParameterizedTestFactory(ParamType parameter) :\n      parameter_(parameter) {}\n  virtual Test* CreateTest() {\n    TestClass::SetParam(&parameter_);\n    return new TestClass();\n  }\n\n private:\n  const ParamType parameter_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);\n};\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// TestMetaFactoryBase is a base class for meta-factories that create\n// test factories for passing into MakeAndRegisterTestInfo function.\ntemplate <class ParamType>\nclass TestMetaFactoryBase {\n public:\n  virtual ~TestMetaFactoryBase() {}\n\n  virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0;\n};\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// TestMetaFactory creates test factories for passing into\n// MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives\n// ownership of test factory pointer, same factory object cannot be passed\n// into that method twice. But ParameterizedTestCaseInfo is going to call\n// it for each Test/Parameter value combination. Thus it needs meta factory\n// creator class.\ntemplate <class TestCase>\nclass TestMetaFactory\n    : public TestMetaFactoryBase<typename TestCase::ParamType> {\n public:\n  typedef typename TestCase::ParamType ParamType;\n\n  TestMetaFactory() {}\n\n  virtual TestFactoryBase* CreateTestFactory(ParamType parameter) {\n    return new ParameterizedTestFactory<TestCase>(parameter);\n  }\n\n private:\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory);\n};\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// ParameterizedTestCaseInfoBase is a generic interface\n// to ParameterizedTestCaseInfo classes. ParameterizedTestCaseInfoBase\n// accumulates test information provided by TEST_P macro invocations\n// and generators provided by INSTANTIATE_TEST_CASE_P macro invocations\n// and uses that information to register all resulting test instances\n// in RegisterTests method. The ParameterizeTestCaseRegistry class holds\n// a collection of pointers to the ParameterizedTestCaseInfo objects\n// and calls RegisterTests() on each of them when asked.\nclass ParameterizedTestCaseInfoBase {\n public:\n  virtual ~ParameterizedTestCaseInfoBase() {}\n\n  // Base part of test case name for display purposes.\n  virtual const string& GetTestCaseName() const = 0;\n  // Test case id to verify identity.\n  virtual TypeId GetTestCaseTypeId() const = 0;\n  // UnitTest class invokes this method to register tests in this\n  // test case right before running them in RUN_ALL_TESTS macro.\n  // This method should not be called more then once on any single\n  // instance of a ParameterizedTestCaseInfoBase derived class.\n  virtual void RegisterTests() = 0;\n\n protected:\n  ParameterizedTestCaseInfoBase() {}\n\n private:\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfoBase);\n};\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// ParameterizedTestCaseInfo accumulates tests obtained from TEST_P\n// macro invocations for a particular test case and generators\n// obtained from INSTANTIATE_TEST_CASE_P macro invocations for that\n// test case. It registers tests with all values generated by all\n// generators when asked.\ntemplate <class TestCase>\nclass ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {\n public:\n  // ParamType and GeneratorCreationFunc are private types but are required\n  // for declarations of public methods AddTestPattern() and\n  // AddTestCaseInstantiation().\n  typedef typename TestCase::ParamType ParamType;\n  // A function that returns an instance of appropriate generator type.\n  typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();\n\n  explicit ParameterizedTestCaseInfo(const char* name)\n      : test_case_name_(name) {}\n\n  // Test case base name for display purposes.\n  virtual const string& GetTestCaseName() const { return test_case_name_; }\n  // Test case id to verify identity.\n  virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); }\n  // TEST_P macro uses AddTestPattern() to record information\n  // about a single test in a LocalTestInfo structure.\n  // test_case_name is the base name of the test case (without invocation\n  // prefix). test_base_name is the name of an individual test without\n  // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is\n  // test case base name and DoBar is test base name.\n  void AddTestPattern(const char* test_case_name,\n                      const char* test_base_name,\n                      TestMetaFactoryBase<ParamType>* meta_factory) {\n    tests_.push_back(linked_ptr<TestInfo>(new TestInfo(test_case_name,\n                                                       test_base_name,\n                                                       meta_factory)));\n  }\n  // INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information\n  // about a generator.\n  int AddTestCaseInstantiation(const string& instantiation_name,\n                               GeneratorCreationFunc* func,\n                               const char* /* file */,\n                               int /* line */) {\n    instantiations_.push_back(::std::make_pair(instantiation_name, func));\n    return 0;  // Return value used only to run this method in namespace scope.\n  }\n  // UnitTest class invokes this method to register tests in this test case\n  // test cases right before running tests in RUN_ALL_TESTS macro.\n  // This method should not be called more then once on any single\n  // instance of a ParameterizedTestCaseInfoBase derived class.\n  // UnitTest has a guard to prevent from calling this method more then once.\n  virtual void RegisterTests() {\n    for (typename TestInfoContainer::iterator test_it = tests_.begin();\n         test_it != tests_.end(); ++test_it) {\n      linked_ptr<TestInfo> test_info = *test_it;\n      for (typename InstantiationContainer::iterator gen_it =\n               instantiations_.begin(); gen_it != instantiations_.end();\n               ++gen_it) {\n        const string& instantiation_name = gen_it->first;\n        ParamGenerator<ParamType> generator((*gen_it->second)());\n\n        Message test_case_name_stream;\n        if ( !instantiation_name.empty() )\n          test_case_name_stream << instantiation_name << \"/\";\n        test_case_name_stream << test_info->test_case_base_name;\n\n        int i = 0;\n        for (typename ParamGenerator<ParamType>::iterator param_it =\n                 generator.begin();\n             param_it != generator.end(); ++param_it, ++i) {\n          Message test_name_stream;\n          test_name_stream << test_info->test_base_name << \"/\" << i;\n          MakeAndRegisterTestInfo(\n              test_case_name_stream.GetString().c_str(),\n              test_name_stream.GetString().c_str(),\n              NULL,  // No type parameter.\n              PrintToString(*param_it).c_str(),\n              GetTestCaseTypeId(),\n              TestCase::SetUpTestCase,\n              TestCase::TearDownTestCase,\n              test_info->test_meta_factory->CreateTestFactory(*param_it));\n        }  // for param_it\n      }  // for gen_it\n    }  // for test_it\n  }  // RegisterTests\n\n private:\n  // LocalTestInfo structure keeps information about a single test registered\n  // with TEST_P macro.\n  struct TestInfo {\n    TestInfo(const char* a_test_case_base_name,\n             const char* a_test_base_name,\n             TestMetaFactoryBase<ParamType>* a_test_meta_factory) :\n        test_case_base_name(a_test_case_base_name),\n        test_base_name(a_test_base_name),\n        test_meta_factory(a_test_meta_factory) {}\n\n    const string test_case_base_name;\n    const string test_base_name;\n    const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;\n  };\n  typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;\n  // Keeps pairs of <Instantiation name, Sequence generator creation function>\n  // received from INSTANTIATE_TEST_CASE_P macros.\n  typedef ::std::vector<std::pair<string, GeneratorCreationFunc*> >\n      InstantiationContainer;\n\n  const string test_case_name_;\n  TestInfoContainer tests_;\n  InstantiationContainer instantiations_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfo);\n};  // class ParameterizedTestCaseInfo\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// ParameterizedTestCaseRegistry contains a map of ParameterizedTestCaseInfoBase\n// classes accessed by test case names. TEST_P and INSTANTIATE_TEST_CASE_P\n// macros use it to locate their corresponding ParameterizedTestCaseInfo\n// descriptors.\nclass ParameterizedTestCaseRegistry {\n public:\n  ParameterizedTestCaseRegistry() {}\n  ~ParameterizedTestCaseRegistry() {\n    for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();\n         it != test_case_infos_.end(); ++it) {\n      delete *it;\n    }\n  }\n\n  // Looks up or creates and returns a structure containing information about\n  // tests and instantiations of a particular test case.\n  template <class TestCase>\n  ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(\n      const char* test_case_name,\n      const char* file,\n      int line) {\n    ParameterizedTestCaseInfo<TestCase>* typed_test_info = NULL;\n    for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();\n         it != test_case_infos_.end(); ++it) {\n      if ((*it)->GetTestCaseName() == test_case_name) {\n        if ((*it)->GetTestCaseTypeId() != GetTypeId<TestCase>()) {\n          // Complain about incorrect usage of Google Test facilities\n          // and terminate the program since we cannot guaranty correct\n          // test case setup and tear-down in this case.\n          ReportInvalidTestCaseType(test_case_name,  file, line);\n          posix::Abort();\n        } else {\n          // At this point we are sure that the object we found is of the same\n          // type we are looking for, so we downcast it to that type\n          // without further checks.\n          typed_test_info = CheckedDowncastToActualType<\n              ParameterizedTestCaseInfo<TestCase> >(*it);\n        }\n        break;\n      }\n    }\n    if (typed_test_info == NULL) {\n      typed_test_info = new ParameterizedTestCaseInfo<TestCase>(test_case_name);\n      test_case_infos_.push_back(typed_test_info);\n    }\n    return typed_test_info;\n  }\n  void RegisterTests() {\n    for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();\n         it != test_case_infos_.end(); ++it) {\n      (*it)->RegisterTests();\n    }\n  }\n\n private:\n  typedef ::std::vector<ParameterizedTestCaseInfoBase*> TestCaseInfoContainer;\n\n  TestCaseInfoContainer test_case_infos_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseRegistry);\n};\n\n}  // namespace internal\n}  // namespace testing\n\n#endif  //  GTEST_HAS_PARAM_TEST\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_\n// This file was GENERATED by command:\n//     pump.py gtest-param-util-generated.h.pump\n// DO NOT EDIT BY HAND!!!\n\n// Copyright 2008 Google Inc.\n// All Rights Reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: vladl@google.com (Vlad Losev)\n\n// Type and function utilities for implementing parameterized tests.\n// This file is generated by a SCRIPT.  DO NOT EDIT BY HAND!\n//\n// Currently Google Test supports at most 50 arguments in Values,\n// and at most 10 arguments in Combine. Please contact\n// googletestframework@googlegroups.com if you need more.\n// Please note that the number of arguments to Combine is limited\n// by the maximum arity of the implementation of tr1::tuple which is\n// currently set at 10.\n\n#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_\n#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_\n\n// scripts/fuse_gtest.py depends on gtest's own header being #included\n// *unconditionally*.  Therefore these #includes cannot be moved\n// inside #if GTEST_HAS_PARAM_TEST.\n\n#if GTEST_HAS_PARAM_TEST\n\nnamespace testing {\n\n// Forward declarations of ValuesIn(), which is implemented in\n// include/gtest/gtest-param-test.h.\ntemplate <typename ForwardIterator>\ninternal::ParamGenerator<\n  typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>\nValuesIn(ForwardIterator begin, ForwardIterator end);\n\ntemplate <typename T, size_t N>\ninternal::ParamGenerator<T> ValuesIn(const T (&array)[N]);\n\ntemplate <class Container>\ninternal::ParamGenerator<typename Container::value_type> ValuesIn(\n    const Container& container);\n\nnamespace internal {\n\n// Used in the Values() function to provide polymorphic capabilities.\ntemplate <typename T1>\nclass ValueArray1 {\n public:\n  explicit ValueArray1(T1 v1) : v1_(v1) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray1& other);\n\n  const T1 v1_;\n};\n\ntemplate <typename T1, typename T2>\nclass ValueArray2 {\n public:\n  ValueArray2(T1 v1, T2 v2) : v1_(v1), v2_(v2) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray2& other);\n\n  const T1 v1_;\n  const T2 v2_;\n};\n\ntemplate <typename T1, typename T2, typename T3>\nclass ValueArray3 {\n public:\n  ValueArray3(T1 v1, T2 v2, T3 v3) : v1_(v1), v2_(v2), v3_(v3) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray3& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4>\nclass ValueArray4 {\n public:\n  ValueArray4(T1 v1, T2 v2, T3 v3, T4 v4) : v1_(v1), v2_(v2), v3_(v3),\n      v4_(v4) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray4& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5>\nclass ValueArray5 {\n public:\n  ValueArray5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) : v1_(v1), v2_(v2), v3_(v3),\n      v4_(v4), v5_(v5) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray5& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6>\nclass ValueArray6 {\n public:\n  ValueArray6(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6) : v1_(v1), v2_(v2),\n      v3_(v3), v4_(v4), v5_(v5), v6_(v6) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray6& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7>\nclass ValueArray7 {\n public:\n  ValueArray7(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7) : v1_(v1),\n      v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray7& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8>\nclass ValueArray8 {\n public:\n  ValueArray8(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,\n      T8 v8) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray8& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9>\nclass ValueArray9 {\n public:\n  ValueArray9(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,\n      T9 v9) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray9& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10>\nclass ValueArray10 {\n public:\n  ValueArray10(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray10& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11>\nclass ValueArray11 {\n public:\n  ValueArray11(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),\n      v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray11& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12>\nclass ValueArray12 {\n public:\n  ValueArray12(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),\n      v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray12& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13>\nclass ValueArray13 {\n public:\n  ValueArray13(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),\n      v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),\n      v12_(v12), v13_(v13) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray13& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14>\nclass ValueArray14 {\n public:\n  ValueArray14(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14) : v1_(v1), v2_(v2), v3_(v3),\n      v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray14& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15>\nclass ValueArray15 {\n public:\n  ValueArray15(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15) : v1_(v1), v2_(v2),\n      v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray15& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16>\nclass ValueArray16 {\n public:\n  ValueArray16(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16) : v1_(v1),\n      v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),\n      v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),\n      v16_(v16) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray16& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17>\nclass ValueArray17 {\n public:\n  ValueArray17(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16,\n      T17 v17) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray17& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18>\nclass ValueArray18 {\n public:\n  ValueArray18(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17), v18_(v18) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray18& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19>\nclass ValueArray19 {\n public:\n  ValueArray19(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),\n      v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13),\n      v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray19& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20>\nclass ValueArray20 {\n public:\n  ValueArray20(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),\n      v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12),\n      v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18),\n      v19_(v19), v20_(v20) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray20& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21>\nclass ValueArray21 {\n public:\n  ValueArray21(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),\n      v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),\n      v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17),\n      v18_(v18), v19_(v19), v20_(v20), v21_(v21) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray21& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22>\nclass ValueArray22 {\n public:\n  ValueArray22(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22) : v1_(v1), v2_(v2), v3_(v3),\n      v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),\n      v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray22& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23>\nclass ValueArray23 {\n public:\n  ValueArray23(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23) : v1_(v1), v2_(v2),\n      v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),\n      v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),\n      v23_(v23) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_,\n        v23_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray23& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24>\nclass ValueArray24 {\n public:\n  ValueArray24(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24) : v1_(v1),\n      v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),\n      v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),\n      v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21),\n      v22_(v22), v23_(v23), v24_(v24) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray24& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25>\nclass ValueArray25 {\n public:\n  ValueArray25(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24,\n      T25 v25) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),\n      v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray25& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26>\nclass ValueArray26 {\n public:\n  ValueArray26(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),\n      v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray26& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27>\nclass ValueArray27 {\n public:\n  ValueArray27(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),\n      v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13),\n      v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19),\n      v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25),\n      v26_(v26), v27_(v27) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray27& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28>\nclass ValueArray28 {\n public:\n  ValueArray28(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),\n      v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12),\n      v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18),\n      v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24),\n      v25_(v25), v26_(v26), v27_(v27), v28_(v28) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray28& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29>\nclass ValueArray29 {\n public:\n  ValueArray29(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),\n      v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),\n      v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17),\n      v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23),\n      v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray29& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30>\nclass ValueArray30 {\n public:\n  ValueArray30(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30) : v1_(v1), v2_(v2), v3_(v3),\n      v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),\n      v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),\n      v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),\n      v29_(v29), v30_(v30) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray30& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31>\nclass ValueArray31 {\n public:\n  ValueArray31(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31) : v1_(v1), v2_(v2),\n      v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),\n      v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),\n      v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),\n      v29_(v29), v30_(v30), v31_(v31) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray31& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32>\nclass ValueArray32 {\n public:\n  ValueArray32(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32) : v1_(v1),\n      v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),\n      v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),\n      v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21),\n      v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27),\n      v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray32& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33>\nclass ValueArray33 {\n public:\n  ValueArray33(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32,\n      T33 v33) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),\n      v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),\n      v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),\n      v33_(v33) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray33& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34>\nclass ValueArray34 {\n public:\n  ValueArray34(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),\n      v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),\n      v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),\n      v33_(v33), v34_(v34) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray34& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35>\nclass ValueArray35 {\n public:\n  ValueArray35(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),\n      v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13),\n      v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19),\n      v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25),\n      v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31),\n      v32_(v32), v33_(v33), v34_(v34), v35_(v35) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_,\n        v35_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray35& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36>\nclass ValueArray36 {\n public:\n  ValueArray36(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),\n      v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12),\n      v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18),\n      v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24),\n      v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30),\n      v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35), v36_(v36) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray36& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37>\nclass ValueArray37 {\n public:\n  ValueArray37(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),\n      v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),\n      v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17),\n      v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23),\n      v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29),\n      v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35),\n      v36_(v36), v37_(v37) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray37& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38>\nclass ValueArray38 {\n public:\n  ValueArray38(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38) : v1_(v1), v2_(v2), v3_(v3),\n      v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),\n      v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),\n      v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),\n      v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34),\n      v35_(v35), v36_(v36), v37_(v37), v38_(v38) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray38& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39>\nclass ValueArray39 {\n public:\n  ValueArray39(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39) : v1_(v1), v2_(v2),\n      v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),\n      v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),\n      v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),\n      v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34),\n      v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray39& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40>\nclass ValueArray40 {\n public:\n  ValueArray40(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40) : v1_(v1),\n      v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),\n      v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),\n      v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21),\n      v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27),\n      v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33),\n      v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39),\n      v40_(v40) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray40& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41>\nclass ValueArray41 {\n public:\n  ValueArray41(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40,\n      T41 v41) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),\n      v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),\n      v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),\n      v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38),\n      v39_(v39), v40_(v40), v41_(v41) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray41& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42>\nclass ValueArray42 {\n public:\n  ValueArray42(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n      T42 v42) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),\n      v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),\n      v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),\n      v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38),\n      v39_(v39), v40_(v40), v41_(v41), v42_(v42) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_, v42_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray42& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n  const T42 v42_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43>\nclass ValueArray43 {\n public:\n  ValueArray43(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n      T42 v42, T43 v43) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),\n      v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13),\n      v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19),\n      v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25),\n      v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31),\n      v32_(v32), v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37),\n      v38_(v38), v39_(v39), v40_(v40), v41_(v41), v42_(v42), v43_(v43) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_, v42_, v43_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray43& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n  const T42 v42_;\n  const T43 v43_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44>\nclass ValueArray44 {\n public:\n  ValueArray44(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n      T42 v42, T43 v43, T44 v44) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),\n      v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12),\n      v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18),\n      v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24),\n      v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30),\n      v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35), v36_(v36),\n      v37_(v37), v38_(v38), v39_(v39), v40_(v40), v41_(v41), v42_(v42),\n      v43_(v43), v44_(v44) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_, v42_, v43_, v44_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray44& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n  const T42 v42_;\n  const T43 v43_;\n  const T44 v44_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45>\nclass ValueArray45 {\n public:\n  ValueArray45(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n      T42 v42, T43 v43, T44 v44, T45 v45) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),\n      v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),\n      v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17),\n      v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23),\n      v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29),\n      v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35),\n      v36_(v36), v37_(v37), v38_(v38), v39_(v39), v40_(v40), v41_(v41),\n      v42_(v42), v43_(v43), v44_(v44), v45_(v45) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_, v42_, v43_, v44_, v45_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray45& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n  const T42 v42_;\n  const T43 v43_;\n  const T44 v44_;\n  const T45 v45_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46>\nclass ValueArray46 {\n public:\n  ValueArray46(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n      T42 v42, T43 v43, T44 v44, T45 v45, T46 v46) : v1_(v1), v2_(v2), v3_(v3),\n      v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),\n      v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),\n      v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),\n      v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34),\n      v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39), v40_(v40),\n      v41_(v41), v42_(v42), v43_(v43), v44_(v44), v45_(v45), v46_(v46) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_, v42_, v43_, v44_, v45_, v46_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray46& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n  const T42 v42_;\n  const T43 v43_;\n  const T44 v44_;\n  const T45 v45_;\n  const T46 v46_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47>\nclass ValueArray47 {\n public:\n  ValueArray47(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n      T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47) : v1_(v1), v2_(v2),\n      v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),\n      v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),\n      v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),\n      v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),\n      v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34),\n      v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39), v40_(v40),\n      v41_(v41), v42_(v42), v43_(v43), v44_(v44), v45_(v45), v46_(v46),\n      v47_(v47) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_, v42_, v43_, v44_, v45_, v46_,\n        v47_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray47& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n  const T42 v42_;\n  const T43 v43_;\n  const T44 v44_;\n  const T45 v45_;\n  const T46 v46_;\n  const T47 v47_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48>\nclass ValueArray48 {\n public:\n  ValueArray48(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n      T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, T48 v48) : v1_(v1),\n      v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),\n      v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),\n      v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21),\n      v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27),\n      v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33),\n      v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39),\n      v40_(v40), v41_(v41), v42_(v42), v43_(v43), v44_(v44), v45_(v45),\n      v46_(v46), v47_(v47), v48_(v48) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_, v42_, v43_, v44_, v45_, v46_, v47_,\n        v48_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray48& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n  const T42 v42_;\n  const T43 v43_;\n  const T44 v44_;\n  const T45 v45_;\n  const T46 v46_;\n  const T47 v47_;\n  const T48 v48_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48, typename T49>\nclass ValueArray49 {\n public:\n  ValueArray49(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n      T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, T48 v48,\n      T49 v49) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),\n      v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),\n      v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),\n      v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38),\n      v39_(v39), v40_(v40), v41_(v41), v42_(v42), v43_(v43), v44_(v44),\n      v45_(v45), v46_(v46), v47_(v47), v48_(v48), v49_(v49) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_, v42_, v43_, v44_, v45_, v46_, v47_,\n        v48_, v49_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray49& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n  const T42 v42_;\n  const T43 v43_;\n  const T44 v44_;\n  const T45 v45_;\n  const T46 v46_;\n  const T47 v47_;\n  const T48 v48_;\n  const T49 v49_;\n};\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48, typename T49, typename T50>\nclass ValueArray50 {\n public:\n  ValueArray50(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n      T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n      T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n      T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n      T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n      T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, T48 v48, T49 v49,\n      T50 v50) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),\n      v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),\n      v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),\n      v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),\n      v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),\n      v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38),\n      v39_(v39), v40_(v40), v41_(v41), v42_(v42), v43_(v43), v44_(v44),\n      v45_(v45), v46_(v46), v47_(v47), v48_(v48), v49_(v49), v50_(v50) {}\n\n  template <typename T>\n  operator ParamGenerator<T>() const {\n    const T array[] = {v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_,\n        v12_, v13_, v14_, v15_, v16_, v17_, v18_, v19_, v20_, v21_, v22_, v23_,\n        v24_, v25_, v26_, v27_, v28_, v29_, v30_, v31_, v32_, v33_, v34_, v35_,\n        v36_, v37_, v38_, v39_, v40_, v41_, v42_, v43_, v44_, v45_, v46_, v47_,\n        v48_, v49_, v50_};\n    return ValuesIn(array);\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const ValueArray50& other);\n\n  const T1 v1_;\n  const T2 v2_;\n  const T3 v3_;\n  const T4 v4_;\n  const T5 v5_;\n  const T6 v6_;\n  const T7 v7_;\n  const T8 v8_;\n  const T9 v9_;\n  const T10 v10_;\n  const T11 v11_;\n  const T12 v12_;\n  const T13 v13_;\n  const T14 v14_;\n  const T15 v15_;\n  const T16 v16_;\n  const T17 v17_;\n  const T18 v18_;\n  const T19 v19_;\n  const T20 v20_;\n  const T21 v21_;\n  const T22 v22_;\n  const T23 v23_;\n  const T24 v24_;\n  const T25 v25_;\n  const T26 v26_;\n  const T27 v27_;\n  const T28 v28_;\n  const T29 v29_;\n  const T30 v30_;\n  const T31 v31_;\n  const T32 v32_;\n  const T33 v33_;\n  const T34 v34_;\n  const T35 v35_;\n  const T36 v36_;\n  const T37 v37_;\n  const T38 v38_;\n  const T39 v39_;\n  const T40 v40_;\n  const T41 v41_;\n  const T42 v42_;\n  const T43 v43_;\n  const T44 v44_;\n  const T45 v45_;\n  const T46 v46_;\n  const T47 v47_;\n  const T48 v48_;\n  const T49 v49_;\n  const T50 v50_;\n};\n\n# if GTEST_HAS_COMBINE\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// Generates values from the Cartesian product of values produced\n// by the argument generators.\n//\ntemplate <typename T1, typename T2>\nclass CartesianProductGenerator2\n    : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2> > {\n public:\n  typedef ::std::tr1::tuple<T1, T2> ParamType;\n\n  CartesianProductGenerator2(const ParamGenerator<T1>& g1,\n      const ParamGenerator<T2>& g2)\n      : g1_(g1), g2_(g2) {}\n  virtual ~CartesianProductGenerator2() {}\n\n  virtual ParamIteratorInterface<ParamType>* Begin() const {\n    return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin());\n  }\n  virtual ParamIteratorInterface<ParamType>* End() const {\n    return new Iterator(this, g1_, g1_.end(), g2_, g2_.end());\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<ParamType> {\n   public:\n    Iterator(const ParamGeneratorInterface<ParamType>* base,\n      const ParamGenerator<T1>& g1,\n      const typename ParamGenerator<T1>::iterator& current1,\n      const ParamGenerator<T2>& g2,\n      const typename ParamGenerator<T2>::iterator& current2)\n        : base_(base),\n          begin1_(g1.begin()), end1_(g1.end()), current1_(current1),\n          begin2_(g2.begin()), end2_(g2.end()), current2_(current2)    {\n      ComputeCurrentValue();\n    }\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {\n      return base_;\n    }\n    // Advance should not be called on beyond-of-range iterators\n    // so no component iterators must be beyond end of range, either.\n    virtual void Advance() {\n      assert(!AtEnd());\n      ++current2_;\n      if (current2_ == end2_) {\n        current2_ = begin2_;\n        ++current1_;\n      }\n      ComputeCurrentValue();\n    }\n    virtual ParamIteratorInterface<ParamType>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const ParamType* Current() const { return &current_value_; }\n    virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const Iterator* typed_other =\n          CheckedDowncastToActualType<const Iterator>(&other);\n      // We must report iterators equal if they both point beyond their\n      // respective ranges. That can happen in a variety of fashions,\n      // so we have to consult AtEnd().\n      return (AtEnd() && typed_other->AtEnd()) ||\n         (\n          current1_ == typed_other->current1_ &&\n          current2_ == typed_other->current2_);\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : base_(other.base_),\n        begin1_(other.begin1_),\n        end1_(other.end1_),\n        current1_(other.current1_),\n        begin2_(other.begin2_),\n        end2_(other.end2_),\n        current2_(other.current2_) {\n      ComputeCurrentValue();\n    }\n\n    void ComputeCurrentValue() {\n      if (!AtEnd())\n        current_value_ = ParamType(*current1_, *current2_);\n    }\n    bool AtEnd() const {\n      // We must report iterator past the end of the range when either of the\n      // component iterators has reached the end of its range.\n      return\n          current1_ == end1_ ||\n          current2_ == end2_;\n    }\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<ParamType>* const base_;\n    // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.\n    // current[i]_ is the actual traversing iterator.\n    const typename ParamGenerator<T1>::iterator begin1_;\n    const typename ParamGenerator<T1>::iterator end1_;\n    typename ParamGenerator<T1>::iterator current1_;\n    const typename ParamGenerator<T2>::iterator begin2_;\n    const typename ParamGenerator<T2>::iterator end2_;\n    typename ParamGenerator<T2>::iterator current2_;\n    ParamType current_value_;\n  };  // class CartesianProductGenerator2::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductGenerator2& other);\n\n  const ParamGenerator<T1> g1_;\n  const ParamGenerator<T2> g2_;\n};  // class CartesianProductGenerator2\n\n\ntemplate <typename T1, typename T2, typename T3>\nclass CartesianProductGenerator3\n    : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3> > {\n public:\n  typedef ::std::tr1::tuple<T1, T2, T3> ParamType;\n\n  CartesianProductGenerator3(const ParamGenerator<T1>& g1,\n      const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3)\n      : g1_(g1), g2_(g2), g3_(g3) {}\n  virtual ~CartesianProductGenerator3() {}\n\n  virtual ParamIteratorInterface<ParamType>* Begin() const {\n    return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,\n        g3_.begin());\n  }\n  virtual ParamIteratorInterface<ParamType>* End() const {\n    return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end());\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<ParamType> {\n   public:\n    Iterator(const ParamGeneratorInterface<ParamType>* base,\n      const ParamGenerator<T1>& g1,\n      const typename ParamGenerator<T1>::iterator& current1,\n      const ParamGenerator<T2>& g2,\n      const typename ParamGenerator<T2>::iterator& current2,\n      const ParamGenerator<T3>& g3,\n      const typename ParamGenerator<T3>::iterator& current3)\n        : base_(base),\n          begin1_(g1.begin()), end1_(g1.end()), current1_(current1),\n          begin2_(g2.begin()), end2_(g2.end()), current2_(current2),\n          begin3_(g3.begin()), end3_(g3.end()), current3_(current3)    {\n      ComputeCurrentValue();\n    }\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {\n      return base_;\n    }\n    // Advance should not be called on beyond-of-range iterators\n    // so no component iterators must be beyond end of range, either.\n    virtual void Advance() {\n      assert(!AtEnd());\n      ++current3_;\n      if (current3_ == end3_) {\n        current3_ = begin3_;\n        ++current2_;\n      }\n      if (current2_ == end2_) {\n        current2_ = begin2_;\n        ++current1_;\n      }\n      ComputeCurrentValue();\n    }\n    virtual ParamIteratorInterface<ParamType>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const ParamType* Current() const { return &current_value_; }\n    virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const Iterator* typed_other =\n          CheckedDowncastToActualType<const Iterator>(&other);\n      // We must report iterators equal if they both point beyond their\n      // respective ranges. That can happen in a variety of fashions,\n      // so we have to consult AtEnd().\n      return (AtEnd() && typed_other->AtEnd()) ||\n         (\n          current1_ == typed_other->current1_ &&\n          current2_ == typed_other->current2_ &&\n          current3_ == typed_other->current3_);\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : base_(other.base_),\n        begin1_(other.begin1_),\n        end1_(other.end1_),\n        current1_(other.current1_),\n        begin2_(other.begin2_),\n        end2_(other.end2_),\n        current2_(other.current2_),\n        begin3_(other.begin3_),\n        end3_(other.end3_),\n        current3_(other.current3_) {\n      ComputeCurrentValue();\n    }\n\n    void ComputeCurrentValue() {\n      if (!AtEnd())\n        current_value_ = ParamType(*current1_, *current2_, *current3_);\n    }\n    bool AtEnd() const {\n      // We must report iterator past the end of the range when either of the\n      // component iterators has reached the end of its range.\n      return\n          current1_ == end1_ ||\n          current2_ == end2_ ||\n          current3_ == end3_;\n    }\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<ParamType>* const base_;\n    // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.\n    // current[i]_ is the actual traversing iterator.\n    const typename ParamGenerator<T1>::iterator begin1_;\n    const typename ParamGenerator<T1>::iterator end1_;\n    typename ParamGenerator<T1>::iterator current1_;\n    const typename ParamGenerator<T2>::iterator begin2_;\n    const typename ParamGenerator<T2>::iterator end2_;\n    typename ParamGenerator<T2>::iterator current2_;\n    const typename ParamGenerator<T3>::iterator begin3_;\n    const typename ParamGenerator<T3>::iterator end3_;\n    typename ParamGenerator<T3>::iterator current3_;\n    ParamType current_value_;\n  };  // class CartesianProductGenerator3::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductGenerator3& other);\n\n  const ParamGenerator<T1> g1_;\n  const ParamGenerator<T2> g2_;\n  const ParamGenerator<T3> g3_;\n};  // class CartesianProductGenerator3\n\n\ntemplate <typename T1, typename T2, typename T3, typename T4>\nclass CartesianProductGenerator4\n    : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4> > {\n public:\n  typedef ::std::tr1::tuple<T1, T2, T3, T4> ParamType;\n\n  CartesianProductGenerator4(const ParamGenerator<T1>& g1,\n      const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,\n      const ParamGenerator<T4>& g4)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4) {}\n  virtual ~CartesianProductGenerator4() {}\n\n  virtual ParamIteratorInterface<ParamType>* Begin() const {\n    return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,\n        g3_.begin(), g4_, g4_.begin());\n  }\n  virtual ParamIteratorInterface<ParamType>* End() const {\n    return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),\n        g4_, g4_.end());\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<ParamType> {\n   public:\n    Iterator(const ParamGeneratorInterface<ParamType>* base,\n      const ParamGenerator<T1>& g1,\n      const typename ParamGenerator<T1>::iterator& current1,\n      const ParamGenerator<T2>& g2,\n      const typename ParamGenerator<T2>::iterator& current2,\n      const ParamGenerator<T3>& g3,\n      const typename ParamGenerator<T3>::iterator& current3,\n      const ParamGenerator<T4>& g4,\n      const typename ParamGenerator<T4>::iterator& current4)\n        : base_(base),\n          begin1_(g1.begin()), end1_(g1.end()), current1_(current1),\n          begin2_(g2.begin()), end2_(g2.end()), current2_(current2),\n          begin3_(g3.begin()), end3_(g3.end()), current3_(current3),\n          begin4_(g4.begin()), end4_(g4.end()), current4_(current4)    {\n      ComputeCurrentValue();\n    }\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {\n      return base_;\n    }\n    // Advance should not be called on beyond-of-range iterators\n    // so no component iterators must be beyond end of range, either.\n    virtual void Advance() {\n      assert(!AtEnd());\n      ++current4_;\n      if (current4_ == end4_) {\n        current4_ = begin4_;\n        ++current3_;\n      }\n      if (current3_ == end3_) {\n        current3_ = begin3_;\n        ++current2_;\n      }\n      if (current2_ == end2_) {\n        current2_ = begin2_;\n        ++current1_;\n      }\n      ComputeCurrentValue();\n    }\n    virtual ParamIteratorInterface<ParamType>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const ParamType* Current() const { return &current_value_; }\n    virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const Iterator* typed_other =\n          CheckedDowncastToActualType<const Iterator>(&other);\n      // We must report iterators equal if they both point beyond their\n      // respective ranges. That can happen in a variety of fashions,\n      // so we have to consult AtEnd().\n      return (AtEnd() && typed_other->AtEnd()) ||\n         (\n          current1_ == typed_other->current1_ &&\n          current2_ == typed_other->current2_ &&\n          current3_ == typed_other->current3_ &&\n          current4_ == typed_other->current4_);\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : base_(other.base_),\n        begin1_(other.begin1_),\n        end1_(other.end1_),\n        current1_(other.current1_),\n        begin2_(other.begin2_),\n        end2_(other.end2_),\n        current2_(other.current2_),\n        begin3_(other.begin3_),\n        end3_(other.end3_),\n        current3_(other.current3_),\n        begin4_(other.begin4_),\n        end4_(other.end4_),\n        current4_(other.current4_) {\n      ComputeCurrentValue();\n    }\n\n    void ComputeCurrentValue() {\n      if (!AtEnd())\n        current_value_ = ParamType(*current1_, *current2_, *current3_,\n            *current4_);\n    }\n    bool AtEnd() const {\n      // We must report iterator past the end of the range when either of the\n      // component iterators has reached the end of its range.\n      return\n          current1_ == end1_ ||\n          current2_ == end2_ ||\n          current3_ == end3_ ||\n          current4_ == end4_;\n    }\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<ParamType>* const base_;\n    // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.\n    // current[i]_ is the actual traversing iterator.\n    const typename ParamGenerator<T1>::iterator begin1_;\n    const typename ParamGenerator<T1>::iterator end1_;\n    typename ParamGenerator<T1>::iterator current1_;\n    const typename ParamGenerator<T2>::iterator begin2_;\n    const typename ParamGenerator<T2>::iterator end2_;\n    typename ParamGenerator<T2>::iterator current2_;\n    const typename ParamGenerator<T3>::iterator begin3_;\n    const typename ParamGenerator<T3>::iterator end3_;\n    typename ParamGenerator<T3>::iterator current3_;\n    const typename ParamGenerator<T4>::iterator begin4_;\n    const typename ParamGenerator<T4>::iterator end4_;\n    typename ParamGenerator<T4>::iterator current4_;\n    ParamType current_value_;\n  };  // class CartesianProductGenerator4::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductGenerator4& other);\n\n  const ParamGenerator<T1> g1_;\n  const ParamGenerator<T2> g2_;\n  const ParamGenerator<T3> g3_;\n  const ParamGenerator<T4> g4_;\n};  // class CartesianProductGenerator4\n\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5>\nclass CartesianProductGenerator5\n    : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5> > {\n public:\n  typedef ::std::tr1::tuple<T1, T2, T3, T4, T5> ParamType;\n\n  CartesianProductGenerator5(const ParamGenerator<T1>& g1,\n      const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,\n      const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5) {}\n  virtual ~CartesianProductGenerator5() {}\n\n  virtual ParamIteratorInterface<ParamType>* Begin() const {\n    return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,\n        g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin());\n  }\n  virtual ParamIteratorInterface<ParamType>* End() const {\n    return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),\n        g4_, g4_.end(), g5_, g5_.end());\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<ParamType> {\n   public:\n    Iterator(const ParamGeneratorInterface<ParamType>* base,\n      const ParamGenerator<T1>& g1,\n      const typename ParamGenerator<T1>::iterator& current1,\n      const ParamGenerator<T2>& g2,\n      const typename ParamGenerator<T2>::iterator& current2,\n      const ParamGenerator<T3>& g3,\n      const typename ParamGenerator<T3>::iterator& current3,\n      const ParamGenerator<T4>& g4,\n      const typename ParamGenerator<T4>::iterator& current4,\n      const ParamGenerator<T5>& g5,\n      const typename ParamGenerator<T5>::iterator& current5)\n        : base_(base),\n          begin1_(g1.begin()), end1_(g1.end()), current1_(current1),\n          begin2_(g2.begin()), end2_(g2.end()), current2_(current2),\n          begin3_(g3.begin()), end3_(g3.end()), current3_(current3),\n          begin4_(g4.begin()), end4_(g4.end()), current4_(current4),\n          begin5_(g5.begin()), end5_(g5.end()), current5_(current5)    {\n      ComputeCurrentValue();\n    }\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {\n      return base_;\n    }\n    // Advance should not be called on beyond-of-range iterators\n    // so no component iterators must be beyond end of range, either.\n    virtual void Advance() {\n      assert(!AtEnd());\n      ++current5_;\n      if (current5_ == end5_) {\n        current5_ = begin5_;\n        ++current4_;\n      }\n      if (current4_ == end4_) {\n        current4_ = begin4_;\n        ++current3_;\n      }\n      if (current3_ == end3_) {\n        current3_ = begin3_;\n        ++current2_;\n      }\n      if (current2_ == end2_) {\n        current2_ = begin2_;\n        ++current1_;\n      }\n      ComputeCurrentValue();\n    }\n    virtual ParamIteratorInterface<ParamType>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const ParamType* Current() const { return &current_value_; }\n    virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const Iterator* typed_other =\n          CheckedDowncastToActualType<const Iterator>(&other);\n      // We must report iterators equal if they both point beyond their\n      // respective ranges. That can happen in a variety of fashions,\n      // so we have to consult AtEnd().\n      return (AtEnd() && typed_other->AtEnd()) ||\n         (\n          current1_ == typed_other->current1_ &&\n          current2_ == typed_other->current2_ &&\n          current3_ == typed_other->current3_ &&\n          current4_ == typed_other->current4_ &&\n          current5_ == typed_other->current5_);\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : base_(other.base_),\n        begin1_(other.begin1_),\n        end1_(other.end1_),\n        current1_(other.current1_),\n        begin2_(other.begin2_),\n        end2_(other.end2_),\n        current2_(other.current2_),\n        begin3_(other.begin3_),\n        end3_(other.end3_),\n        current3_(other.current3_),\n        begin4_(other.begin4_),\n        end4_(other.end4_),\n        current4_(other.current4_),\n        begin5_(other.begin5_),\n        end5_(other.end5_),\n        current5_(other.current5_) {\n      ComputeCurrentValue();\n    }\n\n    void ComputeCurrentValue() {\n      if (!AtEnd())\n        current_value_ = ParamType(*current1_, *current2_, *current3_,\n            *current4_, *current5_);\n    }\n    bool AtEnd() const {\n      // We must report iterator past the end of the range when either of the\n      // component iterators has reached the end of its range.\n      return\n          current1_ == end1_ ||\n          current2_ == end2_ ||\n          current3_ == end3_ ||\n          current4_ == end4_ ||\n          current5_ == end5_;\n    }\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<ParamType>* const base_;\n    // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.\n    // current[i]_ is the actual traversing iterator.\n    const typename ParamGenerator<T1>::iterator begin1_;\n    const typename ParamGenerator<T1>::iterator end1_;\n    typename ParamGenerator<T1>::iterator current1_;\n    const typename ParamGenerator<T2>::iterator begin2_;\n    const typename ParamGenerator<T2>::iterator end2_;\n    typename ParamGenerator<T2>::iterator current2_;\n    const typename ParamGenerator<T3>::iterator begin3_;\n    const typename ParamGenerator<T3>::iterator end3_;\n    typename ParamGenerator<T3>::iterator current3_;\n    const typename ParamGenerator<T4>::iterator begin4_;\n    const typename ParamGenerator<T4>::iterator end4_;\n    typename ParamGenerator<T4>::iterator current4_;\n    const typename ParamGenerator<T5>::iterator begin5_;\n    const typename ParamGenerator<T5>::iterator end5_;\n    typename ParamGenerator<T5>::iterator current5_;\n    ParamType current_value_;\n  };  // class CartesianProductGenerator5::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductGenerator5& other);\n\n  const ParamGenerator<T1> g1_;\n  const ParamGenerator<T2> g2_;\n  const ParamGenerator<T3> g3_;\n  const ParamGenerator<T4> g4_;\n  const ParamGenerator<T5> g5_;\n};  // class CartesianProductGenerator5\n\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6>\nclass CartesianProductGenerator6\n    : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5,\n        T6> > {\n public:\n  typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6> ParamType;\n\n  CartesianProductGenerator6(const ParamGenerator<T1>& g1,\n      const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,\n      const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,\n      const ParamGenerator<T6>& g6)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6) {}\n  virtual ~CartesianProductGenerator6() {}\n\n  virtual ParamIteratorInterface<ParamType>* Begin() const {\n    return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,\n        g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin());\n  }\n  virtual ParamIteratorInterface<ParamType>* End() const {\n    return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),\n        g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end());\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<ParamType> {\n   public:\n    Iterator(const ParamGeneratorInterface<ParamType>* base,\n      const ParamGenerator<T1>& g1,\n      const typename ParamGenerator<T1>::iterator& current1,\n      const ParamGenerator<T2>& g2,\n      const typename ParamGenerator<T2>::iterator& current2,\n      const ParamGenerator<T3>& g3,\n      const typename ParamGenerator<T3>::iterator& current3,\n      const ParamGenerator<T4>& g4,\n      const typename ParamGenerator<T4>::iterator& current4,\n      const ParamGenerator<T5>& g5,\n      const typename ParamGenerator<T5>::iterator& current5,\n      const ParamGenerator<T6>& g6,\n      const typename ParamGenerator<T6>::iterator& current6)\n        : base_(base),\n          begin1_(g1.begin()), end1_(g1.end()), current1_(current1),\n          begin2_(g2.begin()), end2_(g2.end()), current2_(current2),\n          begin3_(g3.begin()), end3_(g3.end()), current3_(current3),\n          begin4_(g4.begin()), end4_(g4.end()), current4_(current4),\n          begin5_(g5.begin()), end5_(g5.end()), current5_(current5),\n          begin6_(g6.begin()), end6_(g6.end()), current6_(current6)    {\n      ComputeCurrentValue();\n    }\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {\n      return base_;\n    }\n    // Advance should not be called on beyond-of-range iterators\n    // so no component iterators must be beyond end of range, either.\n    virtual void Advance() {\n      assert(!AtEnd());\n      ++current6_;\n      if (current6_ == end6_) {\n        current6_ = begin6_;\n        ++current5_;\n      }\n      if (current5_ == end5_) {\n        current5_ = begin5_;\n        ++current4_;\n      }\n      if (current4_ == end4_) {\n        current4_ = begin4_;\n        ++current3_;\n      }\n      if (current3_ == end3_) {\n        current3_ = begin3_;\n        ++current2_;\n      }\n      if (current2_ == end2_) {\n        current2_ = begin2_;\n        ++current1_;\n      }\n      ComputeCurrentValue();\n    }\n    virtual ParamIteratorInterface<ParamType>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const ParamType* Current() const { return &current_value_; }\n    virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const Iterator* typed_other =\n          CheckedDowncastToActualType<const Iterator>(&other);\n      // We must report iterators equal if they both point beyond their\n      // respective ranges. That can happen in a variety of fashions,\n      // so we have to consult AtEnd().\n      return (AtEnd() && typed_other->AtEnd()) ||\n         (\n          current1_ == typed_other->current1_ &&\n          current2_ == typed_other->current2_ &&\n          current3_ == typed_other->current3_ &&\n          current4_ == typed_other->current4_ &&\n          current5_ == typed_other->current5_ &&\n          current6_ == typed_other->current6_);\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : base_(other.base_),\n        begin1_(other.begin1_),\n        end1_(other.end1_),\n        current1_(other.current1_),\n        begin2_(other.begin2_),\n        end2_(other.end2_),\n        current2_(other.current2_),\n        begin3_(other.begin3_),\n        end3_(other.end3_),\n        current3_(other.current3_),\n        begin4_(other.begin4_),\n        end4_(other.end4_),\n        current4_(other.current4_),\n        begin5_(other.begin5_),\n        end5_(other.end5_),\n        current5_(other.current5_),\n        begin6_(other.begin6_),\n        end6_(other.end6_),\n        current6_(other.current6_) {\n      ComputeCurrentValue();\n    }\n\n    void ComputeCurrentValue() {\n      if (!AtEnd())\n        current_value_ = ParamType(*current1_, *current2_, *current3_,\n            *current4_, *current5_, *current6_);\n    }\n    bool AtEnd() const {\n      // We must report iterator past the end of the range when either of the\n      // component iterators has reached the end of its range.\n      return\n          current1_ == end1_ ||\n          current2_ == end2_ ||\n          current3_ == end3_ ||\n          current4_ == end4_ ||\n          current5_ == end5_ ||\n          current6_ == end6_;\n    }\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<ParamType>* const base_;\n    // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.\n    // current[i]_ is the actual traversing iterator.\n    const typename ParamGenerator<T1>::iterator begin1_;\n    const typename ParamGenerator<T1>::iterator end1_;\n    typename ParamGenerator<T1>::iterator current1_;\n    const typename ParamGenerator<T2>::iterator begin2_;\n    const typename ParamGenerator<T2>::iterator end2_;\n    typename ParamGenerator<T2>::iterator current2_;\n    const typename ParamGenerator<T3>::iterator begin3_;\n    const typename ParamGenerator<T3>::iterator end3_;\n    typename ParamGenerator<T3>::iterator current3_;\n    const typename ParamGenerator<T4>::iterator begin4_;\n    const typename ParamGenerator<T4>::iterator end4_;\n    typename ParamGenerator<T4>::iterator current4_;\n    const typename ParamGenerator<T5>::iterator begin5_;\n    const typename ParamGenerator<T5>::iterator end5_;\n    typename ParamGenerator<T5>::iterator current5_;\n    const typename ParamGenerator<T6>::iterator begin6_;\n    const typename ParamGenerator<T6>::iterator end6_;\n    typename ParamGenerator<T6>::iterator current6_;\n    ParamType current_value_;\n  };  // class CartesianProductGenerator6::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductGenerator6& other);\n\n  const ParamGenerator<T1> g1_;\n  const ParamGenerator<T2> g2_;\n  const ParamGenerator<T3> g3_;\n  const ParamGenerator<T4> g4_;\n  const ParamGenerator<T5> g5_;\n  const ParamGenerator<T6> g6_;\n};  // class CartesianProductGenerator6\n\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7>\nclass CartesianProductGenerator7\n    : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,\n        T7> > {\n public:\n  typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7> ParamType;\n\n  CartesianProductGenerator7(const ParamGenerator<T1>& g1,\n      const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,\n      const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,\n      const ParamGenerator<T6>& g6, const ParamGenerator<T7>& g7)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7) {}\n  virtual ~CartesianProductGenerator7() {}\n\n  virtual ParamIteratorInterface<ParamType>* Begin() const {\n    return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,\n        g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_,\n        g7_.begin());\n  }\n  virtual ParamIteratorInterface<ParamType>* End() const {\n    return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),\n        g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end());\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<ParamType> {\n   public:\n    Iterator(const ParamGeneratorInterface<ParamType>* base,\n      const ParamGenerator<T1>& g1,\n      const typename ParamGenerator<T1>::iterator& current1,\n      const ParamGenerator<T2>& g2,\n      const typename ParamGenerator<T2>::iterator& current2,\n      const ParamGenerator<T3>& g3,\n      const typename ParamGenerator<T3>::iterator& current3,\n      const ParamGenerator<T4>& g4,\n      const typename ParamGenerator<T4>::iterator& current4,\n      const ParamGenerator<T5>& g5,\n      const typename ParamGenerator<T5>::iterator& current5,\n      const ParamGenerator<T6>& g6,\n      const typename ParamGenerator<T6>::iterator& current6,\n      const ParamGenerator<T7>& g7,\n      const typename ParamGenerator<T7>::iterator& current7)\n        : base_(base),\n          begin1_(g1.begin()), end1_(g1.end()), current1_(current1),\n          begin2_(g2.begin()), end2_(g2.end()), current2_(current2),\n          begin3_(g3.begin()), end3_(g3.end()), current3_(current3),\n          begin4_(g4.begin()), end4_(g4.end()), current4_(current4),\n          begin5_(g5.begin()), end5_(g5.end()), current5_(current5),\n          begin6_(g6.begin()), end6_(g6.end()), current6_(current6),\n          begin7_(g7.begin()), end7_(g7.end()), current7_(current7)    {\n      ComputeCurrentValue();\n    }\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {\n      return base_;\n    }\n    // Advance should not be called on beyond-of-range iterators\n    // so no component iterators must be beyond end of range, either.\n    virtual void Advance() {\n      assert(!AtEnd());\n      ++current7_;\n      if (current7_ == end7_) {\n        current7_ = begin7_;\n        ++current6_;\n      }\n      if (current6_ == end6_) {\n        current6_ = begin6_;\n        ++current5_;\n      }\n      if (current5_ == end5_) {\n        current5_ = begin5_;\n        ++current4_;\n      }\n      if (current4_ == end4_) {\n        current4_ = begin4_;\n        ++current3_;\n      }\n      if (current3_ == end3_) {\n        current3_ = begin3_;\n        ++current2_;\n      }\n      if (current2_ == end2_) {\n        current2_ = begin2_;\n        ++current1_;\n      }\n      ComputeCurrentValue();\n    }\n    virtual ParamIteratorInterface<ParamType>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const ParamType* Current() const { return &current_value_; }\n    virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const Iterator* typed_other =\n          CheckedDowncastToActualType<const Iterator>(&other);\n      // We must report iterators equal if they both point beyond their\n      // respective ranges. That can happen in a variety of fashions,\n      // so we have to consult AtEnd().\n      return (AtEnd() && typed_other->AtEnd()) ||\n         (\n          current1_ == typed_other->current1_ &&\n          current2_ == typed_other->current2_ &&\n          current3_ == typed_other->current3_ &&\n          current4_ == typed_other->current4_ &&\n          current5_ == typed_other->current5_ &&\n          current6_ == typed_other->current6_ &&\n          current7_ == typed_other->current7_);\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : base_(other.base_),\n        begin1_(other.begin1_),\n        end1_(other.end1_),\n        current1_(other.current1_),\n        begin2_(other.begin2_),\n        end2_(other.end2_),\n        current2_(other.current2_),\n        begin3_(other.begin3_),\n        end3_(other.end3_),\n        current3_(other.current3_),\n        begin4_(other.begin4_),\n        end4_(other.end4_),\n        current4_(other.current4_),\n        begin5_(other.begin5_),\n        end5_(other.end5_),\n        current5_(other.current5_),\n        begin6_(other.begin6_),\n        end6_(other.end6_),\n        current6_(other.current6_),\n        begin7_(other.begin7_),\n        end7_(other.end7_),\n        current7_(other.current7_) {\n      ComputeCurrentValue();\n    }\n\n    void ComputeCurrentValue() {\n      if (!AtEnd())\n        current_value_ = ParamType(*current1_, *current2_, *current3_,\n            *current4_, *current5_, *current6_, *current7_);\n    }\n    bool AtEnd() const {\n      // We must report iterator past the end of the range when either of the\n      // component iterators has reached the end of its range.\n      return\n          current1_ == end1_ ||\n          current2_ == end2_ ||\n          current3_ == end3_ ||\n          current4_ == end4_ ||\n          current5_ == end5_ ||\n          current6_ == end6_ ||\n          current7_ == end7_;\n    }\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<ParamType>* const base_;\n    // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.\n    // current[i]_ is the actual traversing iterator.\n    const typename ParamGenerator<T1>::iterator begin1_;\n    const typename ParamGenerator<T1>::iterator end1_;\n    typename ParamGenerator<T1>::iterator current1_;\n    const typename ParamGenerator<T2>::iterator begin2_;\n    const typename ParamGenerator<T2>::iterator end2_;\n    typename ParamGenerator<T2>::iterator current2_;\n    const typename ParamGenerator<T3>::iterator begin3_;\n    const typename ParamGenerator<T3>::iterator end3_;\n    typename ParamGenerator<T3>::iterator current3_;\n    const typename ParamGenerator<T4>::iterator begin4_;\n    const typename ParamGenerator<T4>::iterator end4_;\n    typename ParamGenerator<T4>::iterator current4_;\n    const typename ParamGenerator<T5>::iterator begin5_;\n    const typename ParamGenerator<T5>::iterator end5_;\n    typename ParamGenerator<T5>::iterator current5_;\n    const typename ParamGenerator<T6>::iterator begin6_;\n    const typename ParamGenerator<T6>::iterator end6_;\n    typename ParamGenerator<T6>::iterator current6_;\n    const typename ParamGenerator<T7>::iterator begin7_;\n    const typename ParamGenerator<T7>::iterator end7_;\n    typename ParamGenerator<T7>::iterator current7_;\n    ParamType current_value_;\n  };  // class CartesianProductGenerator7::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductGenerator7& other);\n\n  const ParamGenerator<T1> g1_;\n  const ParamGenerator<T2> g2_;\n  const ParamGenerator<T3> g3_;\n  const ParamGenerator<T4> g4_;\n  const ParamGenerator<T5> g5_;\n  const ParamGenerator<T6> g6_;\n  const ParamGenerator<T7> g7_;\n};  // class CartesianProductGenerator7\n\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8>\nclass CartesianProductGenerator8\n    : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,\n        T7, T8> > {\n public:\n  typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8> ParamType;\n\n  CartesianProductGenerator8(const ParamGenerator<T1>& g1,\n      const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,\n      const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,\n      const ParamGenerator<T6>& g6, const ParamGenerator<T7>& g7,\n      const ParamGenerator<T8>& g8)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7),\n          g8_(g8) {}\n  virtual ~CartesianProductGenerator8() {}\n\n  virtual ParamIteratorInterface<ParamType>* Begin() const {\n    return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,\n        g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_,\n        g7_.begin(), g8_, g8_.begin());\n  }\n  virtual ParamIteratorInterface<ParamType>* End() const {\n    return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),\n        g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end(), g8_,\n        g8_.end());\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<ParamType> {\n   public:\n    Iterator(const ParamGeneratorInterface<ParamType>* base,\n      const ParamGenerator<T1>& g1,\n      const typename ParamGenerator<T1>::iterator& current1,\n      const ParamGenerator<T2>& g2,\n      const typename ParamGenerator<T2>::iterator& current2,\n      const ParamGenerator<T3>& g3,\n      const typename ParamGenerator<T3>::iterator& current3,\n      const ParamGenerator<T4>& g4,\n      const typename ParamGenerator<T4>::iterator& current4,\n      const ParamGenerator<T5>& g5,\n      const typename ParamGenerator<T5>::iterator& current5,\n      const ParamGenerator<T6>& g6,\n      const typename ParamGenerator<T6>::iterator& current6,\n      const ParamGenerator<T7>& g7,\n      const typename ParamGenerator<T7>::iterator& current7,\n      const ParamGenerator<T8>& g8,\n      const typename ParamGenerator<T8>::iterator& current8)\n        : base_(base),\n          begin1_(g1.begin()), end1_(g1.end()), current1_(current1),\n          begin2_(g2.begin()), end2_(g2.end()), current2_(current2),\n          begin3_(g3.begin()), end3_(g3.end()), current3_(current3),\n          begin4_(g4.begin()), end4_(g4.end()), current4_(current4),\n          begin5_(g5.begin()), end5_(g5.end()), current5_(current5),\n          begin6_(g6.begin()), end6_(g6.end()), current6_(current6),\n          begin7_(g7.begin()), end7_(g7.end()), current7_(current7),\n          begin8_(g8.begin()), end8_(g8.end()), current8_(current8)    {\n      ComputeCurrentValue();\n    }\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {\n      return base_;\n    }\n    // Advance should not be called on beyond-of-range iterators\n    // so no component iterators must be beyond end of range, either.\n    virtual void Advance() {\n      assert(!AtEnd());\n      ++current8_;\n      if (current8_ == end8_) {\n        current8_ = begin8_;\n        ++current7_;\n      }\n      if (current7_ == end7_) {\n        current7_ = begin7_;\n        ++current6_;\n      }\n      if (current6_ == end6_) {\n        current6_ = begin6_;\n        ++current5_;\n      }\n      if (current5_ == end5_) {\n        current5_ = begin5_;\n        ++current4_;\n      }\n      if (current4_ == end4_) {\n        current4_ = begin4_;\n        ++current3_;\n      }\n      if (current3_ == end3_) {\n        current3_ = begin3_;\n        ++current2_;\n      }\n      if (current2_ == end2_) {\n        current2_ = begin2_;\n        ++current1_;\n      }\n      ComputeCurrentValue();\n    }\n    virtual ParamIteratorInterface<ParamType>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const ParamType* Current() const { return &current_value_; }\n    virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const Iterator* typed_other =\n          CheckedDowncastToActualType<const Iterator>(&other);\n      // We must report iterators equal if they both point beyond their\n      // respective ranges. That can happen in a variety of fashions,\n      // so we have to consult AtEnd().\n      return (AtEnd() && typed_other->AtEnd()) ||\n         (\n          current1_ == typed_other->current1_ &&\n          current2_ == typed_other->current2_ &&\n          current3_ == typed_other->current3_ &&\n          current4_ == typed_other->current4_ &&\n          current5_ == typed_other->current5_ &&\n          current6_ == typed_other->current6_ &&\n          current7_ == typed_other->current7_ &&\n          current8_ == typed_other->current8_);\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : base_(other.base_),\n        begin1_(other.begin1_),\n        end1_(other.end1_),\n        current1_(other.current1_),\n        begin2_(other.begin2_),\n        end2_(other.end2_),\n        current2_(other.current2_),\n        begin3_(other.begin3_),\n        end3_(other.end3_),\n        current3_(other.current3_),\n        begin4_(other.begin4_),\n        end4_(other.end4_),\n        current4_(other.current4_),\n        begin5_(other.begin5_),\n        end5_(other.end5_),\n        current5_(other.current5_),\n        begin6_(other.begin6_),\n        end6_(other.end6_),\n        current6_(other.current6_),\n        begin7_(other.begin7_),\n        end7_(other.end7_),\n        current7_(other.current7_),\n        begin8_(other.begin8_),\n        end8_(other.end8_),\n        current8_(other.current8_) {\n      ComputeCurrentValue();\n    }\n\n    void ComputeCurrentValue() {\n      if (!AtEnd())\n        current_value_ = ParamType(*current1_, *current2_, *current3_,\n            *current4_, *current5_, *current6_, *current7_, *current8_);\n    }\n    bool AtEnd() const {\n      // We must report iterator past the end of the range when either of the\n      // component iterators has reached the end of its range.\n      return\n          current1_ == end1_ ||\n          current2_ == end2_ ||\n          current3_ == end3_ ||\n          current4_ == end4_ ||\n          current5_ == end5_ ||\n          current6_ == end6_ ||\n          current7_ == end7_ ||\n          current8_ == end8_;\n    }\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<ParamType>* const base_;\n    // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.\n    // current[i]_ is the actual traversing iterator.\n    const typename ParamGenerator<T1>::iterator begin1_;\n    const typename ParamGenerator<T1>::iterator end1_;\n    typename ParamGenerator<T1>::iterator current1_;\n    const typename ParamGenerator<T2>::iterator begin2_;\n    const typename ParamGenerator<T2>::iterator end2_;\n    typename ParamGenerator<T2>::iterator current2_;\n    const typename ParamGenerator<T3>::iterator begin3_;\n    const typename ParamGenerator<T3>::iterator end3_;\n    typename ParamGenerator<T3>::iterator current3_;\n    const typename ParamGenerator<T4>::iterator begin4_;\n    const typename ParamGenerator<T4>::iterator end4_;\n    typename ParamGenerator<T4>::iterator current4_;\n    const typename ParamGenerator<T5>::iterator begin5_;\n    const typename ParamGenerator<T5>::iterator end5_;\n    typename ParamGenerator<T5>::iterator current5_;\n    const typename ParamGenerator<T6>::iterator begin6_;\n    const typename ParamGenerator<T6>::iterator end6_;\n    typename ParamGenerator<T6>::iterator current6_;\n    const typename ParamGenerator<T7>::iterator begin7_;\n    const typename ParamGenerator<T7>::iterator end7_;\n    typename ParamGenerator<T7>::iterator current7_;\n    const typename ParamGenerator<T8>::iterator begin8_;\n    const typename ParamGenerator<T8>::iterator end8_;\n    typename ParamGenerator<T8>::iterator current8_;\n    ParamType current_value_;\n  };  // class CartesianProductGenerator8::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductGenerator8& other);\n\n  const ParamGenerator<T1> g1_;\n  const ParamGenerator<T2> g2_;\n  const ParamGenerator<T3> g3_;\n  const ParamGenerator<T4> g4_;\n  const ParamGenerator<T5> g5_;\n  const ParamGenerator<T6> g6_;\n  const ParamGenerator<T7> g7_;\n  const ParamGenerator<T8> g8_;\n};  // class CartesianProductGenerator8\n\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9>\nclass CartesianProductGenerator9\n    : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,\n        T7, T8, T9> > {\n public:\n  typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> ParamType;\n\n  CartesianProductGenerator9(const ParamGenerator<T1>& g1,\n      const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,\n      const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,\n      const ParamGenerator<T6>& g6, const ParamGenerator<T7>& g7,\n      const ParamGenerator<T8>& g8, const ParamGenerator<T9>& g9)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8),\n          g9_(g9) {}\n  virtual ~CartesianProductGenerator9() {}\n\n  virtual ParamIteratorInterface<ParamType>* Begin() const {\n    return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,\n        g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_,\n        g7_.begin(), g8_, g8_.begin(), g9_, g9_.begin());\n  }\n  virtual ParamIteratorInterface<ParamType>* End() const {\n    return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),\n        g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end(), g8_,\n        g8_.end(), g9_, g9_.end());\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<ParamType> {\n   public:\n    Iterator(const ParamGeneratorInterface<ParamType>* base,\n      const ParamGenerator<T1>& g1,\n      const typename ParamGenerator<T1>::iterator& current1,\n      const ParamGenerator<T2>& g2,\n      const typename ParamGenerator<T2>::iterator& current2,\n      const ParamGenerator<T3>& g3,\n      const typename ParamGenerator<T3>::iterator& current3,\n      const ParamGenerator<T4>& g4,\n      const typename ParamGenerator<T4>::iterator& current4,\n      const ParamGenerator<T5>& g5,\n      const typename ParamGenerator<T5>::iterator& current5,\n      const ParamGenerator<T6>& g6,\n      const typename ParamGenerator<T6>::iterator& current6,\n      const ParamGenerator<T7>& g7,\n      const typename ParamGenerator<T7>::iterator& current7,\n      const ParamGenerator<T8>& g8,\n      const typename ParamGenerator<T8>::iterator& current8,\n      const ParamGenerator<T9>& g9,\n      const typename ParamGenerator<T9>::iterator& current9)\n        : base_(base),\n          begin1_(g1.begin()), end1_(g1.end()), current1_(current1),\n          begin2_(g2.begin()), end2_(g2.end()), current2_(current2),\n          begin3_(g3.begin()), end3_(g3.end()), current3_(current3),\n          begin4_(g4.begin()), end4_(g4.end()), current4_(current4),\n          begin5_(g5.begin()), end5_(g5.end()), current5_(current5),\n          begin6_(g6.begin()), end6_(g6.end()), current6_(current6),\n          begin7_(g7.begin()), end7_(g7.end()), current7_(current7),\n          begin8_(g8.begin()), end8_(g8.end()), current8_(current8),\n          begin9_(g9.begin()), end9_(g9.end()), current9_(current9)    {\n      ComputeCurrentValue();\n    }\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {\n      return base_;\n    }\n    // Advance should not be called on beyond-of-range iterators\n    // so no component iterators must be beyond end of range, either.\n    virtual void Advance() {\n      assert(!AtEnd());\n      ++current9_;\n      if (current9_ == end9_) {\n        current9_ = begin9_;\n        ++current8_;\n      }\n      if (current8_ == end8_) {\n        current8_ = begin8_;\n        ++current7_;\n      }\n      if (current7_ == end7_) {\n        current7_ = begin7_;\n        ++current6_;\n      }\n      if (current6_ == end6_) {\n        current6_ = begin6_;\n        ++current5_;\n      }\n      if (current5_ == end5_) {\n        current5_ = begin5_;\n        ++current4_;\n      }\n      if (current4_ == end4_) {\n        current4_ = begin4_;\n        ++current3_;\n      }\n      if (current3_ == end3_) {\n        current3_ = begin3_;\n        ++current2_;\n      }\n      if (current2_ == end2_) {\n        current2_ = begin2_;\n        ++current1_;\n      }\n      ComputeCurrentValue();\n    }\n    virtual ParamIteratorInterface<ParamType>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const ParamType* Current() const { return &current_value_; }\n    virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const Iterator* typed_other =\n          CheckedDowncastToActualType<const Iterator>(&other);\n      // We must report iterators equal if they both point beyond their\n      // respective ranges. That can happen in a variety of fashions,\n      // so we have to consult AtEnd().\n      return (AtEnd() && typed_other->AtEnd()) ||\n         (\n          current1_ == typed_other->current1_ &&\n          current2_ == typed_other->current2_ &&\n          current3_ == typed_other->current3_ &&\n          current4_ == typed_other->current4_ &&\n          current5_ == typed_other->current5_ &&\n          current6_ == typed_other->current6_ &&\n          current7_ == typed_other->current7_ &&\n          current8_ == typed_other->current8_ &&\n          current9_ == typed_other->current9_);\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : base_(other.base_),\n        begin1_(other.begin1_),\n        end1_(other.end1_),\n        current1_(other.current1_),\n        begin2_(other.begin2_),\n        end2_(other.end2_),\n        current2_(other.current2_),\n        begin3_(other.begin3_),\n        end3_(other.end3_),\n        current3_(other.current3_),\n        begin4_(other.begin4_),\n        end4_(other.end4_),\n        current4_(other.current4_),\n        begin5_(other.begin5_),\n        end5_(other.end5_),\n        current5_(other.current5_),\n        begin6_(other.begin6_),\n        end6_(other.end6_),\n        current6_(other.current6_),\n        begin7_(other.begin7_),\n        end7_(other.end7_),\n        current7_(other.current7_),\n        begin8_(other.begin8_),\n        end8_(other.end8_),\n        current8_(other.current8_),\n        begin9_(other.begin9_),\n        end9_(other.end9_),\n        current9_(other.current9_) {\n      ComputeCurrentValue();\n    }\n\n    void ComputeCurrentValue() {\n      if (!AtEnd())\n        current_value_ = ParamType(*current1_, *current2_, *current3_,\n            *current4_, *current5_, *current6_, *current7_, *current8_,\n            *current9_);\n    }\n    bool AtEnd() const {\n      // We must report iterator past the end of the range when either of the\n      // component iterators has reached the end of its range.\n      return\n          current1_ == end1_ ||\n          current2_ == end2_ ||\n          current3_ == end3_ ||\n          current4_ == end4_ ||\n          current5_ == end5_ ||\n          current6_ == end6_ ||\n          current7_ == end7_ ||\n          current8_ == end8_ ||\n          current9_ == end9_;\n    }\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<ParamType>* const base_;\n    // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.\n    // current[i]_ is the actual traversing iterator.\n    const typename ParamGenerator<T1>::iterator begin1_;\n    const typename ParamGenerator<T1>::iterator end1_;\n    typename ParamGenerator<T1>::iterator current1_;\n    const typename ParamGenerator<T2>::iterator begin2_;\n    const typename ParamGenerator<T2>::iterator end2_;\n    typename ParamGenerator<T2>::iterator current2_;\n    const typename ParamGenerator<T3>::iterator begin3_;\n    const typename ParamGenerator<T3>::iterator end3_;\n    typename ParamGenerator<T3>::iterator current3_;\n    const typename ParamGenerator<T4>::iterator begin4_;\n    const typename ParamGenerator<T4>::iterator end4_;\n    typename ParamGenerator<T4>::iterator current4_;\n    const typename ParamGenerator<T5>::iterator begin5_;\n    const typename ParamGenerator<T5>::iterator end5_;\n    typename ParamGenerator<T5>::iterator current5_;\n    const typename ParamGenerator<T6>::iterator begin6_;\n    const typename ParamGenerator<T6>::iterator end6_;\n    typename ParamGenerator<T6>::iterator current6_;\n    const typename ParamGenerator<T7>::iterator begin7_;\n    const typename ParamGenerator<T7>::iterator end7_;\n    typename ParamGenerator<T7>::iterator current7_;\n    const typename ParamGenerator<T8>::iterator begin8_;\n    const typename ParamGenerator<T8>::iterator end8_;\n    typename ParamGenerator<T8>::iterator current8_;\n    const typename ParamGenerator<T9>::iterator begin9_;\n    const typename ParamGenerator<T9>::iterator end9_;\n    typename ParamGenerator<T9>::iterator current9_;\n    ParamType current_value_;\n  };  // class CartesianProductGenerator9::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductGenerator9& other);\n\n  const ParamGenerator<T1> g1_;\n  const ParamGenerator<T2> g2_;\n  const ParamGenerator<T3> g3_;\n  const ParamGenerator<T4> g4_;\n  const ParamGenerator<T5> g5_;\n  const ParamGenerator<T6> g6_;\n  const ParamGenerator<T7> g7_;\n  const ParamGenerator<T8> g8_;\n  const ParamGenerator<T9> g9_;\n};  // class CartesianProductGenerator9\n\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10>\nclass CartesianProductGenerator10\n    : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,\n        T7, T8, T9, T10> > {\n public:\n  typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> ParamType;\n\n  CartesianProductGenerator10(const ParamGenerator<T1>& g1,\n      const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,\n      const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,\n      const ParamGenerator<T6>& g6, const ParamGenerator<T7>& g7,\n      const ParamGenerator<T8>& g8, const ParamGenerator<T9>& g9,\n      const ParamGenerator<T10>& g10)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8),\n          g9_(g9), g10_(g10) {}\n  virtual ~CartesianProductGenerator10() {}\n\n  virtual ParamIteratorInterface<ParamType>* Begin() const {\n    return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,\n        g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_,\n        g7_.begin(), g8_, g8_.begin(), g9_, g9_.begin(), g10_, g10_.begin());\n  }\n  virtual ParamIteratorInterface<ParamType>* End() const {\n    return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),\n        g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end(), g8_,\n        g8_.end(), g9_, g9_.end(), g10_, g10_.end());\n  }\n\n private:\n  class Iterator : public ParamIteratorInterface<ParamType> {\n   public:\n    Iterator(const ParamGeneratorInterface<ParamType>* base,\n      const ParamGenerator<T1>& g1,\n      const typename ParamGenerator<T1>::iterator& current1,\n      const ParamGenerator<T2>& g2,\n      const typename ParamGenerator<T2>::iterator& current2,\n      const ParamGenerator<T3>& g3,\n      const typename ParamGenerator<T3>::iterator& current3,\n      const ParamGenerator<T4>& g4,\n      const typename ParamGenerator<T4>::iterator& current4,\n      const ParamGenerator<T5>& g5,\n      const typename ParamGenerator<T5>::iterator& current5,\n      const ParamGenerator<T6>& g6,\n      const typename ParamGenerator<T6>::iterator& current6,\n      const ParamGenerator<T7>& g7,\n      const typename ParamGenerator<T7>::iterator& current7,\n      const ParamGenerator<T8>& g8,\n      const typename ParamGenerator<T8>::iterator& current8,\n      const ParamGenerator<T9>& g9,\n      const typename ParamGenerator<T9>::iterator& current9,\n      const ParamGenerator<T10>& g10,\n      const typename ParamGenerator<T10>::iterator& current10)\n        : base_(base),\n          begin1_(g1.begin()), end1_(g1.end()), current1_(current1),\n          begin2_(g2.begin()), end2_(g2.end()), current2_(current2),\n          begin3_(g3.begin()), end3_(g3.end()), current3_(current3),\n          begin4_(g4.begin()), end4_(g4.end()), current4_(current4),\n          begin5_(g5.begin()), end5_(g5.end()), current5_(current5),\n          begin6_(g6.begin()), end6_(g6.end()), current6_(current6),\n          begin7_(g7.begin()), end7_(g7.end()), current7_(current7),\n          begin8_(g8.begin()), end8_(g8.end()), current8_(current8),\n          begin9_(g9.begin()), end9_(g9.end()), current9_(current9),\n          begin10_(g10.begin()), end10_(g10.end()), current10_(current10)    {\n      ComputeCurrentValue();\n    }\n    virtual ~Iterator() {}\n\n    virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {\n      return base_;\n    }\n    // Advance should not be called on beyond-of-range iterators\n    // so no component iterators must be beyond end of range, either.\n    virtual void Advance() {\n      assert(!AtEnd());\n      ++current10_;\n      if (current10_ == end10_) {\n        current10_ = begin10_;\n        ++current9_;\n      }\n      if (current9_ == end9_) {\n        current9_ = begin9_;\n        ++current8_;\n      }\n      if (current8_ == end8_) {\n        current8_ = begin8_;\n        ++current7_;\n      }\n      if (current7_ == end7_) {\n        current7_ = begin7_;\n        ++current6_;\n      }\n      if (current6_ == end6_) {\n        current6_ = begin6_;\n        ++current5_;\n      }\n      if (current5_ == end5_) {\n        current5_ = begin5_;\n        ++current4_;\n      }\n      if (current4_ == end4_) {\n        current4_ = begin4_;\n        ++current3_;\n      }\n      if (current3_ == end3_) {\n        current3_ = begin3_;\n        ++current2_;\n      }\n      if (current2_ == end2_) {\n        current2_ = begin2_;\n        ++current1_;\n      }\n      ComputeCurrentValue();\n    }\n    virtual ParamIteratorInterface<ParamType>* Clone() const {\n      return new Iterator(*this);\n    }\n    virtual const ParamType* Current() const { return &current_value_; }\n    virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {\n      // Having the same base generator guarantees that the other\n      // iterator is of the same type and we can downcast.\n      GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())\n          << \"The program attempted to compare iterators \"\n          << \"from different generators.\" << std::endl;\n      const Iterator* typed_other =\n          CheckedDowncastToActualType<const Iterator>(&other);\n      // We must report iterators equal if they both point beyond their\n      // respective ranges. That can happen in a variety of fashions,\n      // so we have to consult AtEnd().\n      return (AtEnd() && typed_other->AtEnd()) ||\n         (\n          current1_ == typed_other->current1_ &&\n          current2_ == typed_other->current2_ &&\n          current3_ == typed_other->current3_ &&\n          current4_ == typed_other->current4_ &&\n          current5_ == typed_other->current5_ &&\n          current6_ == typed_other->current6_ &&\n          current7_ == typed_other->current7_ &&\n          current8_ == typed_other->current8_ &&\n          current9_ == typed_other->current9_ &&\n          current10_ == typed_other->current10_);\n    }\n\n   private:\n    Iterator(const Iterator& other)\n        : base_(other.base_),\n        begin1_(other.begin1_),\n        end1_(other.end1_),\n        current1_(other.current1_),\n        begin2_(other.begin2_),\n        end2_(other.end2_),\n        current2_(other.current2_),\n        begin3_(other.begin3_),\n        end3_(other.end3_),\n        current3_(other.current3_),\n        begin4_(other.begin4_),\n        end4_(other.end4_),\n        current4_(other.current4_),\n        begin5_(other.begin5_),\n        end5_(other.end5_),\n        current5_(other.current5_),\n        begin6_(other.begin6_),\n        end6_(other.end6_),\n        current6_(other.current6_),\n        begin7_(other.begin7_),\n        end7_(other.end7_),\n        current7_(other.current7_),\n        begin8_(other.begin8_),\n        end8_(other.end8_),\n        current8_(other.current8_),\n        begin9_(other.begin9_),\n        end9_(other.end9_),\n        current9_(other.current9_),\n        begin10_(other.begin10_),\n        end10_(other.end10_),\n        current10_(other.current10_) {\n      ComputeCurrentValue();\n    }\n\n    void ComputeCurrentValue() {\n      if (!AtEnd())\n        current_value_ = ParamType(*current1_, *current2_, *current3_,\n            *current4_, *current5_, *current6_, *current7_, *current8_,\n            *current9_, *current10_);\n    }\n    bool AtEnd() const {\n      // We must report iterator past the end of the range when either of the\n      // component iterators has reached the end of its range.\n      return\n          current1_ == end1_ ||\n          current2_ == end2_ ||\n          current3_ == end3_ ||\n          current4_ == end4_ ||\n          current5_ == end5_ ||\n          current6_ == end6_ ||\n          current7_ == end7_ ||\n          current8_ == end8_ ||\n          current9_ == end9_ ||\n          current10_ == end10_;\n    }\n\n    // No implementation - assignment is unsupported.\n    void operator=(const Iterator& other);\n\n    const ParamGeneratorInterface<ParamType>* const base_;\n    // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.\n    // current[i]_ is the actual traversing iterator.\n    const typename ParamGenerator<T1>::iterator begin1_;\n    const typename ParamGenerator<T1>::iterator end1_;\n    typename ParamGenerator<T1>::iterator current1_;\n    const typename ParamGenerator<T2>::iterator begin2_;\n    const typename ParamGenerator<T2>::iterator end2_;\n    typename ParamGenerator<T2>::iterator current2_;\n    const typename ParamGenerator<T3>::iterator begin3_;\n    const typename ParamGenerator<T3>::iterator end3_;\n    typename ParamGenerator<T3>::iterator current3_;\n    const typename ParamGenerator<T4>::iterator begin4_;\n    const typename ParamGenerator<T4>::iterator end4_;\n    typename ParamGenerator<T4>::iterator current4_;\n    const typename ParamGenerator<T5>::iterator begin5_;\n    const typename ParamGenerator<T5>::iterator end5_;\n    typename ParamGenerator<T5>::iterator current5_;\n    const typename ParamGenerator<T6>::iterator begin6_;\n    const typename ParamGenerator<T6>::iterator end6_;\n    typename ParamGenerator<T6>::iterator current6_;\n    const typename ParamGenerator<T7>::iterator begin7_;\n    const typename ParamGenerator<T7>::iterator end7_;\n    typename ParamGenerator<T7>::iterator current7_;\n    const typename ParamGenerator<T8>::iterator begin8_;\n    const typename ParamGenerator<T8>::iterator end8_;\n    typename ParamGenerator<T8>::iterator current8_;\n    const typename ParamGenerator<T9>::iterator begin9_;\n    const typename ParamGenerator<T9>::iterator end9_;\n    typename ParamGenerator<T9>::iterator current9_;\n    const typename ParamGenerator<T10>::iterator begin10_;\n    const typename ParamGenerator<T10>::iterator end10_;\n    typename ParamGenerator<T10>::iterator current10_;\n    ParamType current_value_;\n  };  // class CartesianProductGenerator10::Iterator\n\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductGenerator10& other);\n\n  const ParamGenerator<T1> g1_;\n  const ParamGenerator<T2> g2_;\n  const ParamGenerator<T3> g3_;\n  const ParamGenerator<T4> g4_;\n  const ParamGenerator<T5> g5_;\n  const ParamGenerator<T6> g6_;\n  const ParamGenerator<T7> g7_;\n  const ParamGenerator<T8> g8_;\n  const ParamGenerator<T9> g9_;\n  const ParamGenerator<T10> g10_;\n};  // class CartesianProductGenerator10\n\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// Helper classes providing Combine() with polymorphic features. They allow\n// casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is\n// convertible to U.\n//\ntemplate <class Generator1, class Generator2>\nclass CartesianProductHolder2 {\n public:\nCartesianProductHolder2(const Generator1& g1, const Generator2& g2)\n      : g1_(g1), g2_(g2) {}\n  template <typename T1, typename T2>\n  operator ParamGenerator< ::std::tr1::tuple<T1, T2> >() const {\n    return ParamGenerator< ::std::tr1::tuple<T1, T2> >(\n        new CartesianProductGenerator2<T1, T2>(\n        static_cast<ParamGenerator<T1> >(g1_),\n        static_cast<ParamGenerator<T2> >(g2_)));\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductHolder2& other);\n\n  const Generator1 g1_;\n  const Generator2 g2_;\n};  // class CartesianProductHolder2\n\ntemplate <class Generator1, class Generator2, class Generator3>\nclass CartesianProductHolder3 {\n public:\nCartesianProductHolder3(const Generator1& g1, const Generator2& g2,\n    const Generator3& g3)\n      : g1_(g1), g2_(g2), g3_(g3) {}\n  template <typename T1, typename T2, typename T3>\n  operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3> >() const {\n    return ParamGenerator< ::std::tr1::tuple<T1, T2, T3> >(\n        new CartesianProductGenerator3<T1, T2, T3>(\n        static_cast<ParamGenerator<T1> >(g1_),\n        static_cast<ParamGenerator<T2> >(g2_),\n        static_cast<ParamGenerator<T3> >(g3_)));\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductHolder3& other);\n\n  const Generator1 g1_;\n  const Generator2 g2_;\n  const Generator3 g3_;\n};  // class CartesianProductHolder3\n\ntemplate <class Generator1, class Generator2, class Generator3,\n    class Generator4>\nclass CartesianProductHolder4 {\n public:\nCartesianProductHolder4(const Generator1& g1, const Generator2& g2,\n    const Generator3& g3, const Generator4& g4)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4) {}\n  template <typename T1, typename T2, typename T3, typename T4>\n  operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4> >() const {\n    return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4> >(\n        new CartesianProductGenerator4<T1, T2, T3, T4>(\n        static_cast<ParamGenerator<T1> >(g1_),\n        static_cast<ParamGenerator<T2> >(g2_),\n        static_cast<ParamGenerator<T3> >(g3_),\n        static_cast<ParamGenerator<T4> >(g4_)));\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductHolder4& other);\n\n  const Generator1 g1_;\n  const Generator2 g2_;\n  const Generator3 g3_;\n  const Generator4 g4_;\n};  // class CartesianProductHolder4\n\ntemplate <class Generator1, class Generator2, class Generator3,\n    class Generator4, class Generator5>\nclass CartesianProductHolder5 {\n public:\nCartesianProductHolder5(const Generator1& g1, const Generator2& g2,\n    const Generator3& g3, const Generator4& g4, const Generator5& g5)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5) {}\n  template <typename T1, typename T2, typename T3, typename T4, typename T5>\n  operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5> >() const {\n    return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5> >(\n        new CartesianProductGenerator5<T1, T2, T3, T4, T5>(\n        static_cast<ParamGenerator<T1> >(g1_),\n        static_cast<ParamGenerator<T2> >(g2_),\n        static_cast<ParamGenerator<T3> >(g3_),\n        static_cast<ParamGenerator<T4> >(g4_),\n        static_cast<ParamGenerator<T5> >(g5_)));\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductHolder5& other);\n\n  const Generator1 g1_;\n  const Generator2 g2_;\n  const Generator3 g3_;\n  const Generator4 g4_;\n  const Generator5 g5_;\n};  // class CartesianProductHolder5\n\ntemplate <class Generator1, class Generator2, class Generator3,\n    class Generator4, class Generator5, class Generator6>\nclass CartesianProductHolder6 {\n public:\nCartesianProductHolder6(const Generator1& g1, const Generator2& g2,\n    const Generator3& g3, const Generator4& g4, const Generator5& g5,\n    const Generator6& g6)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6) {}\n  template <typename T1, typename T2, typename T3, typename T4, typename T5,\n      typename T6>\n  operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6> >() const {\n    return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6> >(\n        new CartesianProductGenerator6<T1, T2, T3, T4, T5, T6>(\n        static_cast<ParamGenerator<T1> >(g1_),\n        static_cast<ParamGenerator<T2> >(g2_),\n        static_cast<ParamGenerator<T3> >(g3_),\n        static_cast<ParamGenerator<T4> >(g4_),\n        static_cast<ParamGenerator<T5> >(g5_),\n        static_cast<ParamGenerator<T6> >(g6_)));\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductHolder6& other);\n\n  const Generator1 g1_;\n  const Generator2 g2_;\n  const Generator3 g3_;\n  const Generator4 g4_;\n  const Generator5 g5_;\n  const Generator6 g6_;\n};  // class CartesianProductHolder6\n\ntemplate <class Generator1, class Generator2, class Generator3,\n    class Generator4, class Generator5, class Generator6, class Generator7>\nclass CartesianProductHolder7 {\n public:\nCartesianProductHolder7(const Generator1& g1, const Generator2& g2,\n    const Generator3& g3, const Generator4& g4, const Generator5& g5,\n    const Generator6& g6, const Generator7& g7)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7) {}\n  template <typename T1, typename T2, typename T3, typename T4, typename T5,\n      typename T6, typename T7>\n  operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,\n      T7> >() const {\n    return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7> >(\n        new CartesianProductGenerator7<T1, T2, T3, T4, T5, T6, T7>(\n        static_cast<ParamGenerator<T1> >(g1_),\n        static_cast<ParamGenerator<T2> >(g2_),\n        static_cast<ParamGenerator<T3> >(g3_),\n        static_cast<ParamGenerator<T4> >(g4_),\n        static_cast<ParamGenerator<T5> >(g5_),\n        static_cast<ParamGenerator<T6> >(g6_),\n        static_cast<ParamGenerator<T7> >(g7_)));\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductHolder7& other);\n\n  const Generator1 g1_;\n  const Generator2 g2_;\n  const Generator3 g3_;\n  const Generator4 g4_;\n  const Generator5 g5_;\n  const Generator6 g6_;\n  const Generator7 g7_;\n};  // class CartesianProductHolder7\n\ntemplate <class Generator1, class Generator2, class Generator3,\n    class Generator4, class Generator5, class Generator6, class Generator7,\n    class Generator8>\nclass CartesianProductHolder8 {\n public:\nCartesianProductHolder8(const Generator1& g1, const Generator2& g2,\n    const Generator3& g3, const Generator4& g4, const Generator5& g5,\n    const Generator6& g6, const Generator7& g7, const Generator8& g8)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7),\n          g8_(g8) {}\n  template <typename T1, typename T2, typename T3, typename T4, typename T5,\n      typename T6, typename T7, typename T8>\n  operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7,\n      T8> >() const {\n    return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >(\n        new CartesianProductGenerator8<T1, T2, T3, T4, T5, T6, T7, T8>(\n        static_cast<ParamGenerator<T1> >(g1_),\n        static_cast<ParamGenerator<T2> >(g2_),\n        static_cast<ParamGenerator<T3> >(g3_),\n        static_cast<ParamGenerator<T4> >(g4_),\n        static_cast<ParamGenerator<T5> >(g5_),\n        static_cast<ParamGenerator<T6> >(g6_),\n        static_cast<ParamGenerator<T7> >(g7_),\n        static_cast<ParamGenerator<T8> >(g8_)));\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductHolder8& other);\n\n  const Generator1 g1_;\n  const Generator2 g2_;\n  const Generator3 g3_;\n  const Generator4 g4_;\n  const Generator5 g5_;\n  const Generator6 g6_;\n  const Generator7 g7_;\n  const Generator8 g8_;\n};  // class CartesianProductHolder8\n\ntemplate <class Generator1, class Generator2, class Generator3,\n    class Generator4, class Generator5, class Generator6, class Generator7,\n    class Generator8, class Generator9>\nclass CartesianProductHolder9 {\n public:\nCartesianProductHolder9(const Generator1& g1, const Generator2& g2,\n    const Generator3& g3, const Generator4& g4, const Generator5& g5,\n    const Generator6& g6, const Generator7& g7, const Generator8& g8,\n    const Generator9& g9)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8),\n          g9_(g9) {}\n  template <typename T1, typename T2, typename T3, typename T4, typename T5,\n      typename T6, typename T7, typename T8, typename T9>\n  operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8,\n      T9> >() const {\n    return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8,\n        T9> >(\n        new CartesianProductGenerator9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(\n        static_cast<ParamGenerator<T1> >(g1_),\n        static_cast<ParamGenerator<T2> >(g2_),\n        static_cast<ParamGenerator<T3> >(g3_),\n        static_cast<ParamGenerator<T4> >(g4_),\n        static_cast<ParamGenerator<T5> >(g5_),\n        static_cast<ParamGenerator<T6> >(g6_),\n        static_cast<ParamGenerator<T7> >(g7_),\n        static_cast<ParamGenerator<T8> >(g8_),\n        static_cast<ParamGenerator<T9> >(g9_)));\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductHolder9& other);\n\n  const Generator1 g1_;\n  const Generator2 g2_;\n  const Generator3 g3_;\n  const Generator4 g4_;\n  const Generator5 g5_;\n  const Generator6 g6_;\n  const Generator7 g7_;\n  const Generator8 g8_;\n  const Generator9 g9_;\n};  // class CartesianProductHolder9\n\ntemplate <class Generator1, class Generator2, class Generator3,\n    class Generator4, class Generator5, class Generator6, class Generator7,\n    class Generator8, class Generator9, class Generator10>\nclass CartesianProductHolder10 {\n public:\nCartesianProductHolder10(const Generator1& g1, const Generator2& g2,\n    const Generator3& g3, const Generator4& g4, const Generator5& g5,\n    const Generator6& g6, const Generator7& g7, const Generator8& g8,\n    const Generator9& g9, const Generator10& g10)\n      : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8),\n          g9_(g9), g10_(g10) {}\n  template <typename T1, typename T2, typename T3, typename T4, typename T5,\n      typename T6, typename T7, typename T8, typename T9, typename T10>\n  operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8,\n      T9, T10> >() const {\n    return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8,\n        T9, T10> >(\n        new CartesianProductGenerator10<T1, T2, T3, T4, T5, T6, T7, T8, T9,\n            T10>(\n        static_cast<ParamGenerator<T1> >(g1_),\n        static_cast<ParamGenerator<T2> >(g2_),\n        static_cast<ParamGenerator<T3> >(g3_),\n        static_cast<ParamGenerator<T4> >(g4_),\n        static_cast<ParamGenerator<T5> >(g5_),\n        static_cast<ParamGenerator<T6> >(g6_),\n        static_cast<ParamGenerator<T7> >(g7_),\n        static_cast<ParamGenerator<T8> >(g8_),\n        static_cast<ParamGenerator<T9> >(g9_),\n        static_cast<ParamGenerator<T10> >(g10_)));\n  }\n\n private:\n  // No implementation - assignment is unsupported.\n  void operator=(const CartesianProductHolder10& other);\n\n  const Generator1 g1_;\n  const Generator2 g2_;\n  const Generator3 g3_;\n  const Generator4 g4_;\n  const Generator5 g5_;\n  const Generator6 g6_;\n  const Generator7 g7_;\n  const Generator8 g8_;\n  const Generator9 g9_;\n  const Generator10 g10_;\n};  // class CartesianProductHolder10\n\n# endif  // GTEST_HAS_COMBINE\n\n}  // namespace internal\n}  // namespace testing\n\n#endif  //  GTEST_HAS_PARAM_TEST\n\n#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_\n\n#if GTEST_HAS_PARAM_TEST\n\nnamespace testing {\n\n// Functions producing parameter generators.\n//\n// Google Test uses these generators to produce parameters for value-\n// parameterized tests. When a parameterized test case is instantiated\n// with a particular generator, Google Test creates and runs tests\n// for each element in the sequence produced by the generator.\n//\n// In the following sample, tests from test case FooTest are instantiated\n// each three times with parameter values 3, 5, and 8:\n//\n// class FooTest : public TestWithParam<int> { ... };\n//\n// TEST_P(FooTest, TestThis) {\n// }\n// TEST_P(FooTest, TestThat) {\n// }\n// INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));\n//\n\n// Range() returns generators providing sequences of values in a range.\n//\n// Synopsis:\n// Range(start, end)\n//   - returns a generator producing a sequence of values {start, start+1,\n//     start+2, ..., }.\n// Range(start, end, step)\n//   - returns a generator producing a sequence of values {start, start+step,\n//     start+step+step, ..., }.\n// Notes:\n//   * The generated sequences never include end. For example, Range(1, 5)\n//     returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2)\n//     returns a generator producing {1, 3, 5, 7}.\n//   * start and end must have the same type. That type may be any integral or\n//     floating-point type or a user defined type satisfying these conditions:\n//     * It must be assignable (have operator=() defined).\n//     * It must have operator+() (operator+(int-compatible type) for\n//       two-operand version).\n//     * It must have operator<() defined.\n//     Elements in the resulting sequences will also have that type.\n//   * Condition start < end must be satisfied in order for resulting sequences\n//     to contain any elements.\n//\ntemplate <typename T, typename IncrementT>\ninternal::ParamGenerator<T> Range(T start, T end, IncrementT step) {\n  return internal::ParamGenerator<T>(\n      new internal::RangeGenerator<T, IncrementT>(start, end, step));\n}\n\ntemplate <typename T>\ninternal::ParamGenerator<T> Range(T start, T end) {\n  return Range(start, end, 1);\n}\n\n// ValuesIn() function allows generation of tests with parameters coming from\n// a container.\n//\n// Synopsis:\n// ValuesIn(const T (&array)[N])\n//   - returns a generator producing sequences with elements from\n//     a C-style array.\n// ValuesIn(const Container& container)\n//   - returns a generator producing sequences with elements from\n//     an STL-style container.\n// ValuesIn(Iterator begin, Iterator end)\n//   - returns a generator producing sequences with elements from\n//     a range [begin, end) defined by a pair of STL-style iterators. These\n//     iterators can also be plain C pointers.\n//\n// Please note that ValuesIn copies the values from the containers\n// passed in and keeps them to generate tests in RUN_ALL_TESTS().\n//\n// Examples:\n//\n// This instantiates tests from test case StringTest\n// each with C-string values of \"foo\", \"bar\", and \"baz\":\n//\n// const char* strings[] = {\"foo\", \"bar\", \"baz\"};\n// INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings));\n//\n// This instantiates tests from test case StlStringTest\n// each with STL strings with values \"a\" and \"b\":\n//\n// ::std::vector< ::std::string> GetParameterStrings() {\n//   ::std::vector< ::std::string> v;\n//   v.push_back(\"a\");\n//   v.push_back(\"b\");\n//   return v;\n// }\n//\n// INSTANTIATE_TEST_CASE_P(CharSequence,\n//                         StlStringTest,\n//                         ValuesIn(GetParameterStrings()));\n//\n//\n// This will also instantiate tests from CharTest\n// each with parameter values 'a' and 'b':\n//\n// ::std::list<char> GetParameterChars() {\n//   ::std::list<char> list;\n//   list.push_back('a');\n//   list.push_back('b');\n//   return list;\n// }\n// ::std::list<char> l = GetParameterChars();\n// INSTANTIATE_TEST_CASE_P(CharSequence2,\n//                         CharTest,\n//                         ValuesIn(l.begin(), l.end()));\n//\ntemplate <typename ForwardIterator>\ninternal::ParamGenerator<\n  typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>\nValuesIn(ForwardIterator begin, ForwardIterator end) {\n  typedef typename ::testing::internal::IteratorTraits<ForwardIterator>\n      ::value_type ParamType;\n  return internal::ParamGenerator<ParamType>(\n      new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));\n}\n\ntemplate <typename T, size_t N>\ninternal::ParamGenerator<T> ValuesIn(const T (&array)[N]) {\n  return ValuesIn(array, array + N);\n}\n\ntemplate <class Container>\ninternal::ParamGenerator<typename Container::value_type> ValuesIn(\n    const Container& container) {\n  return ValuesIn(container.begin(), container.end());\n}\n\n// Values() allows generating tests from explicitly specified list of\n// parameters.\n//\n// Synopsis:\n// Values(T v1, T v2, ..., T vN)\n//   - returns a generator producing sequences with elements v1, v2, ..., vN.\n//\n// For example, this instantiates tests from test case BarTest each\n// with values \"one\", \"two\", and \"three\":\n//\n// INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values(\"one\", \"two\", \"three\"));\n//\n// This instantiates tests from test case BazTest each with values 1, 2, 3.5.\n// The exact type of values will depend on the type of parameter in BazTest.\n//\n// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));\n//\n// Currently, Values() supports from 1 to 50 parameters.\n//\ntemplate <typename T1>\ninternal::ValueArray1<T1> Values(T1 v1) {\n  return internal::ValueArray1<T1>(v1);\n}\n\ntemplate <typename T1, typename T2>\ninternal::ValueArray2<T1, T2> Values(T1 v1, T2 v2) {\n  return internal::ValueArray2<T1, T2>(v1, v2);\n}\n\ntemplate <typename T1, typename T2, typename T3>\ninternal::ValueArray3<T1, T2, T3> Values(T1 v1, T2 v2, T3 v3) {\n  return internal::ValueArray3<T1, T2, T3>(v1, v2, v3);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4>\ninternal::ValueArray4<T1, T2, T3, T4> Values(T1 v1, T2 v2, T3 v3, T4 v4) {\n  return internal::ValueArray4<T1, T2, T3, T4>(v1, v2, v3, v4);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5>\ninternal::ValueArray5<T1, T2, T3, T4, T5> Values(T1 v1, T2 v2, T3 v3, T4 v4,\n    T5 v5) {\n  return internal::ValueArray5<T1, T2, T3, T4, T5>(v1, v2, v3, v4, v5);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6>\ninternal::ValueArray6<T1, T2, T3, T4, T5, T6> Values(T1 v1, T2 v2, T3 v3,\n    T4 v4, T5 v5, T6 v6) {\n  return internal::ValueArray6<T1, T2, T3, T4, T5, T6>(v1, v2, v3, v4, v5, v6);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7>\ninternal::ValueArray7<T1, T2, T3, T4, T5, T6, T7> Values(T1 v1, T2 v2, T3 v3,\n    T4 v4, T5 v5, T6 v6, T7 v7) {\n  return internal::ValueArray7<T1, T2, T3, T4, T5, T6, T7>(v1, v2, v3, v4, v5,\n      v6, v7);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8>\ninternal::ValueArray8<T1, T2, T3, T4, T5, T6, T7, T8> Values(T1 v1, T2 v2,\n    T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8) {\n  return internal::ValueArray8<T1, T2, T3, T4, T5, T6, T7, T8>(v1, v2, v3, v4,\n      v5, v6, v7, v8);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9>\ninternal::ValueArray9<T1, T2, T3, T4, T5, T6, T7, T8, T9> Values(T1 v1, T2 v2,\n    T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9) {\n  return internal::ValueArray9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(v1, v2, v3,\n      v4, v5, v6, v7, v8, v9);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10>\ninternal::ValueArray10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> Values(T1 v1,\n    T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10) {\n  return internal::ValueArray10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(v1,\n      v2, v3, v4, v5, v6, v7, v8, v9, v10);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11>\ninternal::ValueArray11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,\n    T11> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11) {\n  return internal::ValueArray11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,\n      T11>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12>\ninternal::ValueArray12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n    T12> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12) {\n  return internal::ValueArray12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13>\ninternal::ValueArray13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,\n    T13> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13) {\n  return internal::ValueArray13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14>\ninternal::ValueArray14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13, T14 v14) {\n  return internal::ValueArray14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,\n      v14);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15>\ninternal::ValueArray15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,\n    T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15) {\n  return internal::ValueArray15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12,\n      v13, v14, v15);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16>\ninternal::ValueArray16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,\n    T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,\n    T16 v16) {\n  return internal::ValueArray16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,\n      v12, v13, v14, v15, v16);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17>\ninternal::ValueArray17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,\n    T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,\n    T16 v16, T17 v17) {\n  return internal::ValueArray17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,\n      v11, v12, v13, v14, v15, v16, v17);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18>\ninternal::ValueArray18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6,\n    T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,\n    T16 v16, T17 v17, T18 v18) {\n  return internal::ValueArray18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18>(v1, v2, v3, v4, v5, v6, v7, v8, v9,\n      v10, v11, v12, v13, v14, v15, v16, v17, v18);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19>\ninternal::ValueArray19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,\n    T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14,\n    T15 v15, T16 v16, T17 v17, T18 v18, T19 v19) {\n  return internal::ValueArray19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19>(v1, v2, v3, v4, v5, v6, v7, v8,\n      v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20>\ninternal::ValueArray20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20> Values(T1 v1, T2 v2, T3 v3, T4 v4,\n    T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,\n    T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20) {\n  return internal::ValueArray20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20>(v1, v2, v3, v4, v5, v6, v7,\n      v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21>\ninternal::ValueArray21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21> Values(T1 v1, T2 v2, T3 v3, T4 v4,\n    T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,\n    T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21) {\n  return internal::ValueArray21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21>(v1, v2, v3, v4, v5, v6,\n      v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22>\ninternal::ValueArray22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22> Values(T1 v1, T2 v2, T3 v3,\n    T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,\n    T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,\n    T21 v21, T22 v22) {\n  return internal::ValueArray22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22>(v1, v2, v3, v4,\n      v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,\n      v20, v21, v22);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23>\ninternal::ValueArray23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> Values(T1 v1, T2 v2,\n    T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,\n    T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,\n    T21 v21, T22 v22, T23 v23) {\n  return internal::ValueArray23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23>(v1, v2, v3,\n      v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,\n      v20, v21, v22, v23);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24>\ninternal::ValueArray24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> Values(T1 v1, T2 v2,\n    T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,\n    T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,\n    T21 v21, T22 v22, T23 v23, T24 v24) {\n  return internal::ValueArray24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24>(v1, v2,\n      v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18,\n      v19, v20, v21, v22, v23, v24);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25>\ninternal::ValueArray25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> Values(T1 v1,\n    T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11,\n    T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19,\n    T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25) {\n  return internal::ValueArray25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25>(v1,\n      v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17,\n      v18, v19, v20, v21, v22, v23, v24, v25);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26>\ninternal::ValueArray26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n    T26> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n    T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n    T26 v26) {\n  return internal::ValueArray26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15,\n      v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27>\ninternal::ValueArray27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,\n    T27> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n    T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n    T26 v26, T27 v27) {\n  return internal::ValueArray27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14,\n      v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28>\ninternal::ValueArray28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,\n    T28> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n    T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n    T26 v26, T27 v27, T28 v28) {\n  return internal::ValueArray28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,\n      v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27,\n      v28);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29>\ninternal::ValueArray29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n    T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n    T26 v26, T27 v27, T28 v28, T29 v29) {\n  return internal::ValueArray29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12,\n      v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26,\n      v27, v28, v29);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30>\ninternal::ValueArray30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,\n    T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16,\n    T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24,\n    T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30) {\n  return internal::ValueArray30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,\n      v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25,\n      v26, v27, v28, v29, v30);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31>\ninternal::ValueArray31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,\n    T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,\n    T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,\n    T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31) {\n  return internal::ValueArray31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,\n      v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24,\n      v25, v26, v27, v28, v29, v30, v31);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32>\ninternal::ValueArray32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,\n    T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,\n    T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,\n    T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,\n    T32 v32) {\n  return internal::ValueArray32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32>(v1, v2, v3, v4, v5, v6, v7, v8, v9,\n      v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,\n      v24, v25, v26, v27, v28, v29, v30, v31, v32);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33>\ninternal::ValueArray33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6,\n    T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,\n    T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,\n    T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,\n    T32 v32, T33 v33) {\n  return internal::ValueArray33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33>(v1, v2, v3, v4, v5, v6, v7, v8,\n      v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,\n      v24, v25, v26, v27, v28, v29, v30, v31, v32, v33);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34>\ninternal::ValueArray34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,\n    T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14,\n    T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22,\n    T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30,\n    T31 v31, T32 v32, T33 v33, T34 v34) {\n  return internal::ValueArray34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34>(v1, v2, v3, v4, v5, v6, v7,\n      v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22,\n      v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35>\ninternal::ValueArray35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35> Values(T1 v1, T2 v2, T3 v3, T4 v4,\n    T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,\n    T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21,\n    T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29,\n    T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35) {\n  return internal::ValueArray35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35>(v1, v2, v3, v4, v5, v6,\n      v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,\n      v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36>\ninternal::ValueArray36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36> Values(T1 v1, T2 v2, T3 v3, T4 v4,\n    T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,\n    T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21,\n    T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29,\n    T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36) {\n  return internal::ValueArray36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36>(v1, v2, v3, v4,\n      v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,\n      v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33,\n      v34, v35, v36);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37>\ninternal::ValueArray37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37> Values(T1 v1, T2 v2, T3 v3,\n    T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,\n    T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,\n    T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28,\n    T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36,\n    T37 v37) {\n  return internal::ValueArray37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37>(v1, v2, v3,\n      v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,\n      v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33,\n      v34, v35, v36, v37);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38>\ninternal::ValueArray38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> Values(T1 v1, T2 v2,\n    T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,\n    T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,\n    T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28,\n    T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36,\n    T37 v37, T38 v38) {\n  return internal::ValueArray38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38>(v1, v2,\n      v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18,\n      v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32,\n      v33, v34, v35, v36, v37, v38);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39>\ninternal::ValueArray39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> Values(T1 v1, T2 v2,\n    T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,\n    T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,\n    T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28,\n    T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36,\n    T37 v37, T38 v38, T39 v39) {\n  return internal::ValueArray39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39>(v1,\n      v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17,\n      v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31,\n      v32, v33, v34, v35, v36, v37, v38, v39);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40>\ninternal::ValueArray40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> Values(T1 v1,\n    T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11,\n    T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19,\n    T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27,\n    T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35,\n    T36 v36, T37 v37, T38 v38, T39 v39, T40 v40) {\n  return internal::ValueArray40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15,\n      v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29,\n      v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41>\ninternal::ValueArray41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,\n    T41> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n    T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n    T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n    T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41) {\n  return internal::ValueArray41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14,\n      v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28,\n      v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42>\ninternal::ValueArray42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,\n    T42> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n    T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n    T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n    T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n    T42 v42) {\n  return internal::ValueArray42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41, T42>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,\n      v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27,\n      v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41,\n      v42);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43>\ninternal::ValueArray43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,\n    T43> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n    T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n    T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n    T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n    T42 v42, T43 v43) {\n  return internal::ValueArray43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41, T42, T43>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12,\n      v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26,\n      v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40,\n      v41, v42, v43);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44>\ninternal::ValueArray44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    T44> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,\n    T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,\n    T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,\n    T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,\n    T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,\n    T42 v42, T43 v43, T44 v44) {\n  return internal::ValueArray44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41, T42, T43, T44>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,\n      v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25,\n      v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39,\n      v40, v41, v42, v43, v44);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45>\ninternal::ValueArray45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    T44, T45> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,\n    T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16,\n    T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24,\n    T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32,\n    T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40,\n    T41 v41, T42 v42, T43 v43, T44 v44, T45 v45) {\n  return internal::ValueArray45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41, T42, T43, T44, T45>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,\n      v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24,\n      v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38,\n      v39, v40, v41, v42, v43, v44, v45);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46>\ninternal::ValueArray46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    T44, T45, T46> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,\n    T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,\n    T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,\n    T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,\n    T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39,\n    T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46) {\n  return internal::ValueArray46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41, T42, T43, T44, T45, T46>(v1, v2, v3, v4, v5, v6, v7, v8, v9,\n      v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,\n      v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37,\n      v38, v39, v40, v41, v42, v43, v44, v45, v46);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47>\ninternal::ValueArray47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    T44, T45, T46, T47> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,\n    T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,\n    T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,\n    T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,\n    T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39,\n    T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47) {\n  return internal::ValueArray47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41, T42, T43, T44, T45, T46, T47>(v1, v2, v3, v4, v5, v6, v7, v8,\n      v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,\n      v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37,\n      v38, v39, v40, v41, v42, v43, v44, v45, v46, v47);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48>\ninternal::ValueArray48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    T44, T45, T46, T47, T48> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6,\n    T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,\n    T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,\n    T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,\n    T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39,\n    T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47,\n    T48 v48) {\n  return internal::ValueArray48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41, T42, T43, T44, T45, T46, T47, T48>(v1, v2, v3, v4, v5, v6, v7,\n      v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22,\n      v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36,\n      v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48, typename T49>\ninternal::ValueArray49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    T44, T45, T46, T47, T48, T49> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,\n    T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14,\n    T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22,\n    T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30,\n    T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38,\n    T39 v39, T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46,\n    T47 v47, T48 v48, T49 v49) {\n  return internal::ValueArray49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41, T42, T43, T44, T45, T46, T47, T48, T49>(v1, v2, v3, v4, v5, v6,\n      v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,\n      v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35,\n      v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49);\n}\n\ntemplate <typename T1, typename T2, typename T3, typename T4, typename T5,\n    typename T6, typename T7, typename T8, typename T9, typename T10,\n    typename T11, typename T12, typename T13, typename T14, typename T15,\n    typename T16, typename T17, typename T18, typename T19, typename T20,\n    typename T21, typename T22, typename T23, typename T24, typename T25,\n    typename T26, typename T27, typename T28, typename T29, typename T30,\n    typename T31, typename T32, typename T33, typename T34, typename T35,\n    typename T36, typename T37, typename T38, typename T39, typename T40,\n    typename T41, typename T42, typename T43, typename T44, typename T45,\n    typename T46, typename T47, typename T48, typename T49, typename T50>\ninternal::ValueArray50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,\n    T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,\n    T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,\n    T44, T45, T46, T47, T48, T49, T50> Values(T1 v1, T2 v2, T3 v3, T4 v4,\n    T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,\n    T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21,\n    T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29,\n    T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37,\n    T38 v38, T39 v39, T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45,\n    T46 v46, T47 v47, T48 v48, T49 v49, T50 v50) {\n  return internal::ValueArray50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,\n      T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,\n      T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,\n      T40, T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>(v1, v2, v3, v4,\n      v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,\n      v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33,\n      v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47,\n      v48, v49, v50);\n}\n\n// Bool() allows generating tests with parameters in a set of (false, true).\n//\n// Synopsis:\n// Bool()\n//   - returns a generator producing sequences with elements {false, true}.\n//\n// It is useful when testing code that depends on Boolean flags. Combinations\n// of multiple flags can be tested when several Bool()'s are combined using\n// Combine() function.\n//\n// In the following example all tests in the test case FlagDependentTest\n// will be instantiated twice with parameters false and true.\n//\n// class FlagDependentTest : public testing::TestWithParam<bool> {\n//   virtual void SetUp() {\n//     external_flag = GetParam();\n//   }\n// }\n// INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());\n//\ninline internal::ParamGenerator<bool> Bool() {\n  return Values(false, true);\n}\n\n# if GTEST_HAS_COMBINE\n// Combine() allows the user to combine two or more sequences to produce\n// values of a Cartesian product of those sequences' elements.\n//\n// Synopsis:\n// Combine(gen1, gen2, ..., genN)\n//   - returns a generator producing sequences with elements coming from\n//     the Cartesian product of elements from the sequences generated by\n//     gen1, gen2, ..., genN. The sequence elements will have a type of\n//     tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types\n//     of elements from sequences produces by gen1, gen2, ..., genN.\n//\n// Combine can have up to 10 arguments. This number is currently limited\n// by the maximum number of elements in the tuple implementation used by Google\n// Test.\n//\n// Example:\n//\n// This will instantiate tests in test case AnimalTest each one with\n// the parameter values tuple(\"cat\", BLACK), tuple(\"cat\", WHITE),\n// tuple(\"dog\", BLACK), and tuple(\"dog\", WHITE):\n//\n// enum Color { BLACK, GRAY, WHITE };\n// class AnimalTest\n//     : public testing::TestWithParam<tuple<const char*, Color> > {...};\n//\n// TEST_P(AnimalTest, AnimalLooksNice) {...}\n//\n// INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,\n//                         Combine(Values(\"cat\", \"dog\"),\n//                                 Values(BLACK, WHITE)));\n//\n// This will instantiate tests in FlagDependentTest with all variations of two\n// Boolean flags:\n//\n// class FlagDependentTest\n//     : public testing::TestWithParam<tuple(bool, bool)> > {\n//   virtual void SetUp() {\n//     // Assigns external_flag_1 and external_flag_2 values from the tuple.\n//     tie(external_flag_1, external_flag_2) = GetParam();\n//   }\n// };\n//\n// TEST_P(FlagDependentTest, TestFeature1) {\n//   // Test your code using external_flag_1 and external_flag_2 here.\n// }\n// INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,\n//                         Combine(Bool(), Bool()));\n//\ntemplate <typename Generator1, typename Generator2>\ninternal::CartesianProductHolder2<Generator1, Generator2> Combine(\n    const Generator1& g1, const Generator2& g2) {\n  return internal::CartesianProductHolder2<Generator1, Generator2>(\n      g1, g2);\n}\n\ntemplate <typename Generator1, typename Generator2, typename Generator3>\ninternal::CartesianProductHolder3<Generator1, Generator2, Generator3> Combine(\n    const Generator1& g1, const Generator2& g2, const Generator3& g3) {\n  return internal::CartesianProductHolder3<Generator1, Generator2, Generator3>(\n      g1, g2, g3);\n}\n\ntemplate <typename Generator1, typename Generator2, typename Generator3,\n    typename Generator4>\ninternal::CartesianProductHolder4<Generator1, Generator2, Generator3,\n    Generator4> Combine(\n    const Generator1& g1, const Generator2& g2, const Generator3& g3,\n        const Generator4& g4) {\n  return internal::CartesianProductHolder4<Generator1, Generator2, Generator3,\n      Generator4>(\n      g1, g2, g3, g4);\n}\n\ntemplate <typename Generator1, typename Generator2, typename Generator3,\n    typename Generator4, typename Generator5>\ninternal::CartesianProductHolder5<Generator1, Generator2, Generator3,\n    Generator4, Generator5> Combine(\n    const Generator1& g1, const Generator2& g2, const Generator3& g3,\n        const Generator4& g4, const Generator5& g5) {\n  return internal::CartesianProductHolder5<Generator1, Generator2, Generator3,\n      Generator4, Generator5>(\n      g1, g2, g3, g4, g5);\n}\n\ntemplate <typename Generator1, typename Generator2, typename Generator3,\n    typename Generator4, typename Generator5, typename Generator6>\ninternal::CartesianProductHolder6<Generator1, Generator2, Generator3,\n    Generator4, Generator5, Generator6> Combine(\n    const Generator1& g1, const Generator2& g2, const Generator3& g3,\n        const Generator4& g4, const Generator5& g5, const Generator6& g6) {\n  return internal::CartesianProductHolder6<Generator1, Generator2, Generator3,\n      Generator4, Generator5, Generator6>(\n      g1, g2, g3, g4, g5, g6);\n}\n\ntemplate <typename Generator1, typename Generator2, typename Generator3,\n    typename Generator4, typename Generator5, typename Generator6,\n    typename Generator7>\ninternal::CartesianProductHolder7<Generator1, Generator2, Generator3,\n    Generator4, Generator5, Generator6, Generator7> Combine(\n    const Generator1& g1, const Generator2& g2, const Generator3& g3,\n        const Generator4& g4, const Generator5& g5, const Generator6& g6,\n        const Generator7& g7) {\n  return internal::CartesianProductHolder7<Generator1, Generator2, Generator3,\n      Generator4, Generator5, Generator6, Generator7>(\n      g1, g2, g3, g4, g5, g6, g7);\n}\n\ntemplate <typename Generator1, typename Generator2, typename Generator3,\n    typename Generator4, typename Generator5, typename Generator6,\n    typename Generator7, typename Generator8>\ninternal::CartesianProductHolder8<Generator1, Generator2, Generator3,\n    Generator4, Generator5, Generator6, Generator7, Generator8> Combine(\n    const Generator1& g1, const Generator2& g2, const Generator3& g3,\n        const Generator4& g4, const Generator5& g5, const Generator6& g6,\n        const Generator7& g7, const Generator8& g8) {\n  return internal::CartesianProductHolder8<Generator1, Generator2, Generator3,\n      Generator4, Generator5, Generator6, Generator7, Generator8>(\n      g1, g2, g3, g4, g5, g6, g7, g8);\n}\n\ntemplate <typename Generator1, typename Generator2, typename Generator3,\n    typename Generator4, typename Generator5, typename Generator6,\n    typename Generator7, typename Generator8, typename Generator9>\ninternal::CartesianProductHolder9<Generator1, Generator2, Generator3,\n    Generator4, Generator5, Generator6, Generator7, Generator8,\n    Generator9> Combine(\n    const Generator1& g1, const Generator2& g2, const Generator3& g3,\n        const Generator4& g4, const Generator5& g5, const Generator6& g6,\n        const Generator7& g7, const Generator8& g8, const Generator9& g9) {\n  return internal::CartesianProductHolder9<Generator1, Generator2, Generator3,\n      Generator4, Generator5, Generator6, Generator7, Generator8, Generator9>(\n      g1, g2, g3, g4, g5, g6, g7, g8, g9);\n}\n\ntemplate <typename Generator1, typename Generator2, typename Generator3,\n    typename Generator4, typename Generator5, typename Generator6,\n    typename Generator7, typename Generator8, typename Generator9,\n    typename Generator10>\ninternal::CartesianProductHolder10<Generator1, Generator2, Generator3,\n    Generator4, Generator5, Generator6, Generator7, Generator8, Generator9,\n    Generator10> Combine(\n    const Generator1& g1, const Generator2& g2, const Generator3& g3,\n        const Generator4& g4, const Generator5& g5, const Generator6& g6,\n        const Generator7& g7, const Generator8& g8, const Generator9& g9,\n        const Generator10& g10) {\n  return internal::CartesianProductHolder10<Generator1, Generator2, Generator3,\n      Generator4, Generator5, Generator6, Generator7, Generator8, Generator9,\n      Generator10>(\n      g1, g2, g3, g4, g5, g6, g7, g8, g9, g10);\n}\n# endif  // GTEST_HAS_COMBINE\n\n\n\n# define TEST_P(test_case_name, test_name) \\\n  class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \\\n      : public test_case_name { \\\n   public: \\\n    GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \\\n    virtual void TestBody(); \\\n   private: \\\n    static int AddToRegistry() { \\\n      ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \\\n          GetTestCasePatternHolder<test_case_name>(\\\n              #test_case_name, __FILE__, __LINE__)->AddTestPattern(\\\n                  #test_case_name, \\\n                  #test_name, \\\n                  new ::testing::internal::TestMetaFactory< \\\n                      GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \\\n      return 0; \\\n    } \\\n    static int gtest_registering_dummy_; \\\n    GTEST_DISALLOW_COPY_AND_ASSIGN_(\\\n        GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \\\n  }; \\\n  int GTEST_TEST_CLASS_NAME_(test_case_name, \\\n                             test_name)::gtest_registering_dummy_ = \\\n      GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \\\n  void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()\n\n# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \\\n  ::testing::internal::ParamGenerator<test_case_name::ParamType> \\\n      gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \\\n  int gtest_##prefix##test_case_name##_dummy_ = \\\n      ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \\\n          GetTestCasePatternHolder<test_case_name>(\\\n              #test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiation(\\\n                  #prefix, \\\n                  &gtest_##prefix##test_case_name##_EvalGenerator_, \\\n                  __FILE__, __LINE__)\n\n}  // namespace testing\n\n#endif  // GTEST_HAS_PARAM_TEST\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_\n// Copyright 2006, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n//\n// Google C++ Testing Framework definitions useful in production code.\n\n#ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_\n#define GTEST_INCLUDE_GTEST_GTEST_PROD_H_\n\n// When you need to test the private or protected members of a class,\n// use the FRIEND_TEST macro to declare your tests as friends of the\n// class.  For example:\n//\n// class MyClass {\n//  private:\n//   void MyMethod();\n//   FRIEND_TEST(MyClassTest, MyMethod);\n// };\n//\n// class MyClassTest : public testing::Test {\n//   // ...\n// };\n//\n// TEST_F(MyClassTest, MyMethod) {\n//   // Can call MyClass::MyMethod() here.\n// }\n\n#define FRIEND_TEST(test_case_name, test_name)\\\nfriend class test_case_name##_##test_name##_Test\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_PROD_H_\n// Copyright 2008, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: mheule@google.com (Markus Heule)\n//\n\n#ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_\n#define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_\n\n#include <iosfwd>\n#include <vector>\n\nnamespace testing {\n\n// A copyable object representing the result of a test part (i.e. an\n// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).\n//\n// Don't inherit from TestPartResult as its destructor is not virtual.\nclass GTEST_API_ TestPartResult {\n public:\n  // The possible outcomes of a test part (i.e. an assertion or an\n  // explicit SUCCEED(), FAIL(), or ADD_FAILURE()).\n  enum Type {\n    kSuccess,          // Succeeded.\n    kNonFatalFailure,  // Failed but the test can continue.\n    kFatalFailure      // Failed and the test should be terminated.\n  };\n\n  // C'tor.  TestPartResult does NOT have a default constructor.\n  // Always use this constructor (with parameters) to create a\n  // TestPartResult object.\n  TestPartResult(Type a_type,\n                 const char* a_file_name,\n                 int a_line_number,\n                 const char* a_message)\n      : type_(a_type),\n        file_name_(a_file_name),\n        line_number_(a_line_number),\n        summary_(ExtractSummary(a_message)),\n        message_(a_message) {\n  }\n\n  // Gets the outcome of the test part.\n  Type type() const { return type_; }\n\n  // Gets the name of the source file where the test part took place, or\n  // NULL if it's unknown.\n  const char* file_name() const { return file_name_.c_str(); }\n\n  // Gets the line in the source file where the test part took place,\n  // or -1 if it's unknown.\n  int line_number() const { return line_number_; }\n\n  // Gets the summary of the failure message.\n  const char* summary() const { return summary_.c_str(); }\n\n  // Gets the message associated with the test part.\n  const char* message() const { return message_.c_str(); }\n\n  // Returns true iff the test part passed.\n  bool passed() const { return type_ == kSuccess; }\n\n  // Returns true iff the test part failed.\n  bool failed() const { return type_ != kSuccess; }\n\n  // Returns true iff the test part non-fatally failed.\n  bool nonfatally_failed() const { return type_ == kNonFatalFailure; }\n\n  // Returns true iff the test part fatally failed.\n  bool fatally_failed() const { return type_ == kFatalFailure; }\n private:\n  Type type_;\n\n  // Gets the summary of the failure message by omitting the stack\n  // trace in it.\n  static internal::String ExtractSummary(const char* message);\n\n  // The name of the source file where the test part took place, or\n  // NULL if the source file is unknown.\n  internal::String file_name_;\n  // The line in the source file where the test part took place, or -1\n  // if the line number is unknown.\n  int line_number_;\n  internal::String summary_;  // The test failure summary.\n  internal::String message_;  // The test failure message.\n};\n\n// Prints a TestPartResult object.\nstd::ostream& operator<<(std::ostream& os, const TestPartResult& result);\n\n// An array of TestPartResult objects.\n//\n// Don't inherit from TestPartResultArray as its destructor is not\n// virtual.\nclass GTEST_API_ TestPartResultArray {\n public:\n  TestPartResultArray() {}\n\n  // Appends the given TestPartResult to the array.\n  void Append(const TestPartResult& result);\n\n  // Returns the TestPartResult at the given index (0-based).\n  const TestPartResult& GetTestPartResult(int index) const;\n\n  // Returns the number of TestPartResult objects in the array.\n  int size() const;\n\n private:\n  std::vector<TestPartResult> array_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray);\n};\n\n// This interface knows how to report a test part result.\nclass TestPartResultReporterInterface {\n public:\n  virtual ~TestPartResultReporterInterface() {}\n\n  virtual void ReportTestPartResult(const TestPartResult& result) = 0;\n};\n\nnamespace internal {\n\n// This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a\n// statement generates new fatal failures. To do so it registers itself as the\n// current test part result reporter. Besides checking if fatal failures were\n// reported, it only delegates the reporting to the former result reporter.\n// The original result reporter is restored in the destructor.\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\nclass GTEST_API_ HasNewFatalFailureHelper\n    : public TestPartResultReporterInterface {\n public:\n  HasNewFatalFailureHelper();\n  virtual ~HasNewFatalFailureHelper();\n  virtual void ReportTestPartResult(const TestPartResult& result);\n  bool has_new_fatal_failure() const { return has_new_fatal_failure_; }\n private:\n  bool has_new_fatal_failure_;\n  TestPartResultReporterInterface* original_reporter_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper);\n};\n\n}  // namespace internal\n\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_\n// Copyright 2008 Google Inc.\n// All Rights Reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Author: wan@google.com (Zhanyong Wan)\n\n#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_\n#define GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_\n\n// This header implements typed tests and type-parameterized tests.\n\n// Typed (aka type-driven) tests repeat the same test for types in a\n// list.  You must know which types you want to test with when writing\n// typed tests. Here's how you do it:\n\n#if 0\n\n// First, define a fixture class template.  It should be parameterized\n// by a type.  Remember to derive it from testing::Test.\ntemplate <typename T>\nclass FooTest : public testing::Test {\n public:\n  ...\n  typedef std::list<T> List;\n  static T shared_;\n  T value_;\n};\n\n// Next, associate a list of types with the test case, which will be\n// repeated for each type in the list.  The typedef is necessary for\n// the macro to parse correctly.\ntypedef testing::Types<char, int, unsigned int> MyTypes;\nTYPED_TEST_CASE(FooTest, MyTypes);\n\n// If the type list contains only one type, you can write that type\n// directly without Types<...>:\n//   TYPED_TEST_CASE(FooTest, int);\n\n// Then, use TYPED_TEST() instead of TEST_F() to define as many typed\n// tests for this test case as you want.\nTYPED_TEST(FooTest, DoesBlah) {\n  // Inside a test, refer to TypeParam to get the type parameter.\n  // Since we are inside a derived class template, C++ requires use to\n  // visit the members of FooTest via 'this'.\n  TypeParam n = this->value_;\n\n  // To visit static members of the fixture, add the TestFixture::\n  // prefix.\n  n += TestFixture::shared_;\n\n  // To refer to typedefs in the fixture, add the \"typename\n  // TestFixture::\" prefix.\n  typename TestFixture::List values;\n  values.push_back(n);\n  ...\n}\n\nTYPED_TEST(FooTest, HasPropertyA) { ... }\n\n#endif  // 0\n\n// Type-parameterized tests are abstract test patterns parameterized\n// by a type.  Compared with typed tests, type-parameterized tests\n// allow you to define the test pattern without knowing what the type\n// parameters are.  The defined pattern can be instantiated with\n// different types any number of times, in any number of translation\n// units.\n//\n// If you are designing an interface or concept, you can define a\n// suite of type-parameterized tests to verify properties that any\n// valid implementation of the interface/concept should have.  Then,\n// each implementation can easily instantiate the test suite to verify\n// that it conforms to the requirements, without having to write\n// similar tests repeatedly.  Here's an example:\n\n#if 0\n\n// First, define a fixture class template.  It should be parameterized\n// by a type.  Remember to derive it from testing::Test.\ntemplate <typename T>\nclass FooTest : public testing::Test {\n  ...\n};\n\n// Next, declare that you will define a type-parameterized test case\n// (the _P suffix is for \"parameterized\" or \"pattern\", whichever you\n// prefer):\nTYPED_TEST_CASE_P(FooTest);\n\n// Then, use TYPED_TEST_P() to define as many type-parameterized tests\n// for this type-parameterized test case as you want.\nTYPED_TEST_P(FooTest, DoesBlah) {\n  // Inside a test, refer to TypeParam to get the type parameter.\n  TypeParam n = 0;\n  ...\n}\n\nTYPED_TEST_P(FooTest, HasPropertyA) { ... }\n\n// Now the tricky part: you need to register all test patterns before\n// you can instantiate them.  The first argument of the macro is the\n// test case name; the rest are the names of the tests in this test\n// case.\nREGISTER_TYPED_TEST_CASE_P(FooTest,\n                           DoesBlah, HasPropertyA);\n\n// Finally, you are free to instantiate the pattern with the types you\n// want.  If you put the above code in a header file, you can #include\n// it in multiple C++ source files and instantiate it multiple times.\n//\n// To distinguish different instances of the pattern, the first\n// argument to the INSTANTIATE_* macro is a prefix that will be added\n// to the actual test case name.  Remember to pick unique prefixes for\n// different instances.\ntypedef testing::Types<char, int, unsigned int> MyTypes;\nINSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);\n\n// If the type list contains only one type, you can write that type\n// directly without Types<...>:\n//   INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);\n\n#endif  // 0\n\n\n// Implements typed tests.\n\n#if GTEST_HAS_TYPED_TEST\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// Expands to the name of the typedef for the type parameters of the\n// given test case.\n# define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_\n\n// The 'Types' template argument below must have spaces around it\n// since some compilers may choke on '>>' when passing a template\n// instance (e.g. Types<int>)\n# define TYPED_TEST_CASE(CaseName, Types) \\\n  typedef ::testing::internal::TypeList< Types >::type \\\n      GTEST_TYPE_PARAMS_(CaseName)\n\n# define TYPED_TEST(CaseName, TestName) \\\n  template <typename gtest_TypeParam_> \\\n  class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \\\n      : public CaseName<gtest_TypeParam_> { \\\n   private: \\\n    typedef CaseName<gtest_TypeParam_> TestFixture; \\\n    typedef gtest_TypeParam_ TypeParam; \\\n    virtual void TestBody(); \\\n  }; \\\n  bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \\\n      ::testing::internal::TypeParameterizedTest< \\\n          CaseName, \\\n          ::testing::internal::TemplateSel< \\\n              GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \\\n          GTEST_TYPE_PARAMS_(CaseName)>::Register(\\\n              \"\", #CaseName, #TestName, 0); \\\n  template <typename gtest_TypeParam_> \\\n  void GTEST_TEST_CLASS_NAME_(CaseName, TestName)<gtest_TypeParam_>::TestBody()\n\n#endif  // GTEST_HAS_TYPED_TEST\n\n// Implements type-parameterized tests.\n\n#if GTEST_HAS_TYPED_TEST_P\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// Expands to the namespace name that the type-parameterized tests for\n// the given type-parameterized test case are defined in.  The exact\n// name of the namespace is subject to change without notice.\n# define GTEST_CASE_NAMESPACE_(TestCaseName) \\\n  gtest_case_##TestCaseName##_\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n//\n// Expands to the name of the variable used to remember the names of\n// the defined tests in the given test case.\n# define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \\\n  gtest_typed_test_case_p_state_##TestCaseName##_\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.\n//\n// Expands to the name of the variable used to remember the names of\n// the registered tests in the given test case.\n# define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \\\n  gtest_registered_test_names_##TestCaseName##_\n\n// The variables defined in the type-parameterized test macros are\n// static as typically these macros are used in a .h file that can be\n// #included in multiple translation units linked together.\n# define TYPED_TEST_CASE_P(CaseName) \\\n  static ::testing::internal::TypedTestCasePState \\\n      GTEST_TYPED_TEST_CASE_P_STATE_(CaseName)\n\n# define TYPED_TEST_P(CaseName, TestName) \\\n  namespace GTEST_CASE_NAMESPACE_(CaseName) { \\\n  template <typename gtest_TypeParam_> \\\n  class TestName : public CaseName<gtest_TypeParam_> { \\\n   private: \\\n    typedef CaseName<gtest_TypeParam_> TestFixture; \\\n    typedef gtest_TypeParam_ TypeParam; \\\n    virtual void TestBody(); \\\n  }; \\\n  static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \\\n      GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\\\n          __FILE__, __LINE__, #CaseName, #TestName); \\\n  } \\\n  template <typename gtest_TypeParam_> \\\n  void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody()\n\n# define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \\\n  namespace GTEST_CASE_NAMESPACE_(CaseName) { \\\n  typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \\\n  } \\\n  static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) = \\\n      GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\\\n          __FILE__, __LINE__, #__VA_ARGS__)\n\n// The 'Types' template argument below must have spaces around it\n// since some compilers may choke on '>>' when passing a template\n// instance (e.g. Types<int>)\n# define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \\\n  bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \\\n      ::testing::internal::TypeParameterizedTestCase<CaseName, \\\n          GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \\\n          ::testing::internal::TypeList< Types >::type>::Register(\\\n              #Prefix, #CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName))\n\n#endif  // GTEST_HAS_TYPED_TEST_P\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_\n\n// Depending on the platform, different string classes are available.\n// On Linux, in addition to ::std::string, Google also makes use of\n// class ::string, which has the same interface as ::std::string, but\n// has a different implementation.\n//\n// The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that\n// ::string is available AND is a distinct type to ::std::string, or\n// define it to 0 to indicate otherwise.\n//\n// If the user's ::std::string and ::string are the same class due to\n// aliasing, he should define GTEST_HAS_GLOBAL_STRING to 0.\n//\n// If the user doesn't define GTEST_HAS_GLOBAL_STRING, it is defined\n// heuristically.\n\nnamespace testing {\n\n// Declares the flags.\n\n// This flag temporary enables the disabled tests.\nGTEST_DECLARE_bool_(also_run_disabled_tests);\n\n// This flag brings the debugger on an assertion failure.\nGTEST_DECLARE_bool_(break_on_failure);\n\n// This flag controls whether Google Test catches all test-thrown exceptions\n// and logs them as failures.\nGTEST_DECLARE_bool_(catch_exceptions);\n\n// This flag enables using colors in terminal output. Available values are\n// \"yes\" to enable colors, \"no\" (disable colors), or \"auto\" (the default)\n// to let Google Test decide.\nGTEST_DECLARE_string_(color);\n\n// This flag sets up the filter to select by name using a glob pattern\n// the tests to run. If the filter is not given all tests are executed.\nGTEST_DECLARE_string_(filter);\n\n// This flag causes the Google Test to list tests. None of the tests listed\n// are actually run if the flag is provided.\nGTEST_DECLARE_bool_(list_tests);\n\n// This flag controls whether Google Test emits a detailed XML report to a file\n// in addition to its normal textual output.\nGTEST_DECLARE_string_(output);\n\n// This flags control whether Google Test prints the elapsed time for each\n// test.\nGTEST_DECLARE_bool_(print_time);\n\n// This flag specifies the random number seed.\nGTEST_DECLARE_int32_(random_seed);\n\n// This flag sets how many times the tests are repeated. The default value\n// is 1. If the value is -1 the tests are repeating forever.\nGTEST_DECLARE_int32_(repeat);\n\n// This flag controls whether Google Test includes Google Test internal\n// stack frames in failure stack traces.\nGTEST_DECLARE_bool_(show_internal_stack_frames);\n\n// When this flag is specified, tests' order is randomized on every iteration.\nGTEST_DECLARE_bool_(shuffle);\n\n// This flag specifies the maximum number of stack frames to be\n// printed in a failure message.\nGTEST_DECLARE_int32_(stack_trace_depth);\n\n// When this flag is specified, a failed assertion will throw an\n// exception if exceptions are enabled, or exit the program with a\n// non-zero code otherwise.\nGTEST_DECLARE_bool_(throw_on_failure);\n\n// When this flag is set with a \"host:port\" string, on supported\n// platforms test results are streamed to the specified port on\n// the specified host machine.\nGTEST_DECLARE_string_(stream_result_to);\n\n// The upper limit for valid stack trace depths.\nconst int kMaxStackTraceDepth = 100;\n\nnamespace internal {\n\nclass AssertHelper;\nclass DefaultGlobalTestPartResultReporter;\nclass ExecDeathTest;\nclass NoExecDeathTest;\nclass FinalSuccessChecker;\nclass GTestFlagSaver;\nclass TestResultAccessor;\nclass TestEventListenersAccessor;\nclass TestEventRepeater;\nclass WindowsDeathTest;\nclass UnitTestImpl* GetUnitTestImpl();\nvoid ReportFailureInUnknownLocation(TestPartResult::Type result_type,\n                                    const String& message);\n\n// Converts a streamable value to a String.  A NULL pointer is\n// converted to \"(null)\".  When the input value is a ::string,\n// ::std::string, ::wstring, or ::std::wstring object, each NUL\n// character in it is replaced with \"\\\\0\".\n// Declared in gtest-internal.h but defined here, so that it has access\n// to the definition of the Message class, required by the ARM\n// compiler.\ntemplate <typename T>\nString StreamableToString(const T& streamable) {\n  return (Message() << streamable).GetString();\n}\n\n}  // namespace internal\n\n// The friend relationship of some of these classes is cyclic.\n// If we don't forward declare them the compiler might confuse the classes\n// in friendship clauses with same named classes on the scope.\nclass Test;\nclass TestCase;\nclass TestInfo;\nclass UnitTest;\n\n// A class for indicating whether an assertion was successful.  When\n// the assertion wasn't successful, the AssertionResult object\n// remembers a non-empty message that describes how it failed.\n//\n// To create an instance of this class, use one of the factory functions\n// (AssertionSuccess() and AssertionFailure()).\n//\n// This class is useful for two purposes:\n//   1. Defining predicate functions to be used with Boolean test assertions\n//      EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts\n//   2. Defining predicate-format functions to be\n//      used with predicate assertions (ASSERT_PRED_FORMAT*, etc).\n//\n// For example, if you define IsEven predicate:\n//\n//   testing::AssertionResult IsEven(int n) {\n//     if ((n % 2) == 0)\n//       return testing::AssertionSuccess();\n//     else\n//       return testing::AssertionFailure() << n << \" is odd\";\n//   }\n//\n// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))\n// will print the message\n//\n//   Value of: IsEven(Fib(5))\n//     Actual: false (5 is odd)\n//   Expected: true\n//\n// instead of a more opaque\n//\n//   Value of: IsEven(Fib(5))\n//     Actual: false\n//   Expected: true\n//\n// in case IsEven is a simple Boolean predicate.\n//\n// If you expect your predicate to be reused and want to support informative\n// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up\n// about half as often as positive ones in our tests), supply messages for\n// both success and failure cases:\n//\n//   testing::AssertionResult IsEven(int n) {\n//     if ((n % 2) == 0)\n//       return testing::AssertionSuccess() << n << \" is even\";\n//     else\n//       return testing::AssertionFailure() << n << \" is odd\";\n//   }\n//\n// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print\n//\n//   Value of: IsEven(Fib(6))\n//     Actual: true (8 is even)\n//   Expected: false\n//\n// NB: Predicates that support negative Boolean assertions have reduced\n// performance in positive ones so be careful not to use them in tests\n// that have lots (tens of thousands) of positive Boolean assertions.\n//\n// To use this class with EXPECT_PRED_FORMAT assertions such as:\n//\n//   // Verifies that Foo() returns an even number.\n//   EXPECT_PRED_FORMAT1(IsEven, Foo());\n//\n// you need to define:\n//\n//   testing::AssertionResult IsEven(const char* expr, int n) {\n//     if ((n % 2) == 0)\n//       return testing::AssertionSuccess();\n//     else\n//       return testing::AssertionFailure()\n//         << \"Expected: \" << expr << \" is even\\n  Actual: it's \" << n;\n//   }\n//\n// If Foo() returns 5, you will see the following message:\n//\n//   Expected: Foo() is even\n//     Actual: it's 5\n//\nclass GTEST_API_ AssertionResult {\n public:\n  // Copy constructor.\n  // Used in EXPECT_TRUE/FALSE(assertion_result).\n  AssertionResult(const AssertionResult& other);\n  // Used in the EXPECT_TRUE/FALSE(bool_expression).\n  explicit AssertionResult(bool success) : success_(success) {}\n\n  // Returns true iff the assertion succeeded.\n  operator bool() const { return success_; }  // NOLINT\n\n  // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.\n  AssertionResult operator!() const;\n\n  // Returns the text streamed into this AssertionResult. Test assertions\n  // use it when they fail (i.e., the predicate's outcome doesn't match the\n  // assertion's expectation). When nothing has been streamed into the\n  // object, returns an empty string.\n  const char* message() const {\n    return message_.get() != NULL ?  message_->c_str() : \"\";\n  }\n  // TODO(vladl@google.com): Remove this after making sure no clients use it.\n  // Deprecated; please use message() instead.\n  const char* failure_message() const { return message(); }\n\n  // Streams a custom failure message into this object.\n  template <typename T> AssertionResult& operator<<(const T& value) {\n    AppendMessage(Message() << value);\n    return *this;\n  }\n\n  // Allows streaming basic output manipulators such as endl or flush into\n  // this object.\n  AssertionResult& operator<<(\n      ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {\n    AppendMessage(Message() << basic_manipulator);\n    return *this;\n  }\n\n private:\n  // Appends the contents of message to message_.\n  void AppendMessage(const Message& a_message) {\n    if (message_.get() == NULL)\n      message_.reset(new ::std::string);\n    message_->append(a_message.GetString().c_str());\n  }\n\n  // Stores result of the assertion predicate.\n  bool success_;\n  // Stores the message describing the condition in case the expectation\n  // construct is not satisfied with the predicate's outcome.\n  // Referenced via a pointer to avoid taking too much stack frame space\n  // with test assertions.\n  internal::scoped_ptr< ::std::string> message_;\n\n  GTEST_DISALLOW_ASSIGN_(AssertionResult);\n};\n\n// Makes a successful assertion result.\nGTEST_API_ AssertionResult AssertionSuccess();\n\n// Makes a failed assertion result.\nGTEST_API_ AssertionResult AssertionFailure();\n\n// Makes a failed assertion result with the given failure message.\n// Deprecated; use AssertionFailure() << msg.\nGTEST_API_ AssertionResult AssertionFailure(const Message& msg);\n\n// The abstract class that all tests inherit from.\n//\n// In Google Test, a unit test program contains one or many TestCases, and\n// each TestCase contains one or many Tests.\n//\n// When you define a test using the TEST macro, you don't need to\n// explicitly derive from Test - the TEST macro automatically does\n// this for you.\n//\n// The only time you derive from Test is when defining a test fixture\n// to be used a TEST_F.  For example:\n//\n//   class FooTest : public testing::Test {\n//    protected:\n//     virtual void SetUp() { ... }\n//     virtual void TearDown() { ... }\n//     ...\n//   };\n//\n//   TEST_F(FooTest, Bar) { ... }\n//   TEST_F(FooTest, Baz) { ... }\n//\n// Test is not copyable.\nclass GTEST_API_ Test {\n public:\n  friend class TestInfo;\n\n  // Defines types for pointers to functions that set up and tear down\n  // a test case.\n  typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;\n  typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;\n\n  // The d'tor is virtual as we intend to inherit from Test.\n  virtual ~Test();\n\n  // Sets up the stuff shared by all tests in this test case.\n  //\n  // Google Test will call Foo::SetUpTestCase() before running the first\n  // test in test case Foo.  Hence a sub-class can define its own\n  // SetUpTestCase() method to shadow the one defined in the super\n  // class.\n  static void SetUpTestCase() {}\n\n  // Tears down the stuff shared by all tests in this test case.\n  //\n  // Google Test will call Foo::TearDownTestCase() after running the last\n  // test in test case Foo.  Hence a sub-class can define its own\n  // TearDownTestCase() method to shadow the one defined in the super\n  // class.\n  static void TearDownTestCase() {}\n\n  // Returns true iff the current test has a fatal failure.\n  static bool HasFatalFailure();\n\n  // Returns true iff the current test has a non-fatal failure.\n  static bool HasNonfatalFailure();\n\n  // Returns true iff the current test has a (either fatal or\n  // non-fatal) failure.\n  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }\n\n  // Logs a property for the current test.  Only the last value for a given\n  // key is remembered.\n  // These are public static so they can be called from utility functions\n  // that are not members of the test fixture.\n  // The arguments are const char* instead strings, as Google Test is used\n  // on platforms where string doesn't compile.\n  //\n  // Note that a driving consideration for these RecordProperty methods\n  // was to produce xml output suited to the Greenspan charting utility,\n  // which at present will only chart values that fit in a 32-bit int. It\n  // is the user's responsibility to restrict their values to 32-bit ints\n  // if they intend them to be used with Greenspan.\n  static void RecordProperty(const char* key, const char* value);\n  static void RecordProperty(const char* key, int value);\n\n protected:\n  // Creates a Test object.\n  Test();\n\n  // Sets up the test fixture.\n  virtual void SetUp();\n\n  // Tears down the test fixture.\n  virtual void TearDown();\n\n private:\n  // Returns true iff the current test has the same fixture class as\n  // the first test in the current test case.\n  static bool HasSameFixtureClass();\n\n  // Runs the test after the test fixture has been set up.\n  //\n  // A sub-class must implement this to define the test logic.\n  //\n  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.\n  // Instead, use the TEST or TEST_F macro.\n  virtual void TestBody() = 0;\n\n  // Sets up, executes, and tears down the test.\n  void Run();\n\n  // Deletes self.  We deliberately pick an unusual name for this\n  // internal method to avoid clashing with names used in user TESTs.\n  void DeleteSelf_() { delete this; }\n\n  // Uses a GTestFlagSaver to save and restore all Google Test flags.\n  const internal::GTestFlagSaver* const gtest_flag_saver_;\n\n  // Often a user mis-spells SetUp() as Setup() and spends a long time\n  // wondering why it is never called by Google Test.  The declaration of\n  // the following method is solely for catching such an error at\n  // compile time:\n  //\n  //   - The return type is deliberately chosen to be not void, so it\n  //   will be a conflict if a user declares void Setup() in his test\n  //   fixture.\n  //\n  //   - This method is private, so it will be another compiler error\n  //   if a user calls it from his test fixture.\n  //\n  // DO NOT OVERRIDE THIS FUNCTION.\n  //\n  // If you see an error about overriding the following function or\n  // about it being private, you have mis-spelled SetUp() as Setup().\n  struct Setup_should_be_spelled_SetUp {};\n  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }\n\n  // We disallow copying Tests.\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);\n};\n\ntypedef internal::TimeInMillis TimeInMillis;\n\n// A copyable object representing a user specified test property which can be\n// output as a key/value string pair.\n//\n// Don't inherit from TestProperty as its destructor is not virtual.\nclass TestProperty {\n public:\n  // C'tor.  TestProperty does NOT have a default constructor.\n  // Always use this constructor (with parameters) to create a\n  // TestProperty object.\n  TestProperty(const char* a_key, const char* a_value) :\n    key_(a_key), value_(a_value) {\n  }\n\n  // Gets the user supplied key.\n  const char* key() const {\n    return key_.c_str();\n  }\n\n  // Gets the user supplied value.\n  const char* value() const {\n    return value_.c_str();\n  }\n\n  // Sets a new value, overriding the one supplied in the constructor.\n  void SetValue(const char* new_value) {\n    value_ = new_value;\n  }\n\n private:\n  // The key supplied by the user.\n  internal::String key_;\n  // The value supplied by the user.\n  internal::String value_;\n};\n\n// The result of a single Test.  This includes a list of\n// TestPartResults, a list of TestProperties, a count of how many\n// death tests there are in the Test, and how much time it took to run\n// the Test.\n//\n// TestResult is not copyable.\nclass GTEST_API_ TestResult {\n public:\n  // Creates an empty TestResult.\n  TestResult();\n\n  // D'tor.  Do not inherit from TestResult.\n  ~TestResult();\n\n  // Gets the number of all test parts.  This is the sum of the number\n  // of successful test parts and the number of failed test parts.\n  int total_part_count() const;\n\n  // Returns the number of the test properties.\n  int test_property_count() const;\n\n  // Returns true iff the test passed (i.e. no test part failed).\n  bool Passed() const { return !Failed(); }\n\n  // Returns true iff the test failed.\n  bool Failed() const;\n\n  // Returns true iff the test fatally failed.\n  bool HasFatalFailure() const;\n\n  // Returns true iff the test has a non-fatal failure.\n  bool HasNonfatalFailure() const;\n\n  // Returns the elapsed time, in milliseconds.\n  TimeInMillis elapsed_time() const { return elapsed_time_; }\n\n  // Returns the i-th test part result among all the results. i can range\n  // from 0 to test_property_count() - 1. If i is not in that range, aborts\n  // the program.\n  const TestPartResult& GetTestPartResult(int i) const;\n\n  // Returns the i-th test property. i can range from 0 to\n  // test_property_count() - 1. If i is not in that range, aborts the\n  // program.\n  const TestProperty& GetTestProperty(int i) const;\n\n private:\n  friend class TestInfo;\n  friend class UnitTest;\n  friend class internal::DefaultGlobalTestPartResultReporter;\n  friend class internal::ExecDeathTest;\n  friend class internal::TestResultAccessor;\n  friend class internal::UnitTestImpl;\n  friend class internal::WindowsDeathTest;\n\n  // Gets the vector of TestPartResults.\n  const std::vector<TestPartResult>& test_part_results() const {\n    return test_part_results_;\n  }\n\n  // Gets the vector of TestProperties.\n  const std::vector<TestProperty>& test_properties() const {\n    return test_properties_;\n  }\n\n  // Sets the elapsed time.\n  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }\n\n  // Adds a test property to the list. The property is validated and may add\n  // a non-fatal failure if invalid (e.g., if it conflicts with reserved\n  // key names). If a property is already recorded for the same key, the\n  // value will be updated, rather than storing multiple values for the same\n  // key.\n  void RecordProperty(const TestProperty& test_property);\n\n  // Adds a failure if the key is a reserved attribute of Google Test\n  // testcase tags.  Returns true if the property is valid.\n  // TODO(russr): Validate attribute names are legal and human readable.\n  static bool ValidateTestProperty(const TestProperty& test_property);\n\n  // Adds a test part result to the list.\n  void AddTestPartResult(const TestPartResult& test_part_result);\n\n  // Returns the death test count.\n  int death_test_count() const { return death_test_count_; }\n\n  // Increments the death test count, returning the new count.\n  int increment_death_test_count() { return ++death_test_count_; }\n\n  // Clears the test part results.\n  void ClearTestPartResults();\n\n  // Clears the object.\n  void Clear();\n\n  // Protects mutable state of the property vector and of owned\n  // properties, whose values may be updated.\n  internal::Mutex test_properites_mutex_;\n\n  // The vector of TestPartResults\n  std::vector<TestPartResult> test_part_results_;\n  // The vector of TestProperties\n  std::vector<TestProperty> test_properties_;\n  // Running count of death tests.\n  int death_test_count_;\n  // The elapsed time, in milliseconds.\n  TimeInMillis elapsed_time_;\n\n  // We disallow copying TestResult.\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);\n};  // class TestResult\n\n// A TestInfo object stores the following information about a test:\n//\n//   Test case name\n//   Test name\n//   Whether the test should be run\n//   A function pointer that creates the test object when invoked\n//   Test result\n//\n// The constructor of TestInfo registers itself with the UnitTest\n// singleton such that the RUN_ALL_TESTS() macro knows which tests to\n// run.\nclass GTEST_API_ TestInfo {\n public:\n  // Destructs a TestInfo object.  This function is not virtual, so\n  // don't inherit from TestInfo.\n  ~TestInfo();\n\n  // Returns the test case name.\n  const char* test_case_name() const { return test_case_name_.c_str(); }\n\n  // Returns the test name.\n  const char* name() const { return name_.c_str(); }\n\n  // Returns the name of the parameter type, or NULL if this is not a typed\n  // or a type-parameterized test.\n  const char* type_param() const {\n    if (type_param_.get() != NULL)\n      return type_param_->c_str();\n    return NULL;\n  }\n\n  // Returns the text representation of the value parameter, or NULL if this\n  // is not a value-parameterized test.\n  const char* value_param() const {\n    if (value_param_.get() != NULL)\n      return value_param_->c_str();\n    return NULL;\n  }\n\n  // Returns true if this test should run, that is if the test is not disabled\n  // (or it is disabled but the also_run_disabled_tests flag has been specified)\n  // and its full name matches the user-specified filter.\n  //\n  // Google Test allows the user to filter the tests by their full names.\n  // The full name of a test Bar in test case Foo is defined as\n  // \"Foo.Bar\".  Only the tests that match the filter will run.\n  //\n  // A filter is a colon-separated list of glob (not regex) patterns,\n  // optionally followed by a '-' and a colon-separated list of\n  // negative patterns (tests to exclude).  A test is run if it\n  // matches one of the positive patterns and does not match any of\n  // the negative patterns.\n  //\n  // For example, *A*:Foo.* is a filter that matches any string that\n  // contains the character 'A' or starts with \"Foo.\".\n  bool should_run() const { return should_run_; }\n\n  // Returns the result of the test.\n  const TestResult* result() const { return &result_; }\n\n private:\n\n#if GTEST_HAS_DEATH_TEST\n  friend class internal::DefaultDeathTestFactory;\n#endif  // GTEST_HAS_DEATH_TEST\n  friend class Test;\n  friend class TestCase;\n  friend class internal::UnitTestImpl;\n  friend TestInfo* internal::MakeAndRegisterTestInfo(\n      const char* test_case_name, const char* name,\n      const char* type_param,\n      const char* value_param,\n      internal::TypeId fixture_class_id,\n      Test::SetUpTestCaseFunc set_up_tc,\n      Test::TearDownTestCaseFunc tear_down_tc,\n      internal::TestFactoryBase* factory);\n\n  // Constructs a TestInfo object. The newly constructed instance assumes\n  // ownership of the factory object.\n  TestInfo(const char* test_case_name, const char* name,\n           const char* a_type_param,\n           const char* a_value_param,\n           internal::TypeId fixture_class_id,\n           internal::TestFactoryBase* factory);\n\n  // Increments the number of death tests encountered in this test so\n  // far.\n  int increment_death_test_count() {\n    return result_.increment_death_test_count();\n  }\n\n  // Creates the test object, runs it, records its result, and then\n  // deletes it.\n  void Run();\n\n  static void ClearTestResult(TestInfo* test_info) {\n    test_info->result_.Clear();\n  }\n\n  // These fields are immutable properties of the test.\n  const std::string test_case_name_;     // Test case name\n  const std::string name_;               // Test name\n  // Name of the parameter type, or NULL if this is not a typed or a\n  // type-parameterized test.\n  const internal::scoped_ptr<const ::std::string> type_param_;\n  // Text representation of the value parameter, or NULL if this is not a\n  // value-parameterized test.\n  const internal::scoped_ptr<const ::std::string> value_param_;\n  const internal::TypeId fixture_class_id_;   // ID of the test fixture class\n  bool should_run_;                 // True iff this test should run\n  bool is_disabled_;                // True iff this test is disabled\n  bool matches_filter_;             // True if this test matches the\n                                    // user-specified filter.\n  internal::TestFactoryBase* const factory_;  // The factory that creates\n                                              // the test object\n\n  // This field is mutable and needs to be reset before running the\n  // test for the second time.\n  TestResult result_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);\n};\n\n// A test case, which consists of a vector of TestInfos.\n//\n// TestCase is not copyable.\nclass GTEST_API_ TestCase {\n public:\n  // Creates a TestCase with the given name.\n  //\n  // TestCase does NOT have a default constructor.  Always use this\n  // constructor to create a TestCase object.\n  //\n  // Arguments:\n  //\n  //   name:         name of the test case\n  //   a_type_param: the name of the test's type parameter, or NULL if\n  //                 this is not a type-parameterized test.\n  //   set_up_tc:    pointer to the function that sets up the test case\n  //   tear_down_tc: pointer to the function that tears down the test case\n  TestCase(const char* name, const char* a_type_param,\n           Test::SetUpTestCaseFunc set_up_tc,\n           Test::TearDownTestCaseFunc tear_down_tc);\n\n  // Destructor of TestCase.\n  virtual ~TestCase();\n\n  // Gets the name of the TestCase.\n  const char* name() const { return name_.c_str(); }\n\n  // Returns the name of the parameter type, or NULL if this is not a\n  // type-parameterized test case.\n  const char* type_param() const {\n    if (type_param_.get() != NULL)\n      return type_param_->c_str();\n    return NULL;\n  }\n\n  // Returns true if any test in this test case should run.\n  bool should_run() const { return should_run_; }\n\n  // Gets the number of successful tests in this test case.\n  int successful_test_count() const;\n\n  // Gets the number of failed tests in this test case.\n  int failed_test_count() const;\n\n  // Gets the number of disabled tests in this test case.\n  int disabled_test_count() const;\n\n  // Get the number of tests in this test case that should run.\n  int test_to_run_count() const;\n\n  // Gets the number of all tests in this test case.\n  int total_test_count() const;\n\n  // Returns true iff the test case passed.\n  bool Passed() const { return !Failed(); }\n\n  // Returns true iff the test case failed.\n  bool Failed() const { return failed_test_count() > 0; }\n\n  // Returns the elapsed time, in milliseconds.\n  TimeInMillis elapsed_time() const { return elapsed_time_; }\n\n  // Returns the i-th test among all the tests. i can range from 0 to\n  // total_test_count() - 1. If i is not in that range, returns NULL.\n  const TestInfo* GetTestInfo(int i) const;\n\n private:\n  friend class Test;\n  friend class internal::UnitTestImpl;\n\n  // Gets the (mutable) vector of TestInfos in this TestCase.\n  std::vector<TestInfo*>& test_info_list() { return test_info_list_; }\n\n  // Gets the (immutable) vector of TestInfos in this TestCase.\n  const std::vector<TestInfo*>& test_info_list() const {\n    return test_info_list_;\n  }\n\n  // Returns the i-th test among all the tests. i can range from 0 to\n  // total_test_count() - 1. If i is not in that range, returns NULL.\n  TestInfo* GetMutableTestInfo(int i);\n\n  // Sets the should_run member.\n  void set_should_run(bool should) { should_run_ = should; }\n\n  // Adds a TestInfo to this test case.  Will delete the TestInfo upon\n  // destruction of the TestCase object.\n  void AddTestInfo(TestInfo * test_info);\n\n  // Clears the results of all tests in this test case.\n  void ClearResult();\n\n  // Clears the results of all tests in the given test case.\n  static void ClearTestCaseResult(TestCase* test_case) {\n    test_case->ClearResult();\n  }\n\n  // Runs every test in this TestCase.\n  void Run();\n\n  // Runs SetUpTestCase() for this TestCase.  This wrapper is needed\n  // for catching exceptions thrown from SetUpTestCase().\n  void RunSetUpTestCase() { (*set_up_tc_)(); }\n\n  // Runs TearDownTestCase() for this TestCase.  This wrapper is\n  // needed for catching exceptions thrown from TearDownTestCase().\n  void RunTearDownTestCase() { (*tear_down_tc_)(); }\n\n  // Returns true iff test passed.\n  static bool TestPassed(const TestInfo* test_info) {\n    return test_info->should_run() && test_info->result()->Passed();\n  }\n\n  // Returns true iff test failed.\n  static bool TestFailed(const TestInfo* test_info) {\n    return test_info->should_run() && test_info->result()->Failed();\n  }\n\n  // Returns true iff test is disabled.\n  static bool TestDisabled(const TestInfo* test_info) {\n    return test_info->is_disabled_;\n  }\n\n  // Returns true if the given test should run.\n  static bool ShouldRunTest(const TestInfo* test_info) {\n    return test_info->should_run();\n  }\n\n  // Shuffles the tests in this test case.\n  void ShuffleTests(internal::Random* random);\n\n  // Restores the test order to before the first shuffle.\n  void UnshuffleTests();\n\n  // Name of the test case.\n  internal::String name_;\n  // Name of the parameter type, or NULL if this is not a typed or a\n  // type-parameterized test.\n  const internal::scoped_ptr<const ::std::string> type_param_;\n  // The vector of TestInfos in their original order.  It owns the\n  // elements in the vector.\n  std::vector<TestInfo*> test_info_list_;\n  // Provides a level of indirection for the test list to allow easy\n  // shuffling and restoring the test order.  The i-th element in this\n  // vector is the index of the i-th test in the shuffled test list.\n  std::vector<int> test_indices_;\n  // Pointer to the function that sets up the test case.\n  Test::SetUpTestCaseFunc set_up_tc_;\n  // Pointer to the function that tears down the test case.\n  Test::TearDownTestCaseFunc tear_down_tc_;\n  // True iff any test in this test case should run.\n  bool should_run_;\n  // Elapsed time, in milliseconds.\n  TimeInMillis elapsed_time_;\n\n  // We disallow copying TestCases.\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);\n};\n\n// An Environment object is capable of setting up and tearing down an\n// environment.  The user should subclass this to define his own\n// environment(s).\n//\n// An Environment object does the set-up and tear-down in virtual\n// methods SetUp() and TearDown() instead of the constructor and the\n// destructor, as:\n//\n//   1. You cannot safely throw from a destructor.  This is a problem\n//      as in some cases Google Test is used where exceptions are enabled, and\n//      we may want to implement ASSERT_* using exceptions where they are\n//      available.\n//   2. You cannot use ASSERT_* directly in a constructor or\n//      destructor.\nclass Environment {\n public:\n  // The d'tor is virtual as we need to subclass Environment.\n  virtual ~Environment() {}\n\n  // Override this to define how to set up the environment.\n  virtual void SetUp() {}\n\n  // Override this to define how to tear down the environment.\n  virtual void TearDown() {}\n private:\n  // If you see an error about overriding the following function or\n  // about it being private, you have mis-spelled SetUp() as Setup().\n  struct Setup_should_be_spelled_SetUp {};\n  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }\n};\n\n// The interface for tracing execution of tests. The methods are organized in\n// the order the corresponding events are fired.\nclass TestEventListener {\n public:\n  virtual ~TestEventListener() {}\n\n  // Fired before any test activity starts.\n  virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;\n\n  // Fired before each iteration of tests starts.  There may be more than\n  // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration\n  // index, starting from 0.\n  virtual void OnTestIterationStart(const UnitTest& unit_test,\n                                    int iteration) = 0;\n\n  // Fired before environment set-up for each iteration of tests starts.\n  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;\n\n  // Fired after environment set-up for each iteration of tests ends.\n  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;\n\n  // Fired before the test case starts.\n  virtual void OnTestCaseStart(const TestCase& test_case) = 0;\n\n  // Fired before the test starts.\n  virtual void OnTestStart(const TestInfo& test_info) = 0;\n\n  // Fired after a failed assertion or a SUCCEED() invocation.\n  virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;\n\n  // Fired after the test ends.\n  virtual void OnTestEnd(const TestInfo& test_info) = 0;\n\n  // Fired after the test case ends.\n  virtual void OnTestCaseEnd(const TestCase& test_case) = 0;\n\n  // Fired before environment tear-down for each iteration of tests starts.\n  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;\n\n  // Fired after environment tear-down for each iteration of tests ends.\n  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;\n\n  // Fired after each iteration of tests finishes.\n  virtual void OnTestIterationEnd(const UnitTest& unit_test,\n                                  int iteration) = 0;\n\n  // Fired after all test activities have ended.\n  virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;\n};\n\n// The convenience class for users who need to override just one or two\n// methods and are not concerned that a possible change to a signature of\n// the methods they override will not be caught during the build.  For\n// comments about each method please see the definition of TestEventListener\n// above.\nclass EmptyTestEventListener : public TestEventListener {\n public:\n  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}\n  virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,\n                                    int /*iteration*/) {}\n  virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}\n  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}\n  virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}\n  virtual void OnTestStart(const TestInfo& /*test_info*/) {}\n  virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}\n  virtual void OnTestEnd(const TestInfo& /*test_info*/) {}\n  virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}\n  virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}\n  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}\n  virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,\n                                  int /*iteration*/) {}\n  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}\n};\n\n// TestEventListeners lets users add listeners to track events in Google Test.\nclass GTEST_API_ TestEventListeners {\n public:\n  TestEventListeners();\n  ~TestEventListeners();\n\n  // Appends an event listener to the end of the list. Google Test assumes\n  // the ownership of the listener (i.e. it will delete the listener when\n  // the test program finishes).\n  void Append(TestEventListener* listener);\n\n  // Removes the given event listener from the list and returns it.  It then\n  // becomes the caller's responsibility to delete the listener. Returns\n  // NULL if the listener is not found in the list.\n  TestEventListener* Release(TestEventListener* listener);\n\n  // Returns the standard listener responsible for the default console\n  // output.  Can be removed from the listeners list to shut down default\n  // console output.  Note that removing this object from the listener list\n  // with Release transfers its ownership to the caller and makes this\n  // function return NULL the next time.\n  TestEventListener* default_result_printer() const {\n    return default_result_printer_;\n  }\n\n  // Returns the standard listener responsible for the default XML output\n  // controlled by the --gtest_output=xml flag.  Can be removed from the\n  // listeners list by users who want to shut down the default XML output\n  // controlled by this flag and substitute it with custom one.  Note that\n  // removing this object from the listener list with Release transfers its\n  // ownership to the caller and makes this function return NULL the next\n  // time.\n  TestEventListener* default_xml_generator() const {\n    return default_xml_generator_;\n  }\n\n private:\n  friend class TestCase;\n  friend class TestInfo;\n  friend class internal::DefaultGlobalTestPartResultReporter;\n  friend class internal::NoExecDeathTest;\n  friend class internal::TestEventListenersAccessor;\n  friend class internal::UnitTestImpl;\n\n  // Returns repeater that broadcasts the TestEventListener events to all\n  // subscribers.\n  TestEventListener* repeater();\n\n  // Sets the default_result_printer attribute to the provided listener.\n  // The listener is also added to the listener list and previous\n  // default_result_printer is removed from it and deleted. The listener can\n  // also be NULL in which case it will not be added to the list. Does\n  // nothing if the previous and the current listener objects are the same.\n  void SetDefaultResultPrinter(TestEventListener* listener);\n\n  // Sets the default_xml_generator attribute to the provided listener.  The\n  // listener is also added to the listener list and previous\n  // default_xml_generator is removed from it and deleted. The listener can\n  // also be NULL in which case it will not be added to the list. Does\n  // nothing if the previous and the current listener objects are the same.\n  void SetDefaultXmlGenerator(TestEventListener* listener);\n\n  // Controls whether events will be forwarded by the repeater to the\n  // listeners in the list.\n  bool EventForwardingEnabled() const;\n  void SuppressEventForwarding();\n\n  // The actual list of listeners.\n  internal::TestEventRepeater* repeater_;\n  // Listener responsible for the standard result output.\n  TestEventListener* default_result_printer_;\n  // Listener responsible for the creation of the XML output file.\n  TestEventListener* default_xml_generator_;\n\n  // We disallow copying TestEventListeners.\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);\n};\n\n// A UnitTest consists of a vector of TestCases.\n//\n// This is a singleton class.  The only instance of UnitTest is\n// created when UnitTest::GetInstance() is first called.  This\n// instance is never deleted.\n//\n// UnitTest is not copyable.\n//\n// This class is thread-safe as long as the methods are called\n// according to their specification.\nclass GTEST_API_ UnitTest {\n public:\n  // Gets the singleton UnitTest object.  The first time this method\n  // is called, a UnitTest object is constructed and returned.\n  // Consecutive calls will return the same object.\n  static UnitTest* GetInstance();\n\n  // Runs all tests in this UnitTest object and prints the result.\n  // Returns 0 if successful, or 1 otherwise.\n  //\n  // This method can only be called from the main thread.\n  //\n  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\n  int Run() GTEST_MUST_USE_RESULT_;\n\n  // Returns the working directory when the first TEST() or TEST_F()\n  // was executed.  The UnitTest object owns the string.\n  const char* original_working_dir() const;\n\n  // Returns the TestCase object for the test that's currently running,\n  // or NULL if no test is running.\n  const TestCase* current_test_case() const;\n\n  // Returns the TestInfo object for the test that's currently running,\n  // or NULL if no test is running.\n  const TestInfo* current_test_info() const;\n\n  // Returns the random seed used at the start of the current test run.\n  int random_seed() const;\n\n#if GTEST_HAS_PARAM_TEST\n  // Returns the ParameterizedTestCaseRegistry object used to keep track of\n  // value-parameterized tests and instantiate and register them.\n  //\n  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\n  internal::ParameterizedTestCaseRegistry& parameterized_test_registry();\n#endif  // GTEST_HAS_PARAM_TEST\n\n  // Gets the number of successful test cases.\n  int successful_test_case_count() const;\n\n  // Gets the number of failed test cases.\n  int failed_test_case_count() const;\n\n  // Gets the number of all test cases.\n  int total_test_case_count() const;\n\n  // Gets the number of all test cases that contain at least one test\n  // that should run.\n  int test_case_to_run_count() const;\n\n  // Gets the number of successful tests.\n  int successful_test_count() const;\n\n  // Gets the number of failed tests.\n  int failed_test_count() const;\n\n  // Gets the number of disabled tests.\n  int disabled_test_count() const;\n\n  // Gets the number of all tests.\n  int total_test_count() const;\n\n  // Gets the number of tests that should run.\n  int test_to_run_count() const;\n\n  // Gets the elapsed time, in milliseconds.\n  TimeInMillis elapsed_time() const;\n\n  // Returns true iff the unit test passed (i.e. all test cases passed).\n  bool Passed() const;\n\n  // Returns true iff the unit test failed (i.e. some test case failed\n  // or something outside of all tests failed).\n  bool Failed() const;\n\n  // Gets the i-th test case among all the test cases. i can range from 0 to\n  // total_test_case_count() - 1. If i is not in that range, returns NULL.\n  const TestCase* GetTestCase(int i) const;\n\n  // Returns the list of event listeners that can be used to track events\n  // inside Google Test.\n  TestEventListeners& listeners();\n\n private:\n  // Registers and returns a global test environment.  When a test\n  // program is run, all global test environments will be set-up in\n  // the order they were registered.  After all tests in the program\n  // have finished, all global test environments will be torn-down in\n  // the *reverse* order they were registered.\n  //\n  // The UnitTest object takes ownership of the given environment.\n  //\n  // This method can only be called from the main thread.\n  Environment* AddEnvironment(Environment* env);\n\n  // Adds a TestPartResult to the current TestResult object.  All\n  // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)\n  // eventually call this to report their results.  The user code\n  // should use the assertion macros instead of calling this directly.\n  void AddTestPartResult(TestPartResult::Type result_type,\n                         const char* file_name,\n                         int line_number,\n                         const internal::String& message,\n                         const internal::String& os_stack_trace);\n\n  // Adds a TestProperty to the current TestResult object. If the result already\n  // contains a property with the same key, the value will be updated.\n  void RecordPropertyForCurrentTest(const char* key, const char* value);\n\n  // Gets the i-th test case among all the test cases. i can range from 0 to\n  // total_test_case_count() - 1. If i is not in that range, returns NULL.\n  TestCase* GetMutableTestCase(int i);\n\n  // Accessors for the implementation object.\n  internal::UnitTestImpl* impl() { return impl_; }\n  const internal::UnitTestImpl* impl() const { return impl_; }\n\n  // These classes and funcions are friends as they need to access private\n  // members of UnitTest.\n  friend class Test;\n  friend class internal::AssertHelper;\n  friend class internal::ScopedTrace;\n  friend Environment* AddGlobalTestEnvironment(Environment* env);\n  friend internal::UnitTestImpl* internal::GetUnitTestImpl();\n  friend void internal::ReportFailureInUnknownLocation(\n      TestPartResult::Type result_type,\n      const internal::String& message);\n\n  // Creates an empty UnitTest.\n  UnitTest();\n\n  // D'tor\n  virtual ~UnitTest();\n\n  // Pushes a trace defined by SCOPED_TRACE() on to the per-thread\n  // Google Test trace stack.\n  void PushGTestTrace(const internal::TraceInfo& trace);\n\n  // Pops a trace from the per-thread Google Test trace stack.\n  void PopGTestTrace();\n\n  // Protects mutable state in *impl_.  This is mutable as some const\n  // methods need to lock it too.\n  mutable internal::Mutex mutex_;\n\n  // Opaque implementation object.  This field is never changed once\n  // the object is constructed.  We don't mark it as const here, as\n  // doing so will cause a warning in the constructor of UnitTest.\n  // Mutable state in *impl_ is protected by mutex_.\n  internal::UnitTestImpl* impl_;\n\n  // We disallow copying UnitTest.\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);\n};\n\n// A convenient wrapper for adding an environment for the test\n// program.\n//\n// You should call this before RUN_ALL_TESTS() is called, probably in\n// main().  If you use gtest_main, you need to call this before main()\n// starts for it to take effect.  For example, you can define a global\n// variable like this:\n//\n//   testing::Environment* const foo_env =\n//       testing::AddGlobalTestEnvironment(new FooEnvironment);\n//\n// However, we strongly recommend you to write your own main() and\n// call AddGlobalTestEnvironment() there, as relying on initialization\n// of global variables makes the code harder to read and may cause\n// problems when you register multiple environments from different\n// translation units and the environments have dependencies among them\n// (remember that the compiler doesn't guarantee the order in which\n// global variables from different translation units are initialized).\ninline Environment* AddGlobalTestEnvironment(Environment* env) {\n  return UnitTest::GetInstance()->AddEnvironment(env);\n}\n\n// Initializes Google Test.  This must be called before calling\n// RUN_ALL_TESTS().  In particular, it parses a command line for the\n// flags that Google Test recognizes.  Whenever a Google Test flag is\n// seen, it is removed from argv, and *argc is decremented.\n//\n// No value is returned.  Instead, the Google Test flag variables are\n// updated.\n//\n// Calling the function for the second time has no user-visible effect.\nGTEST_API_ void InitGoogleTest(int* argc, char** argv);\n\n// This overloaded version can be used in Windows programs compiled in\n// UNICODE mode.\nGTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);\n\nnamespace internal {\n\n// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)\n// operand to be used in a failure message.  The type (but not value)\n// of the other operand may affect the format.  This allows us to\n// print a char* as a raw pointer when it is compared against another\n// char*, and print it as a C string when it is compared against an\n// std::string object, for example.\n//\n// The default implementation ignores the type of the other operand.\n// Some specialized versions are used to handle formatting wide or\n// narrow C strings.\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\ntemplate <typename T1, typename T2>\nString FormatForComparisonFailureMessage(const T1& value,\n                                         const T2& /* other_operand */) {\n  // C++Builder compiles this incorrectly if the namespace isn't explicitly\n  // given.\n  return ::testing::PrintToString(value);\n}\n\n// The helper function for {ASSERT|EXPECT}_EQ.\ntemplate <typename T1, typename T2>\nAssertionResult CmpHelperEQ(const char* expected_expression,\n                            const char* actual_expression,\n                            const T1& expected,\n                            const T2& actual) {\n#ifdef _MSC_VER\n# pragma warning(push)          // Saves the current warning state.\n# pragma warning(disable:4389)  // Temporarily disables warning on\n                               // signed/unsigned mismatch.\n#endif\n\n  if (expected == actual) {\n    return AssertionSuccess();\n  }\n\n#ifdef _MSC_VER\n# pragma warning(pop)          // Restores the warning state.\n#endif\n\n  return EqFailure(expected_expression,\n                   actual_expression,\n                   FormatForComparisonFailureMessage(expected, actual),\n                   FormatForComparisonFailureMessage(actual, expected),\n                   false);\n}\n\n// With this overloaded version, we allow anonymous enums to be used\n// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums\n// can be implicitly cast to BiggestInt.\nGTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression,\n                                       const char* actual_expression,\n                                       BiggestInt expected,\n                                       BiggestInt actual);\n\n// The helper class for {ASSERT|EXPECT}_EQ.  The template argument\n// lhs_is_null_literal is true iff the first argument to ASSERT_EQ()\n// is a null pointer literal.  The following default implementation is\n// for lhs_is_null_literal being false.\ntemplate <bool lhs_is_null_literal>\nclass EqHelper {\n public:\n  // This templatized version is for the general case.\n  template <typename T1, typename T2>\n  static AssertionResult Compare(const char* expected_expression,\n                                 const char* actual_expression,\n                                 const T1& expected,\n                                 const T2& actual) {\n    return CmpHelperEQ(expected_expression, actual_expression, expected,\n                       actual);\n  }\n\n  // With this overloaded version, we allow anonymous enums to be used\n  // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous\n  // enums can be implicitly cast to BiggestInt.\n  //\n  // Even though its body looks the same as the above version, we\n  // cannot merge the two, as it will make anonymous enums unhappy.\n  static AssertionResult Compare(const char* expected_expression,\n                                 const char* actual_expression,\n                                 BiggestInt expected,\n                                 BiggestInt actual) {\n    return CmpHelperEQ(expected_expression, actual_expression, expected,\n                       actual);\n  }\n};\n\n// This specialization is used when the first argument to ASSERT_EQ()\n// is a null pointer literal, like NULL, false, or 0.\ntemplate <>\nclass EqHelper<true> {\n public:\n  // We define two overloaded versions of Compare().  The first\n  // version will be picked when the second argument to ASSERT_EQ() is\n  // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or\n  // EXPECT_EQ(false, a_bool).\n  template <typename T1, typename T2>\n  static AssertionResult Compare(\n      const char* expected_expression,\n      const char* actual_expression,\n      const T1& expected,\n      const T2& actual,\n      // The following line prevents this overload from being considered if T2\n      // is not a pointer type.  We need this because ASSERT_EQ(NULL, my_ptr)\n      // expands to Compare(\"\", \"\", NULL, my_ptr), which requires a conversion\n      // to match the Secret* in the other overload, which would otherwise make\n      // this template match better.\n      typename EnableIf<!is_pointer<T2>::value>::type* = 0) {\n    return CmpHelperEQ(expected_expression, actual_expression, expected,\n                       actual);\n  }\n\n  // This version will be picked when the second argument to ASSERT_EQ() is a\n  // pointer, e.g. ASSERT_EQ(NULL, a_pointer).\n  template <typename T>\n  static AssertionResult Compare(\n      const char* expected_expression,\n      const char* actual_expression,\n      // We used to have a second template parameter instead of Secret*.  That\n      // template parameter would deduce to 'long', making this a better match\n      // than the first overload even without the first overload's EnableIf.\n      // Unfortunately, gcc with -Wconversion-null warns when \"passing NULL to\n      // non-pointer argument\" (even a deduced integral argument), so the old\n      // implementation caused warnings in user code.\n      Secret* /* expected (NULL) */,\n      T* actual) {\n    // We already know that 'expected' is a null pointer.\n    return CmpHelperEQ(expected_expression, actual_expression,\n                       static_cast<T*>(NULL), actual);\n  }\n};\n\n// A macro for implementing the helper functions needed to implement\n// ASSERT_?? and EXPECT_??.  It is here just to avoid copy-and-paste\n// of similar code.\n//\n// For each templatized helper function, we also define an overloaded\n// version for BiggestInt in order to reduce code bloat and allow\n// anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled\n// with gcc 4.\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\n#define GTEST_IMPL_CMP_HELPER_(op_name, op)\\\ntemplate <typename T1, typename T2>\\\nAssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \\\n                                   const T1& val1, const T2& val2) {\\\n  if (val1 op val2) {\\\n    return AssertionSuccess();\\\n  } else {\\\n    return AssertionFailure() \\\n        << \"Expected: (\" << expr1 << \") \" #op \" (\" << expr2\\\n        << \"), actual: \" << FormatForComparisonFailureMessage(val1, val2)\\\n        << \" vs \" << FormatForComparisonFailureMessage(val2, val1);\\\n  }\\\n}\\\nGTEST_API_ AssertionResult CmpHelper##op_name(\\\n    const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\n\n// Implements the helper function for {ASSERT|EXPECT}_NE\nGTEST_IMPL_CMP_HELPER_(NE, !=);\n// Implements the helper function for {ASSERT|EXPECT}_LE\nGTEST_IMPL_CMP_HELPER_(LE, <=);\n// Implements the helper function for {ASSERT|EXPECT}_LT\nGTEST_IMPL_CMP_HELPER_(LT, < );\n// Implements the helper function for {ASSERT|EXPECT}_GE\nGTEST_IMPL_CMP_HELPER_(GE, >=);\n// Implements the helper function for {ASSERT|EXPECT}_GT\nGTEST_IMPL_CMP_HELPER_(GT, > );\n\n#undef GTEST_IMPL_CMP_HELPER_\n\n// The helper function for {ASSERT|EXPECT}_STREQ.\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\nGTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,\n                                          const char* actual_expression,\n                                          const char* expected,\n                                          const char* actual);\n\n// The helper function for {ASSERT|EXPECT}_STRCASEEQ.\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\nGTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,\n                                              const char* actual_expression,\n                                              const char* expected,\n                                              const char* actual);\n\n// The helper function for {ASSERT|EXPECT}_STRNE.\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\nGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,\n                                          const char* s2_expression,\n                                          const char* s1,\n                                          const char* s2);\n\n// The helper function for {ASSERT|EXPECT}_STRCASENE.\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\nGTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,\n                                              const char* s2_expression,\n                                              const char* s1,\n                                              const char* s2);\n\n\n// Helper function for *_STREQ on wide strings.\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\nGTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,\n                                          const char* actual_expression,\n                                          const wchar_t* expected,\n                                          const wchar_t* actual);\n\n// Helper function for *_STRNE on wide strings.\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\nGTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,\n                                          const char* s2_expression,\n                                          const wchar_t* s1,\n                                          const wchar_t* s2);\n\n}  // namespace internal\n\n// IsSubstring() and IsNotSubstring() are intended to be used as the\n// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by\n// themselves.  They check whether needle is a substring of haystack\n// (NULL is considered a substring of itself only), and return an\n// appropriate error message when they fail.\n//\n// The {needle,haystack}_expr arguments are the stringified\n// expressions that generated the two real arguments.\nGTEST_API_ AssertionResult IsSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const char* needle, const char* haystack);\nGTEST_API_ AssertionResult IsSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const wchar_t* needle, const wchar_t* haystack);\nGTEST_API_ AssertionResult IsNotSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const char* needle, const char* haystack);\nGTEST_API_ AssertionResult IsNotSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const wchar_t* needle, const wchar_t* haystack);\nGTEST_API_ AssertionResult IsSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const ::std::string& needle, const ::std::string& haystack);\nGTEST_API_ AssertionResult IsNotSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const ::std::string& needle, const ::std::string& haystack);\n\n#if GTEST_HAS_STD_WSTRING\nGTEST_API_ AssertionResult IsSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const ::std::wstring& needle, const ::std::wstring& haystack);\nGTEST_API_ AssertionResult IsNotSubstring(\n    const char* needle_expr, const char* haystack_expr,\n    const ::std::wstring& needle, const ::std::wstring& haystack);\n#endif  // GTEST_HAS_STD_WSTRING\n\nnamespace internal {\n\n// Helper template function for comparing floating-points.\n//\n// Template parameter:\n//\n//   RawType: the raw floating-point type (either float or double)\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\ntemplate <typename RawType>\nAssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,\n                                         const char* actual_expression,\n                                         RawType expected,\n                                         RawType actual) {\n  const FloatingPoint<RawType> lhs(expected), rhs(actual);\n\n  if (lhs.AlmostEquals(rhs)) {\n    return AssertionSuccess();\n  }\n\n  ::std::stringstream expected_ss;\n  expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)\n              << expected;\n\n  ::std::stringstream actual_ss;\n  actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)\n            << actual;\n\n  return EqFailure(expected_expression,\n                   actual_expression,\n                   StringStreamToString(&expected_ss),\n                   StringStreamToString(&actual_ss),\n                   false);\n}\n\n// Helper function for implementing ASSERT_NEAR.\n//\n// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.\nGTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,\n                                                const char* expr2,\n                                                const char* abs_error_expr,\n                                                double val1,\n                                                double val2,\n                                                double abs_error);\n\n// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.\n// A class that enables one to stream messages to assertion macros\nclass GTEST_API_ AssertHelper {\n public:\n  // Constructor.\n  AssertHelper(TestPartResult::Type type,\n               const char* file,\n               int line,\n               const char* message);\n  ~AssertHelper();\n\n  // Message assignment is a semantic trick to enable assertion\n  // streaming; see the GTEST_MESSAGE_ macro below.\n  void operator=(const Message& message) const;\n\n private:\n  // We put our data in a struct so that the size of the AssertHelper class can\n  // be as small as possible.  This is important because gcc is incapable of\n  // re-using stack space even for temporary variables, so every EXPECT_EQ\n  // reserves stack space for another AssertHelper.\n  struct AssertHelperData {\n    AssertHelperData(TestPartResult::Type t,\n                     const char* srcfile,\n                     int line_num,\n                     const char* msg)\n        : type(t), file(srcfile), line(line_num), message(msg) { }\n\n    TestPartResult::Type const type;\n    const char*        const file;\n    int                const line;\n    String             const message;\n\n   private:\n    GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);\n  };\n\n  AssertHelperData* const data_;\n\n  GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);\n};\n\n}  // namespace internal\n\n#if GTEST_HAS_PARAM_TEST\n// The pure interface class that all value-parameterized tests inherit from.\n// A value-parameterized class must inherit from both ::testing::Test and\n// ::testing::WithParamInterface. In most cases that just means inheriting\n// from ::testing::TestWithParam, but more complicated test hierarchies\n// may need to inherit from Test and WithParamInterface at different levels.\n//\n// This interface has support for accessing the test parameter value via\n// the GetParam() method.\n//\n// Use it with one of the parameter generator defining functions, like Range(),\n// Values(), ValuesIn(), Bool(), and Combine().\n//\n// class FooTest : public ::testing::TestWithParam<int> {\n//  protected:\n//   FooTest() {\n//     // Can use GetParam() here.\n//   }\n//   virtual ~FooTest() {\n//     // Can use GetParam() here.\n//   }\n//   virtual void SetUp() {\n//     // Can use GetParam() here.\n//   }\n//   virtual void TearDown {\n//     // Can use GetParam() here.\n//   }\n// };\n// TEST_P(FooTest, DoesBar) {\n//   // Can use GetParam() method here.\n//   Foo foo;\n//   ASSERT_TRUE(foo.DoesBar(GetParam()));\n// }\n// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));\n\ntemplate <typename T>\nclass WithParamInterface {\n public:\n  typedef T ParamType;\n  virtual ~WithParamInterface() {}\n\n  // The current parameter value. Is also available in the test fixture's\n  // constructor. This member function is non-static, even though it only\n  // references static data, to reduce the opportunity for incorrect uses\n  // like writing 'WithParamInterface<bool>::GetParam()' for a test that\n  // uses a fixture whose parameter type is int.\n  const ParamType& GetParam() const { return *parameter_; }\n\n private:\n  // Sets parameter value. The caller is responsible for making sure the value\n  // remains alive and unchanged throughout the current test.\n  static void SetParam(const ParamType* parameter) {\n    parameter_ = parameter;\n  }\n\n  // Static value used for accessing parameter during a test lifetime.\n  static const ParamType* parameter_;\n\n  // TestClass must be a subclass of WithParamInterface<T> and Test.\n  template <class TestClass> friend class internal::ParameterizedTestFactory;\n};\n\ntemplate <typename T>\nconst T* WithParamInterface<T>::parameter_ = NULL;\n\n// Most value-parameterized classes can ignore the existence of\n// WithParamInterface, and can just inherit from ::testing::TestWithParam.\n\ntemplate <typename T>\nclass TestWithParam : public Test, public WithParamInterface<T> {\n};\n\n#endif  // GTEST_HAS_PARAM_TEST\n\n// Macros for indicating success/failure in test code.\n\n// ADD_FAILURE unconditionally adds a failure to the current test.\n// SUCCEED generates a success - it doesn't automatically make the\n// current test successful, as a test is only successful when it has\n// no failure.\n//\n// EXPECT_* verifies that a certain condition is satisfied.  If not,\n// it behaves like ADD_FAILURE.  In particular:\n//\n//   EXPECT_TRUE  verifies that a Boolean condition is true.\n//   EXPECT_FALSE verifies that a Boolean condition is false.\n//\n// FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except\n// that they will also abort the current function on failure.  People\n// usually want the fail-fast behavior of FAIL and ASSERT_*, but those\n// writing data-driven tests often find themselves using ADD_FAILURE\n// and EXPECT_* more.\n//\n// Examples:\n//\n//   EXPECT_TRUE(server.StatusIsOK());\n//   ASSERT_FALSE(server.HasPendingRequest(port))\n//       << \"There are still pending requests \" << \"on port \" << port;\n\n// Generates a nonfatal failure with a generic message.\n#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_(\"Failed\")\n\n// Generates a nonfatal failure at the given source file location with\n// a generic message.\n#define ADD_FAILURE_AT(file, line) \\\n  GTEST_MESSAGE_AT_(file, line, \"Failed\", \\\n                    ::testing::TestPartResult::kNonFatalFailure)\n\n// Generates a fatal failure with a generic message.\n#define GTEST_FAIL() GTEST_FATAL_FAILURE_(\"Failed\")\n\n// Define this macro to 1 to omit the definition of FAIL(), which is a\n// generic name and clashes with some other libraries.\n#if !GTEST_DONT_DEFINE_FAIL\n# define FAIL() GTEST_FAIL()\n#endif\n\n// Generates a success with a generic message.\n#define GTEST_SUCCEED() GTEST_SUCCESS_(\"Succeeded\")\n\n// Define this macro to 1 to omit the definition of SUCCEED(), which\n// is a generic name and clashes with some other libraries.\n#if !GTEST_DONT_DEFINE_SUCCEED\n# define SUCCEED() GTEST_SUCCEED()\n#endif\n\n// Macros for testing exceptions.\n//\n//    * {ASSERT|EXPECT}_THROW(statement, expected_exception):\n//         Tests that the statement throws the expected exception.\n//    * {ASSERT|EXPECT}_NO_THROW(statement):\n//         Tests that the statement doesn't throw any exception.\n//    * {ASSERT|EXPECT}_ANY_THROW(statement):\n//         Tests that the statement throws an exception.\n\n#define EXPECT_THROW(statement, expected_exception) \\\n  GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)\n#define EXPECT_NO_THROW(statement) \\\n  GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)\n#define EXPECT_ANY_THROW(statement) \\\n  GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)\n#define ASSERT_THROW(statement, expected_exception) \\\n  GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)\n#define ASSERT_NO_THROW(statement) \\\n  GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)\n#define ASSERT_ANY_THROW(statement) \\\n  GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)\n\n// Boolean assertions. Condition can be either a Boolean expression or an\n// AssertionResult. For more information on how to use AssertionResult with\n// these macros see comments on that class.\n#define EXPECT_TRUE(condition) \\\n  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \\\n                      GTEST_NONFATAL_FAILURE_)\n#define EXPECT_FALSE(condition) \\\n  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \\\n                      GTEST_NONFATAL_FAILURE_)\n#define ASSERT_TRUE(condition) \\\n  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \\\n                      GTEST_FATAL_FAILURE_)\n#define ASSERT_FALSE(condition) \\\n  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \\\n                      GTEST_FATAL_FAILURE_)\n\n// Includes the auto-generated header that implements a family of\n// generic predicate assertion macros.\n// Copyright 2006, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n// This file is AUTOMATICALLY GENERATED on 09/24/2010 by command\n// 'gen_gtest_pred_impl.py 5'.  DO NOT EDIT BY HAND!\n//\n// Implements a family of generic predicate assertion macros.\n\n#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_\n#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_\n\n// Makes sure this header is not included before gtest.h.\n#ifndef GTEST_INCLUDE_GTEST_GTEST_H_\n# error Do not include gtest_pred_impl.h directly.  Include gtest.h instead.\n#endif  // GTEST_INCLUDE_GTEST_GTEST_H_\n\n// This header implements a family of generic predicate assertion\n// macros:\n//\n//   ASSERT_PRED_FORMAT1(pred_format, v1)\n//   ASSERT_PRED_FORMAT2(pred_format, v1, v2)\n//   ...\n//\n// where pred_format is a function or functor that takes n (in the\n// case of ASSERT_PRED_FORMATn) values and their source expression\n// text, and returns a testing::AssertionResult.  See the definition\n// of ASSERT_EQ in gtest.h for an example.\n//\n// If you don't care about formatting, you can use the more\n// restrictive version:\n//\n//   ASSERT_PRED1(pred, v1)\n//   ASSERT_PRED2(pred, v1, v2)\n//   ...\n//\n// where pred is an n-ary function or functor that returns bool,\n// and the values v1, v2, ..., must support the << operator for\n// streaming to std::ostream.\n//\n// We also define the EXPECT_* variations.\n//\n// For now we only support predicates whose arity is at most 5.\n// Please email googletestframework@googlegroups.com if you need\n// support for higher arities.\n\n// GTEST_ASSERT_ is the basic statement to which all of the assertions\n// in this file reduce.  Don't use this in your code.\n\n#define GTEST_ASSERT_(expression, on_failure) \\\n  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\\n  if (const ::testing::AssertionResult gtest_ar = (expression)) \\\n    ; \\\n  else \\\n    on_failure(gtest_ar.failure_message())\n\n\n// Helper function for implementing {EXPECT|ASSERT}_PRED1.  Don't use\n// this in your code.\ntemplate <typename Pred,\n          typename T1>\nAssertionResult AssertPred1Helper(const char* pred_text,\n                                  const char* e1,\n                                  Pred pred,\n                                  const T1& v1) {\n  if (pred(v1)) return AssertionSuccess();\n\n  return AssertionFailure() << pred_text << \"(\"\n                            << e1 << \") evaluates to false, where\"\n                            << \"\\n\" << e1 << \" evaluates to \" << v1;\n}\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.\n// Don't use this in your code.\n#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\\\n  GTEST_ASSERT_(pred_format(#v1, v1),\\\n                on_failure)\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED1.  Don't use\n// this in your code.\n#define GTEST_PRED1_(pred, v1, on_failure)\\\n  GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \\\n                                             #v1, \\\n                                             pred, \\\n                                             v1), on_failure)\n\n// Unary predicate assertion macros.\n#define EXPECT_PRED_FORMAT1(pred_format, v1) \\\n  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)\n#define EXPECT_PRED1(pred, v1) \\\n  GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)\n#define ASSERT_PRED_FORMAT1(pred_format, v1) \\\n  GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)\n#define ASSERT_PRED1(pred, v1) \\\n  GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)\n\n\n\n// Helper function for implementing {EXPECT|ASSERT}_PRED2.  Don't use\n// this in your code.\ntemplate <typename Pred,\n          typename T1,\n          typename T2>\nAssertionResult AssertPred2Helper(const char* pred_text,\n                                  const char* e1,\n                                  const char* e2,\n                                  Pred pred,\n                                  const T1& v1,\n                                  const T2& v2) {\n  if (pred(v1, v2)) return AssertionSuccess();\n\n  return AssertionFailure() << pred_text << \"(\"\n                            << e1 << \", \"\n                            << e2 << \") evaluates to false, where\"\n                            << \"\\n\" << e1 << \" evaluates to \" << v1\n                            << \"\\n\" << e2 << \" evaluates to \" << v2;\n}\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.\n// Don't use this in your code.\n#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\\\n  GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),\\\n                on_failure)\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED2.  Don't use\n// this in your code.\n#define GTEST_PRED2_(pred, v1, v2, on_failure)\\\n  GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \\\n                                             #v1, \\\n                                             #v2, \\\n                                             pred, \\\n                                             v1, \\\n                                             v2), on_failure)\n\n// Binary predicate assertion macros.\n#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \\\n  GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)\n#define EXPECT_PRED2(pred, v1, v2) \\\n  GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)\n#define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \\\n  GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)\n#define ASSERT_PRED2(pred, v1, v2) \\\n  GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)\n\n\n\n// Helper function for implementing {EXPECT|ASSERT}_PRED3.  Don't use\n// this in your code.\ntemplate <typename Pred,\n          typename T1,\n          typename T2,\n          typename T3>\nAssertionResult AssertPred3Helper(const char* pred_text,\n                                  const char* e1,\n                                  const char* e2,\n                                  const char* e3,\n                                  Pred pred,\n                                  const T1& v1,\n                                  const T2& v2,\n                                  const T3& v3) {\n  if (pred(v1, v2, v3)) return AssertionSuccess();\n\n  return AssertionFailure() << pred_text << \"(\"\n                            << e1 << \", \"\n                            << e2 << \", \"\n                            << e3 << \") evaluates to false, where\"\n                            << \"\\n\" << e1 << \" evaluates to \" << v1\n                            << \"\\n\" << e2 << \" evaluates to \" << v2\n                            << \"\\n\" << e3 << \" evaluates to \" << v3;\n}\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.\n// Don't use this in your code.\n#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\\\n  GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3),\\\n                on_failure)\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED3.  Don't use\n// this in your code.\n#define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\\\n  GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \\\n                                             #v1, \\\n                                             #v2, \\\n                                             #v3, \\\n                                             pred, \\\n                                             v1, \\\n                                             v2, \\\n                                             v3), on_failure)\n\n// Ternary predicate assertion macros.\n#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \\\n  GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)\n#define EXPECT_PRED3(pred, v1, v2, v3) \\\n  GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)\n#define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \\\n  GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)\n#define ASSERT_PRED3(pred, v1, v2, v3) \\\n  GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)\n\n\n\n// Helper function for implementing {EXPECT|ASSERT}_PRED4.  Don't use\n// this in your code.\ntemplate <typename Pred,\n          typename T1,\n          typename T2,\n          typename T3,\n          typename T4>\nAssertionResult AssertPred4Helper(const char* pred_text,\n                                  const char* e1,\n                                  const char* e2,\n                                  const char* e3,\n                                  const char* e4,\n                                  Pred pred,\n                                  const T1& v1,\n                                  const T2& v2,\n                                  const T3& v3,\n                                  const T4& v4) {\n  if (pred(v1, v2, v3, v4)) return AssertionSuccess();\n\n  return AssertionFailure() << pred_text << \"(\"\n                            << e1 << \", \"\n                            << e2 << \", \"\n                            << e3 << \", \"\n                            << e4 << \") evaluates to false, where\"\n                            << \"\\n\" << e1 << \" evaluates to \" << v1\n                            << \"\\n\" << e2 << \" evaluates to \" << v2\n                            << \"\\n\" << e3 << \" evaluates to \" << v3\n                            << \"\\n\" << e4 << \" evaluates to \" << v4;\n}\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.\n// Don't use this in your code.\n#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\\\n  GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4),\\\n                on_failure)\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED4.  Don't use\n// this in your code.\n#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\\\n  GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \\\n                                             #v1, \\\n                                             #v2, \\\n                                             #v3, \\\n                                             #v4, \\\n                                             pred, \\\n                                             v1, \\\n                                             v2, \\\n                                             v3, \\\n                                             v4), on_failure)\n\n// 4-ary predicate assertion macros.\n#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \\\n  GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)\n#define EXPECT_PRED4(pred, v1, v2, v3, v4) \\\n  GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)\n#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \\\n  GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)\n#define ASSERT_PRED4(pred, v1, v2, v3, v4) \\\n  GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)\n\n\n\n// Helper function for implementing {EXPECT|ASSERT}_PRED5.  Don't use\n// this in your code.\ntemplate <typename Pred,\n          typename T1,\n          typename T2,\n          typename T3,\n          typename T4,\n          typename T5>\nAssertionResult AssertPred5Helper(const char* pred_text,\n                                  const char* e1,\n                                  const char* e2,\n                                  const char* e3,\n                                  const char* e4,\n                                  const char* e5,\n                                  Pred pred,\n                                  const T1& v1,\n                                  const T2& v2,\n                                  const T3& v3,\n                                  const T4& v4,\n                                  const T5& v5) {\n  if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();\n\n  return AssertionFailure() << pred_text << \"(\"\n                            << e1 << \", \"\n                            << e2 << \", \"\n                            << e3 << \", \"\n                            << e4 << \", \"\n                            << e5 << \") evaluates to false, where\"\n                            << \"\\n\" << e1 << \" evaluates to \" << v1\n                            << \"\\n\" << e2 << \" evaluates to \" << v2\n                            << \"\\n\" << e3 << \" evaluates to \" << v3\n                            << \"\\n\" << e4 << \" evaluates to \" << v4\n                            << \"\\n\" << e5 << \" evaluates to \" << v5;\n}\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.\n// Don't use this in your code.\n#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\\\n  GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5),\\\n                on_failure)\n\n// Internal macro for implementing {EXPECT|ASSERT}_PRED5.  Don't use\n// this in your code.\n#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\\\n  GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \\\n                                             #v1, \\\n                                             #v2, \\\n                                             #v3, \\\n                                             #v4, \\\n                                             #v5, \\\n                                             pred, \\\n                                             v1, \\\n                                             v2, \\\n                                             v3, \\\n                                             v4, \\\n                                             v5), on_failure)\n\n// 5-ary predicate assertion macros.\n#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \\\n  GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)\n#define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \\\n  GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)\n#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \\\n  GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)\n#define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \\\n  GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)\n\n\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_\n\n// Macros for testing equalities and inequalities.\n//\n//    * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual\n//    * {ASSERT|EXPECT}_NE(v1, v2):           Tests that v1 != v2\n//    * {ASSERT|EXPECT}_LT(v1, v2):           Tests that v1 < v2\n//    * {ASSERT|EXPECT}_LE(v1, v2):           Tests that v1 <= v2\n//    * {ASSERT|EXPECT}_GT(v1, v2):           Tests that v1 > v2\n//    * {ASSERT|EXPECT}_GE(v1, v2):           Tests that v1 >= v2\n//\n// When they are not, Google Test prints both the tested expressions and\n// their actual values.  The values must be compatible built-in types,\n// or you will get a compiler error.  By \"compatible\" we mean that the\n// values can be compared by the respective operator.\n//\n// Note:\n//\n//   1. It is possible to make a user-defined type work with\n//   {ASSERT|EXPECT}_??(), but that requires overloading the\n//   comparison operators and is thus discouraged by the Google C++\n//   Usage Guide.  Therefore, you are advised to use the\n//   {ASSERT|EXPECT}_TRUE() macro to assert that two objects are\n//   equal.\n//\n//   2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on\n//   pointers (in particular, C strings).  Therefore, if you use it\n//   with two C strings, you are testing how their locations in memory\n//   are related, not how their content is related.  To compare two C\n//   strings by content, use {ASSERT|EXPECT}_STR*().\n//\n//   3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to\n//   {ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you\n//   what the actual value is when it fails, and similarly for the\n//   other comparisons.\n//\n//   4. Do not depend on the order in which {ASSERT|EXPECT}_??()\n//   evaluate their arguments, which is undefined.\n//\n//   5. These macros evaluate their arguments exactly once.\n//\n// Examples:\n//\n//   EXPECT_NE(5, Foo());\n//   EXPECT_EQ(NULL, a_pointer);\n//   ASSERT_LT(i, array_size);\n//   ASSERT_GT(records.size(), 0) << \"There is no record left.\";\n\n#define EXPECT_EQ(expected, actual) \\\n  EXPECT_PRED_FORMAT2(::testing::internal:: \\\n                      EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \\\n                      expected, actual)\n#define EXPECT_NE(expected, actual) \\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)\n#define EXPECT_LE(val1, val2) \\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)\n#define EXPECT_LT(val1, val2) \\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)\n#define EXPECT_GE(val1, val2) \\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)\n#define EXPECT_GT(val1, val2) \\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)\n\n#define GTEST_ASSERT_EQ(expected, actual) \\\n  ASSERT_PRED_FORMAT2(::testing::internal:: \\\n                      EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \\\n                      expected, actual)\n#define GTEST_ASSERT_NE(val1, val2) \\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)\n#define GTEST_ASSERT_LE(val1, val2) \\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)\n#define GTEST_ASSERT_LT(val1, val2) \\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)\n#define GTEST_ASSERT_GE(val1, val2) \\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)\n#define GTEST_ASSERT_GT(val1, val2) \\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)\n\n// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of\n// ASSERT_XY(), which clashes with some users' own code.\n\n#if !GTEST_DONT_DEFINE_ASSERT_EQ\n# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)\n#endif\n\n#if !GTEST_DONT_DEFINE_ASSERT_NE\n# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)\n#endif\n\n#if !GTEST_DONT_DEFINE_ASSERT_LE\n# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)\n#endif\n\n#if !GTEST_DONT_DEFINE_ASSERT_LT\n# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)\n#endif\n\n#if !GTEST_DONT_DEFINE_ASSERT_GE\n# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)\n#endif\n\n#if !GTEST_DONT_DEFINE_ASSERT_GT\n# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)\n#endif\n\n// C String Comparisons.  All tests treat NULL and any non-NULL string\n// as different.  Two NULLs are equal.\n//\n//    * {ASSERT|EXPECT}_STREQ(s1, s2):     Tests that s1 == s2\n//    * {ASSERT|EXPECT}_STRNE(s1, s2):     Tests that s1 != s2\n//    * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case\n//    * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case\n//\n// For wide or narrow string objects, you can use the\n// {ASSERT|EXPECT}_??() macros.\n//\n// Don't depend on the order in which the arguments are evaluated,\n// which is undefined.\n//\n// These macros evaluate their arguments exactly once.\n\n#define EXPECT_STREQ(expected, actual) \\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)\n#define EXPECT_STRNE(s1, s2) \\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)\n#define EXPECT_STRCASEEQ(expected, actual) \\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)\n#define EXPECT_STRCASENE(s1, s2)\\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)\n\n#define ASSERT_STREQ(expected, actual) \\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)\n#define ASSERT_STRNE(s1, s2) \\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)\n#define ASSERT_STRCASEEQ(expected, actual) \\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)\n#define ASSERT_STRCASENE(s1, s2)\\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)\n\n// Macros for comparing floating-point numbers.\n//\n//    * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual):\n//         Tests that two float values are almost equal.\n//    * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual):\n//         Tests that two double values are almost equal.\n//    * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):\n//         Tests that v1 and v2 are within the given distance to each other.\n//\n// Google Test uses ULP-based comparison to automatically pick a default\n// error bound that is appropriate for the operands.  See the\n// FloatingPoint template class in gtest-internal.h if you are\n// interested in the implementation details.\n\n#define EXPECT_FLOAT_EQ(expected, actual)\\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \\\n                      expected, actual)\n\n#define EXPECT_DOUBLE_EQ(expected, actual)\\\n  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \\\n                      expected, actual)\n\n#define ASSERT_FLOAT_EQ(expected, actual)\\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \\\n                      expected, actual)\n\n#define ASSERT_DOUBLE_EQ(expected, actual)\\\n  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \\\n                      expected, actual)\n\n#define EXPECT_NEAR(val1, val2, abs_error)\\\n  EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \\\n                      val1, val2, abs_error)\n\n#define ASSERT_NEAR(val1, val2, abs_error)\\\n  ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \\\n                      val1, val2, abs_error)\n\n// These predicate format functions work on floating-point values, and\n// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.\n//\n//   EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);\n\n// Asserts that val1 is less than, or almost equal to, val2.  Fails\n// otherwise.  In particular, it fails if either val1 or val2 is NaN.\nGTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,\n                                   float val1, float val2);\nGTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,\n                                    double val1, double val2);\n\n\n#if GTEST_OS_WINDOWS\n\n// Macros that test for HRESULT failure and success, these are only useful\n// on Windows, and rely on Windows SDK macros and APIs to compile.\n//\n//    * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)\n//\n// When expr unexpectedly fails or succeeds, Google Test prints the\n// expected result and the actual result with both a human-readable\n// string representation of the error, if available, as well as the\n// hex result code.\n# define EXPECT_HRESULT_SUCCEEDED(expr) \\\n    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))\n\n# define ASSERT_HRESULT_SUCCEEDED(expr) \\\n    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))\n\n# define EXPECT_HRESULT_FAILED(expr) \\\n    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))\n\n# define ASSERT_HRESULT_FAILED(expr) \\\n    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))\n\n#endif  // GTEST_OS_WINDOWS\n\n// Macros that execute statement and check that it doesn't generate new fatal\n// failures in the current thread.\n//\n//   * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);\n//\n// Examples:\n//\n//   EXPECT_NO_FATAL_FAILURE(Process());\n//   ASSERT_NO_FATAL_FAILURE(Process()) << \"Process() failed\";\n//\n#define ASSERT_NO_FATAL_FAILURE(statement) \\\n    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)\n#define EXPECT_NO_FATAL_FAILURE(statement) \\\n    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)\n\n// Causes a trace (including the source file path, the current line\n// number, and the given message) to be included in every test failure\n// message generated by code in the current scope.  The effect is\n// undone when the control leaves the current scope.\n//\n// The message argument can be anything streamable to std::ostream.\n//\n// In the implementation, we include the current line number as part\n// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s\n// to appear in the same block - as long as they are on different\n// lines.\n#define SCOPED_TRACE(message) \\\n  ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\\\n    __FILE__, __LINE__, ::testing::Message() << (message))\n\n// Compile-time assertion for type equality.\n// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are\n// the same type.  The value it returns is not interesting.\n//\n// Instead of making StaticAssertTypeEq a class template, we make it a\n// function template that invokes a helper class template.  This\n// prevents a user from misusing StaticAssertTypeEq<T1, T2> by\n// defining objects of that type.\n//\n// CAVEAT:\n//\n// When used inside a method of a class template,\n// StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is\n// instantiated.  For example, given:\n//\n//   template <typename T> class Foo {\n//    public:\n//     void Bar() { testing::StaticAssertTypeEq<int, T>(); }\n//   };\n//\n// the code:\n//\n//   void Test1() { Foo<bool> foo; }\n//\n// will NOT generate a compiler error, as Foo<bool>::Bar() is never\n// actually instantiated.  Instead, you need:\n//\n//   void Test2() { Foo<bool> foo; foo.Bar(); }\n//\n// to cause a compiler error.\ntemplate <typename T1, typename T2>\nbool StaticAssertTypeEq() {\n  (void)internal::StaticAssertTypeEqHelper<T1, T2>();\n  return true;\n}\n\n// Defines a test.\n//\n// The first parameter is the name of the test case, and the second\n// parameter is the name of the test within the test case.\n//\n// The convention is to end the test case name with \"Test\".  For\n// example, a test case for the Foo class can be named FooTest.\n//\n// The user should put his test code between braces after using this\n// macro.  Example:\n//\n//   TEST(FooTest, InitializesCorrectly) {\n//     Foo foo;\n//     EXPECT_TRUE(foo.StatusIsOK());\n//   }\n\n// Note that we call GetTestTypeId() instead of GetTypeId<\n// ::testing::Test>() here to get the type ID of testing::Test.  This\n// is to work around a suspected linker bug when using Google Test as\n// a framework on Mac OS X.  The bug causes GetTypeId<\n// ::testing::Test>() to return different values depending on whether\n// the call is from the Google Test framework itself or from user test\n// code.  GetTestTypeId() is guaranteed to always return the same\n// value, as it always calls GetTypeId<>() from the Google Test\n// framework.\n#define GTEST_TEST(test_case_name, test_name)\\\n  GTEST_TEST_(test_case_name, test_name, \\\n              ::testing::Test, ::testing::internal::GetTestTypeId())\n\n// Define this macro to 1 to omit the definition of TEST(), which\n// is a generic name and clashes with some other libraries.\n#if !GTEST_DONT_DEFINE_TEST\n# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)\n#endif\n\n// Defines a test that uses a test fixture.\n//\n// The first parameter is the name of the test fixture class, which\n// also doubles as the test case name.  The second parameter is the\n// name of the test within the test case.\n//\n// A test fixture class must be declared earlier.  The user should put\n// his test code between braces after using this macro.  Example:\n//\n//   class FooTest : public testing::Test {\n//    protected:\n//     virtual void SetUp() { b_.AddElement(3); }\n//\n//     Foo a_;\n//     Foo b_;\n//   };\n//\n//   TEST_F(FooTest, InitializesCorrectly) {\n//     EXPECT_TRUE(a_.StatusIsOK());\n//   }\n//\n//   TEST_F(FooTest, ReturnsElementCountCorrectly) {\n//     EXPECT_EQ(0, a_.size());\n//     EXPECT_EQ(1, b_.size());\n//   }\n\n#define TEST_F(test_fixture, test_name)\\\n  GTEST_TEST_(test_fixture, test_name, test_fixture, \\\n              ::testing::internal::GetTypeId<test_fixture>())\n\n// Use this macro in main() to run all tests.  It returns 0 if all\n// tests are successful, or 1 otherwise.\n//\n// RUN_ALL_TESTS() should be invoked after the command line has been\n// parsed by InitGoogleTest().\n\n#define RUN_ALL_TESTS()\\\n  (::testing::UnitTest::GetInstance()->Run())\n\n}  // namespace testing\n\n#endif  // GTEST_INCLUDE_GTEST_GTEST_H_\n"
  },
  {
    "path": "src/gtest/gtest_main.cc",
    "content": "// Copyright 2006, Google Inc.\n// All rights reserved.\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n//     * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n//     * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n//     * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n#include <iostream>\n\n#include \"gtest/gtest.h\"\n\nGTEST_API_ int main(int argc, char **argv) {\n  std::cout << \"Running main() from gtest_main.cc\\n\";\n\n  testing::InitGoogleTest(&argc, argv);\n  return RUN_ALL_TESTS();\n}\n"
  },
  {
    "path": "tools/caffe.cpp",
    "content": "#ifdef WITH_PYTHON_LAYER\n#include \"boost/python.hpp\"\nnamespace bp = boost::python;\n#endif\n\n#include <glog/logging.h>\n\n#include <cstring>\n#include <map>\n#include <string>\n#include <vector>\n\n#include \"boost/algorithm/string.hpp\"\n#include \"caffe/caffe.hpp\"\n\nusing caffe::Blob;\nusing caffe::Caffe;\nusing caffe::Net;\nusing caffe::Layer;\nusing caffe::Solver;\nusing caffe::shared_ptr;\nusing caffe::string;\nusing caffe::Timer;\nusing caffe::vector;\nusing std::ostringstream;\n\nDEFINE_string(gpu, \"\",\n    \"Optional; run in GPU mode on given device IDs separated by ','.\"\n    \"Use '-gpu all' to run on all available GPUs. The effective training \"\n    \"batch size is multiplied by the number of devices.\");\nDEFINE_string(solver, \"\",\n    \"The solver definition protocol buffer text file.\");\nDEFINE_string(model, \"\",\n    \"The model definition protocol buffer text file..\");\nDEFINE_string(snapshot, \"\",\n    \"Optional; the snapshot solver state to resume training.\");\nDEFINE_string(weights, \"\",\n    \"Optional; the pretrained weights to initialize finetuning, \"\n    \"separated by ','. Cannot be set simultaneously with snapshot.\");\nDEFINE_int32(iterations, 50,\n    \"The number of iterations to run.\");\n\n// A simple registry for caffe commands.\ntypedef int (*BrewFunction)();\ntypedef std::map<caffe::string, BrewFunction> BrewMap;\nBrewMap g_brew_map;\n\n#define RegisterBrewFunction(func) \\\nnamespace { \\\nclass __Registerer_##func { \\\n public: /* NOLINT */ \\\n  __Registerer_##func() { \\\n    g_brew_map[#func] = &func; \\\n  } \\\n}; \\\n__Registerer_##func g_registerer_##func; \\\n}\n\nstatic BrewFunction GetBrewFunction(const caffe::string& name) {\n  if (g_brew_map.count(name)) {\n    return g_brew_map[name];\n  } else {\n    LOG(ERROR) << \"Available caffe actions:\";\n    for (BrewMap::iterator it = g_brew_map.begin();\n         it != g_brew_map.end(); ++it) {\n      LOG(ERROR) << \"\\t\" << it->first;\n    }\n    LOG(FATAL) << \"Unknown action: \" << name;\n    return NULL;  // not reachable, just to suppress old compiler warnings.\n  }\n}\n\n// Parse GPU ids or use all available devices\nstatic void get_gpus(vector<int>* gpus) {\n  if (FLAGS_gpu == \"all\") {\n    int count = 0;\n#ifndef CPU_ONLY\n    CUDA_CHECK(cudaGetDeviceCount(&count));\n#else\n    NO_GPU;\n#endif\n    for (int i = 0; i < count; ++i) {\n      gpus->push_back(i);\n    }\n  } else if (FLAGS_gpu.size()) {\n    vector<string> strings;\n    boost::split(strings, FLAGS_gpu, boost::is_any_of(\",\"));\n    for (int i = 0; i < strings.size(); ++i) {\n      gpus->push_back(boost::lexical_cast<int>(strings[i]));\n    }\n  } else {\n    CHECK_EQ(gpus->size(), 0);\n  }\n}\n\n// caffe commands to call by\n//     caffe <command> <args>\n//\n// To add a command, define a function \"int command()\" and register it with\n// RegisterBrewFunction(action);\n\n// Device Query: show diagnostic information for a GPU device.\nint device_query() {\n  LOG(INFO) << \"Querying GPUs \" << FLAGS_gpu;\n  vector<int> gpus;\n  get_gpus(&gpus);\n  for (int i = 0; i < gpus.size(); ++i) {\n    caffe::Caffe::SetDevice(gpus[i]);\n    caffe::Caffe::DeviceQuery();\n  }\n  return 0;\n}\nRegisterBrewFunction(device_query);\n\n// Load the weights from the specified caffemodel(s) into the train and\n// test nets.\nvoid CopyLayers(caffe::Solver<float>* solver, const std::string& model_list) {\n  std::vector<std::string> model_names;\n  boost::split(model_names, model_list, boost::is_any_of(\",\") );\n  for (int i = 0; i < model_names.size(); ++i) {\n    LOG(INFO) << \"Finetuning from \" << model_names[i];\n    solver->net()->CopyTrainedLayersFrom(model_names[i]);\n    for (int j = 0; j < solver->test_nets().size(); ++j) {\n      solver->test_nets()[j]->CopyTrainedLayersFrom(model_names[i]);\n    }\n  }\n}\n\n// Train / Finetune a model.\nint train() {\n  CHECK_GT(FLAGS_solver.size(), 0) << \"Need a solver definition to train.\";\n  CHECK(!FLAGS_snapshot.size() || !FLAGS_weights.size())\n      << \"Give a snapshot to resume training or weights to finetune \"\n      \"but not both.\";\n\n  caffe::SolverParameter solver_param;\n  caffe::ReadProtoFromTextFileOrDie(FLAGS_solver, &solver_param);\n\n  // If the gpus flag is not provided, allow the mode and device to be set\n  // in the solver prototxt.\n  if (FLAGS_gpu.size() == 0\n      && solver_param.solver_mode() == caffe::SolverParameter_SolverMode_GPU) {\n      if (solver_param.has_device_id()) {\n          FLAGS_gpu = \"\"  +\n              boost::lexical_cast<string>(solver_param.device_id());\n      } else {  // Set default GPU if unspecified\n          FLAGS_gpu = \"\" + boost::lexical_cast<string>(0);\n      }\n  }\n\n  vector<int> gpus;\n  get_gpus(&gpus);\n  if (gpus.size() == 0) {\n    Caffe::set_mode(Caffe::CPU);\n  } else {\n    ostringstream s;\n    for (int i = 0; i < gpus.size(); ++i) {\n      s << (i ? \", \" : \"\") << gpus[i];\n    }\n    LOG(INFO) << \"Using GPUs \" << s.str();\n\n    solver_param.set_device_id(gpus[0]);\n    Caffe::SetDevice(gpus[0]);\n    Caffe::set_mode(Caffe::GPU);\n    Caffe::set_solver_count(gpus.size());\n  }\n\n  shared_ptr<Solver<float> > solver(caffe::GetSolver<float>(solver_param));\n\n  if (FLAGS_snapshot.size()) {\n    LOG(INFO) << \"Resuming from \" << FLAGS_snapshot;\n    solver->Restore(FLAGS_snapshot.c_str());\n  } else if (FLAGS_weights.size()) {\n    CopyLayers(solver.get(), FLAGS_weights);\n  }\n\n  if (gpus.size() > 1) {\n    caffe::P2PSync<float> sync(solver, NULL, solver->param());\n    sync.run(gpus);\n  } else {\n    LOG(INFO) << \"Starting Optimization\";\n    solver->Solve();\n  }\n  LOG(INFO) << \"Optimization Done.\";\n  return 0;\n}\nRegisterBrewFunction(train);\n\n\n// Test: score a model.\nint test() {\n  CHECK_GT(FLAGS_model.size(), 0) << \"Need a model definition to score.\";\n  CHECK_GT(FLAGS_weights.size(), 0) << \"Need model weights to score.\";\n\n  // Set device id and mode\n  vector<int> gpus;\n  get_gpus(&gpus);\n  if (gpus.size() != 0) {\n    LOG(INFO) << \"Use GPU with device ID \" << gpus[0];\n    Caffe::SetDevice(gpus[0]);\n    Caffe::set_mode(Caffe::GPU);\n  } else {\n    LOG(INFO) << \"Use CPU.\";\n    Caffe::set_mode(Caffe::CPU);\n  }\n  // Instantiate the caffe net.\n  Net<float> caffe_net(FLAGS_model, caffe::TEST);\n  caffe_net.CopyTrainedLayersFrom(FLAGS_weights);\n  LOG(INFO) << \"Running for \" << FLAGS_iterations << \" iterations.\";\n\n  vector<Blob<float>* > bottom_vec;\n  vector<int> test_score_output_id;\n  vector<float> test_score;\n  float loss = 0;\n  for (int i = 0; i < FLAGS_iterations; ++i) {\n    float iter_loss;\n    const vector<Blob<float>*>& result =\n        caffe_net.Forward(bottom_vec, &iter_loss);\n    loss += iter_loss;\n    int idx = 0;\n    for (int j = 0; j < result.size(); ++j) {\n      const float* result_vec = result[j]->cpu_data();\n      for (int k = 0; k < result[j]->count(); ++k, ++idx) {\n        const float score = result_vec[k];\n        if (i == 0) {\n          test_score.push_back(score);\n          test_score_output_id.push_back(j);\n        } else {\n          test_score[idx] += score;\n        }\n        const std::string& output_name = caffe_net.blob_names()[\n            caffe_net.output_blob_indices()[j]];\n        LOG(INFO) << \"Batch \" << i << \", \" << output_name << \" = \" << score;\n      }\n    }\n  }\n  loss /= FLAGS_iterations;\n  LOG(INFO) << \"Loss: \" << loss;\n  for (int i = 0; i < test_score.size(); ++i) {\n    const std::string& output_name = caffe_net.blob_names()[\n        caffe_net.output_blob_indices()[test_score_output_id[i]]];\n    const float loss_weight = caffe_net.blob_loss_weights()[\n        caffe_net.output_blob_indices()[test_score_output_id[i]]];\n    std::ostringstream loss_msg_stream;\n    const float mean_score = test_score[i] / FLAGS_iterations;\n    if (loss_weight) {\n      loss_msg_stream << \" (* \" << loss_weight\n                      << \" = \" << loss_weight * mean_score << \" loss)\";\n    }\n    LOG(INFO) << output_name << \" = \" << mean_score << loss_msg_stream.str();\n  }\n\n  return 0;\n}\nRegisterBrewFunction(test);\n\n\n// Time: benchmark the execution time of a model.\nint time() {\n  CHECK_GT(FLAGS_model.size(), 0) << \"Need a model definition to time.\";\n\n  // Set device id and mode\n  vector<int> gpus;\n  get_gpus(&gpus);\n  if (gpus.size() != 0) {\n    LOG(INFO) << \"Use GPU with device ID \" << gpus[0];\n    Caffe::SetDevice(gpus[0]);\n    Caffe::set_mode(Caffe::GPU);\n  } else {\n    LOG(INFO) << \"Use CPU.\";\n    Caffe::set_mode(Caffe::CPU);\n  }\n  // Instantiate the caffe net.\n  Net<float> caffe_net(FLAGS_model, caffe::TRAIN);\n\n  // Do a clean forward and backward pass, so that memory allocation are done\n  // and future iterations will be more stable.\n  LOG(INFO) << \"Performing Forward\";\n  // Note that for the speed benchmark, we will assume that the network does\n  // not take any input blobs.\n  float initial_loss;\n  caffe_net.Forward(vector<Blob<float>*>(), &initial_loss);\n  LOG(INFO) << \"Initial loss: \" << initial_loss;\n  LOG(INFO) << \"Performing Backward\";\n  caffe_net.Backward();\n\n  const vector<shared_ptr<Layer<float> > >& layers = caffe_net.layers();\n  const vector<vector<Blob<float>*> >& bottom_vecs = caffe_net.bottom_vecs();\n  const vector<vector<Blob<float>*> >& top_vecs = caffe_net.top_vecs();\n  const vector<vector<bool> >& bottom_need_backward =\n      caffe_net.bottom_need_backward();\n  LOG(INFO) << \"*** Benchmark begins ***\";\n  LOG(INFO) << \"Testing for \" << FLAGS_iterations << \" iterations.\";\n  Timer total_timer;\n  total_timer.Start();\n  Timer forward_timer;\n  Timer backward_timer;\n  Timer timer;\n  std::vector<double> forward_time_per_layer(layers.size(), 0.0);\n  std::vector<double> backward_time_per_layer(layers.size(), 0.0);\n  double forward_time = 0.0;\n  double backward_time = 0.0;\n  for (int j = 0; j < FLAGS_iterations; ++j) {\n    Timer iter_timer;\n    iter_timer.Start();\n    forward_timer.Start();\n    for (int i = 0; i < layers.size(); ++i) {\n      timer.Start();\n      layers[i]->Forward(bottom_vecs[i], top_vecs[i]);\n      forward_time_per_layer[i] += timer.MicroSeconds();\n    }\n    forward_time += forward_timer.MicroSeconds();\n    backward_timer.Start();\n    for (int i = layers.size() - 1; i >= 0; --i) {\n      timer.Start();\n      layers[i]->Backward(top_vecs[i], bottom_need_backward[i],\n                          bottom_vecs[i]);\n      backward_time_per_layer[i] += timer.MicroSeconds();\n    }\n    backward_time += backward_timer.MicroSeconds();\n    LOG(INFO) << \"Iteration: \" << j + 1 << \" forward-backward time: \"\n      << iter_timer.MilliSeconds() << \" ms.\";\n  }\n  LOG(INFO) << \"Average time per layer: \";\n  for (int i = 0; i < layers.size(); ++i) {\n    const caffe::string& layername = layers[i]->layer_param().name();\n    LOG(INFO) << std::setfill(' ') << std::setw(10) << layername <<\n      \"\\tforward: \" << forward_time_per_layer[i] / 1000 /\n      FLAGS_iterations << \" ms.\";\n    LOG(INFO) << std::setfill(' ') << std::setw(10) << layername  <<\n      \"\\tbackward: \" << backward_time_per_layer[i] / 1000 /\n      FLAGS_iterations << \" ms.\";\n  }\n  total_timer.Stop();\n  LOG(INFO) << \"Average Forward pass: \" << forward_time / 1000 /\n    FLAGS_iterations << \" ms.\";\n  LOG(INFO) << \"Average Backward pass: \" << backward_time / 1000 /\n    FLAGS_iterations << \" ms.\";\n  LOG(INFO) << \"Average Forward-Backward: \" << total_timer.MilliSeconds() /\n    FLAGS_iterations << \" ms.\";\n  LOG(INFO) << \"Total Time: \" << total_timer.MilliSeconds() << \" ms.\";\n  LOG(INFO) << \"*** Benchmark ends ***\";\n  return 0;\n}\nRegisterBrewFunction(time);\n\nint main(int argc, char** argv) {\n  // Print output to stderr (while still logging).\n  FLAGS_alsologtostderr = 1;\n  // Usage message.\n  gflags::SetUsageMessage(\"command line brew\\n\"\n      \"usage: caffe <command> <args>\\n\\n\"\n      \"commands:\\n\"\n      \"  train           train or finetune a model\\n\"\n      \"  test            score a model\\n\"\n      \"  device_query    show GPU diagnostic information\\n\"\n      \"  time            benchmark model execution time\");\n  // Run tool or show usage.\n  caffe::GlobalInit(&argc, &argv);\n  if (argc == 2) {\n#ifdef WITH_PYTHON_LAYER\n    try {\n#endif\n      return GetBrewFunction(caffe::string(argv[1]))();\n#ifdef WITH_PYTHON_LAYER\n    } catch (bp::error_already_set) {\n      PyErr_Print();\n      return 1;\n    }\n#endif\n  } else {\n    gflags::ShowUsageWithFlagsRestrict(argv[0], \"tools/caffe\");\n  }\n}\n"
  }
]