Modifier Function Naming Style

first-steps

#1

Say I have the following trivial function:

function foo(A, x, b=Vector{Float64}(length(x)))
  b .= A * x
  return b
end

My question is, should the function be named foo, foo!, or should I break this into two functions? While this is mainly a style question, I’d be happy to hear of any performance considerations regarding having this as one versus two functions.


#2

Make that A_mul_B!(b,A,x) if you want that to be non-allocating. The function you wrote is essentially A_mul_B! with a default arg. The weird thing is that normally the mutated variable goes first. But there’s no performance issues with this. Though I would change the header to have b=similar(x)


#3

Nice, thanks! I didn’t know about similar(.), that will be useful.