Is it possible to use blitz++ indexing and blitz functions in scipy.weave.inline

StackOverflow https://stackoverflow.com/questions/9216455

  •  28-04-2021
  •  | 
  •  

문제

The scipy document gives examples of Blitz++ style operations when using weave.blitz() and C style indexing when using weave.inline(). Does weave.inline() also support Blitz++ style indexing and reductions. That will be very convenient. If weave.inline() does indeed allow Blitz++ style indexing, could you tell me how to get a Blitz array from a numpy array in the weave.inline() code. Much appreciated.

도움이 되었습니까?

해결책

Here is an example, set the type_converter = weave.converters.blitz when calling weave.inline()

# -*- coding: utf-8 -*-
import scipy.weave as weave
import numpy as np
import time

def my_sum(a):
    n=int(len(a))
    code="""
    int i;

    double counter;
    counter =0;
    for(i=0;i<n;i++){
        counter=counter+a(i);
    }
    return_val=counter;
    """

    err=weave.inline(  
        code,   
        ['a','n'],   
        type_converters=weave.converters.blitz, 
        compiler="gcc"  
    )
    return err

a = np.arange(0, 10000000, 1.0)
print my_sum(a)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top