Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions cmake/FindR.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.
# All rights reserved.
#
# For the licensing terms see $ROOTSYS/LICENSE.
# For the list of contributors see $ROOTSYS/README/CREDITS.

# CMake module to find R
# - Try to find R
# Once done, this will define
#
# R_FOUND - system has R
# R_INCLUDE_DIRS - the R include directories
# R_LIBRARIES - link these to use R
# R_ROOT_DIR - As reported by R
# Autor: Omar Andres Zapata Mesa 31/05/2013

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_FIND_APPBUNDLE "LAST")
endif()

find_program(R_EXECUTABLE NAMES R R.exe)

#---searching R installtion unsing R executable
if(R_EXECUTABLE)
execute_process(COMMAND ${R_EXECUTABLE} RHOME
OUTPUT_VARIABLE R_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

find_path(R_INCLUDE_DIR R.h
HINTS ${R_ROOT_DIR}
PATHS /usr/local/lib /usr/local/lib64 /usr/share
PATH_SUFFIXES include R/include
DOC "Path to file R.h")

find_library(R_LIBRARY R
HINTS ${R_ROOT_DIR}/lib
DOC "R library (example libR.a, libR.dylib, etc.).")
endif()

#---setting include dirs and libraries
set(R_LIBRARIES ${R_LIBRARY})
set(R_INCLUDE_DIRS ${R_INCLUDE_DIR})
foreach(_cpt ${R_FIND_COMPONENTS})
execute_process(COMMAND echo "cat(find.package('${_cpt}'))"
COMMAND ${R_EXECUTABLE} --vanilla --slave
RESULT_VARIABLE _rc
ERROR_QUIET
OUTPUT_VARIABLE _cpt_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _rc)
set(R_${_cpt}_FOUND 1)
endif()

find_library(R_${_cpt}_LIBRARY
lib${_cpt}.so lib${_cpt}.dylib
HINTS ${_cpt_path}/lib)
if(R_${_cpt}_LIBRARY)
mark_as_advanced(R_${_cpt}_LIBRARY)
list(APPEND R_LIBRARIES ${R_${_cpt}_LIBRARY})
endif()

find_path(R_${_cpt}_INCLUDE_DIR ${_cpt}.h HINTS ${_cpt_path} PATH_SUFFIXES include R/include)
if(R_${_cpt}_INCLUDE_DIR)
mark_as_advanced(R_${_cpt}_INCLUDE_DIR)
list(APPEND R_INCLUDE_DIRS ${R_${_cpt}_INCLUDE_DIR})
endif()

endforeach()

# Handle the QUIETLY and REQUIRED arguments and set R_FOUND to TRUE if all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(R HANDLE_COMPONENTS REQUIRED_VARS R_EXECUTABLE R_INCLUDE_DIR R_LIBRARY)
mark_as_advanced(R_FOUND R_EXECUTABLE R_INCLUDE_DIR R_LIBRARY)
29 changes: 20 additions & 9 deletions src/lib-base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,36 @@ cmake_minimum_required(VERSION 3.5.1)
include(../../cmake/util.cmake)
project( lib-base )

find_package(R)

file( GLOB SRCS src/*.cpp */*.h */*.hpp)

if (R_FOUND)
option(WITH_FEATURE_R "Use R" ON)
else()
option(WITH_FEATURE_R "Use R" OFF)
endif()
option(WITH_FEATURE_URT "Use URT" ON)

add_library (${PROJECT_NAME} ${LINK_TYPE} ${SRCS})
if (WITH_FEATURE_URT)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DUSE_URT)
set (EXTRA_LIBS ${EXTRA_LIBS} URT)
set (EXTRA_LIBS ${EXTRA_LIBS} URT)
set (DEFINITIONS ${DEFINITIONS} -DUSE_URT)
endif()
if (WITH_FEATURE_R)
set (EXTRA_LIBS ${EXTRA_LIBS} ${R_LIBRARIES})
set (DEFINITIONS ${DEFINITIONS} -DUSE_R)
file( GLOB SRCS_R src/r/*.cpp src/r/*.*h)
set (SRCS ${SRCS} ${SRCS_R})
endif()

add_library (${PROJECT_NAME} ${LINK_TYPE} ${SRCS})
enjoSetupTarget(${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${DEFINITIONS})
target_link_libraries(${PROJECT_NAME} EnjoLibBoost EnjoLibStat3rd FuzzyEngine++ URT ${EXTRA_LIBS})
target_include_directories(${PROJECT_NAME} PUBLIC src/r ${R_INCLUDE_DIRS})
enjo_target_pch(${PROJECT_NAME} src/pch_base.h)
target_compile_definitions(${PROJECT_NAME} PUBLIC PUB)
if (APPLE)
# TODO: Upstream this to libBoost
# https://apple.stackexchange.com/questions/337940/why-is-usr-include-missing-i-have-xcode-and-command-line-tools-installed-moja
# https://lists.macports.org/pipermail/macports-dev/2019-September/041201.html
#target_compile_options(${PROJECT_NAME} PUBLIC "-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk")
endif()

#enjoCopyFile(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/../run-tests.sh ../run-tests.sh)
#enjoCopyFile(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/../libs-base.sh ../libs-base.sh)
#enjoCopyFile(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/../libs-stock.sh ../libs-stock.sh)
Expand Down
10 changes: 9 additions & 1 deletion src/lib-base/src/PredictorFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "PredictorAR.h"
#include "PredictorSMAMA.h"
#include "PredictorARMA.h"
#ifdef USE_R
#include "PredictorRBaseline.h"
#include "PredictorRCustom.h"
#endif // USE_R

#include <Util/Except.hpp>

Expand Down Expand Up @@ -41,9 +45,13 @@ CorPtr<IPredictor> PredictorFactory::Create(const IDataProvider & dat, const Pre
case PredictorType::PRED_ARMA: return CorPtr<IPredictor>(new PredictorARMA(dat));
case PredictorType::PRED_BASELINE: return CorPtr<IPredictor>(new PredictorBaseline(dat));
case PredictorType::PRED_BASELINE2: return CorPtr<IPredictor>(new PredictorBaseline2(dat));
#ifdef USE_R
case PredictorType::PRED_R_BASELINE: return CorPtr<IPredictor>(new PredictorRBaseline(dat));
case PredictorType::PRED_R_CUSTOM: return CorPtr<IPredictor>(new PredictorRCustom(dat));
#endif // USE_R
case PredictorType::PRED_TEST: return CorPtr<IPredictor>(new PredictorExperimental(dat));
case PredictorType::PRED_DUMB: return CorPtr<IPredictor>(new PredictorDumb(dat));
case PredictorType::PRED_TRUE: return CorPtr<IPredictor>(new PredictorTrue(dat));
}
throw EnjoLib::ExceptNotImpl("PredictorFactory(): Not implemented type");
}
}
4 changes: 4 additions & 0 deletions src/lib-base/src/PredictorType.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ enum class PredictorType
PRED_AR,
PRED_SMAMA,
PRED_ARMA,
#ifdef USE_R
PRED_R_BASELINE,
PRED_R_CUSTOM,
#endif
PRED_DUMB,
PRED_TEST,
PRED_TRUE
Expand Down
4 changes: 4 additions & 0 deletions src/lib-base/src/PredictorTypeStr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ PredictorTypeStr::PredictorTypeStr()
case PredictorType::PRED_AR: Add(i, "AR"); break;
case PredictorType::PRED_SMAMA: Add(i, "SmaMA"); break;
case PredictorType::PRED_ARMA: Add(i, "ARMA"); break;
#ifdef USE_R
case PredictorType::PRED_R_BASELINE: Add(i, "R-Baseline"); break;
case PredictorType::PRED_R_CUSTOM: Add(i, "R-Custom"); break;
#endif //USE_R
case PredictorType::PRED_TRUE: Add(i, "True"); break;
case PredictorType::PRED_TEST: Add(i, "Test"); break;
case PredictorType::PRED_DUMB: Add(i, "Dumb"); break;
Expand Down
25 changes: 25 additions & 0 deletions src/lib-base/src/r/PredictorRBaseline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "PredictorRBaseline.h"

#include <Rinternals.h>
#include <Rembedded.h>

PredictorRBaseline::PredictorRBaseline(const IDataProvider & dat)
: PredictorBase(dat, "RBaseline")
{
//ctor
}

PredictorRBaseline::~PredictorRBaseline()
{
//dtor
}

EnjoLib::VecD PredictorRBaseline::Predict(const EnjoLib::VecD & data) const
{
return data;
}

unsigned PredictorRBaseline::GetLags() const
{
return 1;
}
21 changes: 21 additions & 0 deletions src/lib-base/src/r/PredictorRBaseline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef PREDICTORRBASELINE_H
#define PREDICTORRBASELINE_H

#include <PredictorBase.h>


class PredictorRBaseline : public PredictorBase
{
public:
PredictorRBaseline(const IDataProvider & dat);
virtual ~PredictorRBaseline();

EnjoLib::VecD Predict(const EnjoLib::VecD & data) const override;
unsigned GetLags() const override;

protected:

private:
};

#endif // PREDICTORRBASELINE_H
22 changes: 22 additions & 0 deletions src/lib-base/src/r/PredictorRCustom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "PredictorRCustom.h"

PredictorRCustom::PredictorRCustom(const IDataProvider & dat)
: PredictorBase(dat, "RCustom")
{
//ctor
}

PredictorRCustom::~PredictorRCustom()
{
//dtor
}

EnjoLib::VecD PredictorRCustom::Predict(const EnjoLib::VecD & data) const
{
return data;
}

unsigned PredictorRCustom::GetLags() const
{
return 1;
}
21 changes: 21 additions & 0 deletions src/lib-base/src/r/PredictorRCustom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef PREDICTORRCUSTOM_H
#define PREDICTORRCUSTOM_H

#include <PredictorBase.h>


class PredictorRCustom : public PredictorBase
{
public:
PredictorRCustom(const IDataProvider & dat);
virtual ~PredictorRCustom();

EnjoLib::VecD Predict(const EnjoLib::VecD & data) const override;
unsigned GetLags() const override;

protected:

private:
};

#endif // PREDICTORRCUSTOM_H
4 changes: 2 additions & 2 deletions util/deps-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ if [ "$(uname)" == "Darwin" ]; then
fi
#HOMEBREW_NO_AUTO_UPDATE=1 brew install qt5
#brew link -v qt5 --force
HOMEBREW_NO_AUTO_UPDATE=1 brew install boost ccache gnuplot eigen gsl unittest-cpp wxwidgets # openssl zmq
HOMEBREW_NO_AUTO_UPDATE=1 brew install boost ccache gnuplot eigen gsl unittest-cpp wxwidgets r # openssl zmq
# TODO: install qt instead of qt5, after moving to latest QCustomPlot. Then the "--prefix" and "link" aren't needed.
elif [ "$(uname)" == "Linux" ]; then
sudo apt update; sudo apt -y install build-essential cmake ccache gnuplot libeigen3-dev libunittest++-dev libgsl-dev libboost-system-dev libboost-filesystem-dev libboost-iostreams-dev libboost-serialization-dev libboost-program-options-dev libboost-date-time-dev libboost-atomic-dev libwxgtk3.0-gtk3-dev qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools # libssl-dev
sudo apt update; sudo apt -y install build-essential cmake ccache gnuplot libeigen3-dev libunittest++-dev libgsl-dev libboost-system-dev libboost-filesystem-dev libboost-iostreams-dev libboost-serialization-dev libboost-program-options-dev libboost-date-time-dev libboost-atomic-dev libwxgtk3.0-gtk3-dev qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools r-base-dev # libssl-dev
else
echo "TODO: install deps"
# TODO: implement MinGW
Expand Down