提交 b05a8dd0 编写于 作者: S superjom

code clean

上级 c65bf61b
...@@ -49,4 +49,3 @@ enable_testing () ...@@ -49,4 +49,3 @@ enable_testing ()
add_custom_target(test_init COMMAND $CMAKE_BINARY_DIR) add_custom_target(test_init COMMAND $CMAKE_BINARY_DIR)
add_test(NAME vstest COMMAND ./vl_test) add_test(NAME vstest COMMAND ./vl_test)
set_target_properties(vl_test PROPERTIES DEPENDS test_init)
#!/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
...@@ -32,5 +32,11 @@ void SimpleWriteSyncGuard<T>::Sync() { ...@@ -32,5 +32,11 @@ void SimpleWriteSyncGuard<T>::Sync() {
template class SimpleWriteSyncGuard<Storage>; template class SimpleWriteSyncGuard<Storage>;
template class SimpleWriteSyncGuard<Tablet>; template class SimpleWriteSyncGuard<Tablet>;
template class SimpleWriteSyncGuard<Record>; template class SimpleWriteSyncGuard<Record>;
template class SimpleWriteSyncGuard<Entry<float>>;
template class SimpleWriteSyncGuard<Entry<double>>;
template class SimpleWriteSyncGuard<Entry<bool>>;
template class SimpleWriteSyncGuard<Entry<long>>;
template class SimpleWriteSyncGuard<Entry<std::string>>;
template class SimpleWriteSyncGuard<Entry<int>>;
} // namespace visualdl } // namespace visualdl
...@@ -15,6 +15,7 @@ PYBIND11_PLUGIN(core) { ...@@ -15,6 +15,7 @@ PYBIND11_PLUGIN(core) {
py::class_<cp::ScalarReader<T>>(m, "ScalarReader__" #T) \ py::class_<cp::ScalarReader<T>>(m, "ScalarReader__" #T) \
.def("records", &cp::ScalarReader<T>::records) \ .def("records", &cp::ScalarReader<T>::records) \
.def("timestamps", &cp::ScalarReader<T>::timestamps) \ .def("timestamps", &cp::ScalarReader<T>::timestamps) \
.def("ids", &cp::ScalarReader<T>::ids) \
.def("caption", &cp::ScalarReader<T>::caption); .def("caption", &cp::ScalarReader<T>::caption);
ADD_SCALAR(int); ADD_SCALAR(int);
ADD_SCALAR(float); ADD_SCALAR(float);
...@@ -57,9 +58,7 @@ PYBIND11_PLUGIN(core) { ...@@ -57,9 +58,7 @@ PYBIND11_PLUGIN(core) {
py::class_<vs::Writer>(m, "Writer") py::class_<vs::Writer>(m, "Writer")
.def("__init__", .def("__init__",
[](vs::Writer& instance, [](vs::Writer& instance, const std::string& dir, int sync_cycle) {
const std::string& dir,
int sync_cycle) {
new (&instance) vs::Writer(dir); new (&instance) vs::Writer(dir);
instance.storage().meta.cycle = sync_cycle; instance.storage().meta.cycle = sync_cycle;
}) })
......
...@@ -4,61 +4,48 @@ namespace visualdl { ...@@ -4,61 +4,48 @@ namespace visualdl {
namespace components { namespace components {
// template <typename T> template <typename T>
// void components::Scalar<T>::AddRecord(int id, const std::vector<T> &values) { std::vector<T> ScalarReader<T>::records() const {
// // add record data std::vector<T> res;
// auto record = tablet_.AddRecord(); for (int i = 0; i < reader_.total_records(); i++) {
// auto entry = record.AddData<T>(); res.push_back(reader_.record(i).data<T>(0).Get());
// for (auto v : values) { }
// entry.Add(v); return res;
// } }
// // set record id
// record.SetId(id); template <typename T>
// // set record timestamp std::vector<T> ScalarReader<T>::ids() const {
// record.SetTimeStamp(time(NULL)); std::vector<T> res;
// } for (int i = 0; i < reader_.total_records(); i++) {
res.push_back(reader_.record(i).id());
// template <typename T> }
// std::vector<T> ScalarReader<T>::records() const { return res;
// std::vector<T> res; }
// for (int i = 0; i < reader_.total_records(); i++) {
// res.push_back(reader_.record(i).data<T>(0)); template <typename T>
// } std::vector<T> ScalarReader<T>::timestamps() const {
// return res; std::vector<T> res;
// } for (int i = 0; i < reader_.total_records(); i++) {
res.push_back(reader_.record(i).timestamp());
// template <typename T> }
// std::vector<int> ScalarReader<T>::ids() const { return res;
// std::vector<int> res; }
// for (int i = 0; i < reader_.total_records(); i++) {
// res.push_back(reader_.record(i).id()); template <typename T>
// } std::string ScalarReader<T>::caption() const {
// return res; CHECK(!reader_.captions().empty()) << "no caption";
// } return reader_.captions().front();
}
// template <typename T>
// std::vector<int> ScalarReader<T>::timestamps() const { template <typename T>
// std::vector<T> res; size_t ScalarReader<T>::size() const {
// for (int i = 0; i < reader_.total_records(); i++) { return reader_.total_records();
// res.push_back(reader_.record(i).timestamp()); }
// }
// return res; template class ScalarReader<int>;
// } template class ScalarReader<int64_t>;
template class ScalarReader<float>;
// template <typename T> template class ScalarReader<double>;
// std::vector<std::string> ScalarReader<T>::captions() const {
// return reader_.captions();
// }
// template <typename T>
// size_t ScalarReader<T>::size() const {
// return reader_.total_records();
// }
// template class Scalar<int>;
// template class Scalar<int64_t>;
// template class Scalar<float>;
// template class Scalar<double>;
} // namespace components } // namespace components
......
...@@ -91,43 +91,6 @@ private: ...@@ -91,43 +91,6 @@ private:
TabletReader reader_; TabletReader reader_;
}; };
template <typename T>
std::vector<T> ScalarReader<T>::records() const {
std::vector<T> res;
for (int i = 0; i < reader_.total_records(); i++) {
res.push_back(reader_.record(i).data<T>(0).Get());
}
return res;
}
template <typename T>
std::vector<T> ScalarReader<T>::ids() const {
std::vector<T> res;
for (int i = 0; i < reader_.total_records(); i++) {
res.push_back(reader_.record(i).id());
}
return res;
}
template <typename T>
std::vector<T> ScalarReader<T>::timestamps() const {
std::vector<T> res;
for (int i = 0; i < reader_.total_records(); i++) {
res.push_back(reader_.record(i).timestamp());
}
return res;
}
template <typename T>
std::string ScalarReader<T>::caption() const {
CHECK(!reader_.captions().empty()) << "no caption";
return reader_.captions().front();
}
template <typename T>
size_t ScalarReader<T>::size() const {
return reader_.total_records();
}
} // namespace components } // namespace components
} // namespace visualdl } // namespace visualdl
......
...@@ -10,4 +10,4 @@ function(py_test TARGET_NAME) ...@@ -10,4 +10,4 @@ function(py_test TARGET_NAME)
) )
endfunction() endfunction()
py_test(test_summary SRCS test_summary.py) py_test(test_summary SRCS test_storage.py)
...@@ -14,12 +14,18 @@ class StorageTest(unittest.TestCase): ...@@ -14,12 +14,18 @@ class StorageTest(unittest.TestCase):
scalar = self.writer.scalar("model/scalar/min") scalar = self.writer.scalar("model/scalar/min")
# scalar.set_caption("model/scalar/min") # scalar.set_caption("model/scalar/min")
for i in range(10): for i in range(10):
scalar.add_record(i, 1.0) scalar.add_record(i, float(i))
print 'test read' print 'test read'
self.reader = storage.StorageReader("train", self.dir) self.reader = storage.StorageReader("train", self.dir)
scalar = self.reader.scalar("model/scalar/min") scalar = self.reader.scalar("model/scalar/min")
self.assertEqual(scalar.caption(), "train") 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__': if __name__ == '__main__':
......
...@@ -9,7 +9,7 @@ add_library(tablet tablet.cc tablet.h ${PROTO_SRCS} ${PROTO_HDRS}) ...@@ -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(record record.cc record.h ${PROTO_SRCS} ${PROTO_HDRS})
add_library(storage storage.cc storage.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(record storage_proto entry)
add_dependencies(tablet storage_proto) add_dependencies(tablet storage_proto)
add_dependencies(storage storage_proto) add_dependencies(storage storage_proto)
...@@ -7,6 +7,7 @@ namespace visualdl { ...@@ -7,6 +7,7 @@ namespace visualdl {
void Entry<ctype__>::method__(ctype__ v) { \ void Entry<ctype__>::method__(ctype__ v) { \
entry->set_dtype(storage::DataType::dtype__); \ entry->set_dtype(storage::DataType::dtype__); \
entry->opr__(v); \ entry->opr__(v); \
WRITE_GUARD \
} }
IMPL_ENTRY_SET_OR_ADD(Set, int, kInt32, set_i32); IMPL_ENTRY_SET_OR_ADD(Set, int, kInt32, set_i32);
...@@ -57,5 +58,4 @@ template class EntryReader<float>; ...@@ -57,5 +58,4 @@ template class EntryReader<float>;
template class EntryReader<double>; template class EntryReader<double>;
template class EntryReader<bool>; template class EntryReader<bool>;
} // namespace visualdl } // namespace visualdl
...@@ -14,7 +14,7 @@ struct Storage; ...@@ -14,7 +14,7 @@ struct Storage;
*/ */
template <typename T> template <typename T>
struct Entry { struct Entry {
DECL_GUARD(Entry) DECL_GUARD(Entry<T>)
// use pointer to avoid copy // use pointer to avoid copy
storage::Entry* entry{nullptr}; storage::Entry* entry{nullptr};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册