| 1785 | } |
| 1786 | |
| 1787 | bool IsAllocatableTransientArray(const Model& model, const string& array_name) { |
| 1788 | // Optional array is not transient |
| 1789 | if (model.IsOptionalArray(array_name)) return false; |
| 1790 | // The model's input and output arrays are externally allocated. |
| 1791 | // They are not transient arrays. |
| 1792 | if (IsInputArray(model, array_name) || IsOutputArray(model, array_name)) { |
| 1793 | return false; |
| 1794 | } |
| 1795 | const auto& array = &model.GetArray(array_name); |
| 1796 | // An array with a constant buffer isn't a transient array. |
| 1797 | if (!!array->buffer) { |
| 1798 | return false; |
| 1799 | } |
| 1800 | // An array without shape isn't allocatable. |
| 1801 | if (!array->has_shape()) { |
| 1802 | return false; |
| 1803 | } |
| 1804 | |
| 1805 | // The size of string tensors is rarely known ahead of time, so all transient |
| 1806 | // tensors of this type will need to be dynamically allocated. |
| 1807 | if (array->final_data_type == ArrayDataType::kString || |
| 1808 | array->data_type == ArrayDataType::kString) { |
| 1809 | return false; |
| 1810 | } |
| 1811 | |
| 1812 | return true; |
| 1813 | } |
| 1814 | |
| 1815 | string AvailableArrayName(const Model& model, const string& name) { |
| 1816 | string sanitized_name = SanitizeNameForTFNode(name); |
no test coverage detected