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 TestRemquo extends RSBaseCompute { 29 30 private ScriptC_TestRemquo script; 31 private ScriptC_TestRemquoRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestRemquo(mRS); 37 scriptRelaxed = new ScriptC_TestRemquoRelaxed(mRS); 38 } 39 40 @Override tearDown()41 protected void tearDown() throws Exception { 42 script.destroy(); 43 scriptRelaxed.destroy(); 44 super.tearDown(); 45 } 46 47 public class ArgumentsFloatFloatIntFloat { 48 public float inNumerator; 49 public float inDenominator; 50 public int outQuotient; 51 public float out; 52 } 53 checkRemquoFloatFloatIntFloat()54 private void checkRemquoFloatFloatIntFloat() { 55 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xcd5efc69edd4ff2al, false); 56 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x4ff0c9312eb19f93l, false); 57 try { 58 Allocation outQuotient = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE); 59 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 60 script.set_gAllocInDenominator(inDenominator); 61 script.set_gAllocOutQuotient(outQuotient); 62 script.forEach_testRemquoFloatFloatIntFloat(inNumerator, out); 63 verifyResultsRemquoFloatFloatIntFloat(inNumerator, inDenominator, outQuotient, out, false); 64 outQuotient.destroy(); 65 out.destroy(); 66 } catch (Exception e) { 67 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloatFloatIntFloat: " + e.toString()); 68 } 69 try { 70 Allocation outQuotient = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE); 71 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 72 scriptRelaxed.set_gAllocInDenominator(inDenominator); 73 scriptRelaxed.set_gAllocOutQuotient(outQuotient); 74 scriptRelaxed.forEach_testRemquoFloatFloatIntFloat(inNumerator, out); 75 verifyResultsRemquoFloatFloatIntFloat(inNumerator, inDenominator, outQuotient, out, true); 76 outQuotient.destroy(); 77 out.destroy(); 78 } catch (Exception e) { 79 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloatFloatIntFloat: " + e.toString()); 80 } 81 inNumerator.destroy(); 82 inDenominator.destroy(); 83 } 84 verifyResultsRemquoFloatFloatIntFloat(Allocation inNumerator, Allocation inDenominator, Allocation outQuotient, Allocation out, boolean relaxed)85 private void verifyResultsRemquoFloatFloatIntFloat(Allocation inNumerator, Allocation inDenominator, Allocation outQuotient, Allocation out, boolean relaxed) { 86 float[] arrayInNumerator = new float[INPUTSIZE * 1]; 87 Arrays.fill(arrayInNumerator, (float) 42); 88 inNumerator.copyTo(arrayInNumerator); 89 float[] arrayInDenominator = new float[INPUTSIZE * 1]; 90 Arrays.fill(arrayInDenominator, (float) 42); 91 inDenominator.copyTo(arrayInDenominator); 92 int[] arrayOutQuotient = new int[INPUTSIZE * 1]; 93 Arrays.fill(arrayOutQuotient, (int) 42); 94 outQuotient.copyTo(arrayOutQuotient); 95 float[] arrayOut = new float[INPUTSIZE * 1]; 96 Arrays.fill(arrayOut, (float) 42); 97 out.copyTo(arrayOut); 98 StringBuilder message = new StringBuilder(); 99 boolean errorFound = false; 100 for (int i = 0; i < INPUTSIZE; i++) { 101 for (int j = 0; j < 1 ; j++) { 102 // Extract the inputs. 103 ArgumentsFloatFloatIntFloat args = new ArgumentsFloatFloatIntFloat(); 104 args.inNumerator = arrayInNumerator[i]; 105 args.inDenominator = arrayInDenominator[i]; 106 // Extract the outputs. 107 args.outQuotient = arrayOutQuotient[i * 1 + j]; 108 args.out = arrayOut[i * 1 + j]; 109 // Ask the CoreMathVerifier to validate. 110 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 111 String errorMessage = CoreMathVerifier.verifyRemquo(args, target); 112 boolean valid = errorMessage == null; 113 if (!valid) { 114 if (!errorFound) { 115 errorFound = true; 116 message.append("Input inNumerator: "); 117 appendVariableToMessage(message, args.inNumerator); 118 message.append("\n"); 119 message.append("Input inDenominator: "); 120 appendVariableToMessage(message, args.inDenominator); 121 message.append("\n"); 122 message.append("Output outQuotient: "); 123 appendVariableToMessage(message, args.outQuotient); 124 message.append("\n"); 125 message.append("Output out: "); 126 appendVariableToMessage(message, args.out); 127 message.append("\n"); 128 message.append(errorMessage); 129 message.append("Errors at"); 130 } 131 message.append(" ["); 132 message.append(Integer.toString(i)); 133 message.append(", "); 134 message.append(Integer.toString(j)); 135 message.append("]"); 136 } 137 } 138 } 139 assertFalse("Incorrect output for checkRemquoFloatFloatIntFloat" + 140 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 141 } 142 checkRemquoFloat2Float2Int2Float2()143 private void checkRemquoFloat2Float2Int2Float2() { 144 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x28c14abc3a27171al, false); 145 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x58f8799a6ba08403l, false); 146 try { 147 Allocation outQuotient = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 148 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 149 script.set_gAllocInDenominator(inDenominator); 150 script.set_gAllocOutQuotient(outQuotient); 151 script.forEach_testRemquoFloat2Float2Int2Float2(inNumerator, out); 152 verifyResultsRemquoFloat2Float2Int2Float2(inNumerator, inDenominator, outQuotient, out, false); 153 outQuotient.destroy(); 154 out.destroy(); 155 } catch (Exception e) { 156 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat2Float2Int2Float2: " + e.toString()); 157 } 158 try { 159 Allocation outQuotient = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 160 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 161 scriptRelaxed.set_gAllocInDenominator(inDenominator); 162 scriptRelaxed.set_gAllocOutQuotient(outQuotient); 163 scriptRelaxed.forEach_testRemquoFloat2Float2Int2Float2(inNumerator, out); 164 verifyResultsRemquoFloat2Float2Int2Float2(inNumerator, inDenominator, outQuotient, out, true); 165 outQuotient.destroy(); 166 out.destroy(); 167 } catch (Exception e) { 168 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat2Float2Int2Float2: " + e.toString()); 169 } 170 inNumerator.destroy(); 171 inDenominator.destroy(); 172 } 173 verifyResultsRemquoFloat2Float2Int2Float2(Allocation inNumerator, Allocation inDenominator, Allocation outQuotient, Allocation out, boolean relaxed)174 private void verifyResultsRemquoFloat2Float2Int2Float2(Allocation inNumerator, Allocation inDenominator, Allocation outQuotient, Allocation out, boolean relaxed) { 175 float[] arrayInNumerator = new float[INPUTSIZE * 2]; 176 Arrays.fill(arrayInNumerator, (float) 42); 177 inNumerator.copyTo(arrayInNumerator); 178 float[] arrayInDenominator = new float[INPUTSIZE * 2]; 179 Arrays.fill(arrayInDenominator, (float) 42); 180 inDenominator.copyTo(arrayInDenominator); 181 int[] arrayOutQuotient = new int[INPUTSIZE * 2]; 182 Arrays.fill(arrayOutQuotient, (int) 42); 183 outQuotient.copyTo(arrayOutQuotient); 184 float[] arrayOut = new float[INPUTSIZE * 2]; 185 Arrays.fill(arrayOut, (float) 42); 186 out.copyTo(arrayOut); 187 StringBuilder message = new StringBuilder(); 188 boolean errorFound = false; 189 for (int i = 0; i < INPUTSIZE; i++) { 190 for (int j = 0; j < 2 ; j++) { 191 // Extract the inputs. 192 ArgumentsFloatFloatIntFloat args = new ArgumentsFloatFloatIntFloat(); 193 args.inNumerator = arrayInNumerator[i * 2 + j]; 194 args.inDenominator = arrayInDenominator[i * 2 + j]; 195 // Extract the outputs. 196 args.outQuotient = arrayOutQuotient[i * 2 + j]; 197 args.out = arrayOut[i * 2 + j]; 198 // Ask the CoreMathVerifier to validate. 199 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 200 String errorMessage = CoreMathVerifier.verifyRemquo(args, target); 201 boolean valid = errorMessage == null; 202 if (!valid) { 203 if (!errorFound) { 204 errorFound = true; 205 message.append("Input inNumerator: "); 206 appendVariableToMessage(message, args.inNumerator); 207 message.append("\n"); 208 message.append("Input inDenominator: "); 209 appendVariableToMessage(message, args.inDenominator); 210 message.append("\n"); 211 message.append("Output outQuotient: "); 212 appendVariableToMessage(message, args.outQuotient); 213 message.append("\n"); 214 message.append("Output out: "); 215 appendVariableToMessage(message, args.out); 216 message.append("\n"); 217 message.append(errorMessage); 218 message.append("Errors at"); 219 } 220 message.append(" ["); 221 message.append(Integer.toString(i)); 222 message.append(", "); 223 message.append(Integer.toString(j)); 224 message.append("]"); 225 } 226 } 227 } 228 assertFalse("Incorrect output for checkRemquoFloat2Float2Int2Float2" + 229 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 230 } 231 checkRemquoFloat3Float3Int3Float3()232 private void checkRemquoFloat3Float3Int3Float3() { 233 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xf60211df96052526l, false); 234 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xd1d6c7fcf273f8afl, false); 235 try { 236 Allocation outQuotient = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 237 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 238 script.set_gAllocInDenominator(inDenominator); 239 script.set_gAllocOutQuotient(outQuotient); 240 script.forEach_testRemquoFloat3Float3Int3Float3(inNumerator, out); 241 verifyResultsRemquoFloat3Float3Int3Float3(inNumerator, inDenominator, outQuotient, out, false); 242 outQuotient.destroy(); 243 out.destroy(); 244 } catch (Exception e) { 245 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat3Float3Int3Float3: " + e.toString()); 246 } 247 try { 248 Allocation outQuotient = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 249 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 250 scriptRelaxed.set_gAllocInDenominator(inDenominator); 251 scriptRelaxed.set_gAllocOutQuotient(outQuotient); 252 scriptRelaxed.forEach_testRemquoFloat3Float3Int3Float3(inNumerator, out); 253 verifyResultsRemquoFloat3Float3Int3Float3(inNumerator, inDenominator, outQuotient, out, true); 254 outQuotient.destroy(); 255 out.destroy(); 256 } catch (Exception e) { 257 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat3Float3Int3Float3: " + e.toString()); 258 } 259 inNumerator.destroy(); 260 inDenominator.destroy(); 261 } 262 verifyResultsRemquoFloat3Float3Int3Float3(Allocation inNumerator, Allocation inDenominator, Allocation outQuotient, Allocation out, boolean relaxed)263 private void verifyResultsRemquoFloat3Float3Int3Float3(Allocation inNumerator, Allocation inDenominator, Allocation outQuotient, Allocation out, boolean relaxed) { 264 float[] arrayInNumerator = new float[INPUTSIZE * 4]; 265 Arrays.fill(arrayInNumerator, (float) 42); 266 inNumerator.copyTo(arrayInNumerator); 267 float[] arrayInDenominator = new float[INPUTSIZE * 4]; 268 Arrays.fill(arrayInDenominator, (float) 42); 269 inDenominator.copyTo(arrayInDenominator); 270 int[] arrayOutQuotient = new int[INPUTSIZE * 4]; 271 Arrays.fill(arrayOutQuotient, (int) 42); 272 outQuotient.copyTo(arrayOutQuotient); 273 float[] arrayOut = new float[INPUTSIZE * 4]; 274 Arrays.fill(arrayOut, (float) 42); 275 out.copyTo(arrayOut); 276 StringBuilder message = new StringBuilder(); 277 boolean errorFound = false; 278 for (int i = 0; i < INPUTSIZE; i++) { 279 for (int j = 0; j < 3 ; j++) { 280 // Extract the inputs. 281 ArgumentsFloatFloatIntFloat args = new ArgumentsFloatFloatIntFloat(); 282 args.inNumerator = arrayInNumerator[i * 4 + j]; 283 args.inDenominator = arrayInDenominator[i * 4 + j]; 284 // Extract the outputs. 285 args.outQuotient = arrayOutQuotient[i * 4 + j]; 286 args.out = arrayOut[i * 4 + j]; 287 // Ask the CoreMathVerifier to validate. 288 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 289 String errorMessage = CoreMathVerifier.verifyRemquo(args, target); 290 boolean valid = errorMessage == null; 291 if (!valid) { 292 if (!errorFound) { 293 errorFound = true; 294 message.append("Input inNumerator: "); 295 appendVariableToMessage(message, args.inNumerator); 296 message.append("\n"); 297 message.append("Input inDenominator: "); 298 appendVariableToMessage(message, args.inDenominator); 299 message.append("\n"); 300 message.append("Output outQuotient: "); 301 appendVariableToMessage(message, args.outQuotient); 302 message.append("\n"); 303 message.append("Output out: "); 304 appendVariableToMessage(message, args.out); 305 message.append("\n"); 306 message.append(errorMessage); 307 message.append("Errors at"); 308 } 309 message.append(" ["); 310 message.append(Integer.toString(i)); 311 message.append(", "); 312 message.append(Integer.toString(j)); 313 message.append("]"); 314 } 315 } 316 } 317 assertFalse("Incorrect output for checkRemquoFloat3Float3Int3Float3" + 318 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 319 } 320 checkRemquoFloat4Float4Int4Float4()321 private void checkRemquoFloat4Float4Int4Float4() { 322 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xc342d902f1e33332l, false); 323 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x4ab5165f79476d5bl, false); 324 try { 325 Allocation outQuotient = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 326 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 327 script.set_gAllocInDenominator(inDenominator); 328 script.set_gAllocOutQuotient(outQuotient); 329 script.forEach_testRemquoFloat4Float4Int4Float4(inNumerator, out); 330 verifyResultsRemquoFloat4Float4Int4Float4(inNumerator, inDenominator, outQuotient, out, false); 331 outQuotient.destroy(); 332 out.destroy(); 333 } catch (Exception e) { 334 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat4Float4Int4Float4: " + e.toString()); 335 } 336 try { 337 Allocation outQuotient = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 338 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 339 scriptRelaxed.set_gAllocInDenominator(inDenominator); 340 scriptRelaxed.set_gAllocOutQuotient(outQuotient); 341 scriptRelaxed.forEach_testRemquoFloat4Float4Int4Float4(inNumerator, out); 342 verifyResultsRemquoFloat4Float4Int4Float4(inNumerator, inDenominator, outQuotient, out, true); 343 outQuotient.destroy(); 344 out.destroy(); 345 } catch (Exception e) { 346 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testRemquoFloat4Float4Int4Float4: " + e.toString()); 347 } 348 inNumerator.destroy(); 349 inDenominator.destroy(); 350 } 351 verifyResultsRemquoFloat4Float4Int4Float4(Allocation inNumerator, Allocation inDenominator, Allocation outQuotient, Allocation out, boolean relaxed)352 private void verifyResultsRemquoFloat4Float4Int4Float4(Allocation inNumerator, Allocation inDenominator, Allocation outQuotient, Allocation out, boolean relaxed) { 353 float[] arrayInNumerator = new float[INPUTSIZE * 4]; 354 Arrays.fill(arrayInNumerator, (float) 42); 355 inNumerator.copyTo(arrayInNumerator); 356 float[] arrayInDenominator = new float[INPUTSIZE * 4]; 357 Arrays.fill(arrayInDenominator, (float) 42); 358 inDenominator.copyTo(arrayInDenominator); 359 int[] arrayOutQuotient = new int[INPUTSIZE * 4]; 360 Arrays.fill(arrayOutQuotient, (int) 42); 361 outQuotient.copyTo(arrayOutQuotient); 362 float[] arrayOut = new float[INPUTSIZE * 4]; 363 Arrays.fill(arrayOut, (float) 42); 364 out.copyTo(arrayOut); 365 StringBuilder message = new StringBuilder(); 366 boolean errorFound = false; 367 for (int i = 0; i < INPUTSIZE; i++) { 368 for (int j = 0; j < 4 ; j++) { 369 // Extract the inputs. 370 ArgumentsFloatFloatIntFloat args = new ArgumentsFloatFloatIntFloat(); 371 args.inNumerator = arrayInNumerator[i * 4 + j]; 372 args.inDenominator = arrayInDenominator[i * 4 + j]; 373 // Extract the outputs. 374 args.outQuotient = arrayOutQuotient[i * 4 + j]; 375 args.out = arrayOut[i * 4 + j]; 376 // Ask the CoreMathVerifier to validate. 377 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 378 String errorMessage = CoreMathVerifier.verifyRemquo(args, target); 379 boolean valid = errorMessage == null; 380 if (!valid) { 381 if (!errorFound) { 382 errorFound = true; 383 message.append("Input inNumerator: "); 384 appendVariableToMessage(message, args.inNumerator); 385 message.append("\n"); 386 message.append("Input inDenominator: "); 387 appendVariableToMessage(message, args.inDenominator); 388 message.append("\n"); 389 message.append("Output outQuotient: "); 390 appendVariableToMessage(message, args.outQuotient); 391 message.append("\n"); 392 message.append("Output out: "); 393 appendVariableToMessage(message, args.out); 394 message.append("\n"); 395 message.append(errorMessage); 396 message.append("Errors at"); 397 } 398 message.append(" ["); 399 message.append(Integer.toString(i)); 400 message.append(", "); 401 message.append(Integer.toString(j)); 402 message.append("]"); 403 } 404 } 405 } 406 assertFalse("Incorrect output for checkRemquoFloat4Float4Int4Float4" + 407 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 408 } 409 testRemquo()410 public void testRemquo() { 411 checkRemquoFloatFloatIntFloat(); 412 checkRemquoFloat2Float2Int2Float2(); 413 checkRemquoFloat3Float3Int3Float3(); 414 checkRemquoFloat4Float4Int4Float4(); 415 } 416 } 417