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

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

  •  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