MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / parse_input_and_attr

Method parse_input_and_attr

paddle/phi/api/generator/api_base.py:337–441  ·  view source on GitHub ↗
(self, api_name, args_config, optional_vars=[])

Source from the content-addressed store, hash-verified

335 )
336
337 def parse_input_and_attr(self, api_name, args_config, optional_vars=[]):
338 inputs = {'names': [], 'input_info': {}}
339 attrs = {'names': [], 'attr_info': {}}
340 args_str = args_config.strip()
341 assert args_str.startswith('(') and args_str.endswith(')'), (
342 f"Args declaration should start with '(' and end with ')', please check the args of {api_name} in yaml."
343 )
344 args_str = args_str[1:-1]
345 pattern = re.compile(r',(?![^{]*\})') # support int[] a={1,3}
346 args_list = re.split(pattern, args_str.strip())
347 args_list = [x.strip() for x in args_list]
348 input_types_map = {
349 'Tensor': 'const Tensor&',
350 'Tensor[]': 'const std::vector<Tensor>&',
351 }
352 attr_types_map = {
353 'IntArray': 'const IntArray&',
354 'Scalar': 'const Scalar&',
355 'Scalar(int)': 'const Scalar&',
356 'Scalar(int64_t)': 'const Scalar&',
357 'Scalar(float)': 'const Scalar&',
358 'Scalar(double)': 'const Scalar&',
359 'Scalar[]': 'const std::vector<phi::Scalar>&',
360 'int': 'int',
361 'int32_t': 'int32_t',
362 'int64_t': 'int64_t',
363 'long': 'long',
364 'size_t': 'size_t',
365 'float': 'float',
366 'float[]': 'const std::vector<float>&',
367 'double': 'double',
368 'double[]': 'const std::vector<double>&',
369 'bool': 'bool',
370 'bool[]': 'const std::vector<bool>&',
371 'str': 'const std::string&',
372 'str[]': 'const std::vector<std::string>&',
373 'Place': 'const Place&',
374 'DataLayout': 'DataLayout',
375 'DataType': 'DataType',
376 'int64_t[]': 'const std::vector<int64_t>&',
377 'int[]': 'const std::vector<int>&',
378 }
379 optional_types_trans = {
380 'Tensor': 'const paddle::optional<Tensor>&',
381 'Tensor[]': 'const paddle::optional<std::vector<Tensor>>&',
382 'int': 'paddle::optional<int>',
383 'int32_t': 'paddle::optional<int32_t>',
384 'int64_t': 'paddle::optional<int64_t>',
385 'float': 'paddle::optional<float>',
386 'double': 'paddle::optional<double>',
387 'bool': 'paddle::optional<bool>',
388 'Place': 'paddle::optional<const Place&>',
389 'DataLayout': 'paddle::optional<DataLayout>',
390 'DataType': 'paddle::optional<DataType>',
391 }
392
393 for item in args_list:
394 item = item.strip()

Callers 2

parse_argsMethod · 0.95
parse_forward_configMethod · 0.45

Calls 4

compileMethod · 0.45
splitMethod · 0.45
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected