Skip to content

Commit

Permalink
[ShogunBoard] Guard everything TFLogger related.
Browse files Browse the repository at this point in the history
Add a HAVE_TFLOGGER flag.
  • Loading branch information
geektoni authored and vigsterkr committed Jul 12, 2017
1 parent 392ecd2 commit 91ac0de
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/interfaces/swig/ParameterObserver.i
@@ -1,3 +1,5 @@
#ifdef HAVE_TFLOGGER

%include "std_vector.i"
%include "std_string.i"
%template(ParameterList) std::vector<std::string>;
Expand All @@ -13,3 +15,5 @@
%include <shogun/lib/ParameterObserverTensorBoard.h>
%include <shogun/lib/ParameterObserverScalar.h>
%include <shogun/lib/ParameterObserverHistogram.h>

#endif // HAVE_TFLOGGER
8 changes: 1 addition & 7 deletions src/shogun/CMakeLists.txt
Expand Up @@ -287,15 +287,9 @@ ENDIF()
# TFLogger package
FIND_PACKAGE(TFLogger 0.1.0 CONFIG)
IF (TFLogger_FOUND)
SET(HAVE_TFLOGGER 1)
SHOGUN_INCLUDE_DIRS(SCOPE PRIVATE SYSTEM ${TFLogger_INCLUDE_DIR})
target_link_libraries(shogun PRIVATE tflogger::tflogger)
ELSE()
include(external/tflogger)
SHOGUN_INCLUDE_DIRS(SCOPE PRIVATE SYSTEM
$<BUILD_INTERFACE:${TFLogger_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include/shogun/lib/external/tflogger>
)
target_link_libraries(shogun PRIVATE tflogger::tflogger)
ENDIF()

#### LAPACK
Expand Down
4 changes: 4 additions & 0 deletions src/shogun/io/TBOutputFormat.cpp
@@ -1,6 +1,8 @@
/*
* Written (W) 2017 Giovanni De Toni
*/
#include <shogun/lib/config.h>
#ifdef HAVE_TFLOGGER

#include <chrono>
#include <vector>
Expand Down Expand Up @@ -117,3 +119,5 @@ tensorflow::Event TBOutputFormat::convert_vector(

return e;
}

#endif // HAVE_TFLOGGER
3 changes: 3 additions & 0 deletions src/shogun/io/TBOutputFormat.h
@@ -1,6 +1,8 @@
/*
* Written (W) 2017 Giovanni De Toni
*/
#include <shogun/lib/config.h>
#ifdef HAVE_TFLOGGER

#ifndef SHOGUN_OUTPUTFORMAT_H
#define SHOGUN_OUTPUTFORMAT_H
Expand Down Expand Up @@ -47,3 +49,4 @@ namespace shogun
}

#endif // SHOGUN_OUTPUTFORMAT_H
#endif // HAVE_TFLOGGER
5 changes: 4 additions & 1 deletion src/shogun/lib/ParameterObserverHistogram.cpp
@@ -1,6 +1,8 @@
/*
* Written (W) 2017 Giovanni De Toni
*/
#include <shogun/lib/config.h>
#ifdef HAVE_TFLOGGER

#include <shogun/io/TBOutputFormat.h>
#include <shogun/lib/ParameterObserverHistogram.h>
Expand All @@ -25,7 +27,6 @@ ParameterObserverHistogram::ParameterObserverHistogram(
}

ParameterObserverHistogram::~ParameterObserverHistogram()
: ~ParameterObserverTensorBoard()
{
}

Expand Down Expand Up @@ -56,3 +57,5 @@ bool ParameterObserverHistogram::filter(const std::string& param)
return true;
return false;
}

#endif // HAVE_TFLOGGER
3 changes: 3 additions & 0 deletions src/shogun/lib/ParameterObserverHistogram.h
@@ -1,6 +1,8 @@
/*
* Written (W) 2017 Giovanni De Toni
*/
#include <shogun/lib/config.h>
#ifdef HAVE_TFLOGGER

#ifndef SHOGUN_PARAMETEROBSERVERHISTOGRAM_H
#define SHOGUN_PARAMETEROBSERVERHISTOGRAM_H
Expand Down Expand Up @@ -32,3 +34,4 @@ namespace shogun
}

#endif // SHOGUN_PARAMETEROBSERVERHISTOGRAM_H
#endif // HAVE_TFLOGGER
5 changes: 4 additions & 1 deletion src/shogun/lib/ParameterObserverScalar.cpp
@@ -1,6 +1,8 @@
/*
* Written (W) 2017 Giovanni De Toni
*/
#include <shogun/lib/config.h>
#ifdef HAVE_TFLOGGER

#include <shogun/io/TBOutputFormat.h>
#include <shogun/lib/ParameterObserverScalar.h>
Expand All @@ -25,7 +27,6 @@ ParameterObserverScalar::ParameterObserverScalar(
}

ParameterObserverScalar::~ParameterObserverScalar()
: ~ParameterObserverTensorBoard()
{
}

Expand Down Expand Up @@ -56,3 +57,5 @@ bool ParameterObserverScalar::filter(const std::string& param)
return true;
return false;
}

#endif // HAVE_TFLOGGER
3 changes: 3 additions & 0 deletions src/shogun/lib/ParameterObserverScalar.h
@@ -1,6 +1,8 @@
/*
* Written (W) 2017 Giovanni De Toni
*/
#include <shogun/lib/config.h>
#ifdef HAVE_TFLOGGER

#ifndef SHOGUN_PARAMETEROBSERVERSCALAR_H
#define SHOGUN_PARAMETEROBSERVERSCALAR_H
Expand Down Expand Up @@ -32,3 +34,4 @@ namespace shogun
}

#endif // SHOGUN_PARAMETEROBSERVERSCALAR_H
#endif // HAVE_TFLOGGER
5 changes: 4 additions & 1 deletion src/shogun/lib/ParameterObserverTensorBoard.cpp
@@ -1,6 +1,8 @@
/*
* Written (W) 2017 Giovanni De Toni
*/
#include <shogun/lib/config.h>
#ifdef HAVE_TFLOGGER

#include "ParameterObserverTensorBoard.h"

Expand All @@ -27,8 +29,9 @@ ParameterObserverTensorBoard::ParameterObserverTensorBoard(
}

ParameterObserverTensorBoard::~ParameterObserverTensorBoard()
: ~ParameterObserverTensorBoard()
{
m_writer.flush();
m_writer.close();
}

#endif // HAVE_TFLOGGER
7 changes: 5 additions & 2 deletions src/shogun/lib/ParameterObserverTensorBoard.h
@@ -1,13 +1,15 @@
/*
* Written (W) 2017 Giovanni De Toni
*/
#include <shogun/lib/config.h>
#ifdef HAVE_TFLOGGER

#ifndef SHOGUN_PARAMETEROBSERVERTENSORBOARD_H
#define SHOGUN_PARAMETEROBSERVERTENSORBOARD_H

#include <shogun/lib/ParameterObserverInterface.h>

#include <tflogger/tensorflow_logger.h>
#include <tflogger/event_logger.h>

namespace shogun
{
Expand Down Expand Up @@ -42,8 +44,9 @@ namespace shogun
/**
* Writer object which will be used to write tensorflow::Event files
*/
tflogger::TensorFlowLogger m_writer;
tflogger::EventLogger m_writer;
};
}

#endif // SHOGUN_PARAMETEROBSERVERTENSORBOARD_H
#endif // HAVE_TFLOGGER
1 change: 1 addition & 0 deletions src/shogun/lib/config.h.in
Expand Up @@ -14,6 +14,7 @@
#cmakedefine HAVE_LAPACK 1
#cmakedefine HAVE_MVEC 1
#cmakedefine HAVE_PROTOBUF 1
#cmakedefine HAVE_TFLOGGER 1

#cmakedefine HAVE_ARPACK 1
#cmakedefine HAVE_VIENNACL 1
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lib/ParameterObserverScalar_unittest.cc
Expand Up @@ -2,10 +2,10 @@
#include <vector>
#include <gtest/gtest.h>

using namespace shogun;

std::vector<std::string> test_params = {"a", "b", "c", "d"};

using namespace shogun;

TEST(ParameterObserverScalar, filter_empty)
{
ParameterObserverScalar tmp;
Expand Down

0 comments on commit 91ac0de

Please sign in to comment.