SetAttr

Description

Sets the attribute values of an operator.

An operator may have multiple attributes. After an attribute value is set for the first time, the data type of the attribute is fixed. The following data types are supported:

  • Integer: int64_t, uint32_t, or int32_t

    Use SetAttr(const string& name, int64_t attrValue) to set the attribute value, and use GetAttr(const string& name, int32_t& attrValue) or GetAttr(const string& name, uint32_t& attrValue) to obtain the value. Ensure that the integer data is not truncated. It is the same for the types int32_t and uint32_t.

  • List of integers: std::vector<int64_t>, std::vector<int32_t>, std::vector<uint32_t>, or std::initializer_list<int64_t>&&
  • Floating-point number: float
  • List of floating-point numbers: std::vector<float>
  • String: string
  • String list: std::vector<std::string>
  • Bool: bool
  • List of bools: std::vector<bool>
  • Tensor: Tensor
  • List of Tensors: std::vector<Tensor>
  • Arrays of bytes: OpBytes, that it, (vector<uint8_t>) or (const uint8_t* data, size_t size)
  • AttrValue: AttrValue
  • 2D list of integers: std::vector<std::vector<int64_t>>
  • List of DataTypes: std::vector<ge::DataType>
  • DataType: ge::DataType
  • NamedAttrs type: ge::NamedAttrs
  • List of NamedAttrs: std::vector<ge::NamedAttrs>

Prototype

APIs using strings will be deprecated in later versions. Use APIs supporting non-string data instead.

Operator &SetAttr(const std::string &name, int64_t attr_value)

Operator &SetAttr(const std::string &name, int32_t attr_value)

Operator &SetAttr(const std::string &name, uint32_t attr_value)

Operator &SetAttr(const std::string &name, const std::vector<int64_t> &attr_value)

Operator &SetAttr(const std::string &name, const std::vector<int32_t> &attr_value)

Operator &SetAttr(const std::string &name, const std::vector<uint32_t> &attr_value)

Operator &SetAttr(const std::string &name, std::initializer_list<int64_t> &&attr_value)

Operator &SetAttr(const std::string &name, float32_t attr_value)

Operator &SetAttr(const std::string &name, const std::vector<float32_t> &attr_value)

Operator &SetAttr(const std::string &name, AttrValue &&attr_value)

Operator &SetAttr(const std::string &name, const std::string &attr_value)

Operator &SetAttr(const std::string &name, const std::vector<std::string> &attr_value)

Operator &SetAttr(const std::string &name, bool attr_value)

Operator &SetAttr(const std::string &name, const std::vector<bool> &attr_value)

Operator &SetAttr(const std::string &name, const Tensor &attr_value)

Operator &SetAttr(const std::string &name, const std::vector<Tensor> &attr_value)

Operator &SetAttr(const std::string &name, const OpBytes &attr_value)

Operator &SetAttr(const std::string &name, const std::vector<std::vector<int64_t>> &attr_value)

Operator &SetAttr(const std::string &name, const std::vector<ge::DataType> &attr_value)

Operator &SetAttr(const std::string &name, const ge::DataType &attr_value)

Operator &SetAttr(const std::string &name, const ge::NamedAttrs &attr_value)

Operator &SetAttr(const std::string &name, const std::vector<ge::NamedAttrs> &attr_value)

Operator &SetAttr(const char_t *name, int64_t attr_value)

Operator &SetAttr(const char_t *name, int32_t attr_value)

Operator &SetAttr(const char_t *name, uint32_t attr_value)

Operator &SetAttr(const char_t *name, const std::vector<int64_t> &attr_value)

Operator &SetAttr(const char_t *name, const std::vector<int32_t> &attr_value)

Operator &SetAttr(const char_t *name, const std::vector<uint32_t> &attr_value)

Operator &SetAttr(const char_t *name, std::initializer_list<int64_t> &&attr_value)

Operator &SetAttr(const char_t *name, float32_t attr_value)

Operator &SetAttr(const char_t *name, const std::vector<float32_t> &attr_value)

Operator &SetAttr(const char_t *name, AttrValue &&attr_value)

Operator &SetAttr(const char_t *name, const char_t *attr_value)

Operator &SetAttr(const char_t *name, const AscendString &attr_value)

Operator &SetAttr(const char_t *name, const std::vector<AscendString> &attr_values)

Operator &SetAttr(const char_t *name, bool attr_value)

Operator &SetAttr(const char_t *name, const std::vector<bool> &attr_value)

Operator &SetAttr(const char_t *name, const Tensor &attr_value)

Operator &SetAttr(const char_t *name, const std::vector<Tensor> &attr_value)

Operator &SetAttr(const char_t *name, const OpBytes &attr_value)

Operator &SetAttr(const char_t *name, const std::vector<std::vector<int64_t>> &attr_value)

Operator &SetAttr(const char_t *name, const std::vector<ge::DataType> &attr_value)

Operator &SetAttr(const char_t *name, const ge::DataType &attr_value)

Operator &SetAttr(const char_t *name, const ge::NamedAttrs &attr_value)

Operator &SetAttr(const char_t *name, const std::vector<ge::NamedAttrs> &attr_value)

Parameters

Parameter

Input/Output

Description

name

Input

Attribute name.

attr_value

Input

Attribute value of type int64_t.

attr_value

Input

Attribute value of type int32_t.

attr_value

Input

Attribute value of type uint32_t.

attr_value

Input

Attribute value of type std::vector<int64_t>.

attr_value

Input

Attribute value of type std::vector<int32_t>.

attr_value

Input

Attribute value of type std::vector<uint32_t>.

attr_value

Input

Attribute value of type std::initializer_list<int64_t>&&.

attr_value

Input

Attribute value of type float.

attr_value

Input

Attribute value of type std::vector<float>.

attr_value

Input

Attribute value of type bool.

attr_value

Input

Attribute value of type std::vector<bool>.

attr_value

Input

Attribute value of type AttrValue.

attr_value

Input

Attribute value of type string.

attr_value

Input

Attribute value of type std::vector<string>.

attr_value

Input

Attribute value of type tensor.

attr_value

Input

Attribute value of type std::vector<Tensor>.

attr_value

Input

Attribute value of type OpBytes, or std::vector<uint8_t>.

data

Input

Attribute value of type Bytes, specifying the start address of a byte stream.

size

Input

Attribute value of type Bytes, specifying the length of a byte stream.

attr_value

Input

Attribute value to be set of the quantized data type.

attr_value

Input

Attribute value of type std::vector<std::vector<int64_t>>.

attr_value

Input

Attribute value of type std::vector<ge::DataType>.

attr_value

Input

Attribute value of type DataType.

attr_value

Input

Attribute value of type NamedAttrs.

attr_value

Input

Attribute value of type std::vector<ge::NamedAttrs>.

Returns

Operator object

Exception Handling

None

Restrictions

None