SINGA-84 Header Files Rearrange Delete redundant includes of source codes in input_layer folder. Rename src/test/test_shard.cc -> src/test/test_kvfile.cc
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/d452a2fd Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/d452a2fd Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/d452a2fd Branch: refs/heads/master Commit: d452a2fdc0380058a3d1f2e1a0b3220071c80ae2 Parents: e469503 Author: ijingo <[email protected]> Authored: Fri Oct 9 14:41:02 2015 +0800 Committer: ijingo <[email protected]> Committed: Fri Oct 9 14:41:02 2015 +0800 ---------------------------------------------------------------------- Makefile.am | 2 +- src/neuralnet/input_layer/csv_record.cc | 8 -- src/neuralnet/input_layer/image_preprocess.cc | 8 -- src/neuralnet/input_layer/prefetch.cc | 7 -- src/neuralnet/input_layer/proto_record.cc | 8 -- src/neuralnet/input_layer/store_input.cc | 8 -- src/neuralnet/loss_layer/euclidean.cc | 5 -- src/neuralnet/loss_layer/softmax.cc | 4 +- src/neuralnet/neuron_layer/convolution.cc | 1 - src/neuralnet/neuron_layer/dropout.cc | 1 - src/neuralnet/neuron_layer/inner_product.cc | 2 - src/neuralnet/neuron_layer/lrn.cc | 2 - src/neuralnet/neuron_layer/pooling.cc | 2 - src/neuralnet/neuron_layer/rbm.cc | 2 - src/neuralnet/neuron_layer/relu.cc | 2 - src/neuralnet/neuron_layer/sigmoid.cc | 2 - src/neuralnet/neuron_layer/stanh.cc | 2 - src/test/test_kvfile.cc | 86 ++++++++++++++++++++++ src/test/test_shard.cc | 85 --------------------- 19 files changed, 88 insertions(+), 149 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/Makefile.am ---------------------------------------------------------------------- diff --git a/Makefile.am b/Makefile.am index 6419980..2639368 100644 --- a/Makefile.am +++ b/Makefile.am @@ -114,7 +114,7 @@ TEST_SRCS := include/gtest/gtest_main.cc \ src/test/test_msg.cc \ src/test/test_neuralnet.cc \ src/test/test_paramslicer.cc \ - src/test/test_shard.cc \ + src/test/test_kvfile.cc \ src/test/test_store.cc \ src/test/test_proto_record_layer.cc \ src/test/test_csv_record_layer.cc http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/input_layer/csv_record.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/input_layer/csv_record.cc b/src/neuralnet/input_layer/csv_record.cc index 0065a2e..f755de9 100644 --- a/src/neuralnet/input_layer/csv_record.cc +++ b/src/neuralnet/input_layer/csv_record.cc @@ -20,20 +20,12 @@ *************************************************************/ #include "singa/neuralnet/input_layer/csv_record.h" -#include "mshadow/tensor.h" -#include "singa/utils/image_transform.h" #include "singa/utils/tokenizer.h" namespace singa { -using namespace mshadow; -using mshadow::cpu; -using mshadow::Shape4; -using mshadow::Tensor; - using std::string; using std::vector; - void CSVRecordLayer::Setup(const LayerProto& conf, const vector<Layer*>& srclayers) { SingleLabelRecordLayer::Setup(conf, srclayers); http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/input_layer/image_preprocess.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/input_layer/image_preprocess.cc b/src/neuralnet/input_layer/image_preprocess.cc index 87344e1..110605b 100644 --- a/src/neuralnet/input_layer/image_preprocess.cc +++ b/src/neuralnet/input_layer/image_preprocess.cc @@ -20,17 +20,9 @@ *************************************************************/ #include "singa/neuralnet/input_layer/image_preprocess.h" -#include "mshadow/tensor.h" #include "singa/utils/image_transform.h" -#include "singa/utils/tokenizer.h" namespace singa { -using namespace mshadow; -using mshadow::cpu; -using mshadow::Shape4; -using mshadow::Tensor; - -using std::string; using std::vector; void ImagePreprocessLayer::Setup(const LayerProto& conf, http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/input_layer/prefetch.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/input_layer/prefetch.cc b/src/neuralnet/input_layer/prefetch.cc index 9c1d7ee..1348a37 100644 --- a/src/neuralnet/input_layer/prefetch.cc +++ b/src/neuralnet/input_layer/prefetch.cc @@ -20,15 +20,8 @@ *************************************************************/ #include "singa/neuralnet/input_layer/prefetch.h" -#include "mshadow/tensor.h" namespace singa { -using namespace mshadow; -using mshadow::cpu; -using mshadow::Shape4; -using mshadow::Tensor; - -using std::string; using std::vector; PrefetchLayer::~PrefetchLayer() { http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/input_layer/proto_record.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/input_layer/proto_record.cc b/src/neuralnet/input_layer/proto_record.cc index 96da9d5..34457b2 100644 --- a/src/neuralnet/input_layer/proto_record.cc +++ b/src/neuralnet/input_layer/proto_record.cc @@ -20,16 +20,8 @@ *************************************************************/ #include "singa/neuralnet/input_layer/proto_record.h" -#include "mshadow/tensor.h" -#include "singa/utils/image_transform.h" -#include "singa/utils/tokenizer.h" namespace singa { -using namespace mshadow; -using mshadow::cpu; -using mshadow::Shape4; -using mshadow::Tensor; - using std::string; using std::vector; http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/input_layer/store_input.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/input_layer/store_input.cc b/src/neuralnet/input_layer/store_input.cc index fc8af7c..6d040e9 100644 --- a/src/neuralnet/input_layer/store_input.cc +++ b/src/neuralnet/input_layer/store_input.cc @@ -20,16 +20,8 @@ *************************************************************/ #include "singa/neuralnet/input_layer/store_input.h" -#include "mshadow/tensor.h" -#include "singa/utils/image_transform.h" -#include "singa/utils/tokenizer.h" namespace singa { -using namespace mshadow; -using mshadow::cpu; -using mshadow::Shape4; -using mshadow::Tensor; - using std::string; using std::vector; http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/loss_layer/euclidean.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/loss_layer/euclidean.cc b/src/neuralnet/loss_layer/euclidean.cc index a253942..daab15c 100644 --- a/src/neuralnet/loss_layer/euclidean.cc +++ b/src/neuralnet/loss_layer/euclidean.cc @@ -29,14 +29,9 @@ namespace singa { using namespace mshadow; using mshadow::cpu; -using mshadow::Shape; using mshadow::Shape1; -using mshadow::Shape2; -using mshadow::Shape3; -using mshadow::Shape4; using mshadow::Tensor; -using std::string; using std::vector; void EuclideanLossLayer::Setup(const LayerProto& conf, http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/loss_layer/softmax.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/loss_layer/softmax.cc b/src/neuralnet/loss_layer/softmax.cc index 9fdd59b..058462c 100644 --- a/src/neuralnet/loss_layer/softmax.cc +++ b/src/neuralnet/loss_layer/softmax.cc @@ -21,6 +21,7 @@ #include "singa/neuralnet/loss_layer/softmax.h" +#include <algorithm> #include <glog/logging.h> #include "mshadow/tensor.h" @@ -32,11 +33,8 @@ using mshadow::cpu; using mshadow::Shape; using mshadow::Shape1; using mshadow::Shape2; -using mshadow::Shape3; -using mshadow::Shape4; using mshadow::Tensor; -using std::string; using std::vector; void SoftmaxLossLayer::Setup(const LayerProto& proto, http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/neuron_layer/convolution.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/convolution.cc b/src/neuralnet/neuron_layer/convolution.cc index 03ddbbb..fa74dcf 100644 --- a/src/neuralnet/neuron_layer/convolution.cc +++ b/src/neuralnet/neuron_layer/convolution.cc @@ -22,7 +22,6 @@ #include "singa/neuralnet/neuron_layer/convolution.h" #include <glog/logging.h> -#include <algorithm> #include "singa/utils/singleton.h" namespace singa { http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/neuron_layer/dropout.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/dropout.cc b/src/neuralnet/neuron_layer/dropout.cc index 3cb9e5e..59d9bc5 100644 --- a/src/neuralnet/neuron_layer/dropout.cc +++ b/src/neuralnet/neuron_layer/dropout.cc @@ -22,7 +22,6 @@ #include "singa/neuralnet/neuron_layer/dropout.h" #include <glog/logging.h> -#include <algorithm> #include "singa/utils/singleton.h" namespace singa { http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/neuron_layer/inner_product.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/inner_product.cc b/src/neuralnet/neuron_layer/inner_product.cc index 0f7744c..3f38d9c 100644 --- a/src/neuralnet/neuron_layer/inner_product.cc +++ b/src/neuralnet/neuron_layer/inner_product.cc @@ -22,12 +22,10 @@ #include "singa/neuralnet/neuron_layer/inner_product.h" #include <glog/logging.h> -#include <algorithm> #include "singa/utils/singleton.h" namespace singa { -using std::string; using std::vector; InnerProductLayer::~InnerProductLayer() { http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/neuron_layer/lrn.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/lrn.cc b/src/neuralnet/neuron_layer/lrn.cc index 44fa9f3..f1c302f 100644 --- a/src/neuralnet/neuron_layer/lrn.cc +++ b/src/neuralnet/neuron_layer/lrn.cc @@ -22,12 +22,10 @@ #include "singa/neuralnet/neuron_layer/lrn.h" #include <glog/logging.h> -#include <algorithm> #include "singa/utils/singleton.h" namespace singa { -using std::string; using std::vector; void LRNLayer::Setup(const LayerProto& conf, const vector<Layer*>& srclayers) { http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/neuron_layer/pooling.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/pooling.cc b/src/neuralnet/neuron_layer/pooling.cc index 9d634cb..a3c5e6f 100644 --- a/src/neuralnet/neuron_layer/pooling.cc +++ b/src/neuralnet/neuron_layer/pooling.cc @@ -22,12 +22,10 @@ #include "singa/neuralnet/neuron_layer/pooling.h" #include <glog/logging.h> -#include <algorithm> #include "singa/utils/singleton.h" namespace singa { -using std::string; using std::vector; /******************** Implementation for PoolingLayer******************/ http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/neuron_layer/rbm.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/rbm.cc b/src/neuralnet/neuron_layer/rbm.cc index d676b1f..f0b73b3 100644 --- a/src/neuralnet/neuron_layer/rbm.cc +++ b/src/neuralnet/neuron_layer/rbm.cc @@ -22,12 +22,10 @@ #include "singa/neuralnet/neuron_layer/rbm.h" #include <glog/logging.h> -#include <algorithm> #include "singa/utils/singleton.h" namespace singa { -using std::string; using std::vector; /**************** Implementation for RBMLayer********************/ http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/neuron_layer/relu.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/relu.cc b/src/neuralnet/neuron_layer/relu.cc index fa4ea54..247d077 100644 --- a/src/neuralnet/neuron_layer/relu.cc +++ b/src/neuralnet/neuron_layer/relu.cc @@ -22,12 +22,10 @@ #include "singa/neuralnet/neuron_layer/relu.h" #include <glog/logging.h> -#include <algorithm> #include "singa/utils/singleton.h" namespace singa { -using std::string; using std::vector; void ReLULayer::Setup(const LayerProto& conf, http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/neuron_layer/sigmoid.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/sigmoid.cc b/src/neuralnet/neuron_layer/sigmoid.cc index 861140c..3ddefd8 100644 --- a/src/neuralnet/neuron_layer/sigmoid.cc +++ b/src/neuralnet/neuron_layer/sigmoid.cc @@ -22,12 +22,10 @@ #include "singa/neuralnet/neuron_layer/sigmoid.h" #include <glog/logging.h> -#include <algorithm> #include "singa/utils/singleton.h" namespace singa { -using std::string; using std::vector; void SigmoidLayer::Setup(const LayerProto& conf, http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/neuralnet/neuron_layer/stanh.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/neuron_layer/stanh.cc b/src/neuralnet/neuron_layer/stanh.cc index 4347d1e..3036850 100644 --- a/src/neuralnet/neuron_layer/stanh.cc +++ b/src/neuralnet/neuron_layer/stanh.cc @@ -22,12 +22,10 @@ #include "singa/neuralnet/neuron_layer/stanh.h" #include <glog/logging.h> -#include <algorithm> #include "singa/utils/singleton.h" namespace singa { -using std::string; using std::vector; void STanhLayer::Setup(const LayerProto& conf, http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/test/test_kvfile.cc ---------------------------------------------------------------------- diff --git a/src/test/test_kvfile.cc b/src/test/test_kvfile.cc new file mode 100644 index 0000000..9c30734 --- /dev/null +++ b/src/test/test_kvfile.cc @@ -0,0 +1,86 @@ +/************************************************************ +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you 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 <sys/stat.h> + +#include "gtest/gtest.h" +#include "singa/io/kvfile.h" + +std::string key[] = {"firstkey", + "secondkey", + "3key", + "key4", + "key5"}; +std::string tuple[] = {"firsttuple", + "2th-tuple", + "thridtuple", + "tuple4", + "tuple5"}; +namespace singa { +namespace io { +TEST(KVFileTest, CreateKVFile) { + std::string path = "src/test/shard_test"; + mkdir(path.c_str(), 0755); + KVFile shard(path, KVFile::kCreate, 50); + shard.Insert(key[0], tuple[0]); + shard.Insert(key[1], tuple[1]); + shard.Insert(key[2], tuple[2]); + shard.Flush(); +} + +TEST(KVFileTest, AppendKVFile) { + std::string path = "src/test/shard_test"; + KVFile shard(path, KVFile::kAppend, 50); + shard.Insert(key[3], tuple[3]); + shard.Insert(key[4], tuple[4]); + shard.Flush(); +} + +TEST(KVFileTest, CountKVFile) { + std::string path = "src/test/shard_test"; + KVFile shard(path, KVFile::kRead, 50); + int count = shard.Count(); + ASSERT_EQ(5, count); +} + +TEST(KVFileTest, ReadKVFile) { + std::string path = "src/test/shard_test"; + KVFile shard(path, KVFile::kRead, 50); + std::string k, t; + ASSERT_TRUE(shard.Next(&k, &t)); + ASSERT_STREQ(key[0].c_str(), k.c_str()); + ASSERT_STREQ(tuple[0].c_str(), t.c_str()); + ASSERT_TRUE(shard.Next(&k, &t)); + ASSERT_STREQ(key[1].c_str(), k.c_str()); + ASSERT_STREQ(tuple[1].c_str(), t.c_str()); + ASSERT_TRUE(shard.Next(&k, &t)); + ASSERT_TRUE(shard.Next(&k, &t)); + ASSERT_TRUE(shard.Next(&k, &t)); + ASSERT_STREQ(key[4].c_str(), k.c_str()); + ASSERT_STREQ(tuple[4].c_str(), t.c_str()); + ASSERT_FALSE(shard.Next(&k, &t)); + shard.SeekToFirst(); + ASSERT_TRUE(shard.Next(&k, &t)); + ASSERT_STREQ(key[0].c_str(), k.c_str()); + ASSERT_STREQ(tuple[0].c_str(), t.c_str()); +} +} // namespace io +} // namespace singa http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d452a2fd/src/test/test_shard.cc ---------------------------------------------------------------------- diff --git a/src/test/test_shard.cc b/src/test/test_shard.cc deleted file mode 100644 index 9ba898a..0000000 --- a/src/test/test_shard.cc +++ /dev/null @@ -1,85 +0,0 @@ -/************************************************************ -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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 <sys/stat.h> - -#include "gtest/gtest.h" -#include "singa/utils/data_shard.h" - -std::string key[] = {"firstkey", - "secondkey", - "3key", - "key4", - "key5"}; -std::string tuple[] = {"firsttuple", - "2th-tuple", - "thridtuple", - "tuple4", - "tuple5"}; - -using namespace singa; - -TEST(DataShardTest, CreateDataShard) { - std::string path = "src/test/shard_test"; - mkdir(path.c_str(), 0755); - DataShard shard(path, DataShard::kCreate, 50); - shard.Insert(key[0], tuple[0]); - shard.Insert(key[1], tuple[1]); - shard.Insert(key[2], tuple[2]); - shard.Flush(); -} - -TEST(DataShardTest, AppendDataShard) { - std::string path = "src/test/shard_test"; - DataShard shard(path, DataShard::kAppend, 50); - shard.Insert(key[3], tuple[3]); - shard.Insert(key[4], tuple[4]); - shard.Flush(); -} - -TEST(DataShardTest, CountDataShard) { - std::string path = "src/test/shard_test"; - DataShard shard(path, DataShard::kRead, 50); - int count = shard.Count(); - ASSERT_EQ(5, count); -} - -TEST(DataShardTest, ReadDataShard) { - std::string path = "src/test/shard_test"; - DataShard shard(path, DataShard::kRead, 50); - std::string k, t; - ASSERT_TRUE(shard.Next(&k, &t)); - ASSERT_STREQ(key[0].c_str(), k.c_str()); - ASSERT_STREQ(tuple[0].c_str(), t.c_str()); - ASSERT_TRUE(shard.Next(&k, &t)); - ASSERT_STREQ(key[1].c_str(), k.c_str()); - ASSERT_STREQ(tuple[1].c_str(), t.c_str()); - ASSERT_TRUE(shard.Next(&k, &t)); - ASSERT_TRUE(shard.Next(&k, &t)); - ASSERT_TRUE(shard.Next(&k, &t)); - ASSERT_STREQ(key[4].c_str(), k.c_str()); - ASSERT_STREQ(tuple[4].c_str(), t.c_str()); - ASSERT_FALSE(shard.Next(&k, &t)); - shard.SeekToFirst(); - ASSERT_TRUE(shard.Next(&k, &t)); - ASSERT_STREQ(key[0].c_str(), k.c_str()); - ASSERT_STREQ(tuple[0].c_str(), t.c_str()); -}
