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