-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some intro articles. Shorten the readme as it now needs to cover …
…less ground, point to doc articles instead.
- Loading branch information
Showing
5 changed files
with
88 additions
and
43 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.. _doc_godot_interop: | ||
|
||
Godot Interoperability | ||
====================== | ||
|
||
Explicit Adaptations | ||
-------------------- | ||
|
||
NumDot can adapt most `Variant <https://docs.godotengine.org/en/stable/classes/class_variant.html>`__ objects explicitly. The objects are copied on conversion: | ||
|
||
.. code-block:: gdscript | ||
var packed := PackedFloat32Array([1, 2, 3]) | ||
var a := nd.add(packed, 5) | ||
packed = a.to_packed_float32_array() | ||
print(packed) # [6, 7, 8] | ||
In-Place Views | ||
-------------- | ||
|
||
In the future, we want to support in-place modification without copying. This is not yet implemented. | ||
|
||
.. code-block:: gdscript | ||
var packed := PackedFloat32Array([1, 2, 3]) | ||
var a := nd.as_array(packed) | ||
a.add(a, 5) | ||
print(packed) # [6, 7, 8] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
NumPy;xtensor;NumDot;Notes | ||
``a[0]``;``xt::view(a, { 0 })``;``a.get(0)``;Create a view. | ||
``a[:]``;``xt::view(a, { xt::all() })``;``a.get(null)``;Select all elements. | ||
``a[None]``;``xt::view(a, { xt::newaxis() })``;"``a.get(&""newaxis"")``";Insert new axis. | ||
``a[..., 0]``;``xt::view(a, { xt::ellipsis(), 0 })``;"``a.get(&""..."", 0)``";Ellipsis stands in for all other dimensions. | ||
``a[2:]``;``xt::view(a, { 2|_ })``;``a.get(nd.from(2))``;Select elements starting at index 2. | ||
``a[:2]``;``xt::view(a, { _|2 })``;``a.get(nd.to(2))``;Select elements ending at index 2. | ||
``a[2:4]``;``xt::view(a, { 2|4 })``;``a.get(nd.range(2, 4))``;Select elements starting at index 2, ending at index 4. | ||
``a[2:40:2]``;``xt::view(a, { 2|40|2 })``;``a.get(nd.range(2, 40, 2))``;Select every second element, starting at index 2, ending at index 4. | ||
"| ``a + b`` | ||
| ``np.add(a, b)``";``a + b``;``nd.add(a, b)``; | ||
"| ``a - b`` | ||
| ``np.subtract(a, b)``";``a - b``;``nd.subtract(a, b)``; | ||
"| ``a * b`` | ||
| ``np.multiply(a, b)``";``a * b``;``nd.multiply(a, b)``; | ||
"| ``a / b`` | ||
| ``np.divide(a, b)``";``a / b``;``nd.divide(a, b)``; | ||
``np.sin(a)``;``xt::sin(a)``;``nd.sin(a)``;Analogous for all trig functions. | ||
"| ``np.degrees`` | ||
| ``np.deg2rad``";``xt::deg2rad``;``nd.deg2rad``; | ||
"| ``np.radians`` | ||
| ``np.rad2deg``";``xt::rad2deg``;``nd.rad2deg``; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.. _doc_numpy_xtensor_numdot: | ||
|
||
NumPy, xtensor, and NumDot | ||
========================== | ||
|
||
NumDot attempts to recreate `NumPy <https://numpy.org>`_-like behavior, and uses `xtensor <https://github.com/xtensor-stack/xtensor>`_ under the hood. | ||
While most things are consistent across all three libraries, differences exist. | ||
|
||
Fundamental Comparison | ||
---------------------- | ||
|
||
- NumDot functions always return tensors, to avoid accidentally promoting dtypes. NumPy returned types like ``np.float32`` can be used like primitive numbers. | ||
- NumDot does not overload operators like ``+`` and ``*``, due to a `gdscript limitation <https://github.com/godotengine/godot-proposals/issues/8383>`_. | ||
- NumDot does not support subscripts (``a[start:stop:step]``, due to a `gdscript limitation <https://github.com/Ivorforce/NumDot/issues/6>`_. Instead, use ``a.get(nd.range(start, stop, step)``. | ||
- NumPy supports keyword arguments. NumDot only supports ordered arguments, due to a `gdscript limitation <https://github.com/Ivorforce/NumDot/issues/10>`_. | ||
- ``xtensor`` operations are lazy views. NumPy and NumDot operations evaluate immediately, with the exception of strideable views. | ||
|
||
Function Cheat Sheet | ||
-------------------- | ||
|
||
.. csv-table:: NumPy, xtensor and NumDot Cheat Sheet | ||
:file: numpy-xtensor-numdot.csv | ||
:widths: 25, 25, 25, 25 | ||
:delim: ; | ||
:header-rows: 1 | ||
|
||
Haven't found what you need? Try :ref:`nd <class_nd>`! |
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