Skip to content

Instantly share code, notes, and snippets.

@miho
miho / VectorInput.groovy
Created November 19, 2016 22:36
Demonstrates how to develop a vector input component
package eu.mihosoft.vrl.user;
@ComponentInfo(name="VectorInput", category="ODE")
public class VectorInput implements java.io.Serializable {
private static final long serialVersionUID=1L;
// add your code here
@MethodInfo(name="", valueName="v", valueStyle="default", valueOptions="", hide=false)
public double[] vector(@ParamInfo(name="", style="array", options="") Double[] v) {
return v
}
// first
m = [
[1, 1, 1],
[0, 2, 5],
[2, 5, -1]
]
// second
m = [
[2, 0, 2],
package eu.mihosoft.vrl.user;
import java.text.NumberFormat;
import java.text.DecimalFormat;
@ComponentInfo(name="Vector2String", category="ODE")
public class Vector2String implements java.io.Serializable {
private static final long serialVersionUID=1L;
@OutputInfo(style="default")
package eu.mihosoft.vrl.user;
@ComponentInfo(name="JacobianInput", category="ODE")
public class JacobianInput implements Serializable, JacobianInputInterface {
private static final long serialVersionUID = 1L;
private transient Script script;
@MethodInfo(name="", valueName="", valueStyle="default", valueOptions="", hide=false)
public JacobianInputInterface setExpression(
@ParamInfo(name="<html><b>Jacobian J(t,u)</b>: <br>Param: double t, double[] <b>u</b><br>Return: double[][] <b>j</b></hmtl>", style="code", options="") String expression) {
import java.text.NumberFormat;
import java.text.DecimalFormat;
@ComponentInfo(name="Matrix2String", category="ODE")
public class Matrix2String implements java.io.Serializable {
private static final long serialVersionUID=1L;
@OutputInfo(style="editor")
public String print(@ParamInfo(name="Matrix", options="serialization=false") double[][] matrix) {
package eu.mihosoft.vrl.user;
@ComponentInfo(name="MatrixInput", category="ODE")
public class MatrixInput implements Serializable {
private static final long serialVersionUID = 1L;
private transient Script script;
@MethodInfo(name="", valueName="Matrix", valueStyle="default", valueOptions="serialization=false", hide=false)
public double[][] matrix(
@ParamInfo(name="<html><b>Matrix m</b></hmtl>", style="code", options="") String expression) {
@ComponentInfo(name="SimplePlotter", category="ODE")
public class SimplePlotter implements Serializable {
private static final long serialVersionUID = 1L;
transient private BufferedImage image;
@OutputInfo(options="fixedAspectRatio=true")
public BufferedImage plot(
@ParamInfo(name = "Input Trajectory") ArrayList<double[]> t1) {
@ComponentInfo(name="VectorRhsODE", category="ODE")
public class VectorRhsODE implements Serializable, VectorRhsODEInterface {
private static final long serialVersionUID = 1L;
private transient Script script;
@MethodInfo(name="", valueName="", valueStyle="default", valueOptions="", hide=false)
public VectorRhsODEInterface setExpression(
@ParamInfo(name="<html><b>Vector-valued Function f(t,u)</b>: <br>Param: double t, double[] <b>u</b><br>Return: double[] <b>f</b></hmtl>", style="code", options="") String expression) {
GroovyShell shell = new GroovyShell();
@ComponentInfo(name="EvaluatorTemplate", category="ODE")
public class EvaluatorTemplate implements java.io.Serializable {
private static final long serialVersionUID=1L;
public Trajectory run(
@ParamInfo(name="f(x)")
Function1D f,
@ParamInfo(name="x0", options="value=0.0D")
double x0,
@ParamInfo(name="xn", options="value=1.0D")
@miho
miho / Fib.txt
Created October 13, 2016 12:43 — forked from kabutz/Fib.txt
A simple exponential time shootout between C, Java and Swift
/*
Algorithm is exponential - very bad. It is just meant to exercise the CPU a bit and
to see what happens with different languages. Not representative of real code.
Interesting that Java beats C, thanks to HotSpot. I expected Swift to be as fast as C
at least. I also expected the compiled Swift to be faster than when run as a script.
A bit disappointed, but more time needed to see where the bottlenecks are. Plus I
need to run some real code for benchmarking.
Update: swiftc -O improved the speed quite a bit to be about the same speed as Java