Skip to content
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

Creating a tensor from array versus a numpy array #337

Open
tgkolda opened this issue Nov 13, 2024 · 2 comments
Open

Creating a tensor from array versus a numpy array #337

tgkolda opened this issue Nov 13, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@tgkolda
Copy link

tgkolda commented Nov 13, 2024

It seems that ttb.tensor only supports creating a tensor from a numpy array. Is there any reason it cannot create a tensor directly from a Python array?

Right now, the user has to type the following:

X = ttb.tensor(np.array([8, 9, 2, 9, 6, 1, 3, 5]), (2, 2, 2));

I'm suggesting instead that the following should be possible:

X = ttb.tensor([8, 9, 2, 9, 6, 1, 3, 5], (2, 2, 2));

Also, I'm not sure where the creation is clearly documented. I sort of inferred that it had to be a numpy array, but it's not clearly stated nor is there any example where you specify a simple tensor like this one.

@ntjohnson1
Copy link
Collaborator

I see the potential additional user friendliness to the later. Will share some thoughts but I'd be interested to hear Danny's thoughts on it.

A python list is effectively a list of pointers so it can be a collection of arbitrary types, and isn't contiguous in memory. Internally we'd have to convert to a numpy array, and make a decision about when to complain that the conversion isn't appropriately accurate. If we do make this move we can probably generate a utility to help for it, and we'd want to push that interface change out across the project, since right now I think for all numeric containers we've be requiring numpy arrays as the defacto python standard.

As for the documentation can you clarify what you were looking at?
help(ttb.tensor) vs https://pyttb.readthedocs.io/en/latest/tensor.html we do have types in the signature, and a very basic example where we provide a numpy array to construct a tensor. But I'm not sure where a new user looks first.

@ntjohnson1 ntjohnson1 added the enhancement New feature or request label Nov 14, 2024
@tgkolda
Copy link
Author

tgkolda commented Nov 14, 2024

I was looking at the tutorials. I think most folks will start there, though they are in a sort of random order rather than structured like in the MATLAB help pages. I was looking here: https://pyttb.readthedocs.io/en/latest/tutorial/class_tensor.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants