@@ -565,3 +565,89 @@ def rank_2d_generic(object in_arr, axis=0, ties_method='average',
565
565
# for j in range(K):
566
566
# result[i, j] = values[i, indexer[i, j]]
567
567
# return result
568
+
569
+ @ cython.wraparound (False )
570
+ @ cython.boundscheck (False )
571
+ def diff_2d_float64 (ndarray[float64_t , ndim = 2 ] arr,
572
+ ndarray[float64_t , ndim = 2 ] out,
573
+ Py_ssize_t periods , int axis ):
574
+ cdef:
575
+ Py_ssize_t i, j, sx, sy
576
+
577
+ sx, sy = (< object > arr).shape
578
+ if arr.flags.f_contiguous:
579
+ if axis == 0 :
580
+ for j in range (sy):
581
+ for i in range (periods, sx):
582
+ out[i, j] = arr[i, j] - arr[i - periods, j]
583
+ else :
584
+ for j in range (periods, sy):
585
+ for i in range (sx):
586
+ out[i, j] = arr[i, j] - arr[i, j - periods]
587
+ else :
588
+ if axis == 0 :
589
+ for i in range (periods, sx):
590
+ for j in range (sy):
591
+ out[i, j] = arr[i, j] - arr[i - periods, j]
592
+ else :
593
+ for i in range (sx):
594
+ for j in range (periods, sy):
595
+ out[i, j] = arr[i, j] - arr[i, j - periods]
596
+
597
+ @ cython.wraparound (False )
598
+ @ cython.boundscheck (False )
599
+ def diff_2d_int64 (ndarray[int64_t , ndim = 2 ] arr,
600
+ ndarray[float64_t , ndim = 2 ] out,
601
+ Py_ssize_t periods , int axis ):
602
+ cdef:
603
+ Py_ssize_t i, j, sx, sy
604
+
605
+ sx, sy = (< object > arr).shape
606
+ if arr.flags.f_contiguous:
607
+ if axis == 0 :
608
+ for j in range (sy):
609
+ for i in range (periods, sx):
610
+ out[i, j] = arr[i, j] - arr[i - periods, j]
611
+ else :
612
+ for j in range (periods, sy):
613
+ for i in range (sx):
614
+ out[i, j] = arr[i, j] - arr[i, j - periods]
615
+ else :
616
+ if axis == 0 :
617
+ for i in range (periods, sx):
618
+ for j in range (sy):
619
+ out[i, j] = arr[i, j] - arr[i - periods, j]
620
+ else :
621
+ for i in range (sx):
622
+ for j in range (periods, sy):
623
+ out[i, j] = arr[i, j] - arr[i, j - periods]
624
+
625
+
626
+ @ cython.wraparound (False )
627
+ @ cython.boundscheck (False )
628
+ def diff_2d_int32 (ndarray[int64_t , ndim = 2 ] arr,
629
+ ndarray[float64_t , ndim = 2 ] out,
630
+ Py_ssize_t periods , int axis ):
631
+ cdef:
632
+ Py_ssize_t i, j, sx, sy
633
+
634
+ sx, sy = (< object > arr).shape
635
+ if arr.flags.f_contiguous:
636
+ if axis == 0 :
637
+ for j in range (sy):
638
+ for i in range (periods, sx):
639
+ out[i, j] = arr[i, j] - arr[i - periods, j]
640
+ else :
641
+ for j in range (periods, sy):
642
+ for i in range (sx):
643
+ out[i, j] = arr[i, j] - arr[i, j - periods]
644
+ else :
645
+ if axis == 0 :
646
+ for i in range (periods, sx):
647
+ for j in range (sy):
648
+ out[i, j] = arr[i, j] - arr[i - periods, j]
649
+ else :
650
+ for i in range (sx):
651
+ for j in range (periods, sy):
652
+ out[i, j] = arr[i, j] - arr[i, j - periods]
653
+
0 commit comments