Skip to content

Commit

Permalink
Update to notebook for new Format syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-griffiths committed Nov 2, 2024
1 parent 45110db commit af8c216
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 452 deletions.
144 changes: 67 additions & 77 deletions doc/bitformat_tour.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,16 @@
"id": "8e03b8012da3337d",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.215206Z",
"start_time": "2024-09-17T17:24:06.989356Z"
"end_time": "2024-11-02T11:51:02.033863Z",
"start_time": "2024-11-02T11:50:54.849849Z"
}
},
"source": [
"!pip install -q git+https://github.com/scott-griffiths/bitformat\n",
"from bitformat import Bits, Dtype, Array, Field, Format"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\r\n",
"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m23.2.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m24.2\u001B[0m\r\n",
"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\r\n"
]
}
],
"execution_count": 42
"outputs": [],
"execution_count": 19
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -92,8 +82,8 @@
"id": "53c713fcc45e4e5a",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.227607Z",
"start_time": "2024-09-17T17:24:18.223296Z"
"end_time": "2024-11-02T11:51:02.053650Z",
"start_time": "2024-11-02T11:51:02.047066Z"
}
},
"source": [
Expand All @@ -105,7 +95,7 @@
"f = Bits('0b001, u32=90, 0x5e') # Three Bits objects concatenated together"
],
"outputs": [],
"execution_count": 43
"execution_count": 20
},
{
"cell_type": "markdown",
Expand All @@ -120,8 +110,8 @@
"id": "396522c67c8e64cf",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.310652Z",
"start_time": "2024-09-17T17:24:18.306640Z"
"end_time": "2024-11-02T11:51:02.137466Z",
"start_time": "2024-11-02T11:51:02.132874Z"
}
},
"source": [
Expand All @@ -131,7 +121,7 @@
"j = Bits.pack('f16', -13.81) # A 16-bit IEEE floating point number"
],
"outputs": [],
"execution_count": 44
"execution_count": 21
},
{
"cell_type": "markdown",
Expand All @@ -150,8 +140,8 @@
"id": "d3d60f076765ee43",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.367620Z",
"start_time": "2024-09-17T17:24:18.363383Z"
"end_time": "2024-11-02T11:51:02.191967Z",
"start_time": "2024-11-02T11:51:02.187871Z"
}
},
"source": [
Expand All @@ -168,7 +158,7 @@
]
}
],
"execution_count": 45
"execution_count": 22
},
{
"cell_type": "markdown",
Expand All @@ -183,16 +173,16 @@
"id": "5351ff48f143d54",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.427715Z",
"start_time": "2024-09-17T17:24:18.423992Z"
"end_time": "2024-11-02T11:51:02.247179Z",
"start_time": "2024-11-02T11:51:02.243844Z"
}
},
"source": [
"assert g.u == 65\n",
"assert h.hex == 'abcde'"
],
"outputs": [],
"execution_count": 46
"execution_count": 23
},
{
"cell_type": "markdown",
Expand All @@ -207,8 +197,8 @@
"id": "5bbb6591db1061c6",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.492369Z",
"start_time": "2024-09-17T17:24:18.488226Z"
"end_time": "2024-11-02T11:51:02.307120Z",
"start_time": "2024-11-02T11:51:02.303324Z"
}
},
"source": [
Expand All @@ -231,7 +221,7 @@
]
}
],
"execution_count": 47
"execution_count": 24
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -265,13 +255,13 @@
"id": "18c65a86-b4c1-47a8-8cde-ff7b8f4e4345",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.547130Z",
"start_time": "2024-09-17T17:24:18.543580Z"
"end_time": "2024-11-02T11:51:02.363632Z",
"start_time": "2024-11-02T11:51:02.360543Z"
}
},
"source": [
"f_str = \"\"\"\n",
"sequence_header: [\n",
"sequence_header = (\n",
" sequence_header_code: const hex8 = 0x000001b3,\n",
" horizontal_size_value: u12,\n",
" vertical_size_value: u12,\n",
Expand All @@ -282,12 +272,12 @@
" vbv_buffer_size_value: u10,\n",
" constrained_parameters_flag: bool,\n",
" load_intra_quantiser_matrix: u1\n",
"]\n",
")\n",
"\"\"\"\n",
"f = Format(f_str) "
],
"outputs": [],
"execution_count": 48
"execution_count": 25
},
{
"cell_type": "markdown",
Expand All @@ -305,8 +295,8 @@
"metadata": {
"scrolled": true,
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.610760Z",
"start_time": "2024-09-17T17:24:18.605490Z"
"end_time": "2024-11-02T11:51:02.429022Z",
"start_time": "2024-11-02T11:51:02.420085Z"
}
},
"source": [
Expand All @@ -318,22 +308,22 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001B[32msequence_header\u001B[0m: [\n",
" \u001B[32msequence_header_code\u001B[0m: \u001B[35mconst hex8\u001B[0m = \u001B[36m000001b3\u001B[0m,\n",
" \u001B[32mhorizontal_size_value\u001B[0m: \u001B[35mu12\u001B[0m = \u001B[36m352\u001B[0m,\n",
" \u001B[32mvertical_size_value\u001B[0m: \u001B[35mu12\u001B[0m = \u001B[36m288\u001B[0m,\n",
" \u001B[32maspect_ratio_information\u001B[0m: \u001B[35mu4\u001B[0m = \u001B[36m0\u001B[0m,\n",
" \u001B[32mframe_rate_code\u001B[0m: \u001B[35mu4\u001B[0m = \u001B[36m1\u001B[0m,\n",
" \u001B[32mbit_rate_value\u001B[0m: \u001B[35mu18\u001B[0m = \u001B[36m104000\u001B[0m,\n",
" \u001B[32mmarker_bit\u001B[0m: \u001B[35mbool\u001B[0m = \u001B[36mTrue\u001B[0m,\n",
" \u001B[32mvbv_buffer_size_value\u001B[0m: \u001B[35mu10\u001B[0m = \u001B[36m880\u001B[0m,\n",
" \u001B[32mconstrained_parameters_flag\u001B[0m: \u001B[35mbool\u001B[0m = \u001B[36mFalse\u001B[0m,\n",
"\u001B[32msequence_header\u001B[0m = (\n",
" \u001B[32msequence_header_code\u001B[0m: \u001B[35mconst hex8\u001B[0m = \u001B[36m000001b3\u001B[0m\n",
" \u001B[32mhorizontal_size_value\u001B[0m: \u001B[35mu12\u001B[0m = \u001B[36m352\u001B[0m\n",
" \u001B[32mvertical_size_value\u001B[0m: \u001B[35mu12\u001B[0m = \u001B[36m288\u001B[0m\n",
" \u001B[32maspect_ratio_information\u001B[0m: \u001B[35mu4\u001B[0m = \u001B[36m0\u001B[0m\n",
" \u001B[32mframe_rate_code\u001B[0m: \u001B[35mu4\u001B[0m = \u001B[36m1\u001B[0m\n",
" \u001B[32mbit_rate_value\u001B[0m: \u001B[35mu18\u001B[0m = \u001B[36m104000\u001B[0m\n",
" \u001B[32mmarker_bit\u001B[0m: \u001B[35mbool\u001B[0m = \u001B[36mTrue\u001B[0m\n",
" \u001B[32mvbv_buffer_size_value\u001B[0m: \u001B[35mu10\u001B[0m = \u001B[36m880\u001B[0m\n",
" \u001B[32mconstrained_parameters_flag\u001B[0m: \u001B[35mbool\u001B[0m = \u001B[36mFalse\u001B[0m\n",
" \u001B[32mload_intra_quantiser_matrix\u001B[0m: \u001B[35mu1\u001B[0m = \u001B[36m1\u001B[0m\n",
"]\n"
")\n"
]
}
],
"execution_count": 49
"execution_count": 26
},
{
"cell_type": "markdown",
Expand All @@ -348,8 +338,8 @@
"id": "66e47d06-b52f-4d47-a6ff-06932443663f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.673749Z",
"start_time": "2024-09-17T17:24:18.666730Z"
"end_time": "2024-11-02T11:51:02.516644Z",
"start_time": "2024-11-02T11:51:02.512263Z"
}
},
"source": [
Expand All @@ -367,7 +357,7 @@
]
}
],
"execution_count": 50
"execution_count": 27
},
{
"cell_type": "markdown",
Expand All @@ -383,8 +373,8 @@
"id": "a5d48d44-b53f-442b-8ebc-b8336fd8e323",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.736429Z",
"start_time": "2024-09-17T17:24:18.731133Z"
"end_time": "2024-11-02T11:51:02.587897Z",
"start_time": "2024-11-02T11:51:02.584278Z"
}
},
"source": [
Expand All @@ -397,22 +387,22 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001B[32msequence_header\u001B[0m: [\n",
" \u001B[32msequence_header_code\u001B[0m: \u001B[35mconst hex8\u001B[0m = \u001B[36m000001b3\u001B[0m,\n",
" \u001B[32mhorizontal_size_value\u001B[0m: \u001B[35mu12\u001B[0m = \u001B[36m352\u001B[0m,\n",
" \u001B[32mvertical_size_value\u001B[0m: \u001B[35mu12\u001B[0m = \u001B[36m288\u001B[0m,\n",
" \u001B[32maspect_ratio_information\u001B[0m: \u001B[35mu4\u001B[0m = \u001B[36m0\u001B[0m,\n",
" \u001B[32mframe_rate_code\u001B[0m: \u001B[35mu4\u001B[0m = \u001B[36m1\u001B[0m,\n",
" \u001B[32mbit_rate_value\u001B[0m: \u001B[35mu18\u001B[0m = \u001B[36m26000\u001B[0m,\n",
" \u001B[32mmarker_bit\u001B[0m: \u001B[35mbool\u001B[0m = \u001B[36mTrue\u001B[0m,\n",
" \u001B[32mvbv_buffer_size_value\u001B[0m: \u001B[35mu10\u001B[0m = \u001B[36m880\u001B[0m,\n",
" \u001B[32mconstrained_parameters_flag\u001B[0m: \u001B[35mbool\u001B[0m = \u001B[36mFalse\u001B[0m,\n",
"\u001B[32msequence_header\u001B[0m = (\n",
" \u001B[32msequence_header_code\u001B[0m: \u001B[35mconst hex8\u001B[0m = \u001B[36m000001b3\u001B[0m\n",
" \u001B[32mhorizontal_size_value\u001B[0m: \u001B[35mu12\u001B[0m = \u001B[36m352\u001B[0m\n",
" \u001B[32mvertical_size_value\u001B[0m: \u001B[35mu12\u001B[0m = \u001B[36m288\u001B[0m\n",
" \u001B[32maspect_ratio_information\u001B[0m: \u001B[35mu4\u001B[0m = \u001B[36m0\u001B[0m\n",
" \u001B[32mframe_rate_code\u001B[0m: \u001B[35mu4\u001B[0m = \u001B[36m1\u001B[0m\n",
" \u001B[32mbit_rate_value\u001B[0m: \u001B[35mu18\u001B[0m = \u001B[36m26000\u001B[0m\n",
" \u001B[32mmarker_bit\u001B[0m: \u001B[35mbool\u001B[0m = \u001B[36mTrue\u001B[0m\n",
" \u001B[32mvbv_buffer_size_value\u001B[0m: \u001B[35mu10\u001B[0m = \u001B[36m880\u001B[0m\n",
" \u001B[32mconstrained_parameters_flag\u001B[0m: \u001B[35mbool\u001B[0m = \u001B[36mFalse\u001B[0m\n",
" \u001B[32mload_intra_quantiser_matrix\u001B[0m: \u001B[35mu1\u001B[0m = \u001B[36m1\u001B[0m\n",
"]\n"
")\n"
]
}
],
"execution_count": 51
"execution_count": 28
},
{
"cell_type": "markdown",
Expand All @@ -433,8 +423,8 @@
"id": "747a972f-0271-4b17-bc56-22068bfb3054",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:18.804561Z",
"start_time": "2024-09-17T17:24:18.797601Z"
"end_time": "2024-11-02T11:51:02.655856Z",
"start_time": "2024-11-02T11:51:02.650103Z"
}
},
"source": [
Expand All @@ -450,12 +440,12 @@
"2"
]
},
"execution_count": 52,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 52
"execution_count": 29
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -483,8 +473,8 @@
"id": "b36a7c6e-b19d-418c-b08f-138c512c2fb8",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:21.423465Z",
"start_time": "2024-09-17T17:24:18.869214Z"
"end_time": "2024-11-02T11:51:10.662557Z",
"start_time": "2024-11-02T11:51:02.782292Z"
}
},
"source": [
Expand Down Expand Up @@ -515,7 +505,7 @@
]
}
],
"execution_count": 53
"execution_count": 30
},
{
"cell_type": "markdown",
Expand All @@ -532,20 +522,20 @@
"id": "fe303d2f-9828-47e5-ab23-c22ac088e207",
"metadata": {
"ExecuteTime": {
"end_time": "2024-09-17T17:24:21.503012Z",
"start_time": "2024-09-17T17:24:21.493958Z"
"end_time": "2024-11-02T11:51:10.674308Z",
"start_time": "2024-11-02T11:51:10.669487Z"
}
},
"source": [
"import sys\n",
"is_prime[0:1000].pp(width=80)"
"is_prime[0:1000].pp()"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<Bits, fmt='\u001B[35mbin\u001B[0m, \u001B[34mhex\u001B[0m', length=\u001B[32m1000\u001B[0m bits> [\n",
"<Bits, dtype1='\u001B[35mbin\u001B[0m', dtype2='\u001B[34mhex\u001B[0m', length=\u001B[32m1000\u001B[0m bits> [\n",
"\u001B[32m 0: \u001B[0m\u001B[35m00110101 00010100 01010001 00000101 00000100 01010001\u001B[0m : \u001B[34m35 14 51 05 04 51\u001B[0m\n",
"\u001B[32m 48: \u001B[0m\u001B[35m00000100 00010100 00010001 01000001 00010000 01000000\u001B[0m : \u001B[34m04 14 11 41 10 40\u001B[0m\n",
"\u001B[32m 96: \u001B[0m\u001B[35m01000101 00010100 01000000 00000001 00010000 01010000\u001B[0m : \u001B[34m45 14 40 01 10 50\u001B[0m\n",
Expand All @@ -571,7 +561,7 @@
]
}
],
"execution_count": 54
"execution_count": 31
},
{
"cell_type": "markdown",
Expand Down
Loading

0 comments on commit af8c216

Please sign in to comment.