• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 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 "include/ms_tensor.h"
18 #include "src/tensor.h"
19 
20 namespace mindspore {
21 namespace tensor {
CreateTensor(const std::string & name,TypeId type,const std::vector<int> & shape,const void * data,size_t data_len)22 tensor::MSTensor *tensor::MSTensor::CreateTensor(const std::string &name, TypeId type, const std::vector<int> &shape,
23                                                  const void *data, size_t data_len) {
24   auto tensor = new (std::nothrow) lite::Tensor();
25   if (tensor == nullptr) {
26     MS_LOG(ERROR) << "Failed to allocate tensor.";
27     return nullptr;
28   }
29   tensor->set_data(const_cast<void *>(data));
30   tensor->set_shape(shape);
31   tensor->set_tensor_name(name);
32   tensor->set_data_type(type);
33   return tensor;
34 }
35 }  // namespace tensor
36 }  // namespace mindspore
37