c-适用于Windows的python ncreduce

我正在使用python进行天文图像处理,并且numpy.std(a)正在消耗过多的内存.一些搜索显示了Luis Pedro的ncreduce软件包,但是我很难构建here软件包的下载.ActiveState似乎表明该软件包不能在Windows上构建.我正在使用Win...

我正在使用python进行天文图像处理,并且numpy.std(a)正在消耗过多的内存.一些搜索显示了Luis Pedro的ncreduce软件包,但是我很难构建here软件包的下载.ActiveState似乎表明该软件包不能在Windows上构建.我正在使用Windows 7和Python 2.7.

是否可以在Windows上使用ncreduce?如果不是,是否有替代的快速算法来计算标准偏差或方差,而不像numpy.std(a)那样耗费内存?

解决方法:

该软件包需要一些小的更改才能使用msvc构建.它已经很老了,没有测试,所以使用后果自负.

--- ncreduce/reduce.cpp Thu Aug 14 13:02:50 2008
+++ ncreduce/reduce.cpp Thu Sep 26 11:56:04 2013
@@ -6,6 +6,7 @@
 #include <iterator>
 #include <vector>
 #include <cmath>
+#include <limits>
 extern "C" {
     #include <Python.h>
     #include <numpy/ndarrayobject.h>
@@ -98,7 +99,7 @@
         }
         *result /= N;
         if (extra.is_std) {
-            *result = std::sqrt(*result);
+            *result = std::sqrt((double)(*result));
         }
     }

@@ -142,7 +143,7 @@
         for (unsigned i = 0; i != result.diameter(); ++i) {
             first_result[i] = divide(first_result[i],ArrSize/result.diameter());
             if (extra.is_std) {
-                first_result[i] = sqrt(first_result[i]);
+                first_result[i] = sqrt((double)first_result[i]);
             }
         }

--- setup.py    Thu Aug 14 13:54:48 2008
+++ setup.py    Thu Sep 26 12:03:16 2013
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 from numpy.distutils.core import setup, Extension

-ncreduce = Extension('ncreduce', sources = ['ncreduce/reduce.cpp', 'ncreduce/numpy_utils.hpp'], extra_compile_args=['-Wno-sign-compare'])
+ncreduce = Extension('ncreduce', sources = ['ncreduce/reduce.cpp', 'ncreduce/numpy_utils.hpp'], extra_compile_args=['/EHsc'])

 classifiers = [
     'Development Status :: 4 - Beta',

我把二进制数设为http://www.lfd.uci.edu/~gohlke/pythonlibs/.搜索ncreduce.

本文标题为:c-适用于Windows的python ncreduce

基础教程推荐