1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh. 18 19 package android.renderscript.cts; 20 21 import android.renderscript.Allocation; 22 import android.renderscript.RSRuntimeException; 23 import android.renderscript.Element; 24 import android.renderscript.cts.Target; 25 26 import java.util.Arrays; 27 28 public class TestCross extends RSBaseCompute { 29 30 private ScriptC_TestCross script; 31 private ScriptC_TestCrossRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestCross(mRS); 37 scriptRelaxed = new ScriptC_TestCrossRelaxed(mRS); 38 } 39 40 public class ArgumentsFloatNFloatNFloatN { 41 public float[] inLeftVector; 42 public float[] inRightVector; 43 public Target.Floaty[] out; 44 } 45 checkCrossFloat3Float3Float3()46 private void checkCrossFloat3Float3Float3() { 47 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x382f1ad4l, false); 48 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xde024b21l, false); 49 try { 50 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 51 script.set_gAllocInRightVector(inRightVector); 52 script.forEach_testCrossFloat3Float3Float3(inLeftVector, out); 53 verifyResultsCrossFloat3Float3Float3(inLeftVector, inRightVector, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat3Float3Float3: " + e.toString()); 56 } 57 try { 58 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 59 scriptRelaxed.set_gAllocInRightVector(inRightVector); 60 scriptRelaxed.forEach_testCrossFloat3Float3Float3(inLeftVector, out); 61 verifyResultsCrossFloat3Float3Float3(inLeftVector, inRightVector, out, true); 62 } catch (Exception e) { 63 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat3Float3Float3: " + e.toString()); 64 } 65 } 66 verifyResultsCrossFloat3Float3Float3(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)67 private void verifyResultsCrossFloat3Float3Float3(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 68 float[] arrayInLeftVector = new float[INPUTSIZE * 4]; 69 Arrays.fill(arrayInLeftVector, (float) 42); 70 inLeftVector.copyTo(arrayInLeftVector); 71 float[] arrayInRightVector = new float[INPUTSIZE * 4]; 72 Arrays.fill(arrayInRightVector, (float) 42); 73 inRightVector.copyTo(arrayInRightVector); 74 float[] arrayOut = new float[INPUTSIZE * 4]; 75 Arrays.fill(arrayOut, (float) 42); 76 out.copyTo(arrayOut); 77 StringBuilder message = new StringBuilder(); 78 boolean errorFound = false; 79 for (int i = 0; i < INPUTSIZE; i++) { 80 ArgumentsFloatNFloatNFloatN args = new ArgumentsFloatNFloatNFloatN(); 81 // Create the appropriate sized arrays in args 82 args.inLeftVector = new float[3]; 83 args.inRightVector = new float[3]; 84 args.out = new Target.Floaty[3]; 85 // Fill args with the input values 86 for (int j = 0; j < 3 ; j++) { 87 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 88 } 89 for (int j = 0; j < 3 ; j++) { 90 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 91 } 92 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 93 CoreMathVerifier.computeCross(args, target); 94 95 // Compare the expected outputs to the actual values returned by RS. 96 boolean valid = true; 97 for (int j = 0; j < 3 ; j++) { 98 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) { 99 valid = false; 100 } 101 } 102 if (!valid) { 103 if (!errorFound) { 104 errorFound = true; 105 for (int j = 0; j < 3 ; j++) { 106 message.append("Input inLeftVector: "); 107 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 108 message.append("\n"); 109 } 110 for (int j = 0; j < 3 ; j++) { 111 message.append("Input inRightVector: "); 112 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 113 message.append("\n"); 114 } 115 for (int j = 0; j < 3 ; j++) { 116 message.append("Expected output out: "); 117 appendVariableToMessage(message, args.out[j]); 118 message.append("\n"); 119 message.append("Actual output out: "); 120 appendVariableToMessage(message, arrayOut[i * 4 + j]); 121 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) { 122 message.append(" FAIL"); 123 } 124 message.append("\n"); 125 } 126 message.append("Errors at"); 127 } 128 message.append(" ["); 129 message.append(Integer.toString(i)); 130 message.append("]"); 131 } 132 } 133 assertFalse("Incorrect output for checkCrossFloat3Float3Float3" + 134 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 135 } 136 checkCrossFloat4Float4Float4()137 private void checkCrossFloat4Float4Float4() { 138 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x906fbeffl, false); 139 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xb0ddde5al, false); 140 try { 141 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 142 script.set_gAllocInRightVector(inRightVector); 143 script.forEach_testCrossFloat4Float4Float4(inLeftVector, out); 144 verifyResultsCrossFloat4Float4Float4(inLeftVector, inRightVector, out, false); 145 } catch (Exception e) { 146 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat4Float4Float4: " + e.toString()); 147 } 148 try { 149 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 150 scriptRelaxed.set_gAllocInRightVector(inRightVector); 151 scriptRelaxed.forEach_testCrossFloat4Float4Float4(inLeftVector, out); 152 verifyResultsCrossFloat4Float4Float4(inLeftVector, inRightVector, out, true); 153 } catch (Exception e) { 154 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat4Float4Float4: " + e.toString()); 155 } 156 } 157 verifyResultsCrossFloat4Float4Float4(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)158 private void verifyResultsCrossFloat4Float4Float4(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 159 float[] arrayInLeftVector = new float[INPUTSIZE * 4]; 160 Arrays.fill(arrayInLeftVector, (float) 42); 161 inLeftVector.copyTo(arrayInLeftVector); 162 float[] arrayInRightVector = new float[INPUTSIZE * 4]; 163 Arrays.fill(arrayInRightVector, (float) 42); 164 inRightVector.copyTo(arrayInRightVector); 165 float[] arrayOut = new float[INPUTSIZE * 4]; 166 Arrays.fill(arrayOut, (float) 42); 167 out.copyTo(arrayOut); 168 StringBuilder message = new StringBuilder(); 169 boolean errorFound = false; 170 for (int i = 0; i < INPUTSIZE; i++) { 171 ArgumentsFloatNFloatNFloatN args = new ArgumentsFloatNFloatNFloatN(); 172 // Create the appropriate sized arrays in args 173 args.inLeftVector = new float[4]; 174 args.inRightVector = new float[4]; 175 args.out = new Target.Floaty[4]; 176 // Fill args with the input values 177 for (int j = 0; j < 4 ; j++) { 178 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 179 } 180 for (int j = 0; j < 4 ; j++) { 181 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 182 } 183 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 184 CoreMathVerifier.computeCross(args, target); 185 186 // Compare the expected outputs to the actual values returned by RS. 187 boolean valid = true; 188 for (int j = 0; j < 4 ; j++) { 189 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) { 190 valid = false; 191 } 192 } 193 if (!valid) { 194 if (!errorFound) { 195 errorFound = true; 196 for (int j = 0; j < 4 ; j++) { 197 message.append("Input inLeftVector: "); 198 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 199 message.append("\n"); 200 } 201 for (int j = 0; j < 4 ; j++) { 202 message.append("Input inRightVector: "); 203 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 204 message.append("\n"); 205 } 206 for (int j = 0; j < 4 ; j++) { 207 message.append("Expected output out: "); 208 appendVariableToMessage(message, args.out[j]); 209 message.append("\n"); 210 message.append("Actual output out: "); 211 appendVariableToMessage(message, arrayOut[i * 4 + j]); 212 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) { 213 message.append(" FAIL"); 214 } 215 message.append("\n"); 216 } 217 message.append("Errors at"); 218 } 219 message.append(" ["); 220 message.append(Integer.toString(i)); 221 message.append("]"); 222 } 223 } 224 assertFalse("Incorrect output for checkCrossFloat4Float4Float4" + 225 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 226 } 227 228 public class ArgumentsHalfNHalfNHalfN { 229 public short[] inLeftVector; 230 public double[] inLeftVectorDouble; 231 public short[] inRightVector; 232 public double[] inRightVectorDouble; 233 public Target.Floaty[] out; 234 } 235 checkCrossHalf3Half3Half3()236 private void checkCrossHalf3Half3Half3() { 237 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xfc3afdafl, false); 238 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xcc0165eal, false); 239 try { 240 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 241 script.set_gAllocInRightVector(inRightVector); 242 script.forEach_testCrossHalf3Half3Half3(inLeftVector, out); 243 verifyResultsCrossHalf3Half3Half3(inLeftVector, inRightVector, out, false); 244 } catch (Exception e) { 245 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossHalf3Half3Half3: " + e.toString()); 246 } 247 try { 248 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 249 scriptRelaxed.set_gAllocInRightVector(inRightVector); 250 scriptRelaxed.forEach_testCrossHalf3Half3Half3(inLeftVector, out); 251 verifyResultsCrossHalf3Half3Half3(inLeftVector, inRightVector, out, true); 252 } catch (Exception e) { 253 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossHalf3Half3Half3: " + e.toString()); 254 } 255 } 256 verifyResultsCrossHalf3Half3Half3(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)257 private void verifyResultsCrossHalf3Half3Half3(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 258 short[] arrayInLeftVector = new short[INPUTSIZE * 4]; 259 Arrays.fill(arrayInLeftVector, (short) 42); 260 inLeftVector.copyTo(arrayInLeftVector); 261 short[] arrayInRightVector = new short[INPUTSIZE * 4]; 262 Arrays.fill(arrayInRightVector, (short) 42); 263 inRightVector.copyTo(arrayInRightVector); 264 short[] arrayOut = new short[INPUTSIZE * 4]; 265 Arrays.fill(arrayOut, (short) 42); 266 out.copyTo(arrayOut); 267 StringBuilder message = new StringBuilder(); 268 boolean errorFound = false; 269 for (int i = 0; i < INPUTSIZE; i++) { 270 ArgumentsHalfNHalfNHalfN args = new ArgumentsHalfNHalfNHalfN(); 271 // Create the appropriate sized arrays in args 272 args.inLeftVector = new short[3]; 273 args.inLeftVectorDouble = new double[3]; 274 args.inRightVector = new short[3]; 275 args.inRightVectorDouble = new double[3]; 276 args.out = new Target.Floaty[3]; 277 // Fill args with the input values 278 for (int j = 0; j < 3 ; j++) { 279 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 280 args.inLeftVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inLeftVector[j]); 281 } 282 for (int j = 0; j < 3 ; j++) { 283 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 284 args.inRightVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inRightVector[j]); 285 } 286 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 287 CoreMathVerifier.computeCross(args, target); 288 289 // Compare the expected outputs to the actual values returned by RS. 290 boolean valid = true; 291 for (int j = 0; j < 3 ; j++) { 292 if (!args.out[j].couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 293 valid = false; 294 } 295 } 296 if (!valid) { 297 if (!errorFound) { 298 errorFound = true; 299 for (int j = 0; j < 3 ; j++) { 300 message.append("Input inLeftVector: "); 301 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 302 message.append("\n"); 303 } 304 for (int j = 0; j < 3 ; j++) { 305 message.append("Input inRightVector: "); 306 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 307 message.append("\n"); 308 } 309 for (int j = 0; j < 3 ; j++) { 310 message.append("Expected output out: "); 311 appendVariableToMessage(message, args.out[j]); 312 message.append("\n"); 313 message.append("Actual output out: "); 314 appendVariableToMessage(message, arrayOut[i * 4 + j]); 315 message.append("\n"); 316 message.append("Actual output out (in double): "); 317 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 318 if (!args.out[j].couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 319 message.append(" FAIL"); 320 } 321 message.append("\n"); 322 } 323 message.append("Errors at"); 324 } 325 message.append(" ["); 326 message.append(Integer.toString(i)); 327 message.append("]"); 328 } 329 } 330 assertFalse("Incorrect output for checkCrossHalf3Half3Half3" + 331 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 332 } 333 checkCrossHalf4Half4Half4()334 private void checkCrossHalf4Half4Half4() { 335 Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xa8692054l, false); 336 Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xb7c137a1l, false); 337 try { 338 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 339 script.set_gAllocInRightVector(inRightVector); 340 script.forEach_testCrossHalf4Half4Half4(inLeftVector, out); 341 verifyResultsCrossHalf4Half4Half4(inLeftVector, inRightVector, out, false); 342 } catch (Exception e) { 343 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossHalf4Half4Half4: " + e.toString()); 344 } 345 try { 346 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 347 scriptRelaxed.set_gAllocInRightVector(inRightVector); 348 scriptRelaxed.forEach_testCrossHalf4Half4Half4(inLeftVector, out); 349 verifyResultsCrossHalf4Half4Half4(inLeftVector, inRightVector, out, true); 350 } catch (Exception e) { 351 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossHalf4Half4Half4: " + e.toString()); 352 } 353 } 354 verifyResultsCrossHalf4Half4Half4(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed)355 private void verifyResultsCrossHalf4Half4Half4(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { 356 short[] arrayInLeftVector = new short[INPUTSIZE * 4]; 357 Arrays.fill(arrayInLeftVector, (short) 42); 358 inLeftVector.copyTo(arrayInLeftVector); 359 short[] arrayInRightVector = new short[INPUTSIZE * 4]; 360 Arrays.fill(arrayInRightVector, (short) 42); 361 inRightVector.copyTo(arrayInRightVector); 362 short[] arrayOut = new short[INPUTSIZE * 4]; 363 Arrays.fill(arrayOut, (short) 42); 364 out.copyTo(arrayOut); 365 StringBuilder message = new StringBuilder(); 366 boolean errorFound = false; 367 for (int i = 0; i < INPUTSIZE; i++) { 368 ArgumentsHalfNHalfNHalfN args = new ArgumentsHalfNHalfNHalfN(); 369 // Create the appropriate sized arrays in args 370 args.inLeftVector = new short[4]; 371 args.inLeftVectorDouble = new double[4]; 372 args.inRightVector = new short[4]; 373 args.inRightVectorDouble = new double[4]; 374 args.out = new Target.Floaty[4]; 375 // Fill args with the input values 376 for (int j = 0; j < 4 ; j++) { 377 args.inLeftVector[j] = arrayInLeftVector[i * 4 + j]; 378 args.inLeftVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inLeftVector[j]); 379 } 380 for (int j = 0; j < 4 ; j++) { 381 args.inRightVector[j] = arrayInRightVector[i * 4 + j]; 382 args.inRightVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inRightVector[j]); 383 } 384 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 385 CoreMathVerifier.computeCross(args, target); 386 387 // Compare the expected outputs to the actual values returned by RS. 388 boolean valid = true; 389 for (int j = 0; j < 4 ; j++) { 390 if (!args.out[j].couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 391 valid = false; 392 } 393 } 394 if (!valid) { 395 if (!errorFound) { 396 errorFound = true; 397 for (int j = 0; j < 4 ; j++) { 398 message.append("Input inLeftVector: "); 399 appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]); 400 message.append("\n"); 401 } 402 for (int j = 0; j < 4 ; j++) { 403 message.append("Input inRightVector: "); 404 appendVariableToMessage(message, arrayInRightVector[i * 4 + j]); 405 message.append("\n"); 406 } 407 for (int j = 0; j < 4 ; j++) { 408 message.append("Expected output out: "); 409 appendVariableToMessage(message, args.out[j]); 410 message.append("\n"); 411 message.append("Actual output out: "); 412 appendVariableToMessage(message, arrayOut[i * 4 + j]); 413 message.append("\n"); 414 message.append("Actual output out (in double): "); 415 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 416 if (!args.out[j].couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 417 message.append(" FAIL"); 418 } 419 message.append("\n"); 420 } 421 message.append("Errors at"); 422 } 423 message.append(" ["); 424 message.append(Integer.toString(i)); 425 message.append("]"); 426 } 427 } 428 assertFalse("Incorrect output for checkCrossHalf4Half4Half4" + 429 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 430 } 431 testCross()432 public void testCross() { 433 checkCrossFloat3Float3Float3(); 434 checkCrossFloat4Float4Float4(); 435 checkCrossHalf3Half3Half3(); 436 checkCrossHalf4Half4Half4(); 437 } 438 } 439