It seems like div might do exactly what you want, although I'm not sure what it does behind the scenes.
julia> A = rand(Uint8, (100, 100)); julia> b = div(A, uint8(2)) 100x100 Array{Uint8,2}: ... Also, it seems like it keeps the type of the numerator, no matter the (integer) type of the denominator. However, if the denominator is a float it returns floats as well, which to me seems a bit silly since the results are by definition integers (but I don't know if this really is an inconsistency). On Fri, Apr 4, 2014, at 2:54, Carlos Becker wrote: Thanks Tim, that makes total sense, though I was thinking of a way of expressing this in a matlab-ish kind of way. How about defining a macro to override type promotion, similar to @inbounds? @nopromote b = A / uint8(2) I would like something shorter, but we could decide on the exact name later. Does this make sense? ------------------------------------------ Carlos On Fri, Apr 4, 2014 at 11:40 AM, Tim Holy <[1]tim.h...@gmail.com> wrote: This doesn't address your bigger question, but for truncating division by n I usually use b[i] = div(A[i], convert(eltype(A), n)). For the particular case of dividing by 2, an even better choice is b[i] = A[i] >> 1. --Tim On Friday, April 04, 2014 02:09:24 AM Carlos Becker wrote: > I've seen previous posts in this list about this, but either I missed some > of them or this particular issue is not addressed. I apologize if it is the > former. > > I have a Uint8 array and I want to divide (still in Uint8) by 2. This is > very handy when dealing with large images: no need to use more memory than > needed. > So, for example: > > A = rand(Uint8, (100,100)); # simulated image > > b = A / uint8(2) > > typeof( b ) # ==> returns Array{Float32,2} > > > I understand why one may want that, but is there a way to override it and > do the plain, element-wise uint8-by-uint8 division? > (ie ignore promotion rules) > > Thanks. References 1. mailto:tim.h...@gmail.com