253 254 interface FBinMaskOp { 255 $type$ apply($type$ a, $type$ b, boolean m); 256 257 static FBinMaskOp lift(FBinOp f) { 258 return (a, b, m) -> m ? f.apply(a, b) : a; 259 } 260 } 261 262 static void assertArraysEquals($type$[] a, $type$[] b, $type$[] r, FBinOp f) { 263 int i = 0; 264 try { 265 for (; i < a.length; i++) { 266 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 267 } 268 } catch (AssertionError e) { 269 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 270 } 271 } 272 273 static void assertArraysEquals($type$[] a, $type$[] b, $type$[] r, boolean[] mask, FBinOp f) { 274 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 275 } 276 277 static void assertArraysEquals($type$[] a, $type$[] b, $type$[] r, boolean[] mask, FBinMaskOp f) { 278 int i = 0; 279 try { 280 for (; i < a.length; i++) { 281 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 282 } 283 } catch (AssertionError err) { 284 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); 285 } 286 } 287 288 static void assertShiftArraysEquals($type$[] a, $type$[] b, $type$[] r, FBinOp f) { 289 int i = 0; 290 int j = 0; 291 try { 292 for (; j < a.length; j += SPECIES.length()) { 293 for (i = 0; i < SPECIES.length(); i++) { 294 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 295 } 296 } 297 } catch (AssertionError e) { 298 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 299 } 300 } 301 302 static void assertShiftArraysEquals($type$[] a, $type$[] b, $type$[] r, boolean[] mask, FBinOp f) { 303 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 304 } | 253 254 interface FBinMaskOp { 255 $type$ apply($type$ a, $type$ b, boolean m); 256 257 static FBinMaskOp lift(FBinOp f) { 258 return (a, b, m) -> m ? f.apply(a, b) : a; 259 } 260 } 261 262 static void assertArraysEquals($type$[] a, $type$[] b, $type$[] r, FBinOp f) { 263 int i = 0; 264 try { 265 for (; i < a.length; i++) { 266 Assert.assertEquals(r[i], f.apply(a[i], b[i])); 267 } 268 } catch (AssertionError e) { 269 Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i); 270 } 271 } 272 273 static void assertBroadcastArraysEquals($type$[] a, $type$[] b, $type$[] r, FBinOp f) { 274 int i = 0; 275 try { 276 for (; i < a.length; i++) { 277 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()])); 278 } 279 } catch (AssertionError e) { 280 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), 281 "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i); 282 } 283 } 284 285 static void assertArraysEquals($type$[] a, $type$[] b, $type$[] r, boolean[] mask, FBinOp f) { 286 assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 287 } 288 289 static void assertArraysEquals($type$[] a, $type$[] b, $type$[] r, boolean[] mask, FBinMaskOp f) { 290 int i = 0; 291 try { 292 for (; i < a.length; i++) { 293 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); 294 } 295 } catch (AssertionError err) { 296 Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); 297 } 298 } 299 300 static void assertBroadcastArraysEquals($type$[] a, $type$[] b, $type$[] r, boolean[] mask, FBinOp f) { 301 assertBroadcastArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 302 } 303 304 static void assertBroadcastArraysEquals($type$[] a, $type$[] b, $type$[] r, boolean[] mask, FBinMaskOp f) { 305 int i = 0; 306 try { 307 for (; i < a.length; i++) { 308 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], mask[i % SPECIES.length()])); 309 } 310 } catch (AssertionError err) { 311 Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()], 312 mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + 313 ", input2 = " + b[(i / SPECIES.length()) * SPECIES.length()] + ", mask = " + 314 mask[i % SPECIES.length()]); 315 } 316 } 317 318 static void assertShiftArraysEquals($type$[] a, $type$[] b, $type$[] r, FBinOp f) { 319 int i = 0; 320 int j = 0; 321 try { 322 for (; j < a.length; j += SPECIES.length()) { 323 for (i = 0; i < SPECIES.length(); i++) { 324 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j])); 325 } 326 } 327 } catch (AssertionError e) { 328 Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j]), "at index #" + i + ", " + j); 329 } 330 } 331 332 static void assertShiftArraysEquals($type$[] a, $type$[] b, $type$[] r, boolean[] mask, FBinOp f) { 333 assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); 334 } |