|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": 1, |
| 5 | + "execution_count": 2, |
6 | 6 | "metadata": {}, |
7 | | - "outputs": [], |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "value: 1.0\n" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "data": { |
| 17 | + "text/plain": [ |
| 18 | + "Array(2., dtype=float32, weak_type=True)" |
| 19 | + ] |
| 20 | + }, |
| 21 | + "execution_count": 2, |
| 22 | + "metadata": {}, |
| 23 | + "output_type": "execute_result" |
| 24 | + } |
| 25 | + ], |
8 | 26 | "source": [ |
9 | | - "# import equinox as eqx\n", |
10 | | - "# import ihoop\n", |
11 | | - "# import jax\n", |
| 27 | + "import equinox as eqx\n", |
| 28 | + "import ihoop\n", |
| 29 | + "import jax\n", |
| 30 | + "\n", |
12 | 31 | "\n", |
13 | | - "# # works with https://github.com/patrick-kidger/equinox/pull/1028\n", |
14 | | - "# class _StrictEqxMeta(ihoop.strict._StrictMeta, eqx._module._module._ModuleMeta):\n", |
15 | | - "# def __new__(mcs, name, bases, namespace, **kwargs):\n", |
16 | | - "# return super().__new__(mcs, name, bases, namespace, **kwargs)\n", |
| 32 | + "class _StrictEqxMeta(ihoop.strict._StrictMeta, eqx._module._module._ModuleMeta):\n", |
| 33 | + " def __new__(mcs, name, bases, namespace, **kwargs):\n", |
| 34 | + " return super().__new__(mcs, name, bases, namespace, **kwargs)\n", |
17 | 35 | "\n", |
18 | 36 | "\n", |
19 | | - "# class StrictModule(eqx.Module, ihoop.Strict, metaclass=_StrictEqxMeta):\n", |
20 | | - "# pass\n", |
| 37 | + "class StrictModule(eqx.Module, ihoop.Strict, metaclass=_StrictEqxMeta):\n", |
| 38 | + " pass\n", |
21 | 39 | "\n", |
22 | 40 | "\n", |
23 | | - "# class Test(StrictModule):\n", |
24 | | - "# x: float\n", |
| 41 | + "class Test(StrictModule):\n", |
| 42 | + " x: float\n", |
25 | 43 | "\n", |
26 | | - "# def __init__(self):\n", |
27 | | - "# self.x = 1.0\n", |
| 44 | + " def __init__(self):\n", |
| 45 | + " self.x = 1.0\n", |
28 | 46 | "\n", |
29 | 47 | "\n", |
30 | | - "# t = Test()\n", |
31 | | - "# print(\"value:\", t.x)\n", |
| 48 | + "t = Test()\n", |
| 49 | + "print(\"value:\", t.x)\n", |
32 | 50 | "\n", |
33 | 51 | "\n", |
34 | | - "# def f(x):\n", |
35 | | - "# return x.x**2\n", |
| 52 | + "def f(x):\n", |
| 53 | + " return x.x**2\n", |
36 | 54 | "\n", |
37 | 55 | "\n", |
38 | | - "# jax.grad(f)(t).x" |
| 56 | + "jax.jit(jax.grad(f))(t).x" |
39 | 57 | ] |
40 | 58 | }, |
41 | 59 | { |
|
0 commit comments