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

Add a BLAS wrapper for axpby #23291

Merged
merged 4 commits into from
Aug 22, 2017
Merged

Conversation

haampie
Copy link
Contributor

@haampie haampie commented Aug 17, 2017

The axpby! routine computes y = a * x + b * y and is an extension of BLAS. The current BLAS-style alternative is to do scale!(b, y); axpy!(a, x, y), which does the same amount of computational work, but requires going through memory twice.

I have not added generic fallbacks for this method because I'm unsure about #13640 which made axpy! basically xapy!. It also does not come with axpby!(a, x, indices_x, b, y, indices_y) because I think that's superfluous when when there are views.

Copy link
Member

@fredrikekre fredrikekre left a comment

Choose a reason for hiding this comment

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

Nice first PR 👍

@@ -463,6 +463,55 @@ function axpy!(alpha::Number, x::Array{T}, rx::Union{UnitRange{Ti},Range{Ti}},
y
end

"""
axpby!(a, X, b, Y)
Copy link
Member

Choose a reason for hiding this comment

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

4 space indent for the signature.

"""
axpby!(a, X, b, Y)

Overwrite `Y` with `a*X + b*Y`, where `a` and `b` are scalars. Returns `Y`.
Copy link
Member

Choose a reason for hiding this comment

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

Returns -> Return


Overwrite `Y` with `a*X + b*Y`, where `a` and `b` are scalars. Returns `Y`.

# Example:
Copy link
Member

Choose a reason for hiding this comment

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

# Example: -> # Examples


# Example:
```jldoctest
julia> x = [1.; 2; 3];
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps change to commas in the vector, i.e. [1., 2, 3] and likewise for y?

# INTEGER INCX,INCY,N
#* .. Array Arguments ..
# DOUBLE PRECISION DX(*),DY(*)
function axpby!(n::Integer, alpha::($elty), dx::Union{Ptr{$elty}, DenseArray{$elty}}, incx::Integer, beta::($elty), dy::Union{Ptr{$elty}, DenseArray{$elty}}, incy::Integer)
Copy link
Contributor

Choose a reason for hiding this comment

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

getting a bit beyond the line length recommendation

would also be more conventional to indent the whole @eval block since it's inside a for loop (or do @eval function since the begin is somewhat superfluous)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks :) don't know why the indenting got messed up

@haampie
Copy link
Contributor Author

haampie commented Aug 18, 2017

I discussed #13640 with @andreasnoack and I think it makes sense indeed to add a generic axpby that computes y = x * a + y * b.

Also the ccall should probably not use &

@andreasnoack
Copy link
Member

Bump

# INTEGER INCX,INCY,N
#* .. Array Arguments ..
# DOUBLE PRECISION DX(*),DY(*)
function axpby!(n::Integer, alpha::($elty), dx::Union{Ptr{$elty},
Copy link
Contributor

Choose a reason for hiding this comment

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

does this exist in every blas implementation? if it isn't in netlib I don't think we can unconditionally have a wrapper for it here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants