Esempio n. 1
0
def test_to_snake_case_impl():
    fn_name_tests = [
        ('Test', 'test'),
        ('OneTwo', 'one_two'),
        ('TestXYZ', 'test_xyz'),
        ('testX', 'test_x'),
        ('TestXx', 'test_xx'),
        ('testXX', 'test_xx'),
        ('OneXYZTwo', 'one_xyz_two'),
        ('MFCC', 'mfcc'),
        ('RandomBBoxCrop', 'random_bbox_crop'),
        ('STFT_CPU', 'stft_cpu'),
        ('DOUBLE__UNDERSCORE', 'double__underscore'),
        ('double__underscore', 'double__underscore'),
        ('XYZ1ABC', 'xyz1abc'),
        ('XYZ1abc', 'xyz1abc'),
        ('trailing__', 'trailing__'),
        ('TRAILING__', 'trailing__'),
        ('Caffe2Reader', 'caffe2_reader'),
        ('COCOReader', 'coco_reader'),
        ('DLTensorPythonFunction', 'dl_tensor_python_function'),
        ('TFRecordReader', 'tfrecord_reader'),
    ]

    for inp, out in fn_name_tests:
        assert fn._to_snake_case(inp) == out, f"{fn._to_snake_case(inp)} != {out}"
Esempio n. 2
0
def _op_name(op_schema_name, api="fn"):
    full_name, submodule, op_name = _process_op_name(op_schema_name)
    if api == "fn":
        return ".".join([*submodule, _functional._to_snake_case(op_name)])
    elif api == "ops":
        return full_name
    else:
        raise ValueError('{} is not a valid DALI api name, try one of {"fn", "ops"}'.format(api))
Esempio n. 3
0
def to_fn_name(full_op_name):
    tokens = full_op_name.split('.')
    tokens[-1] = fn._to_snake_case(tokens[-1])
    return '.'.join(tokens)
Esempio n. 4
0
class DataNodeDebug(_DataNode):
    """Wrapper class around Tensor, implementing all of the DataNode attributes."""
    def __init__(self, data, name, device, source):
        super().__init__(name, device, source)
        self._data = data

    def __str__(self):
        indent = ' ' * 4
        return f'DataNodeDebug(\n{indent}name="{self.name}",\n{indent}data=' \
            + f'{_tensors._tensorlist_to_string(self._data, indent + " " * 5)})'

    __repr__ = __str__

    def gpu(self):
        if self.device == 'gpu':
            return self
        return DataNodeDebug(self._data._as_gpu(), self.name, 'gpu',
                             self.source)

    def get(self):
        return self._data

    def shape(self):
        return self._data.shape()

    @staticmethod
    def _arithm_op(*inputs, name=None):
        return _PipelineDebug.current()._wrap_op_call(
            _ops.ArithmeticGenericOp,
            DataNodeDebug._aritm_op_name,
            *inputs,
            name=name)

    def __add__(self, other):
        return self._arithm_op(self, other, name='add')

    def __radd__(self, other):
        return self._arithm_op(other, self, name='add')

    def __sub__(self, other):
        return self._arithm_op(self, other, name='sub')

    def __rsub__(self, other):
        return self._arithm_op(other, self, name='sub')

    def __mul__(self, other):
        return self._arithm_op(self, other, name='mul')

    def __rmul__(self, other):
        return self._arithm_op(other, self, name='mul')

    def __pow__(self, other):
        return self._arithm_op(self, other, name='pow')

    def __rpow__(self, other):
        return self._arithm_op(other, self, name='pow')

    def __truediv__(self, other):
        return self._arithm_op(self, other, name='fdiv')

    def __rtruediv__(self, other):
        return self._arithm_op(other, self, name='fdiv')

    def __floordiv__(self, other):
        return self._arithm_op(self, other, name='div')

    def __rfloordiv__(self, other):
        return self._arithm_op(other, self, name='div')

    def __neg__(self):
        return self._arithm_op(self, name='minus')

    def __eq__(self, other):
        return self._arithm_op(self, other, name='eq')

    def __ne__(self, other):
        return self._arithm_op(self, other, name='neq')

    def __lt__(self, other):
        return self._arithm_op(self, other, name='lt')

    def __le__(self, other):
        return self._arithm_op(self, other, name='leq')

    def __gt__(self, other):
        return self._arithm_op(self, other, name='gt')

    def __ge__(self, other):
        return self._arithm_op(self, other, name='geq')

    def __and__(self, other):
        return self._arithm_op(self, other, name='bitand')

    def __rand__(self, other):
        return self._arithm_op(other, self, name='bitand')

    def __or__(self, other):
        return self._arithm_op(self, other, name='bitor')

    def __ror__(self, other):
        return self._arithm_op(other, self, name='bitor')

    def __xor__(self, other):
        return self._arithm_op(self, other, name='bitxor')

    def __rxor__(self, other):
        return self._arithm_op(other, self, name='bitxor')

    _aritm_op_name = _to_snake_case(_ops.ArithmeticGenericOp.__name__)