Skip to content

Instantly share code, notes, and snippets.

@antoine-levitt
Created June 18, 2017 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoine-levitt/0b91d17222c770cd613fc20d447f41df to your computer and use it in GitHub Desktop.
Save antoine-levitt/0b91d17222c770cd613fc20d447f41df to your computer and use it in GitHub Desktop.
Patch for ROPTLIB with julia 0.6
diff --git a/Julia/BeginROPTLIB.jl b/Julia/BeginROPTLIB.jl
index ea53bd6..d56b1fc 100644
--- a/Julia/BeginROPTLIB.jl
+++ b/Julia/BeginROPTLIB.jl
@@ -2,12 +2,12 @@
using Cxx
# to the path of ROPTLIB
-cd("/home/whuang/Documents/ROPTLIB")
+cd("/home/antoine/ROPTLIB")
# import the directory of the header files of Julia
-addHeaderDir("/home/whuang/Documents/julia/usr/include", kind=C_System)
-addHeaderDir("/home/whuang/Documents/julia/src", kind=C_System)
-addHeaderDir("/home/whuang/Documents/julia/src/support", kind=C_System)
+addHeaderDir("/home/antoine/julia/include/julia", kind=C_System)
+addHeaderDir("/home/antoine/julia/src", kind=C_System)
+addHeaderDir("/home/antoine/julia/src/support", kind=C_System)
const path_to_lib = pwd()
diff --git a/Makefile b/Makefile
index f61e1d6..886bd81 100644
--- a/Makefile
+++ b/Makefile
@@ -2,16 +2,16 @@
# set compiler
CC = g++
-CXXFLAGS:=-O3 -ffastmath -march=native -ggdb3
+CXXFLAGS:=-O0 -ffastmath -march=native -ggdb3
# default test problem is the Brockett cost function on the Stiefel manifold
-TP?=TestSimpleExample
+TP?=DriverJuliaProb
#the path of ROPTLIB
ROOTPATH:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
# set the path of Julia
-JULIA_DIR:=/home/whuang/Documents/julia
+JULIA_DIR:=/home/antoine/julia
# directories of ROPTLIB header files
INCDIRS = -I$(ROOTPATH)/
@@ -113,9 +113,9 @@ ROPTLIB:
libropt.so:
$(CC) -w -std=c++0x -shared -fPIC -O3 $(MANIFOLDS) $(OTHERS) $(PROBLEMS) $(SOLVERS) $(INCDIRS) -llapack -lblas -lm -o $@
-JULIA_LIB:=$(JULIA_DIR)/usr/lib
+JULIA_LIB:=$(JULIA_DIR)/lib
JULIA_SRC:=$(JULIA_DIR)/src
-JULIA_INC:=$(JULIA_DIR)/usr/include
+JULIA_INC:=$(JULIA_DIR)/include/julia
CPPFLAGS:=-I$(JULIA_INC) -I$(JULIA_SRC) -I$(JULIA_SRC)/support
LDFLAGS:=-L$(JULIA_LIB)
LDLIBS=-ljulia
@@ -123,4 +123,4 @@ export LD_LIBRARY_PATH:=$(JULIA_LIB):$(JULIA_LIB)/julia
# make a shared library, which is used by Julia
JuliaROPTLIB:
- $(CC) -O3 -shared -fPIC -std=c++0x $(ROOTPATH)/test/$(TP).cpp $(CPPS) $(INCDIRS) -D$(UPPER_TP) $(CPPFLAGS) $(LDFLAGS) -Wl,-rpath,$(JULIA_LIB) -lm $(LDLIBS) -DJULIA_LIB_DIR=\"$(JULIA_DIR)/lib/julia\" -llapack -lblas -o $(TP).so
+ $(CC) -O0 -g -shared -fPIC -std=c++0x $(ROOTPATH)/test/$(TP).cpp $(CPPS) $(INCDIRS) -D$(UPPER_TP) $(CPPFLAGS) $(LDFLAGS) -Wl,-rpath,$(JULIA_LIB) -lm $(LDLIBS) -DJULIA_LIB_DIR=\"$(JULIA_DIR)/lib/julia\" -llapack -lblas -o $(TP).so
diff --git a/Problems/juliaProblem.cpp b/Problems/juliaProblem.cpp
index 2543292..6d02926 100644
--- a/Problems/juliaProblem.cpp
+++ b/Problems/juliaProblem.cpp
@@ -20,7 +20,7 @@ namespace ROPTLIB{
double juliaProblem::f(Variable *x) const
{
// x->Print("cpp f x");//---
- jl_value_t* array_type = jl_apply_array_type(jl_float64_type, 1);
+ jl_value_t* array_type = jl_apply_array_type(reinterpret_cast<jl_value_t *>(jl_float64_type), 1);
double *xptr = x->ObtainWritePartialData();
jl_array_t *arrx = jl_ptr_to_array_1d(array_type, xptr, x->Getlength(), 0);
@@ -48,7 +48,7 @@ namespace ROPTLIB{
x->RemoveFromTempData("Tmp");
x->AddToTempData("Tmp", sharedouttmp);
- if(jl_is_float64(fx))
+ if(jl_typeis(fx, jl_float64_type))
{
double result = jl_unbox_float64(fx);
// std::cout << "cpp f fx:" << result << std::endl;//-----
@@ -61,7 +61,7 @@ namespace ROPTLIB{
void juliaProblem::EucGrad(Variable *x, Vector *egf) const
{
// x->Print("cpp gf x");//---
- jl_value_t* array_type = jl_apply_array_type(jl_float64_type, 1);
+ jl_value_t* array_type = jl_apply_array_type(reinterpret_cast<jl_value_t *>(jl_float64_type), 1);
double *xptr = x->ObtainWritePartialData();
jl_array_t *arrx = jl_ptr_to_array_1d(array_type, xptr, x->Getlength(), 0);
@@ -107,7 +107,7 @@ namespace ROPTLIB{
{
// x->Print("cpp hf x");//---
// etax->Print("cpp hf etax");//---
- jl_value_t* array_type = jl_apply_array_type(jl_float64_type, 1);
+ jl_value_t* array_type = jl_apply_array_type(reinterpret_cast<jl_value_t *>(jl_float64_type), 1);
double *xptr = x->ObtainWritePartialData();
jl_array_t *arrx = jl_ptr_to_array_1d(array_type, xptr, x->Getlength(), 0);
double *etaxptr = etax->ObtainWritePartialData();
diff --git a/test/DriverJuliaProb.cpp b/test/DriverJuliaProb.cpp
index a24b5fa..a422c05 100644
--- a/test/DriverJuliaProb.cpp
+++ b/test/DriverJuliaProb.cpp
@@ -98,7 +98,7 @@ namespace RJULIA{
bool juliaInnerStop(Variable *x, Vector *gf, double f, double ngf, double ngf0, const Problem *prob, const Solvers *solver)
{
jl_value_t *args[5] = {nullptr};
- jl_value_t* array_type = jl_apply_array_type(jl_float64_type, 1);
+ jl_value_t* array_type = jl_apply_array_type(reinterpret_cast<jl_value_t *>(jl_float64_type), 1);
double *xptr = x->ObtainWritePartialData();
jl_array_t *arrx = jl_ptr_to_array_1d(array_type, xptr, x->Getlength(), 0);
double *gfptr = gf->ObtainWritePartialData();
@@ -131,7 +131,7 @@ namespace RJULIA{
double juliaLinesearchInput(integer iter, Variable *x1, Vector *eta1, double initialstepsize, double initialslope, const Problem *prob, const Solvers *solver)
{
jl_value_t *args[4] = {nullptr};
- jl_value_t* array_type = jl_apply_array_type(jl_float64_type, 1);
+ jl_value_t* array_type = jl_apply_array_type(reinterpret_cast<jl_value_t *>(jl_float64_type), 1);
double *xptr = x1->ObtainWritePartialData();
jl_array_t *arrx = jl_ptr_to_array_1d(array_type, xptr, x1->Getlength(), 0);
double *etaptr = eta1->ObtainWritePartialData();
@@ -144,7 +144,7 @@ namespace RJULIA{
jl_value_t *retx = jl_call(LinesearchInput, args, 5);
- if(jl_is_float64(retx))
+ if(jl_typeis(retx, jl_float64_type) )
{
double result = jl_unbox_float64(retx);
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment