Skip to content

Commit

Permalink
modified: CMakeLists.txt
Browse files Browse the repository at this point in the history
	modified:   CMakeListsCeres.txt
	modified:   CeresHelper.js
	modified:   README.md
	modified:   build.sh
	new file:   ceresold.js
	modified:   dist/ceres.js
	modified:   docs/arrow_functions.html
	modified:   docs/json_syntax.html
	modified:   docs/powell.html
	modified:   docs/quadratic.html
	modified:   docs/rosenbrock.html
	new file:   docs/test.html
	modified:   docs/user1.html
	modified:   shortBuild.sh
  • Loading branch information
miner committed Jan 5, 2024
1 parent bc934dd commit 24344e7
Show file tree
Hide file tree
Showing 15 changed files with 7,602 additions and 3,701 deletions.
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ SET_TARGET_PROPERTIES(Ceres PROPERTIES LINK_FLAGS -g)
#string(CONCAT HELPERJS "" "")
#string(CONCAT HELPERJS "--post-js " "${CMAKE_CURRENT_SOURCE_DIR}/CeresHelper.js")
#set( CMAKE_CXX_FLAGS "-O3 -s --bind -s ASSERTIONS=1 -s MODULARIZE=1 -s EXPORT_NAME=Ceresjs -s SINGLE_FILE=1 ${HELPERJS}" )
set( CMAKE_CXX_FLAGS "-O3 -s --bind -s MODULARIZE=2 -s ALLOW_TABLE_GROWTH=1 -s EXPORT_NAME=CeresModule -s FILESYSTEM=0 -s SINGLE_FILE=1" )
#set( CMAKE_CXX_FLAGS "-O3 -s --bind -s ALLOW_TABLE_GROWTH=1 -s EXPORT_NAME=CeresModule -s FILESYSTEM=0 -s SINGLE_FILE=1 ${HELPERJS}" )
#set( CMAKE_CXX_FLAGS "-O3 -s --bind -s MODULARIZE=2 -s ALLOW_TABLE_GROWTH=1 -s EXPORT_NAME=CeresModule -s FILESYSTEM=0 -s SINGLE_FILE=1 ${HELPERJS}" )
#set( CMAKE_CXX_FLAGS "-O3 -s --bind -s ASSERTIONS=1 -s MODULARIZE=2 -s ALLOW_TABLE_GROWTH=1 -s EXPORT_NAME=CeresModule -s FILESYSTEM=0 -s SINGLE_FILE=1 ${HELPERJS}" )
#set( CMAKE_CXX_FLAGS "-O2 -s --bind -s ALLOW_TABLE_GROWTH=1 -s ASSERTIONS=1 -s SINGLE_FILE=1 ${HELPERJS}" )
#set( CMAKE_CXX_FLAGS "-O3 -s --bind -s MODULARIZE=2 -s ALLOW_TABLE_GROWTH=1 -s EXPORT_NAME=CeresModule -s FILESYSTEM=0 -s SINGLE_FILE=1" )


set( CMAKE_CXX_FLAGS "-O2 -s --bind -s MODULARIZE -s ALLOW_TABLE_GROWTH=1 -s EXPORT_NAME=CeresModule -s FILESYSTEM=0 -s SINGLE_FILE=1 -s EXPORTED_FUNCTIONS=\"['_malloc']\"" )


#set( CMAKE_CXX_FLAGS "-O1 -g4 --source-map-base -s --bind -s ALLOW_TABLE_GROWTH=1 -s SINGLE_FILE=1 ${HELPERJS}" )
432 changes: 202 additions & 230 deletions CMakeListsCeres.txt

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions CeresHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ export class Ceres {

//console.log(jsonSystem.functions)
let variables = jsonSystem.variables
jsonSystem.functions = jsonSystem.functions.map(function(x) { return Ceres.parseFunctionFromJson(x, variables); });
let jsonFunctions = jsonSystem.functions.map(function(x) { return Ceres.parseFunctionFromJson(x, variables); });

// sanitize the input to prevent injection attacks
jsonSystem.functions = jsonSystem.functions.map(Ceres.sanitizeInput);
jsonFunctions = jsonFunctions.map(Ceres.sanitizeInput);
//console.log(jsonSystem.functions)

jsonSystem.functions.forEach(jsonFunction => this.addFunction(new Function('x', `return ${jsonFunction}`)));
jsonFunctions.forEach(jsonFunction => this.addFunction(new Function('x', `return ${jsonFunction}`)));

Object.keys(jsonSystem.variables).forEach((varName, index) => {
let variable = jsonSystem.variables[varName];
Expand All @@ -182,6 +182,10 @@ export class Ceres {
});
}

generateInitialGuess(variablesMapping) {
return Object.keys(variablesMapping).map(varName => variablesMapping[varName].guess);
}

async run(jsonSystem, max_numb_iterations = 2000, parameter_tolerance = 1e-10, function_tolerance = 1e-16, gradient_tolerance = 1e-16, max_solver_time_in_seconds = 100, initial_trust_region_radius = 1e4, max_trust_region_radius = 1e16, max_num_consecutive_invalid_steps = 5) {
this.setSystemFromJson(jsonSystem);
let initial_guess = this.generateInitialGuess(jsonSystem.variables);
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can install Ceres.js by including the Ceres.js file in your HTML or js code.
```HTML
<script>
async function ceresLoading() {
const {Ceres} = await import('https://cdn.jsdelivr.net/gh/Pterodactylus/Ceres.js@master/dist/ceres.js');
const {Ceres} = await import('https://cdn.jsdelivr.net/gh/Pterodactylus/Ceres.js@master/dist/ceres.min.js');
//Your Code Here
}
Expand Down Expand Up @@ -43,7 +43,7 @@ Recently in 2024 we have introduced a new syntax for the Ceres js engine.
};
async function ceresLoading() {
const {Ceres} = await import('https://cdn.jsdelivr.net/gh/Pterodactylus/Ceres.js@master/dist/ceres.js');
const {Ceres} = await import('https://cdn.jsdelivr.net/gh/Pterodactylus/Ceres.js@master/dist/ceres.min.js');
var solver = new Ceres();
solver.run(jsonSystem);
}
Expand All @@ -60,7 +60,7 @@ Ceres.js takes a vector of residual equations that are all equal to zero when th
```html
<script>
async function ceresLoading() {
const {Ceres} = await import('https://cdn.jsdelivr.net/gh/Pterodactylus/Ceres.js@master/dist/ceres.js'); //Always imported via ES6 import
const {Ceres} = await import('https://cdn.jsdelivr.net/gh/Pterodactylus/Ceres.js@master/dist/ceres.min.js'); //Always imported via ES6 import
var fn1 = function f1(x){
return (x[0]+10*x[1]-20); //this equation is of the form f1(x) = 0
Expand Down
14 changes: 8 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash

set -x

#cd ~/Ceres.js
cwd=$(pwd)
bdir=$(pwd)/build

echo $bdir
# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git $bdir/emsdk
git clone -b "3.1.51" https://github.com/emscripten-core/emsdk.git $bdir/emsdk

# Enter that directory
cd $bdir/emsdk
Expand All @@ -24,8 +27,8 @@ source ./emsdk_env.sh

mkdir $bdir/packages
cd $bdir/packages
git clone -b "2.0.0" https://ceres-solver.googlesource.com/ceres-solver $bdir/packages/ceres-solver
git clone https://gitlab.com/libeigen/eigen.git $bdir/packages/eigen
git clone -b "2.2.0" https://ceres-solver.googlesource.com/ceres-solver $bdir/packages/ceres-solver
git clone -b "3.4.0" https://gitlab.com/libeigen/eigen.git $bdir/packages/eigen

#rm -rf ~/ceres.js-master/buildpkg
mkdir $bdir/buildpkg
Expand All @@ -46,7 +49,7 @@ mkdir $bdir/buildpkg/eigen
cd $bdir/buildpkg/eigen
#$bdir/emsdk/upstream/emscripten/emconfigure cmake $bdir/packages/eigen -DCMAKE_INSTALL_PREFIX=$bdir/installpkg
$bdir/emsdk/upstream/emscripten/emcmake cmake $bdir/packages/eigen -DCMAKE_INSTALL_PREFIX=$bdir/installpkg
$bdir/emsdk/upstream/emscripten/emmake make
$bdir/emsdk/upstream/emscripten/emmake make
make -j4 install

#rm -rf ~/ceres.js-master/buildpkg/ceres-solver
Expand All @@ -64,11 +67,10 @@ make -j4 install
mkdir $bdir/Ceres.js
cd $bdir/Ceres.js

#This line is returning an error due to problems with the ceres solver. The sed command is a workaround.
sed -i 's/include(CeresCodeGeneration)/# include(CeresCodeGeneration)/' $bdir/installpkg/lib/cmake/Ceres/CeresConfig.cmake
#$bdir/emsdk/upstream/emscripten/emconfigure cmake $cwd/ -DCMAKE_INSTALL_PREFIX=$bdir/installpkg
$bdir/emsdk/upstream/emscripten/emcmake cmake $cwd/ -DCMAKE_INSTALL_PREFIX=$bdir/installpkg
$bdir/emsdk/upstream/emscripten/emmake make
cat $cwd/CeresHelper.js >> $bdir/Ceres.js/Ceres.js
cp --verbose $bdir/Ceres.js/Ceres.js $cwd/dist/ceres.js

#~/emsdk/upstream/emscripten/emrun --browser "explorer.exe" ~/ceres.js-master/index.html
Expand Down
Loading

0 comments on commit 24344e7

Please sign in to comment.