MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / CheckCaffeRandom

Function CheckCaffeRandom

rtpose_wrapper/scripts/cpp_lint.py:1640–1663  ·  view source on GitHub ↗

Checks for calls to C random functions (rand, rand_r, random, ...). Caffe code should (almost) always use the caffe_rng_* functions rather than these, as the internal state of these C functions is independent of the native Caffe RNG system which should produce deterministic results for a fi

(filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

1638 )
1639
1640def CheckCaffeRandom(filename, clean_lines, linenum, error):
1641 """Checks for calls to C random functions (rand, rand_r, random, ...).
1642
1643 Caffe code should (almost) always use the caffe_rng_* functions rather
1644 than these, as the internal state of these C functions is independent of the
1645 native Caffe RNG system which should produce deterministic results for a
1646 fixed Caffe seed set using Caffe::set_random_seed(...).
1647
1648 Args:
1649 filename: The name of the current file.
1650 clean_lines: A CleansedLines instance containing the file.
1651 linenum: The number of the line to check.
1652 error: The function to call with any errors found.
1653 """
1654 line = clean_lines.elided[linenum]
1655 for function in c_random_function_list:
1656 ix = line.find(function)
1657 # Comparisons made explicit for clarity -- pylint: disable=g-explicit-bool-comparison
1658 if ix >= 0 and (ix == 0 or (not line[ix - 1].isalnum() and
1659 line[ix - 1] not in ('_', '.', '>'))):
1660 error(filename, linenum, 'caffe/random_fn', 2,
1661 'Use caffe_rng_rand() (or other caffe_rng_* function) instead of '
1662 + function +
1663 ') to ensure results are deterministic for a fixed Caffe seed.')
1664
1665
1666threading_list = (

Callers 1

ProcessLineFunction · 0.85

Calls 1

errorFunction · 0.85

Tested by

no test coverage detected