Created
May 13, 2022 20:22
-
-
Save ajfriend/167afffde74bc08b0e809e10b92ecde3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "8453a67e-337e-4a4c-964e-c36d0ac819f2", | |
"metadata": {}, | |
"source": [ | |
"# Python version with the `basic_int` API" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "e8aaaedc-8d51-449e-be1b-e4c64862b06f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"614553206126542847\n" | |
] | |
} | |
], | |
"source": [ | |
"import h3.api.basic_int as h3\n", | |
"\n", | |
"a = 619056805752340479\n", | |
"b = h3.h3_to_parent(a, 8)\n", | |
"print(b)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "d7bbea1a-50ef-494b-8e05-dea1343430f0", | |
"metadata": {}, | |
"source": [ | |
"# Cython versions\n", | |
"\n", | |
"https://cython.readthedocs.io/en/latest/src/quickstart/build.html#using-the-jupyter-notebook" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "4aa349f5-6ac5-424f-8f50-9f978acb6c82", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%load_ext Cython" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "1767e750-bce9-4933-898e-31f78066a4e1", | |
"metadata": {}, | |
"source": [ | |
"## Using C functions\n", | |
"\n", | |
"Uses the C library functions from https://github.com/uber/h3/blob/master/src/h3lib/include/h3api.h.in" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "fc866dee-d1b0-43a0-8958-dbc6ee108d62", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"614553206126542847\n" | |
] | |
} | |
], | |
"source": [ | |
"%%cython\n", | |
"\n", | |
"from h3._cy.h3lib cimport H3int, h3ToParent\n", | |
"\n", | |
"cdef:\n", | |
" H3int a = 619056805752340479\n", | |
"\n", | |
"b = h3ToParent(a, 8)\n", | |
"print(b)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "57e2c861-0243-433a-b813-dfc3a6411733", | |
"metadata": {}, | |
"source": [ | |
"## Using Cython functions\n", | |
"\n", | |
"Uses the Cython functions listed in https://github.com/uber/h3-py/blob/master/src/h3/_cy/__init__.py" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "45dfa1fa-0450-454b-ac91-10c2b2e241dc", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"614553206126542847\n" | |
] | |
} | |
], | |
"source": [ | |
"%%cython\n", | |
"\n", | |
"from h3._cy.h3lib cimport H3int\n", | |
"from h3._cy.cells cimport parent\n", | |
"\n", | |
"cdef:\n", | |
" H3int a = 619056805752340479\n", | |
"\n", | |
"b = parent(a, 8)\n", | |
"print(b)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "02072a2d-b16e-4d1b-9196-e9513446b8e9", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.10.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment