]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/blob - src/caffeine/test/test_blob.cpp
minor updates
[jacinto-ai/caffe-jacinto.git] / src / caffeine / test / test_blob.cpp
1 #include <cstring>
2 #include <cuda_runtime.h>
4 #include "gtest/gtest.h"
5 #include "caffeine/common.hpp"
6 #include "caffeine/blob.hpp"
7 #include "caffeine/filler.hpp"
9 #include "caffeine/test/test_caffeine_main.hpp"
11 namespace caffeine {
12   
13 template <typename Dtype>
14 class BlobSimpleTest : public ::testing::Test {
15  protected:
16   BlobSimpleTest()
17       : blob_(new Blob<Dtype>()),
18         blob_preshaped_(new Blob<Dtype>(2, 3, 4, 5)) {};
19   virtual ~BlobSimpleTest() { delete blob_; delete blob_preshaped_; }
20   Blob<Dtype>* const blob_;
21   Blob<Dtype>* const blob_preshaped_;
22 };
24 typedef ::testing::Types<float, double> Dtypes;
25 TYPED_TEST_CASE(BlobSimpleTest, Dtypes);
27 TYPED_TEST(BlobSimpleTest, TestInitialization) {
28   EXPECT_TRUE(this->blob_);
29   EXPECT_TRUE(this->blob_preshaped_);
30   EXPECT_EQ(this->blob_preshaped_->num(), 2);
31   EXPECT_EQ(this->blob_preshaped_->channels(), 3);
32   EXPECT_EQ(this->blob_preshaped_->height(), 4);
33   EXPECT_EQ(this->blob_preshaped_->width(), 5);
34   EXPECT_EQ(this->blob_preshaped_->count(), 120);
35   EXPECT_EQ(this->blob_->num(), 0);
36   EXPECT_EQ(this->blob_->channels(), 0);
37   EXPECT_EQ(this->blob_->height(), 0);
38   EXPECT_EQ(this->blob_->width(), 0);
39   EXPECT_EQ(this->blob_->count(), 0);
40 }
42 TYPED_TEST(BlobSimpleTest, TestPointers) {
43   EXPECT_TRUE(this->blob_preshaped_->gpu_data());
44   EXPECT_TRUE(this->blob_preshaped_->cpu_data());
45   EXPECT_TRUE(this->blob_preshaped_->mutable_gpu_data());
46   EXPECT_TRUE(this->blob_preshaped_->mutable_cpu_data());
47 }
49 TYPED_TEST(BlobSimpleTest, TestReshape) {
50   this->blob_->Reshape(2, 3, 4, 5);
51   EXPECT_EQ(this->blob_->num(), 2);
52   EXPECT_EQ(this->blob_->channels(), 3);
53   EXPECT_EQ(this->blob_->height(), 4);
54   EXPECT_EQ(this->blob_->width(), 5);
55   EXPECT_EQ(this->blob_->count(), 120);
56 }
58 TYPED_TEST(BlobSimpleTest, TestCopyConstructor) {
59   Blob<TypeParam> source(2, 3, 4, 5);
60   FillerParameter filler_param;
61   UniformFiller<TypeParam> filler(filler_param);
62   filler.Fill(&source);
63   Blob<TypeParam> target(source);
64   const TypeParam* source_data = source.cpu_data();
65   const TypeParam* target_data = target.cpu_data();
66   EXPECT_EQ(target.num(), source.num());
67   EXPECT_EQ(target.channels(), source.channels());
68   EXPECT_EQ(target.height(), source.height());
69   EXPECT_EQ(target.width(), source.width());
70   EXPECT_EQ(target.count(), source.count());
71   for (int i = 0; i < source.count(); ++i) {
72     EXPECT_EQ(source_data[i], target_data[i]);
73   }
74 }
76 }