小编Joe*_*ntz的帖子

使用iso_c_binding在Fortran-C桥中的字符串数组

我正在编写将使用Fortran的C互操作性机制从Fortran调用C函数的代码(在Fortran 2003中引入并在较新版本的gfortran和ifort中实现).

这个答案几乎就是我所需要的,但是我不能完全理解我应该在Fortran中使用哪个接口声明来获得一个看起来像这样的C函数:

int use_array(int n, char * array[]){
    int i;
    for(i=0; i<n; i++){
        printf("Item %d = %s\n",i,array[i]);
    }
    return n;
}
Run Code Online (Sandbox Code Playgroud)

我不清楚Fortran端的接口应该是什么声明:

interface
    function use_array(n, x) bind(C)
        use iso_c_binding
        integer (c_int) use_array
        integer (c_int), value :: n
        character(c_char) WHAT_SHOULD_GO_HERE? :: x
    end function use_array
end interface
Run Code Online (Sandbox Code Playgroud)

我知道我也必须处理空终止问题.

c interop fortran fortran-iso-c-binding

12
推荐指数
1
解决办法
3675
查看次数

相交并排序两个numpy数组的索引

我有两个numpy整数数组,长度都是几亿.在每个数组中,值是唯一的,并且每个值最初都是未排序的.

我希望每个索引产生它们的排序交集.例如:

x = np.array([4, 1, 10, 5, 8, 13, 11])
y = np.array([20, 5, 4, 9, 11, 7, 25])
Run Code Online (Sandbox Code Playgroud)

然后这些排序的交集是[4, 5, 11],所以我们想要将x和y中的每一个转换成该数组的索引,所以我们希望它返回:

mx = np.array([0, 3, 6])
my = np.array([2, 1, 4])
Run Code Online (Sandbox Code Playgroud)

自那时候起 x[mx] == y[my] == np.intersect1d(x, y)

到目前为止,我们唯一的解决方案涉及三种不同的方法,因此似乎不太可能是最优的.

每个值代表一个星系,以防这个问题变得更有趣.

python sorting optimization numpy set-intersection

8
推荐指数
1
解决办法
954
查看次数

ios MapKit MKOverlayView动画即刻发生

我试图使用以下代码在iOS 5中为MapKit重叠视图(特别是MKCircleView)的alpha值设置动画:

-(void) animateCircle:(MKCircle*)circle onMap:(MKMapView*) mapView
{
    MKCircleView * circleView = (MKCircleView*) [mapView viewForOverlay:circle];
    UIViewAnimationOptions options = UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionTransitionNone;
    [UIView animateWithDuration:5.0 
                          delay:0.0 
                        options:options 
                     animations:^(void) { circleView.alpha = 0.9; }
                     completion:^(BOOL finished) {} 
     ];    
}
Run Code Online (Sandbox Code Playgroud)

叠加层的alpha值正在按我的意愿改变,但它会瞬间跳到那里,而不是在指定的持续时间内动画.

任何人都可以建议可能出错的地方?也许叠加视图上的动画与块比我想象的更复杂.

animation overlay mapkit ios

6
推荐指数
1
解决办法
1075
查看次数