Skip to content

Commit 74fa879

Browse files
committed
Add lint rule for caffe data layer setup
1 parent 09cfe1c commit 74fa879

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

scripts/cpp_lint.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
'build/printf_format',
156156
'build/storage_class',
157157
'caffe/alt_fn',
158+
'caffe/data_layer_setup',
158159
'caffe/random_fn',
159160
'legal/copyright',
160161
'readability/alt_tokens',
@@ -1591,6 +1592,45 @@ def CheckCaffeAlternatives(filename, clean_lines, linenum, error):
15911592
(' or '.join(disp_alts), function))
15921593

15931594

1595+
def CheckCaffeDataLayerSetUp(filename, clean_lines, linenum, error):
1596+
"""Except the base classes, Caffe DataLayer should define DataLayerSetUp
1597+
instead of LayerSetUp.
1598+
1599+
The base DataLayers define common SetUp steps, the subclasses should
1600+
not override them.
1601+
1602+
Args:
1603+
filename: The name of the current file.
1604+
clean_lines: A CleansedLines instance containing the file.
1605+
linenum: The number of the line to check.
1606+
error: The function to call with any errors found.
1607+
"""
1608+
line = clean_lines.elided[linenum]
1609+
ix = line.find('DataLayer<Dtype>::LayerSetUp')
1610+
if ix >= 0 and (
1611+
line.find('void DataLayer<Dtype>::LayerSetUp') != -1 or
1612+
line.find('void ImageDataLayer<Dtype>::LayerSetUp') != -1 or
1613+
line.find('void MemoryDataLayer<Dtype>::LayerSetUp') != -1 or
1614+
line.find('void WindowDataLayer<Dtype>::LayerSetUp') != -1):
1615+
error(filename, linenum, 'caffe/data_layer_setup', 2,
1616+
'Except the base classes, Caffe DataLayer should define'
1617+
+ ' DataLayerSetUp instead of LayerSetUp. The base DataLayers'
1618+
+ ' define common SetUp steps, the subclasses should'
1619+
+ ' not override them.')
1620+
ix = line.find('DataLayer<Dtype>::DataLayerSetUp')
1621+
if ix >= 0 and (
1622+
line.find('void Base') == -1 and
1623+
line.find('void DataLayer<Dtype>::DataLayerSetUp') == -1 and
1624+
line.find('void ImageDataLayer<Dtype>::DataLayerSetUp') == -1 and
1625+
line.find('void MemoryDataLayer<Dtype>::DataLayerSetUp') == -1 and
1626+
line.find('void WindowDataLayer<Dtype>::DataLayerSetUp') == -1):
1627+
error(filename, linenum, 'caffe/data_layer_setup', 2,
1628+
'Except the base classes, Caffe DataLayer should define'
1629+
+ ' DataLayerSetUp instead of LayerSetUp. The base DataLayers'
1630+
+ ' define common SetUp steps, the subclasses should'
1631+
+ ' not override them.')
1632+
1633+
15941634
c_random_function_list = (
15951635
'rand(',
15961636
'rand_r(',
@@ -4593,6 +4633,7 @@ def ProcessLine(filename, file_extension, clean_lines, line,
45934633
nesting_state, error)
45944634
CheckVlogArguments(filename, clean_lines, line, error)
45954635
CheckCaffeAlternatives(filename, clean_lines, line, error)
4636+
CheckCaffeDataLayerSetUp(filename, clean_lines, line, error)
45964637
CheckCaffeRandom(filename, clean_lines, line, error)
45974638
CheckPosixThreading(filename, clean_lines, line, error)
45984639
CheckInvalidIncrement(filename, clean_lines, line, error)

0 commit comments

Comments
 (0)