Skip to content

Commit

Permalink
make into standard folder structure, not usable yet
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhonglin committed Dec 11, 2014
1 parent 854de5a commit 6823769
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Created by http://www.gitignore.io

### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/


### C++ ###
# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app


### CMake ###
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
install_manifest.txt

### build ###
/build/*
/bin/*
/emacs-build/*
/output/*
/viewer.py
# /python/*
/test/*
libpysegfit.so
segfit
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: cpp
compiler:
- clang
notifications:
email: false
env:
matrix:
- JULIAVERSION="juliareleases"
- JULIAVERSION="julianightlies"
before_install:
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
- sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y
- sudo apt-get update -qq -y
- sudo apt-get install libpcre3-dev julia -y
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
script:
- julia -e 'Pkg.init(); Pkg.clone(pwd()); Pkg.test("Lbfgsb")'
25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The Lbfgsb.jl package is licensed under the Simplified "2-clause" BSD License:

> Copyright (c) 2014: Honglin Yu.
>
> Redistribution and use in source and binary forms, with or without
> modification, are permitted provided that the following conditions are
> met:
>
> 1. Redistributions of source code must retain the above copyright
> notice, this list of conditions and the following disclaimer.
> 2. Redistributions in binary form must reproduce the above copyright
> notice, this list of conditions and the following disclaimer in the
> documentation and/or other materials provided with the distribution.
>
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ BSD-3

[lbfgsb fortran library]:http://users.iems.northwestern.edu/~nocedal/lbfgsb.html
[this wrapper]:http://hannes.nickisch.org/code/glm-ie/pls/lbfgsb/README.html

137 changes: 137 additions & 0 deletions src/Lbfgsb.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
module Lbfgsb

# package code goes here
macro callLBFGS(cmd)
quote
if length($cmd) != 0
@simd for i = 1:length($cmd)
task[i] = ($cmd)[i];
end
@simd for i = length($cmd)+1:60
task[i] = ' ';
end
end

ccall((:setulb_, "./liblbfgsb.so"),
Void,
(Ptr{Int32},
Ptr{Int32},
Ptr{Float64},
Ptr{Float64},
Ptr{Float64},
Ptr{Int32},
Ptr{Float64},
Ptr{Float64},
Ptr{Float64},
Ptr{Float64},
Ptr{Float64},
Ptr{Int32},
Ptr{Uint8},
Ptr{Int32},
Ptr{Uint8},
Ptr{Bool},
Ptr{Int32},
Ptr{Float64} ),
n,
m,
x,
lb,
ub,
btype,
f,
g,
factr,
pgtol,
wa,
iwa,
task,
iprint,
csave,
lsave,
isave,
dsave );
end
end

function lbfgsb (ogFunc,
x;
lb = [],
ub = [],
btype = [],
m::Int64 = 5,
maxiter::Int64 = 100,
factr::Float64 = 1e7,
pgtol::Float64 = 1e-5,
iprint::Int64 = -1 # does not print
)
m = [convert(Int32, m)]
factr = [convert(Float64, factr)];
pgtol = [convert(Float64, pgtol)];
iprint = [convert(Int32, iprint)];

n = [convert(Int32, length(x))]; # number of variables
f = [convert(Float64, 0.0)]; # The value of the objective.
g = [convert(Float64, 0.0) for i=1:(n[1])]; # The value of the gradient.

if length(lb) == 0
lb = [-Inf for i=1:(n[1])];
else
lb = [convert(Float64, i) for i in lb]
end

if length(ub) == 0
ub = [Inf for i=1:(n[1])];
else
ub = [convert(Float64, i) for i in ub]
end

if length(btype) == 0
btype = [convert(Int32, 2) for i=1:(n[1])];
else
btype = [convert(Int32, i) for i in btype];
end

# structures used by the L-BFGS-B routine.
wa = [convert(Float64, 0.0) for i = 1:(2*m[1] + 5)*n[1] + 12*m[1]*(m[1] + 1)];
iwa = [convert(Int32, 0) for i = 1:3*n[1]];
task = [convert(Uint8, 0) for i =1:60];
csave = [convert(Uint8, 0) for i =1:60];
lsave = [convert(Bool, 0) for i=1:4];
isave = [convert(Int32, 0) for i=1:44];
dsave = [convert(Float64, 0.0) for i=1:29];

@callLBFGS "START"

status = "success";

t = 0;

while true

if task[1] == 'F'
tf, g = ogFunc(x);
f[1] = convert(Float64, tf);

elseif task[1] == 'N'
t += 1;
if t >= maxiter # exceed maximum number of iteration
@callLBFGS "STOP"
break;
end
elseif task[1] == 'C' # convergence
break;
elseif task[1] == 'A'
status = "abnormal";
break;
elseif task[1] == 'E'
status = "error";
break;
end

@callLBFGS ""
end

return (f, x, status, t);
end

end # module

0 comments on commit 6823769

Please sign in to comment.