|
1 | | -using System; |
2 | | -using System.Diagnostics.CodeAnalysis; |
3 | | -using System.Runtime.CompilerServices; |
4 | | -using NumSharp.Backends; |
5 | | -using NumSharp.Generic; |
6 | | -using NumSharp.Utilities; |
7 | | - |
8 | | -namespace NumSharp |
| 1 | +namespace NumSharp |
9 | 2 | { |
10 | 3 | public partial class NDArray |
11 | 4 | { |
12 | | - [MethodImpl((MethodImplOptions)768)] |
13 | | - [SuppressMessage("ReSharper", "JoinDeclarationAndInitializer")] |
14 | | - [SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator")] |
15 | | - public static unsafe NumSharp.Generic.NDArray<bool> operator >(NDArray lhs, NDArray rhs) |
16 | | - { |
17 | | - if(lhs.typecode == NPTypeCode.Int32 && rhs.typecode == NPTypeCode.Int32) |
18 | | - { |
19 | | - if (lhs.Shape.IsScalar && rhs.Shape.IsScalar) |
20 | | - return NDArray.Scalar<bool>(*(int*)lhs.Address > *(int*)rhs.Address).MakeGeneric<bool>(); |
21 | | - |
22 | | - (Shape BroadcastedLeftShape, Shape BroadcastedRightShape) = DefaultEngine.Broadcast(lhs.Shape, rhs.Shape); |
23 | | - var lhs_address = (int*)lhs.Address; |
24 | | - var rhs_address = (int*)rhs.Address; |
25 | | - var ret = new NDArray<bool>(new Shape(BroadcastedLeftShape.dimensions), true); |
26 | | - Shape retShape = ret.Shape; |
27 | | - |
28 | | - //iterate |
29 | | - var ret_address = (bool*)ret.Address; |
30 | | - var incr = new NDCoordinatesIncrementor(BroadcastedLeftShape.dimensions); //doesn't matter which side it is. |
31 | | - int[] current = incr.Index; |
32 | | - do |
33 | | - { |
34 | | - *(ret_address + retShape.GetOffset(current)) = (*(lhs_address + BroadcastedLeftShape.GetOffset(current))) > *(rhs_address + BroadcastedRightShape.GetOffset(current)); |
35 | | - } while (incr.Next() != null); |
36 | | - |
37 | | - return ret; |
38 | | - } |
39 | | - else if (lhs.typecode == NPTypeCode.Float && rhs.typecode == NPTypeCode.Float) |
40 | | - { |
41 | | - if (lhs.Shape.IsScalar && rhs.Shape.IsScalar) |
42 | | - return NDArray.Scalar<bool>(*(float*)lhs.Address > *(float*)rhs.Address).MakeGeneric<bool>(); |
43 | | - |
44 | | - (Shape BroadcastedLeftShape, Shape BroadcastedRightShape) = DefaultEngine.Broadcast(lhs.Shape, rhs.Shape); |
45 | | - var lhs_address = (float*)lhs.Address; |
46 | | - var rhs_address = (float*)rhs.Address; |
47 | | - var ret = new NDArray<bool>(new Shape(BroadcastedLeftShape.dimensions), true); |
48 | | - Shape retShape = ret.Shape; |
49 | | - |
50 | | - //iterate |
51 | | - var ret_address = (bool*)ret.Address; |
52 | | - var incr = new NDCoordinatesIncrementor(BroadcastedLeftShape.dimensions); //doesn't matter which side it is. |
53 | | - int[] current = incr.Index; |
54 | | - do |
55 | | - { |
56 | | - *(ret_address + retShape.GetOffset(current)) = (*(lhs_address + BroadcastedLeftShape.GetOffset(current))) > *(rhs_address + BroadcastedRightShape.GetOffset(current)); |
57 | | - } while (incr.Next() != null); |
58 | | - |
59 | | - return ret; |
60 | | - } |
61 | | - else |
62 | | - { |
63 | | - throw new NotImplementedException($"{lhs.typecode} > {rhs.typecode}"); |
64 | | - } |
65 | | - } |
66 | | - |
67 | 5 | public static NumSharp.Generic.NDArray<bool> operator >(NDArray np, int obj) |
68 | 6 | { |
69 | 7 | return (np > (System.Object)obj); |
|
0 commit comments