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

Constructor update #213

Merged
merged 20 commits into from
Aug 22, 2023
Merged

Constructor update #213

merged 20 commits into from
Aug 22, 2023

Conversation

ntjohnson1
Copy link
Collaborator

@ntjohnson1 ntjohnson1 commented Aug 19, 2023

Addresses #187 #188 (and ttensor but I didn't bother with a ticket for that) and #209. Filed #214 as follow up because tenmat's relationships between the constructors is kind of weird, so needs more thought. I followed the design discussed in #145 which I believe was the intention of the first two issues.

There were also three commits ca9629b, 862201b, 2655c82 related to simplifying some edge cases in ruff. Basically, we replaced isort with ruff but weren't applying the import sorting/removal of redundant imports to our tests. Also ruff can detect and fix unused variables etc which could be useful if we realize our tests aren't actually doing what we expect.

A few notes for where I set copy=False already. I didn't look at our profiling at all to see if this helped in our performance. I didn't do an exhaustive analysis for where we can skip the copies. Generally I looked for obvious usages where copies were redundant:

  • All inputs are newly allocated values
  • The re-used inputs are imutable (such as shape) so we don't have to worry about the reference issue

While the content is mostly unrelated I expect this to clash with #212 but they both are based off latest master so feel free to merge whichever you prefer first and I'll resolve the conflicts.(Resolved)


📚 Documentation preview 📚: https://pyttb--213.org.readthedocs.build/en/213/

@ntjohnson1 ntjohnson1 marked this pull request as ready for review August 20, 2023 13:21
@ntjohnson1 ntjohnson1 requested a review from dmdunla August 20, 2023 13:21
@dmdunla
Copy link
Collaborator

dmdunla commented Aug 20, 2023

Just updated #212. Please update as needed.

@ntjohnson1
Copy link
Collaborator Author

Great. I rebased and did a quick check so this should be ready to go now. I elaborated a bit more on the PR description in case that is useful, but feel free to let me know if anything seems weird or I misinterpreted the direction we were discussing for the interfaces.

@dmdunla
Copy link
Collaborator

dmdunla commented Aug 22, 2023

I notice differences from ktensor but only in the docs ...

Can you align the docs/source/*.rst files for the tensor classes with ktensor.rst. The docs show pyttb.ktensor() as the class constructor, whereas pyttb.sptensor.sptensor() is the class constructor with a method called __init__. The same in the latter case for tensor and ttensor. With the changes the documentation makes them appear very different, and I confused these differences for implementation differences. I think the main difference is the exclusion of __init__, but this should be confirmed.

* Remove undocumented methods/members
 * No longer need to explicitly exclude members by name
* Move all tensor types to use slots
* Don't skip __init__ since we were dropping that entire doc string
* Merges __init__ with class definition instead of a separate __init__ entry
@ntjohnson1
Copy link
Collaborator Author

I notice differences from ktensor but only in the docs ...

Can you align the docs/source/*.rst files for the tensor classes with ktensor.rst. The docs show pyttb.ktensor() as the class constructor, whereas pyttb.sptensor.sptensor() is the class constructor with a method called __init__. The same in the latter case for tensor and ttensor. With the changes the documentation makes them appear very different, and I confused these differences for implementation differences. I think the main difference is the exclusion of __init__, but this should be confirmed.

I added two commits for this since there are some stylistic preferences (details are in the commits but adding more info in case it is clearer). For the first I dropped undoc-members since if we haven't documented things I think we should skip them (this avoids needing to explicitly skip factor_matrices and other class members). Then I un-excluded __init__ so we actually got the documentation for that.

In the second commit I merged the __init__ docstring with the class doc string since that was more similar to what ktensor looked like before and I think is the desired style.

Since this brings all our tensor types into the same format in the future copy pasting should make new types match as well.

@dmdunla dmdunla merged commit 500c2cb into sandialabs:main Aug 22, 2023
@ntjohnson1 ntjohnson1 deleted the constructor_update branch August 22, 2023 18:58
DeepBlockDeepak pushed a commit that referenced this pull request Aug 23, 2023
* tensor Update __init__ and remove from_data:
* Update all usages

* tensor add explicit copy and deepcopy dunder

* sptensor update __init__ and remove from_data

* sptensor add copy and deepcopy dunder

* ttensor: Rename u to factor_matrices to match ktensor.

* ruff: Add minimal coverage to tests dir:
* We can now run ruff check . from root
* Fix imports unused, unsorted in tests
* Fix fstring errors, unused variables, etc
* All test changes via ruff check . --fix

* ttensor: update __init__ and remove from_data

* ttensor: add copy and dunder deepcopy

* ttensor: Remove from_tensor_type
* Only worked as copy constructor before so explicit copy replaces

* tensor: Remove from_tensor_type:
* Push to_tensor to all callers

* ruff: Add bugbear to catch bugs and better align with pylint

* pylint: Disable false positive if we don't remove pylint first

* sptensor: Remove from_tensor and push conversion to callers

* ttensor: Add to_tensor

* tutorials: Update to use new interfaces

* Updated doc and test to capture or ruff support of tests directory:
* Basically just keep imports reasonable and avoid logic errors (unused variables etc)

* Missed a pylint disable statement in the rebase. A search over the project no longer matches pylint

* Documentation consistency:
* Remove undocumented methods/members
 * No longer need to explicitly exclude members by name
* Move all tensor types to use slots
* Don't skip __init__ since we were dropping that entire doc string

* Documentation style:
* Merges __init__ with class definition instead of a separate __init__ entry

* Add forgotten arguments to docstring
dmdunla added a commit that referenced this pull request Sep 6, 2023
* A valid indices check added to the sptensor.from_data() class method: if an index is found that is less than zero or gte to the size of the dimension it indexes, a ValueError is raised.

* Formatting

* using tt_subscheck and shape check in from_data

* formatting the file.

* Making a check for when subs.size == 0, because this means that tt_subscheck() returns True, meaning empty subscript arrays are considered valid in the sptensor constructor.

* Constructor update (#213)

* tensor Update __init__ and remove from_data:
* Update all usages

* tensor add explicit copy and deepcopy dunder

* sptensor update __init__ and remove from_data

* sptensor add copy and deepcopy dunder

* ttensor: Rename u to factor_matrices to match ktensor.

* ruff: Add minimal coverage to tests dir:
* We can now run ruff check . from root
* Fix imports unused, unsorted in tests
* Fix fstring errors, unused variables, etc
* All test changes via ruff check . --fix

* ttensor: update __init__ and remove from_data

* ttensor: add copy and dunder deepcopy

* ttensor: Remove from_tensor_type
* Only worked as copy constructor before so explicit copy replaces

* tensor: Remove from_tensor_type:
* Push to_tensor to all callers

* ruff: Add bugbear to catch bugs and better align with pylint

* pylint: Disable false positive if we don't remove pylint first

* sptensor: Remove from_tensor and push conversion to callers

* ttensor: Add to_tensor

* tutorials: Update to use new interfaces

* Updated doc and test to capture or ruff support of tests directory:
* Basically just keep imports reasonable and avoid logic errors (unused variables etc)

* Missed a pylint disable statement in the rebase. A search over the project no longer matches pylint

* Documentation consistency:
* Remove undocumented methods/members
 * No longer need to explicitly exclude members by name
* Move all tensor types to use slots
* Don't skip __init__ since we were dropping that entire doc string

* Documentation style:
* Merges __init__ with class definition instead of a separate __init__ entry

* Add forgotten arguments to docstring

* Sptensor: Add better validation check of shape consistency
* Added as an assert so `python -O` can run to skip it if desired

* Tensor: Docstring fails on my machine because it prints dtype int64

* TTensor: Catch uncovered line from previous PR

* Black: Run black and update local test to check black to avoid hitting the error in CI.

---------

Co-authored-by: DeepBlockDeepak <[email protected]>
Co-authored-by: Danny Dunlavy <[email protected]>
Co-authored-by: Nick <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants