OS X

gmpy

python から GMP を利用するためのパッケージです。
pip でインストールします。
パッケージを検索すると以下のものが見つかります。

$ pip search gmpy
gmpy2                     - GMP/MPIR, MPFR, and MPC interface to Python 2.6+ and 3.x
gmpy                      - GMP or MPIR interface to Python 2.4+ and 3.x
gmpy_cffi                 - GMP CFFI wrapper

gmpy
https://code.google.com/p/gmpy/

GMPY と GMPY2 は高速な多倍長演算をサポートする C で書かれた Python 拡張モジュールです。

GMPY は GMP だけをサポートしており、高速な多倍長整数と有理数の演算を提供します。
また GMP から限定的な多倍長浮動小数点型もサポートされます。

GMPY2 は整数と有理数の演算のため GMP をサポートしますが、
MPFR と MPC ライブラリから提供されるので実数と複素数の多倍長演算も追加してサポートします。

GMPの他、MPFRとMPCもインストールしてあるので gmpy2 をインストールします。
(Mac OS X Mavericks 10.9.3 で確認しています。)

$ sudo pip install gmpy2
Password:
Downloading/unpacking gmpy2
  Downloading gmpy2-2.0.3.zip (279kB): 279kB downloaded
  Running setup.py (path:/private/tmp/pip_build_root/gmpy2/setup.py) egg_info for package gmpy2
    
Installing collected packages: gmpy2
  Running setup.py install for gmpy2
    building 'gmpy2' extension
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv \
    -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes \
    -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -DWITHMPFR -DWITHMPC -I./src -I/usr/local/include \
    -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/gmpy2.c -o build/temp.macosx-10.9-intel-2.7/src/gmpy2.o
    In file included from src/gmpy2.c:508:
    ./src/gmpy_mpz_prp.c:1043:33: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
        for (j = mpz_sizeinbase(s,2)-1; j >= 1; j--) {
               ~ ~~~~~~~~~~~~~~~~~~~^~
    In file included from src/gmpy2.c:519:
    ./src/gmpy_mpz.c:1915:5: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        PARSE_ONE_MPZ_OPT_CLONG(&reps,
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./src/gmpy_args.h:123:20: note: expanded from macro 'PARSE_ONE_MPZ_OPT_CLONG'
                *var = clong_From_Integer(PyTuple_GET_ITEM(args, 0)); \
                     ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from src/gmpy2.c:519:
    ./src/gmpy_mpz.c:1915:5: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        PARSE_ONE_MPZ_OPT_CLONG(&reps,
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./src/gmpy_args.h:137:20: note: expanded from macro 'PARSE_ONE_MPZ_OPT_CLONG'
                *var = clong_From_Integer(PyTuple_GET_ITEM(args, 1)); \
                     ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3 warnings generated.
    In file included from src/gmpy2.c:480:
    ./src/mpz_pylong.c:55:10: warning: shift count >= width of type [-Wshift-count-overflow]
      if ((x >> 32) != 0) { x >>= 32; cnt += 32; }
             ^  ~~
    ./src/mpz_pylong.c:55:27: warning: shift count >= width of type [-Wshift-count-overflow]
      if ((x >> 32) != 0) { x >>= 32; cnt += 32; }
                              ^   ~~
    2 warnings generated.
    cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.9-intel-2.7/src/gmpy2.o \
    -L/usr/local/lib -L/usr/local/lib -lgmp -lmpfr -lmpc -o build/lib.macosx-10.9-intel-2.7/gmpy2.so
    ld: warning: ignoring file /usr/local/lib/libgmp.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libgmp.dylib
    ld: warning: ignoring file /usr/local/lib/libmpfr.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libmpfr.dylib
    ld: warning: ignoring file /usr/local/lib/libmpc.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libmpc.dylib
     
Successfully installed gmpy2
Cleaning up...

数カ所ワーニングが出ますが正常にインストールされます。
Using gmpy2 and mpfr
のサンプルなどを実行してみて正常に実行できればインストールは成功です。

$ python
Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gmpy2
>>> gmpy2.mpfr("1.2")
mpfr('1.2')
>>> gmpy2.sqrt(gmpy2.mpfr("3.2"))
mpfr('1.7888543819998317')
>>> gmpy2.sin(gmpy2.mpfr(".5"))
mpfr('0.47942553860420301')
>>>

BC::labsへの質問は、bc9-dev @ googlegroups.com までお願い致します。
トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS
Last-modified: 2014-05-20 (火) 20:42:55 (3630d)