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