Commit 8311dc45 authored by Mircea Cimpoi's avatar Mircea Cimpoi Committed by Facebook GitHub Bot
Browse files

Allow multiple separators in transform string

Summary:
Pull Request resolved: https://github.com/facebookresearch/d2go/pull/464

Allow multiple and nested transforms in to be parsed.

Reviewed By: wat3rBro

Differential Revision: D42997149

fbshipit-source-id: 317a27351342f44facab947ca0cba74fbc6c94bb
parent 0753f8b4
...@@ -85,13 +85,14 @@ _TRANSFORM_REPR_SEPARATOR = "::" ...@@ -85,13 +85,14 @@ _TRANSFORM_REPR_SEPARATOR = "::"
def parse_tfm_gen_repr(tfm_gen_repr: str) -> Tuple[str, Optional[str]]: def parse_tfm_gen_repr(tfm_gen_repr: str) -> Tuple[str, Optional[str]]:
if tfm_gen_repr.count(_TRANSFORM_REPR_SEPARATOR) == 0: if tfm_gen_repr.count(_TRANSFORM_REPR_SEPARATOR) == 0:
return tfm_gen_repr, None return tfm_gen_repr, None
elif tfm_gen_repr.count(_TRANSFORM_REPR_SEPARATOR) == 1:
return tfm_gen_repr.split(_TRANSFORM_REPR_SEPARATOR)
else: else:
raise ValueError( # Split only after first delimiter, to allow for:
"Can't to parse transform repr name because of multiple separator found." # - nested transforms, e.g:
" Offending name: {}" # 'SomeTransformOp::{"args": ["SubTransform2Op::{\\"param1\\": 0, \\"param2\\": false}", "SubTransform2Op::{\\"param1\\": 0.8}"], "other_args": 2}'
) # - list of transforms, e.g.:
# ["SubTransform2Op::{\\"param1\\": 0, \\"param2\\": false}", "SubTransform2Op::{\\"param1\\": 0.8}"]
# TODO(T144470024): Support recursive parsing. For now, it's user responsibility to ensure the nested transforms are parsed correctly.
return tfm_gen_repr.split(_TRANSFORM_REPR_SEPARATOR, 1)
def build_transform_gen( def build_transform_gen(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment