[Numpy-discussion] Linear assignment problem: Jonker-Volgenant algorithm

2011-05-16 Thread Gael Varoquaux
Following a suggestion by Joseph, I am trying to implement the
Jonker-Volgenant algorithm for best linear assignment in Python, using
numpy. Unsuprisingly, it is proving time-costly. I cannot afford to spend
too much time on this, as it not to solve a problem of mine, but for the
scikits.learn. Thus I was wondering if someone had a BSD-licensed Python
version of the algorithm that he would be willing to share.

Cheers,

Gael
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] ANN: NumPy 1.6.0 [Problems on OS X w/ Python 2.6 and XCode 4]

2011-05-16 Thread Andrew Jaffe
Dear all,

I have OSX 10.6.7, XCode 4, and Python.org python 2.6.6 and 2.7.1, where 
2.7 is 64-bit.

With 2.7, easy_install successfully compiles and installs the package, 
both over the web and with an explicit download.

With 2.6, there seems to be a problem with attempting to compile the PPC 
architecture, seen in this error.

/usr/libexec/gcc/powerpc-apple-darwin10/4.0.1/as: assembler 
(/usr/bin/../libexec/gcc/darwin/ppc/as or 
/usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not 
installed

If I explicitly set CFLAGS and LDFLAGS to have -arch i386 -arch x86_64 
in them as appropriate, it seems to work...

Is this a correctable bug in the packaging, or just a quirk of my setup?

Andrew


On 15/05/2011 17:39, Ralf Gommers wrote:


 On Sat, May 14, 2011 at 3:09 PM, Charles R Harris
 charlesr.har...@gmail.com mailto:charlesr.har...@gmail.com wrote:



 On Sat, May 14, 2011 at 3:54 AM, Ralf Gommers
 ralf.gomm...@googlemail.com mailto:ralf.gomm...@googlemail.com
 wrote:

 Hi,

 I am pleased to announce the release of NumPy 1.6.0. This
 release is the result of 9 months of work, and includes many new
 features, performance improvements and bug fixes. Some
 highlights are:

- Re-introduction of datetime dtype support to deal with
 dates in arrays.
- A new 16-bit floating point type.
- A new iterator, which improves performance of many functions.


 The link is http://sourceforge.net/projects/numpy/files/NumPy/1.6.0/

 The OS X binaries are also up now.

 Ralf



 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear assignment problem: Jonker-Volgenant algorithm

2011-05-16 Thread Charles R Harris
On Mon, May 16, 2011 at 1:18 AM, Gael Varoquaux 
gael.varoqu...@normalesup.org wrote:

 Following a suggestion by Joseph, I am trying to implement the
 Jonker-Volgenant algorithm for best linear assignment in Python, using
 numpy. Unsuprisingly, it is proving time-costly. I cannot afford to spend
 too much time on this, as it not to solve a problem of mine, but for the
 scikits.learn. Thus I was wondering if someone had a BSD-licensed Python
 version of the algorithm that he would be willing to share.


I was at a presentation two weeks ago where open source software for linear
assignment was referenced, so I think some is available, although that part
went by so quickly I might have missed something. I still don't know what
linear assignment does, but that is another problem...

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear assignment problem: Jonker-Volgenant algorithm

2011-05-16 Thread josef . pktd
On Mon, May 16, 2011 at 8:53 AM, Charles R Harris
charlesr.har...@gmail.com wrote:


 On Mon, May 16, 2011 at 1:18 AM, Gael Varoquaux
 gael.varoqu...@normalesup.org wrote:

 Following a suggestion by Joseph, I am trying to implement the
 Jonker-Volgenant algorithm for best linear assignment in Python, using
 numpy. Unsuprisingly, it is proving time-costly. I cannot afford to spend
 too much time on this, as it not to solve a problem of mine, but for the
 scikits.learn. Thus I was wondering if someone had a BSD-licensed Python
 version of the algorithm that he would be willing to share.


 I was at a presentation two weeks ago where open source software for linear
 assignment was referenced, so I think some is available, although that part
 went by so quickly I might have missed something. I still don't know what
 linear assignment does, but that is another problem...

OT for the implementation question:
linear assignment in the simplest case is just optimal matching of
pairs, male-female, seller-buyer, where each side has full ranking
preferences about being matched with anyone on the other side.

more general case, college and student matching, or interns and
hospitals, where one side has a capacity to be matched with more than
one from the other side.

(more fun if you allow for side-payments, i.e. prices)

Josef



 Chuck


 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear assignment problem: Jonker-Volgenant algorithm

2011-05-16 Thread Charles R Harris
On Mon, May 16, 2011 at 7:07 AM, josef.p...@gmail.com wrote:

 On Mon, May 16, 2011 at 8:53 AM, Charles R Harris
 charlesr.har...@gmail.com wrote:
 
 
  On Mon, May 16, 2011 at 1:18 AM, Gael Varoquaux
  gael.varoqu...@normalesup.org wrote:
 
  Following a suggestion by Joseph, I am trying to implement the
  Jonker-Volgenant algorithm for best linear assignment in Python, using
  numpy. Unsuprisingly, it is proving time-costly. I cannot afford to
 spend
  too much time on this, as it not to solve a problem of mine, but for the
  scikits.learn. Thus I was wondering if someone had a BSD-licensed Python
  version of the algorithm that he would be willing to share.
 
 
  I was at a presentation two weeks ago where open source software for
 linear
  assignment was referenced, so I think some is available, although that
 part
  went by so quickly I might have missed something. I still don't know what
  linear assignment does, but that is another problem...

 OT for the implementation question:
 linear assignment in the simplest case is just optimal matching of
 pairs, male-female, seller-buyer, where each side has full ranking
 preferences about being matched with anyone on the other side.

 more general case, college and student matching, or interns and
 hospitals, where one side has a capacity to be matched with more than
 one from the other side.

 (more fun if you allow for side-payments, i.e. prices)


Thanks Josef, that makes sense in the context of the presentation I
attended.

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear assignment problem: Jonker-Volgenant algorithm

2011-05-16 Thread Hoyt Koepke
On Mon, May 16, 2011 at 12:18 AM, Gael Varoquaux
gael.varoqu...@normalesup.org wrote:
 Following a suggestion by Joseph, I am trying to implement the
 Jonker-Volgenant algorithm for best linear assignment in Python, using
 numpy. Unsuprisingly, it is proving time-costly. I cannot afford to spend
 too much time on this, as it not to solve a problem of mine, but for the
 scikits.learn. Thus I was wondering if someone had a BSD-licensed Python
 version of the algorithm that he would be willing to share.

There are a number available.  The lemon graph library
(http://lemon.cs.elte.hu/trac/lemon) has solvers for this problem and
has python bindings.  It's under the boost license (is that ok?).   It
might be a bit heavyweight for this, though, but it's great software.

-- Hoyt


+ Hoyt Koepke
+ University of Washington Department of Statistics
+ http://www.stat.washington.edu/~hoytak/
+ hoy...@gmail.com
++
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear assignment problem: Jonker-Volgenant algorithm

2011-05-16 Thread Gael Varoquaux
Hey

On Mon, May 16, 2011 at 08:49:58AM -0700, Hoyt Koepke wrote:
 On Mon, May 16, 2011 at 12:18 AM, Gael Varoquaux
 gael.varoqu...@normalesup.org wrote:
  Jonker-Volgenant algorithm for best linear assignment in Python, using
  numpy. Unsuprisingly, it is proving time-costly. I cannot afford to spend
  too much time on this, as it not to solve a problem of mine, but for the
  scikits.learn. Thus I was wondering if someone had a BSD-licensed Python
  version of the algorithm that he would be willing to share.

 There are a number available.  The lemon graph library
 (http://lemon.cs.elte.hu/trac/lemon) has solvers for this problem and
 has python bindings.  It's under the boost license (is that ok?).   It
 might be a bit heavyweight for this, though, but it's great software.

Thanks for the suggestion. Unfortunately, I do not want to add compiled
code (or an external dependency) to the scikit for this solver, as it is
a fairly minor step for us. I particular chances are that it will never
be a computational bottleneck on our poblems.

Cheers,

Gael
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear assignment problem: Jonker-Volgenant algorithm

2011-05-16 Thread Hoyt Koepke
In this case, lemon exists only as C++ header files, with no compiled
code.  A few cython functions should make it pretty simple.  However,
yeah, it is a bit heavyweight.

 Thanks for the suggestion. Unfortunately, I do not want to add compiled
 code (or an external dependency) to the scikit for this solver, as it is
 a fairly minor step for us. I particular chances are that it will never
 be a computational bottleneck on our poblems.

If that's the case, I suggest just using the Hungarian algorithm.
It's a little slower on large graphs, but it still is pretty quick.
And there's tons of implementations out there, as it's often a
standard coding project in undergrad algorithms courses.
http://en.wikipedia.org/wiki/Hungarian_algorithm has links to a few.

-- Hoyt


+ Hoyt Koepke
+ University of Washington Department of Statistics
+ http://www.stat.washington.edu/~hoytak/
+ hoy...@gmail.com
++
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear assignment problem: Jonker-Volgenant algorithm

2011-05-16 Thread Gael Varoquaux
On Mon, May 16, 2011 at 09:15:21AM -0700, Hoyt Koepke wrote:
  Thanks for the suggestion. Unfortunately, I do not want to add compiled
  code (or an external dependency) to the scikit for this solver, as it is
  a fairly minor step for us. I particular chances are that it will never
  be a computational bottleneck on our poblems.

 If that's the case, I suggest just using the Hungarian algorithm.

I might go that way: I already have pure-Python code that implements it
and that I have been using for a year or so. 

 It's a little slower on large graphs, but it still is pretty quick.

Can you put any numbers on the difference, or rule of thumbs? Is there an
algorithmic complexity difference? If so, what kind of dependency are we
talking about? Is it only in the prefactors?

Sorry for drowning you with questions, but linear programming has always
seem a dark craft to me, due to my lack of training on these issues.

Cheers,

Gael
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear assignment problem: Jonker-Volgenant algorithm

2011-05-16 Thread Hoyt Koepke
 I might go that way: I already have pure-Python code that implements it
 and that I have been using for a year or so.

Fair enough -- though you'd probably get a big speed up moving to cython.

 It's a little slower on large graphs, but it still is pretty quick.

 Can you put any numbers on the difference, or rule of thumbs? Is there an
 algorithmic complexity difference? If so, what kind of dependency are we
 talking about? Is it only in the prefactors?

Well, the hungarian algorithm has a theoretical upper bound of O(n^3),
with n being the number of nodes, which is pretty much the best you
can do if you have a dense graph and make no assumptions on
capacities.  If you have a sparse graph, other algorithms can exploit
that structure a bit more efficiently (e.g. lemon's implementation is
O(nm logn), with m being the number of edges).  Other algorithms can
use capacities and include the capacity bounds as part of the
theoretic performance of the algorithms, e.g.
http://arxiv.org/abs/1105.1569.
However, all these bounds are generally very much upper bounds and
actual practical performance varies greatly.  The hungarian algorithm
is popular mainly because it's the best one that can be coded up
efficiently in a few hundred lines of code.

Hope that answers your questions :-).

--Hoyt



+ Hoyt Koepke
+ University of Washington Department of Statistics
+ http://www.stat.washington.edu/~hoytak/
+ hoy...@gmail.com
++
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] ANN: NumPy 1.6.0 [Problems on OS X w/ Python 2.6 and XCode 4]

2011-05-16 Thread Ralf Gommers
On Mon, May 16, 2011 at 12:41 PM, Andrew Jaffe a.h.ja...@gmail.com wrote:

 Dear all,

 I have OSX 10.6.7, XCode 4, and Python.org python 2.6.6 and 2.7.1, where
 2.7 is 64-bit.

 With 2.7, easy_install successfully compiles and installs the package,
 both over the web and with an explicit download.

 With 2.6, there seems to be a problem with attempting to compile the PPC
 architecture, seen in this error.


Please just use python setup.py install, easy_install is very unreliable.



 /usr/libexec/gcc/powerpc-apple-darwin10/4.0.1/as: assembler
 (/usr/bin/../libexec/gcc/darwin/ppc/as or
 /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not
 installed

 XCode 4 does not support PPC, use version 3.2. Then it should work as
advertized.

Cheers,
Ralf
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] ANN: NumPy 1.6.0 [Problems on OS X w/ Python 2.6 and XCode 4]

2011-05-16 Thread Andrew Jaffe
On 16/05/2011 18:45, Ralf Gommers wrote:

 On Mon, May 16, 2011 at 12:41 PM, Andrew Jaffe a.h.ja...@gmail.com
 mailto:a.h.ja...@gmail.com wrote:

 Dear all,

 I have OSX 10.6.7, XCode 4, and Python.org python 2.6.6 and 2.7.1, where
 2.7 is 64-bit.

 With 2.7, easy_install successfully compiles and installs the package,
 both over the web and with an explicit download.

 With 2.6, there seems to be a problem with attempting to compile the PPC
 architecture, seen in this error.

 Please just use python setup.py install, easy_install is very unreliable.


 /usr/libexec/gcc/powerpc-apple-darwin10/4.0.1/as: assembler
 (/usr/bin/../libexec/gcc/darwin/ppc/as or
 /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not
 installed

 XCode 4 does not support PPC, use version 3.2. Then it should work as
 advertized.

Aha, thanks!

But they're both installed, but how do force this? (Does 64-bit 2.7 not 
care about PPC?)

Yours,

Andrew


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] convert integer into bit array

2011-05-16 Thread Nikolas Tautenhahn
Hi,

for some research, I need to convert lots of integers into their bit
representation - but as a bit array, not a string like
numpy.binary_repr() returns it.

So instead of
In [22]: numpy.binary_repr(23)
Out[22]: '10111


I'd need:
numpy.binary_magic(23)
Out: array([ True, False,  True,  True,  True], dtype=bool)

is there any way to do this efficiently?

best regards,
Nik
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] ANN: NumPy 1.6.0 [Problems on OS X w/ Python 2.6 and XCode 4]

2011-05-16 Thread Ralf Gommers
On Mon, May 16, 2011 at 8:30 PM, Andrew Jaffe a.h.ja...@gmail.com wrote:

 On 16/05/2011 18:45, Ralf Gommers wrote:
 
  On Mon, May 16, 2011 at 12:41 PM, Andrew Jaffe a.h.ja...@gmail.com
  mailto:a.h.ja...@gmail.com wrote:
 
  Dear all,
 
  I have OSX 10.6.7, XCode 4, and Python.org python 2.6.6 and 2.7.1,
 where
  2.7 is 64-bit.
 
  With 2.7, easy_install successfully compiles and installs the
 package,
  both over the web and with an explicit download.
 
  With 2.6, there seems to be a problem with attempting to compile the
 PPC
  architecture, seen in this error.
 
  Please just use python setup.py install, easy_install is very
 unreliable.
 
 
  /usr/libexec/gcc/powerpc-apple-darwin10/4.0.1/as: assembler
  (/usr/bin/../libexec/gcc/darwin/ppc/as or
  /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not
  installed
 
  XCode 4 does not support PPC, use version 3.2. Then it should work as
  advertized.

 Aha, thanks!

 But they're both installed, but how do force this?


You have to figure out where the right compiler is located. Then try export
CC=/path/to/compiler. Or if you have MacPorts installed you can use its
gcc_select. Or google for another solution.


 (Does 64-bit 2.7 not care about PPC?)


No, it's an Intel 32 + 64-bit bundle.

Cheers,
Ralf
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] convert integer into bit array

2011-05-16 Thread Pearu Peterson
Hi,

I have used bitarray for that

  http://pypi.python.org/pypi/bitarray/

Here


http://code.google.com/p/pylibtiff/source/browse/#svn%2Ftrunk%2Flibtiff%2Fbitarray-0.3.5-numpy

you can find bitarray with numpy support.

HTH,
Pearu

On Mon, May 16, 2011 at 9:55 PM, Nikolas Tautenhahn virt...@gmx.de wrote:

 Hi,

 for some research, I need to convert lots of integers into their bit
 representation - but as a bit array, not a string like
 numpy.binary_repr() returns it.

 So instead of
 In [22]: numpy.binary_repr(23)
 Out[22]: '10111


 I'd need:
 numpy.binary_magic(23)
 Out: array([ True, False,  True,  True,  True], dtype=bool)

 is there any way to do this efficiently?

 best regards,
 Nik
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Performance issues with numpy cross tabulation

2011-05-16 Thread Justin Thomas
Hello,

 I am having trouble with performance when trying to create a cross
tabulation using numpy.  Ideally, I would calculate each cell in the
cross tabulation separately because this gives me the greatest amount
of flexibility.  I have included some sample code as a reference and
am really looking for better approaches to the simpleLoop method.  So
far the histogram2d and histogramdd methods seem to outperform any
code I write by a factor of about 100, at least.  I chalk this up to I
just don't understand enough about numpy, yet.  Any help would be
appreciated.

Here is the test code:
import numpy as np
import time
import random


# Create a simple loop and count up the number of matching cases
# Basic cross tabulation or histogram of the data
# This approach is prefered because of the need to customize the
calculation potentially for each cell.
def simpleLoop(c):

   #number of items per inner loop
   a_cnt = len(np.unique(c[:,0]))
   b_cnt = len(np.unique(c[:,1]))
   idx = 0
   result = np.zeros(b_cnt * a_cnt)
   for i in np.unique(c[:,0]):
   for j in np.unique(c[:,1]):
   result[idx] = np.sum(1*(c[:,0] == i)  (c[:,1] == j))
   idx += 1

   result.resize(len(result)/b_cnt,b_cnt)
   return result


# Use numpys histogram method to calculate the matrix of combinations
and the number of cases in each one.
def simpleHistogram(c):

   #number of items per inner loop
   return np.histogramdd((c[:,0],c[:,1]), bins=[np.unique(c[:,
0]),range(1,11)])


# Variation1 of simple histogram
def simpleHistogram1(c):

   #number of items per inner loop
   results = []
   for i in np.unique(c[:,1]):
   results.append(np.histogramdd((c[:,0][c[:,1]==i]),
bins=[np.unique(c[:,0])]) or 0)

   return np.column_stack([result[0] for result in results])

if __name__ == '__main__':
   a = np.random.randint(1,900,20)
   b = np.random.randint(1,10,20)
   c = np.column_stack((a,b))

   print ' Simple Loop '
   start = time.time()
   results = simpleLoop(c)
   print results[0]
   print time.time() - start

   print ' Histogram dd no looping '
   start = time.time()
   results = simpleHistogram(c)
   print results[0][0]
   print time.time() - start

   print ' Histogram run 1 time for each item in column 1 (10 times)
'
   start = time.time()
   results = simpleHistogram1(c)
   print results[0]
   print time.time() - start
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] convert integer into bit array

2011-05-16 Thread Nikolas Tautenhahn
Hi,

 Here
  
 http://code.google.com/p/pylibtiff/source/browse/#svn%2Ftrunk%2Flibtiff%2Fbitarray-0.3.5-numpy
 
 you can find bitarray with numpy support.
 

Thanks, that looks promising - to get a numpy array, I need to do

numpy.array(bitarray.bitarray(numpy.binary_repr(i, l)))

for an integer i and l with i  2**l, right?

best regards,
Nik
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] convert integer into bit array

2011-05-16 Thread Tom Krauss
Here's a one-liner:

In [31]: x=np.arange(-8,8)

In [32]: x
Out[32]: array([-8, -7, -6, -5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5,  6,  7])

In [33]: 1(x[:,np.newaxis]/2**np.arange(3,-1,-1))
Out[33]:
array([[1, 0, 0, 0],
   [1, 0, 0, 1],
   [1, 0, 1, 0],
   [1, 0, 1, 1],
   [1, 1, 0, 0],
   [1, 1, 0, 1],
   [1, 1, 1, 0],
   [1, 1, 1, 1],
   [0, 0, 0, 0],
   [0, 0, 0, 1],
   [0, 0, 1, 0],
   [0, 0, 1, 1],
   [0, 1, 0, 0],
   [0, 1, 0, 1],
   [0, 1, 1, 0],
   [0, 1, 1, 1]])


On Mon, May 16, 2011 at 4:04 PM, Nikolas Tautenhahn virt...@gmx.de wrote:
 Hi,

 Here

 http://code.google.com/p/pylibtiff/source/browse/#svn%2Ftrunk%2Flibtiff%2Fbitarray-0.3.5-numpy

 you can find bitarray with numpy support.


 Thanks, that looks promising - to get a numpy array, I need to do

 numpy.array(bitarray.bitarray(numpy.binary_repr(i, l)))

 for an integer i and l with i  2**l, right?

 best regards,
 Nik
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] PyArray_ContiguousFromObject PyDECREF

2011-05-16 Thread Hyunsoo Noh
Hi,

I think it should give the memory leaking.

I have a similar issue. I am wondering if it works fine when using Py_DECREF() 
in the code. In my case, I tried to decref the PyArrayObject using Py_DECREF() 
but it gives a segmentation fault. Instead, if I use the PyArray_XDECREF(), it 
doesn't give any segmentation fault. However, I am not sure whether it gives 
any 
memory leaking issue when I use PyArray_XDECREF().

Thanks.
Hyunsoo Noh




___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] convert integer into bit array

2011-05-16 Thread Pearu Peterson
On Tue, May 17, 2011 at 12:04 AM, Nikolas Tautenhahn virt...@gmx.de wrote:

 Hi,

  Here
 
 
 http://code.google.com/p/pylibtiff/source/browse/#svn%2Ftrunk%2Flibtiff%2Fbitarray-0.3.5-numpy
 
  you can find bitarray with numpy support.
 

 Thanks, that looks promising - to get a numpy array, I need to do

 numpy.array(bitarray.bitarray(numpy.binary_repr(i, l)))

 for an integer i and l with i  2**l, right?


If l  64 and little endian is assumed then you can use the

  fromword(i, l)

method:

 from libtiff import bitarray
 barr = bitarray.bitarray(0, 'little')
 barr.fromword(3,4)
 barr
bitarray('1100')

that will append 4 bits of the value 3 to the bitarray barr.

Also check out various bitarray `to*` and `from*` methods.

HTH,
Pearu
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] convert integer into bit array

2011-05-16 Thread Pearu Peterson
On Tue, May 17, 2011 at 8:05 AM, Pearu Peterson pearu.peter...@gmail.comwrote:



 On Tue, May 17, 2011 at 12:04 AM, Nikolas Tautenhahn virt...@gmx.dewrote:

 Hi,

  Here
 
 
 http://code.google.com/p/pylibtiff/source/browse/#svn%2Ftrunk%2Flibtiff%2Fbitarray-0.3.5-numpy
 
  you can find bitarray with numpy support.
 

 Thanks, that looks promising - to get a numpy array, I need to do

 numpy.array(bitarray.bitarray(numpy.binary_repr(i, l)))

 for an integer i and l with i  2**l, right?


 If l  64 and little endian is assumed then you can use the

   fromword(i, l)

 method:

  from libtiff import bitarray
  barr = bitarray.bitarray(0, 'little')
  barr.fromword(3,4)
  barr
 bitarray('1100')

 that will append 4 bits of the value 3 to the bitarray barr.


 numpy.array(barr)
array([ True,  True, False, False], dtype=bool)

to complete the example...

Pearu


 Also check out various bitarray `to*` and `from*` methods.

 HTH,
 Pearu

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion