Tensor Descriptor class * * Structure that contains all the required meta-data to represent a tensor */
| 502 | * Structure that contains all the required meta-data to represent a tensor |
| 503 | */ |
| 504 | class TensorDescriptor |
| 505 | { |
| 506 | public: |
| 507 | /** Constructor |
| 508 | * |
| 509 | * @param[in] shape Shape of the tensor |
| 510 | * @param[in] data_type Data type of the tensor |
| 511 | */ |
| 512 | TensorDescriptor(const std::vector<int32_t> &shape, DataType data_type) : _shape(shape), _data_type(data_type) |
| 513 | { |
| 514 | _cdesc.ndims = _shape.size(); |
| 515 | _cdesc.shape = _shape.data(); |
| 516 | _cdesc.data_type = detail::as_cenum<AclDataType>(_data_type); |
| 517 | _cdesc.strides = nullptr; |
| 518 | _cdesc.boffset = 0; |
| 519 | } |
| 520 | /** Constructor |
| 521 | * |
| 522 | * @param[in] desc C-type descriptor |
| 523 | */ |
| 524 | explicit TensorDescriptor(const AclTensorDescriptor &desc) |
| 525 | { |
| 526 | _cdesc = desc; |
| 527 | _data_type = detail::as_enum<DataType>(desc.data_type); |
| 528 | _shape.reserve(desc.ndims); |
| 529 | for (int32_t d = 0; d < desc.ndims; ++d) |
| 530 | { |
| 531 | _shape.emplace_back(desc.shape[d]); |
| 532 | } |
| 533 | } |
| 534 | /** Get underlying C tensor descriptor |
| 535 | * |
| 536 | * @return Underlying structure |
| 537 | */ |
| 538 | const AclTensorDescriptor *get() const |
| 539 | { |
| 540 | return &_cdesc; |
| 541 | } |
| 542 | /** Operator to compare two TensorDescriptor |
| 543 | * |
| 544 | * @param[in] other The instance to compare against |
| 545 | * |
| 546 | * @return True if two instances have the same shape and data type |
| 547 | */ |
| 548 | bool operator==(const TensorDescriptor &other) |
| 549 | { |
| 550 | bool is_same = true; |
| 551 | |
| 552 | is_same &= _data_type == other._data_type; |
| 553 | is_same &= _shape.size() == other._shape.size(); |
| 554 | |
| 555 | if (is_same) |
| 556 | { |
| 557 | for (uint32_t d = 0; d < _shape.size(); ++d) |
| 558 | { |
| 559 | is_same &= _shape[d] == other._shape[d]; |
| 560 | } |
| 561 | } |
no outgoing calls
no test coverage detected