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

Small feature request: hvec function #37768

Open
Deduction42 opened this issue Sep 26, 2020 · 1 comment
Open

Small feature request: hvec function #37768

Deduction42 opened this issue Sep 26, 2020 · 1 comment
Labels
domain:arrays [a, r, r, a, y, s]

Comments

@Deduction42
Copy link

Hello, I know you guys have a vec function that essentially works like this

vec(a::AbstractArray) = reshape(a,length(a))
vec(a::AbstractVector) = a

I find myself having to write an hvec function to create horizontal vectors out of arrays for convenience.

hvec(x::AbstractArray) = reshape(x, 1, :)

Using something like vec(x)' only works if x is numeric. When trying to broadcast an operation to operate on every pair of elements in x and y to form a matrix, it's very helpful to be able to quickly construct a vertical vector for x and a horizontal one for y.

M = some_scalar_operation.( vec(x), hvec(y) )

Do you think it would be reasonable to put hvec into base or make vec(x)' work for vectors of all types?

@jebej
Copy link
Contributor

jebej commented Sep 26, 2020

hvec(x::AbstractArray) = reshape(x, 1, :)

That function seems reasonable.

or make vec(x)' work for vectors of all types?

This won't happen, it was decided a while ago that this syntax (') would be for linear algebra, and not for reshaping of arrays of arbitrary objects (see e.g. #20978 & #21037).

As a sidenote, be careful with the ' operator: it's a complex transpose, and will therefore conjugate each element of the vector.

@JeffBezanson JeffBezanson added the domain:arrays [a, r, r, a, y, s] label Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s]
Projects
None yet
Development

No branches or pull requests

3 participants