提交 47583c6f 编写于 作者: J Jun Tian 提交者: wuzewu

[WIP] Add support for Julia (#529)

* sync

* sync

* sync

* sync

* only support Float32

* add more data types

* clang format

* clang format

* typo fix in vdljl.cc

* Delete vdl.jl
上级 40676420
......@@ -33,6 +33,7 @@ set(THIRD_PARTY_PATH "${CMAKE_BINARY_DIR}/third_party" CACHE STRING
option(WITH_DOC "Compile VisualDL with documentation" OFF)
option(WITH_TESTING "Compile VisualDL with unit testing" ON)
option(WITH_PYTHON3 "Compile VisualDL with Python 3" OFF)
option(WITH_JULIA "Compile VisualDL with Julia" OFF)
option(ON_RELEASE "RELEASE mode" ON)
......@@ -65,6 +66,10 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/visualdl/storage)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/visualdl/logic)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/visualdl/python)
if(WITH_JULIA)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/visualdl/julia)
endif()
# compile test only in release mode
if (NOT ON_RELEASE)
add_executable(vl_test
......
find_package(JlCxx REQUIRED)
add_library(vdljl SHARED vdljl.cc)
add_dependencies(vdljl im entry tablet sdk storage protobuf eigen3)
target_link_libraries(vdljl PRIVATE JlCxx::cxxwrap_julia entry binary_record im tablet storage sdk protobuf ${OPTIONAL_LINK_FLAGS})
#include <cstdlib>
#include <iostream>
#include <jlcxx/jlcxx.hpp>
#include <string>
#include "visualdl/logic/sdk.h"
#include "visualdl/storage/storage.h"
#include "visualdl/storage/tablet.h"
namespace vs = visualdl;
namespace cp = visualdl::components;
struct WrapScalar {
template <typename TypeWrapperT>
void operator()(TypeWrapperT&& wrapped) {
typedef typename TypeWrapperT::type WrappedT;
wrapped.template constructor<vs::Tablet>();
wrapped.method("set_caption", &WrappedT::SetCaption);
wrapped.method("add_record", &WrappedT::AddRecord);
}
};
struct WrapHistogram {
template <typename TypeWrapperT>
void operator()(TypeWrapperT&& wrapped) {
typedef typename TypeWrapperT::type WrappedT;
typedef typename WrappedT::data_type T;
wrapped.template constructor<vs::Tablet, int>();
wrapped.method("add_record",
[](WrappedT h, int step, jlcxx::ArrayRef<T, 1> data) {
std::vector<T> d(data.begin(), data.end());
return h.AddRecord(step, d);
});
}
};
JLCXX_MODULE define_julia_module(jlcxx::Module& vdl) {
vdl.add_type<vs::Tablet>("Tablet");
vdl.add_type<vs::TabletReader>("TabletReader");
vdl.add_type<vs::Storage>("Storage");
vdl.add_type<vs::StorageReader>("StorageReader");
vdl.add_type<vs::LogWriter>("LogWriter")
.constructor<const std::string&, int>()
.constructor<const vs::LogWriter&>()
.method("set_mode", &vs::LogWriter::SetMode)
.method("save", &vs::LogWriter::Save)
.method("as_mode", &vs::LogWriter::AsMode)
.method("add_tablet", &vs::LogWriter::AddTablet)
.method("storage", &vs::LogWriter::storage);
vdl.add_type<vs::LogReader>("LogReader")
.constructor<const std::string&>()
.method("set_mode", &vs::LogReader::SetMode)
.method("as_mode", &vs::LogReader::AsMode)
.method("mode", &vs::LogReader::mode)
.method("tablet", &vs::LogReader::tablet)
.method("storage", &vs::LogReader::storage)
.method("alltags",
[](vs::LogReader& lr) {
auto alltags = lr.all_tags();
return jlcxx::ArrayRef<std::string, 1>(alltags.data(),
alltags.size());
})
.method("tags", [](vs::LogReader& lr, const std::string& x) {
auto tags = lr.tags(x);
return jlcxx::ArrayRef<std::string, 1>(tags.data(), tags.size());
});
// components
vdl.add_type<jlcxx::Parametric<jlcxx::TypeVar<1>>>("Scalar")
.apply<cp::Scalar<float>,
cp::Scalar<double>,
cp::Scalar<int>,
cp::Scalar<long>>(WrapScalar());
vdl.add_type<jlcxx::Parametric<jlcxx::TypeVar<1>>>("Histogram")
.apply<cp::Histogram<float>,
cp::Histogram<double>,
cp::Histogram<int>,
cp::Histogram<long>>(WrapHistogram());
vdl.add_type<cp::Image>("Image")
.constructor<vs::Tablet, int, int>()
.method("set_caption", &cp::Image::SetCaption)
.method("start_sampling", &cp::Image::StartSampling)
.method("finish_sampling", &cp::Image::FinishSampling)
.method("add_sample",
[](cp::Image& img,
jlcxx::ArrayRef<cp::Image::shape_t, 1> shape,
jlcxx::ArrayRef<cp::Image::value_t, 1> data) {
std::vector<cp::Image::shape_t> s(shape.begin(), shape.end());
std::vector<cp::Image::value_t> d(data.begin(), data.end());
return img.AddSample(s, d);
})
.method("index_of_sample_taken", &cp::Image::IndexOfSampleTaken)
.method("set_sample",
[](cp::Image& img,
int index,
jlcxx::ArrayRef<cp::Image::shape_t, 1> shape,
jlcxx::ArrayRef<cp::Image::value_t, 1> data) {
std::vector<cp::Image::shape_t> s(shape.begin(), shape.end());
std::vector<cp::Image::value_t> d(data.begin(), data.end());
return img.SetSample(index, s, d);
});
vdl.add_type<cp::Text>("Text")
.constructor<vs::Tablet>()
.method("set_caption", &cp::Text::SetCaption)
.method("add_record", &cp::Text::AddRecord);
vdl.add_type<cp::Audio>("Audio")
.constructor<vs::Tablet, int, int>()
.method("set_caption", &cp::Audio::SetCaption)
.method("start_sampling", &cp::Audio::StartSampling)
.method("finish_sampling", &cp::Audio::FinishSampling)
.method("add_sample",
[](cp::Audio& img,
jlcxx::ArrayRef<cp::Audio::shape_t, 1> shape,
jlcxx::ArrayRef<cp::Audio::value_t, 1> data) {
std::vector<cp::Audio::shape_t> s(shape.begin(), shape.end());
std::vector<cp::Audio::value_t> d(data.begin(), data.end());
return img.AddSample(s, d);
})
.method("index_of_sample_taken", &cp::Audio::IndexOfSampleTaken)
.method("set_sample",
[](cp::Audio& img,
int index,
jlcxx::ArrayRef<cp::Audio::shape_t, 1> shape,
jlcxx::ArrayRef<cp::Audio::value_t, 1> data) {
std::vector<cp::Audio::shape_t> s(shape.begin(), shape.end());
std::vector<cp::Audio::value_t> d(data.begin(), data.end());
return img.SetSample(index, s, d);
});
}
......@@ -258,6 +258,8 @@ private:
*/
template <typename T>
struct Histogram {
typedef T data_type;
Histogram(Tablet tablet, int num_buckets)
: writer_(tablet), num_buckets_(num_buckets) {
writer_.SetType(Tablet::Type::kHistogram);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册