Skip to content

Commit

Permalink
update meson and ci (#15)
Browse files Browse the repository at this point in the history
* update meson and ci

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* update gitignore

* fix unittest

* fixup travis
  • Loading branch information
9il authored Mar 30, 2020
1 parent e0186f2 commit 32260ef
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 73 deletions.
22 changes: 22 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2.1

orbs:
mirci: libmir/[email protected]

workflows:
version: 2
build-deploy:
jobs:
- mirci/test_and_build_docs:
filters:
tags:
only: /^v(\d)+(\.(\d)+)+$/
- mirci/upload_docs:
to: mir-optim.libmir.org
requires:
- mirci/test_and_build_docs
filters:
branches:
ignore: /.*/
tags:
only: /^v(\d)+(\.(\d)+)+$/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ build/mir-random/
*.dll
x.txt
subprojects/*/
web
docgen
12 changes: 0 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,9 @@ branches:
script:
- dub test -c unittest-blas
# - if [ "$DC" = "ldc2" ]; then rm -rf .dub && dub build -c blas --compiler=ldmd2 --build-mode=singleFile --build=better-c-release --force && g++ -std=c++1y -pthread -I./include examples/least_squares.cpp -L./ -lmir-optim -llapack -lblas && ./a.out; fi
# - meson build -D with_test=true && cd build && ninja -j4 && ninja test -v && cd ..

addons:
apt:
update: true
packages:
- liblapack-dev
- pkg-config

# install:
# - pyenv global system 3.6
# - pip3 install 'meson>=0.45'
# - mkdir .ntmp
# - curl -L https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip -o .ntmp/ninja-linux.zip
# - unzip .ntmp/ninja-linux.zip -d .ntmp
# before_script:
# - export PATH=$PATH:$PWD/.ntmp

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Dlang BetterC Nonlinear Optimisers.
- Modified Levenberg-Marquardt Algorithm (Nonlinear Least Squares).
- Boxed Constrained Quadratic Problem Solver

See also [online documentation](https://mir-optim.dpldocs.info/mir.html) (deprecated?).
See also [online documentation](http://mir-optim.libmir.org).

### Features

Expand Down
27 changes: 27 additions & 0 deletions index.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Ddoc

$(H1 Dlang BetterC Nonlinear Optimisers)

$(P The following table is a quick reference guide for which Mir Optim modules to
use for a given category of functionality.)

$(BOOKTABLE ,
$(TR
$(TH Modules)
$(TH Description)
)
$(TR
$(TDNW $(MREF mir,optim,boxcqp))
$(TD High Bound Constrained Convex Quadratic Problem Solver)
)
$(TR
$(TDNW $(MREF mir,optim,least_squares))
$(TD Nonlinear Least Squares Solver)
)
)

Macros:
TITLE=Mir Optim
WIKI=Mir Optim
DDOC_BLANKLINE=
_=
106 changes: 61 additions & 45 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,70 +1,86 @@
project('mir-optim', 'd', version : '1.0.0', license: 'BSL-1.0')

cblas_d_dep = dependency('cblas-d', fallback : ['cblas', 'cblas_dep'])
lapack_d_dep = dependency('lapack-d', fallback : ['lapack', 'lapack_dep'])
mir_algorithm_dep = dependency('mir-algorithm', fallback : ['mir-algorithm', 'mir_algorithm_dep'])
mir_blas_dep = dependency('mir-blas', fallback : ['mir-blas', 'mir_blas_dep'])
mir_core_dep = dependency('mir-core', fallback : ['mir-core', 'mir_core_dep'])
mir_lapack_dep = dependency('mir-lapack', fallback : ['mir-lapack', 'mir_lapack_dep'])
mir_random_dep = dependency('mir-random', fallback : ['mir-random', 'mir_random_dep'], default_options : ['extended=true'])

required_deps = [
cblas_d_dep,
lapack_d_dep,
mir_algorithm_dep,
mir_blas_dep,
mir_core_dep,
mir_lapack_dep,
mir_random_dep,
project('mir-optim', 'd', version: '2.0.0', license: 'BSL-1.0')

description = 'Mir Optim - Nonlinear Optimisers'

subprojects = [
'cblas-d',
'lapack-d',
'mir-algorithm',
'mir-blas',
'mir-core',
'mir-lapack',
'mir-random',
]

if target_machine.system() == 'linux'
mir_linux_kernel_dep = dependency('mir-linux-kernel', fallback : ['mir-linux-kernel', 'mir_linux_kernel_dep'])
required_deps = [required_deps, mir_linux_kernel_dep]
subprojects += 'mir-linux-kernel'
endif

mir_optim_dir = include_directories('source/')
has_cpp_headers = false

mir_optim_src = [
'source/mir/optim/least_squares.d',
'source/mir/optim/boxcqp.d',
sources_list = [
'mir/optim/boxcqp',
'mir/optim/least_squares',
]

mir_optim_lib = library(meson.project_name(),
mir_optim_src,
include_directories: mir_optim_dir,
sources = []
foreach s : sources_list
sources += 'source/' + s + '.d'
endforeach

add_project_arguments([
'-preview=dip1008',
'-lowmem',
], language: 'd')

required_deps = []

foreach p : subprojects
required_deps += dependency(p, fallback : [p, 'this_dep'])
endforeach

directories = ['source']

if has_cpp_headers
directories += 'include'
endif

directories = include_directories(directories)

this_lib = library(meson.project_name(),
sources,
include_directories: directories,
install: true,
version: meson.project_version(),
dependencies: required_deps,
)

mir_optim_dep = declare_dependency(
link_with: [mir_optim_lib],
include_directories: mir_optim_dir,
this_dep = declare_dependency(
link_with: [this_lib],
include_directories: directories,
dependencies: required_deps,
)

test_versions = ['mir_optim_test']

if has_cpp_headers
install_subdir('include/',
strip_directory :true,
install_dir: 'include/',
)
endif

install_subdir('source/',
strip_directory : true,
install_dir: 'include/d/' + meson.project_name(),
)

import('pkgconfig').generate(mir_optim_lib,
description: 'Optimisation Framework',
import('pkgconfig').generate(this_lib,
description: description,
subdirs: 'd/' + meson.project_name(),
)

if get_option('with_test')
mir_optim_dep = this_dep
mir_optim_lib = this_lib

mir_optim_test_exe = executable(meson.project_name() + '-test',
mir_optim_src,
include_directories: mir_optim_dir,
d_unittest: true,
d_module_versions: ['mir_optim_test'],
link_args: '-main',
dependencies: required_deps,
)

test(meson.project_name() + '-test', mir_optim_test_exe)

endif
test_subdirs = []
1 change: 0 additions & 1 deletion meson_options.txt

This file was deleted.

19 changes: 8 additions & 11 deletions source/mir/optim/boxcqp.d
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/++
$(H1 Bound Constrained Convex Quadratic Problem Solver)
Paper: $(HTTP www.cse.uoi.gr/tech_reports/publications/boxcqp.pdf,
BOXCQP: AN ALGORITHM FOR BOUND CONSTRAINED CONVEX QUADRATIC PROBLEMS)
Paper: $(HTTP www.cse.uoi.gr/tech_reports/publications/boxcqp.pdf, BOXCQP: AN ALGORITHM FOR BOUND CONSTRAINED CONVEX QUADRATIC PROBLEMS)
Copyright: Copyright © 2020, Symmetry Investments & Kaleidic Associates Advisory Limited
Authors: Ilya Yaroshenko
Macros:
NDSLICE = $(REF_ALTTEXT $(TT $2), $2, mir, ndslice, $1)$(NBSP)
T2=$(TR $(TDNW $(LREF $1)) $(TD $+))
+/
module mir.optim.boxcqp;

Expand Down Expand Up @@ -81,8 +76,8 @@ Solves:
Params:
P = Positive-definite Matrix, NxN
q = Linear component, N
l = Lower bounds in [-inf, +inf), N
u = Upper bounds in (-inf, +inf], N
l = Lower bounds in `[-inf, +inf$(RPAREN)`, N
u = Upper bounds in `$(LPAREN)-inf, +inf]`, N
x = solutoin, N
settings = Iteration settings (optional)
+/
Expand Down Expand Up @@ -115,8 +110,8 @@ Params:
The upper triangular part (and diagonal) of the matrix is used for temporary data and then can be resotored.
Matrix diagonal is always restored.
q = Linear component, N
l = Lower bounds in [-inf, +inf), N
u = Upper bounds in (-inf, +inf], N
l = Lower bounds in `[-inf, +inf$(RPAREN)`, N
u = Upper bounds in `$(LPAREN)-inf, +inf]`, N
x = solutoin, N
unconstrainedSolution =
work = workspace, $(LREF mir_box_qp_work_length)(N)
Expand Down Expand Up @@ -388,6 +383,8 @@ version(mir_optim_test)
unittest
{
import mir.ndslice;
import mir.algorithm.iteration;
import mir.math.common;

auto P = [
[ 2.0, -1, 0],
Expand All @@ -401,7 +398,7 @@ unittest
auto x = slice!double(q.length);

solveBoxQP(P, q, l, u, x);
assert(x == [-0.5, 2, 1]);
assert(x.equal!approxEqual([-0.5, 2, 1]));
}

package(mir) void applyBounds(T)(Slice!(T*) x, Slice!(const(T)*) l, Slice!(const(T)*) u)
Expand Down
25 changes: 24 additions & 1 deletion source/mir/optim/least_squares.d
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ version(mir_optim_test)
{
import mir.algorithm.iteration: all;
import mir.ndslice.allocation: slice;
import mir.ndslice.slice: sliced;
import mir.ndslice.slice: Slice, sliced;
import mir.blas: nrm2;

LeastSquaresSettings!double settings;
Expand Down Expand Up @@ -450,6 +450,10 @@ Params:
g = `m × n` Jacobian (optional)
tm = thread manager for finite difference jacobian approximation in case of g is null (optional)
settings = Levenberg-Marquardt data structure
m = length (dimension) of `y = f(x)`
x = initial (in) and final (out) X value
l = lower X bound
u = upper X bound
See_also: $(LREF optimize)
+/
LeastSquaresResult!T optimizeLeastSquares(alias f, alias g = null, alias tm = null, T)(
Expand Down Expand Up @@ -575,9 +579,15 @@ alias LeastSquaresThreadManager = void delegate(
Low level `extern(D)` instatiation.
Params:
settings = Levenberg-Marquardt data structure
m = length (dimension) of `y = f(x)`
x = initial (in) and final (out) X value
l = lower X bound
u = upper X bound
f = `n -> m` function
g = `m × n` Jacobian (optional)
tm = thread manager for finite difference jacobian approximation in case of g is null (optional)
work = floating point workspace length of at least $(LREF mir_least_squares_work_length)
iwork = floating point workspace length of at least $(LREF mir_least_squares_iwork_length)
+/
pragma(inline, false)
LeastSquaresResult!double optimizeLeastSquaresD
Expand Down Expand Up @@ -674,6 +684,19 @@ extern(C) @safe nothrow @nogc
gContext = context for the Jacobian (optional)
g = `m × n` Jacobian (optional)
tm = thread manager for finite difference jacobian approximation in case of g is null (optional)
m = length (dimension) of `y = f(x)`
n = length (dimension) of X
x = initial (in) and final (out) X value
l = lower X bound
u = upper X bound
f = `n -> m` function
fContext = `f` context
g = `m × n` Jacobian (optional)
gContext = `g` context
tm = thread manager for finite difference jacobian approximation in case of g is null (optional)
tmContext = `tm` context
work = floating point workspace length of at least $(LREF mir_least_squares_work_length)
iwork = floating point workspace length of at least $(LREF mir_least_squares_iwork_length)
+/
extern(C)
pragma(inline, false)
Expand Down
2 changes: 1 addition & 1 deletion subprojects/cblas.wrap → subprojects/cblas-d.wrap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[wrap-git]
directory=cblas
directory=cblas-d
url=https://github.com/DlangScience/cblas.git
revision=head
2 changes: 1 addition & 1 deletion subprojects/lapack.wrap → subprojects/lapack-d.wrap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[wrap-git]
directory=lapack
directory=lapack-d
url=https://github.com/libmir/lapack.git
revision=head

0 comments on commit 32260ef

Please sign in to comment.