提交 b05a8dd0 编写于 作者: S superjom

code clean

上级 c65bf61b
......@@ -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)
#!/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() {
template class SimpleWriteSyncGuard<Storage>;
template class SimpleWriteSyncGuard<Tablet>;
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
......@@ -15,6 +15,7 @@ PYBIND11_PLUGIN(core) {
py::class_<cp::ScalarReader<T>>(m, "ScalarReader__" #T) \
.def("records", &cp::ScalarReader<T>::records) \
.def("timestamps", &cp::ScalarReader<T>::timestamps) \
.def("ids", &cp::ScalarReader<T>::ids) \
.def("caption", &cp::ScalarReader<T>::caption);
ADD_SCALAR(int);
ADD_SCALAR(float);
......@@ -57,9 +58,7 @@ PYBIND11_PLUGIN(core) {
py::class_<vs::Writer>(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;
})
......
......@@ -4,61 +4,48 @@ namespace visualdl {
namespace components {
// template <typename T>
// void components::Scalar<T>::AddRecord(int id, const std::vector<T> &values) {
// // add record data
// auto record = tablet_.AddRecord();
// auto entry = record.AddData<T>();
// for (auto v : values) {
// entry.Add(v);
// }
// // set record id
// record.SetId(id);
// // set record timestamp
// record.SetTimeStamp(time(NULL));
// }
// 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));
// }
// return res;
// }
// template <typename T>
// std::vector<int> ScalarReader<T>::ids() const {
// std::vector<int> res;
// for (int i = 0; i < reader_.total_records(); i++) {
// res.push_back(reader_.record(i).id());
// }
// return res;
// }
// template <typename T>
// std::vector<int> 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::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>;
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();
}
template class ScalarReader<int>;
template class ScalarReader<int64_t>;
template class ScalarReader<float>;
template class ScalarReader<double>;
} // namespace components
......
......@@ -91,43 +91,6 @@ private:
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 visualdl
......
......@@ -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)
......@@ -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__':
......
......@@ -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)
......@@ -7,6 +7,7 @@ namespace visualdl {
void Entry<ctype__>::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<float>;
template class EntryReader<double>;
template class EntryReader<bool>;
} // namespace visualdl
......@@ -14,7 +14,7 @@ struct Storage;
*/
template <typename T>
struct Entry {
DECL_GUARD(Entry)
DECL_GUARD(Entry<T>)
// use pointer to avoid copy
storage::Entry* entry{nullptr};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册