-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapping of pyttb ttb functionality #291
Changes from all commits
feefeb9
afd927f
5b3f607
05a37a1
b115908
2dceaff
3311b11
982a6cd
b310115
38ec12b
f3babc9
ccef927
19680f2
8d1c32f
af30fe5
16a9f01
a7b595f
75c0f1b
ea3613e
ebd328a
7b71366
960fac8
3d0e814
a65d7cd
6d300c1
9379112
c42b3ab
4c35c29
a9fe513
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pyttb for MATLAB users | ||
====================== | ||
|
||
Already familiar with MATLAB Tensor Toolbox? To assist transitions from the | ||
Tensor Toolbox for MATLAB to pyttb, this guide documents some key differences. | ||
|
||
In the ``pyttb`` calling conventions below we'll use the following notation: | ||
- ``pyttb.<TENSOR_TYPE>``: ``X`` (and ``Y`` for binary operators) | ||
- ``<SCALAR_TYPE>``: ``a`` for scalars. | ||
|
||
.. toctree:: | ||
:glob: | ||
|
||
matlab/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
:orphan: | ||
|
||
Getting Started | ||
*************** | ||
|
||
In construction | ||
Tutorials | ||
========= | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
tutorials.rst | ||
|
||
Coming from MATLAB | ||
================== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
for_matlab_users.rst |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
General key differences | ||
----------------------- | ||
|
||
Data members | ||
^^^^^^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| ``size`` | ``shape`` | ``X.shape`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
|
||
Methods | ||
^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| ``and`` | ``logical_and`` | ``X.logical_and(Y)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``disp`` | ``__str__`` | ``X`` | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, for all the names |
||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``display`` | ``__repr__`` | ``print(X)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``eq`` | ``__eq__`` | ``X == Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``ge`` | ``__ge__`` | ``X >= Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``gt`` | ``__gt__`` | ``X > Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``ldivide`` | ``__truediv__`` | ``X / Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``le`` | ``__le__`` | ``X <= Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``lt`` | ``__lt__`` | ``X < Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``minus`` | ``__sub__`` | ``X - Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``mldivide`` | ``__truediv__`` | ``X / Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``mrdivide`` | ``__rtruediv__`` | ``X / Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``mtimes`` | ``__rmul__`` | ``a * X`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``ne`` | ``__ne__`` | ``X != Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``not`` | ``logical_not`` | ``X.logical_not(Y)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``or`` | ``logical_or`` | ``X.logical_or(Y)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``plus`` | ``__add__`` | ``X + Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``power`` | ``__pow__`` | ``X ** a`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``rdivide`` | ``__rtruediv__`` | ``X / Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``subsasgn`` | ``__setitem__`` | ``X[index] = a`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``subsref`` | ``__getitem__`` | ``X[index]`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``tenfun`` | ``tt_tenfun`` | e.g., ``pyttb.tt_tenfun(lambda x: x + 1, A)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``times`` | ``__mul__`` | ``X * Y`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``uminus`` | ``__neg__`` | ``-X`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``uplus`` | ``__pos__`` | ``+X`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``xor`` | ``logical_xor`` | ``X.logical_xor(Y)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
|
||
Copying | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be useful to note this is fairly common for non-builtin types in python and include a link. Hereish? https://docs.python.org/3/library/copy.html |
||
^^^^^^^^^^^^^^^^^^^^ | ||
Copying a ``pyttb`` tensor works differently than MATLAB. For example in MATLAB, copying a tensor ``Y`` | ||
as ``Y = X`` returns a tensor ``Y`` that is independent of ``X``. Changing the value of ``Y`` does not | ||
change the value of ``X``. However, the same syntax in ``pyttb``, ``Y = X``, returns a *shallow copy* of ``X``; | ||
the shallow copy ``Y`` is a *reference* to ``X``. For that reason, each ``pyttb`` tensor class provides a ``copy()`` | ||
method that returns a *deep copy* ``Y`` that is independent of ``X``, which is called as ``Y = X.copy()``. | ||
|
||
MATLAB methods not included in ``pyttb`` | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
- ``datadisp`` | ||
- ``isscalar`` | ||
- ``transpose`` | ||
- ``tocell`` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
``ktensor`` | ||
----------------- | ||
|
||
Data members | ||
^^^^^^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| ``lambda`` | ``weights`` | ``X.weights`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``U`` | ``factor_matrices`` | ``X.factor_matrices`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
|
||
Methods | ||
^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| | ``from_vector`` | ``ttb.ktensor.from_vector(data[:], shape)`` | | ||
| ``ktensor`` +----------------------+------------------------------------------------------------------------+ | ||
| | ``from_function`` | ``ttb.tensor.from_function(<function>, shape)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``tensor`` | ``to_tensor`` | ``X.to_tensor()`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
|
||
MATLAB methods not included in ``pyttb`` | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
* ``viz`` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
``sptenmat`` | ||
------------ | ||
|
||
Data members | ||
^^^^^^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| ``size`` | ``shape`` | ``X.shape`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``tsize`` | ``tshape`` | ``X.tshape`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
|
||
Methods | ||
^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| | ``from_data`` | ``A = ttb.sptenmat.from_data(subs, vals, rdims, cdims, tshape)`` | | ||
| +----------------------+------------------------------------------------------------------------+ | ||
| ``sptenmat`` | ``from_tensor_type`` | ``A = ttb.sptenmat.from_tensor_type(X, np.array([0]))`` | | ||
| +----------------------+------------------------------------------------------------------------+ | ||
| | ``from_array`` | ``A = ttb.sptenmat.from_data(B, rdims, cdims, tshape)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``sptensor`` | ``to_sptensor`` | ``X.to_sptensor()`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
|
||
MATLAB methods not included in ``pyttb`` | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
* ``aatx`` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
``sptensor`` | ||
---------------- | ||
|
||
Methods | ||
^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| | ``from_function`` | ``ttb.sptensor.from_function(<function>, shape)`` | | ||
| ``sptensor`` +----------------------+------------------------------------------------------------------------+ | ||
| | ``from_aggregator`` | ``ttb.sptensor.from_aggregator(subs, vals, shape, function_handle)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``tensor`` | ``to_tensor`` | ``X.to_tensor()`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
``sumtensor`` | ||
------------------- | ||
|
||
Data members | ||
^^^^^^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| ``part`` | ``parts`` | ``X.parts`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
``symktensor`` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO I think it might be clearer to just remove the placeholders. I'm not sure what the plan is for actually covering these other classes. |
||
-------------------- | ||
|
||
Data members | ||
^^^^^^^^^^^^ | ||
|
||
Methods | ||
^^^^^^^ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
``symtensor`` | ||
------------------- | ||
|
||
Data members | ||
^^^^^^^^^^^^ | ||
|
||
Methods | ||
^^^^^^^ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
``tenmat`` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a PR up now that updates the tenmat constructors. I believe this is correct currently but once Danny merges my PR this will go stale. |
||
---------------- | ||
|
||
Data members | ||
^^^^^^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| ``tsize`` | ``tshape`` | ``X.tshape`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
|
||
Methods | ||
^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| | ``from_data`` | ``B = ttb.tenmat.from_data(A.data, A.rindices, A.cindices, A.tshape)`` | | ||
| ``tenmat`` +----------------------+------------------------------------------------------------------------+ | ||
| | ``from_tensor_type`` | ``A = ttb.tenmat.from_tensor_type(X, np.array([1]))`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``tensor`` | ``to_tensor`` | ``X.to_tensor()`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
``tensor`` | ||
------------------ | ||
|
||
Methods | ||
^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| ``tensor`` | ``from_function`` | ``ttb.tensor.from_function(<function>, shape)`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``sptensor`` | ``to_sptensor`` | ``X.to_sptensor()`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
``ttensor`` | ||
----------------- | ||
|
||
Data members | ||
^^^^^^^^^^^^ | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| ``U`` | ``factors`` | ``X.factors`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
|
||
Methods | ||
^^^^^^^ | ||
|
||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| MATLAB name | ``pyttb`` name | Calling convention | | ||
+=================+======================+========================================================================+ | ||
| ``size`` | ``shape`` | ``X.shape()`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ | ||
| ``tensor`` | ``to_tensor`` | ``X.to_tensor()`` | | ||
+-----------------+----------------------+------------------------------------------------------------------------+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to mention that the tutorials are similar to the MATLAB ones if they want a hands on approach. I think that's already implied but might not be a bad idea to be explicit.