GithubHelp home page GithubHelp logo

src-d / lapjv Goto Github PK

View Code? Open in Web Editor NEW
243.0 11.0 28.0 307 KB

Linear Assignmment Problem solver using Jonker-Volgenant algorithm - Python 3 native module.

License: MIT License

C++ 82.35% Python 17.65%

lapjv's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lapjv's Issues

Broken PyPI packages.

I cannot import lapjv when using version 1.3.12. See this fresh in a docker:

(test_env) root@19fe463947e8:/workspace# pip list | grep lapjv
lapjv                         1.3.12
(test_env) root@19fe463947e8:/workspace#  python -c "import lapjv"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'lapjv'

Downgrading to 1.3.11 does not work either but it could be that I've something missing in my configuration 'cos its gcc who fails (although I was expecting to get a whl rather than an a source):

(test_env) root@19fe463947e8:/workspace# pip install lapjv==1.3.11 -q
  ERROR: Command errored out with exit status 1:
   command: /opt/conda/envs/test_env/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q_vgkdfk/lapjv_2d7f287e40a34d0ab1c389a7a666a146/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q_vgkdfk/lapjv_2d7f287e40a34d0ab1c389a7a666a146/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-u6g16myx
       cwd: /tmp/pip-install-q_vgkdfk/lapjv_2d7f287e40a34d0ab1c389a7a666a146/
  Complete output (16 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'lapjv' extension
  creating build
  creating build/temp.linux-x86_64-3.7
  gcc -pthread -B /opt/conda/envs/test_env/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/envs/test_env/lib/python3.7/site-packages/numpy/core/include -I/opt/conda/envs/test_env/include/python3.7m -c python.cc -o build/temp.linux-x86_64-3.7/python.o -fopenmp -std=c++17 -march=native -ftree-vectorize
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  python.cc:9:8: error: ‘SIMDFlags’ does not name a type
   static SIMDFlags simd_flags = SIMDFlags();
          ^~~~~~~~~
  python.cc: In function ‘double call_lap(int, const void*, bool, int*, int*, void*, void*)’:
  python.cc:72:18: error: ‘simd_flags’ was not declared in this scope
     bool hasAVX2 = simd_flags.hasAVX2();
                    ^~~~~~~~~~
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for lapjv
    ERROR: Command errored out with exit status 1:
     command: /opt/conda/envs/test_env/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q_vgkdfk/lapjv_2d7f287e40a34d0ab1c389a7a666a146/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q_vgkdfk/lapjv_2d7f287e40a34d0ab1c389a7a666a146/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-z5iv5kj0/install-record.txt --single-version-externally-managed --compile --install-headers /opt/conda/envs/test_env/include/python3.7m/lapjv
         cwd: /tmp/pip-install-q_vgkdfk/lapjv_2d7f287e40a34d0ab1c389a7a666a146/
    Complete output (16 lines):
    running install
    running build
    running build_ext
    building 'lapjv' extension
    creating build
    creating build/temp.linux-x86_64-3.7
    gcc -pthread -B /opt/conda/envs/test_env/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/conda/envs/test_env/lib/python3.7/site-packages/numpy/core/include -I/opt/conda/envs/test_env/include/python3.7m -c python.cc -o build/temp.linux-x86_64-3.7/python.o -fopenmp -std=c++17 -march=native -ftree-vectorize
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    python.cc:9:8: error: ‘SIMDFlags’ does not name a type
     static SIMDFlags simd_flags = SIMDFlags();
            ^~~~~~~~~
    python.cc: In function ‘double call_lap(int, const void*, bool, int*, int*, void*, void*)’:
    python.cc:72:18: error: ‘simd_flags’ was not declared in this scope
       bool hasAVX2 = simd_flags.hasAVX2();
                      ^~~~~~~~~~
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /opt/conda/envs/test_env/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q_vgkdfk/lapjv_2d7f287e40a34d0ab1c389a7a666a146/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q_vgkdfk/lapjv_2d7f287e40a34d0ab1c389a7a666a146/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-z5iv5kj0/install-record.txt --single-version-externally-managed --compile --install-headers /opt/conda/envs/test_env/include/python3.7m/lapjv Check the logs for full command output.

Usuing 1.3.10 works, though:

(test_env) root@19fe463947e8:/workspace# pip install lapjv==1.3.10 -q
(test_env) root@19fe463947e8:/workspace# python -c "import lapjv"
(test_env) root@19fe463947e8:/workspace# 

LAPJV is not giving the correct result.

I followed the instructions and installed the package using pip3 install lapjv. However, when I test it with a simple matrix, the results are incorrect. I compared the results with scipy linear_sum_assignment.

from lapjv import lapjv
from scipy.optimize import linear_sum_assignment as lsa
import numpy as np
# cost_matrix = np.array([[9.0, 7.6, 7.5,100.0],[3.5, 8.5, 5.5,100.0],[12.5, 9.5, 9.0,100.0],[4.5, 11.0, 9.5,100.0]])
cost_matrix = np.array([[9.0, 7.6, 7.5,7.0],[3.5, 8.5, 5.5,6.5],[12.5, 9.5, 9.0,10.5],[4.5, 11.0, 9.5,11.5]])
row_ind, col_ind, _ = lapjv(cost_matrix)
cost_tot = 0
print("===LAPJV sol: ")
for id in range (len(row_ind)):
    i = row_ind[id]
    j = col_ind[id]
    print (f"track {i} match det {j} cost {cost_matrix[i,j]}")
    cost_tot += cost_matrix[i,j]
print (f"cost total = {cost_tot}")

row_ind1, col_ind1= lsa(cost_matrix)
print("===LSA sol: ")
cost_tot = 0
for id in range (len(row_ind)):
    i = row_ind1[id]
    j = col_ind1[id]
    print (f"track {i} match det {j} cost {cost_matrix[i,j]}")


    cost_tot += cost_matrix[i,j]
print (f"cost total = {cost_tot}")

I get

===LAPJV sol: 
track 3 match det 3 cost 11.5
track 2 match det 2 cost 9.0
track 1 match det 1 cost 8.5
track 0 match det 0 cost 9.0
cost total = 38.0
===LSA sol: 
track 0 match det 3 cost 7.0
track 1 match det 2 cost 5.5
track 2 match det 1 cost 9.5
track 3 match det 0 cost 4.5
cost total = 26.5

I also took the cpp code in the repo created a main. The project is here lapjv-cpp.zip and run the same squared matrix and I get this

9.000000 7.600000 7.500000 7.000000 
3.500000 8.500000 5.500000 6.500000 
12.500000 9.500000 9.000000 10.500000 
4.500000 11.000000 9.500000 11.500000 
start
Beginning lapjv method.
AVX2: enabled
lapjv: COLUMN REDUCTION finished
lapjv: REDUCTION TRANSFER finished
lapjv: AUGMENTING ROW REDUCTION 1 / 2
lapjv: AUGMENTING ROW REDUCTION 2 / 2
lapjv: AUGMENT SOLUTION finished
lapjv: optimal cost calculated
Track 2 assigned to detect 3.  Cost: 10.5
Track 1 assigned to detect 1.  Cost: 8.5
Track 3 assigned to detect 0.  Cost: 4.5
Track 0 assigned to detect 2.  Cost: 7.5
Total cost = 31


dim     4 - lap cost  3.500 - runtime  0.017 ms

Something is up with this code. I would appreciate any help with it. Am I missing something?

Illegal Instruction (core dumped) error

May I ask how to solve the "Illegal Instruction (core dumped)" error? I have googled online and checked that avx is one of my flags when I ran lscpu on Ubuntu 16.04 terminal. Here are my specifications:

Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 12
On-line CPU(s) list: 0-11
Thread(s) per core: 2
Core(s) per socket: 6
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 62
Model name: Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz
Stepping: 4
CPU MHz: 1530.757
CPU max MHz: 3900.0000
CPU min MHz: 1200.0000
BogoMIPS: 6983.31
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 12288K
NUMA node0 CPU(s): 0-11
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm cpuid_fault epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts flush_l1d

Could it be other issues?

Optimisations for rectangular matrices

Hi,

I was looking for a fast linear assignment solver and came across this project. Great work! Thank you.

It compares well against Scipy's linear_sum_assignment on square matrices, but is significantly worse on rectangular matrices.
The implementation appears to not support rectangular matrices out of the box, so to test it against Scipy I padded the cost matrix with high values to make it square.

In this setting the algorithm this implementation was much slower than the Scipy implementation on rectangular matrices (and still faster than Scipy implementation on the padded matrix).

I was wondering if the this algorithm could be made to work efficiently on rectangular matrices, or whether there are perhaps some fundamental limitations that would prevent this.

Thanks,
Alexey

pip install lapjv doesn't work, but compiling from source does.

I tried to install lapjv using pip/pip3 install lapjv on both Windows and Mac and got errors.

Downloading the source files and compiling / installing via setup.py works fine. Any ideas?

Windows error installing via pip:

C:\WINDOWS\system32>pip install lapjv
Collecting lapjv
  Using cached lapjv-1.3.0.tar.gz
Requirement already satisfied: numpy in c:\users\chaos\anaconda3\lib\site-packages (from lapjv)
Building wheels for collected packages: lapjv
  Running setup.py bdist_wheel for lapjv ... error
  Complete output from command C:\Users\chaos\Anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\chaos\\AppData\\Local\\Temp\\pip-build-q8o85_ei\\lapjv\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\chaos\AppData\Local\Temp\tmp1orybszxpip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_ext
  building 'lapjv' extension
  creating build
  creating build\temp.win-amd64-3.5
  creating build\temp.win-amd64-3.5\Release
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\chaos\Anaconda3\lib\site-packages\numpy\core\include -IC:\Users\chaos\Anaconda3\include -IC:\Users\chaos\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\winrt" /EHsc /Tppython.cc /Fobuild\temp.win-amd64-3.5\Release\python.obj -fopenmp -std=c++11 -march=native -ftree-vectorize
  cl : Command line warning D9002 : ignoring unknown option '-fopenmp'
  cl : Command line warning D9002 : ignoring unknown option '-std=c++11'
  cl : Command line warning D9002 : ignoring unknown option '-march=native'
  cl : Command line warning D9002 : ignoring unknown option '-ftree-vectorize'
  python.cc
  c:\users\chaos\appdata\local\temp\pip-build-q8o85_ei\lapjv\lap.h(7): error C2988: unrecognizable template declaration/definition
  c:\users\chaos\appdata\local\temp\pip-build-q8o85_ei\lapjv\lap.h(7): error C2059: syntax error: '('
  c:\users\chaos\appdata\local\temp\pip-build-q8o85_ei\lapjv\lap.h(215): error C2143: syntax error: missing ';' before '{'
  c:\users\chaos\appdata\local\temp\pip-build-q8o85_ei\lapjv\lap.h(215): error C2447: '{': missing function header (old-style formal list?)
  python.cc(16): error C2065: 'py_lapjv': undeclared identifier
  python.cc(102): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
  python.cc(123): error C3861: 'lap': identifier not found
  python.cc(130): error C3861: 'lap': identifier not found
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

Building from source repo:

running build
running build_ext
building 'lapjv' extension
creating build
creating build\temp.win-amd64-3.5
creating build\temp.win-amd64-3.5\Release
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\chaos\Anaconda3\lib\site-packages\numpy\core\include -IC:\Users\chaos\Anaconda3\include -IC:\Users\chaos\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\winrt" /EHsc /Tppython.cc /Fobuild\temp.win-amd64-3.5\Release\python.obj /openmp /std:c++latest /arch:AVX2
python.cc
python.cc(102): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
python.cc(124): warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
python.cc(131): warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
creating C:\Users\chaos\Downloads\lapjv-master\lapjv-master\build\lib.win-amd64-3.5
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\chaos\Anaconda3\libs /LIBPATH:C:\Users\chaos\Anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.14393.0\um\x64" /EXPORT:PyInit_lapjv build\temp.win-amd64-3.5\Release\python.obj /OUT:build\lib.win-amd64-3.5\lapjv.cp35-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.5\Release\lapjv.cp35-win_amd64.lib
python.obj : warning LNK4197: export 'PyInit_lapjv' specified multiple times; using first specification
   Creating library build\temp.win-amd64-3.5\Release\lapjv.cp35-win_amd64.lib and object build\temp.win-amd64-3.5\Release\lapjv.cp35-win_amd64.exp
Generating code
Finished generating code

Install fails on MacOS 10.13.6

Hi!

I get an error when trying to install when using pip. I'm using MacOS 10.13.6, using Conda's default environment. I have the following clang/g++ setup.

g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Googling the errors points to std=c++11, but "Darwin": ["-std=c++11", "-march=native", "-ftree-vectorize"] works, as the command in the error log uses these flags. The closed issues related to installation on Mac didn't help.

I'm using a default conda environment with python 3.7 and pip 19.0.1.

Here's the dump:

pip install lapjv
Collecting lapjv
  Using cached https://files.pythonhosted.org/packages/98/75/d64ba8523db4168646a8f8d74f104c4eaea820ad0464a6b41ff1e692840f/lapjv-1.3.1.tar.gz
Requirement already satisfied: numpy in /anaconda3/envs/mot/lib/python3.7/site-packages (from lapjv) (1.15.4)
Building wheels for collected packages: lapjv
  Building wheel for lapjv (setup.py) ... error
  Complete output from command /anaconda3/envs/mot/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/q0/yv4nhd652f5_70s5r6tqhr3m0000gn/T/pip-install-avpiyzzw/lapjv/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /private/var/folders/q0/yv4nhd652f5_70s5r6tqhr3m0000gn/T/pip-wheel-_7qalaoh --python-tag cp37:
  running bdist_wheel
  running build
  running build_ext
  building 'lapjv' extension
  creating build
  creating build/temp.macosx-10.7-x86_64-3.7
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/anaconda3/envs/mot/include -arch x86_64 -I/anaconda3/envs/mot/include -arch x86_64 -I/anaconda3/envs/mot/lib/python3.7/site-packages/numpy/core/include -I/anaconda3/envs/mot/include/python3.7m -c python.cc -o build/temp.macosx-10.7-x86_64-3.7/python.o -std=c++11 -march=native -ftree-vectorize
  In file included from python.cc:6:
  ./lap.h:18:20: error: no template named 'tuple' in namespace 'std'
  always_inline std::tuple<cost, cost, idx, idx>
                ~~~~~^
  ./lap.h:41:15: error: no member named 'make_tuple' in namespace 'std'
    return std::make_tuple(umin, usubmin, j1, j2);
           ~~~~~^
  ./lap.h:52:20: error: no template named 'tuple' in namespace 'std'
  always_inline std::tuple<float, float, idx, idx>
                ~~~~~^
  ./lap.h:127:15: error: no member named 'make_tuple' in namespace 'std'
    return std::make_tuple(umin, usubmin, j1, j2);
           ~~~~~^
  ./lap.h:131:20: error: no template named 'tuple' in namespace 'std'
  always_inline std::tuple<double, double, idx, idx>
                ~~~~~^
  ./lap.h:206:15: error: no member named 'make_tuple' in namespace 'std'
    return std::make_tuple(umin, usubmin, j1, j2);
           ~~~~~^
  ./lap.h:228:20: error: no member named 'unique_ptr' in namespace 'std'
    auto free = std::unique_ptr<idx[]>(new idx[dim]);     // list of unassigned rows.
                ~~~~~^
  ./lap.h:228:31: error: 'idx' does not refer to a value
    auto free = std::unique_ptr<idx[]>(new idx[dim]);     // list of unassigned rows.
                                ^
  ./lap.h:224:20: note: declared here
  template <typename idx, typename cost>
                     ^
  ./lap.h:228:35: error: expected expression
    auto free = std::unique_ptr<idx[]>(new idx[dim]);     // list of unassigned rows.
                                    ^
  ./lap.h:229:23: error: no member named 'unique_ptr' in namespace 'std'
    auto collist = std::unique_ptr<idx[]>(new idx[dim]);  // list of columns to be scanned in various ways.
                   ~~~~~^
  ./lap.h:229:34: error: 'idx' does not refer to a value
    auto collist = std::unique_ptr<idx[]>(new idx[dim]);  // list of columns to be scanned in various ways.
                                   ^
  ./lap.h:224:20: note: declared here
  template <typename idx, typename cost>
                     ^
  ./lap.h:229:38: error: expected expression
    auto collist = std::unique_ptr<idx[]>(new idx[dim]);  // list of columns to be scanned in various ways.
                                       ^
  ./lap.h:230:23: error: no member named 'unique_ptr' in namespace 'std'
    auto matches = std::unique_ptr<idx[]>(new idx[dim]);  // counts how many times a row could be assigned.
                   ~~~~~^
  ./lap.h:230:34: error: 'idx' does not refer to a value
    auto matches = std::unique_ptr<idx[]>(new idx[dim]);  // counts how many times a row could be assigned.
                                   ^
  ./lap.h:224:20: note: declared here
  template <typename idx, typename cost>
                     ^
  ./lap.h:230:38: error: expected expression
    auto matches = std::unique_ptr<idx[]>(new idx[dim]);  // counts how many times a row could be assigned.
                                       ^
  ./lap.h:231:17: error: no member named 'unique_ptr' in namespace 'std'
    auto d = std::unique_ptr<cost[]>(new cost[dim]);      // 'cost-distance' in augmenting path calculation.
             ~~~~~^
  ./lap.h:231:28: error: 'cost' does not refer to a value
    auto d = std::unique_ptr<cost[]>(new cost[dim]);      // 'cost-distance' in augmenting path calculation.
                             ^
  ./lap.h:224:34: note: declared here
  template <typename idx, typename cost>
                                   ^
  ./lap.h:231:33: error: expected expression
    auto d = std::unique_ptr<cost[]>(new cost[dim]);      // 'cost-distance' in augmenting path calculation.
                                  ^
  ./lap.h:232:20: error: no member named 'unique_ptr' in namespace 'std'
    auto pred = std::unique_ptr<idx[]>(new idx[dim]);     // row-predecessor of column in augmenting/alternating path.
                ~~~~~^
  fatal error: too many errors emitted, stopping now [-ferror-limit=]
  20 errors generated.
  error: command 'gcc' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for lapjv
  Running setup.py clean for lapjv
Failed to build lapjv
Installing collected packages: lapjv
  Running setup.py install for lapjv ... error
    Complete output from command /anaconda3/envs/mot/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/q0/yv4nhd652f5_70s5r6tqhr3m0000gn/T/pip-install-avpiyzzw/lapjv/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/q0/yv4nhd652f5_70s5r6tqhr3m0000gn/T/pip-record-66ygc0ip/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'lapjv' extension
    creating build
    creating build/temp.macosx-10.7-x86_64-3.7
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/anaconda3/envs/mot/include -arch x86_64 -I/anaconda3/envs/mot/include -arch x86_64 -I/anaconda3/envs/mot/lib/python3.7/site-packages/numpy/core/include -I/anaconda3/envs/mot/include/python3.7m -c python.cc -o build/temp.macosx-10.7-x86_64-3.7/python.o -std=c++11 -march=native -ftree-vectorize
    In file included from python.cc:6:
    ./lap.h:18:20: error: no template named 'tuple' in namespace 'std'
    always_inline std::tuple<cost, cost, idx, idx>
                  ~~~~~^
    ./lap.h:41:15: error: no member named 'make_tuple' in namespace 'std'
      return std::make_tuple(umin, usubmin, j1, j2);
             ~~~~~^
    ./lap.h:52:20: error: no template named 'tuple' in namespace 'std'
    always_inline std::tuple<float, float, idx, idx>
                  ~~~~~^
    ./lap.h:127:15: error: no member named 'make_tuple' in namespace 'std'
      return std::make_tuple(umin, usubmin, j1, j2);
             ~~~~~^
    ./lap.h:131:20: error: no template named 'tuple' in namespace 'std'
    always_inline std::tuple<double, double, idx, idx>
                  ~~~~~^
    ./lap.h:206:15: error: no member named 'make_tuple' in namespace 'std'
      return std::make_tuple(umin, usubmin, j1, j2);
             ~~~~~^
    ./lap.h:228:20: error: no member named 'unique_ptr' in namespace 'std'
      auto free = std::unique_ptr<idx[]>(new idx[dim]);     // list of unassigned rows.
                  ~~~~~^
    ./lap.h:228:31: error: 'idx' does not refer to a value
      auto free = std::unique_ptr<idx[]>(new idx[dim]);     // list of unassigned rows.
                                  ^
    ./lap.h:224:20: note: declared here
    template <typename idx, typename cost>
                       ^
    ./lap.h:228:35: error: expected expression
      auto free = std::unique_ptr<idx[]>(new idx[dim]);     // list of unassigned rows.
                                      ^
    ./lap.h:229:23: error: no member named 'unique_ptr' in namespace 'std'
      auto collist = std::unique_ptr<idx[]>(new idx[dim]);  // list of columns to be scanned in various ways.
                     ~~~~~^
    ./lap.h:229:34: error: 'idx' does not refer to a value
      auto collist = std::unique_ptr<idx[]>(new idx[dim]);  // list of columns to be scanned in various ways.
                                     ^
    ./lap.h:224:20: note: declared here
    template <typename idx, typename cost>
                       ^
    ./lap.h:229:38: error: expected expression
      auto collist = std::unique_ptr<idx[]>(new idx[dim]);  // list of columns to be scanned in various ways.
                                         ^
    ./lap.h:230:23: error: no member named 'unique_ptr' in namespace 'std'
      auto matches = std::unique_ptr<idx[]>(new idx[dim]);  // counts how many times a row could be assigned.
                     ~~~~~^
    ./lap.h:230:34: error: 'idx' does not refer to a value
      auto matches = std::unique_ptr<idx[]>(new idx[dim]);  // counts how many times a row could be assigned.
                                     ^
    ./lap.h:224:20: note: declared here
    template <typename idx, typename cost>
                       ^
    ./lap.h:230:38: error: expected expression
      auto matches = std::unique_ptr<idx[]>(new idx[dim]);  // counts how many times a row could be assigned.
                                         ^
    ./lap.h:231:17: error: no member named 'unique_ptr' in namespace 'std'
      auto d = std::unique_ptr<cost[]>(new cost[dim]);      // 'cost-distance' in augmenting path calculation.
               ~~~~~^
    ./lap.h:231:28: error: 'cost' does not refer to a value
      auto d = std::unique_ptr<cost[]>(new cost[dim]);      // 'cost-distance' in augmenting path calculation.
                               ^
    ./lap.h:224:34: note: declared here
    template <typename idx, typename cost>
                                     ^
    ./lap.h:231:33: error: expected expression
      auto d = std::unique_ptr<cost[]>(new cost[dim]);      // 'cost-distance' in augmenting path calculation.
                                    ^
    ./lap.h:232:20: error: no member named 'unique_ptr' in namespace 'std'
      auto pred = std::unique_ptr<idx[]>(new idx[dim]);     // row-predecessor of column in augmenting/alternating path.
                  ~~~~~^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    20 errors generated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/anaconda3/envs/mot/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/q0/yv4nhd652f5_70s5r6tqhr3m0000gn/T/pip-install-avpiyzzw/lapjv/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/q0/yv4nhd652f5_70s5r6tqhr3m0000gn/T/pip-record-66ygc0ip/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/q0/yv4nhd652f5_70s5r6tqhr3m0000gn/T/pip-install-avpiyzzw/lapjv/

I understand if this is shouldn't be on your table as I would guess that it has something to do with g++/clang, but I figured I could post it here anyways. Any help is appreciated.

Thanks!

Install Fail on Windows

Installation attempt via:
pip3 install git+https://github.com/src-d/lapjv

This appears to be a continuation of __cpuidex problems

Installing collected packages: lapjv
  Running setup.py install for lapjv ... error
  error: subprocess-exited-with-error

  × Running setup.py install for lapjv did not run successfully.
  │ exit code: 1
  ╰─> [22 lines of output]
      running install
      C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_ext
      building 'lapjv' extension
      creating build
      creating build\temp.win-amd64-3.10
      creating build\temp.win-amd64-3.10\Release
      "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\core\include "-IC:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\include" "-IC:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\Include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.2\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt" /EHsc /Tppython.cc /Fobuild\temp.win-amd64-3.10\Release\python.obj /openmp /std:c++latest /arch:AVX2
      python.cc
      C:\Users\USER\AppData\Local\Temp\pip-req-build-xf_k2cp2\cpuid.h(22): error C2664: 'void __cpuidex(int [],int,int)': cannot convert argument 1 from 'unsigned int [4]' to 'int []'
      C:\Users\USER\AppData\Local\Temp\pip-req-build-xf_k2cp2\cpuid.h(22): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\intrin.h(161): note: see declaration of '__cpuidex'
      C:\Users\USER\AppData\Local\Temp\pip-req-build-xf_k2cp2\cpuid.h(32): error C2664: 'void __cpuidex(int [],int,int)': cannot convert argument 1 from 'unsigned int [4]' to 'int []'
      C:\Users\USER\AppData\Local\Temp\pip-req-build-xf_k2cp2\cpuid.h(32): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\intrin.h(161): note: see declaration of '__cpuidex'
      C:\Users\USER\AppData\Local\Temp\pip-req-build-xf_k2cp2\cpuid.h(36): error C2664: 'void __cpuidex(int [],int,int)': cannot convert argument 1 from 'unsigned int [4]' to 'int []'
      C:\Users\USER\AppData\Local\Temp\pip-req-build-xf_k2cp2\cpuid.h(36): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\intrin.h(161): note: see declaration of '__cpuidex'
      python.cc(127): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lapjv

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

Breaks immediately on very large problems

Hey great library!
I'm curious about why this function crashes on large assignment problems.
It worked for me for 5000 and 10,000 position problems but crashed for 55,000 immediately.
At first I thought it was a memory issue but it seems to be crashing long before exhausting all the memory on the machines I tried.
Do you have any idea why?

Inconsistent result for NaNs

If I give lapjv a matrix full of np.nan then the row_idx vector contains a -1 but misses the value n-1 where n is the square matrix size. col_idx on the other hand contains two times the 0 and missing n-2. This is at least the way it is for n=100. This seems highly inconsistent and should be handled by the package, either in deciding to not produce a valid output (all idxs to -1) or producing a fixed assignment (random would be ok, as any assigment would produce NaN total cost). I am not sure how the pattern I observed is achieved through the code and how other edge cases with NaNs and +-Infs are handled, making it handling outside very difficult. E.g. with a few +Inf entries the LAProblem is still well-defined.

Code to reproduce:

from lapjv import lapjv
import numpy as np
print(lapjv(np.zeros((100,100))*np.nan))

Installation failed on Windows

### I am tryin to run 'pip3 install lapjv' on windows but getting this error. Could you help me identify the problem?

Microsoft Windows [Version 10.0.19042.1466]
(c) Microsoft Corporation. All rights reserved.

C:\Users\User>cd C:\Users\User\Desktop\error-browser-research\lapjv

C:\Users\User\Desktop\error-browser-research\lapjv>pip3 install lapjv
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)
Collecting lapjv
Using cached lapjv-1.3.14.tar.gz (10 kB)
Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy>=1.20.0 in c:\users\User\appdata\roaming\python\python39\site-packages (from lapjv) (1.21.4)
Building wheels for collected packages: lapjv
Building wheel for lapjv (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'C:\Python39\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\User\AppData\Local\Temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\setup.py'"'"'; file='"'"'C:\Users\User\AppData\Local\Temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\User\AppData\Local\Temp\pip-wheel-a_3stb1f'
cwd: C:\Users\User\AppData\Local\Temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb
Complete output (14 lines):
running bdist_wheel
running build
running build_ext
building 'lapjv' extension
creating build
creating build\temp.win-amd64-3.9
creating build\temp.win-amd64-3.9\Release
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\User\AppData\Roaming\Python\Python39\site-packages\numpy\core\include -IC:\Python39\include -IC:\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt /EHsc /Tppython.cc /Fobuild\temp.win-amd64-3.9\Release\python.obj /openmp /std:c++latest /arch:AVX2
python.cc
c:\users\User\appdata\local\temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\cpuid.h(19): error C3861: '__cpuidex': identifier not found
c:\users\User\appdata\local\temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\cpuid.h(29): error C3861: '__cpuidex': identifier not found
c:\users\User\appdata\local\temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\cpuid.h(33): error C3861: '__cpuidex': identifier not found
python.cc(127): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit code 2

ERROR: Failed building wheel for lapjv
Running setup.py clean for lapjv
Failed to build lapjv
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)
Installing collected packages: lapjv
Running setup.py install for lapjv ... error
ERROR: Command errored out with exit status 1:
command: 'C:\Python39\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\User\AppData\Local\Temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\setup.py'"'"'; file='"'"'C:\Users\User\AppData\Local\Temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\User\AppData\Local\Temp\pip-record-c_nqbwwu\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Python39\Include\lapjv'
cwd: C:\Users\User\AppData\Local\Temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb
Complete output (14 lines):
running install
running build
running build_ext
building 'lapjv' extension
creating build
creating build\temp.win-amd64-3.9
creating build\temp.win-amd64-3.9\Release
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\User\AppData\Roaming\Python\Python39\site-packages\numpy\core\include -IC:\Python39\include -IC:\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt /EHsc /Tppython.cc /Fobuild\temp.win-amd64-3.9\Release\python.obj /openmp /std:c++latest /arch:AVX2
python.cc
c:\users\User\appdata\local\temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\cpuid.h(19): error C3861: '__cpuidex': identifier not found
c:\users\User\appdata\local\temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\cpuid.h(29): error C3861: '__cpuidex': identifier not found
c:\users\User\appdata\local\temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\cpuid.h(33): error C3861: '__cpuidex': identifier not found
python.cc(127): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit code 2
----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Python39\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\User\AppData\Local\Temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\setup.py'"'"'; file='"'"'C:\Users\User\AppData\Local\Temp\pip-install-diukxk6m\lapjv_1f8b6cef705b415d898b52e267b857bb\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\User\AppData\Local\Temp\pip-record-c_nqbwwu\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Python39\Include\lapjv' Check the logs for full command output.
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution - (c:\python39\lib\site-packages)

C:\Users\User\Desktop\error-browser-research\lapjv>

Install fail on MacOS

Hi, I am trying install lapjv on macOS by using command 'pip3 install lapjv', but I got some trouble, like this
image
Can you help me? Thank you very much!

Assignment matrix reconstruction

Hi,
Let me tell you guys that this is the fastest python lib I come around with when surfing frenzily on the net looking for THIS python lib that could save me from the scipy slowness (usually algorithms from scipy lib are very efficient 💯 ) .

Just one headeach, it was a real headeach to figure out how to derive the assignment matrix from lapjv's output. Could you please report in your docstring/readme that we could get the assignment matrix by doing :

 x,_, _ = lapjv(cost) 
 row_ind = np.arange(len(x))    
 col_ind = x[row_ind]

Thanks in advance.

Possible solution to large data sets?

This has already been mentioned in another issue, but I thought it merits its own thread, and besides the other one hasn't been updated for quite a while.

Since the algorithm complexity is $O(n^3)$, the computation can get quite costly quite quickly, both time-wise and memory-wise. Are there any solutions or approximation algorithms to address this problem?

In the other thread a data size of 55K was already considered a big data set, and I have a data set that is thousands of times its size... Any hope?

Installation fail -- requirements are invalid

The current setup.py lists:

    install_requires=["numpy>=1.0.0"],
    tests_require=["scipy>=1.0.0"],
    setup_requires=["numpy>=1.20.0"],

This means pip will try to install the current version on lapjv even if numpy is older than 1.20. It will build against numpy 1.20, install it in your environment with older numpy, and import lapjv will fail with:

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import

Please sync install_requires with setup_requires as building with one version and running with another does NOT work.

Incorrect results?

It appears that this library sometimes returns incorrect results. The example below shows two failure cases. For both problem instances, this library incorrectly assigns both rows to the same column. For reference, I have also included the (presumably correct) results returned by the scipy implementation.

import scipy.optimize
import lapjv
import numpy as np

C1 = np.array([[8., 9.],
               [1., 4.]])
C2 = np.array([[5., 1.],
               [8., 9.]])

for C in [C1, C2]:
    print('\n%s' % C)
    print('LAPJV result: %s, %s' % lapjv.lapjv(C)[1:])
    print('Scipy result: %s, %s' % scipy.optimize.linear_sum_assignment(C))

Result

[[8. 9.]
 [1. 4.]]
LAPJV result: [1 0], [1 0]
Scipy result: [0 1], [1 0]

[[5. 1.]
 [8. 9.]]
LAPJV result: [1 0], [1 0]
Scipy result: [0 1], [1 0]

Please let me know if I'm using the library incorrectly, or if there are certain types of inputs to avoid.

Installation fail

the command : python -m pip install --upgrade pip
the result :

(DeepBinDif) C:\Users\Acer\Desktop\DeepBinDiff-master>python -m pip install lapjv
Collecting lapjv
Using cached lapjv-1.3.21.tar.gz (10 kB)
Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy>=1.20.0 in c:\programdata\anaconda3\envs\deepbindif\lib\site-packages (from lapjv) (1.21.6)
Building wheels for collected packages: lapjv
Building wheel for lapjv (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [5 lines of output]
running bdist_wheel
running build
running build_ext
building 'lapjv' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for lapjv
Running setup.py clean for lapjv
Failed to build lapjv
Installing collected packages: lapjv
Running setup.py install for lapjv ... error
error: subprocess-exited-with-error

× Running setup.py install for lapjv did not run successfully.
│ exit code: 1
╰─> [7 lines of output]
running install
C:\ProgramData\Anaconda3\envs\DeepBinDif\lib\site-packages\setuptools\command\install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
setuptools.SetuptoolsDeprecationWarning,
running build
running build_ext
building 'lapjv' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lapjv

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

Not working with non-square matrix

Hi, I'm trying your implementation in order to replace the munkres one for optimizing a project.

row_ind, col_ind, _ = compute(np.array(cost_matrix))
ValueError: "cost_matrix" must be a square 2D numpy array

cost_matrix is here a N*M ; Are you going to add this feature ?

Thanks

install failed on windows with vs2022

pip install lapjvandpip install git+https://**** both failed.
And their output are same

      running install
      running build
      running build_ext
      building 'lapjv' extension
      creating build
      creating build\temp.win-amd64-3.10
      creating build\temp.win-amd64-3.10\Release
      C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -ID:\Program Files\Python310\lib\site-packages\numpy\core\include -ID:\Program Files\Python310\include -ID:\Program Files\Python310\Include -IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\ATLMFC\include -IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt /EHsc /Tppython.cc /Fobuild\temp.win-amd64-3.10\Release\python.obj /openmp /std:c++latest /arch:AVX2      
      python.cc
      python.cc(127): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
      C:\Users\lizhi\AppData\Local\Temp\pip-req-build-q0tw56zx\lap.h(72): error C2440: 'reinterpret_cast': cannot convert from '__m256' to '__m256i'
      C:\Users\lizhi\AppData\Local\Temp\pip-req-build-q0tw56zx\lap.h(72): note: Conversion requires a constructor or user-defined-conversion operator, which can't be used by const_cast or reinterpret_cast
      C:\Users\lizhi\AppData\Local\Temp\pip-req-build-q0tw56zx\lap.h(216): note: see reference to function template instantiation 'std::tuple<cost,cost,int,int> find_umins_avx2<idx>(idx,idx,const float *__restrict ,const float *__restrict )' being compiled
              with
              [
                  cost=float,
                  idx=int
              ]
      C:\Users\lizhi\AppData\Local\Temp\pip-req-build-q0tw56zx\lap.h(311): note: see reference to function template instantiation 'std::tuple<cost,cost,int,int> find_umins<true,int,cost>(idx,idx,const cost *__restrict ,const cost *__restrict )' being compiled
              with
              [
                  cost=float,
                  idx=int
              ]
      python.cc(80): note: see reference to function template instantiation 'cost lap<true,int,F>(int,const cost *__restrict ,bool,idx *__restrict ,idx *__restrict ,cost *__restrict ,cost *__restrict )' being compiled
              with
              [
                  cost=float,
                  F=float,
                  idx=int
              ]
      python.cc(147): note: see reference to function template instantiation 'double call_lap<float>(int,const void *__restrict ,bool,int *__restrict ,int *__restrict ,void *__restrict ,void *__restrict )' being compiled
      C:\Users\lizhi\AppData\Local\Temp\pip-req-build-q0tw56zx\lap.h(71): error C2660: '_mm256_blendv_epi8': function does not take 2 arguments
      C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\immintrin.h(1559): note: see declaration of '_mm256_blendv_epi8'
      C:\Users\lizhi\AppData\Local\Temp\pip-req-build-q0tw56zx\lap.h(75): error C2440: 'reinterpret_cast': cannot convert from '__m256' to '__m256i'
      C:\Users\lizhi\AppData\Local\Temp\pip-req-build-q0tw56zx\lap.h(75): note: Conversion requires a constructor or user-defined-conversion operator, which can't be used by const_cast or reinterpret_cast
      C:\Users\lizhi\AppData\Local\Temp\pip-req-build-q0tw56zx\lap.h(74): error C2660: '_mm256_blendv_epi8': function does not take 2 arguments
      C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\immintrin.h(1559): note: see declaration of '_mm256_blendv_epi8'
      C:\Users\lizhi\AppData\Local\Temp\pip-req-build-q0tw56zx\lap.h(79): error C2440: 'reinterpret_cast': cannot convert from '__m256' to '__m256i'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.