1 /* 2 * Copyright (C) 2015 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 25 import java.util.Arrays; 26 27 public class TestNextafter extends RSBaseCompute { 28 29 private ScriptC_TestNextafter script; 30 private ScriptC_TestNextafterRelaxed scriptRelaxed; 31 32 @Override 33 protected void setUp() throws Exception { 34 super.setUp(); 35 script = new ScriptC_TestNextafter(mRS); 36 scriptRelaxed = new ScriptC_TestNextafterRelaxed(mRS); 37 } 38 39 public class ArgumentsFloatFloatFloat { 40 public float inV; 41 public float inTarget; 42 public Target.Floaty out; 43 } 44 45 private void checkNextafterFloatFloatFloat() { 46 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xad412956l, false); 47 Allocation inTarget = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xafd7c03dl, false); 48 try { 49 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 50 script.set_gAllocInTarget(inTarget); 51 script.forEach_testNextafterFloatFloatFloat(inV, out); 52 verifyResultsNextafterFloatFloatFloat(inV, inTarget, out, false); 53 } catch (Exception e) { 54 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNextafterFloatFloatFloat: " + e.toString()); 55 } 56 try { 57 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 58 scriptRelaxed.set_gAllocInTarget(inTarget); 59 scriptRelaxed.forEach_testNextafterFloatFloatFloat(inV, out); 60 verifyResultsNextafterFloatFloatFloat(inV, inTarget, out, true); 61 } catch (Exception e) { 62 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNextafterFloatFloatFloat: " + e.toString()); 63 } 64 } 65 66 private void verifyResultsNextafterFloatFloatFloat(Allocation inV, Allocation inTarget, Allocation out, boolean relaxed) { 67 float[] arrayInV = new float[INPUTSIZE * 1]; 68 Arrays.fill(arrayInV, (float) 42); 69 inV.copyTo(arrayInV); 70 float[] arrayInTarget = new float[INPUTSIZE * 1]; 71 Arrays.fill(arrayInTarget, (float) 42); 72 inTarget.copyTo(arrayInTarget); 73 float[] arrayOut = new float[INPUTSIZE * 1]; 74 Arrays.fill(arrayOut, (float) 42); 75 out.copyTo(arrayOut); 76 StringBuilder message = new StringBuilder(); 77 boolean errorFound = false; 78 for (int i = 0; i < INPUTSIZE; i++) { 79 for (int j = 0; j < 1 ; j++) { 80 // Extract the inputs. 81 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 82 args.inV = arrayInV[i]; 83 args.inTarget = arrayInTarget[i]; 84 // Figure out what the outputs should have been. 85 Target target = new Target(relaxed); 86 CoreMathVerifier.computeNextafter(args, target); 87 // Validate the outputs. 88 boolean valid = true; 89 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 90 valid = false; 91 } 92 if (!valid) { 93 if (!errorFound) { 94 errorFound = true; 95 message.append("Input inV: "); 96 appendVariableToMessage(message, args.inV); 97 message.append("\n"); 98 message.append("Input inTarget: "); 99 appendVariableToMessage(message, args.inTarget); 100 message.append("\n"); 101 message.append("Expected output out: "); 102 appendVariableToMessage(message, args.out); 103 message.append("\n"); 104 message.append("Actual output out: "); 105 appendVariableToMessage(message, arrayOut[i * 1 + j]); 106 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 107 message.append(" FAIL"); 108 } 109 message.append("\n"); 110 message.append("Errors at"); 111 } 112 message.append(" ["); 113 message.append(Integer.toString(i)); 114 message.append(", "); 115 message.append(Integer.toString(j)); 116 message.append("]"); 117 } 118 } 119 } 120 assertFalse("Incorrect output for checkNextafterFloatFloatFloat" + 121 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 122 } 123 124 private void checkNextafterFloat2Float2Float2() { 125 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x584a1e22l, false); 126 Allocation inTarget = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xf7e4d541l, false); 127 try { 128 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 129 script.set_gAllocInTarget(inTarget); 130 script.forEach_testNextafterFloat2Float2Float2(inV, out); 131 verifyResultsNextafterFloat2Float2Float2(inV, inTarget, out, false); 132 } catch (Exception e) { 133 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNextafterFloat2Float2Float2: " + e.toString()); 134 } 135 try { 136 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 137 scriptRelaxed.set_gAllocInTarget(inTarget); 138 scriptRelaxed.forEach_testNextafterFloat2Float2Float2(inV, out); 139 verifyResultsNextafterFloat2Float2Float2(inV, inTarget, out, true); 140 } catch (Exception e) { 141 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNextafterFloat2Float2Float2: " + e.toString()); 142 } 143 } 144 145 private void verifyResultsNextafterFloat2Float2Float2(Allocation inV, Allocation inTarget, Allocation out, boolean relaxed) { 146 float[] arrayInV = new float[INPUTSIZE * 2]; 147 Arrays.fill(arrayInV, (float) 42); 148 inV.copyTo(arrayInV); 149 float[] arrayInTarget = new float[INPUTSIZE * 2]; 150 Arrays.fill(arrayInTarget, (float) 42); 151 inTarget.copyTo(arrayInTarget); 152 float[] arrayOut = new float[INPUTSIZE * 2]; 153 Arrays.fill(arrayOut, (float) 42); 154 out.copyTo(arrayOut); 155 StringBuilder message = new StringBuilder(); 156 boolean errorFound = false; 157 for (int i = 0; i < INPUTSIZE; i++) { 158 for (int j = 0; j < 2 ; j++) { 159 // Extract the inputs. 160 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 161 args.inV = arrayInV[i * 2 + j]; 162 args.inTarget = arrayInTarget[i * 2 + j]; 163 // Figure out what the outputs should have been. 164 Target target = new Target(relaxed); 165 CoreMathVerifier.computeNextafter(args, target); 166 // Validate the outputs. 167 boolean valid = true; 168 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 169 valid = false; 170 } 171 if (!valid) { 172 if (!errorFound) { 173 errorFound = true; 174 message.append("Input inV: "); 175 appendVariableToMessage(message, args.inV); 176 message.append("\n"); 177 message.append("Input inTarget: "); 178 appendVariableToMessage(message, args.inTarget); 179 message.append("\n"); 180 message.append("Expected output out: "); 181 appendVariableToMessage(message, args.out); 182 message.append("\n"); 183 message.append("Actual output out: "); 184 appendVariableToMessage(message, arrayOut[i * 2 + j]); 185 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 186 message.append(" FAIL"); 187 } 188 message.append("\n"); 189 message.append("Errors at"); 190 } 191 message.append(" ["); 192 message.append(Integer.toString(i)); 193 message.append(", "); 194 message.append(Integer.toString(j)); 195 message.append("]"); 196 } 197 } 198 } 199 assertFalse("Incorrect output for checkNextafterFloat2Float2Float2" + 200 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 201 } 202 203 private void checkNextafterFloat3Float3Float3() { 204 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x5a281fc3l, false); 205 Allocation inTarget = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe4f910dcl, false); 206 try { 207 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 208 script.set_gAllocInTarget(inTarget); 209 script.forEach_testNextafterFloat3Float3Float3(inV, out); 210 verifyResultsNextafterFloat3Float3Float3(inV, inTarget, out, false); 211 } catch (Exception e) { 212 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNextafterFloat3Float3Float3: " + e.toString()); 213 } 214 try { 215 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 216 scriptRelaxed.set_gAllocInTarget(inTarget); 217 scriptRelaxed.forEach_testNextafterFloat3Float3Float3(inV, out); 218 verifyResultsNextafterFloat3Float3Float3(inV, inTarget, out, true); 219 } catch (Exception e) { 220 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNextafterFloat3Float3Float3: " + e.toString()); 221 } 222 } 223 224 private void verifyResultsNextafterFloat3Float3Float3(Allocation inV, Allocation inTarget, Allocation out, boolean relaxed) { 225 float[] arrayInV = new float[INPUTSIZE * 4]; 226 Arrays.fill(arrayInV, (float) 42); 227 inV.copyTo(arrayInV); 228 float[] arrayInTarget = new float[INPUTSIZE * 4]; 229 Arrays.fill(arrayInTarget, (float) 42); 230 inTarget.copyTo(arrayInTarget); 231 float[] arrayOut = new float[INPUTSIZE * 4]; 232 Arrays.fill(arrayOut, (float) 42); 233 out.copyTo(arrayOut); 234 StringBuilder message = new StringBuilder(); 235 boolean errorFound = false; 236 for (int i = 0; i < INPUTSIZE; i++) { 237 for (int j = 0; j < 3 ; j++) { 238 // Extract the inputs. 239 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 240 args.inV = arrayInV[i * 4 + j]; 241 args.inTarget = arrayInTarget[i * 4 + j]; 242 // Figure out what the outputs should have been. 243 Target target = new Target(relaxed); 244 CoreMathVerifier.computeNextafter(args, target); 245 // Validate the outputs. 246 boolean valid = true; 247 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 248 valid = false; 249 } 250 if (!valid) { 251 if (!errorFound) { 252 errorFound = true; 253 message.append("Input inV: "); 254 appendVariableToMessage(message, args.inV); 255 message.append("\n"); 256 message.append("Input inTarget: "); 257 appendVariableToMessage(message, args.inTarget); 258 message.append("\n"); 259 message.append("Expected output out: "); 260 appendVariableToMessage(message, args.out); 261 message.append("\n"); 262 message.append("Actual output out: "); 263 appendVariableToMessage(message, arrayOut[i * 4 + j]); 264 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 265 message.append(" FAIL"); 266 } 267 message.append("\n"); 268 message.append("Errors at"); 269 } 270 message.append(" ["); 271 message.append(Integer.toString(i)); 272 message.append(", "); 273 message.append(Integer.toString(j)); 274 message.append("]"); 275 } 276 } 277 } 278 assertFalse("Incorrect output for checkNextafterFloat3Float3Float3" + 279 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 280 } 281 282 private void checkNextafterFloat4Float4Float4() { 283 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x5c062164l, false); 284 Allocation inTarget = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xd20d4c77l, false); 285 try { 286 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 287 script.set_gAllocInTarget(inTarget); 288 script.forEach_testNextafterFloat4Float4Float4(inV, out); 289 verifyResultsNextafterFloat4Float4Float4(inV, inTarget, out, false); 290 } catch (Exception e) { 291 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNextafterFloat4Float4Float4: " + e.toString()); 292 } 293 try { 294 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 295 scriptRelaxed.set_gAllocInTarget(inTarget); 296 scriptRelaxed.forEach_testNextafterFloat4Float4Float4(inV, out); 297 verifyResultsNextafterFloat4Float4Float4(inV, inTarget, out, true); 298 } catch (Exception e) { 299 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNextafterFloat4Float4Float4: " + e.toString()); 300 } 301 } 302 303 private void verifyResultsNextafterFloat4Float4Float4(Allocation inV, Allocation inTarget, Allocation out, boolean relaxed) { 304 float[] arrayInV = new float[INPUTSIZE * 4]; 305 Arrays.fill(arrayInV, (float) 42); 306 inV.copyTo(arrayInV); 307 float[] arrayInTarget = new float[INPUTSIZE * 4]; 308 Arrays.fill(arrayInTarget, (float) 42); 309 inTarget.copyTo(arrayInTarget); 310 float[] arrayOut = new float[INPUTSIZE * 4]; 311 Arrays.fill(arrayOut, (float) 42); 312 out.copyTo(arrayOut); 313 StringBuilder message = new StringBuilder(); 314 boolean errorFound = false; 315 for (int i = 0; i < INPUTSIZE; i++) { 316 for (int j = 0; j < 4 ; j++) { 317 // Extract the inputs. 318 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 319 args.inV = arrayInV[i * 4 + j]; 320 args.inTarget = arrayInTarget[i * 4 + j]; 321 // Figure out what the outputs should have been. 322 Target target = new Target(relaxed); 323 CoreMathVerifier.computeNextafter(args, target); 324 // Validate the outputs. 325 boolean valid = true; 326 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 327 valid = false; 328 } 329 if (!valid) { 330 if (!errorFound) { 331 errorFound = true; 332 message.append("Input inV: "); 333 appendVariableToMessage(message, args.inV); 334 message.append("\n"); 335 message.append("Input inTarget: "); 336 appendVariableToMessage(message, args.inTarget); 337 message.append("\n"); 338 message.append("Expected output out: "); 339 appendVariableToMessage(message, args.out); 340 message.append("\n"); 341 message.append("Actual output out: "); 342 appendVariableToMessage(message, arrayOut[i * 4 + j]); 343 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 344 message.append(" FAIL"); 345 } 346 message.append("\n"); 347 message.append("Errors at"); 348 } 349 message.append(" ["); 350 message.append(Integer.toString(i)); 351 message.append(", "); 352 message.append(Integer.toString(j)); 353 message.append("]"); 354 } 355 } 356 } 357 assertFalse("Incorrect output for checkNextafterFloat4Float4Float4" + 358 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 359 } 360 361 public void testNextafter() { 362 checkNextafterFloatFloatFloat(); 363 checkNextafterFloat2Float2Float2(); 364 checkNextafterFloat3Float3Float3(); 365 checkNextafterFloat4Float4Float4(); 366 } 367 } 368