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

vload from array with ndims=2 #97

Open
davidbp opened this issue Sep 1, 2022 · 4 comments
Open

vload from array with ndims=2 #97

davidbp opened this issue Sep 1, 2022 · 4 comments

Comments

@davidbp
Copy link

davidbp commented Sep 1, 2022

In the readme one can read that vload allows to load from an array

arr = Vector{Float64}(undef, 100)
xs = vload(Vec{4,Float64}, arr, 1)

But for a "matrix" this does not seem to work.

arr = Matrix{Float64}(undef, 100, 100)
xs = vload(Vec{4,Float64}, arr, 1)

Is there a way to do it?

@davidbp
Copy link
Author

davidbp commented Mar 28, 2023

Looking at the source code of vload it seems the code

Vec(Intrinsics.maskedload(ptr, mask.data, Val(Aligned), Val(Nontemporal)))

would work even if the input data of vload was any array.

If we consider

X = Int.(reshape(1:32,4,8))

to be

4×8 Matrix{Int64}:
 1  5   9  13  17  21  25  29
 2  6  10  14  18  22  26  30
 3  7  11  15  19  23  27  31
 4  8  12  16  20  24  28  32

Could the package allow us to do the following?

xs = vload(Vec{4,Float64}, X, 1) # to load [1,2,3,4]
xs = vload(Vec{4,Float64}, X, 4) # to load [5,6,7,8]
xs = vload(Vec{4,Float64}, X, 2) # to load [2,3,4,5]

@KristofferC
Copy link
Collaborator

Maybe you can use vec as a workaround for now?

@davidbp
Copy link
Author

davidbp commented Mar 28, 2023

You mean store X_as_vec = vec(X) and then work with X_as_vec ?

Yes, but I would love to be able to work with 2D arrays as mentioned above (actually it seems the backend code of vload would work with any array!).
Specially because in some cases I don't want copy the data of a matrix into a vector before calling a function.
The fact we can't do it seems to be of a limitation of the input types of vload than the code that vload ends up calling.

@KristofferC
Copy link
Collaborator

vec does not copy. And as I said, this would just be an immidiately workaround.

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

No branches or pull requests

2 participants