Similar to GetValueIterator above, but expands CompositeTensor and TypeSpec.
| 561 | |
| 562 | // Similar to GetValueIterator above, but expands CompositeTensor and TypeSpec. |
| 563 | ValueIteratorPtr GetValueIteratorForComposite(PyObject* nested) { |
| 564 | if (IsCompositeTensor(nested)) { |
| 565 | Safe_PyObjectPtr spec(PyObject_GetAttrString(nested, "_type_spec")); |
| 566 | if (PyErr_Occurred() || !spec) { |
| 567 | return absl::make_unique<ErrorValueIterator>(); |
| 568 | } |
| 569 | |
| 570 | static char to_components[] = "_to_components"; |
| 571 | static char argspec[] = "(O)"; |
| 572 | Safe_PyObjectPtr components( |
| 573 | PyObject_CallMethod(spec.get(), to_components, argspec, nested)); |
| 574 | if (PyErr_Occurred() || components == nullptr) { |
| 575 | return absl::make_unique<ErrorValueIterator>(); |
| 576 | } |
| 577 | return absl::make_unique<SingleValueIterator>(components.get()); |
| 578 | } |
| 579 | |
| 580 | if (IsTypeSpec(nested)) { |
| 581 | Safe_PyObjectPtr specs(PyObject_GetAttrString(nested, "_component_specs")); |
| 582 | if (PyErr_Occurred() || specs == nullptr) { |
| 583 | return absl::make_unique<ErrorValueIterator>(); |
| 584 | } |
| 585 | return absl::make_unique<SingleValueIterator>(specs.get()); |
| 586 | } |
| 587 | |
| 588 | return GetValueIterator(nested); |
| 589 | } |
| 590 | |
| 591 | bool FlattenHelper( |
| 592 | PyObject* nested, PyObject* list, |
nothing calls this directly
no test coverage detected