@@ -1057,13 +1057,39 @@ inline proc ndarray.hardswish() {
10571057 const dom = this .domain ;
10581058 var rl = new ndarray(dom, eltType);
10591059 ref rld = rl.data;
1060+
10601061 forall i in dom.every() {
10611062 const x = thisData[ i] ;
10621063 const floatMax: eltType = Types.max (eltType);
1063- const xgeq3: eltType = Math.ceil(1.0 / floatMax); // x >= 3: 1 if true, 0 otherwise
1064- const xleqn3: eltType = Math.ceil(1.0 / floatMax); // x <= -3: 1 if true, 0 otherwise
1065- rld[ i] = x * xgeq3 + x * (x + 3 ) / 6.0 * (1 - xgeq3) * xleqn3;
1064+ const xgeq3: eltType = Math.ceil((x - 3.0 ) / floatMax); // x >= 3: 1 if true, 0 otherwise
1065+ const xleqn3: eltType = Math.ceil(( - x - 3.0 ) / floatMax); // x <= -3: 1 if true, 0 otherwise
1066+ rld[ i] = x * xgeq3 + x * (x + 3 ) / 6.0 * (1 - xgeq3) * ( 1 - xleqn3) ;
10661067 }
1068+
1069+ // use CTypes only c_sizeof, c_ptrTo;
1070+ // use OS.POSIX only memcpy;
1071+
1072+ // type intType = int(numBits(eltType)); // integer w/ same #ofbits as real
1073+ // forall i in dom.every() {
1074+ // const x = thisData[i]; // negative x
1075+ // const threshold: eltType = 20.0;
1076+
1077+ // var func: eltType = ; // result after applying hardswish(x) activation function
1078+ // var lin: eltType = x;
1079+
1080+ // var func_bits: intType;
1081+ // var lin_bits: intType;
1082+ // memcpy(c_ptrTo(func_bits), c_ptrTo(func), c_sizeof(eltType));
1083+ // memcpy(c_ptrTo(lin_bits), c_ptrTo(lin), c_sizeof(eltType));
1084+
1085+ // const condition: intType = (-x > threshold);
1086+ // const mask: intType = 0 - condition;
1087+
1088+ // var result_bits: intType = (mask & lin_bits) | (~mask & func_bits);
1089+
1090+ // // rld[i] = output;
1091+ // memcpy(c_ptrTo(rld[i]), c_ptrTo(result_bits), c_sizeof(eltType));
1092+ // }
10671093 return rl;
10681094}
10691095
@@ -1205,7 +1231,7 @@ inline proc ndarray.celu(alpha: eltType=1.0) {
12051231 return rl;
12061232}
12071233
1208- inline proc ndarray.leakyrelu(negativeSlope: eltType= Math.exp( - 2 ) ) {
1234+ inline proc ndarray.leakyrelu(negativeSlope: eltType= 0.01 ) {
12091235 const ref thisData = data;
12101236 const dom = this .domain ;
12111237 var rl = new ndarray(dom, eltType);
0 commit comments