Skip to content

Confusing example in "Copy-view behaviour and mutability" #82

Closed
@eric-wieser

Description

@eric-wieser

I find this example very confusing:

This happens when views are combined with mutating operations. This simple example illustrates that:

x = ones(1)
x += 2
y = x   # `y` *may* be a view
y -= 1  # if `y` is a view, this modifies `x`

The semantics of Python mean that y = x always makes y a "view" of x - x is y by definition.

I think the point this example is trying to make is that "if -= operates in place, this modifies x" - but the comments tell a different and incorrect story.

Either that, or the example should include a slice operation of some kind, where the library actually does have an chance to decide whether to make a copy or view.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions