提交 cb1d1f16 编写于 作者: Y Yi Wang

Add unit test

上级 642d3c46
/*
Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "paddle/framework/eigen.h"
#include <gtest/gtest.h>
#include "paddle/framework/tensor.h"
TEST(Eigen, Tensor) {
using paddle::platform::Tensor;
using paddle::platform::EigenTensor;
using paddle::platform::make_ddim;
Tensor t;
float* p = t.mutable_data<float>(make_ddim({1, 2, 3}), CPUPlace());
for (int i = 0; i < 1 * 2 * 3; i++) {
p[i] = static_cast<float>(i);
}
EigenTensor::Type et = EigenTensor::From(t);
// TODO: check the content of et.
}
TEST(Eigen, Vector) {}
TEST(Eigen, Matrix) {}
......@@ -20,7 +20,6 @@ limitations under the License. */
#include <typeindex>
#include "paddle/framework/ddim.h"
#include "paddle/framework/enforce.h"
#include "paddle/framework/tensor_types.h"
#include "paddle/memory/memory.h"
#include "paddle/platform/place.h"
#include "unsupported/Eigen/CXX11/Tensor"
......@@ -35,6 +34,18 @@ struct CastToPyBufferImpl;
namespace framework {
class Tensor {
template <bool less, size_t i, typename... args>
friend struct paddle::pybind::details::CastToPyBufferImpl;
template <typename T, size_t D, typename IndexType = Eigen::DenseIndex>
friend struct EigenTensor;
template <typename T, typename IndexType = Eigen::DenseIndex>
friend struct EigenVector;
template <typename T, typename IndexType = Eigen::DenseIndex>
friend struct EigenMatrix;
public:
Tensor() : offset_(0) {}
......@@ -191,8 +202,6 @@ class Tensor {
std::shared_ptr<Placeholder> holder_; // holds the memory block if allocated.
DDim dims_;
size_t offset_; // marks the begin of tensor data area.
template <bool less, size_t i, typename... args>
friend struct paddle::pybind::details::CastToPyBufferImpl;
};
} // namespace framework
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册