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