Builds a constant op with the specified attribute `value`. The result op's type is deduced from `value`; if `value` is of scalar type, wraps it up with a tensor type of empty shape.
| 847 | // op's type is deduced from `value`; if `value` is of scalar type, |
| 848 | // wraps it up with a tensor type of empty shape. |
| 849 | void ConstOp::build(Builder *builder, OperationState &result, Attribute value) { |
| 850 | ShapedType type; |
| 851 | if (auto elemAttr = value.dyn_cast<ElementsAttr>()) { |
| 852 | type = elemAttr.getType(); |
| 853 | } else if (value.isa<BoolAttr>() || value.isa<FloatAttr>() || |
| 854 | value.isa<IntegerAttr>()) { |
| 855 | // All TensorFlow types must be tensor types. In the build() method, |
| 856 | // we want to provide more flexibility by allowing attributes of scalar |
| 857 | // types. But we need to wrap it up with ElementsAttr to construct |
| 858 | // valid TensorFlow constants. |
| 859 | type = RankedTensorType::get(/*shape=*/{}, value.getType()); |
| 860 | value = DenseElementsAttr::get(type, value); |
| 861 | } |
| 862 | // TODO: support other TensorFlow specific types. |
| 863 | assert(type && "unsupported attribute type for building tf.Const"); |
| 864 | result.types.push_back(type); |
| 865 | result.addAttribute("value", value); |
| 866 | } |
| 867 | |
| 868 | void ConstOp::build(Builder *builder, OperationState &result, Type type, |
| 869 | Attribute value) { |
nothing calls this directly
no test coverage detected