[Numpy-discussion] binary shift for ndarray

dmitrey dmitrey.kroshko at scipy.org
Wed May 20 15:46:22 EDT 2009


On May 20, 10:34 pm, Robert Kern <robert.k... at gmail.com> wrote:
> On Wed, May 20, 2009 at 14:24, dmitrey <dmitrey.kros... at scipy.org> wrote:
> > hi all,
>
> > suppose I have A that is numpy ndarray of floats, with shape n x n.
>
> > I want to obtain dot(A, b), b is vector of length n and norm(b)=1, but
> > instead of exact multiplication I want to approximate b as a vector
> > [+/- 2^m0, ± 2^m1, ± 2^m2 ,,, ± 2^m_n], m_i are integers, and then
> > invoke left_shift(vector_m) for rows of A.
>
> You don't shift floats. You only shift integers. For floats,
> multiplying by an integer power of 2 should be fast because of the
> floating point representation (the exponent just gets incremented or
> decremented), so just do the multiplication.
>
> > So, what is the simplest way to do it, without cycles of course? Or it
> > cannot be implemented w/o cycles with current numpy version?
>
> It might help if you showed us an example of an actual b vector
> decomposed the way you describe. Your description is ambiguous.
>
> --
> Robert Kern

For the task involved (I intend to try using it for speed up ralg
solver) it doesn't matter essentially (using ceil, floor or round),
but for example let m_i is
floor(log2(b_i)) for b_i > 1e-15,
ceil(log2(-b_i)) for b_i < - 1e-15,
for - 1e-15 <= b_i <= 1e-15 - don't modify the elements of A related
to the b_i at all.

D.



More information about the NumPy-Discussion mailing list