Skip to content

Commit 0c4ab7c

Browse files
committed
Added cdb.utils.develop package with routines for development
1 parent 3ba44d4 commit 0c4ab7c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

core/packages/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ set(PACKAGES
2828
core/manip
2929
core/solve
3030
utils/node
31+
utils/develop
3132
sympy/solvers
3233
relativity/schwarzschild
3334
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"cell_id" : 2699372611842746848,
3+
"cells" :
4+
[
5+
{
6+
"cell_id" : 5937432672654218849,
7+
"cell_origin" : "client",
8+
"cell_type" : "input",
9+
"source" : "def time_algo(algo, ex, *args, iterations=100):\n\t\"\"\"\n\tSimple function to time the execution of an algorithm with given inputs.\n\tThe arguments in *args are passed directly, but ex is copied before each\n\tinvocation and so remains unmodified. \n\n\tExample usage:\n\t\ttime_algo(sort_sum, $b + d + e + a$, iterations=20)\n\t\"\"\"\n\ts = Stopwatch()\n\tfor i in range(iterations):\n\t\ttmp := @(ex);\n\t\ts.start()\n\t\talgo(tmp, *args)\n\t\ts.stop()\n\treturn (s.seconds() + s.useconds() / 1000000) / iterations"
10+
},
11+
{
12+
"cell_id" : 15123798302514262900,
13+
"cell_origin" : "client",
14+
"cell_type" : "input",
15+
"source" : "def test_algo(expected):\n\t\"\"\"\n\tDecorator to aid defining unit tests for algorithms. This\n\tadds the boilerplate code and adds an assert for the test.\n\n\tExample usage:\n\t\t@test_algo($a + b + c$)\n\t\tdef sort_sum_test():\n\t\t\tex := b + a + c.\n\t\t\treturn sort_sum(ex)\n\t\"\"\"\n\tdef bind_args(func):\n\t\tdef test_wrapper(*args, **kwargs):\n\t\t\t__cdbkernel__ = cadabra2.__cdbkernel__\n\t\t\tresult = func(*args, **kwargs)\n\t\t\tassert result == expected, f\"Failed test: expected \\u0024{expected}\\u0024\" \\\n\t\t\t\t\t\t\t\t\tf\" but got \\u0024{result}\\u0024\"\n\t\t\treturn True\n\t\treturn test_wrapper\n\treturn bind_args"
16+
},
17+
{
18+
"cell_id" : 460414117077303111,
19+
"cell_origin" : "client",
20+
"cell_type" : "input",
21+
"source" : ""
22+
}
23+
],
24+
"description" : "Cadabra JSON notebook format",
25+
"version" : 1
26+
}

0 commit comments

Comments
 (0)