Skip to content

Commit

Permalink
remove generic types from searchSorted
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpotts committed Sep 20, 2024
1 parent 07fe429 commit a565806
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 156 deletions.
13 changes: 3 additions & 10 deletions src/SortMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ module SortMsg
}
}


proc sort(array: [?d] ?t, alg: string, axis: int): [d] t throws
where ((t == real) || (t==int) || (t==uint(64))) && (d.rank > 1) {

Expand Down Expand Up @@ -92,16 +91,15 @@ module SortMsg
return sorted;
}


proc sort(array: [?d] ?t, alg: string, axis: int): [d] t throws
where ((t != real) && (t!=int) && (t!=uint(64))) {
throw new Error("sort does not support type %s".format(type2str(t)));
}

// https://data-apis.org/array-api/latest/API_specification/generated/array_api.searchsorted.html#array_api.searchsorted
@arkouda.registerCommand
proc searchSorted(x1: [?d1] ?t, x2: [?d2] ?t2, side: string): [d2] int throws
where (t == real) && (t2 == real) && (d1.rank == 1) {
proc searchSorted(x1: [?d1] real, x2: [?d2] real, side: string): [d2] int throws
where (d1.rank == 1) {

if side != "left" && side != "right" {
throw new Error("searchSorted side must be a string with value 'left' or 'right'.");
Expand All @@ -125,16 +123,11 @@ module SortMsg
return ret;
}

proc searchSorted(x1: [?d1] ?t, x2: [?d2] ?t2, side: string): [d2] int throws
proc searchSorted(x1: [?d1] real, x2: [?d2] real, side: string): [d2] int throws
where (d1.rank != 1){
throw new Error("searchSorted only arrays x1 of dimension 1.");
}

proc searchSorted(x1: [?d1] ?t, x2: [?d2] ?t2, side: string): [d2] int throws
where ((t != real) || (t2 != real)) && (d1.rank == 1){
throw new Error("searchSorted only supports float64 type.");
}

record leftCmp: relativeComparator {
proc compare(a: real, b: real): int {
if a < b then return -1;
Expand Down
152 changes: 6 additions & 146 deletions src/registry/Commands.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1905,10 +1905,10 @@ proc ark_sort_bigint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed
return ark_reg_sort_generic(cmd, msgArgs, st, array_dtype_0=bigint, array_nd_0=1);
registerFunction('sort<bigint,1>', ark_sort_bigint_1, 'SortMsg', 34);

proc ark_reg_searchSorted_generic(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab, type array_dtype_0, param array_nd_0: int, type array_dtype_1, param array_nd_1: int): MsgTuple throws {
var x1_array_sym = st[msgArgs['x1']]: SymEntry(array_dtype_0, array_nd_0);
proc ark_reg_searchSorted_generic(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab, param array_nd_0: int, param array_nd_1: int): MsgTuple throws {
var x1_array_sym = st[msgArgs['x1']]: SymEntry(real, array_nd_0);
ref x1 = x1_array_sym.a;
var x2_array_sym = st[msgArgs['x2']]: SymEntry(array_dtype_1, array_nd_1);
var x2_array_sym = st[msgArgs['x2']]: SymEntry(real, array_nd_1);
ref x2 = x2_array_sym.a;
var side = msgArgs['side'].toScalar(string);
var ark_result = SortMsg.searchSorted(x1,x2,side);
Expand All @@ -1917,149 +1917,9 @@ proc ark_reg_searchSorted_generic(cmd: string, msgArgs: borrowed MessageArgs, st
return st.insert(ark_result_symbol);
}

proc ark_searchSorted_int_1_int_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=int, array_nd_0=1, array_dtype_1=int, array_nd_1=1);
registerFunction('searchSorted<int64,1,int64,1>', ark_searchSorted_int_1_int_1, 'SortMsg', 103);

proc ark_searchSorted_int_1_uint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=int, array_nd_0=1, array_dtype_1=uint, array_nd_1=1);
registerFunction('searchSorted<int64,1,uint64,1>', ark_searchSorted_int_1_uint_1, 'SortMsg', 103);

proc ark_searchSorted_int_1_uint8_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=int, array_nd_0=1, array_dtype_1=uint(8), array_nd_1=1);
registerFunction('searchSorted<int64,1,uint8,1>', ark_searchSorted_int_1_uint8_1, 'SortMsg', 103);

proc ark_searchSorted_int_1_real_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=int, array_nd_0=1, array_dtype_1=real, array_nd_1=1);
registerFunction('searchSorted<int64,1,float64,1>', ark_searchSorted_int_1_real_1, 'SortMsg', 103);

proc ark_searchSorted_int_1_bool_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=int, array_nd_0=1, array_dtype_1=bool, array_nd_1=1);
registerFunction('searchSorted<int64,1,bool,1>', ark_searchSorted_int_1_bool_1, 'SortMsg', 103);

proc ark_searchSorted_int_1_bigint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=int, array_nd_0=1, array_dtype_1=bigint, array_nd_1=1);
registerFunction('searchSorted<int64,1,bigint,1>', ark_searchSorted_int_1_bigint_1, 'SortMsg', 103);

proc ark_searchSorted_uint_1_int_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint, array_nd_0=1, array_dtype_1=int, array_nd_1=1);
registerFunction('searchSorted<uint64,1,int64,1>', ark_searchSorted_uint_1_int_1, 'SortMsg', 103);

proc ark_searchSorted_uint_1_uint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint, array_nd_0=1, array_dtype_1=uint, array_nd_1=1);
registerFunction('searchSorted<uint64,1,uint64,1>', ark_searchSorted_uint_1_uint_1, 'SortMsg', 103);

proc ark_searchSorted_uint_1_uint8_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint, array_nd_0=1, array_dtype_1=uint(8), array_nd_1=1);
registerFunction('searchSorted<uint64,1,uint8,1>', ark_searchSorted_uint_1_uint8_1, 'SortMsg', 103);

proc ark_searchSorted_uint_1_real_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint, array_nd_0=1, array_dtype_1=real, array_nd_1=1);
registerFunction('searchSorted<uint64,1,float64,1>', ark_searchSorted_uint_1_real_1, 'SortMsg', 103);

proc ark_searchSorted_uint_1_bool_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint, array_nd_0=1, array_dtype_1=bool, array_nd_1=1);
registerFunction('searchSorted<uint64,1,bool,1>', ark_searchSorted_uint_1_bool_1, 'SortMsg', 103);

proc ark_searchSorted_uint_1_bigint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint, array_nd_0=1, array_dtype_1=bigint, array_nd_1=1);
registerFunction('searchSorted<uint64,1,bigint,1>', ark_searchSorted_uint_1_bigint_1, 'SortMsg', 103);

proc ark_searchSorted_uint8_1_int_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint(8), array_nd_0=1, array_dtype_1=int, array_nd_1=1);
registerFunction('searchSorted<uint8,1,int64,1>', ark_searchSorted_uint8_1_int_1, 'SortMsg', 103);

proc ark_searchSorted_uint8_1_uint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint(8), array_nd_0=1, array_dtype_1=uint, array_nd_1=1);
registerFunction('searchSorted<uint8,1,uint64,1>', ark_searchSorted_uint8_1_uint_1, 'SortMsg', 103);

proc ark_searchSorted_uint8_1_uint8_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint(8), array_nd_0=1, array_dtype_1=uint(8), array_nd_1=1);
registerFunction('searchSorted<uint8,1,uint8,1>', ark_searchSorted_uint8_1_uint8_1, 'SortMsg', 103);

proc ark_searchSorted_uint8_1_real_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint(8), array_nd_0=1, array_dtype_1=real, array_nd_1=1);
registerFunction('searchSorted<uint8,1,float64,1>', ark_searchSorted_uint8_1_real_1, 'SortMsg', 103);

proc ark_searchSorted_uint8_1_bool_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint(8), array_nd_0=1, array_dtype_1=bool, array_nd_1=1);
registerFunction('searchSorted<uint8,1,bool,1>', ark_searchSorted_uint8_1_bool_1, 'SortMsg', 103);

proc ark_searchSorted_uint8_1_bigint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=uint(8), array_nd_0=1, array_dtype_1=bigint, array_nd_1=1);
registerFunction('searchSorted<uint8,1,bigint,1>', ark_searchSorted_uint8_1_bigint_1, 'SortMsg', 103);

proc ark_searchSorted_real_1_int_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=real, array_nd_0=1, array_dtype_1=int, array_nd_1=1);
registerFunction('searchSorted<float64,1,int64,1>', ark_searchSorted_real_1_int_1, 'SortMsg', 103);

proc ark_searchSorted_real_1_uint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=real, array_nd_0=1, array_dtype_1=uint, array_nd_1=1);
registerFunction('searchSorted<float64,1,uint64,1>', ark_searchSorted_real_1_uint_1, 'SortMsg', 103);

proc ark_searchSorted_real_1_uint8_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=real, array_nd_0=1, array_dtype_1=uint(8), array_nd_1=1);
registerFunction('searchSorted<float64,1,uint8,1>', ark_searchSorted_real_1_uint8_1, 'SortMsg', 103);

proc ark_searchSorted_real_1_real_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=real, array_nd_0=1, array_dtype_1=real, array_nd_1=1);
registerFunction('searchSorted<float64,1,float64,1>', ark_searchSorted_real_1_real_1, 'SortMsg', 103);

proc ark_searchSorted_real_1_bool_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=real, array_nd_0=1, array_dtype_1=bool, array_nd_1=1);
registerFunction('searchSorted<float64,1,bool,1>', ark_searchSorted_real_1_bool_1, 'SortMsg', 103);

proc ark_searchSorted_real_1_bigint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=real, array_nd_0=1, array_dtype_1=bigint, array_nd_1=1);
registerFunction('searchSorted<float64,1,bigint,1>', ark_searchSorted_real_1_bigint_1, 'SortMsg', 103);

proc ark_searchSorted_bool_1_int_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bool, array_nd_0=1, array_dtype_1=int, array_nd_1=1);
registerFunction('searchSorted<bool,1,int64,1>', ark_searchSorted_bool_1_int_1, 'SortMsg', 103);

proc ark_searchSorted_bool_1_uint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bool, array_nd_0=1, array_dtype_1=uint, array_nd_1=1);
registerFunction('searchSorted<bool,1,uint64,1>', ark_searchSorted_bool_1_uint_1, 'SortMsg', 103);

proc ark_searchSorted_bool_1_uint8_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bool, array_nd_0=1, array_dtype_1=uint(8), array_nd_1=1);
registerFunction('searchSorted<bool,1,uint8,1>', ark_searchSorted_bool_1_uint8_1, 'SortMsg', 103);

proc ark_searchSorted_bool_1_real_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bool, array_nd_0=1, array_dtype_1=real, array_nd_1=1);
registerFunction('searchSorted<bool,1,float64,1>', ark_searchSorted_bool_1_real_1, 'SortMsg', 103);

proc ark_searchSorted_bool_1_bool_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bool, array_nd_0=1, array_dtype_1=bool, array_nd_1=1);
registerFunction('searchSorted<bool,1,bool,1>', ark_searchSorted_bool_1_bool_1, 'SortMsg', 103);

proc ark_searchSorted_bool_1_bigint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bool, array_nd_0=1, array_dtype_1=bigint, array_nd_1=1);
registerFunction('searchSorted<bool,1,bigint,1>', ark_searchSorted_bool_1_bigint_1, 'SortMsg', 103);

proc ark_searchSorted_bigint_1_int_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bigint, array_nd_0=1, array_dtype_1=int, array_nd_1=1);
registerFunction('searchSorted<bigint,1,int64,1>', ark_searchSorted_bigint_1_int_1, 'SortMsg', 103);

proc ark_searchSorted_bigint_1_uint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bigint, array_nd_0=1, array_dtype_1=uint, array_nd_1=1);
registerFunction('searchSorted<bigint,1,uint64,1>', ark_searchSorted_bigint_1_uint_1, 'SortMsg', 103);

proc ark_searchSorted_bigint_1_uint8_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bigint, array_nd_0=1, array_dtype_1=uint(8), array_nd_1=1);
registerFunction('searchSorted<bigint,1,uint8,1>', ark_searchSorted_bigint_1_uint8_1, 'SortMsg', 103);

proc ark_searchSorted_bigint_1_real_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bigint, array_nd_0=1, array_dtype_1=real, array_nd_1=1);
registerFunction('searchSorted<bigint,1,float64,1>', ark_searchSorted_bigint_1_real_1, 'SortMsg', 103);

proc ark_searchSorted_bigint_1_bool_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bigint, array_nd_0=1, array_dtype_1=bool, array_nd_1=1);
registerFunction('searchSorted<bigint,1,bool,1>', ark_searchSorted_bigint_1_bool_1, 'SortMsg', 103);

proc ark_searchSorted_bigint_1_bigint_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_dtype_0=bigint, array_nd_0=1, array_dtype_1=bigint, array_nd_1=1);
registerFunction('searchSorted<bigint,1,bigint,1>', ark_searchSorted_bigint_1_bigint_1, 'SortMsg', 103);
proc ark_searchSorted_1_1(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws do
return ark_reg_searchSorted_generic(cmd, msgArgs, st, array_nd_0=1, array_nd_1=1);
registerFunction('searchSorted<1,1>', ark_searchSorted_1_1, 'SortMsg', 101);

import StatsMsg;

Expand Down

0 comments on commit a565806

Please sign in to comment.