Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is exactly the definition of function-like macros such as CHECK & CHECK_EQ in Caffe?

As I noticed, there are lots of function-like macros such as CHECK, CHECK_EQ, ... which are frequently used in Caffe headers and source files, for example in blob.cpp we have:

template <typename Dtype>
void Blob<Dtype>::FromProto(const BlobProto& proto, bool reshape) {
if (reshape) {
  vector<int> shape;
  if (proto.has_num() || proto.has_channels() ||
      proto.has_height() || proto.has_width()) {
    // Using deprecated 4D Blob dimensions --
    // shape is (num, channels, height, width).
    shape.resize(4);
    shape[0] = proto.num();
    shape[1] = proto.channels();
    shape[2] = proto.height();
    shape[3] = proto.width();
  } else {
    shape.resize(proto.shape().dim_size());
    for (int i = 0; i < proto.shape().dim_size(); ++i) {
      shape[i] = proto.shape().dim(i);
    }
  }
  Reshape(shape);
} else {
  CHECK(ShapeEquals(proto)) << "shape mismatch (reshape not set)";
}
// copy data
Dtype* data_vec = mutable_cpu_data();
if (proto.double_data_size() > 0) {
  CHECK_EQ(count_, proto.double_data_size());
  for (int i = 0; i < count_; ++i) {
    data_vec[i] = proto.double_data(i);
  }
} else {
  CHECK_EQ(count_, proto.data_size());
  for (int i = 0; i < count_; ++i) {
    data_vec[i] = proto.data(i);
  }
}
if (proto.double_diff_size() > 0) {
  CHECK_EQ(count_, proto.double_diff_size());
  Dtype* diff_vec = mutable_cpu_diff();
  for (int i = 0; i < count_; ++i) {
    diff_vec[i] = proto.double_diff(i);
  }
} else if (proto.diff_size() > 0) {
  CHECK_EQ(count_, proto.diff_size());
  Dtype* diff_vec = mutable_cpu_diff();
  for (int i = 0; i < count_; ++i) {
    diff_vec[i] = proto.diff(i);
  }
 }

Where is exactly the definition of these macros?

like image 580
Ali Sharifi B. Avatar asked Jul 21 '16 16:07

Ali Sharifi B.


People also ask

How do you define a function-like a macro?

Function-like macro definition: An identifier followed by a parameter list in parentheses and the replacement tokens. The parameters are imbedded in the replacement code. White space cannot separate the identifier (which is the name of the macro) and the left parenthesis of the parameter list.

Where can a macro be defined?

A macro is a fragment of code that is given a name. You can define a macro in C using the #define preprocessor directive.

How are macros defined #define?

noun. plural macros. Definition of macro (Entry 2 of 3) : a single computer instruction that stands for a sequence of operations.

What is the function of macro?

A macro is an automated input sequence that imitates keystrokes or mouse actions. A macro is typically used to replace a repetitive series of keyboard and mouse actions and used often in spreadsheets and word processing applications like MS Excel and MS Word. The file extension of a macro is commonly .


1 Answers

These macros are part of Google's glog logging library that caffe is using.

like image 164
Shai Avatar answered Sep 23 '22 21:09

Shai