Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
c4e5886
1
Parent(s):
a949e43
Show off `%%julia` magic in notebook example
Browse files- examples/pysr_demo.ipynb +42 -2
examples/pysr_demo.ipynb
CHANGED
@@ -796,7 +796,24 @@
|
|
796 |
},
|
797 |
"outputs": [],
|
798 |
"source": [
|
799 |
-
"jl.seval(\"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
800 |
]
|
801 |
},
|
802 |
{
|
@@ -821,7 +838,7 @@
|
|
821 |
" \"\"\"\n",
|
822 |
"function p(i::T) where T\n",
|
823 |
" if 0.5 < i < 1000\n",
|
824 |
-
" return T(
|
825 |
" else\n",
|
826 |
" return T(NaN)\n",
|
827 |
" end\n",
|
@@ -830,6 +847,29 @@
|
|
830 |
")"
|
831 |
]
|
832 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
{
|
834 |
"cell_type": "markdown",
|
835 |
"metadata": {
|
|
|
796 |
},
|
797 |
"outputs": [],
|
798 |
"source": [
|
799 |
+
"jl.seval(\"using Primes: prime\")"
|
800 |
+
]
|
801 |
+
},
|
802 |
+
{
|
803 |
+
"cell_type": "markdown",
|
804 |
+
"metadata": {},
|
805 |
+
"source": [
|
806 |
+
"Note that PySR should automatically load the `juliacall.ipython` extension for you,\n",
|
807 |
+
"which means that you can also execute Julia code in the notebook using the `%%julia` magic:"
|
808 |
+
]
|
809 |
+
},
|
810 |
+
{
|
811 |
+
"cell_type": "code",
|
812 |
+
"execution_count": null,
|
813 |
+
"metadata": {},
|
814 |
+
"outputs": [],
|
815 |
+
"source": [
|
816 |
+
"%julia using Primes: prime"
|
817 |
]
|
818 |
},
|
819 |
{
|
|
|
838 |
" \"\"\"\n",
|
839 |
"function p(i::T) where T\n",
|
840 |
" if 0.5 < i < 1000\n",
|
841 |
+
" return T(prime(round(Int, i)))\n",
|
842 |
" else\n",
|
843 |
" return T(NaN)\n",
|
844 |
" end\n",
|
|
|
847 |
")"
|
848 |
]
|
849 |
},
|
850 |
+
{
|
851 |
+
"cell_type": "markdown",
|
852 |
+
"metadata": {},
|
853 |
+
"source": [
|
854 |
+
"Or, equivalently:"
|
855 |
+
]
|
856 |
+
},
|
857 |
+
{
|
858 |
+
"cell_type": "code",
|
859 |
+
"execution_count": null,
|
860 |
+
"metadata": {},
|
861 |
+
"outputs": [],
|
862 |
+
"source": [
|
863 |
+
"%%julia\n",
|
864 |
+
"function p(i::T) where T\n",
|
865 |
+
" if 0.5 < i < 1000\n",
|
866 |
+
" return T(prime(round(Int, i)))\n",
|
867 |
+
" else\n",
|
868 |
+
" return T(NaN)\n",
|
869 |
+
" end\n",
|
870 |
+
"end"
|
871 |
+
]
|
872 |
+
},
|
873 |
{
|
874 |
"cell_type": "markdown",
|
875 |
"metadata": {
|