Skip to content

Do not require DenseArray #2

@orenbenkiki

Description

@orenbenkiki

Right not the constructor of StridedView requires the base array to be DenseArray.
However there are types which support strides and are not DenseArray,
so would work in a StridedView - if it were not for the requirements.

How about removing the <:DenseArray from the signature? If the argument has strides, it "should" just work; if it does not, then it would fail with a more informative error message (missing strides) than today (not having a StridedView constructor).

Right now StridedView knows about some special cases (e.g. Transpose) which can be made strided w/o being DenseArray, but this doesn't work with non-Base types. I encountered this trying to pass PyArray from PythonCall to @strided, but this is just one example.

julia> using BenchmarkTools

julia> using Strided

julia> using PythonCall

julia> a = rand(4000, 4000);

julia> pa = PyArray(a);

julia> b = similar(a);

julia> pb = PyArray(b);

julia> @btime b .= (a .+ a) ./ 2;
  18.413 ms (4 allocations: 128 bytes)

julia> @btime pb .= (a .+ a) ./ 2;
  18.694 ms (4 allocations: 128 bytes)

julia> @btime @strided b .= (a .+ a) ./ 2;
  8.684 ms (17 allocations: 1.06 KiB)

julia> @btime @strided pb .= (pa .+ pa) ./ 2;
ERROR: MethodError: no method matching StridedView(::PyArray{Float64, 2, true, true, Float64})

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