1 /**
2 * Copyright 2020-2021 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "minddata/dataset/core/tensor_row.h"
18
19 #include <utility>
20
21 namespace mindspore {
22 namespace dataset {
23
TensorRow()24 TensorRow::TensorRow() noexcept : id_(kDefaultRowId), path_({}), tensor_row_flag_(kFlagNone) {}
25
TensorRow(size_type n,const TensorRow::value_type & t)26 TensorRow::TensorRow(size_type n, const TensorRow::value_type &t) noexcept
27 : id_(kDefaultRowId), path_({}), row_(n, t), tensor_row_flag_(kFlagNone) {}
28
TensorRow(const TensorRow::vector_type & v)29 TensorRow::TensorRow(const TensorRow::vector_type &v)
30 : id_(kDefaultRowId), path_({}), row_(v), tensor_row_flag_(kFlagNone) {}
31
TensorRow(row_id_type id,const std::initializer_list<value_type> & lst)32 TensorRow::TensorRow(row_id_type id, const std::initializer_list<value_type> &lst)
33 : id_(id), path_({}), row_(lst), tensor_row_flag_(kFlagNone) {}
34
TensorRow(const TensorRow & tr)35 TensorRow::TensorRow(const TensorRow &tr)
36 : id_(tr.id_), path_(tr.path_), row_(tr.row_), tensor_row_flag_(tr.tensor_row_flag_) {}
37
TensorRow(TensorRow::TensorRowFlags flag)38 TensorRow::TensorRow(TensorRow::TensorRowFlags flag) : id_(kDefaultRowId), path_({}), tensor_row_flag_(flag) {}
39
operator =(const TensorRow & tr)40 TensorRow &TensorRow::operator=(const TensorRow &tr) {
41 if (this == &tr) {
42 return *this;
43 }
44 row_ = tr.row_;
45 id_ = tr.id_;
46 path_ = tr.path_;
47 tensor_row_flag_ = tr.tensor_row_flag_;
48 return *this;
49 }
50
operator =(const std::initializer_list<TensorRow::value_type> & lst)51 TensorRow &TensorRow::operator=(const std::initializer_list<TensorRow::value_type> &lst) {
52 row_ = lst;
53 tensor_row_flag_ = kFlagNone;
54 return *this;
55 }
56
TensorRow(TensorRow::vector_type && v)57 TensorRow::TensorRow(TensorRow::vector_type &&v) noexcept
58 : id_(kDefaultRowId), path_({}), row_(std::move(v)), tensor_row_flag_(kFlagNone) {}
59
TensorRow(row_id_type id,std::initializer_list<value_type> && lst)60 TensorRow::TensorRow(row_id_type id, std::initializer_list<value_type> &&lst) noexcept
61 : id_(id), path_({}), row_(std::move(lst)), tensor_row_flag_(kFlagNone) {}
62
TensorRow(TensorRow && tr)63 TensorRow::TensorRow(TensorRow &&tr) noexcept {
64 id_ = tr.id_;
65 path_ = std::move(tr.path_);
66 row_ = std::move(tr.row_);
67 tensor_row_flag_ = tr.tensor_row_flag_;
68 }
69
operator =(TensorRow && tr)70 TensorRow &TensorRow::operator=(TensorRow &&tr) noexcept {
71 if (this == &tr) {
72 return *this;
73 }
74 row_ = std::move(tr.row_);
75 id_ = tr.id_;
76 tr.id_ = kDefaultRowId;
77 path_ = std::move(tr.path_);
78 tensor_row_flag_ = tr.tensor_row_flag_;
79 return *this;
80 }
81
operator =(std::initializer_list<TensorRow::value_type> && lst)82 TensorRow &TensorRow::operator=(std::initializer_list<TensorRow::value_type> &&lst) noexcept {
83 row_ = std::move(lst);
84 tensor_row_flag_ = kFlagNone;
85 return *this;
86 }
87
ValidateTensorRow(const TensorRow & input,const DataType & data_type)88 Status TensorRow::ValidateTensorRow(const TensorRow &input, const DataType &data_type) {
89 if (data_type == DataType::DE_UNKNOWN) {
90 RETURN_STATUS_UNEXPECTED("ConvertFromTensorRow: Data type was not recognized.");
91 }
92 if (data_type == DataType::DE_STRING) {
93 RETURN_STATUS_UNEXPECTED("ConvertFromTensorRow: Data type string is not supported.");
94 }
95 if (input.size() != 1) {
96 RETURN_STATUS_UNEXPECTED("ConvertFromTensorRow: The input TensorRow must have exactly one tensor.");
97 }
98 return Status::OK();
99 }
100
101 } // namespace dataset
102 } // namespace mindspore
103