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

Copy constructor #55

Merged
merged 2 commits into from Jan 2, 2018
Merged

Conversation

nils-werner
Copy link
Contributor

This is inspired by NumPy's behaviour, where people tend to do numpy.array(a) on any iterable a, including ndarrays, just to make sure it is an ndarray.

Do you think something like this would make sense? Would save us having to do type checks in places where we just want to make sure it is a COO instance.

self.sorted = coords.sorted
self.shape = coords.shape
return

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flake8 is crapping out here. You can have a maximum of one continuous blank line inside of a function.

sparse/core.py Outdated
@@ -1366,7 +1375,7 @@ def concatenate(arrays, axis=0):

def stack(arrays, axis=0):
assert len(set(x.shape for x in arrays)) == 1
arrays = [x if type(x) is COO else COO(x) for x in arrays]
arrays = [COO(x) for x in arrays]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave these as-is, or maybe change them to arrays = [x if isinstance(x, COO) else COO(x) for x in arrays]. Generally, we want to avoid making copies where possible.

I realize what you are doing is a shallow copy, not a deep one, but in the future, if we allow manipulation of arrays (if we make the COO type mutable), we might need to change this to a deep copy, and that might be expensive.

@hameerabbasi
Copy link
Collaborator

Some minor comments.

@hameerabbasi
Copy link
Collaborator

Actually, it'd be nice to have a test for equality. Something like generating a random matrix and then COO(x) , asserting they're not the same object, and an assert_eq.

@mrocklin
Copy link
Collaborator

mrocklin commented Jan 2, 2018 via email

@hameerabbasi
Copy link
Collaborator

I don't know the convention in Python here. I know Numpy makes a deep copy but we might get away with a shallow one since we're not mutating the original data and coords in any way. I'm good with this until it raises issues (which I suspect won't be for a long time since COO is immutable).

@mrocklin
Copy link
Collaborator

mrocklin commented Jan 2, 2018 via email

@hameerabbasi hameerabbasi merged commit 9b6caa9 into pydata:master Jan 2, 2018
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.

None yet

3 participants