You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It may be nice to have instructions or helper functions for listing all the methods in pyttb. Not all are listed in the documentation (e.g., khatrirao). Also, it's nice just to have compact lists of names. Here is some sample code and outputs. Note also that not all functions have short descriptions and some of the short descriptions could be more illuminating, e.g., indicating when the underscore methods are actually called.
Here is code to do the listings that may be helpful....
# %%
# Script to test the pyttb module
import pyttb as ttb
import numpy as np
import inspect
# %%
# List functions in pyttb
functions_list = []
for func in dir(ttb):
if inspect.isfunction(getattr(ttb, func)):
doc = getattr(ttb, func).__doc__.split('\n')[0] if getattr(ttb, func).__doc__ else 'No description available'
functions_list.append(f"{func}: {doc}")
for func in functions_list:
print(func)
# %%
# List classes in pyttb
classes_list = []
for name, obj in inspect.getmembers(ttb, inspect.isclass):
doc = obj.__doc__.split('\n')[0] if obj.__doc__ else 'No description available'
classes_list.append(f"{name}: {doc}")
for cls in classes_list:
print(cls)
# %%
# List methods for each class in pyttb
for cls in classes_list:
class_name = cls.split(':')[0]
class_obj = getattr(ttb, class_name, None)
if class_obj:
print(f"Class: {class_name}")
print("-" * 40)
methods_list = []
for name, method in inspect.getmembers(class_obj, inspect.isfunction):
doc = method.__doc__.split('\n')[0] if method.__doc__ else 'No description available'
methods_list.append(f"{name}: {doc}")
for method in methods_list:
print(method)
print("\n")
Listing functions in pyttb:
cp_als: Compute CP decomposition with alternating least squares.
cp_apr:
export_data: Export tensor-related data to a file.
gcp_opt: Fits Generalized CP decomposition with user-specified function.
hosvd: Compute sequentially-truncated higher-order SVD (Tucker).
ignore_warnings: Disable warnings.
import_data: Import tensor data.
khatrirao:
sptendiag: Create a :class:`pyttb.sptensor` with elements along the super diagonal.
sptenrand: Create a :class:`pyttb.sptensor` with random entries and indices.
tendiag: Create a tensor with elements along super diagonal.
teneye: Create identity tensor of specified shape.
tenones: Create a tensor of all ones.
tenrand: Create a tensor with entries drawn from a uniform distribution on [0, 1].
tenzeros: Create a tensor of all zeros.
tucker_als: Compute Tucker decomposition with alternating least squares.
Listing classes in pyttb:
ktensor:
sptenmat: Store sparse tensor as a sparse matrix.
sptensor:
sptensor3: A sparse tensor variant.
sumtensor: Class for implicit sum of other tensors.
symktensor: Class for symmetric Kruskal tensors (decomposed).
symtensor: Class for storing only unique entries of symmetric tensor.
tenmat: Store tensor as a matrix.
tensor:
ttensor: Class for Tucker tensors (decomposed).
Listing methods for each class in pyttb:
Class: ktensor
----------------------------------------
__add__:
__deepcopy__: Return deep copy of ktensor.
__init__: Create a :class:`pyttb.ktensor`.
__mul__: Elementwise (including scalar) multiplication for :class:`pyttb.ktensor`.
__neg__:
__pos__:
__repr__: Return string representation of a :class:`pyttb.ktensor`.
__rmul__: Elementwise (including scalar) multiplication for :class:`pyttb.ktensor`.
__str__: Return string representation of a :class:`pyttb.ktensor`.
__sub__:
arrange: Arrange the rank-1 components of a :class:`pyttb.ktensor` in place.
copy:
double:
extract: Create a new :class:`pyttb.ktensor` with only the specified components.
fixsigns: Change the elements of a :class:`pyttb.ktensor` in place.
full:
innerprod:
isequal:
issymmetric: Return True if :class:`pyttb.ktensor` is symmetric for every permutation.
mask: Extract :class:`pyttb.ktensor` values as specified by `W`.
mttkrp:
norm: Compute the norm of a :class:`pyttb.ktensor`.
normalize: Normalize the columns of the factor matrices in place.
nvecs:
permute:
redistribute: Distribute weights of a :class:`pyttb.ktensor` to the specified mode.
score: Check if two :class:`pyttb.ktensor` with the same shape match.
symmetrize:
to_tenmat: Construct a :class:`pyttb.tenmat` from a :class:`pyttb.ktensor`.
to_tensor: Convert to tensor.
tolist: Convert :class:`pyttb.ktensor` to a list of factor matrices.
tovec: Convert :class:`pyttb.ktensor` to column vector.
ttv:
update: Update a :class:`pyttb.ktensor` in the specific dimensions.
vis:
Class: sptenmat
----------------------------------------
__deepcopy__: Return deepcopy of this sptenmat.
__init__: Construct a :class:`pyttb.sptenmat`.
__neg__:
__pos__:
__repr__: Return string representation of a :class:`pyttb.sptenmat`.
__setitem__:
__str__: Return string representation of a :class:`pyttb.sptenmat`.
copy:
double:
full:
isequal:
norm: Compute the norm of the :class:`pyttb.sptenmat`.
to_sptensor: Contruct a :class:`pyttb.sptensor` from `:class:pyttb.sptenmat`.
Class: sptensor
----------------------------------------
__add__:
__deepcopy__: Return deep copy of this sptensor.
__eq__:
__ge__:
__getitem__:
__gt__:
__init__: Construct a :class:`pyttb.sptensor`.
__le__:
__lt__:
__mul__:
__ne__:
__neg__:
__pos__:
__repr__: Return string representation of a :class:`pyttb.sptensor`.
__rmul__:
__rtruediv__:
__setitem__:
__str__: Return string representation of a :class:`pyttb.sptensor`.
__sub__:
__truediv__: Element-wise left division operator (/).
_compare: Generalized Comparison operation.
_set_subscripts: No description available
_set_subtensor: No description available
allsubs:
collapse:
contract: Contract the :class:`pyttb.sptensor` along two dimensions.
copy:
double:
elemfun: Apply a function to the nonzero elements of the :class:`pyttb.sptensor`.
extract:
find:
full:
innerprod: Compute inner product of the :class:`pyttb.sptensor` with another tensor.
isequal: Determine if the :class:`pyttb.sptensor` is equal to another tensor.
logical_and:
logical_not:
logical_or:
logical_xor:
mask: Extract values of the :class:`pyttb.sptensor` as specified by `W`.
mttkrp: Matricized tensor times Khatri-Rao product using :class:`pyttb.sptensor`.
norm: Compute the norm of the :class:`pyttb.sptensor`.
nvecs:
ones:
permute: Permute the :class:`pyttb.sptensor` dimensions.
reshape: Reshape the :class:`pyttb.sptensor` to the `new_shape`.
scale:
spmatrix: Convert 2-way :class:`pyttb.sptensor` to :class:`scipy.sparse.coo_matrix`.
squash:
squeeze: Remove singleton dimensions from the :class:`pyttb.sptensor`.
subdims:
to_sptenmat: Construct a :class:`pyttb.sptenmat` from a :class:`pyttb.sptensor`.
to_tensor: Convert to dense tensor.
ttm:
ttv:
Class: sptensor3
----------------------------------------
__init__: No description available
Class: sumtensor
----------------------------------------
__add__:
__deepcopy__: Return deepcopy of this sumtensor.
__init__: Create a :class:`pyttb.sumtensor` from a collection of tensors.
__neg__:
__pos__:
__radd__:
__repr__: Return string representation of the sumtensor.
__str__: Return string representation of the sumtensor.
copy: Make a deep copy of a :class:`pyttb.sumtensor`.
double:
full:
innerprod: Efficient inner product between a sumtensor and other `pyttb` tensors.
mttkrp: Matricized tensor times Khatri-Rao product.
norm: Compatibility Interface. Just returns 0.
to_tensor: Return sumtensor converted to dense tensor.
ttv:
Class: symktensor
----------------------------------------
__init__: No description available
Class: symtensor
----------------------------------------
__init__: No description available
Class: tenmat
----------------------------------------
__add__:
__deepcopy__: Return deep copy of this tenmat.
__getitem__:
__init__: Construct a :class:`pyttb.tenmat` from explicit components.
__mul__:
__neg__:
__pos__:
__radd__:
__repr__: Return string representation of a :class:`pyttb.tenmat`.
__rmul__:
__rsub__:
__setitem__:
__str__: Return string representation of a :class:`pyttb.tenmat`.
__sub__:
copy:
ctranspose:
double:
isequal:
norm: Frobenius norm of a :class:`pyttb.tenmat`.
to_tensor:
Class: tensor
----------------------------------------
__add__:
__deepcopy__: Return deep copy of this tensor.
__eq__:
__ge__:
__getitem__:
__gt__:
__init__: Create a :class:`pyttb.tensor` from a :class:`numpy.ndarray`.
__le__:
__lt__:
__mul__: Element-wise multiplication (*) for tensors, self*other.
__ne__:
__neg__:
__pos__:
__pow__:
__radd__: Right binary addition (+) for tensors.
__repr__: Return string representation of the tensor.
__rmul__: Element wise right multiplication (*) for tensors, other*self.
__rtruediv__: Element wise right division (/) for tensors, other/self.
__setitem__:
__str__: Return string representation of the tensor.
__sub__:
__truediv__: Element-wise left division (/) for tensors, self/other.
_matches_order: Check if provided array matches tensor memory layout.
_set_linear: No description available
_set_subscripts: No description available
_set_subtensor: No description available
_tt_to_tensor: Convert a variety of data structures to a dense tensor.
collapse:
contract:
copy: Make a deep copy of a :class:`pyttb.tensor`.
double:
exp:
find:
full:
innerprod: Efficient inner product between a tensor and other `pyttb` tensors.
isequal:
issymmetric:
logical_and:
logical_not:
logical_or:
logical_xor:
mask:
mttkrp: Matricized tensor times Khatri-Rao product.
mttkrps:
norm: Frobenius norm of the tensor.
nvecs:
permute: Permute tensor dimensions.
reshape:
scale:
squeeze: Remove singleton dimensions from the tensor.
symmetrize:
tenfun: Apply a function to each element in a tensor or tensors.
tenfun_binary: Apply a binary operation to two tensors or a tensor and a scalar.
tenfun_unary: Apply a unary operation to multiple tensors columnwise.
to_sptensor: Contruct a :class:`pyttb.sptensor` from `:class:pyttb.tensor`.
to_tenmat: Construct a :class:`pyttb.tenmat` from a :class:`pyttb.tensor`.
ttm:
ttsv:
ttt:
ttv:
Class: ttensor
----------------------------------------
__deepcopy__: Return deepcopy of class.
__init__:
__mul__: Element wise multiplication (*) for ttensors (only scalars supported).
__neg__: Unary minus (-) for ttensors.
__pos__:
__repr__: Return string representation of a tucker tensor.
__rmul__: Element wise right multiplication (*) for ttensors (only scalars supported).
__str__: Return string representation of a tucker tensor.
_validate_ttensor: Verify constructed ttensor.
copy: Make a deep copy of a :class:`pyttb.ttensor`.
double: Convert ttensor to an array of doubles.
full: Convert a ttensor to a (dense) tensor.
innerprod: Efficient inner product with a ttensor.
isequal: Component equality for ttensors.
mttkrp:
norm:
nvecs:
permute:
reconstruct:
to_tensor: Convert to tensor.
ttm: Tensor times matrix for ttensor.
ttv: TTensor times vector.
The text was updated successfully, but these errors were encountered:
This doesn't seem pythonic. I'm not sure of any package that does this, but will look around a little more.
Not all are listed in the documentation (e.g., khatrirao)
We should fix this oversight either way.
Note also that not all functions have short descriptions and some of the short descriptions could be more illuminating, e.g., indicating when the underscore methods are actually called.
I think the short description missing is just a formatting issue. I believe I fixed that on some of the open PRs. Note on the underscores, double underscore (__add__, etc) are all internal python structures well defined by the language and single underscores are denoting private methods by convention (python doesn't block them from use but intentionally hides them when using standard help(<class>) calls).
It may be nice to have instructions or helper functions for listing all the methods in pyttb. Not all are listed in the documentation (e.g., khatrirao). Also, it's nice just to have compact lists of names. Here is some sample code and outputs. Note also that not all functions have short descriptions and some of the short descriptions could be more illuminating, e.g., indicating when the underscore methods are actually called.
Here is code to do the listings that may be helpful....
Listing functions in pyttb:
Listing classes in pyttb:
Listing methods for each class in pyttb:
The text was updated successfully, but these errors were encountered: