From b05a8dd02daad728f6d1262435dbaa7fe6a63285 Mon Sep 17 00:00:00 2001 From: superjom Date: Mon, 25 Dec 2017 10:31:00 +0800 Subject: [PATCH] code clean --- CMakeLists.txt | 1 - tests.sh | 13 --- visualdl/logic/im.cc | 6 ++ visualdl/logic/pybind.cc | 5 +- visualdl/logic/sdk.cc | 97 ++++++++----------- visualdl/logic/sdk.h | 37 ------- visualdl/python/CMakeLists.txt | 2 +- .../{test_summary.py => test_storage.py} | 8 +- visualdl/storage/CMakeLists.txt | 2 +- visualdl/storage/entry.cc | 2 +- visualdl/storage/entry.h | 2 +- 11 files changed, 61 insertions(+), 114 deletions(-) delete mode 100644 tests.sh rename visualdl/python/{test_summary.py => test_storage.py} (68%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 025f6989..590abdd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,4 +49,3 @@ enable_testing () add_custom_target(test_init COMMAND $CMAKE_BINARY_DIR) add_test(NAME vstest COMMAND ./vl_test) -set_target_properties(vl_test PROPERTIES DEPENDS test_init) diff --git a/tests.sh b/tests.sh deleted file mode 100644 index 7e51cb30..00000000 --- a/tests.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -ex - -sudo pip install numpy -#sudo apt-get install --only-upgrade cmake -y -mkdir -p build -cd build -cmake .. -make -make test - -#if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./travis/run_on_pull_requests; fi -#if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./travis/run_on_non_pull_requests; fi diff --git a/visualdl/logic/im.cc b/visualdl/logic/im.cc index f8fe1924..a2ec1f22 100644 --- a/visualdl/logic/im.cc +++ b/visualdl/logic/im.cc @@ -32,5 +32,11 @@ void SimpleWriteSyncGuard::Sync() { template class SimpleWriteSyncGuard; template class SimpleWriteSyncGuard; template class SimpleWriteSyncGuard; +template class SimpleWriteSyncGuard>; +template class SimpleWriteSyncGuard>; +template class SimpleWriteSyncGuard>; +template class SimpleWriteSyncGuard>; +template class SimpleWriteSyncGuard>; +template class SimpleWriteSyncGuard>; } // namespace visualdl diff --git a/visualdl/logic/pybind.cc b/visualdl/logic/pybind.cc index 7503ed74..de82b415 100644 --- a/visualdl/logic/pybind.cc +++ b/visualdl/logic/pybind.cc @@ -15,6 +15,7 @@ PYBIND11_PLUGIN(core) { py::class_>(m, "ScalarReader__" #T) \ .def("records", &cp::ScalarReader::records) \ .def("timestamps", &cp::ScalarReader::timestamps) \ + .def("ids", &cp::ScalarReader::ids) \ .def("caption", &cp::ScalarReader::caption); ADD_SCALAR(int); ADD_SCALAR(float); @@ -57,9 +58,7 @@ PYBIND11_PLUGIN(core) { py::class_(m, "Writer") .def("__init__", - [](vs::Writer& instance, - const std::string& dir, - int sync_cycle) { + [](vs::Writer& instance, const std::string& dir, int sync_cycle) { new (&instance) vs::Writer(dir); instance.storage().meta.cycle = sync_cycle; }) diff --git a/visualdl/logic/sdk.cc b/visualdl/logic/sdk.cc index 7f94ceef..62c46ea6 100644 --- a/visualdl/logic/sdk.cc +++ b/visualdl/logic/sdk.cc @@ -4,61 +4,48 @@ namespace visualdl { namespace components { -// template -// void components::Scalar::AddRecord(int id, const std::vector &values) { -// // add record data -// auto record = tablet_.AddRecord(); -// auto entry = record.AddData(); -// for (auto v : values) { -// entry.Add(v); -// } -// // set record id -// record.SetId(id); -// // set record timestamp -// record.SetTimeStamp(time(NULL)); -// } - -// template -// std::vector ScalarReader::records() const { -// std::vector res; -// for (int i = 0; i < reader_.total_records(); i++) { -// res.push_back(reader_.record(i).data(0)); -// } -// return res; -// } - -// template -// std::vector ScalarReader::ids() const { -// std::vector res; -// for (int i = 0; i < reader_.total_records(); i++) { -// res.push_back(reader_.record(i).id()); -// } -// return res; -// } - -// template -// std::vector ScalarReader::timestamps() const { -// std::vector res; -// for (int i = 0; i < reader_.total_records(); i++) { -// res.push_back(reader_.record(i).timestamp()); -// } -// return res; -// } - -// template -// std::vector ScalarReader::captions() const { -// return reader_.captions(); -// } - -// template -// size_t ScalarReader::size() const { -// return reader_.total_records(); -// } - -// template class Scalar; -// template class Scalar; -// template class Scalar; -// template class Scalar; +template +std::vector ScalarReader::records() const { + std::vector res; + for (int i = 0; i < reader_.total_records(); i++) { + res.push_back(reader_.record(i).data(0).Get()); + } + return res; +} + +template +std::vector ScalarReader::ids() const { + std::vector res; + for (int i = 0; i < reader_.total_records(); i++) { + res.push_back(reader_.record(i).id()); + } + return res; +} + +template +std::vector ScalarReader::timestamps() const { + std::vector res; + for (int i = 0; i < reader_.total_records(); i++) { + res.push_back(reader_.record(i).timestamp()); + } + return res; +} + +template +std::string ScalarReader::caption() const { + CHECK(!reader_.captions().empty()) << "no caption"; + return reader_.captions().front(); +} + +template +size_t ScalarReader::size() const { + return reader_.total_records(); +} + +template class ScalarReader; +template class ScalarReader; +template class ScalarReader; +template class ScalarReader; } // namespace components diff --git a/visualdl/logic/sdk.h b/visualdl/logic/sdk.h index 0c7525d8..96ee4321 100644 --- a/visualdl/logic/sdk.h +++ b/visualdl/logic/sdk.h @@ -91,43 +91,6 @@ private: TabletReader reader_; }; -template -std::vector ScalarReader::records() const { - std::vector res; - for (int i = 0; i < reader_.total_records(); i++) { - res.push_back(reader_.record(i).data(0).Get()); - } - return res; -} - -template -std::vector ScalarReader::ids() const { - std::vector res; - for (int i = 0; i < reader_.total_records(); i++) { - res.push_back(reader_.record(i).id()); - } - return res; -} - -template -std::vector ScalarReader::timestamps() const { - std::vector res; - for (int i = 0; i < reader_.total_records(); i++) { - res.push_back(reader_.record(i).timestamp()); - } - return res; -} - -template -std::string ScalarReader::caption() const { - CHECK(!reader_.captions().empty()) << "no caption"; - return reader_.captions().front(); -} - -template -size_t ScalarReader::size() const { - return reader_.total_records(); -} } // namespace components } // namespace visualdl diff --git a/visualdl/python/CMakeLists.txt b/visualdl/python/CMakeLists.txt index def51de9..2f37afb5 100644 --- a/visualdl/python/CMakeLists.txt +++ b/visualdl/python/CMakeLists.txt @@ -10,4 +10,4 @@ function(py_test TARGET_NAME) ) endfunction() -py_test(test_summary SRCS test_summary.py) +py_test(test_summary SRCS test_storage.py) diff --git a/visualdl/python/test_summary.py b/visualdl/python/test_storage.py similarity index 68% rename from visualdl/python/test_summary.py rename to visualdl/python/test_storage.py index 460e05a3..ef591499 100644 --- a/visualdl/python/test_summary.py +++ b/visualdl/python/test_storage.py @@ -14,12 +14,18 @@ class StorageTest(unittest.TestCase): scalar = self.writer.scalar("model/scalar/min") # scalar.set_caption("model/scalar/min") for i in range(10): - scalar.add_record(i, 1.0) + scalar.add_record(i, float(i)) print 'test read' self.reader = storage.StorageReader("train", self.dir) scalar = self.reader.scalar("model/scalar/min") self.assertEqual(scalar.caption(), "train") + records = scalar.records() + ids = scalar.ids() + self.assertTrue(np.equal(records, [float(i) for i in range(10)]).all()) + self.assertTrue(np.equal(ids, [float(i) for i in range(10)]).all()) + print 'records', records + print 'ids', ids if __name__ == '__main__': diff --git a/visualdl/storage/CMakeLists.txt b/visualdl/storage/CMakeLists.txt index 3a0b36ca..ec9dfbbf 100644 --- a/visualdl/storage/CMakeLists.txt +++ b/visualdl/storage/CMakeLists.txt @@ -9,7 +9,7 @@ add_library(tablet tablet.cc tablet.h ${PROTO_SRCS} ${PROTO_HDRS}) add_library(record record.cc record.h ${PROTO_SRCS} ${PROTO_HDRS}) add_library(storage storage.cc storage.h ${PROTO_SRCS} ${PROTO_HDRS}) -add_dependencies(entry storage_proto) +add_dependencies(entry storage_proto im) add_dependencies(record storage_proto entry) add_dependencies(tablet storage_proto) add_dependencies(storage storage_proto) diff --git a/visualdl/storage/entry.cc b/visualdl/storage/entry.cc index 71e11884..0d4fc8dd 100644 --- a/visualdl/storage/entry.cc +++ b/visualdl/storage/entry.cc @@ -7,6 +7,7 @@ namespace visualdl { void Entry::method__(ctype__ v) { \ entry->set_dtype(storage::DataType::dtype__); \ entry->opr__(v); \ + WRITE_GUARD \ } IMPL_ENTRY_SET_OR_ADD(Set, int, kInt32, set_i32); @@ -57,5 +58,4 @@ template class EntryReader; template class EntryReader; template class EntryReader; - } // namespace visualdl diff --git a/visualdl/storage/entry.h b/visualdl/storage/entry.h index 6516efb3..060b0382 100644 --- a/visualdl/storage/entry.h +++ b/visualdl/storage/entry.h @@ -14,7 +14,7 @@ struct Storage; */ template struct Entry { - DECL_GUARD(Entry) + DECL_GUARD(Entry) // use pointer to avoid copy storage::Entry* entry{nullptr}; -- GitLab