/usr/local/lib64/python3.6/site-packages/torch/include/caffe2/core
NameSizeModeActions
allocator.h1360644editdlrm
blob.h41680644editdlrm
blob_serialization.h107910644editdlrm
blob_serializer_base.h39050644editdlrm
blob_stats.h11270644editdlrm
common.h43290644editdlrm
common_cudnn.h98930644editdlrm
common_gpu.h214140644editdlrm
common_omp.h1560644editdlrm
context.h61740644editdlrm
context_base.h43820644editdlrm
context_gpu.h110140644editdlrm
cudnn_wrappers.h69560644editdlrm
db.h93520644editdlrm
distributions_stubs.h21610644editdlrm
event.h124200644editdlrm
event_cpu.h11920644editdlrm
export_c10_op_to_caffe2.h94870644editdlrm
export_caffe2_op_to_c10.h111010644editdlrm
flags.h740644editdlrm
graph.h52580644editdlrm
init.h64960644editdlrm
logging.h750644editdlrm
macros.h34260644editdlrm
memonger.h8170644editdlrm
module.h24730644editdlrm
net.h46340644editdlrm
net_async_base.h73970644editdlrm
net_async_scheduling.h9930644editdlrm
net_async_task.h8330644editdlrm
net_async_task_future.h19250644editdlrm
net_async_task_graph.h22530644editdlrm
net_async_tracing.h50930644editdlrm
net_dag_utils.h21460644editdlrm
net_parallel.h21440644editdlrm
net_simple.h26060644editdlrm
net_simple_refcount.h20970644editdlrm
numa.h720644editdlrm
observer.h38090644editdlrm
operator.h588720644editdlrm
operator_gradient.h102220644editdlrm
operator_schema.h184770644editdlrm
plan_executor.h2190644editdlrm
prof_dag_counters.h27510644editdlrm
qtensor.h66150644editdlrm
qtensor_serialization.h26240644editdlrm
scope_guard.h46750644editdlrm
static_tracepoint.h3980644editdlrm
static_tracepoint_elfx86.h55550644editdlrm
stats.h103650644editdlrm
storage.h7330644editdlrm
tensor.h186680644editdlrm
tensor_impl.h3510644editdlrm
tensor_int8.h4500644editdlrm
test_utils.h62850644editdlrm
timer.h12180644editdlrm
transform.h57410644editdlrm
types.h22480644editdlrm
workspace.h113050644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/include/caffe2/core/test_utils.h (6285B)
#ifndef CAFFE2_UTILS_TEST_UTILS_H_ #define CAFFE2_UTILS_TEST_UTILS_H_ #include "caffe2/core/tensor.h" #include "caffe2/core/workspace.h" #include "caffe2/utils/proto_utils.h" #include #include #include #include // Utilities that make it easier to write caffe2 C++ unit tests. // These utils are designed to be concise and easy to use. They may sacrifice // performance and should only be used in tests/non production code. namespace caffe2 { namespace testing { // Asserts that the values of two tensors are the same. TORCH_API void assertTensorEquals( const TensorCPU& tensor1, const TensorCPU& tensor2, float eps = 1e-6); // Asserts that two float values are close within epsilon. TORCH_API void assertNear(float value1, float value2, float epsilon); // Asserts that the numeric values of a tensor is equal to a data vector. template void assertTensorEquals( const TensorCPU& tensor, const std::vector& data, float epsilon = 0.1f) { CAFFE_ENFORCE(tensor.IsType()); CAFFE_ENFORCE_EQ(tensor.numel(), data.size()); for (auto idx = 0; idx < tensor.numel(); ++idx) { if (tensor.IsType()) { assertNear(tensor.data()[idx], data[idx], epsilon); } else { CAFFE_ENFORCE_EQ(tensor.data()[idx], data[idx]); } } } // Assertion for tensor sizes and values. template void assertTensor( const TensorCPU& tensor, const std::vector& sizes, const std::vector& data, float epsilon = 0.1f) { CAFFE_ENFORCE_EQ(tensor.sizes(), sizes); assertTensorEquals(tensor, data, epsilon); } // Asserts a list of tensors presented in two workspaces are equal. TORCH_API void assertTensorListEquals( const std::vector& tensorNames, const Workspace& workspace1, const Workspace& workspace2); // Read a tensor from the workspace. TORCH_API const caffe2::Tensor& getTensor( const caffe2::Workspace& workspace, const std::string& name); // Create a new tensor in the workspace. TORCH_API caffe2::Tensor* createTensor( const std::string& name, caffe2::Workspace* workspace); // Create a new operator in the net. TORCH_API caffe2::OperatorDef* createOperator( const std::string& type, const std::vector& inputs, const std::vector& outputs, caffe2::NetDef* net); // Fill a buffer with randomly generated numbers given range [min, max) // T can only be float, double or long double template void randomFill( RealType* data, size_t size, const double min = 0.0, const double max = 1.0) { std::mt19937 gen(42); std::uniform_real_distribution dis( static_cast(min), static_cast(max)); for (size_t i = 0; i < size; i++) { data[i] = dis(gen); } } // Fill data from a vector to a tensor. template void fillTensor( const std::vector& shape, const std::vector& data, TensorCPU* tensor) { tensor->Resize(shape); CAFFE_ENFORCE_EQ(data.size(), tensor->numel()); auto ptr = tensor->mutable_data(); for (int i = 0; i < tensor->numel(); ++i) { ptr[i] = data[i]; } } // Create a tensor and fill data. template caffe2::Tensor* createTensorAndFill( const std::string& name, const std::vector& shape, const std::vector& data, Workspace* workspace) { auto* tensor = createTensor(name, workspace); fillTensor(shape, data, tensor); return tensor; } template caffe2::Tensor createTensorAndFill( const std::vector& shape, const std::vector& data) { Tensor tensor(caffe2::CPU); fillTensor(shape, data, &tensor); return tensor; } // Fill a constant to a tensor. template void constantFillTensor( const vector& shape, const T& data, TensorCPU* tensor) { tensor->Resize(shape); auto ptr = tensor->mutable_data(); for (int i = 0; i < tensor->numel(); ++i) { ptr[i] = data; } } // Create a tensor and fill a constant. template caffe2::Tensor* createTensorAndConstantFill( const std::string& name, const std::vector& shape, const T& data, Workspace* workspace) { auto* tensor = createTensor(name, workspace); constantFillTensor(shape, data, tensor); return tensor; } // Concise util class to mutate a net in a chaining fashion. class TORCH_API NetMutator { public: // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) explicit NetMutator(caffe2::NetDef* net) : net_(net) {} NetMutator& newOp( const std::string& type, const std::vector& inputs, const std::vector& outputs); NetMutator& externalInputs(const std::vector& externalInputs); NetMutator& externalOutputs(const std::vector& externalOutputs); // Add argument to the last created op. template NetMutator& addArgument(const std::string& name, const T& value) { CAFFE_ENFORCE(lastCreatedOp_ != nullptr); AddArgument(name, value, lastCreatedOp_); return *this; } // Set device name for the last created op. NetMutator& setDeviceOptionName(const std::string& name); private: caffe2::NetDef* net_; caffe2::OperatorDef* lastCreatedOp_; }; // Concise util class to mutate a workspace in a chaining fashion. class TORCH_API WorkspaceMutator { public: explicit WorkspaceMutator(caffe2::Workspace* workspace) : workspace_(workspace) {} // New tensor filled by a data vector. template WorkspaceMutator& newTensor( const std::string& name, const std::vector& shape, const std::vector& data) { createTensorAndFill(name, shape, data, workspace_); return *this; } // New tensor filled by a constant. template WorkspaceMutator& newTensorConst( const std::string& name, const std::vector& shape, const T& data) { createTensorAndConstantFill(name, shape, data, workspace_); return *this; } private: caffe2::Workspace* workspace_; }; } // namespace testing } // namespace caffe2 #endif // CAFFE2_UTILS_TEST_UTILS_H_