File: smart_tensor_printer.h

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (50 lines) | stat: -rw-r--r-- 1,402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include "caffe2/core/tensor.h"

namespace caffe2 {

// This is a wrapper around the TensorPrinter that doesn't require the user to
// explicit specify the type of the tensor while calling the Print() method.
// It also supports a convenience function with a default constructed printer as
// a static method.
class TORCH_API SmartTensorPrinter {
 public:
  // The proliferation of constructors is to give the feature parity with
  // TensorPrinter
  // yet not repeat the default arguments explicitly in case they change in the
  // future.
  SmartTensorPrinter() = default;

  explicit SmartTensorPrinter(const std::string& tensor_name);

  SmartTensorPrinter(
      const std::string& tensor_name,
      const std::string& file_name);

  SmartTensorPrinter(
      const std::string& tensor_name,
      const std::string& file_name,
      int limit);

  void Print(const Tensor& tensor);

  void PrintMeta(const Tensor& tensor) {
    tensorPrinter_.PrintMeta(tensor);
  }

  // Uses a default constructed SmartTensorPrinter
  static void PrintTensor(const Tensor& tensor);

  // Uses a default constructed SmartTensorPrinter
  void PrintTensorMeta(const Tensor& tensor) {
    DefaultTensorPrinter().PrintMeta(tensor);
  }

 private:
  // Returns a thread local default constructed TensorPrinter
  static SmartTensorPrinter& DefaultTensorPrinter();

  TensorPrinter tensorPrinter_;
};
}