├── README.md ├── caffemodel_compress.py └── quantz_kit ├── .kmeans_genx.cpp.bak ├── _weights_quantization.so ├── build.sh ├── caffemodel_compress.py ├── module_test.py ├── weights_compress.cpp ├── weights_compress.i ├── weights_compress.o ├── weights_compress_wrap.c ├── weights_compress_wrap.o ├── weights_quantization.py └── weights_quantization.pyc /README.md: -------------------------------------------------------------------------------- 1 | Caffe Model Compression 2 | =================== 3 | 4 | 5 | This is a python tool used to compress the trained caffe weights. For Alexnet, we got 17x compression rate (~233M bytes to 14M bytes). The idea comes from [Deep Compression](http://arxiv.org/pdf/1510.00149v5.pdf) . This work does not implement purning and Huffman coding, but implement the Kmeans -based quantization to compress the weights of convolution and full-connected layer. One contribution of this work is using OpenMP to accelerate the Kmeans processing. 6 | 7 | ---------- 8 | 9 | 10 | ####Dependency 11 | 12 | > - Python/Numpy 13 | > - Caffe 14 | 15 | 16 | ####Authors 17 | > - [Li, Victor](yuanyuan.li85@gmail.com) 18 | > - [Qiu, Junyi](geoffrey0824@sjtu.edu.cn) 19 | 20 | ####How to Build: 21 | ``` 22 | cd quantz_kit 23 | ./build.sh 24 | ``` 25 | ####How to use it: 26 | ``` 27 | caffe_model_compress: #function to compress model 28 | caffe_model_decompress: #function to decompress model 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /caffemodel_compress.py: -------------------------------------------------------------------------------- 1 | import os 2 | import caffe 3 | import numpy as np 4 | from math import ceil 5 | #from quantz_kit.weights_quantization import weights_quantization 6 | import sys 7 | sys.path.append("./quantz_kit") 8 | import weights_quantization as wqtz 9 | import time 10 | 11 | 12 | def caffe_model_compress(model, weights, storefile, convbit=6, fcbit=2, use_savez_compressed=True): 13 | net = caffe.Net(model, caffe.TEST); 14 | net.copy_from(weights); 15 | 16 | xdict = dict() 17 | #version 1 ; bits of conv layer and bits of full-connected layer 18 | xdict['compz_info'] = (1, int(convbit), int(fcbit)) 19 | 20 | for item in net.params.items(): 21 | name, layer = item 22 | print "compressing layer", name 23 | 24 | #compress weights 25 | weights = net.params[name][0].data 26 | #don't compress bais 27 | bais = net.params[name][1].data 28 | 29 | #bits for conv and full-connected layer. 30 | if "fc" in name: 31 | nbit = int(fcbit) 32 | elif "conv" in name: 33 | nbit = int(convbit) 34 | 35 | weights_vec = weights.flatten().astype(np.float32) 36 | vec_length = weights_vec.size 37 | nelem = 32 / nbit 38 | newlabel = np.empty(((vec_length+nelem-1)/nelem),dtype=np.int32) 39 | codebook = np.empty((2**nbit),dtype=np.float32) 40 | 41 | #t_start = time.time() 42 | wqtz.compress_layer_weights(newlabel, codebook, weights_vec, vec_length, nbit) 43 | #t_stop = time.time() 44 | #kmeans_time = kmeans_time + t_stop - t_start 45 | 46 | xdict[name+'_weight_labels'] = newlabel 47 | xdict[name+'_weight_codebook'] = codebook 48 | xdict[name+'_bias'] = bais 49 | 50 | #keep result into output file 51 | if (use_savez_compressed): 52 | np.savez_compressed(storefile, **xdict) 53 | else: 54 | np.savez(storefile, **xdict) 55 | 56 | 57 | def caffe_model_decompress(model, weights, loadfile): 58 | net = caffe.Net(model, caffe.TEST); 59 | cmpr_model = np.load(loadfile) 60 | 61 | print cmpr_model.files 62 | 63 | version, convbit, fcbit = cmpr_model['compz_info'] 64 | 65 | assert(version == 1), "compz version not support" 66 | 67 | 68 | for item in net.params.items(): 69 | name, layer = item 70 | newlabels = cmpr_model[name+'_weight_labels'] 71 | codebook = cmpr_model[name+'_weight_codebook'] 72 | 73 | origin_size = net.params[name][0].data.flatten().size 74 | weights_vec = np.empty(origin_size, dtype=np.float32) 75 | vec_length = weights_vec.size 76 | 77 | #need have a way to get bits for fc and conv 78 | if "fc" in name: 79 | nbit = fcbit 80 | elif "conv" in name: 81 | nbit = convbit 82 | 83 | wqtz.decompress_layer_weights(weights_vec, newlabels, codebook, vec_length, nbit) 84 | newweights = weights_vec.reshape(net.params[name][0].data.shape) 85 | net.params[name][0].data[...] = newweights 86 | 87 | newbias = cmpr_model[name+'_bias'] 88 | net.params[name][1].data[...] = newbias[...] 89 | net.save(weights) 90 | 91 | if __name__ == "__main__": 92 | ALEXNET_PATH = "/home/junyi/caffe/models/bvlc_alexnet" 93 | netmodel = os.path.join(ALEXNET_PATH, "deploy.prototxt") 94 | netweights = os.path.join(ALEXNET_PATH, "bvlc_alexnet.caffemodel") 95 | output = "alexnetzip" 96 | caffe_model_compress(netmodel, netweights, output, 6, 2) 97 | 98 | caffe_model_decompress(netmodel, "alexnet_xx.caffemodel", "alexnetzip.npz") 99 | 100 | print "Done" 101 | -------------------------------------------------------------------------------- /quantz_kit/.kmeans_genx.cpp.bak: -------------------------------------------------------------------------------- 1 | /** 2 | *** 3 | *** Copyright (C) 1985-2011 Intel Corporation. All rights reserved. 4 | *** 5 | *** The information and source code contained herein is the exclusive 6 | *** property of Intel Corporation. and may not be disclosed, examined 7 | *** or reproduced in whole or in part without explicit written authorization 8 | *** from the company. 9 | *** 10 | *** ---------------------------------------------------------------------------- 11 | **/ 12 | #include 13 | 14 | extern "C" _GENX_MAIN_ void 15 | linear(SurfaceIndex ibuf, SurfaceIndex obuf, uint h_pos, uint v_pos) 16 | { 17 | matrix in; 18 | matrix out; 19 | matrix m; 20 | 21 | read(ibuf, h_pos*24, v_pos*6, in); 22 | 23 | m = in.select<6,1,24,1>(1,3); 24 | 25 | m += in.select<6,1,24,1>(0,0); 26 | m += in.select<6,1,24,1>(0,3); 27 | m += in.select<6,1,24,1>(0,6); 28 | 29 | m += in.select<6,1,24,1>(1,0); 30 | m += in.select<6,1,24,1>(1,6); 31 | 32 | m += in.select<6,1,24,1>(2,0); 33 | m += in.select<6,1,24,1>(2,3); 34 | m += in.select<6,1,24,1>(2,6); 35 | 36 | out = m * 0.111f; 37 | 38 | write(obuf, h_pos*24, v_pos*6, out); 39 | } 40 | -------------------------------------------------------------------------------- /quantz_kit/_weights_quantization.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuanyuanli85/CaffeModelCompression/0fbf138cdabc6f85608daca44438e36e0b5506fe/quantz_kit/_weights_quantization.so -------------------------------------------------------------------------------- /quantz_kit/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #swig -python weights_compress.i 4 | g++ -O3 -mavx2 -Wno-cpp -std=c++11 -fopenmp -fPIC -c weights_compress.cpp weights_compress_wrap.c -I/usr/local/include/ -I/usr/include/python2.7/ -I/usr/include/numpy -I. 5 | #g++ -Wno-cpp -std=c++11 -fopenmp -fPIC -c KmDriver.cpp -I/usr/local/include/ -I/usr/include/python2.7/ -I/usr/include/numpy -I. 6 | #g++ -Wno-cpp -std=c++11 -fopenmp -fPIC -c KmPointer.cpp -I/usr/local/include/ -I/usr/include/python2.7/ -I/usr/include/numpy -I. 7 | g++ -fopenmp -shared weights_compress.o weights_compress_wrap.o -o _weights_quantization.so 8 | -------------------------------------------------------------------------------- /quantz_kit/caffemodel_compress.py: -------------------------------------------------------------------------------- 1 | import os 2 | import caffe 3 | import numpy as np 4 | from math import ceil 5 | #from quantz_kit.weights_quantization import weights_quantization 6 | import sys 7 | sys.path.append("./quantz_kit") 8 | import weights_quantization as wqtz 9 | import time 10 | 11 | 12 | def caffe_model_compress(model, weights, storefile, convbit=6, fcbit=2, use_savez_compressed=True): 13 | net = caffe.Net(model, caffe.TEST); 14 | net.copy_from(weights); 15 | 16 | xdict = dict() 17 | #version 1 ; bits of conv layer and bits of full-connected layer 18 | xdict['compz_info'] = (1, int(convbit), int(fcbit)) 19 | 20 | for item in net.params.items(): 21 | name, layer = item 22 | print "compressing layer", name 23 | 24 | #compress weights 25 | weights = net.params[name][0].data 26 | #don't compress bais 27 | bais = net.params[name][1].data 28 | 29 | #bits for conv and full-connected layer. 30 | if "fc" in name: 31 | nbit = int(fcbit) 32 | elif "conv" in name: 33 | nbit = int(convbit) 34 | 35 | weights_vec = weights.flatten().astype(np.float32) 36 | vec_length = weights_vec.size 37 | nelem = 32 / nbit 38 | newlabel = np.empty(((vec_length+nelem-1)/nelem),dtype=np.int32) 39 | codebook = np.empty((2**nbit),dtype=np.float32) 40 | 41 | #t_start = time.time() 42 | wqtz.compress_layer_weights(newlabel, codebook, weights_vec, vec_length, nbit) 43 | #t_stop = time.time() 44 | #kmeans_time = kmeans_time + t_stop - t_start 45 | 46 | xdict[name+'_weight_labels'] = newlabel 47 | xdict[name+'_weight_codebook'] = codebook 48 | xdict[name+'_bias'] = bais 49 | 50 | #keep result into output file 51 | if (use_savez_compressed): 52 | np.savez_compressed(storefile, **xdict) 53 | else: 54 | np.savez(storefile, **xdict) 55 | 56 | 57 | def caffe_model_decompress(model, weights, loadfile): 58 | net = caffe.Net(model, caffe.TEST); 59 | cmpr_model = np.load(loadfile) 60 | 61 | print cmpr_model.files 62 | 63 | version, convbit, fcbit = cmpr_model['compz_info'] 64 | 65 | assert(version == 1), "compz version not support" 66 | 67 | 68 | for item in net.params.items(): 69 | name, layer = item 70 | newlabels = cmpr_model[name+'_weight_labels'] 71 | codebook = cmpr_model[name+'_weight_codebook'] 72 | 73 | origin_size = net.params[name][0].data.flatten().size 74 | weights_vec = np.empty(origin_size, dtype=np.float32) 75 | vec_length = weights_vec.size 76 | 77 | #need have a way to get bits for fc and conv 78 | if "fc" in name: 79 | nbit = fcbit 80 | elif "conv" in name: 81 | nbit = convbit 82 | 83 | wqtz.decompress_layer_weights(weights_vec, newlabels, codebook, vec_length, nbit) 84 | newweights = weights_vec.reshape(net.params[name][0].data.shape) 85 | net.params[name][0].data[...] = newweights 86 | 87 | newbias = cmpr_model[name+'_bias'] 88 | net.params[name][1].data[...] = newbias[...] 89 | net.save(weights) 90 | 91 | if __name__ == "__main__": 92 | ALEXNET_PATH = "/home/junyi/caffe/models/bvlc_alexnet" 93 | netmodel = os.path.join(ALEXNET_PATH, "deploy.prototxt") 94 | netweights = os.path.join(ALEXNET_PATH, "bvlc_alexnet.caffemodel") 95 | output = "alexnetzip" 96 | caffe_model_compress(netmodel, netweights, output, 6, 2) 97 | 98 | caffe_model_decompress(netmodel, "alexnet_xx.caffemodel", "alexnetzip.npz") 99 | 100 | print "Done" 101 | -------------------------------------------------------------------------------- /quantz_kit/module_test.py: -------------------------------------------------------------------------------- 1 | import kmeans_clustering as kc 2 | import numpy as np 3 | 4 | init_centro = np.array([1.0,2.0,3.5], dtype=np.float32) 5 | centro = np.empty(init_centro.shape, dtype=np.float32) 6 | 7 | nodes_list = np.array([1.1,3.3,1.9,3.4,0.8,2.1,2.7,1.8], dtype=np.float32) 8 | label = np.empty(nodes_list.shape, dtype=np.int32) 9 | 10 | print "nodes: ", nodes_list 11 | print "init centros: ", init_centro 12 | kc.kmeans_cluster(label, centro, nodes_list, nodes_list.size, 1, init_centro.size, init_centro, 5) 13 | print "label: ", label 14 | print "centros: ", centro 15 | -------------------------------------------------------------------------------- /quantz_kit/weights_compress.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "numpy/arrayobject.h" 9 | #include 10 | //#include "KmDriver.h" 11 | 12 | 13 | using namespace std; 14 | 15 | void kmeans_cluster(int *cLabel, float *cCentro, float *cNodes, int nNode, int nDimension, int nCluster, float *cInitCentro=nullptr, int max_iter=1000) 16 | { 17 | // get threads number from the env variable 18 | int tSize; 19 | if (const char* env_omp_tnum = getenv("OMP_NUM_THREADS")) 20 | tSize = atoi(env_omp_tnum); 21 | else 22 | tSize = omp_get_num_procs(); 23 | 24 | // generate initial centroids 25 | float max_global=numeric_limits::min(), min_global=numeric_limits::max(); 26 | float max_private[tSize], min_private[tSize]; 27 | if (cInitCentro != nullptr) 28 | memcpy(cCentro, cInitCentro, sizeof(float)*nCluster*nDimension); 29 | else 30 | { 31 | #pragma omp parallel 32 | { 33 | float max=numeric_limits::min(), min=numeric_limits::max(); 34 | #pragma omp for 35 | for (int n=0; n cNodes[n]) ? cNodes[n] : min; 39 | } 40 | int tid = omp_get_thread_num(); 41 | max_private[tid]=max; 42 | min_private[tid]=min; 43 | } 44 | for (int i=0; i min_private[i]) ? min_private[i] : min_global; 48 | } 49 | cInitCentro = new float[nCluster]; 50 | for (int k=0; k::max(); 55 | 56 | // initialize 57 | float *cDistance = new float[nNode*nDimension]; 58 | int *cClusterSize = new int[nCluster]; 59 | 60 | float *pCentroPos = new float[nCluster*tSize]; 61 | int *pClusterSize = new int[nCluster*tSize]; 62 | memset(pClusterSize, 0, sizeof(int)*nCluster*tSize); 63 | memset(pCentroPos, 0, sizeof(float)*nCluster*tSize); 64 | 65 | int iter = 0; 66 | float tk1=0.f, tk2=0.f, tk3=0.f; 67 | double mCurDistance = 0.0; 68 | double mPreDistance = numeric_limits::max(); 69 | 70 | // clustering 71 | while (iter < max_iter) 72 | { 73 | // check convergence 74 | if (fabs(mPreDistance-mCurDistance)/mPreDistance < 0.01) break; 75 | mPreDistance = mCurDistance; 76 | mCurDistance = 0.0; 77 | 78 | // select nearest cluster 79 | #pragma omp parallel 80 | { 81 | #pragma omp for //nowait 82 | for(int n=0; n> nres; 219 | __uname += nelem; 220 | } 221 | } 222 | 223 | // proceed the rest 224 | if (num % ngroup != 0) 225 | { 226 | int ng = num/ngroup; 227 | int nres = 0; 228 | int __uname = 0; 229 | for(int nt=0; nt= num) break; 238 | cmprLabel[nt] |= orgLabel[ng*ngroup+__uname+ne] << (32-nres-(ne+1)*nbit); 239 | } 240 | if ((ng*ngroup+__uname+nelem) >= num) break; 241 | nres = (nelem+1)*nbit+nres-32; 242 | if (nres != 0) 243 | cmprLabel[nt] |= orgLabel[ng*ngroup+__uname+nelem] >> nres; 244 | __uname += nelem + 1; 245 | } 246 | } 247 | 248 | }*/ 249 | } 250 | 251 | void decode_label(int *dcmprLabel, int *cmprLabel, int num, const int nbit) 252 | { 253 | int mask = 1; 254 | for(int i=1; i> ((ngroup-1-ng)*nbit)) & mask; 266 | } 267 | { 268 | int *cGroup = dcmprLabel+(num/ngroup)*ngroup; 269 | int token = *(cmprLabel+num/ngroup); 270 | for (int ng=0; ng<(num%ngroup); ng++) 271 | cGroup[ng] = (token >> ((ngroup-1-ng)*nbit)) & mask; 272 | } 273 | } 274 | 275 | void compress_layer_weights(PyObject *pComprsLabel, PyObject *pCodeBook, PyObject *pWeights, int nWeight, int nBit) 276 | { 277 | float *cWeights = (float *) PyArray_GETPTR1(pWeights, 0); 278 | float *cCodeBook = (float *) PyArray_GETPTR1(pCodeBook, 0); 279 | int *cLabel = new int[nWeight]; 280 | int nCentroid = 1 << nBit; 281 | float *cCentroid = new float[nCentroid]; 282 | int *cCmprLabel = (int *) PyArray_GETPTR1(pComprsLabel, 0); 283 | 284 | kmeans_cluster(cLabel, cCentroid, cWeights, nWeight, 1, nCentroid, nullptr, 1000); 285 | memcpy(cCodeBook, cCentroid, nCentroid*sizeof(float)); 286 | encode_label(cCmprLabel, cLabel, nWeight, nBit); 287 | } 288 | 289 | void decompress_layer_weights(PyObject *pWeights, PyObject *pComprsLabel, PyObject *pCodeBook, int nWeight, int nBit) 290 | { 291 | int nCentroid = 1 << nBit; 292 | int *cLabel = new int[nWeight]; 293 | int *cCmprLabel = (int *) PyArray_GETPTR1(pComprsLabel, 0); 294 | float *cWeights = (float *) PyArray_GETPTR1(pWeights, 0); 295 | float *cCodeBook = (float *) PyArray_GETPTR1(pCodeBook, 0); 296 | 297 | decode_label(cLabel, cCmprLabel, nWeight, nBit); 298 | //translate 299 | #pragma omp parallel for 300 | for(int n=0; n 4 | #include "numpy/arrayobject.h" 5 | void compress_layer_weights(PyObject *pComprsLabel, PyObject *pCodeBook, PyObject *pWeights, int nWeight, int nBit); 6 | void decompress_layer_weights(PyObject *pWeights, PyObject *pComprsLabel, PyObject *pCodeBook, int nWeight, int nBit); 7 | void quantize_layer_weights(PyObject *pWeights, int nWeight, int nBit); 8 | %} 9 | #include 10 | #include "numpy/arrayobject.h" 11 | void compress_layer_weights(PyObject *pComprsLabel, PyObject *pCodeBook, PyObject *pWeights, int nWeight, int nBit); 12 | void decompress_layer_weights(PyObject *pWeights, PyObject *pComprsLabel, PyObject *pCodeBook, int nWeight, int nBit); 13 | void quantize_layer_weights(PyObject *pWeights, int nWeight, int nBit); 14 | -------------------------------------------------------------------------------- /quantz_kit/weights_compress.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuanyuanli85/CaffeModelCompression/0fbf138cdabc6f85608daca44438e36e0b5506fe/quantz_kit/weights_compress.o -------------------------------------------------------------------------------- /quantz_kit/weights_compress_wrap.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 2.0.12 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | #define SWIGPYTHON 12 | #define SWIG_PYTHON_DIRECTOR_NO_VTABLE 13 | 14 | /* ----------------------------------------------------------------------------- 15 | * This section contains generic SWIG labels for method/variable 16 | * declarations/attributes, and other compiler dependent labels. 17 | * ----------------------------------------------------------------------------- */ 18 | 19 | /* template workaround for compilers that cannot correctly implement the C++ standard */ 20 | #ifndef SWIGTEMPLATEDISAMBIGUATOR 21 | # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) 22 | # define SWIGTEMPLATEDISAMBIGUATOR template 23 | # elif defined(__HP_aCC) 24 | /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ 25 | /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ 26 | # define SWIGTEMPLATEDISAMBIGUATOR template 27 | # else 28 | # define SWIGTEMPLATEDISAMBIGUATOR 29 | # endif 30 | #endif 31 | 32 | /* inline attribute */ 33 | #ifndef SWIGINLINE 34 | # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) 35 | # define SWIGINLINE inline 36 | # else 37 | # define SWIGINLINE 38 | # endif 39 | #endif 40 | 41 | /* attribute recognised by some compilers to avoid 'unused' warnings */ 42 | #ifndef SWIGUNUSED 43 | # if defined(__GNUC__) 44 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 45 | # define SWIGUNUSED __attribute__ ((__unused__)) 46 | # else 47 | # define SWIGUNUSED 48 | # endif 49 | # elif defined(__ICC) 50 | # define SWIGUNUSED __attribute__ ((__unused__)) 51 | # else 52 | # define SWIGUNUSED 53 | # endif 54 | #endif 55 | 56 | #ifndef SWIG_MSC_UNSUPPRESS_4505 57 | # if defined(_MSC_VER) 58 | # pragma warning(disable : 4505) /* unreferenced local function has been removed */ 59 | # endif 60 | #endif 61 | 62 | #ifndef SWIGUNUSEDPARM 63 | # ifdef __cplusplus 64 | # define SWIGUNUSEDPARM(p) 65 | # else 66 | # define SWIGUNUSEDPARM(p) p SWIGUNUSED 67 | # endif 68 | #endif 69 | 70 | /* internal SWIG method */ 71 | #ifndef SWIGINTERN 72 | # define SWIGINTERN static SWIGUNUSED 73 | #endif 74 | 75 | /* internal inline SWIG method */ 76 | #ifndef SWIGINTERNINLINE 77 | # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE 78 | #endif 79 | 80 | /* exporting methods */ 81 | #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 82 | # ifndef GCC_HASCLASSVISIBILITY 83 | # define GCC_HASCLASSVISIBILITY 84 | # endif 85 | #endif 86 | 87 | #ifndef SWIGEXPORT 88 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 89 | # if defined(STATIC_LINKED) 90 | # define SWIGEXPORT 91 | # else 92 | # define SWIGEXPORT __declspec(dllexport) 93 | # endif 94 | # else 95 | # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) 96 | # define SWIGEXPORT __attribute__ ((visibility("default"))) 97 | # else 98 | # define SWIGEXPORT 99 | # endif 100 | # endif 101 | #endif 102 | 103 | /* calling conventions for Windows */ 104 | #ifndef SWIGSTDCALL 105 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 106 | # define SWIGSTDCALL __stdcall 107 | # else 108 | # define SWIGSTDCALL 109 | # endif 110 | #endif 111 | 112 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 113 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) 114 | # define _CRT_SECURE_NO_DEPRECATE 115 | #endif 116 | 117 | /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ 118 | #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) 119 | # define _SCL_SECURE_NO_DEPRECATE 120 | #endif 121 | 122 | 123 | 124 | #if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG) 125 | /* Use debug wrappers with the Python release dll */ 126 | # undef _DEBUG 127 | # include 128 | # define _DEBUG 129 | #else 130 | # include 131 | #endif 132 | 133 | /* ----------------------------------------------------------------------------- 134 | * swigrun.swg 135 | * 136 | * This file contains generic C API SWIG runtime support for pointer 137 | * type checking. 138 | * ----------------------------------------------------------------------------- */ 139 | 140 | /* This should only be incremented when either the layout of swig_type_info changes, 141 | or for whatever reason, the runtime changes incompatibly */ 142 | #define SWIG_RUNTIME_VERSION "4" 143 | 144 | /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ 145 | #ifdef SWIG_TYPE_TABLE 146 | # define SWIG_QUOTE_STRING(x) #x 147 | # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) 148 | # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) 149 | #else 150 | # define SWIG_TYPE_TABLE_NAME 151 | #endif 152 | 153 | /* 154 | You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for 155 | creating a static or dynamic library from the SWIG runtime code. 156 | In 99.9% of the cases, SWIG just needs to declare them as 'static'. 157 | 158 | But only do this if strictly necessary, ie, if you have problems 159 | with your compiler or suchlike. 160 | */ 161 | 162 | #ifndef SWIGRUNTIME 163 | # define SWIGRUNTIME SWIGINTERN 164 | #endif 165 | 166 | #ifndef SWIGRUNTIMEINLINE 167 | # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE 168 | #endif 169 | 170 | /* Generic buffer size */ 171 | #ifndef SWIG_BUFFER_SIZE 172 | # define SWIG_BUFFER_SIZE 1024 173 | #endif 174 | 175 | /* Flags for pointer conversions */ 176 | #define SWIG_POINTER_DISOWN 0x1 177 | #define SWIG_CAST_NEW_MEMORY 0x2 178 | 179 | /* Flags for new pointer objects */ 180 | #define SWIG_POINTER_OWN 0x1 181 | 182 | 183 | /* 184 | Flags/methods for returning states. 185 | 186 | The SWIG conversion methods, as ConvertPtr, return an integer 187 | that tells if the conversion was successful or not. And if not, 188 | an error code can be returned (see swigerrors.swg for the codes). 189 | 190 | Use the following macros/flags to set or process the returning 191 | states. 192 | 193 | In old versions of SWIG, code such as the following was usually written: 194 | 195 | if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { 196 | // success code 197 | } else { 198 | //fail code 199 | } 200 | 201 | Now you can be more explicit: 202 | 203 | int res = SWIG_ConvertPtr(obj,vptr,ty.flags); 204 | if (SWIG_IsOK(res)) { 205 | // success code 206 | } else { 207 | // fail code 208 | } 209 | 210 | which is the same really, but now you can also do 211 | 212 | Type *ptr; 213 | int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); 214 | if (SWIG_IsOK(res)) { 215 | // success code 216 | if (SWIG_IsNewObj(res) { 217 | ... 218 | delete *ptr; 219 | } else { 220 | ... 221 | } 222 | } else { 223 | // fail code 224 | } 225 | 226 | I.e., now SWIG_ConvertPtr can return new objects and you can 227 | identify the case and take care of the deallocation. Of course that 228 | also requires SWIG_ConvertPtr to return new result values, such as 229 | 230 | int SWIG_ConvertPtr(obj, ptr,...) { 231 | if () { 232 | if () { 233 | *ptr = ; 234 | return SWIG_NEWOBJ; 235 | } else { 236 | *ptr = ; 237 | return SWIG_OLDOBJ; 238 | } 239 | } else { 240 | return SWIG_BADOBJ; 241 | } 242 | } 243 | 244 | Of course, returning the plain '0(success)/-1(fail)' still works, but you can be 245 | more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the 246 | SWIG errors code. 247 | 248 | Finally, if the SWIG_CASTRANK_MODE is enabled, the result code 249 | allows to return the 'cast rank', for example, if you have this 250 | 251 | int food(double) 252 | int fooi(int); 253 | 254 | and you call 255 | 256 | food(1) // cast rank '1' (1 -> 1.0) 257 | fooi(1) // cast rank '0' 258 | 259 | just use the SWIG_AddCast()/SWIG_CheckState() 260 | */ 261 | 262 | #define SWIG_OK (0) 263 | #define SWIG_ERROR (-1) 264 | #define SWIG_IsOK(r) (r >= 0) 265 | #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) 266 | 267 | /* The CastRankLimit says how many bits are used for the cast rank */ 268 | #define SWIG_CASTRANKLIMIT (1 << 8) 269 | /* The NewMask denotes the object was created (using new/malloc) */ 270 | #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) 271 | /* The TmpMask is for in/out typemaps that use temporal objects */ 272 | #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) 273 | /* Simple returning values */ 274 | #define SWIG_BADOBJ (SWIG_ERROR) 275 | #define SWIG_OLDOBJ (SWIG_OK) 276 | #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) 277 | #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) 278 | /* Check, add and del mask methods */ 279 | #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) 280 | #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) 281 | #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) 282 | #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) 283 | #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) 284 | #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) 285 | 286 | /* Cast-Rank Mode */ 287 | #if defined(SWIG_CASTRANK_MODE) 288 | # ifndef SWIG_TypeRank 289 | # define SWIG_TypeRank unsigned long 290 | # endif 291 | # ifndef SWIG_MAXCASTRANK /* Default cast allowed */ 292 | # define SWIG_MAXCASTRANK (2) 293 | # endif 294 | # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) 295 | # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) 296 | SWIGINTERNINLINE int SWIG_AddCast(int r) { 297 | return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; 298 | } 299 | SWIGINTERNINLINE int SWIG_CheckState(int r) { 300 | return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; 301 | } 302 | #else /* no cast-rank mode */ 303 | # define SWIG_AddCast(r) (r) 304 | # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) 305 | #endif 306 | 307 | 308 | #include 309 | 310 | #ifdef __cplusplus 311 | extern "C" { 312 | #endif 313 | 314 | typedef void *(*swig_converter_func)(void *, int *); 315 | typedef struct swig_type_info *(*swig_dycast_func)(void **); 316 | 317 | /* Structure to store information on one type */ 318 | typedef struct swig_type_info { 319 | const char *name; /* mangled name of this type */ 320 | const char *str; /* human readable name of this type */ 321 | swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ 322 | struct swig_cast_info *cast; /* linked list of types that can cast into this type */ 323 | void *clientdata; /* language specific type data */ 324 | int owndata; /* flag if the structure owns the clientdata */ 325 | } swig_type_info; 326 | 327 | /* Structure to store a type and conversion function used for casting */ 328 | typedef struct swig_cast_info { 329 | swig_type_info *type; /* pointer to type that is equivalent to this type */ 330 | swig_converter_func converter; /* function to cast the void pointers */ 331 | struct swig_cast_info *next; /* pointer to next cast in linked list */ 332 | struct swig_cast_info *prev; /* pointer to the previous cast */ 333 | } swig_cast_info; 334 | 335 | /* Structure used to store module information 336 | * Each module generates one structure like this, and the runtime collects 337 | * all of these structures and stores them in a circularly linked list.*/ 338 | typedef struct swig_module_info { 339 | swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ 340 | size_t size; /* Number of types in this module */ 341 | struct swig_module_info *next; /* Pointer to next element in circularly linked list */ 342 | swig_type_info **type_initial; /* Array of initially generated type structures */ 343 | swig_cast_info **cast_initial; /* Array of initially generated casting structures */ 344 | void *clientdata; /* Language specific module data */ 345 | } swig_module_info; 346 | 347 | /* 348 | Compare two type names skipping the space characters, therefore 349 | "char*" == "char *" and "Class" == "Class", etc. 350 | 351 | Return 0 when the two name types are equivalent, as in 352 | strncmp, but skipping ' '. 353 | */ 354 | SWIGRUNTIME int 355 | SWIG_TypeNameComp(const char *f1, const char *l1, 356 | const char *f2, const char *l2) { 357 | for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { 358 | while ((*f1 == ' ') && (f1 != l1)) ++f1; 359 | while ((*f2 == ' ') && (f2 != l2)) ++f2; 360 | if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; 361 | } 362 | return (int)((l1 - f1) - (l2 - f2)); 363 | } 364 | 365 | /* 366 | Check type equivalence in a name list like ||... 367 | Return 0 if equal, -1 if nb < tb, 1 if nb > tb 368 | */ 369 | SWIGRUNTIME int 370 | SWIG_TypeCmp(const char *nb, const char *tb) { 371 | int equiv = 1; 372 | const char* te = tb + strlen(tb); 373 | const char* ne = nb; 374 | while (equiv != 0 && *ne) { 375 | for (nb = ne; *ne; ++ne) { 376 | if (*ne == '|') break; 377 | } 378 | equiv = SWIG_TypeNameComp(nb, ne, tb, te); 379 | if (*ne) ++ne; 380 | } 381 | return equiv; 382 | } 383 | 384 | /* 385 | Check type equivalence in a name list like ||... 386 | Return 0 if not equal, 1 if equal 387 | */ 388 | SWIGRUNTIME int 389 | SWIG_TypeEquiv(const char *nb, const char *tb) { 390 | return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; 391 | } 392 | 393 | /* 394 | Check the typename 395 | */ 396 | SWIGRUNTIME swig_cast_info * 397 | SWIG_TypeCheck(const char *c, swig_type_info *ty) { 398 | if (ty) { 399 | swig_cast_info *iter = ty->cast; 400 | while (iter) { 401 | if (strcmp(iter->type->name, c) == 0) { 402 | if (iter == ty->cast) 403 | return iter; 404 | /* Move iter to the top of the linked list */ 405 | iter->prev->next = iter->next; 406 | if (iter->next) 407 | iter->next->prev = iter->prev; 408 | iter->next = ty->cast; 409 | iter->prev = 0; 410 | if (ty->cast) ty->cast->prev = iter; 411 | ty->cast = iter; 412 | return iter; 413 | } 414 | iter = iter->next; 415 | } 416 | } 417 | return 0; 418 | } 419 | 420 | /* 421 | Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison 422 | */ 423 | SWIGRUNTIME swig_cast_info * 424 | SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { 425 | if (ty) { 426 | swig_cast_info *iter = ty->cast; 427 | while (iter) { 428 | if (iter->type == from) { 429 | if (iter == ty->cast) 430 | return iter; 431 | /* Move iter to the top of the linked list */ 432 | iter->prev->next = iter->next; 433 | if (iter->next) 434 | iter->next->prev = iter->prev; 435 | iter->next = ty->cast; 436 | iter->prev = 0; 437 | if (ty->cast) ty->cast->prev = iter; 438 | ty->cast = iter; 439 | return iter; 440 | } 441 | iter = iter->next; 442 | } 443 | } 444 | return 0; 445 | } 446 | 447 | /* 448 | Cast a pointer up an inheritance hierarchy 449 | */ 450 | SWIGRUNTIMEINLINE void * 451 | SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { 452 | return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); 453 | } 454 | 455 | /* 456 | Dynamic pointer casting. Down an inheritance hierarchy 457 | */ 458 | SWIGRUNTIME swig_type_info * 459 | SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { 460 | swig_type_info *lastty = ty; 461 | if (!ty || !ty->dcast) return ty; 462 | while (ty && (ty->dcast)) { 463 | ty = (*ty->dcast)(ptr); 464 | if (ty) lastty = ty; 465 | } 466 | return lastty; 467 | } 468 | 469 | /* 470 | Return the name associated with this type 471 | */ 472 | SWIGRUNTIMEINLINE const char * 473 | SWIG_TypeName(const swig_type_info *ty) { 474 | return ty->name; 475 | } 476 | 477 | /* 478 | Return the pretty name associated with this type, 479 | that is an unmangled type name in a form presentable to the user. 480 | */ 481 | SWIGRUNTIME const char * 482 | SWIG_TypePrettyName(const swig_type_info *type) { 483 | /* The "str" field contains the equivalent pretty names of the 484 | type, separated by vertical-bar characters. We choose 485 | to print the last name, as it is often (?) the most 486 | specific. */ 487 | if (!type) return NULL; 488 | if (type->str != NULL) { 489 | const char *last_name = type->str; 490 | const char *s; 491 | for (s = type->str; *s; s++) 492 | if (*s == '|') last_name = s+1; 493 | return last_name; 494 | } 495 | else 496 | return type->name; 497 | } 498 | 499 | /* 500 | Set the clientdata field for a type 501 | */ 502 | SWIGRUNTIME void 503 | SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { 504 | swig_cast_info *cast = ti->cast; 505 | /* if (ti->clientdata == clientdata) return; */ 506 | ti->clientdata = clientdata; 507 | 508 | while (cast) { 509 | if (!cast->converter) { 510 | swig_type_info *tc = cast->type; 511 | if (!tc->clientdata) { 512 | SWIG_TypeClientData(tc, clientdata); 513 | } 514 | } 515 | cast = cast->next; 516 | } 517 | } 518 | SWIGRUNTIME void 519 | SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { 520 | SWIG_TypeClientData(ti, clientdata); 521 | ti->owndata = 1; 522 | } 523 | 524 | /* 525 | Search for a swig_type_info structure only by mangled name 526 | Search is a O(log #types) 527 | 528 | We start searching at module start, and finish searching when start == end. 529 | Note: if start == end at the beginning of the function, we go all the way around 530 | the circular list. 531 | */ 532 | SWIGRUNTIME swig_type_info * 533 | SWIG_MangledTypeQueryModule(swig_module_info *start, 534 | swig_module_info *end, 535 | const char *name) { 536 | swig_module_info *iter = start; 537 | do { 538 | if (iter->size) { 539 | register size_t l = 0; 540 | register size_t r = iter->size - 1; 541 | do { 542 | /* since l+r >= 0, we can (>> 1) instead (/ 2) */ 543 | register size_t i = (l + r) >> 1; 544 | const char *iname = iter->types[i]->name; 545 | if (iname) { 546 | register int compare = strcmp(name, iname); 547 | if (compare == 0) { 548 | return iter->types[i]; 549 | } else if (compare < 0) { 550 | if (i) { 551 | r = i - 1; 552 | } else { 553 | break; 554 | } 555 | } else if (compare > 0) { 556 | l = i + 1; 557 | } 558 | } else { 559 | break; /* should never happen */ 560 | } 561 | } while (l <= r); 562 | } 563 | iter = iter->next; 564 | } while (iter != end); 565 | return 0; 566 | } 567 | 568 | /* 569 | Search for a swig_type_info structure for either a mangled name or a human readable name. 570 | It first searches the mangled names of the types, which is a O(log #types) 571 | If a type is not found it then searches the human readable names, which is O(#types). 572 | 573 | We start searching at module start, and finish searching when start == end. 574 | Note: if start == end at the beginning of the function, we go all the way around 575 | the circular list. 576 | */ 577 | SWIGRUNTIME swig_type_info * 578 | SWIG_TypeQueryModule(swig_module_info *start, 579 | swig_module_info *end, 580 | const char *name) { 581 | /* STEP 1: Search the name field using binary search */ 582 | swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); 583 | if (ret) { 584 | return ret; 585 | } else { 586 | /* STEP 2: If the type hasn't been found, do a complete search 587 | of the str field (the human readable name) */ 588 | swig_module_info *iter = start; 589 | do { 590 | register size_t i = 0; 591 | for (; i < iter->size; ++i) { 592 | if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) 593 | return iter->types[i]; 594 | } 595 | iter = iter->next; 596 | } while (iter != end); 597 | } 598 | 599 | /* neither found a match */ 600 | return 0; 601 | } 602 | 603 | /* 604 | Pack binary data into a string 605 | */ 606 | SWIGRUNTIME char * 607 | SWIG_PackData(char *c, void *ptr, size_t sz) { 608 | static const char hex[17] = "0123456789abcdef"; 609 | register const unsigned char *u = (unsigned char *) ptr; 610 | register const unsigned char *eu = u + sz; 611 | for (; u != eu; ++u) { 612 | register unsigned char uu = *u; 613 | *(c++) = hex[(uu & 0xf0) >> 4]; 614 | *(c++) = hex[uu & 0xf]; 615 | } 616 | return c; 617 | } 618 | 619 | /* 620 | Unpack binary data from a string 621 | */ 622 | SWIGRUNTIME const char * 623 | SWIG_UnpackData(const char *c, void *ptr, size_t sz) { 624 | register unsigned char *u = (unsigned char *) ptr; 625 | register const unsigned char *eu = u + sz; 626 | for (; u != eu; ++u) { 627 | register char d = *(c++); 628 | register unsigned char uu; 629 | if ((d >= '0') && (d <= '9')) 630 | uu = ((d - '0') << 4); 631 | else if ((d >= 'a') && (d <= 'f')) 632 | uu = ((d - ('a'-10)) << 4); 633 | else 634 | return (char *) 0; 635 | d = *(c++); 636 | if ((d >= '0') && (d <= '9')) 637 | uu |= (d - '0'); 638 | else if ((d >= 'a') && (d <= 'f')) 639 | uu |= (d - ('a'-10)); 640 | else 641 | return (char *) 0; 642 | *u = uu; 643 | } 644 | return c; 645 | } 646 | 647 | /* 648 | Pack 'void *' into a string buffer. 649 | */ 650 | SWIGRUNTIME char * 651 | SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { 652 | char *r = buff; 653 | if ((2*sizeof(void *) + 2) > bsz) return 0; 654 | *(r++) = '_'; 655 | r = SWIG_PackData(r,&ptr,sizeof(void *)); 656 | if (strlen(name) + 1 > (bsz - (r - buff))) return 0; 657 | strcpy(r,name); 658 | return buff; 659 | } 660 | 661 | SWIGRUNTIME const char * 662 | SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { 663 | if (*c != '_') { 664 | if (strcmp(c,"NULL") == 0) { 665 | *ptr = (void *) 0; 666 | return name; 667 | } else { 668 | return 0; 669 | } 670 | } 671 | return SWIG_UnpackData(++c,ptr,sizeof(void *)); 672 | } 673 | 674 | SWIGRUNTIME char * 675 | SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { 676 | char *r = buff; 677 | size_t lname = (name ? strlen(name) : 0); 678 | if ((2*sz + 2 + lname) > bsz) return 0; 679 | *(r++) = '_'; 680 | r = SWIG_PackData(r,ptr,sz); 681 | if (lname) { 682 | strncpy(r,name,lname+1); 683 | } else { 684 | *r = 0; 685 | } 686 | return buff; 687 | } 688 | 689 | SWIGRUNTIME const char * 690 | SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { 691 | if (*c != '_') { 692 | if (strcmp(c,"NULL") == 0) { 693 | memset(ptr,0,sz); 694 | return name; 695 | } else { 696 | return 0; 697 | } 698 | } 699 | return SWIG_UnpackData(++c,ptr,sz); 700 | } 701 | 702 | #ifdef __cplusplus 703 | } 704 | #endif 705 | 706 | /* Errors in SWIG */ 707 | #define SWIG_UnknownError -1 708 | #define SWIG_IOError -2 709 | #define SWIG_RuntimeError -3 710 | #define SWIG_IndexError -4 711 | #define SWIG_TypeError -5 712 | #define SWIG_DivisionByZero -6 713 | #define SWIG_OverflowError -7 714 | #define SWIG_SyntaxError -8 715 | #define SWIG_ValueError -9 716 | #define SWIG_SystemError -10 717 | #define SWIG_AttributeError -11 718 | #define SWIG_MemoryError -12 719 | #define SWIG_NullReferenceError -13 720 | 721 | 722 | 723 | /* Compatibility macros for Python 3 */ 724 | #if PY_VERSION_HEX >= 0x03000000 725 | 726 | #define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type) 727 | #define PyInt_Check(x) PyLong_Check(x) 728 | #define PyInt_AsLong(x) PyLong_AsLong(x) 729 | #define PyInt_FromLong(x) PyLong_FromLong(x) 730 | #define PyInt_FromSize_t(x) PyLong_FromSize_t(x) 731 | #define PyString_Check(name) PyBytes_Check(name) 732 | #define PyString_FromString(x) PyUnicode_FromString(x) 733 | #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) 734 | #define PyString_AsString(str) PyBytes_AsString(str) 735 | #define PyString_Size(str) PyBytes_Size(str) 736 | #define PyString_InternFromString(key) PyUnicode_InternFromString(key) 737 | #define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE 738 | #define PyString_AS_STRING(x) PyUnicode_AS_STRING(x) 739 | #define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x) 740 | 741 | #endif 742 | 743 | #ifndef Py_TYPE 744 | # define Py_TYPE(op) ((op)->ob_type) 745 | #endif 746 | 747 | /* SWIG APIs for compatibility of both Python 2 & 3 */ 748 | 749 | #if PY_VERSION_HEX >= 0x03000000 750 | # define SWIG_Python_str_FromFormat PyUnicode_FromFormat 751 | #else 752 | # define SWIG_Python_str_FromFormat PyString_FromFormat 753 | #endif 754 | 755 | 756 | /* Warning: This function will allocate a new string in Python 3, 757 | * so please call SWIG_Python_str_DelForPy3(x) to free the space. 758 | */ 759 | SWIGINTERN char* 760 | SWIG_Python_str_AsChar(PyObject *str) 761 | { 762 | #if PY_VERSION_HEX >= 0x03000000 763 | char *cstr; 764 | char *newstr; 765 | Py_ssize_t len; 766 | str = PyUnicode_AsUTF8String(str); 767 | PyBytes_AsStringAndSize(str, &cstr, &len); 768 | newstr = (char *) malloc(len+1); 769 | memcpy(newstr, cstr, len+1); 770 | Py_XDECREF(str); 771 | return newstr; 772 | #else 773 | return PyString_AsString(str); 774 | #endif 775 | } 776 | 777 | #if PY_VERSION_HEX >= 0x03000000 778 | # define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) 779 | #else 780 | # define SWIG_Python_str_DelForPy3(x) 781 | #endif 782 | 783 | 784 | SWIGINTERN PyObject* 785 | SWIG_Python_str_FromChar(const char *c) 786 | { 787 | #if PY_VERSION_HEX >= 0x03000000 788 | return PyUnicode_FromString(c); 789 | #else 790 | return PyString_FromString(c); 791 | #endif 792 | } 793 | 794 | /* Add PyOS_snprintf for old Pythons */ 795 | #if PY_VERSION_HEX < 0x02020000 796 | # if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) 797 | # define PyOS_snprintf _snprintf 798 | # else 799 | # define PyOS_snprintf snprintf 800 | # endif 801 | #endif 802 | 803 | /* A crude PyString_FromFormat implementation for old Pythons */ 804 | #if PY_VERSION_HEX < 0x02020000 805 | 806 | #ifndef SWIG_PYBUFFER_SIZE 807 | # define SWIG_PYBUFFER_SIZE 1024 808 | #endif 809 | 810 | static PyObject * 811 | PyString_FromFormat(const char *fmt, ...) { 812 | va_list ap; 813 | char buf[SWIG_PYBUFFER_SIZE * 2]; 814 | int res; 815 | va_start(ap, fmt); 816 | res = vsnprintf(buf, sizeof(buf), fmt, ap); 817 | va_end(ap); 818 | return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); 819 | } 820 | #endif 821 | 822 | /* Add PyObject_Del for old Pythons */ 823 | #if PY_VERSION_HEX < 0x01060000 824 | # define PyObject_Del(op) PyMem_DEL((op)) 825 | #endif 826 | #ifndef PyObject_DEL 827 | # define PyObject_DEL PyObject_Del 828 | #endif 829 | 830 | /* A crude PyExc_StopIteration exception for old Pythons */ 831 | #if PY_VERSION_HEX < 0x02020000 832 | # ifndef PyExc_StopIteration 833 | # define PyExc_StopIteration PyExc_RuntimeError 834 | # endif 835 | # ifndef PyObject_GenericGetAttr 836 | # define PyObject_GenericGetAttr 0 837 | # endif 838 | #endif 839 | 840 | /* Py_NotImplemented is defined in 2.1 and up. */ 841 | #if PY_VERSION_HEX < 0x02010000 842 | # ifndef Py_NotImplemented 843 | # define Py_NotImplemented PyExc_RuntimeError 844 | # endif 845 | #endif 846 | 847 | /* A crude PyString_AsStringAndSize implementation for old Pythons */ 848 | #if PY_VERSION_HEX < 0x02010000 849 | # ifndef PyString_AsStringAndSize 850 | # define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} 851 | # endif 852 | #endif 853 | 854 | /* PySequence_Size for old Pythons */ 855 | #if PY_VERSION_HEX < 0x02000000 856 | # ifndef PySequence_Size 857 | # define PySequence_Size PySequence_Length 858 | # endif 859 | #endif 860 | 861 | /* PyBool_FromLong for old Pythons */ 862 | #if PY_VERSION_HEX < 0x02030000 863 | static 864 | PyObject *PyBool_FromLong(long ok) 865 | { 866 | PyObject *result = ok ? Py_True : Py_False; 867 | Py_INCREF(result); 868 | return result; 869 | } 870 | #endif 871 | 872 | /* Py_ssize_t for old Pythons */ 873 | /* This code is as recommended by: */ 874 | /* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ 875 | #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) 876 | typedef int Py_ssize_t; 877 | # define PY_SSIZE_T_MAX INT_MAX 878 | # define PY_SSIZE_T_MIN INT_MIN 879 | typedef inquiry lenfunc; 880 | typedef intargfunc ssizeargfunc; 881 | typedef intintargfunc ssizessizeargfunc; 882 | typedef intobjargproc ssizeobjargproc; 883 | typedef intintobjargproc ssizessizeobjargproc; 884 | typedef getreadbufferproc readbufferproc; 885 | typedef getwritebufferproc writebufferproc; 886 | typedef getsegcountproc segcountproc; 887 | typedef getcharbufferproc charbufferproc; 888 | static long PyNumber_AsSsize_t (PyObject *x, void *SWIGUNUSEDPARM(exc)) 889 | { 890 | long result = 0; 891 | PyObject *i = PyNumber_Int(x); 892 | if (i) { 893 | result = PyInt_AsLong(i); 894 | Py_DECREF(i); 895 | } 896 | return result; 897 | } 898 | #endif 899 | 900 | #if PY_VERSION_HEX < 0x02050000 901 | #define PyInt_FromSize_t(x) PyInt_FromLong((long)x) 902 | #endif 903 | 904 | #if PY_VERSION_HEX < 0x02040000 905 | #define Py_VISIT(op) \ 906 | do { \ 907 | if (op) { \ 908 | int vret = visit((op), arg); \ 909 | if (vret) \ 910 | return vret; \ 911 | } \ 912 | } while (0) 913 | #endif 914 | 915 | #if PY_VERSION_HEX < 0x02030000 916 | typedef struct { 917 | PyTypeObject type; 918 | PyNumberMethods as_number; 919 | PyMappingMethods as_mapping; 920 | PySequenceMethods as_sequence; 921 | PyBufferProcs as_buffer; 922 | PyObject *name, *slots; 923 | } PyHeapTypeObject; 924 | #endif 925 | 926 | #if PY_VERSION_HEX < 0x02030000 927 | typedef destructor freefunc; 928 | #endif 929 | 930 | #if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION > 6) || \ 931 | (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 0) || \ 932 | (PY_MAJOR_VERSION > 3)) 933 | # define SWIGPY_USE_CAPSULE 934 | # define SWIGPY_CAPSULE_NAME ((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME) 935 | #endif 936 | 937 | #if PY_VERSION_HEX < 0x03020000 938 | #define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type) 939 | #define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name) 940 | #endif 941 | 942 | /* ----------------------------------------------------------------------------- 943 | * error manipulation 944 | * ----------------------------------------------------------------------------- */ 945 | 946 | SWIGRUNTIME PyObject* 947 | SWIG_Python_ErrorType(int code) { 948 | PyObject* type = 0; 949 | switch(code) { 950 | case SWIG_MemoryError: 951 | type = PyExc_MemoryError; 952 | break; 953 | case SWIG_IOError: 954 | type = PyExc_IOError; 955 | break; 956 | case SWIG_RuntimeError: 957 | type = PyExc_RuntimeError; 958 | break; 959 | case SWIG_IndexError: 960 | type = PyExc_IndexError; 961 | break; 962 | case SWIG_TypeError: 963 | type = PyExc_TypeError; 964 | break; 965 | case SWIG_DivisionByZero: 966 | type = PyExc_ZeroDivisionError; 967 | break; 968 | case SWIG_OverflowError: 969 | type = PyExc_OverflowError; 970 | break; 971 | case SWIG_SyntaxError: 972 | type = PyExc_SyntaxError; 973 | break; 974 | case SWIG_ValueError: 975 | type = PyExc_ValueError; 976 | break; 977 | case SWIG_SystemError: 978 | type = PyExc_SystemError; 979 | break; 980 | case SWIG_AttributeError: 981 | type = PyExc_AttributeError; 982 | break; 983 | default: 984 | type = PyExc_RuntimeError; 985 | } 986 | return type; 987 | } 988 | 989 | 990 | SWIGRUNTIME void 991 | SWIG_Python_AddErrorMsg(const char* mesg) 992 | { 993 | PyObject *type = 0; 994 | PyObject *value = 0; 995 | PyObject *traceback = 0; 996 | 997 | if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); 998 | if (value) { 999 | char *tmp; 1000 | PyObject *old_str = PyObject_Str(value); 1001 | PyErr_Clear(); 1002 | Py_XINCREF(type); 1003 | 1004 | PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); 1005 | SWIG_Python_str_DelForPy3(tmp); 1006 | Py_DECREF(old_str); 1007 | Py_DECREF(value); 1008 | } else { 1009 | PyErr_SetString(PyExc_RuntimeError, mesg); 1010 | } 1011 | } 1012 | 1013 | #if defined(SWIG_PYTHON_NO_THREADS) 1014 | # if defined(SWIG_PYTHON_THREADS) 1015 | # undef SWIG_PYTHON_THREADS 1016 | # endif 1017 | #endif 1018 | #if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ 1019 | # if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) 1020 | # if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ 1021 | # define SWIG_PYTHON_USE_GIL 1022 | # endif 1023 | # endif 1024 | # if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ 1025 | # ifndef SWIG_PYTHON_INITIALIZE_THREADS 1026 | # define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() 1027 | # endif 1028 | # ifdef __cplusplus /* C++ code */ 1029 | class SWIG_Python_Thread_Block { 1030 | bool status; 1031 | PyGILState_STATE state; 1032 | public: 1033 | void end() { if (status) { PyGILState_Release(state); status = false;} } 1034 | SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} 1035 | ~SWIG_Python_Thread_Block() { end(); } 1036 | }; 1037 | class SWIG_Python_Thread_Allow { 1038 | bool status; 1039 | PyThreadState *save; 1040 | public: 1041 | void end() { if (status) { PyEval_RestoreThread(save); status = false; }} 1042 | SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} 1043 | ~SWIG_Python_Thread_Allow() { end(); } 1044 | }; 1045 | # define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block 1046 | # define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() 1047 | # define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow 1048 | # define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() 1049 | # else /* C code */ 1050 | # define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() 1051 | # define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) 1052 | # define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() 1053 | # define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) 1054 | # endif 1055 | # else /* Old thread way, not implemented, user must provide it */ 1056 | # if !defined(SWIG_PYTHON_INITIALIZE_THREADS) 1057 | # define SWIG_PYTHON_INITIALIZE_THREADS 1058 | # endif 1059 | # if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) 1060 | # define SWIG_PYTHON_THREAD_BEGIN_BLOCK 1061 | # endif 1062 | # if !defined(SWIG_PYTHON_THREAD_END_BLOCK) 1063 | # define SWIG_PYTHON_THREAD_END_BLOCK 1064 | # endif 1065 | # if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) 1066 | # define SWIG_PYTHON_THREAD_BEGIN_ALLOW 1067 | # endif 1068 | # if !defined(SWIG_PYTHON_THREAD_END_ALLOW) 1069 | # define SWIG_PYTHON_THREAD_END_ALLOW 1070 | # endif 1071 | # endif 1072 | #else /* No thread support */ 1073 | # define SWIG_PYTHON_INITIALIZE_THREADS 1074 | # define SWIG_PYTHON_THREAD_BEGIN_BLOCK 1075 | # define SWIG_PYTHON_THREAD_END_BLOCK 1076 | # define SWIG_PYTHON_THREAD_BEGIN_ALLOW 1077 | # define SWIG_PYTHON_THREAD_END_ALLOW 1078 | #endif 1079 | 1080 | /* ----------------------------------------------------------------------------- 1081 | * Python API portion that goes into the runtime 1082 | * ----------------------------------------------------------------------------- */ 1083 | 1084 | #ifdef __cplusplus 1085 | extern "C" { 1086 | #endif 1087 | 1088 | /* ----------------------------------------------------------------------------- 1089 | * Constant declarations 1090 | * ----------------------------------------------------------------------------- */ 1091 | 1092 | /* Constant Types */ 1093 | #define SWIG_PY_POINTER 4 1094 | #define SWIG_PY_BINARY 5 1095 | 1096 | /* Constant information structure */ 1097 | typedef struct swig_const_info { 1098 | int type; 1099 | char *name; 1100 | long lvalue; 1101 | double dvalue; 1102 | void *pvalue; 1103 | swig_type_info **ptype; 1104 | } swig_const_info; 1105 | 1106 | 1107 | /* ----------------------------------------------------------------------------- 1108 | * Wrapper of PyInstanceMethod_New() used in Python 3 1109 | * It is exported to the generated module, used for -fastproxy 1110 | * ----------------------------------------------------------------------------- */ 1111 | #if PY_VERSION_HEX >= 0x03000000 1112 | SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) 1113 | { 1114 | return PyInstanceMethod_New(func); 1115 | } 1116 | #else 1117 | SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(func)) 1118 | { 1119 | return NULL; 1120 | } 1121 | #endif 1122 | 1123 | #ifdef __cplusplus 1124 | } 1125 | #endif 1126 | 1127 | 1128 | /* ----------------------------------------------------------------------------- 1129 | * pyrun.swg 1130 | * 1131 | * This file contains the runtime support for Python modules 1132 | * and includes code for managing global variables and pointer 1133 | * type checking. 1134 | * 1135 | * ----------------------------------------------------------------------------- */ 1136 | 1137 | /* Common SWIG API */ 1138 | 1139 | /* for raw pointers */ 1140 | #define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) 1141 | #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) 1142 | #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) 1143 | 1144 | #ifdef SWIGPYTHON_BUILTIN 1145 | #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(self, ptr, type, flags) 1146 | #else 1147 | #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) 1148 | #endif 1149 | 1150 | #define SWIG_InternalNewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) 1151 | 1152 | #define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) 1153 | #define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) 1154 | #define swig_owntype int 1155 | 1156 | /* for raw packed data */ 1157 | #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) 1158 | #define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) 1159 | 1160 | /* for class or struct pointers */ 1161 | #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) 1162 | #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) 1163 | 1164 | /* for C or C++ function pointers */ 1165 | #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) 1166 | #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(NULL, ptr, type, 0) 1167 | 1168 | /* for C++ member pointers, ie, member methods */ 1169 | #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) 1170 | #define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) 1171 | 1172 | 1173 | /* Runtime API */ 1174 | 1175 | #define SWIG_GetModule(clientdata) SWIG_Python_GetModule(clientdata) 1176 | #define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) 1177 | #define SWIG_NewClientData(obj) SwigPyClientData_New(obj) 1178 | 1179 | #define SWIG_SetErrorObj SWIG_Python_SetErrorObj 1180 | #define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg 1181 | #define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) 1182 | #define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) 1183 | #define SWIG_fail goto fail 1184 | 1185 | 1186 | /* Runtime API implementation */ 1187 | 1188 | /* Error manipulation */ 1189 | 1190 | SWIGINTERN void 1191 | SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { 1192 | SWIG_PYTHON_THREAD_BEGIN_BLOCK; 1193 | PyErr_SetObject(errtype, obj); 1194 | Py_DECREF(obj); 1195 | SWIG_PYTHON_THREAD_END_BLOCK; 1196 | } 1197 | 1198 | SWIGINTERN void 1199 | SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { 1200 | SWIG_PYTHON_THREAD_BEGIN_BLOCK; 1201 | PyErr_SetString(errtype, msg); 1202 | SWIG_PYTHON_THREAD_END_BLOCK; 1203 | } 1204 | 1205 | #define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) 1206 | 1207 | /* Set a constant value */ 1208 | 1209 | #if defined(SWIGPYTHON_BUILTIN) 1210 | 1211 | SWIGINTERN void 1212 | SwigPyBuiltin_AddPublicSymbol(PyObject *seq, const char *key) { 1213 | PyObject *s = PyString_InternFromString(key); 1214 | PyList_Append(seq, s); 1215 | Py_DECREF(s); 1216 | } 1217 | 1218 | SWIGINTERN void 1219 | SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { 1220 | #if PY_VERSION_HEX < 0x02030000 1221 | PyDict_SetItemString(d, (char *)name, obj); 1222 | #else 1223 | PyDict_SetItemString(d, name, obj); 1224 | #endif 1225 | Py_DECREF(obj); 1226 | if (public_interface) 1227 | SwigPyBuiltin_AddPublicSymbol(public_interface, name); 1228 | } 1229 | 1230 | #else 1231 | 1232 | SWIGINTERN void 1233 | SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { 1234 | #if PY_VERSION_HEX < 0x02030000 1235 | PyDict_SetItemString(d, (char *)name, obj); 1236 | #else 1237 | PyDict_SetItemString(d, name, obj); 1238 | #endif 1239 | Py_DECREF(obj); 1240 | } 1241 | 1242 | #endif 1243 | 1244 | /* Append a value to the result obj */ 1245 | 1246 | SWIGINTERN PyObject* 1247 | SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { 1248 | #if !defined(SWIG_PYTHON_OUTPUT_TUPLE) 1249 | if (!result) { 1250 | result = obj; 1251 | } else if (result == Py_None) { 1252 | Py_DECREF(result); 1253 | result = obj; 1254 | } else { 1255 | if (!PyList_Check(result)) { 1256 | PyObject *o2 = result; 1257 | result = PyList_New(1); 1258 | PyList_SetItem(result, 0, o2); 1259 | } 1260 | PyList_Append(result,obj); 1261 | Py_DECREF(obj); 1262 | } 1263 | return result; 1264 | #else 1265 | PyObject* o2; 1266 | PyObject* o3; 1267 | if (!result) { 1268 | result = obj; 1269 | } else if (result == Py_None) { 1270 | Py_DECREF(result); 1271 | result = obj; 1272 | } else { 1273 | if (!PyTuple_Check(result)) { 1274 | o2 = result; 1275 | result = PyTuple_New(1); 1276 | PyTuple_SET_ITEM(result, 0, o2); 1277 | } 1278 | o3 = PyTuple_New(1); 1279 | PyTuple_SET_ITEM(o3, 0, obj); 1280 | o2 = result; 1281 | result = PySequence_Concat(o2, o3); 1282 | Py_DECREF(o2); 1283 | Py_DECREF(o3); 1284 | } 1285 | return result; 1286 | #endif 1287 | } 1288 | 1289 | /* Unpack the argument tuple */ 1290 | 1291 | SWIGINTERN int 1292 | SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) 1293 | { 1294 | if (!args) { 1295 | if (!min && !max) { 1296 | return 1; 1297 | } else { 1298 | PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", 1299 | name, (min == max ? "" : "at least "), (int)min); 1300 | return 0; 1301 | } 1302 | } 1303 | if (!PyTuple_Check(args)) { 1304 | if (min <= 1 && max >= 1) { 1305 | register int i; 1306 | objs[0] = args; 1307 | for (i = 1; i < max; ++i) { 1308 | objs[i] = 0; 1309 | } 1310 | return 2; 1311 | } 1312 | PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); 1313 | return 0; 1314 | } else { 1315 | register Py_ssize_t l = PyTuple_GET_SIZE(args); 1316 | if (l < min) { 1317 | PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", 1318 | name, (min == max ? "" : "at least "), (int)min, (int)l); 1319 | return 0; 1320 | } else if (l > max) { 1321 | PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", 1322 | name, (min == max ? "" : "at most "), (int)max, (int)l); 1323 | return 0; 1324 | } else { 1325 | register int i; 1326 | for (i = 0; i < l; ++i) { 1327 | objs[i] = PyTuple_GET_ITEM(args, i); 1328 | } 1329 | for (; l < max; ++l) { 1330 | objs[l] = 0; 1331 | } 1332 | return i + 1; 1333 | } 1334 | } 1335 | } 1336 | 1337 | /* A functor is a function object with one single object argument */ 1338 | #if PY_VERSION_HEX >= 0x02020000 1339 | #define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); 1340 | #else 1341 | #define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); 1342 | #endif 1343 | 1344 | /* 1345 | Helper for static pointer initialization for both C and C++ code, for example 1346 | static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); 1347 | */ 1348 | #ifdef __cplusplus 1349 | #define SWIG_STATIC_POINTER(var) var 1350 | #else 1351 | #define SWIG_STATIC_POINTER(var) var = 0; if (!var) var 1352 | #endif 1353 | 1354 | /* ----------------------------------------------------------------------------- 1355 | * Pointer declarations 1356 | * ----------------------------------------------------------------------------- */ 1357 | 1358 | /* Flags for new pointer objects */ 1359 | #define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) 1360 | #define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) 1361 | 1362 | #define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) 1363 | 1364 | #define SWIG_BUILTIN_TP_INIT (SWIG_POINTER_OWN << 2) 1365 | #define SWIG_BUILTIN_INIT (SWIG_BUILTIN_TP_INIT | SWIG_POINTER_OWN) 1366 | 1367 | #ifdef __cplusplus 1368 | extern "C" { 1369 | #endif 1370 | 1371 | /* How to access Py_None */ 1372 | #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 1373 | # ifndef SWIG_PYTHON_NO_BUILD_NONE 1374 | # ifndef SWIG_PYTHON_BUILD_NONE 1375 | # define SWIG_PYTHON_BUILD_NONE 1376 | # endif 1377 | # endif 1378 | #endif 1379 | 1380 | #ifdef SWIG_PYTHON_BUILD_NONE 1381 | # ifdef Py_None 1382 | # undef Py_None 1383 | # define Py_None SWIG_Py_None() 1384 | # endif 1385 | SWIGRUNTIMEINLINE PyObject * 1386 | _SWIG_Py_None(void) 1387 | { 1388 | PyObject *none = Py_BuildValue((char*)""); 1389 | Py_DECREF(none); 1390 | return none; 1391 | } 1392 | SWIGRUNTIME PyObject * 1393 | SWIG_Py_None(void) 1394 | { 1395 | static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); 1396 | return none; 1397 | } 1398 | #endif 1399 | 1400 | /* The python void return value */ 1401 | 1402 | SWIGRUNTIMEINLINE PyObject * 1403 | SWIG_Py_Void(void) 1404 | { 1405 | PyObject *none = Py_None; 1406 | Py_INCREF(none); 1407 | return none; 1408 | } 1409 | 1410 | /* SwigPyClientData */ 1411 | 1412 | typedef struct { 1413 | PyObject *klass; 1414 | PyObject *newraw; 1415 | PyObject *newargs; 1416 | PyObject *destroy; 1417 | int delargs; 1418 | int implicitconv; 1419 | PyTypeObject *pytype; 1420 | } SwigPyClientData; 1421 | 1422 | SWIGRUNTIMEINLINE int 1423 | SWIG_Python_CheckImplicit(swig_type_info *ty) 1424 | { 1425 | SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; 1426 | return data ? data->implicitconv : 0; 1427 | } 1428 | 1429 | SWIGRUNTIMEINLINE PyObject * 1430 | SWIG_Python_ExceptionType(swig_type_info *desc) { 1431 | SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; 1432 | PyObject *klass = data ? data->klass : 0; 1433 | return (klass ? klass : PyExc_RuntimeError); 1434 | } 1435 | 1436 | 1437 | SWIGRUNTIME SwigPyClientData * 1438 | SwigPyClientData_New(PyObject* obj) 1439 | { 1440 | if (!obj) { 1441 | return 0; 1442 | } else { 1443 | SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); 1444 | /* the klass element */ 1445 | data->klass = obj; 1446 | Py_INCREF(data->klass); 1447 | /* the newraw method and newargs arguments used to create a new raw instance */ 1448 | if (PyClass_Check(obj)) { 1449 | data->newraw = 0; 1450 | data->newargs = obj; 1451 | Py_INCREF(obj); 1452 | } else { 1453 | #if (PY_VERSION_HEX < 0x02020000) 1454 | data->newraw = 0; 1455 | #else 1456 | data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); 1457 | #endif 1458 | if (data->newraw) { 1459 | Py_INCREF(data->newraw); 1460 | data->newargs = PyTuple_New(1); 1461 | PyTuple_SetItem(data->newargs, 0, obj); 1462 | } else { 1463 | data->newargs = obj; 1464 | } 1465 | Py_INCREF(data->newargs); 1466 | } 1467 | /* the destroy method, aka as the C++ delete method */ 1468 | data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); 1469 | if (PyErr_Occurred()) { 1470 | PyErr_Clear(); 1471 | data->destroy = 0; 1472 | } 1473 | if (data->destroy) { 1474 | int flags; 1475 | Py_INCREF(data->destroy); 1476 | flags = PyCFunction_GET_FLAGS(data->destroy); 1477 | #ifdef METH_O 1478 | data->delargs = !(flags & (METH_O)); 1479 | #else 1480 | data->delargs = 0; 1481 | #endif 1482 | } else { 1483 | data->delargs = 0; 1484 | } 1485 | data->implicitconv = 0; 1486 | data->pytype = 0; 1487 | return data; 1488 | } 1489 | } 1490 | 1491 | SWIGRUNTIME void 1492 | SwigPyClientData_Del(SwigPyClientData *data) { 1493 | Py_XDECREF(data->newraw); 1494 | Py_XDECREF(data->newargs); 1495 | Py_XDECREF(data->destroy); 1496 | } 1497 | 1498 | /* =============== SwigPyObject =====================*/ 1499 | 1500 | typedef struct { 1501 | PyObject_HEAD 1502 | void *ptr; 1503 | swig_type_info *ty; 1504 | int own; 1505 | PyObject *next; 1506 | #ifdef SWIGPYTHON_BUILTIN 1507 | PyObject *dict; 1508 | #endif 1509 | } SwigPyObject; 1510 | 1511 | SWIGRUNTIME PyObject * 1512 | SwigPyObject_long(SwigPyObject *v) 1513 | { 1514 | return PyLong_FromVoidPtr(v->ptr); 1515 | } 1516 | 1517 | SWIGRUNTIME PyObject * 1518 | SwigPyObject_format(const char* fmt, SwigPyObject *v) 1519 | { 1520 | PyObject *res = NULL; 1521 | PyObject *args = PyTuple_New(1); 1522 | if (args) { 1523 | if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) { 1524 | PyObject *ofmt = SWIG_Python_str_FromChar(fmt); 1525 | if (ofmt) { 1526 | #if PY_VERSION_HEX >= 0x03000000 1527 | res = PyUnicode_Format(ofmt,args); 1528 | #else 1529 | res = PyString_Format(ofmt,args); 1530 | #endif 1531 | Py_DECREF(ofmt); 1532 | } 1533 | Py_DECREF(args); 1534 | } 1535 | } 1536 | return res; 1537 | } 1538 | 1539 | SWIGRUNTIME PyObject * 1540 | SwigPyObject_oct(SwigPyObject *v) 1541 | { 1542 | return SwigPyObject_format("%o",v); 1543 | } 1544 | 1545 | SWIGRUNTIME PyObject * 1546 | SwigPyObject_hex(SwigPyObject *v) 1547 | { 1548 | return SwigPyObject_format("%x",v); 1549 | } 1550 | 1551 | SWIGRUNTIME PyObject * 1552 | #ifdef METH_NOARGS 1553 | SwigPyObject_repr(SwigPyObject *v) 1554 | #else 1555 | SwigPyObject_repr(SwigPyObject *v, PyObject *args) 1556 | #endif 1557 | { 1558 | const char *name = SWIG_TypePrettyName(v->ty); 1559 | PyObject *repr = SWIG_Python_str_FromFormat("", (name ? name : "unknown"), (void *)v); 1560 | if (v->next) { 1561 | # ifdef METH_NOARGS 1562 | PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); 1563 | # else 1564 | PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args); 1565 | # endif 1566 | # if PY_VERSION_HEX >= 0x03000000 1567 | PyObject *joined = PyUnicode_Concat(repr, nrep); 1568 | Py_DecRef(repr); 1569 | Py_DecRef(nrep); 1570 | repr = joined; 1571 | # else 1572 | PyString_ConcatAndDel(&repr,nrep); 1573 | # endif 1574 | } 1575 | return repr; 1576 | } 1577 | 1578 | SWIGRUNTIME int 1579 | SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) 1580 | { 1581 | void *i = v->ptr; 1582 | void *j = w->ptr; 1583 | return (i < j) ? -1 : ((i > j) ? 1 : 0); 1584 | } 1585 | 1586 | /* Added for Python 3.x, would it also be useful for Python 2.x? */ 1587 | SWIGRUNTIME PyObject* 1588 | SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) 1589 | { 1590 | PyObject* res; 1591 | if( op != Py_EQ && op != Py_NE ) { 1592 | Py_INCREF(Py_NotImplemented); 1593 | return Py_NotImplemented; 1594 | } 1595 | res = PyBool_FromLong( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ? 1 : 0); 1596 | return res; 1597 | } 1598 | 1599 | 1600 | SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void); 1601 | 1602 | #ifdef SWIGPYTHON_BUILTIN 1603 | static swig_type_info *SwigPyObject_stype = 0; 1604 | SWIGRUNTIME PyTypeObject* 1605 | SwigPyObject_type(void) { 1606 | SwigPyClientData *cd; 1607 | assert(SwigPyObject_stype); 1608 | cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; 1609 | assert(cd); 1610 | assert(cd->pytype); 1611 | return cd->pytype; 1612 | } 1613 | #else 1614 | SWIGRUNTIME PyTypeObject* 1615 | SwigPyObject_type(void) { 1616 | static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce(); 1617 | return type; 1618 | } 1619 | #endif 1620 | 1621 | SWIGRUNTIMEINLINE int 1622 | SwigPyObject_Check(PyObject *op) { 1623 | #ifdef SWIGPYTHON_BUILTIN 1624 | PyTypeObject *target_tp = SwigPyObject_type(); 1625 | if (PyType_IsSubtype(op->ob_type, target_tp)) 1626 | return 1; 1627 | return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0); 1628 | #else 1629 | return (Py_TYPE(op) == SwigPyObject_type()) 1630 | || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0); 1631 | #endif 1632 | } 1633 | 1634 | SWIGRUNTIME PyObject * 1635 | SwigPyObject_New(void *ptr, swig_type_info *ty, int own); 1636 | 1637 | SWIGRUNTIME void 1638 | SwigPyObject_dealloc(PyObject *v) 1639 | { 1640 | SwigPyObject *sobj = (SwigPyObject *) v; 1641 | PyObject *next = sobj->next; 1642 | if (sobj->own == SWIG_POINTER_OWN) { 1643 | swig_type_info *ty = sobj->ty; 1644 | SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; 1645 | PyObject *destroy = data ? data->destroy : 0; 1646 | if (destroy) { 1647 | /* destroy is always a VARARGS method */ 1648 | PyObject *res; 1649 | if (data->delargs) { 1650 | /* we need to create a temporary object to carry the destroy operation */ 1651 | PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); 1652 | res = SWIG_Python_CallFunctor(destroy, tmp); 1653 | Py_DECREF(tmp); 1654 | } else { 1655 | PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); 1656 | PyObject *mself = PyCFunction_GET_SELF(destroy); 1657 | res = ((*meth)(mself, v)); 1658 | } 1659 | Py_XDECREF(res); 1660 | } 1661 | #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) 1662 | else { 1663 | const char *name = SWIG_TypePrettyName(ty); 1664 | printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); 1665 | } 1666 | #endif 1667 | } 1668 | Py_XDECREF(next); 1669 | PyObject_DEL(v); 1670 | } 1671 | 1672 | SWIGRUNTIME PyObject* 1673 | SwigPyObject_append(PyObject* v, PyObject* next) 1674 | { 1675 | SwigPyObject *sobj = (SwigPyObject *) v; 1676 | #ifndef METH_O 1677 | PyObject *tmp = 0; 1678 | if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; 1679 | next = tmp; 1680 | #endif 1681 | if (!SwigPyObject_Check(next)) { 1682 | return NULL; 1683 | } 1684 | sobj->next = next; 1685 | Py_INCREF(next); 1686 | return SWIG_Py_Void(); 1687 | } 1688 | 1689 | SWIGRUNTIME PyObject* 1690 | #ifdef METH_NOARGS 1691 | SwigPyObject_next(PyObject* v) 1692 | #else 1693 | SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) 1694 | #endif 1695 | { 1696 | SwigPyObject *sobj = (SwigPyObject *) v; 1697 | if (sobj->next) { 1698 | Py_INCREF(sobj->next); 1699 | return sobj->next; 1700 | } else { 1701 | return SWIG_Py_Void(); 1702 | } 1703 | } 1704 | 1705 | SWIGINTERN PyObject* 1706 | #ifdef METH_NOARGS 1707 | SwigPyObject_disown(PyObject *v) 1708 | #else 1709 | SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) 1710 | #endif 1711 | { 1712 | SwigPyObject *sobj = (SwigPyObject *)v; 1713 | sobj->own = 0; 1714 | return SWIG_Py_Void(); 1715 | } 1716 | 1717 | SWIGINTERN PyObject* 1718 | #ifdef METH_NOARGS 1719 | SwigPyObject_acquire(PyObject *v) 1720 | #else 1721 | SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) 1722 | #endif 1723 | { 1724 | SwigPyObject *sobj = (SwigPyObject *)v; 1725 | sobj->own = SWIG_POINTER_OWN; 1726 | return SWIG_Py_Void(); 1727 | } 1728 | 1729 | SWIGINTERN PyObject* 1730 | SwigPyObject_own(PyObject *v, PyObject *args) 1731 | { 1732 | PyObject *val = 0; 1733 | #if (PY_VERSION_HEX < 0x02020000) 1734 | if (!PyArg_ParseTuple(args,(char *)"|O:own",&val)) 1735 | #elif (PY_VERSION_HEX < 0x02050000) 1736 | if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) 1737 | #else 1738 | if (!PyArg_UnpackTuple(args, "own", 0, 1, &val)) 1739 | #endif 1740 | { 1741 | return NULL; 1742 | } 1743 | else 1744 | { 1745 | SwigPyObject *sobj = (SwigPyObject *)v; 1746 | PyObject *obj = PyBool_FromLong(sobj->own); 1747 | if (val) { 1748 | #ifdef METH_NOARGS 1749 | if (PyObject_IsTrue(val)) { 1750 | SwigPyObject_acquire(v); 1751 | } else { 1752 | SwigPyObject_disown(v); 1753 | } 1754 | #else 1755 | if (PyObject_IsTrue(val)) { 1756 | SwigPyObject_acquire(v,args); 1757 | } else { 1758 | SwigPyObject_disown(v,args); 1759 | } 1760 | #endif 1761 | } 1762 | return obj; 1763 | } 1764 | } 1765 | 1766 | #ifdef METH_O 1767 | static PyMethodDef 1768 | swigobject_methods[] = { 1769 | {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, 1770 | {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"acquires ownership of the pointer"}, 1771 | {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, 1772 | {(char *)"append", (PyCFunction)SwigPyObject_append, METH_O, (char *)"appends another 'this' object"}, 1773 | {(char *)"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, 1774 | {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, (char *)"returns object representation"}, 1775 | {0, 0, 0, 0} 1776 | }; 1777 | #else 1778 | static PyMethodDef 1779 | swigobject_methods[] = { 1780 | {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, 1781 | {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, 1782 | {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, 1783 | {(char *)"append", (PyCFunction)SwigPyObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, 1784 | {(char *)"next", (PyCFunction)SwigPyObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, 1785 | {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_VARARGS, (char *)"returns object representation"}, 1786 | {0, 0, 0, 0} 1787 | }; 1788 | #endif 1789 | 1790 | #if PY_VERSION_HEX < 0x02020000 1791 | SWIGINTERN PyObject * 1792 | SwigPyObject_getattr(SwigPyObject *sobj,char *name) 1793 | { 1794 | return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); 1795 | } 1796 | #endif 1797 | 1798 | SWIGRUNTIME PyTypeObject* 1799 | SwigPyObject_TypeOnce(void) { 1800 | static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; 1801 | 1802 | static PyNumberMethods SwigPyObject_as_number = { 1803 | (binaryfunc)0, /*nb_add*/ 1804 | (binaryfunc)0, /*nb_subtract*/ 1805 | (binaryfunc)0, /*nb_multiply*/ 1806 | /* nb_divide removed in Python 3 */ 1807 | #if PY_VERSION_HEX < 0x03000000 1808 | (binaryfunc)0, /*nb_divide*/ 1809 | #endif 1810 | (binaryfunc)0, /*nb_remainder*/ 1811 | (binaryfunc)0, /*nb_divmod*/ 1812 | (ternaryfunc)0,/*nb_power*/ 1813 | (unaryfunc)0, /*nb_negative*/ 1814 | (unaryfunc)0, /*nb_positive*/ 1815 | (unaryfunc)0, /*nb_absolute*/ 1816 | (inquiry)0, /*nb_nonzero*/ 1817 | 0, /*nb_invert*/ 1818 | 0, /*nb_lshift*/ 1819 | 0, /*nb_rshift*/ 1820 | 0, /*nb_and*/ 1821 | 0, /*nb_xor*/ 1822 | 0, /*nb_or*/ 1823 | #if PY_VERSION_HEX < 0x03000000 1824 | 0, /*nb_coerce*/ 1825 | #endif 1826 | (unaryfunc)SwigPyObject_long, /*nb_int*/ 1827 | #if PY_VERSION_HEX < 0x03000000 1828 | (unaryfunc)SwigPyObject_long, /*nb_long*/ 1829 | #else 1830 | 0, /*nb_reserved*/ 1831 | #endif 1832 | (unaryfunc)0, /*nb_float*/ 1833 | #if PY_VERSION_HEX < 0x03000000 1834 | (unaryfunc)SwigPyObject_oct, /*nb_oct*/ 1835 | (unaryfunc)SwigPyObject_hex, /*nb_hex*/ 1836 | #endif 1837 | #if PY_VERSION_HEX >= 0x03000000 /* 3.0 */ 1838 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ 1839 | #elif PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ 1840 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ 1841 | #elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ 1842 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ 1843 | #elif PY_VERSION_HEX >= 0x02000000 /* 2.0.0 */ 1844 | 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ 1845 | #endif 1846 | }; 1847 | 1848 | static PyTypeObject swigpyobject_type; 1849 | static int type_init = 0; 1850 | if (!type_init) { 1851 | const PyTypeObject tmp = { 1852 | /* PyObject header changed in Python 3 */ 1853 | #if PY_VERSION_HEX >= 0x03000000 1854 | PyVarObject_HEAD_INIT(NULL, 0) 1855 | #else 1856 | PyObject_HEAD_INIT(NULL) 1857 | 0, /* ob_size */ 1858 | #endif 1859 | (char *)"SwigPyObject", /* tp_name */ 1860 | sizeof(SwigPyObject), /* tp_basicsize */ 1861 | 0, /* tp_itemsize */ 1862 | (destructor)SwigPyObject_dealloc, /* tp_dealloc */ 1863 | 0, /* tp_print */ 1864 | #if PY_VERSION_HEX < 0x02020000 1865 | (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ 1866 | #else 1867 | (getattrfunc)0, /* tp_getattr */ 1868 | #endif 1869 | (setattrfunc)0, /* tp_setattr */ 1870 | #if PY_VERSION_HEX >= 0x03000000 1871 | 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ 1872 | #else 1873 | (cmpfunc)SwigPyObject_compare, /* tp_compare */ 1874 | #endif 1875 | (reprfunc)SwigPyObject_repr, /* tp_repr */ 1876 | &SwigPyObject_as_number, /* tp_as_number */ 1877 | 0, /* tp_as_sequence */ 1878 | 0, /* tp_as_mapping */ 1879 | (hashfunc)0, /* tp_hash */ 1880 | (ternaryfunc)0, /* tp_call */ 1881 | 0, /* tp_str */ 1882 | PyObject_GenericGetAttr, /* tp_getattro */ 1883 | 0, /* tp_setattro */ 1884 | 0, /* tp_as_buffer */ 1885 | Py_TPFLAGS_DEFAULT, /* tp_flags */ 1886 | swigobject_doc, /* tp_doc */ 1887 | 0, /* tp_traverse */ 1888 | 0, /* tp_clear */ 1889 | (richcmpfunc)SwigPyObject_richcompare,/* tp_richcompare */ 1890 | 0, /* tp_weaklistoffset */ 1891 | #if PY_VERSION_HEX >= 0x02020000 1892 | 0, /* tp_iter */ 1893 | 0, /* tp_iternext */ 1894 | swigobject_methods, /* tp_methods */ 1895 | 0, /* tp_members */ 1896 | 0, /* tp_getset */ 1897 | 0, /* tp_base */ 1898 | 0, /* tp_dict */ 1899 | 0, /* tp_descr_get */ 1900 | 0, /* tp_descr_set */ 1901 | 0, /* tp_dictoffset */ 1902 | 0, /* tp_init */ 1903 | 0, /* tp_alloc */ 1904 | 0, /* tp_new */ 1905 | 0, /* tp_free */ 1906 | 0, /* tp_is_gc */ 1907 | 0, /* tp_bases */ 1908 | 0, /* tp_mro */ 1909 | 0, /* tp_cache */ 1910 | 0, /* tp_subclasses */ 1911 | 0, /* tp_weaklist */ 1912 | #endif 1913 | #if PY_VERSION_HEX >= 0x02030000 1914 | 0, /* tp_del */ 1915 | #endif 1916 | #if PY_VERSION_HEX >= 0x02060000 1917 | 0, /* tp_version */ 1918 | #endif 1919 | #ifdef COUNT_ALLOCS 1920 | 0,0,0,0 /* tp_alloc -> tp_next */ 1921 | #endif 1922 | }; 1923 | swigpyobject_type = tmp; 1924 | type_init = 1; 1925 | #if PY_VERSION_HEX < 0x02020000 1926 | swigpyobject_type.ob_type = &PyType_Type; 1927 | #else 1928 | if (PyType_Ready(&swigpyobject_type) < 0) 1929 | return NULL; 1930 | #endif 1931 | } 1932 | return &swigpyobject_type; 1933 | } 1934 | 1935 | SWIGRUNTIME PyObject * 1936 | SwigPyObject_New(void *ptr, swig_type_info *ty, int own) 1937 | { 1938 | SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_type()); 1939 | if (sobj) { 1940 | sobj->ptr = ptr; 1941 | sobj->ty = ty; 1942 | sobj->own = own; 1943 | sobj->next = 0; 1944 | } 1945 | return (PyObject *)sobj; 1946 | } 1947 | 1948 | /* ----------------------------------------------------------------------------- 1949 | * Implements a simple Swig Packed type, and use it instead of string 1950 | * ----------------------------------------------------------------------------- */ 1951 | 1952 | typedef struct { 1953 | PyObject_HEAD 1954 | void *pack; 1955 | swig_type_info *ty; 1956 | size_t size; 1957 | } SwigPyPacked; 1958 | 1959 | SWIGRUNTIME int 1960 | SwigPyPacked_print(SwigPyPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) 1961 | { 1962 | char result[SWIG_BUFFER_SIZE]; 1963 | fputs("pack, v->size, 0, sizeof(result))) { 1965 | fputs("at ", fp); 1966 | fputs(result, fp); 1967 | } 1968 | fputs(v->ty->name,fp); 1969 | fputs(">", fp); 1970 | return 0; 1971 | } 1972 | 1973 | SWIGRUNTIME PyObject * 1974 | SwigPyPacked_repr(SwigPyPacked *v) 1975 | { 1976 | char result[SWIG_BUFFER_SIZE]; 1977 | if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { 1978 | return SWIG_Python_str_FromFormat("", result, v->ty->name); 1979 | } else { 1980 | return SWIG_Python_str_FromFormat("", v->ty->name); 1981 | } 1982 | } 1983 | 1984 | SWIGRUNTIME PyObject * 1985 | SwigPyPacked_str(SwigPyPacked *v) 1986 | { 1987 | char result[SWIG_BUFFER_SIZE]; 1988 | if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ 1989 | return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); 1990 | } else { 1991 | return SWIG_Python_str_FromChar(v->ty->name); 1992 | } 1993 | } 1994 | 1995 | SWIGRUNTIME int 1996 | SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w) 1997 | { 1998 | size_t i = v->size; 1999 | size_t j = w->size; 2000 | int s = (i < j) ? -1 : ((i > j) ? 1 : 0); 2001 | return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); 2002 | } 2003 | 2004 | SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void); 2005 | 2006 | SWIGRUNTIME PyTypeObject* 2007 | SwigPyPacked_type(void) { 2008 | static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce(); 2009 | return type; 2010 | } 2011 | 2012 | SWIGRUNTIMEINLINE int 2013 | SwigPyPacked_Check(PyObject *op) { 2014 | return ((op)->ob_type == SwigPyPacked_TypeOnce()) 2015 | || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0); 2016 | } 2017 | 2018 | SWIGRUNTIME void 2019 | SwigPyPacked_dealloc(PyObject *v) 2020 | { 2021 | if (SwigPyPacked_Check(v)) { 2022 | SwigPyPacked *sobj = (SwigPyPacked *) v; 2023 | free(sobj->pack); 2024 | } 2025 | PyObject_DEL(v); 2026 | } 2027 | 2028 | SWIGRUNTIME PyTypeObject* 2029 | SwigPyPacked_TypeOnce(void) { 2030 | static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; 2031 | static PyTypeObject swigpypacked_type; 2032 | static int type_init = 0; 2033 | if (!type_init) { 2034 | const PyTypeObject tmp = { 2035 | /* PyObject header changed in Python 3 */ 2036 | #if PY_VERSION_HEX>=0x03000000 2037 | PyVarObject_HEAD_INIT(NULL, 0) 2038 | #else 2039 | PyObject_HEAD_INIT(NULL) 2040 | 0, /* ob_size */ 2041 | #endif 2042 | (char *)"SwigPyPacked", /* tp_name */ 2043 | sizeof(SwigPyPacked), /* tp_basicsize */ 2044 | 0, /* tp_itemsize */ 2045 | (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ 2046 | (printfunc)SwigPyPacked_print, /* tp_print */ 2047 | (getattrfunc)0, /* tp_getattr */ 2048 | (setattrfunc)0, /* tp_setattr */ 2049 | #if PY_VERSION_HEX>=0x03000000 2050 | 0, /* tp_reserved in 3.0.1 */ 2051 | #else 2052 | (cmpfunc)SwigPyPacked_compare, /* tp_compare */ 2053 | #endif 2054 | (reprfunc)SwigPyPacked_repr, /* tp_repr */ 2055 | 0, /* tp_as_number */ 2056 | 0, /* tp_as_sequence */ 2057 | 0, /* tp_as_mapping */ 2058 | (hashfunc)0, /* tp_hash */ 2059 | (ternaryfunc)0, /* tp_call */ 2060 | (reprfunc)SwigPyPacked_str, /* tp_str */ 2061 | PyObject_GenericGetAttr, /* tp_getattro */ 2062 | 0, /* tp_setattro */ 2063 | 0, /* tp_as_buffer */ 2064 | Py_TPFLAGS_DEFAULT, /* tp_flags */ 2065 | swigpacked_doc, /* tp_doc */ 2066 | 0, /* tp_traverse */ 2067 | 0, /* tp_clear */ 2068 | 0, /* tp_richcompare */ 2069 | 0, /* tp_weaklistoffset */ 2070 | #if PY_VERSION_HEX >= 0x02020000 2071 | 0, /* tp_iter */ 2072 | 0, /* tp_iternext */ 2073 | 0, /* tp_methods */ 2074 | 0, /* tp_members */ 2075 | 0, /* tp_getset */ 2076 | 0, /* tp_base */ 2077 | 0, /* tp_dict */ 2078 | 0, /* tp_descr_get */ 2079 | 0, /* tp_descr_set */ 2080 | 0, /* tp_dictoffset */ 2081 | 0, /* tp_init */ 2082 | 0, /* tp_alloc */ 2083 | 0, /* tp_new */ 2084 | 0, /* tp_free */ 2085 | 0, /* tp_is_gc */ 2086 | 0, /* tp_bases */ 2087 | 0, /* tp_mro */ 2088 | 0, /* tp_cache */ 2089 | 0, /* tp_subclasses */ 2090 | 0, /* tp_weaklist */ 2091 | #endif 2092 | #if PY_VERSION_HEX >= 0x02030000 2093 | 0, /* tp_del */ 2094 | #endif 2095 | #if PY_VERSION_HEX >= 0x02060000 2096 | 0, /* tp_version */ 2097 | #endif 2098 | #ifdef COUNT_ALLOCS 2099 | 0,0,0,0 /* tp_alloc -> tp_next */ 2100 | #endif 2101 | }; 2102 | swigpypacked_type = tmp; 2103 | type_init = 1; 2104 | #if PY_VERSION_HEX < 0x02020000 2105 | swigpypacked_type.ob_type = &PyType_Type; 2106 | #else 2107 | if (PyType_Ready(&swigpypacked_type) < 0) 2108 | return NULL; 2109 | #endif 2110 | } 2111 | return &swigpypacked_type; 2112 | } 2113 | 2114 | SWIGRUNTIME PyObject * 2115 | SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) 2116 | { 2117 | SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_type()); 2118 | if (sobj) { 2119 | void *pack = malloc(size); 2120 | if (pack) { 2121 | memcpy(pack, ptr, size); 2122 | sobj->pack = pack; 2123 | sobj->ty = ty; 2124 | sobj->size = size; 2125 | } else { 2126 | PyObject_DEL((PyObject *) sobj); 2127 | sobj = 0; 2128 | } 2129 | } 2130 | return (PyObject *) sobj; 2131 | } 2132 | 2133 | SWIGRUNTIME swig_type_info * 2134 | SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) 2135 | { 2136 | if (SwigPyPacked_Check(obj)) { 2137 | SwigPyPacked *sobj = (SwigPyPacked *)obj; 2138 | if (sobj->size != size) return 0; 2139 | memcpy(ptr, sobj->pack, size); 2140 | return sobj->ty; 2141 | } else { 2142 | return 0; 2143 | } 2144 | } 2145 | 2146 | /* ----------------------------------------------------------------------------- 2147 | * pointers/data manipulation 2148 | * ----------------------------------------------------------------------------- */ 2149 | 2150 | SWIGRUNTIMEINLINE PyObject * 2151 | _SWIG_This(void) 2152 | { 2153 | return SWIG_Python_str_FromChar("this"); 2154 | } 2155 | 2156 | static PyObject *swig_this = NULL; 2157 | 2158 | SWIGRUNTIME PyObject * 2159 | SWIG_This(void) 2160 | { 2161 | if (swig_this == NULL) 2162 | swig_this = _SWIG_This(); 2163 | return swig_this; 2164 | } 2165 | 2166 | /* #define SWIG_PYTHON_SLOW_GETSET_THIS */ 2167 | 2168 | /* TODO: I don't know how to implement the fast getset in Python 3 right now */ 2169 | #if PY_VERSION_HEX>=0x03000000 2170 | #define SWIG_PYTHON_SLOW_GETSET_THIS 2171 | #endif 2172 | 2173 | SWIGRUNTIME SwigPyObject * 2174 | SWIG_Python_GetSwigThis(PyObject *pyobj) 2175 | { 2176 | PyObject *obj; 2177 | 2178 | if (SwigPyObject_Check(pyobj)) 2179 | return (SwigPyObject *) pyobj; 2180 | 2181 | #ifdef SWIGPYTHON_BUILTIN 2182 | (void)obj; 2183 | # ifdef PyWeakref_CheckProxy 2184 | if (PyWeakref_CheckProxy(pyobj)) { 2185 | pyobj = PyWeakref_GET_OBJECT(pyobj); 2186 | if (pyobj && SwigPyObject_Check(pyobj)) 2187 | return (SwigPyObject*) pyobj; 2188 | } 2189 | # endif 2190 | return NULL; 2191 | #else 2192 | 2193 | obj = 0; 2194 | 2195 | #if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) 2196 | if (PyInstance_Check(pyobj)) { 2197 | obj = _PyInstance_Lookup(pyobj, SWIG_This()); 2198 | } else { 2199 | PyObject **dictptr = _PyObject_GetDictPtr(pyobj); 2200 | if (dictptr != NULL) { 2201 | PyObject *dict = *dictptr; 2202 | obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; 2203 | } else { 2204 | #ifdef PyWeakref_CheckProxy 2205 | if (PyWeakref_CheckProxy(pyobj)) { 2206 | PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); 2207 | return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; 2208 | } 2209 | #endif 2210 | obj = PyObject_GetAttr(pyobj,SWIG_This()); 2211 | if (obj) { 2212 | Py_DECREF(obj); 2213 | } else { 2214 | if (PyErr_Occurred()) PyErr_Clear(); 2215 | return 0; 2216 | } 2217 | } 2218 | } 2219 | #else 2220 | obj = PyObject_GetAttr(pyobj,SWIG_This()); 2221 | if (obj) { 2222 | Py_DECREF(obj); 2223 | } else { 2224 | if (PyErr_Occurred()) PyErr_Clear(); 2225 | return 0; 2226 | } 2227 | #endif 2228 | if (obj && !SwigPyObject_Check(obj)) { 2229 | /* a PyObject is called 'this', try to get the 'real this' 2230 | SwigPyObject from it */ 2231 | return SWIG_Python_GetSwigThis(obj); 2232 | } 2233 | return (SwigPyObject *)obj; 2234 | #endif 2235 | } 2236 | 2237 | /* Acquire a pointer value */ 2238 | 2239 | SWIGRUNTIME int 2240 | SWIG_Python_AcquirePtr(PyObject *obj, int own) { 2241 | if (own == SWIG_POINTER_OWN) { 2242 | SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); 2243 | if (sobj) { 2244 | int oldown = sobj->own; 2245 | sobj->own = own; 2246 | return oldown; 2247 | } 2248 | } 2249 | return 0; 2250 | } 2251 | 2252 | /* Convert a pointer value */ 2253 | 2254 | SWIGRUNTIME int 2255 | SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { 2256 | int res; 2257 | SwigPyObject *sobj; 2258 | int implicit_conv = (flags & SWIG_POINTER_IMPLICIT_CONV) != 0; 2259 | 2260 | if (!obj) 2261 | return SWIG_ERROR; 2262 | if (obj == Py_None && !implicit_conv) { 2263 | if (ptr) 2264 | *ptr = 0; 2265 | return SWIG_OK; 2266 | } 2267 | 2268 | res = SWIG_ERROR; 2269 | 2270 | sobj = SWIG_Python_GetSwigThis(obj); 2271 | if (own) 2272 | *own = 0; 2273 | while (sobj) { 2274 | void *vptr = sobj->ptr; 2275 | if (ty) { 2276 | swig_type_info *to = sobj->ty; 2277 | if (to == ty) { 2278 | /* no type cast needed */ 2279 | if (ptr) *ptr = vptr; 2280 | break; 2281 | } else { 2282 | swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); 2283 | if (!tc) { 2284 | sobj = (SwigPyObject *)sobj->next; 2285 | } else { 2286 | if (ptr) { 2287 | int newmemory = 0; 2288 | *ptr = SWIG_TypeCast(tc,vptr,&newmemory); 2289 | if (newmemory == SWIG_CAST_NEW_MEMORY) { 2290 | assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ 2291 | if (own) 2292 | *own = *own | SWIG_CAST_NEW_MEMORY; 2293 | } 2294 | } 2295 | break; 2296 | } 2297 | } 2298 | } else { 2299 | if (ptr) *ptr = vptr; 2300 | break; 2301 | } 2302 | } 2303 | if (sobj) { 2304 | if (own) 2305 | *own = *own | sobj->own; 2306 | if (flags & SWIG_POINTER_DISOWN) { 2307 | sobj->own = 0; 2308 | } 2309 | res = SWIG_OK; 2310 | } else { 2311 | if (implicit_conv) { 2312 | SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; 2313 | if (data && !data->implicitconv) { 2314 | PyObject *klass = data->klass; 2315 | if (klass) { 2316 | PyObject *impconv; 2317 | data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ 2318 | impconv = SWIG_Python_CallFunctor(klass, obj); 2319 | data->implicitconv = 0; 2320 | if (PyErr_Occurred()) { 2321 | PyErr_Clear(); 2322 | impconv = 0; 2323 | } 2324 | if (impconv) { 2325 | SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); 2326 | if (iobj) { 2327 | void *vptr; 2328 | res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); 2329 | if (SWIG_IsOK(res)) { 2330 | if (ptr) { 2331 | *ptr = vptr; 2332 | /* transfer the ownership to 'ptr' */ 2333 | iobj->own = 0; 2334 | res = SWIG_AddCast(res); 2335 | res = SWIG_AddNewMask(res); 2336 | } else { 2337 | res = SWIG_AddCast(res); 2338 | } 2339 | } 2340 | } 2341 | Py_DECREF(impconv); 2342 | } 2343 | } 2344 | } 2345 | } 2346 | if (!SWIG_IsOK(res) && obj == Py_None) { 2347 | if (ptr) 2348 | *ptr = 0; 2349 | if (PyErr_Occurred()) 2350 | PyErr_Clear(); 2351 | res = SWIG_OK; 2352 | } 2353 | } 2354 | return res; 2355 | } 2356 | 2357 | /* Convert a function ptr value */ 2358 | 2359 | SWIGRUNTIME int 2360 | SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { 2361 | if (!PyCFunction_Check(obj)) { 2362 | return SWIG_ConvertPtr(obj, ptr, ty, 0); 2363 | } else { 2364 | void *vptr = 0; 2365 | 2366 | /* here we get the method pointer for callbacks */ 2367 | const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); 2368 | const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; 2369 | if (desc) 2370 | desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; 2371 | if (!desc) 2372 | return SWIG_ERROR; 2373 | if (ty) { 2374 | swig_cast_info *tc = SWIG_TypeCheck(desc,ty); 2375 | if (tc) { 2376 | int newmemory = 0; 2377 | *ptr = SWIG_TypeCast(tc,vptr,&newmemory); 2378 | assert(!newmemory); /* newmemory handling not yet implemented */ 2379 | } else { 2380 | return SWIG_ERROR; 2381 | } 2382 | } else { 2383 | *ptr = vptr; 2384 | } 2385 | return SWIG_OK; 2386 | } 2387 | } 2388 | 2389 | /* Convert a packed value value */ 2390 | 2391 | SWIGRUNTIME int 2392 | SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { 2393 | swig_type_info *to = SwigPyPacked_UnpackData(obj, ptr, sz); 2394 | if (!to) return SWIG_ERROR; 2395 | if (ty) { 2396 | if (to != ty) { 2397 | /* check type cast? */ 2398 | swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); 2399 | if (!tc) return SWIG_ERROR; 2400 | } 2401 | } 2402 | return SWIG_OK; 2403 | } 2404 | 2405 | /* ----------------------------------------------------------------------------- 2406 | * Create a new pointer object 2407 | * ----------------------------------------------------------------------------- */ 2408 | 2409 | /* 2410 | Create a new instance object, without calling __init__, and set the 2411 | 'this' attribute. 2412 | */ 2413 | 2414 | SWIGRUNTIME PyObject* 2415 | SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) 2416 | { 2417 | #if (PY_VERSION_HEX >= 0x02020000) 2418 | PyObject *inst = 0; 2419 | PyObject *newraw = data->newraw; 2420 | if (newraw) { 2421 | inst = PyObject_Call(newraw, data->newargs, NULL); 2422 | if (inst) { 2423 | #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) 2424 | PyObject **dictptr = _PyObject_GetDictPtr(inst); 2425 | if (dictptr != NULL) { 2426 | PyObject *dict = *dictptr; 2427 | if (dict == NULL) { 2428 | dict = PyDict_New(); 2429 | *dictptr = dict; 2430 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2431 | } 2432 | } 2433 | #else 2434 | PyObject *key = SWIG_This(); 2435 | PyObject_SetAttr(inst, key, swig_this); 2436 | #endif 2437 | } 2438 | } else { 2439 | #if PY_VERSION_HEX >= 0x03000000 2440 | inst = PyBaseObject_Type.tp_new((PyTypeObject*) data->newargs, Py_None, Py_None); 2441 | if (inst) { 2442 | PyObject_SetAttr(inst, SWIG_This(), swig_this); 2443 | Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; 2444 | } 2445 | #else 2446 | PyObject *dict = PyDict_New(); 2447 | if (dict) { 2448 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2449 | inst = PyInstance_NewRaw(data->newargs, dict); 2450 | Py_DECREF(dict); 2451 | } 2452 | #endif 2453 | } 2454 | return inst; 2455 | #else 2456 | #if (PY_VERSION_HEX >= 0x02010000) 2457 | PyObject *inst = 0; 2458 | PyObject *dict = PyDict_New(); 2459 | if (dict) { 2460 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2461 | inst = PyInstance_NewRaw(data->newargs, dict); 2462 | Py_DECREF(dict); 2463 | } 2464 | return (PyObject *) inst; 2465 | #else 2466 | PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); 2467 | if (inst == NULL) { 2468 | return NULL; 2469 | } 2470 | inst->in_class = (PyClassObject *)data->newargs; 2471 | Py_INCREF(inst->in_class); 2472 | inst->in_dict = PyDict_New(); 2473 | if (inst->in_dict == NULL) { 2474 | Py_DECREF(inst); 2475 | return NULL; 2476 | } 2477 | #ifdef Py_TPFLAGS_HAVE_WEAKREFS 2478 | inst->in_weakreflist = NULL; 2479 | #endif 2480 | #ifdef Py_TPFLAGS_GC 2481 | PyObject_GC_Init(inst); 2482 | #endif 2483 | PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); 2484 | return (PyObject *) inst; 2485 | #endif 2486 | #endif 2487 | } 2488 | 2489 | SWIGRUNTIME void 2490 | SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) 2491 | { 2492 | PyObject *dict; 2493 | #if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) 2494 | PyObject **dictptr = _PyObject_GetDictPtr(inst); 2495 | if (dictptr != NULL) { 2496 | dict = *dictptr; 2497 | if (dict == NULL) { 2498 | dict = PyDict_New(); 2499 | *dictptr = dict; 2500 | } 2501 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2502 | return; 2503 | } 2504 | #endif 2505 | dict = PyObject_GetAttrString(inst, (char*)"__dict__"); 2506 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2507 | Py_DECREF(dict); 2508 | } 2509 | 2510 | 2511 | SWIGINTERN PyObject * 2512 | SWIG_Python_InitShadowInstance(PyObject *args) { 2513 | PyObject *obj[2]; 2514 | if (!SWIG_Python_UnpackTuple(args, "swiginit", 2, 2, obj)) { 2515 | return NULL; 2516 | } else { 2517 | SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); 2518 | if (sthis) { 2519 | SwigPyObject_append((PyObject*) sthis, obj[1]); 2520 | } else { 2521 | SWIG_Python_SetSwigThis(obj[0], obj[1]); 2522 | } 2523 | return SWIG_Py_Void(); 2524 | } 2525 | } 2526 | 2527 | /* Create a new pointer object */ 2528 | 2529 | SWIGRUNTIME PyObject * 2530 | SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int flags) { 2531 | SwigPyClientData *clientdata; 2532 | PyObject * robj; 2533 | int own; 2534 | 2535 | if (!ptr) 2536 | return SWIG_Py_Void(); 2537 | 2538 | clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; 2539 | own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; 2540 | if (clientdata && clientdata->pytype) { 2541 | SwigPyObject *newobj; 2542 | if (flags & SWIG_BUILTIN_TP_INIT) { 2543 | newobj = (SwigPyObject*) self; 2544 | if (newobj->ptr) { 2545 | PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0); 2546 | while (newobj->next) 2547 | newobj = (SwigPyObject *) newobj->next; 2548 | newobj->next = next_self; 2549 | newobj = (SwigPyObject *)next_self; 2550 | } 2551 | } else { 2552 | newobj = PyObject_New(SwigPyObject, clientdata->pytype); 2553 | } 2554 | if (newobj) { 2555 | newobj->ptr = ptr; 2556 | newobj->ty = type; 2557 | newobj->own = own; 2558 | newobj->next = 0; 2559 | #ifdef SWIGPYTHON_BUILTIN 2560 | newobj->dict = 0; 2561 | #endif 2562 | return (PyObject*) newobj; 2563 | } 2564 | return SWIG_Py_Void(); 2565 | } 2566 | 2567 | assert(!(flags & SWIG_BUILTIN_TP_INIT)); 2568 | 2569 | robj = SwigPyObject_New(ptr, type, own); 2570 | if (robj && clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { 2571 | PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); 2572 | Py_DECREF(robj); 2573 | robj = inst; 2574 | } 2575 | return robj; 2576 | } 2577 | 2578 | /* Create a new packed object */ 2579 | 2580 | SWIGRUNTIMEINLINE PyObject * 2581 | SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { 2582 | return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); 2583 | } 2584 | 2585 | /* -----------------------------------------------------------------------------* 2586 | * Get type list 2587 | * -----------------------------------------------------------------------------*/ 2588 | 2589 | #ifdef SWIG_LINK_RUNTIME 2590 | void *SWIG_ReturnGlobalTypeList(void *); 2591 | #endif 2592 | 2593 | SWIGRUNTIME swig_module_info * 2594 | SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) { 2595 | static void *type_pointer = (void *)0; 2596 | /* first check if module already created */ 2597 | if (!type_pointer) { 2598 | #ifdef SWIG_LINK_RUNTIME 2599 | type_pointer = SWIG_ReturnGlobalTypeList((void *)0); 2600 | #else 2601 | # ifdef SWIGPY_USE_CAPSULE 2602 | type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0); 2603 | # else 2604 | type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, 2605 | (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); 2606 | # endif 2607 | if (PyErr_Occurred()) { 2608 | PyErr_Clear(); 2609 | type_pointer = (void *)0; 2610 | } 2611 | #endif 2612 | } 2613 | return (swig_module_info *) type_pointer; 2614 | } 2615 | 2616 | #if PY_MAJOR_VERSION < 2 2617 | /* PyModule_AddObject function was introduced in Python 2.0. The following function 2618 | is copied out of Python/modsupport.c in python version 2.3.4 */ 2619 | SWIGINTERN int 2620 | PyModule_AddObject(PyObject *m, char *name, PyObject *o) 2621 | { 2622 | PyObject *dict; 2623 | if (!PyModule_Check(m)) { 2624 | PyErr_SetString(PyExc_TypeError, 2625 | "PyModule_AddObject() needs module as first arg"); 2626 | return SWIG_ERROR; 2627 | } 2628 | if (!o) { 2629 | PyErr_SetString(PyExc_TypeError, 2630 | "PyModule_AddObject() needs non-NULL value"); 2631 | return SWIG_ERROR; 2632 | } 2633 | 2634 | dict = PyModule_GetDict(m); 2635 | if (dict == NULL) { 2636 | /* Internal error -- modules must have a dict! */ 2637 | PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", 2638 | PyModule_GetName(m)); 2639 | return SWIG_ERROR; 2640 | } 2641 | if (PyDict_SetItemString(dict, name, o)) 2642 | return SWIG_ERROR; 2643 | Py_DECREF(o); 2644 | return SWIG_OK; 2645 | } 2646 | #endif 2647 | 2648 | SWIGRUNTIME void 2649 | #ifdef SWIGPY_USE_CAPSULE 2650 | SWIG_Python_DestroyModule(PyObject *obj) 2651 | #else 2652 | SWIG_Python_DestroyModule(void *vptr) 2653 | #endif 2654 | { 2655 | #ifdef SWIGPY_USE_CAPSULE 2656 | swig_module_info *swig_module = (swig_module_info *) PyCapsule_GetPointer(obj, SWIGPY_CAPSULE_NAME); 2657 | #else 2658 | swig_module_info *swig_module = (swig_module_info *) vptr; 2659 | #endif 2660 | swig_type_info **types = swig_module->types; 2661 | size_t i; 2662 | for (i =0; i < swig_module->size; ++i) { 2663 | swig_type_info *ty = types[i]; 2664 | if (ty->owndata) { 2665 | SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; 2666 | if (data) SwigPyClientData_Del(data); 2667 | } 2668 | } 2669 | Py_DECREF(SWIG_This()); 2670 | swig_this = NULL; 2671 | } 2672 | 2673 | SWIGRUNTIME void 2674 | SWIG_Python_SetModule(swig_module_info *swig_module) { 2675 | #if PY_VERSION_HEX >= 0x03000000 2676 | /* Add a dummy module object into sys.modules */ 2677 | PyObject *module = PyImport_AddModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION); 2678 | #else 2679 | static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} }; /* Sentinel */ 2680 | PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table); 2681 | #endif 2682 | #ifdef SWIGPY_USE_CAPSULE 2683 | PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); 2684 | if (pointer && module) { 2685 | PyModule_AddObject(module, (char*)"type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer); 2686 | } else { 2687 | Py_XDECREF(pointer); 2688 | } 2689 | #else 2690 | PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); 2691 | if (pointer && module) { 2692 | PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); 2693 | } else { 2694 | Py_XDECREF(pointer); 2695 | } 2696 | #endif 2697 | } 2698 | 2699 | /* The python cached type query */ 2700 | SWIGRUNTIME PyObject * 2701 | SWIG_Python_TypeCache(void) { 2702 | static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); 2703 | return cache; 2704 | } 2705 | 2706 | SWIGRUNTIME swig_type_info * 2707 | SWIG_Python_TypeQuery(const char *type) 2708 | { 2709 | PyObject *cache = SWIG_Python_TypeCache(); 2710 | PyObject *key = SWIG_Python_str_FromChar(type); 2711 | PyObject *obj = PyDict_GetItem(cache, key); 2712 | swig_type_info *descriptor; 2713 | if (obj) { 2714 | #ifdef SWIGPY_USE_CAPSULE 2715 | descriptor = (swig_type_info *) PyCapsule_GetPointer(obj, NULL); 2716 | #else 2717 | descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); 2718 | #endif 2719 | } else { 2720 | swig_module_info *swig_module = SWIG_GetModule(0); 2721 | descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); 2722 | if (descriptor) { 2723 | #ifdef SWIGPY_USE_CAPSULE 2724 | obj = PyCapsule_New((void*) descriptor, NULL, NULL); 2725 | #else 2726 | obj = PyCObject_FromVoidPtr(descriptor, NULL); 2727 | #endif 2728 | PyDict_SetItem(cache, key, obj); 2729 | Py_DECREF(obj); 2730 | } 2731 | } 2732 | Py_DECREF(key); 2733 | return descriptor; 2734 | } 2735 | 2736 | /* 2737 | For backward compatibility only 2738 | */ 2739 | #define SWIG_POINTER_EXCEPTION 0 2740 | #define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) 2741 | #define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) 2742 | 2743 | SWIGRUNTIME int 2744 | SWIG_Python_AddErrMesg(const char* mesg, int infront) 2745 | { 2746 | if (PyErr_Occurred()) { 2747 | PyObject *type = 0; 2748 | PyObject *value = 0; 2749 | PyObject *traceback = 0; 2750 | PyErr_Fetch(&type, &value, &traceback); 2751 | if (value) { 2752 | char *tmp; 2753 | PyObject *old_str = PyObject_Str(value); 2754 | Py_XINCREF(type); 2755 | PyErr_Clear(); 2756 | if (infront) { 2757 | PyErr_Format(type, "%s %s", mesg, tmp = SWIG_Python_str_AsChar(old_str)); 2758 | } else { 2759 | PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); 2760 | } 2761 | SWIG_Python_str_DelForPy3(tmp); 2762 | Py_DECREF(old_str); 2763 | } 2764 | return 1; 2765 | } else { 2766 | return 0; 2767 | } 2768 | } 2769 | 2770 | SWIGRUNTIME int 2771 | SWIG_Python_ArgFail(int argnum) 2772 | { 2773 | if (PyErr_Occurred()) { 2774 | /* add information about failing argument */ 2775 | char mesg[256]; 2776 | PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); 2777 | return SWIG_Python_AddErrMesg(mesg, 1); 2778 | } else { 2779 | return 0; 2780 | } 2781 | } 2782 | 2783 | SWIGRUNTIMEINLINE const char * 2784 | SwigPyObject_GetDesc(PyObject *self) 2785 | { 2786 | SwigPyObject *v = (SwigPyObject *)self; 2787 | swig_type_info *ty = v ? v->ty : 0; 2788 | return ty ? ty->str : ""; 2789 | } 2790 | 2791 | SWIGRUNTIME void 2792 | SWIG_Python_TypeError(const char *type, PyObject *obj) 2793 | { 2794 | if (type) { 2795 | #if defined(SWIG_COBJECT_TYPES) 2796 | if (obj && SwigPyObject_Check(obj)) { 2797 | const char *otype = (const char *) SwigPyObject_GetDesc(obj); 2798 | if (otype) { 2799 | PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%s)' is received", 2800 | type, otype); 2801 | return; 2802 | } 2803 | } else 2804 | #endif 2805 | { 2806 | const char *otype = (obj ? obj->ob_type->tp_name : 0); 2807 | if (otype) { 2808 | PyObject *str = PyObject_Str(obj); 2809 | const char *cstr = str ? SWIG_Python_str_AsChar(str) : 0; 2810 | if (cstr) { 2811 | PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", 2812 | type, otype, cstr); 2813 | SWIG_Python_str_DelForPy3(cstr); 2814 | } else { 2815 | PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", 2816 | type, otype); 2817 | } 2818 | Py_XDECREF(str); 2819 | return; 2820 | } 2821 | } 2822 | PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); 2823 | } else { 2824 | PyErr_Format(PyExc_TypeError, "unexpected type is received"); 2825 | } 2826 | } 2827 | 2828 | 2829 | /* Convert a pointer value, signal an exception on a type mismatch */ 2830 | SWIGRUNTIME void * 2831 | SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int SWIGUNUSEDPARM(argnum), int flags) { 2832 | void *result; 2833 | if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { 2834 | PyErr_Clear(); 2835 | #if SWIG_POINTER_EXCEPTION 2836 | if (flags) { 2837 | SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); 2838 | SWIG_Python_ArgFail(argnum); 2839 | } 2840 | #endif 2841 | } 2842 | return result; 2843 | } 2844 | 2845 | #ifdef SWIGPYTHON_BUILTIN 2846 | SWIGRUNTIME int 2847 | SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { 2848 | PyTypeObject *tp = obj->ob_type; 2849 | PyObject *descr; 2850 | PyObject *encoded_name; 2851 | descrsetfunc f; 2852 | int res = -1; 2853 | 2854 | # ifdef Py_USING_UNICODE 2855 | if (PyString_Check(name)) { 2856 | name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); 2857 | if (!name) 2858 | return -1; 2859 | } else if (!PyUnicode_Check(name)) 2860 | # else 2861 | if (!PyString_Check(name)) 2862 | # endif 2863 | { 2864 | PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name); 2865 | return -1; 2866 | } else { 2867 | Py_INCREF(name); 2868 | } 2869 | 2870 | if (!tp->tp_dict) { 2871 | if (PyType_Ready(tp) < 0) 2872 | goto done; 2873 | } 2874 | 2875 | descr = _PyType_Lookup(tp, name); 2876 | f = NULL; 2877 | if (descr != NULL) 2878 | f = descr->ob_type->tp_descr_set; 2879 | if (!f) { 2880 | if (PyString_Check(name)) { 2881 | encoded_name = name; 2882 | Py_INCREF(name); 2883 | } else { 2884 | encoded_name = PyUnicode_AsUTF8String(name); 2885 | } 2886 | PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name)); 2887 | Py_DECREF(encoded_name); 2888 | } else { 2889 | res = f(descr, obj, value); 2890 | } 2891 | 2892 | done: 2893 | Py_DECREF(name); 2894 | return res; 2895 | } 2896 | #endif 2897 | 2898 | 2899 | #ifdef __cplusplus 2900 | } 2901 | #endif 2902 | 2903 | 2904 | 2905 | #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) 2906 | 2907 | #define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else 2908 | 2909 | 2910 | 2911 | /* -------- TYPES TABLE (BEGIN) -------- */ 2912 | 2913 | #define SWIGTYPE_p_char swig_types[0] 2914 | static swig_type_info *swig_types[2]; 2915 | static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0}; 2916 | #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) 2917 | #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) 2918 | 2919 | /* -------- TYPES TABLE (END) -------- */ 2920 | 2921 | #if (PY_VERSION_HEX <= 0x02000000) 2922 | # if !defined(SWIG_PYTHON_CLASSIC) 2923 | # error "This python version requires swig to be run with the '-classic' option" 2924 | # endif 2925 | #endif 2926 | 2927 | /*----------------------------------------------- 2928 | @(target):= _weights_quantization.so 2929 | ------------------------------------------------*/ 2930 | #if PY_VERSION_HEX >= 0x03000000 2931 | # define SWIG_init PyInit__weights_quantization 2932 | 2933 | #else 2934 | # define SWIG_init init_weights_quantization 2935 | 2936 | #endif 2937 | #define SWIG_name "_weights_quantization" 2938 | 2939 | #define SWIGVERSION 0x020012 2940 | #define SWIG_VERSION SWIGVERSION 2941 | 2942 | 2943 | #define SWIG_as_voidptr(a) (void *)((const void *)(a)) 2944 | #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a)) 2945 | 2946 | 2947 | #include 2948 | #include "numpy/arrayobject.h" 2949 | void compress_layer_weights(PyObject *pComprsLabel, PyObject *pCodeBook, PyObject *pWeights, int nWeight, int nBit); 2950 | void decompress_layer_weights(PyObject *pWeights, PyObject *pComprsLabel, PyObject *pCodeBook, int nWeight, int nBit); 2951 | void quantize_layer_weights(PyObject *pWeights, int nWeight, int nBit); 2952 | 2953 | 2954 | #include 2955 | #if !defined(SWIG_NO_LLONG_MAX) 2956 | # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) 2957 | # define LLONG_MAX __LONG_LONG_MAX__ 2958 | # define LLONG_MIN (-LLONG_MAX - 1LL) 2959 | # define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) 2960 | # endif 2961 | #endif 2962 | 2963 | 2964 | SWIGINTERN int 2965 | SWIG_AsVal_double (PyObject *obj, double *val) 2966 | { 2967 | int res = SWIG_TypeError; 2968 | if (PyFloat_Check(obj)) { 2969 | if (val) *val = PyFloat_AsDouble(obj); 2970 | return SWIG_OK; 2971 | } else if (PyInt_Check(obj)) { 2972 | if (val) *val = PyInt_AsLong(obj); 2973 | return SWIG_OK; 2974 | } else if (PyLong_Check(obj)) { 2975 | double v = PyLong_AsDouble(obj); 2976 | if (!PyErr_Occurred()) { 2977 | if (val) *val = v; 2978 | return SWIG_OK; 2979 | } else { 2980 | PyErr_Clear(); 2981 | } 2982 | } 2983 | #ifdef SWIG_PYTHON_CAST_MODE 2984 | { 2985 | int dispatch = 0; 2986 | double d = PyFloat_AsDouble(obj); 2987 | if (!PyErr_Occurred()) { 2988 | if (val) *val = d; 2989 | return SWIG_AddCast(SWIG_OK); 2990 | } else { 2991 | PyErr_Clear(); 2992 | } 2993 | if (!dispatch) { 2994 | long v = PyLong_AsLong(obj); 2995 | if (!PyErr_Occurred()) { 2996 | if (val) *val = v; 2997 | return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); 2998 | } else { 2999 | PyErr_Clear(); 3000 | } 3001 | } 3002 | } 3003 | #endif 3004 | return res; 3005 | } 3006 | 3007 | 3008 | #include 3009 | 3010 | 3011 | #include 3012 | 3013 | 3014 | SWIGINTERNINLINE int 3015 | SWIG_CanCastAsInteger(double *d, double min, double max) { 3016 | double x = *d; 3017 | if ((min <= x && x <= max)) { 3018 | double fx = floor(x); 3019 | double cx = ceil(x); 3020 | double rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ 3021 | if ((errno == EDOM) || (errno == ERANGE)) { 3022 | errno = 0; 3023 | } else { 3024 | double summ, reps, diff; 3025 | if (rd < x) { 3026 | diff = x - rd; 3027 | } else if (rd > x) { 3028 | diff = rd - x; 3029 | } else { 3030 | return 1; 3031 | } 3032 | summ = rd + x; 3033 | reps = diff/summ; 3034 | if (reps < 8*DBL_EPSILON) { 3035 | *d = rd; 3036 | return 1; 3037 | } 3038 | } 3039 | } 3040 | return 0; 3041 | } 3042 | 3043 | 3044 | SWIGINTERN int 3045 | SWIG_AsVal_long (PyObject *obj, long* val) 3046 | { 3047 | if (PyInt_Check(obj)) { 3048 | if (val) *val = PyInt_AsLong(obj); 3049 | return SWIG_OK; 3050 | } else if (PyLong_Check(obj)) { 3051 | long v = PyLong_AsLong(obj); 3052 | if (!PyErr_Occurred()) { 3053 | if (val) *val = v; 3054 | return SWIG_OK; 3055 | } else { 3056 | PyErr_Clear(); 3057 | } 3058 | } 3059 | #ifdef SWIG_PYTHON_CAST_MODE 3060 | { 3061 | int dispatch = 0; 3062 | long v = PyInt_AsLong(obj); 3063 | if (!PyErr_Occurred()) { 3064 | if (val) *val = v; 3065 | return SWIG_AddCast(SWIG_OK); 3066 | } else { 3067 | PyErr_Clear(); 3068 | } 3069 | if (!dispatch) { 3070 | double d; 3071 | int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); 3072 | if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { 3073 | if (val) *val = (long)(d); 3074 | return res; 3075 | } 3076 | } 3077 | } 3078 | #endif 3079 | return SWIG_TypeError; 3080 | } 3081 | 3082 | 3083 | SWIGINTERN int 3084 | SWIG_AsVal_int (PyObject * obj, int *val) 3085 | { 3086 | long v; 3087 | int res = SWIG_AsVal_long (obj, &v); 3088 | if (SWIG_IsOK(res)) { 3089 | if ((v < INT_MIN || v > INT_MAX)) { 3090 | return SWIG_OverflowError; 3091 | } else { 3092 | if (val) *val = (int)(v); 3093 | } 3094 | } 3095 | return res; 3096 | } 3097 | 3098 | #ifdef __cplusplus 3099 | extern "C" { 3100 | #endif 3101 | SWIGINTERN PyObject *_wrap_compress_layer_weights(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { 3102 | PyObject *resultobj = 0; 3103 | PyObject *arg1 = (PyObject *) 0 ; 3104 | PyObject *arg2 = (PyObject *) 0 ; 3105 | PyObject *arg3 = (PyObject *) 0 ; 3106 | int arg4 ; 3107 | int arg5 ; 3108 | int val4 ; 3109 | int ecode4 = 0 ; 3110 | int val5 ; 3111 | int ecode5 = 0 ; 3112 | PyObject * obj0 = 0 ; 3113 | PyObject * obj1 = 0 ; 3114 | PyObject * obj2 = 0 ; 3115 | PyObject * obj3 = 0 ; 3116 | PyObject * obj4 = 0 ; 3117 | 3118 | if (!PyArg_ParseTuple(args,(char *)"OOOOO:compress_layer_weights",&obj0,&obj1,&obj2,&obj3,&obj4)) SWIG_fail; 3119 | arg1 = obj0; 3120 | arg2 = obj1; 3121 | arg3 = obj2; 3122 | ecode4 = SWIG_AsVal_int(obj3, &val4); 3123 | if (!SWIG_IsOK(ecode4)) { 3124 | SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "compress_layer_weights" "', argument " "4"" of type '" "int""'"); 3125 | } 3126 | arg4 = (int)(val4); 3127 | ecode5 = SWIG_AsVal_int(obj4, &val5); 3128 | if (!SWIG_IsOK(ecode5)) { 3129 | SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "compress_layer_weights" "', argument " "5"" of type '" "int""'"); 3130 | } 3131 | arg5 = (int)(val5); 3132 | compress_layer_weights(arg1,arg2,arg3,arg4,arg5); 3133 | resultobj = SWIG_Py_Void(); 3134 | return resultobj; 3135 | fail: 3136 | return NULL; 3137 | } 3138 | 3139 | 3140 | SWIGINTERN PyObject *_wrap_decompress_layer_weights(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { 3141 | PyObject *resultobj = 0; 3142 | PyObject *arg1 = (PyObject *) 0 ; 3143 | PyObject *arg2 = (PyObject *) 0 ; 3144 | PyObject *arg3 = (PyObject *) 0 ; 3145 | int arg4 ; 3146 | int arg5 ; 3147 | int val4 ; 3148 | int ecode4 = 0 ; 3149 | int val5 ; 3150 | int ecode5 = 0 ; 3151 | PyObject * obj0 = 0 ; 3152 | PyObject * obj1 = 0 ; 3153 | PyObject * obj2 = 0 ; 3154 | PyObject * obj3 = 0 ; 3155 | PyObject * obj4 = 0 ; 3156 | 3157 | if (!PyArg_ParseTuple(args,(char *)"OOOOO:decompress_layer_weights",&obj0,&obj1,&obj2,&obj3,&obj4)) SWIG_fail; 3158 | arg1 = obj0; 3159 | arg2 = obj1; 3160 | arg3 = obj2; 3161 | ecode4 = SWIG_AsVal_int(obj3, &val4); 3162 | if (!SWIG_IsOK(ecode4)) { 3163 | SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "decompress_layer_weights" "', argument " "4"" of type '" "int""'"); 3164 | } 3165 | arg4 = (int)(val4); 3166 | ecode5 = SWIG_AsVal_int(obj4, &val5); 3167 | if (!SWIG_IsOK(ecode5)) { 3168 | SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "decompress_layer_weights" "', argument " "5"" of type '" "int""'"); 3169 | } 3170 | arg5 = (int)(val5); 3171 | decompress_layer_weights(arg1,arg2,arg3,arg4,arg5); 3172 | resultobj = SWIG_Py_Void(); 3173 | return resultobj; 3174 | fail: 3175 | return NULL; 3176 | } 3177 | 3178 | 3179 | SWIGINTERN PyObject *_wrap_quantize_layer_weights(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { 3180 | PyObject *resultobj = 0; 3181 | PyObject *arg1 = (PyObject *) 0 ; 3182 | int arg2 ; 3183 | int arg3 ; 3184 | int val2 ; 3185 | int ecode2 = 0 ; 3186 | int val3 ; 3187 | int ecode3 = 0 ; 3188 | PyObject * obj0 = 0 ; 3189 | PyObject * obj1 = 0 ; 3190 | PyObject * obj2 = 0 ; 3191 | 3192 | if (!PyArg_ParseTuple(args,(char *)"OOO:quantize_layer_weights",&obj0,&obj1,&obj2)) SWIG_fail; 3193 | arg1 = obj0; 3194 | ecode2 = SWIG_AsVal_int(obj1, &val2); 3195 | if (!SWIG_IsOK(ecode2)) { 3196 | SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "quantize_layer_weights" "', argument " "2"" of type '" "int""'"); 3197 | } 3198 | arg2 = (int)(val2); 3199 | ecode3 = SWIG_AsVal_int(obj2, &val3); 3200 | if (!SWIG_IsOK(ecode3)) { 3201 | SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "quantize_layer_weights" "', argument " "3"" of type '" "int""'"); 3202 | } 3203 | arg3 = (int)(val3); 3204 | quantize_layer_weights(arg1,arg2,arg3); 3205 | resultobj = SWIG_Py_Void(); 3206 | return resultobj; 3207 | fail: 3208 | return NULL; 3209 | } 3210 | 3211 | 3212 | static PyMethodDef SwigMethods[] = { 3213 | { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, 3214 | { (char *)"compress_layer_weights", _wrap_compress_layer_weights, METH_VARARGS, NULL}, 3215 | { (char *)"decompress_layer_weights", _wrap_decompress_layer_weights, METH_VARARGS, NULL}, 3216 | { (char *)"quantize_layer_weights", _wrap_quantize_layer_weights, METH_VARARGS, NULL}, 3217 | { NULL, NULL, 0, NULL } 3218 | }; 3219 | 3220 | 3221 | /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ 3222 | 3223 | static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; 3224 | 3225 | static swig_type_info *swig_type_initial[] = { 3226 | &_swigt__p_char, 3227 | }; 3228 | 3229 | static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; 3230 | 3231 | static swig_cast_info *swig_cast_initial[] = { 3232 | _swigc__p_char, 3233 | }; 3234 | 3235 | 3236 | /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ 3237 | 3238 | static swig_const_info swig_const_table[] = { 3239 | {0, 0, 0, 0.0, 0, 0}}; 3240 | 3241 | #ifdef __cplusplus 3242 | } 3243 | #endif 3244 | /* ----------------------------------------------------------------------------- 3245 | * Type initialization: 3246 | * This problem is tough by the requirement that no dynamic 3247 | * memory is used. Also, since swig_type_info structures store pointers to 3248 | * swig_cast_info structures and swig_cast_info structures store pointers back 3249 | * to swig_type_info structures, we need some lookup code at initialization. 3250 | * The idea is that swig generates all the structures that are needed. 3251 | * The runtime then collects these partially filled structures. 3252 | * The SWIG_InitializeModule function takes these initial arrays out of 3253 | * swig_module, and does all the lookup, filling in the swig_module.types 3254 | * array with the correct data and linking the correct swig_cast_info 3255 | * structures together. 3256 | * 3257 | * The generated swig_type_info structures are assigned staticly to an initial 3258 | * array. We just loop through that array, and handle each type individually. 3259 | * First we lookup if this type has been already loaded, and if so, use the 3260 | * loaded structure instead of the generated one. Then we have to fill in the 3261 | * cast linked list. The cast data is initially stored in something like a 3262 | * two-dimensional array. Each row corresponds to a type (there are the same 3263 | * number of rows as there are in the swig_type_initial array). Each entry in 3264 | * a column is one of the swig_cast_info structures for that type. 3265 | * The cast_initial array is actually an array of arrays, because each row has 3266 | * a variable number of columns. So to actually build the cast linked list, 3267 | * we find the array of casts associated with the type, and loop through it 3268 | * adding the casts to the list. The one last trick we need to do is making 3269 | * sure the type pointer in the swig_cast_info struct is correct. 3270 | * 3271 | * First off, we lookup the cast->type name to see if it is already loaded. 3272 | * There are three cases to handle: 3273 | * 1) If the cast->type has already been loaded AND the type we are adding 3274 | * casting info to has not been loaded (it is in this module), THEN we 3275 | * replace the cast->type pointer with the type pointer that has already 3276 | * been loaded. 3277 | * 2) If BOTH types (the one we are adding casting info to, and the 3278 | * cast->type) are loaded, THEN the cast info has already been loaded by 3279 | * the previous module so we just ignore it. 3280 | * 3) Finally, if cast->type has not already been loaded, then we add that 3281 | * swig_cast_info to the linked list (because the cast->type) pointer will 3282 | * be correct. 3283 | * ----------------------------------------------------------------------------- */ 3284 | 3285 | #ifdef __cplusplus 3286 | extern "C" { 3287 | #if 0 3288 | } /* c-mode */ 3289 | #endif 3290 | #endif 3291 | 3292 | #if 0 3293 | #define SWIGRUNTIME_DEBUG 3294 | #endif 3295 | 3296 | 3297 | SWIGRUNTIME void 3298 | SWIG_InitializeModule(void *clientdata) { 3299 | size_t i; 3300 | swig_module_info *module_head, *iter; 3301 | int found, init; 3302 | 3303 | /* check to see if the circular list has been setup, if not, set it up */ 3304 | if (swig_module.next==0) { 3305 | /* Initialize the swig_module */ 3306 | swig_module.type_initial = swig_type_initial; 3307 | swig_module.cast_initial = swig_cast_initial; 3308 | swig_module.next = &swig_module; 3309 | init = 1; 3310 | } else { 3311 | init = 0; 3312 | } 3313 | 3314 | /* Try and load any already created modules */ 3315 | module_head = SWIG_GetModule(clientdata); 3316 | if (!module_head) { 3317 | /* This is the first module loaded for this interpreter */ 3318 | /* so set the swig module into the interpreter */ 3319 | SWIG_SetModule(clientdata, &swig_module); 3320 | module_head = &swig_module; 3321 | } else { 3322 | /* the interpreter has loaded a SWIG module, but has it loaded this one? */ 3323 | found=0; 3324 | iter=module_head; 3325 | do { 3326 | if (iter==&swig_module) { 3327 | found=1; 3328 | break; 3329 | } 3330 | iter=iter->next; 3331 | } while (iter!= module_head); 3332 | 3333 | /* if the is found in the list, then all is done and we may leave */ 3334 | if (found) return; 3335 | /* otherwise we must add out module into the list */ 3336 | swig_module.next = module_head->next; 3337 | module_head->next = &swig_module; 3338 | } 3339 | 3340 | /* When multiple interpreters are used, a module could have already been initialized in 3341 | a different interpreter, but not yet have a pointer in this interpreter. 3342 | In this case, we do not want to continue adding types... everything should be 3343 | set up already */ 3344 | if (init == 0) return; 3345 | 3346 | /* Now work on filling in swig_module.types */ 3347 | #ifdef SWIGRUNTIME_DEBUG 3348 | printf("SWIG_InitializeModule: size %d\n", swig_module.size); 3349 | #endif 3350 | for (i = 0; i < swig_module.size; ++i) { 3351 | swig_type_info *type = 0; 3352 | swig_type_info *ret; 3353 | swig_cast_info *cast; 3354 | 3355 | #ifdef SWIGRUNTIME_DEBUG 3356 | printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); 3357 | #endif 3358 | 3359 | /* if there is another module already loaded */ 3360 | if (swig_module.next != &swig_module) { 3361 | type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); 3362 | } 3363 | if (type) { 3364 | /* Overwrite clientdata field */ 3365 | #ifdef SWIGRUNTIME_DEBUG 3366 | printf("SWIG_InitializeModule: found type %s\n", type->name); 3367 | #endif 3368 | if (swig_module.type_initial[i]->clientdata) { 3369 | type->clientdata = swig_module.type_initial[i]->clientdata; 3370 | #ifdef SWIGRUNTIME_DEBUG 3371 | printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); 3372 | #endif 3373 | } 3374 | } else { 3375 | type = swig_module.type_initial[i]; 3376 | } 3377 | 3378 | /* Insert casting types */ 3379 | cast = swig_module.cast_initial[i]; 3380 | while (cast->type) { 3381 | /* Don't need to add information already in the list */ 3382 | ret = 0; 3383 | #ifdef SWIGRUNTIME_DEBUG 3384 | printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); 3385 | #endif 3386 | if (swig_module.next != &swig_module) { 3387 | ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); 3388 | #ifdef SWIGRUNTIME_DEBUG 3389 | if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); 3390 | #endif 3391 | } 3392 | if (ret) { 3393 | if (type == swig_module.type_initial[i]) { 3394 | #ifdef SWIGRUNTIME_DEBUG 3395 | printf("SWIG_InitializeModule: skip old type %s\n", ret->name); 3396 | #endif 3397 | cast->type = ret; 3398 | ret = 0; 3399 | } else { 3400 | /* Check for casting already in the list */ 3401 | swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); 3402 | #ifdef SWIGRUNTIME_DEBUG 3403 | if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); 3404 | #endif 3405 | if (!ocast) ret = 0; 3406 | } 3407 | } 3408 | 3409 | if (!ret) { 3410 | #ifdef SWIGRUNTIME_DEBUG 3411 | printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); 3412 | #endif 3413 | if (type->cast) { 3414 | type->cast->prev = cast; 3415 | cast->next = type->cast; 3416 | } 3417 | type->cast = cast; 3418 | } 3419 | cast++; 3420 | } 3421 | /* Set entry in modules->types array equal to the type */ 3422 | swig_module.types[i] = type; 3423 | } 3424 | swig_module.types[i] = 0; 3425 | 3426 | #ifdef SWIGRUNTIME_DEBUG 3427 | printf("**** SWIG_InitializeModule: Cast List ******\n"); 3428 | for (i = 0; i < swig_module.size; ++i) { 3429 | int j = 0; 3430 | swig_cast_info *cast = swig_module.cast_initial[i]; 3431 | printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); 3432 | while (cast->type) { 3433 | printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); 3434 | cast++; 3435 | ++j; 3436 | } 3437 | printf("---- Total casts: %d\n",j); 3438 | } 3439 | printf("**** SWIG_InitializeModule: Cast List ******\n"); 3440 | #endif 3441 | } 3442 | 3443 | /* This function will propagate the clientdata field of type to 3444 | * any new swig_type_info structures that have been added into the list 3445 | * of equivalent types. It is like calling 3446 | * SWIG_TypeClientData(type, clientdata) a second time. 3447 | */ 3448 | SWIGRUNTIME void 3449 | SWIG_PropagateClientData(void) { 3450 | size_t i; 3451 | swig_cast_info *equiv; 3452 | static int init_run = 0; 3453 | 3454 | if (init_run) return; 3455 | init_run = 1; 3456 | 3457 | for (i = 0; i < swig_module.size; i++) { 3458 | if (swig_module.types[i]->clientdata) { 3459 | equiv = swig_module.types[i]->cast; 3460 | while (equiv) { 3461 | if (!equiv->converter) { 3462 | if (equiv->type && !equiv->type->clientdata) 3463 | SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); 3464 | } 3465 | equiv = equiv->next; 3466 | } 3467 | } 3468 | } 3469 | } 3470 | 3471 | #ifdef __cplusplus 3472 | #if 0 3473 | { 3474 | /* c-mode */ 3475 | #endif 3476 | } 3477 | #endif 3478 | 3479 | 3480 | 3481 | #ifdef __cplusplus 3482 | extern "C" { 3483 | #endif 3484 | 3485 | /* Python-specific SWIG API */ 3486 | #define SWIG_newvarlink() SWIG_Python_newvarlink() 3487 | #define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) 3488 | #define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) 3489 | 3490 | /* ----------------------------------------------------------------------------- 3491 | * global variable support code. 3492 | * ----------------------------------------------------------------------------- */ 3493 | 3494 | typedef struct swig_globalvar { 3495 | char *name; /* Name of global variable */ 3496 | PyObject *(*get_attr)(void); /* Return the current value */ 3497 | int (*set_attr)(PyObject *); /* Set the value */ 3498 | struct swig_globalvar *next; 3499 | } swig_globalvar; 3500 | 3501 | typedef struct swig_varlinkobject { 3502 | PyObject_HEAD 3503 | swig_globalvar *vars; 3504 | } swig_varlinkobject; 3505 | 3506 | SWIGINTERN PyObject * 3507 | swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { 3508 | #if PY_VERSION_HEX >= 0x03000000 3509 | return PyUnicode_InternFromString(""); 3510 | #else 3511 | return PyString_FromString(""); 3512 | #endif 3513 | } 3514 | 3515 | SWIGINTERN PyObject * 3516 | swig_varlink_str(swig_varlinkobject *v) { 3517 | #if PY_VERSION_HEX >= 0x03000000 3518 | PyObject *str = PyUnicode_InternFromString("("); 3519 | PyObject *tail; 3520 | PyObject *joined; 3521 | swig_globalvar *var; 3522 | for (var = v->vars; var; var=var->next) { 3523 | tail = PyUnicode_FromString(var->name); 3524 | joined = PyUnicode_Concat(str, tail); 3525 | Py_DecRef(str); 3526 | Py_DecRef(tail); 3527 | str = joined; 3528 | if (var->next) { 3529 | tail = PyUnicode_InternFromString(", "); 3530 | joined = PyUnicode_Concat(str, tail); 3531 | Py_DecRef(str); 3532 | Py_DecRef(tail); 3533 | str = joined; 3534 | } 3535 | } 3536 | tail = PyUnicode_InternFromString(")"); 3537 | joined = PyUnicode_Concat(str, tail); 3538 | Py_DecRef(str); 3539 | Py_DecRef(tail); 3540 | str = joined; 3541 | #else 3542 | PyObject *str = PyString_FromString("("); 3543 | swig_globalvar *var; 3544 | for (var = v->vars; var; var=var->next) { 3545 | PyString_ConcatAndDel(&str,PyString_FromString(var->name)); 3546 | if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); 3547 | } 3548 | PyString_ConcatAndDel(&str,PyString_FromString(")")); 3549 | #endif 3550 | return str; 3551 | } 3552 | 3553 | SWIGINTERN int 3554 | swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { 3555 | char *tmp; 3556 | PyObject *str = swig_varlink_str(v); 3557 | fprintf(fp,"Swig global variables "); 3558 | fprintf(fp,"%s\n", tmp = SWIG_Python_str_AsChar(str)); 3559 | SWIG_Python_str_DelForPy3(tmp); 3560 | Py_DECREF(str); 3561 | return 0; 3562 | } 3563 | 3564 | SWIGINTERN void 3565 | swig_varlink_dealloc(swig_varlinkobject *v) { 3566 | swig_globalvar *var = v->vars; 3567 | while (var) { 3568 | swig_globalvar *n = var->next; 3569 | free(var->name); 3570 | free(var); 3571 | var = n; 3572 | } 3573 | } 3574 | 3575 | SWIGINTERN PyObject * 3576 | swig_varlink_getattr(swig_varlinkobject *v, char *n) { 3577 | PyObject *res = NULL; 3578 | swig_globalvar *var = v->vars; 3579 | while (var) { 3580 | if (strcmp(var->name,n) == 0) { 3581 | res = (*var->get_attr)(); 3582 | break; 3583 | } 3584 | var = var->next; 3585 | } 3586 | if (res == NULL && !PyErr_Occurred()) { 3587 | PyErr_SetString(PyExc_NameError,"Unknown C global variable"); 3588 | } 3589 | return res; 3590 | } 3591 | 3592 | SWIGINTERN int 3593 | swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { 3594 | int res = 1; 3595 | swig_globalvar *var = v->vars; 3596 | while (var) { 3597 | if (strcmp(var->name,n) == 0) { 3598 | res = (*var->set_attr)(p); 3599 | break; 3600 | } 3601 | var = var->next; 3602 | } 3603 | if (res == 1 && !PyErr_Occurred()) { 3604 | PyErr_SetString(PyExc_NameError,"Unknown C global variable"); 3605 | } 3606 | return res; 3607 | } 3608 | 3609 | SWIGINTERN PyTypeObject* 3610 | swig_varlink_type(void) { 3611 | static char varlink__doc__[] = "Swig var link object"; 3612 | static PyTypeObject varlink_type; 3613 | static int type_init = 0; 3614 | if (!type_init) { 3615 | const PyTypeObject tmp = { 3616 | /* PyObject header changed in Python 3 */ 3617 | #if PY_VERSION_HEX >= 0x03000000 3618 | PyVarObject_HEAD_INIT(NULL, 0) 3619 | #else 3620 | PyObject_HEAD_INIT(NULL) 3621 | 0, /* ob_size */ 3622 | #endif 3623 | (char *)"swigvarlink", /* tp_name */ 3624 | sizeof(swig_varlinkobject), /* tp_basicsize */ 3625 | 0, /* tp_itemsize */ 3626 | (destructor) swig_varlink_dealloc, /* tp_dealloc */ 3627 | (printfunc) swig_varlink_print, /* tp_print */ 3628 | (getattrfunc) swig_varlink_getattr, /* tp_getattr */ 3629 | (setattrfunc) swig_varlink_setattr, /* tp_setattr */ 3630 | 0, /* tp_compare */ 3631 | (reprfunc) swig_varlink_repr, /* tp_repr */ 3632 | 0, /* tp_as_number */ 3633 | 0, /* tp_as_sequence */ 3634 | 0, /* tp_as_mapping */ 3635 | 0, /* tp_hash */ 3636 | 0, /* tp_call */ 3637 | (reprfunc) swig_varlink_str, /* tp_str */ 3638 | 0, /* tp_getattro */ 3639 | 0, /* tp_setattro */ 3640 | 0, /* tp_as_buffer */ 3641 | 0, /* tp_flags */ 3642 | varlink__doc__, /* tp_doc */ 3643 | 0, /* tp_traverse */ 3644 | 0, /* tp_clear */ 3645 | 0, /* tp_richcompare */ 3646 | 0, /* tp_weaklistoffset */ 3647 | #if PY_VERSION_HEX >= 0x02020000 3648 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ 3649 | #endif 3650 | #if PY_VERSION_HEX >= 0x02030000 3651 | 0, /* tp_del */ 3652 | #endif 3653 | #if PY_VERSION_HEX >= 0x02060000 3654 | 0, /* tp_version */ 3655 | #endif 3656 | #ifdef COUNT_ALLOCS 3657 | 0,0,0,0 /* tp_alloc -> tp_next */ 3658 | #endif 3659 | }; 3660 | varlink_type = tmp; 3661 | type_init = 1; 3662 | #if PY_VERSION_HEX < 0x02020000 3663 | varlink_type.ob_type = &PyType_Type; 3664 | #else 3665 | if (PyType_Ready(&varlink_type) < 0) 3666 | return NULL; 3667 | #endif 3668 | } 3669 | return &varlink_type; 3670 | } 3671 | 3672 | /* Create a variable linking object for use later */ 3673 | SWIGINTERN PyObject * 3674 | SWIG_Python_newvarlink(void) { 3675 | swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); 3676 | if (result) { 3677 | result->vars = 0; 3678 | } 3679 | return ((PyObject*) result); 3680 | } 3681 | 3682 | SWIGINTERN void 3683 | SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { 3684 | swig_varlinkobject *v = (swig_varlinkobject *) p; 3685 | swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); 3686 | if (gv) { 3687 | size_t size = strlen(name)+1; 3688 | gv->name = (char *)malloc(size); 3689 | if (gv->name) { 3690 | strncpy(gv->name,name,size); 3691 | gv->get_attr = get_attr; 3692 | gv->set_attr = set_attr; 3693 | gv->next = v->vars; 3694 | } 3695 | } 3696 | v->vars = gv; 3697 | } 3698 | 3699 | SWIGINTERN PyObject * 3700 | SWIG_globals(void) { 3701 | static PyObject *_SWIG_globals = 0; 3702 | if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); 3703 | return _SWIG_globals; 3704 | } 3705 | 3706 | /* ----------------------------------------------------------------------------- 3707 | * constants/methods manipulation 3708 | * ----------------------------------------------------------------------------- */ 3709 | 3710 | /* Install Constants */ 3711 | SWIGINTERN void 3712 | SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { 3713 | PyObject *obj = 0; 3714 | size_t i; 3715 | for (i = 0; constants[i].type; ++i) { 3716 | switch(constants[i].type) { 3717 | case SWIG_PY_POINTER: 3718 | obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); 3719 | break; 3720 | case SWIG_PY_BINARY: 3721 | obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); 3722 | break; 3723 | default: 3724 | obj = 0; 3725 | break; 3726 | } 3727 | if (obj) { 3728 | PyDict_SetItemString(d, constants[i].name, obj); 3729 | Py_DECREF(obj); 3730 | } 3731 | } 3732 | } 3733 | 3734 | /* -----------------------------------------------------------------------------*/ 3735 | /* Fix SwigMethods to carry the callback ptrs when needed */ 3736 | /* -----------------------------------------------------------------------------*/ 3737 | 3738 | SWIGINTERN void 3739 | SWIG_Python_FixMethods(PyMethodDef *methods, 3740 | swig_const_info *const_table, 3741 | swig_type_info **types, 3742 | swig_type_info **types_initial) { 3743 | size_t i; 3744 | for (i = 0; methods[i].ml_name; ++i) { 3745 | const char *c = methods[i].ml_doc; 3746 | if (c && (c = strstr(c, "swig_ptr: "))) { 3747 | int j; 3748 | swig_const_info *ci = 0; 3749 | const char *name = c + 10; 3750 | for (j = 0; const_table[j].type; ++j) { 3751 | if (strncmp(const_table[j].name, name, 3752 | strlen(const_table[j].name)) == 0) { 3753 | ci = &(const_table[j]); 3754 | break; 3755 | } 3756 | } 3757 | if (ci) { 3758 | void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; 3759 | if (ptr) { 3760 | size_t shift = (ci->ptype) - types; 3761 | swig_type_info *ty = types_initial[shift]; 3762 | size_t ldoc = (c - methods[i].ml_doc); 3763 | size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; 3764 | char *ndoc = (char*)malloc(ldoc + lptr + 10); 3765 | if (ndoc) { 3766 | char *buff = ndoc; 3767 | strncpy(buff, methods[i].ml_doc, ldoc); 3768 | buff += ldoc; 3769 | strncpy(buff, "swig_ptr: ", 10); 3770 | buff += 10; 3771 | SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); 3772 | methods[i].ml_doc = ndoc; 3773 | } 3774 | } 3775 | } 3776 | } 3777 | } 3778 | } 3779 | 3780 | #ifdef __cplusplus 3781 | } 3782 | #endif 3783 | 3784 | /* -----------------------------------------------------------------------------* 3785 | * Partial Init method 3786 | * -----------------------------------------------------------------------------*/ 3787 | 3788 | #ifdef __cplusplus 3789 | extern "C" 3790 | #endif 3791 | 3792 | SWIGEXPORT 3793 | #if PY_VERSION_HEX >= 0x03000000 3794 | PyObject* 3795 | #else 3796 | void 3797 | #endif 3798 | SWIG_init(void) { 3799 | PyObject *m, *d, *md; 3800 | #if PY_VERSION_HEX >= 0x03000000 3801 | static struct PyModuleDef SWIG_module = { 3802 | # if PY_VERSION_HEX >= 0x03020000 3803 | PyModuleDef_HEAD_INIT, 3804 | # else 3805 | { 3806 | PyObject_HEAD_INIT(NULL) 3807 | NULL, /* m_init */ 3808 | 0, /* m_index */ 3809 | NULL, /* m_copy */ 3810 | }, 3811 | # endif 3812 | (char *) SWIG_name, 3813 | NULL, 3814 | -1, 3815 | SwigMethods, 3816 | NULL, 3817 | NULL, 3818 | NULL, 3819 | NULL 3820 | }; 3821 | #endif 3822 | 3823 | #if defined(SWIGPYTHON_BUILTIN) 3824 | static SwigPyClientData SwigPyObject_clientdata = { 3825 | 0, 0, 0, 0, 0, 0, 0 3826 | }; 3827 | static PyGetSetDef this_getset_def = { 3828 | (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL 3829 | }; 3830 | static SwigPyGetSet thisown_getset_closure = { 3831 | (PyCFunction) SwigPyObject_own, 3832 | (PyCFunction) SwigPyObject_own 3833 | }; 3834 | static PyGetSetDef thisown_getset_def = { 3835 | (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure 3836 | }; 3837 | PyObject *metatype_args; 3838 | PyTypeObject *builtin_pytype; 3839 | int builtin_base_count; 3840 | swig_type_info *builtin_basetype; 3841 | PyObject *tuple; 3842 | PyGetSetDescrObject *static_getset; 3843 | PyTypeObject *metatype; 3844 | SwigPyClientData *cd; 3845 | PyObject *public_interface, *public_symbol; 3846 | PyObject *this_descr; 3847 | PyObject *thisown_descr; 3848 | int i; 3849 | 3850 | (void)builtin_pytype; 3851 | (void)builtin_base_count; 3852 | (void)builtin_basetype; 3853 | (void)tuple; 3854 | (void)static_getset; 3855 | 3856 | /* metatype is used to implement static member variables. */ 3857 | metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type); 3858 | assert(metatype_args); 3859 | metatype = (PyTypeObject *) PyType_Type.tp_call((PyObject *) &PyType_Type, metatype_args, NULL); 3860 | assert(metatype); 3861 | Py_DECREF(metatype_args); 3862 | metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; 3863 | assert(PyType_Ready(metatype) >= 0); 3864 | #endif 3865 | 3866 | /* Fix SwigMethods to carry the callback ptrs when needed */ 3867 | SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); 3868 | 3869 | #if PY_VERSION_HEX >= 0x03000000 3870 | m = PyModule_Create(&SWIG_module); 3871 | #else 3872 | m = Py_InitModule((char *) SWIG_name, SwigMethods); 3873 | #endif 3874 | md = d = PyModule_GetDict(m); 3875 | (void)md; 3876 | 3877 | SWIG_InitializeModule(0); 3878 | 3879 | #ifdef SWIGPYTHON_BUILTIN 3880 | SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); 3881 | assert(SwigPyObject_stype); 3882 | cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; 3883 | if (!cd) { 3884 | SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; 3885 | SwigPyObject_clientdata.pytype = SwigPyObject_TypeOnce(); 3886 | } else if (SwigPyObject_TypeOnce()->tp_basicsize != cd->pytype->tp_basicsize) { 3887 | PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); 3888 | # if PY_VERSION_HEX >= 0x03000000 3889 | return NULL; 3890 | # else 3891 | return; 3892 | # endif 3893 | } 3894 | 3895 | /* All objects have a 'this' attribute */ 3896 | this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); 3897 | (void)this_descr; 3898 | 3899 | /* All objects have a 'thisown' attribute */ 3900 | thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); 3901 | (void)thisown_descr; 3902 | 3903 | public_interface = PyList_New(0); 3904 | public_symbol = 0; 3905 | (void)public_symbol; 3906 | 3907 | PyDict_SetItemString(md, "__all__", public_interface); 3908 | Py_DECREF(public_interface); 3909 | for (i = 0; SwigMethods[i].ml_name != NULL; ++i) 3910 | SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name); 3911 | for (i = 0; swig_const_table[i].name != 0; ++i) 3912 | SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name); 3913 | #endif 3914 | 3915 | SWIG_InstallConstants(d,swig_const_table); 3916 | 3917 | #if PY_VERSION_HEX >= 0x03000000 3918 | return m; 3919 | #else 3920 | return; 3921 | #endif 3922 | } 3923 | 3924 | -------------------------------------------------------------------------------- /quantz_kit/weights_compress_wrap.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuanyuanli85/CaffeModelCompression/0fbf138cdabc6f85608daca44438e36e0b5506fe/quantz_kit/weights_compress_wrap.o -------------------------------------------------------------------------------- /quantz_kit/weights_quantization.py: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by SWIG (http://www.swig.org). 2 | # Version 2.0.12 3 | # 4 | # Do not make changes to this file unless you know what you are doing--modify 5 | # the SWIG interface file instead. 6 | 7 | 8 | 9 | 10 | 11 | from sys import version_info 12 | if version_info >= (2,6,0): 13 | def swig_import_helper(): 14 | from os.path import dirname 15 | import imp 16 | fp = None 17 | try: 18 | fp, pathname, description = imp.find_module('_weights_quantization', [dirname(__file__)]) 19 | except ImportError: 20 | import _weights_quantization 21 | return _weights_quantization 22 | if fp is not None: 23 | try: 24 | _mod = imp.load_module('_weights_quantization', fp, pathname, description) 25 | finally: 26 | fp.close() 27 | return _mod 28 | _weights_quantization = swig_import_helper() 29 | del swig_import_helper 30 | else: 31 | import _weights_quantization 32 | del version_info 33 | try: 34 | _swig_property = property 35 | except NameError: 36 | pass # Python < 2.2 doesn't have 'property'. 37 | def _swig_setattr_nondynamic(self,class_type,name,value,static=1): 38 | if (name == "thisown"): return self.this.own(value) 39 | if (name == "this"): 40 | if type(value).__name__ == 'SwigPyObject': 41 | self.__dict__[name] = value 42 | return 43 | method = class_type.__swig_setmethods__.get(name,None) 44 | if method: return method(self,value) 45 | if (not static): 46 | self.__dict__[name] = value 47 | else: 48 | raise AttributeError("You cannot add attributes to %s" % self) 49 | 50 | def _swig_setattr(self,class_type,name,value): 51 | return _swig_setattr_nondynamic(self,class_type,name,value,0) 52 | 53 | def _swig_getattr(self,class_type,name): 54 | if (name == "thisown"): return self.this.own() 55 | method = class_type.__swig_getmethods__.get(name,None) 56 | if method: return method(self) 57 | raise AttributeError(name) 58 | 59 | def _swig_repr(self): 60 | try: strthis = "proxy of " + self.this.__repr__() 61 | except: strthis = "" 62 | return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) 63 | 64 | try: 65 | _object = object 66 | _newclass = 1 67 | except AttributeError: 68 | class _object : pass 69 | _newclass = 0 70 | 71 | 72 | 73 | def compress_layer_weights(*args): 74 | return _weights_quantization.compress_layer_weights(*args) 75 | compress_layer_weights = _weights_quantization.compress_layer_weights 76 | 77 | def decompress_layer_weights(*args): 78 | return _weights_quantization.decompress_layer_weights(*args) 79 | decompress_layer_weights = _weights_quantization.decompress_layer_weights 80 | 81 | def quantize_layer_weights(*args): 82 | return _weights_quantization.quantize_layer_weights(*args) 83 | quantize_layer_weights = _weights_quantization.quantize_layer_weights 84 | # This file is compatible with both classic and new-style classes. 85 | 86 | 87 | -------------------------------------------------------------------------------- /quantz_kit/weights_quantization.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuanyuanli85/CaffeModelCompression/0fbf138cdabc6f85608daca44438e36e0b5506fe/quantz_kit/weights_quantization.pyc --------------------------------------------------------------------------------