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